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
23using namespace ns3;
24
32{
33 public:
35 const Ipv4Header& header,
37 Socket::SocketErrno& sockerr) override
38 {
39 return nullptr;
40 }
41
43 const Ipv4Header& header,
48 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
62 {
63 }
64
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
85{
86 public:
88 const Ipv4Header& header,
90 Socket::SocketErrno& sockerr) override
91 {
92 return nullptr;
93 }
94
96 const Ipv4Header& header,
101 ErrorCallback ecb) override
102 {
103 return false;
104 }
105
106 void NotifyInterfaceUp(uint32_t interface) override
107 {
108 }
109
110 void NotifyInterfaceDown(uint32_t interface) override
111 {
112 }
113
115 {
116 }
117
119 {
120 }
121
122 void SetIpv4(Ptr<Ipv4> ipv4) override
123 {
124 }
125
126 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
127 {
128 }
129};
130
138{
139 public:
141 void DoRun() override;
142};
143
145 : TestCase("Check negative priorities")
146{
147}
148
149void
151{
152 Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting>();
153 Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting>();
154 Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting>();
155 // The Ipv4BRouting should be added with higher priority (larger integer value)
156 lr->AddRoutingProtocol(aRouting, -10);
157 lr->AddRoutingProtocol(bRouting, -5);
158 int16_t first = 3;
159 uint32_t num = lr->GetNRoutingProtocols();
160 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
161 Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
162 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
163 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
164}
165
173{
174 public:
176 void DoRun() override;
177};
178
180 : TestCase("Check positive priorities")
181{
182}
183
184void
186{
187 Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting>();
188 Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting>();
189 Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting>();
190 // The Ipv4ARouting should be added with higher priority (larger integer
191 // value) and will be fetched first below
192 lr->AddRoutingProtocol(aRouting, 10);
193 lr->AddRoutingProtocol(bRouting, 5);
194 int16_t first = 3;
195 int16_t second = 3;
196 uint32_t num = lr->GetNRoutingProtocols();
197 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
198 Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
199 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
200 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
201 Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
202 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
203 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
204}
205
213{
214 public:
216 : TestSuite("ipv4-list-routing", UNIT)
217 {
218 AddTestCase(new Ipv4ListRoutingPositiveTestCase(), TestCase::QUICK);
219 AddTestCase(new Ipv4ListRoutingNegativeTestCase(), TestCase::QUICK);
220 }
221};
222
IPv4 dummy routing class (A)
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 NotifyInterfaceDown(uint32_t interface) override
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb) override
Route an input packet (to be forwarded or locally delivered)
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const override
Print the Routing Table entries.
void NotifyInterfaceUp(uint32_t interface) override
void SetIpv4(Ptr< Ipv4 > ipv4) 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.
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb) override
Route an input packet (to be forwarded or locally delivered)
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 NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceDown(uint32_t interface) override
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceUp(uint32_t interface) override
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Callback template class.
Definition: callback.h:443
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
Abstract base class for IPv4 routing protocols.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
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
static Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
Static variable for test initialization.
Definition: first.py:1
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: second.py:1