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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "ns3/ipv6-list-routing.h"
9#include "ns3/ipv6-route.h"
10#include "ns3/ipv6-routing-protocol.h"
11#include "ns3/test.h"
12
13namespace ns3
14{
15
16/**
17 * @ingroup internet-test
18 *
19 * @brief IPv6 dummy routing class (A)
20 */
22{
23 public:
25 const Ipv6Header& header,
27 Socket::SocketErrno& sockerr) override
28 {
29 return nullptr;
30 }
31
33 const Ipv6Header& header,
35 const UnicastForwardCallback& ucb,
36 const MulticastForwardCallback& mcb,
37 const LocalDeliverCallback& lcb,
38 const ErrorCallback& ecb) override
39 {
40 return false;
41 }
42
43 void NotifyInterfaceUp(uint32_t interface) override
44 {
45 }
46
47 void NotifyInterfaceDown(uint32_t interface) override
48 {
49 }
50
51 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
52 {
53 }
54
55 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
56 {
57 }
58
60 Ipv6Prefix mask,
61 Ipv6Address nextHop,
62 uint32_t interface,
63 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
64 {
65 }
66
68 Ipv6Prefix mask,
69 Ipv6Address nextHop,
70 uint32_t interface,
71 Ipv6Address prefixToUse) override
72 {
73 }
74
75 void SetIpv6(Ptr<Ipv6> ipv6) override
76 {
77 }
78
79 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
80 {
81 }
82};
83
84/**
85 * @ingroup internet-test
86 *
87 * @brief IPv6 dummy routing class (B)
88 */
90{
91 public:
93 const Ipv6Header& header,
95 Socket::SocketErrno& sockerr) override
96 {
97 return nullptr;
98 }
99
101 const Ipv6Header& header,
103 const UnicastForwardCallback& ucb,
104 const MulticastForwardCallback& mcb,
105 const LocalDeliverCallback& lcb,
106 const ErrorCallback& ecb) override
107 {
108 return false;
109 }
110
111 void NotifyInterfaceUp(uint32_t interface) override
112 {
113 }
114
115 void NotifyInterfaceDown(uint32_t interface) override
116 {
117 }
118
119 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
120 {
121 }
122
123 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
124 {
125 }
126
128 Ipv6Prefix mask,
129 Ipv6Address nextHop,
130 uint32_t interface,
131 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
132 {
133 }
134
136 Ipv6Prefix mask,
137 Ipv6Address nextHop,
138 uint32_t interface,
139 Ipv6Address prefixToUse) override
140 {
141 }
142
143 void SetIpv6(Ptr<Ipv6> ipv6) override
144 {
145 }
146
147 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
148 {
149 }
150};
151
152/**
153 * @ingroup internet-test
154 *
155 * @brief IPv6 ListRouting negative test.
156 */
158{
159 public:
161 void DoRun() override;
162};
163
168
169void
171{
175 // The Ipv6BRouting should be added with higher priority (larger integer value)
176 lr->AddRoutingProtocol(aRouting, -10);
177 lr->AddRoutingProtocol(bRouting, -5);
178 int16_t first = 3;
179 uint32_t num = lr->GetNRoutingProtocols();
180 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
181 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
182 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
183 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
184}
185
186/**
187 * @ingroup internet-test
188 *
189 * @brief IPv6 ListRouting positive test.
190 */
192{
193 public:
195 void DoRun() override;
196};
197
202
203void
205{
209 // The Ipv6ARouting should be added with higher priority (larger integer
210 // value) and will be fetched first below
211 lr->AddRoutingProtocol(aRouting, 10);
212 lr->AddRoutingProtocol(bRouting, 5);
213 int16_t first = 3;
214 int16_t second = 3;
215 uint32_t num = lr->GetNRoutingProtocols();
216 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
217 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
218 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
219 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
220 Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
221 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
222 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
223}
224
225/**
226 * @ingroup internet-test
227 *
228 * @brief IPv6 ListRouting TestSuite
229 */
240
241static Ipv6ListRoutingTestSuite
242 g_ipv6ListRoutingTestSuite; //!< Static variable for test initialization
243
244} // 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.
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:24
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.
Abstract base class for IPv6 routing protocols.
Smart pointer class similar to boost::intrusive_ptr.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
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.