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
31{
32 public:
34 const Ipv4Header& header,
36 Socket::SocketErrno& sockerr) override
37 {
38 return nullptr;
39 }
40
42 const Ipv4Header& header,
47 ErrorCallback ecb) override
48 {
49 return false;
50 }
51
52 void NotifyInterfaceUp(uint32_t interface) override
53 {
54 }
55
56 void NotifyInterfaceDown(uint32_t interface) override
57 {
58 }
59
61 {
62 }
63
65 {
66 }
67
68 void SetIpv4(Ptr<Ipv4> ipv4) override
69 {
70 }
71
72 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
73 {
74 }
75};
76
83{
84 public:
86 const Ipv4Header& header,
88 Socket::SocketErrno& sockerr) override
89 {
90 return nullptr;
91 }
92
94 const Ipv4Header& header,
99 ErrorCallback ecb) override
100 {
101 return false;
102 }
103
104 void NotifyInterfaceUp(uint32_t interface) override
105 {
106 }
107
108 void NotifyInterfaceDown(uint32_t interface) override
109 {
110 }
111
113 {
114 }
115
117 {
118 }
119
120 void SetIpv4(Ptr<Ipv4> ipv4) override
121 {
122 }
123
124 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
125 {
126 }
127};
128
135{
136 public:
138 void DoRun() override;
139};
140
142 : TestCase("Check negative priorities")
143{
144}
145
146void
148{
149 Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting>();
150 Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting>();
151 Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting>();
152 // The Ipv4BRouting should be added with higher priority (larger integer value)
153 lr->AddRoutingProtocol(aRouting, -10);
154 lr->AddRoutingProtocol(bRouting, -5);
155 int16_t first = 3;
156 uint32_t num = lr->GetNRoutingProtocols();
157 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
158 Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
159 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
160 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
161}
162
169{
170 public:
172 void DoRun() override;
173};
174
176 : TestCase("Check positive priorities")
177{
178}
179
180void
182{
183 Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting>();
184 Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting>();
185 Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting>();
186 // The Ipv4ARouting should be added with higher priority (larger integer
187 // value) and will be fetched first below
188 lr->AddRoutingProtocol(aRouting, 10);
189 lr->AddRoutingProtocol(bRouting, 5);
190 int16_t first = 3;
191 int16_t second = 3;
192 uint32_t num = lr->GetNRoutingProtocols();
193 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
194 Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
195 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
196 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
197 Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
198 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
199 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
200}
201
208{
209 public:
211 : TestSuite("ipv4-list-routing", UNIT)
212 {
213 AddTestCase(new Ipv4ListRoutingPositiveTestCase(), TestCase::QUICK);
214 AddTestCase(new Ipv4ListRoutingNegativeTestCase(), TestCase::QUICK);
215 }
216};
217
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