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 * \ingroup internet-test
84 *
85 * \brief IPv6 dummy routing class (B)
86 */
88{
89 public:
91 const Ipv6Header& header,
93 Socket::SocketErrno& sockerr) override
94 {
95 return nullptr;
96 }
97
99 const Ipv6Header& header,
101 const UnicastForwardCallback& ucb,
102 const MulticastForwardCallback& mcb,
103 const LocalDeliverCallback& lcb,
104 const ErrorCallback& ecb) override
105 {
106 return false;
107 }
108
109 void NotifyInterfaceUp(uint32_t interface) override
110 {
111 }
112
113 void NotifyInterfaceDown(uint32_t interface) override
114 {
115 }
116
117 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
118 {
119 }
120
121 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
122 {
123 }
124
126 Ipv6Prefix mask,
127 Ipv6Address nextHop,
128 uint32_t interface,
129 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
130 {
131 }
132
134 Ipv6Prefix mask,
135 Ipv6Address nextHop,
136 uint32_t interface,
137 Ipv6Address prefixToUse) override
138 {
139 }
140
141 void SetIpv6(Ptr<Ipv6> ipv6) override
142 {
143 }
144
145 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override{};
146};
147
148/**
149 * \ingroup internet-test
150 *
151 * \brief IPv6 ListRouting negative test.
152 */
154{
155 public:
157 void DoRun() override;
158};
159
164
165void
167{
171 // The Ipv6BRouting should be added with higher priority (larger integer value)
172 lr->AddRoutingProtocol(aRouting, -10);
173 lr->AddRoutingProtocol(bRouting, -5);
174 int16_t first = 3;
175 uint32_t num = lr->GetNRoutingProtocols();
176 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
177 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
178 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
179 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
180}
181
182/**
183 * \ingroup internet-test
184 *
185 * \brief IPv6 ListRouting positive test.
186 */
188{
189 public:
191 void DoRun() override;
192};
193
198
199void
201{
205 // The Ipv6ARouting should be added with higher priority (larger integer
206 // value) and will be fetched first below
207 lr->AddRoutingProtocol(aRouting, 10);
208 lr->AddRoutingProtocol(bRouting, 5);
209 int16_t first = 3;
210 int16_t second = 3;
211 uint32_t num = lr->GetNRoutingProtocols();
212 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
213 Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
214 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
215 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
216 Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
217 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
218 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
219}
220
221/**
222 * \ingroup internet-test
223 *
224 * \brief IPv6 ListRouting TestSuite
225 */
236
237static Ipv6ListRoutingTestSuite
238 g_ipv6ListRoutingTestSuite; //!< Static variable for test initialization
239
240} // 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.