A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv4-test.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
16  *
17  */
22 #include "ns3/simulator.h"
23 #include "ns3/test.h"
24 #include "ns3/log.h"
25 #include "ns3/inet-socket-address.h"
26 #include "ns3/node.h"
27 
28 #include "ns3/ipv4-l3-protocol.h"
29 #include "ns3/arp-l3-protocol.h"
30 #include "ns3/ipv4-interface.h"
31 #include "ns3/loopback-net-device.h"
32 
33 namespace ns3 {
34 
36 {
37 public:
45  virtual
51  virtual void
52  DoRun (void);
53 
54 };
55 
57  TestCase ("Verify the IPv4 layer 3 protocol")
58 {
59 }
60 
62 {
63 }
64 void
66 {
67  Ptr<Node> node = CreateObject<Node> ();
68  Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
69  Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
70  Ptr<LoopbackNetDevice> device = CreateObject<LoopbackNetDevice> ();
71  node->AddDevice (device);
72  interface->SetDevice (device);
73  interface->SetNode (node);
74  uint32_t index = ipv4->AddIpv4Interface (interface);
75  NS_TEST_ASSERT_MSG_EQ (index, 0, "No interface should be found??");
76  interface->SetUp ();
77  Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1",
78  "255.255.255.0");
79  interface->AddAddress (ifaceAddr1);
80  Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2",
81  "255.255.255.0");
82  interface->AddAddress (ifaceAddr2);
83  Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1",
84  "255.255.255.0");
85  interface->AddAddress (ifaceAddr3);
86  Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1",
87  "255.255.255.0");
88  interface->AddAddress (ifaceAddr4);
89  uint32_t num = interface->GetNAddresses ();
90  NS_TEST_ASSERT_MSG_EQ (num, 4, "Should find 4 interfaces??");
91  interface->RemoveAddress (2);
92  num = interface->GetNAddresses ();
93  NS_TEST_ASSERT_MSG_EQ (num, 3, "Should find 3 interfaces??");
94  Ipv4InterfaceAddress output = interface->GetAddress (2);
95  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
96  "The addresses should be identical");
98 }
99 
100 static class IPv4L3ProtocolTestSuite : public TestSuite
101 {
102 public:
104  TestSuite ("ipv4-protocol", UNIT)
105  {
106  AddTestCase (new Ipv4L3ProtocolTestCase (), TestCase::QUICK);
107  }
108 } g_ipv4protocolTestSuite;
109 
110 } // namespace ns3
A suite of tests to run.
Definition: test.h:962
Ipv4L3ProtocolTestCase()
Constructor.
Definition: ipv4-test.cc:56
encapsulates test code
Definition: test.h:834
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
virtual void DoRun(void)
Run unit tests for this class.
Definition: ipv4-test.cc:65
static void Destroy(void)
Definition: simulator.cc:121
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
virtual ~Ipv4L3ProtocolTestCase()
Destructor.
Definition: ipv4-test.cc:61
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
a class to store IPv4 address information on an interface