A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
24namespace ns3
25{
26
27/**
28 * \ingroup internet-test
29 *
30 * \brief IPv6 dummy routing class (A)
31 */
33{
34 public:
36 const Ipv6Header& header,
38 Socket::SocketErrno& sockerr) override
39 {
40 return nullptr;
41 }
42
44 const Ipv6Header& header,
46 const UnicastForwardCallback& ucb,
47 const MulticastForwardCallback& mcb,
48 const LocalDeliverCallback& lcb,
49 const 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
62 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
63 {
64 }
65
66 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
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
93/**
94 * \ingroup internet-test
95 *
96 * \brief IPv6 dummy routing class (B)
97 */
99{
100 public:
102 const Ipv6Header& header,
103 Ptr<NetDevice> oif,
104 Socket::SocketErrno& sockerr) override
105 {
106 return nullptr;
107 }
108
110 const Ipv6Header& header,
112 const UnicastForwardCallback& ucb,
113 const MulticastForwardCallback& mcb,
114 const LocalDeliverCallback& lcb,
115 const ErrorCallback& ecb) override
116 {
117 return false;
118 }
119
120 void NotifyInterfaceUp(uint32_t interface) override
121 {
122 }
123
124 void NotifyInterfaceDown(uint32_t interface) override
125 {
126 }
127
128 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
129 {
130 }
131
132 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
133 {
134 }
135
137 Ipv6Prefix mask,
138 Ipv6Address nextHop,
139 uint32_t interface,
140 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
141 {
142 }
143
145 Ipv6Prefix mask,
146 Ipv6Address nextHop,
147 uint32_t interface,
148 Ipv6Address prefixToUse) override
149 {
150 }
151
152 void SetIpv6(Ptr<Ipv6> ipv6) override
153 {
154 }
155
156 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override{};
157};
158
159/**
160 * \ingroup internet-test
161 *
162 * \brief IPv6 ListRouting negative test.
163 */
165{
166 public:
168 void DoRun() override;
169};
170
172 : TestCase("Check negative priorities")
173{
174}
175
176void
178{
179 Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting>();
180 Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting>();
181 Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting>();
182 // The Ipv6BRouting should be added with higher priority (larger integer value)
183 lr->AddRoutingProtocol(aRouting, -10);
184 lr->AddRoutingProtocol(bRouting, -5);
185 int16_t first = 3;
186 uint32_t num = lr->GetNRoutingProtocols();
187 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
188 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
189 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
190 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
191}
192
193/**
194 * \ingroup internet-test
195 *
196 * \brief IPv6 ListRouting positive test.
197 */
199{
200 public:
202 void DoRun() override;
203};
204
206 : TestCase("Check positive priorities")
207{
208}
209
210void
212{
213 Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting>();
214 Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting>();
215 Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting>();
216 // The Ipv6ARouting should be added with higher priority (larger integer
217 // value) and will be fetched first below
218 lr->AddRoutingProtocol(aRouting, 10);
219 lr->AddRoutingProtocol(bRouting, 5);
220 int16_t first = 3;
221 int16_t second = 3;
222 uint32_t num = lr->GetNRoutingProtocols();
223 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
224 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
225 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
226 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
227 Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
228 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
229 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
230}
231
232/**
233 * \ingroup internet-test
234 *
235 * \brief IPv6 ListRouting TestSuite
236 */
238{
239 public:
241 : TestSuite("ipv6-list-routing", Type::UNIT)
242 {
245 }
246};
247
248static Ipv6ListRoutingTestSuite
249 g_ipv6ListRoutingTestSuite; //!< Static variable for test initialization
250
251} // namespace ns3
IPv6 dummy routing class (A)
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.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &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 PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit) const override
Print the Routing Table entries.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) override
Notify route removing.
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.
Describes an IPv6 address.
Definition: ipv6-address.h:49
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
IPv6 dummy routing class (B)
void NotifyAddAddress(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.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
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.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &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 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 NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Packet header for IPv6.
Definition: ipv6-header.h:35
IPv6 address associated with an interface.
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
Abstract base class for IPv6 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:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
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:145
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Ipv6ListRoutingTestSuite g_ipv6ListRoutingTestSuite
Static variable for test initialization.
Definition: second.py:1