A Discrete-Event Network Simulator
API
ipv4-list-routing-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 
19 #include "ns3/ipv4-list-routing.h"
20 #include "ns3/ipv4-routing-protocol.h"
21 #include "ns3/test.h"
22 
23 namespace ns3
24 {
25 
32 {
33  public:
35  const Ipv4Header& header,
36  Ptr<NetDevice> oif,
37  Socket::SocketErrno& sockerr) override
38  {
39  return nullptr;
40  }
41 
43  const Ipv4Header& header,
45  const UnicastForwardCallback& ucb,
46  const MulticastForwardCallback& mcb,
47  const LocalDeliverCallback& lcb,
48  const ErrorCallback& ecb) override
49  {
50  return false;
51  }
52 
53  void NotifyInterfaceUp(uint32_t interface) override
54  {
55  }
56 
57  void NotifyInterfaceDown(uint32_t interface) override
58  {
59  }
60 
61  void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
62  {
63  }
64 
65  void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
66  {
67  }
68 
69  void SetIpv4(Ptr<Ipv4> ipv4) override
70  {
71  }
72 
73  void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
74  {
75  }
76 };
77 
84 {
85  public:
87  const Ipv4Header& header,
88  Ptr<NetDevice> oif,
89  Socket::SocketErrno& sockerr) override
90  {
91  return nullptr;
92  }
93 
95  const Ipv4Header& header,
97  const UnicastForwardCallback& ucb,
98  const MulticastForwardCallback& mcb,
99  const LocalDeliverCallback& lcb,
100  const ErrorCallback& ecb) override
101  {
102  return false;
103  }
104 
105  void NotifyInterfaceUp(uint32_t interface) override
106  {
107  }
108 
109  void NotifyInterfaceDown(uint32_t interface) override
110  {
111  }
112 
113  void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
114  {
115  }
116 
117  void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
118  {
119  }
120 
121  void SetIpv4(Ptr<Ipv4> ipv4) override
122  {
123  }
124 
125  void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
126  {
127  }
128 };
129 
136 {
137  public:
139  void DoRun() override;
140 };
141 
143  : TestCase("Check negative priorities")
144 {
145 }
146 
147 void
149 {
150  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting>();
151  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting>();
152  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting>();
153  // The Ipv4BRouting should be added with higher priority (larger integer value)
154  lr->AddRoutingProtocol(aRouting, -10);
155  lr->AddRoutingProtocol(bRouting, -5);
156  int16_t first = 3;
157  uint32_t num = lr->GetNRoutingProtocols();
158  NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
159  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
160  NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
161  NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
162 }
163 
170 {
171  public:
173  void DoRun() override;
174 };
175 
177  : TestCase("Check positive priorities")
178 {
179 }
180 
181 void
183 {
184  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting>();
185  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting>();
186  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting>();
187  // The Ipv4ARouting should be added with higher priority (larger integer
188  // value) and will be fetched first below
189  lr->AddRoutingProtocol(aRouting, 10);
190  lr->AddRoutingProtocol(bRouting, 5);
191  int16_t first = 3;
192  int16_t second = 3;
193  uint32_t num = lr->GetNRoutingProtocols();
194  NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
195  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
196  NS_TEST_ASSERT_MSG_EQ(10, first, "201");
197  NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
198  Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
199  NS_TEST_ASSERT_MSG_EQ(5, second, "203");
200  NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
201 }
202 
209 {
210  public:
212  : TestSuite("ipv4-list-routing", UNIT)
213  {
216  }
217 };
218 
219 static Ipv4ListRoutingTestSuite
221 
222 } // namespace ns3
IPv4 dummy routing class (A)
void SetIpv4(Ptr< Ipv4 > ipv4) override
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const override
Print the Routing Table entries.
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
void NotifyInterfaceUp(uint32_t interface) override
void NotifyInterfaceDown(uint32_t interface) override
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
IPv4 dummy routing class (B)
void SetIpv4(Ptr< Ipv4 > ipv4) override
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const override
Print the Routing Table entries.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceDown(uint32_t interface) override
void NotifyInterfaceUp(uint32_t interface) override
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Abstract base class for IPv4 routing protocols.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
Definition: first.py:1
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
Static variable for test initialization.
Definition: second.py:1