LEFT | RIGHT |
(no file at all) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2017 NITK Surathkal |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Authors: Ankit Deepak <adadeepak8@gmail.com> |
| 19 * Deepti Rajagopal <deeptir96@gmail.com> |
| 20 * |
| 21 */ |
| 22 |
| 23 #include "ns3/core-module.h" |
| 24 #include "ns3/network-module.h" |
| 25 #include "ns3/internet-apps-module.h" |
| 26 #include "ns3/csma-module.h" |
| 27 #include "ns3/internet-module.h" |
| 28 |
| 29 #include "ns3/test.h" |
| 30 |
| 31 using namespace ns3; |
| 32 |
| 33 class DhcpTestCase1 : public TestCase |
| 34 { |
| 35 public: |
| 36 DhcpTestCase1 (); |
| 37 virtual ~DhcpTestCase1 (); |
| 38 |
| 39 private: |
| 40 virtual void DoRun (void); |
| 41 }; |
| 42 |
| 43 DhcpTestCase1::DhcpTestCase1 () |
| 44 : TestCase ("Dhcp test case ") |
| 45 { |
| 46 } |
| 47 |
| 48 DhcpTestCase1::~DhcpTestCase1 () |
| 49 { |
| 50 } |
| 51 |
| 52 void |
| 53 DhcpTestCase1::DoRun (void) |
| 54 { |
| 55 /*Set up devices*/ |
| 56 NodeContainer MN; |
| 57 NodeContainer Router; |
| 58 MN.Create (3); |
| 59 Router.Create (2); |
| 60 |
| 61 NodeContainer net (MN, Router); |
| 62 |
| 63 CsmaHelper csma; |
| 64 csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps")); |
| 65 csma.SetChannelAttribute ("Delay", StringValue ("2ms")); |
| 66 csma.SetDeviceAttribute ("Mtu", UintegerValue (1500)); |
| 67 NetDeviceContainer dev_net = csma.Install (net); |
| 68 |
| 69 InternetStackHelper tcpip; |
| 70 tcpip.Install (MN); |
| 71 tcpip.Install (Router); |
| 72 |
| 73 Ptr<Ipv4> ipv4MN = net.Get (0)->GetObject<Ipv4> (); |
| 74 uint32_t ifIndex = ipv4MN->AddInterface (dev_net.Get (0)); |
| 75 ipv4MN->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("0.0.0.0"), Ip
v4Mask ("/0"))); |
| 76 ipv4MN->SetForwarding (ifIndex, true); |
| 77 ipv4MN->SetUp (ifIndex); |
| 78 |
| 79 Ptr<Ipv4> ipv4MN1 = net.Get (1)->GetObject<Ipv4> (); |
| 80 uint32_t ifIndex1 = ipv4MN1->AddInterface (dev_net.Get (1)); |
| 81 ipv4MN1->AddAddress (ifIndex1, Ipv4InterfaceAddress (Ipv4Address ("0.0.0.0"),
Ipv4Mask ("/0"))); |
| 82 ipv4MN1->SetForwarding (ifIndex1, true); |
| 83 ipv4MN1->SetUp (ifIndex1); |
| 84 |
| 85 Ptr<Ipv4> ipv4MN2 = net.Get (2)->GetObject<Ipv4> (); |
| 86 uint32_t ifIndex2 = ipv4MN2->AddInterface (dev_net.Get (2)); |
| 87 ipv4MN2->AddAddress (ifIndex2, Ipv4InterfaceAddress (Ipv4Address ("0.0.0.0"),
Ipv4Mask ("/0"))); |
| 88 ipv4MN2->SetForwarding (ifIndex2, true); |
| 89 ipv4MN2->SetUp (ifIndex2); |
| 90 |
| 91 Ptr<Ipv4> ipv4Router = net.Get (3)->GetObject<Ipv4> (); |
| 92 ifIndex = ipv4Router->AddInterface (dev_net.Get (3)); |
| 93 ipv4Router->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("172.30.0.
12"), Ipv4Mask ("/0"))); // need to remove this workaround |
| 94 ipv4Router->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("172.30.0.
12"), Ipv4Mask ("/24"))); |
| 95 ipv4Router->SetForwarding (ifIndex, true); |
| 96 ipv4Router->SetUp (ifIndex); |
| 97 |
| 98 Ptr<Ipv4> ipv4Router1 = net.Get (4)->GetObject<Ipv4> (); |
| 99 ifIndex = ipv4Router1->AddInterface (dev_net.Get (4)); |
| 100 ipv4Router1->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("173.30.0
.12"), Ipv4Mask ("/0"))); // need to remove this workaround |
| 101 ipv4Router1->AddAddress (ifIndex, Ipv4InterfaceAddress (Ipv4Address ("173.30.0
.12"), Ipv4Mask ("/24"))); |
| 102 ipv4Router1->SetForwarding (ifIndex, true); |
| 103 ipv4Router1->SetUp (ifIndex); |
| 104 |
| 105 DhcpServerHelper dhcp_server (Ipv4Address ("172.30.0.0"), Ipv4Mask ("/24"), Ip
v4Address ("172.30.0.12"), Ipv4Address ("172.30.0.10"), Ipv4Address ("172.30.0.1
00")); |
| 106 ApplicationContainer ap_dhcp_server = dhcp_server.Install (Router.Get (0)); |
| 107 ap_dhcp_server.Start (Seconds (1.0)); |
| 108 ap_dhcp_server.Stop (Seconds (500.0)); |
| 109 |
| 110 DhcpServerHelper dhcp_server1 (Ipv4Address ("173.30.0.0"), Ipv4Mask ("/24"), I
pv4Address ("173.30.0.12"), Ipv4Address ("173.30.0.10"), Ipv4Address ("173.30.0.
100")); |
| 111 ApplicationContainer ap_dhcp_server1 = dhcp_server1.Install (Router.Get (1)); |
| 112 ap_dhcp_server1.Start (Seconds (1.0)); |
| 113 ap_dhcp_server1.Stop (Seconds (500.0)); |
| 114 |
| 115 DhcpClientHelper dhcp_client (0); |
| 116 ApplicationContainer ap_dhcp_client = dhcp_client.Install (MN.Get (0)); |
| 117 ap_dhcp_client.Start (Seconds (1.0)); |
| 118 ap_dhcp_client.Stop (Seconds (100.0)); |
| 119 |
| 120 ApplicationContainer ap_dhcp_client3 = dhcp_client.Install (MN.Get (0)); |
| 121 ap_dhcp_client3.Start (Seconds (400.0)); |
| 122 ap_dhcp_client3.Stop (Seconds (500.0)); |
| 123 |
| 124 DhcpClientHelper dhcp_client1 (0); |
| 125 ApplicationContainer ap_dhcp_client1 = dhcp_client1.Install (MN.Get (1)); |
| 126 ap_dhcp_client1.Start (Seconds (1.0)); |
| 127 ap_dhcp_client1.Stop (Seconds (500.0)); |
| 128 |
| 129 DhcpClientHelper dhcp_client2 (0); |
| 130 ApplicationContainer ap_dhcp_client2 = dhcp_client2.Install (MN.Get (2)); |
| 131 ap_dhcp_client2.Start (Seconds (1.0)); |
| 132 ap_dhcp_client2.Stop (Seconds (500.0)); |
| 133 |
| 134 Simulator::Stop (Seconds (500.0)); |
| 135 |
| 136 Simulator::Run (); |
| 137 |
| 138 Ipv4Address address = ipv4MN->GetAddress (ifIndex, 0).GetLocal (); |
| 139 NS_TEST_ASSERT_MSG_EQ (Ipv4Address ("172.30.0.11"),address,address); |
| 140 |
| 141 Ipv4Address address1 = ipv4MN1->GetAddress (ifIndex, 0).GetLocal (); |
| 142 NS_TEST_ASSERT_MSG_EQ (Ipv4Address ("172.30.0.14"),address1,address1); |
| 143 |
| 144 Ipv4Address address2 = ipv4MN2->GetAddress (ifIndex, 0).GetLocal (); |
| 145 NS_TEST_ASSERT_MSG_EQ (Ipv4Address ("172.30.0.13"),address2,address2); |
| 146 |
| 147 Simulator::Destroy (); |
| 148 } |
| 149 |
| 150 class DhcpTestSuite : public TestSuite |
| 151 { |
| 152 public: |
| 153 DhcpTestSuite (); |
| 154 }; |
| 155 |
| 156 DhcpTestSuite::DhcpTestSuite () |
| 157 : TestSuite ("dhcp", UNIT) |
| 158 { |
| 159 AddTestCase (new DhcpTestCase1, TestCase::QUICK); |
| 160 } |
| 161 |
| 162 static DhcpTestSuite dhcpTestSuite; |
| 163 |
LEFT | RIGHT |