A Discrete-Event Network Simulator
API
ipv6-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/ipv6-list-routing.h"
20#include "ns3/ipv6-route.h"
21#include "ns3/ipv6-routing-protocol.h"
22#include "ns3/test.h"
23
24using namespace ns3;
25
33{
34 public:
36 const Ipv6Header& header,
38 Socket::SocketErrno& sockerr) override
39 {
40 return nullptr;
41 }
42
44 const Ipv6Header& header,
49 ErrorCallback ecb) override
50 {
51 return false;
52 }
53
54 void NotifyInterfaceUp(uint32_t interface) override
55 {
56 }
57
58 void NotifyInterfaceDown(uint32_t interface) override
59 {
60 }
61
63 {
64 }
65
67 {
68 }
69
71 Ipv6Prefix mask,
72 Ipv6Address nextHop,
73 uint32_t interface,
74 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
75 {
76 }
77
79 Ipv6Prefix mask,
80 Ipv6Address nextHop,
81 uint32_t interface,
82 Ipv6Address prefixToUse) override
83 {
84 }
85
86 void SetIpv6(Ptr<Ipv6> ipv6) override
87 {
88 }
89
90 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override{};
91};
92
100{
101 public:
103 const Ipv6Header& header,
104 Ptr<NetDevice> oif,
105 Socket::SocketErrno& sockerr) override
106 {
107 return nullptr;
108 }
109
111 const Ipv6Header& header,
116 ErrorCallback ecb) override
117 {
118 return false;
119 }
120
121 void NotifyInterfaceUp(uint32_t interface) override
122 {
123 }
124
125 void NotifyInterfaceDown(uint32_t interface) override
126 {
127 }
128
130 {
131 }
132
134 {
135 }
136
138 Ipv6Prefix mask,
139 Ipv6Address nextHop,
140 uint32_t interface,
141 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
142 {
143 }
144
146 Ipv6Prefix mask,
147 Ipv6Address nextHop,
148 uint32_t interface,
149 Ipv6Address prefixToUse) override
150 {
151 }
152
153 void SetIpv6(Ptr<Ipv6> ipv6) override
154 {
155 }
156
157 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override{};
158};
159
167{
168 public:
170 void DoRun() override;
171};
172
174 : TestCase("Check negative priorities")
175{
176}
177
178void
180{
181 Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting>();
182 Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting>();
183 Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting>();
184 // The Ipv6BRouting should be added with higher priority (larger integer value)
185 lr->AddRoutingProtocol(aRouting, -10);
186 lr->AddRoutingProtocol(bRouting, -5);
187 int16_t first = 3;
188 uint32_t num = lr->GetNRoutingProtocols();
189 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
190 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
191 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
192 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
193}
194
202{
203 public:
205 void DoRun() override;
206};
207
209 : TestCase("Check positive priorities")
210{
211}
212
213void
215{
216 Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting>();
217 Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting>();
218 Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting>();
219 // The Ipv6ARouting should be added with higher priority (larger integer
220 // value) and will be fetched first below
221 lr->AddRoutingProtocol(aRouting, 10);
222 lr->AddRoutingProtocol(bRouting, 5);
223 int16_t first = 3;
224 int16_t second = 3;
225 uint32_t num = lr->GetNRoutingProtocols();
226 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
227 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
228 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
229 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
230 Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
231 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
232 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
233}
234
242{
243 public:
245 : TestSuite("ipv6-list-routing", UNIT)
246 {
247 AddTestCase(new Ipv6ListRoutingPositiveTestCase(), TestCase::QUICK);
248 AddTestCase(new Ipv6ListRoutingNegativeTestCase(), TestCase::QUICK);
249 }
250};
251
IPv6 dummy routing class (A)
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &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
Notify when specified interface goes DOWN.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const override
Print the Routing Table entries.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) override
Notify route removing.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb) override
Route an input packet (to be forwarded or locally delivered)
IPv6 dummy routing class (B)
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &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
Notify when specified interface goes DOWN.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &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 NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) override
Notify route removing.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const override
Print the Routing Table entries.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
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
Describes an IPv6 address.
Definition: ipv6-address.h:50
Packet header for IPv6.
Definition: ipv6-header.h:36
IPv6 address associated with an interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
Abstract base class for IPv6 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 Ipv6ListRoutingTestSuite g_ipv6ListRoutingTestSuite
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