A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-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/ipv4-list-routing.h"
9#include "ns3/ipv4-routing-protocol.h"
10#include "ns3/test.h"
11
12namespace ns3
13{
14
15/**
16 * \ingroup internet-test
17 *
18 * \brief IPv4 dummy routing class (A)
19 */
21{
22 public:
24 const Ipv4Header& header,
26 Socket::SocketErrno& sockerr) override
27 {
28 return nullptr;
29 }
30
32 const Ipv4Header& header,
34 const UnicastForwardCallback& ucb,
35 const MulticastForwardCallback& mcb,
36 const LocalDeliverCallback& lcb,
37 const ErrorCallback& ecb) override
38 {
39 return false;
40 }
41
42 void NotifyInterfaceUp(uint32_t interface) override
43 {
44 }
45
46 void NotifyInterfaceDown(uint32_t interface) override
47 {
48 }
49
50 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
51 {
52 }
53
54 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
55 {
56 }
57
58 void SetIpv4(Ptr<Ipv4> ipv4) override
59 {
60 }
61
62 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
63 {
64 }
65};
66
67/**
68 * \ingroup internet-test
69 *
70 * \brief IPv4 dummy routing class (B)
71 */
73{
74 public:
76 const Ipv4Header& header,
78 Socket::SocketErrno& sockerr) override
79 {
80 return nullptr;
81 }
82
84 const Ipv4Header& header,
86 const UnicastForwardCallback& ucb,
87 const MulticastForwardCallback& mcb,
88 const LocalDeliverCallback& lcb,
89 const ErrorCallback& ecb) override
90 {
91 return false;
92 }
93
94 void NotifyInterfaceUp(uint32_t interface) override
95 {
96 }
97
98 void NotifyInterfaceDown(uint32_t interface) override
99 {
100 }
101
102 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
103 {
104 }
105
106 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
107 {
108 }
109
110 void SetIpv4(Ptr<Ipv4> ipv4) override
111 {
112 }
113
114 void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override
115 {
116 }
117};
118
119/**
120 * \ingroup internet-test
121 *
122 * \brief IPv4 ListRouting negative test.
123 */
125{
126 public:
128 void DoRun() override;
129};
130
135
136void
138{
142 // The Ipv4BRouting should be added with higher priority (larger integer value)
143 lr->AddRoutingProtocol(aRouting, -10);
144 lr->AddRoutingProtocol(bRouting, -5);
145 int16_t first = 3;
146 uint32_t num = lr->GetNRoutingProtocols();
147 NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
148 Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
149 NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
150 NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
151}
152
153/**
154 * \ingroup internet-test
155 *
156 * \brief IPv4 ListRouting positive test.
157 */
159{
160 public:
162 void DoRun() override;
163};
164
169
170void
172{
176 // The Ipv4ARouting should be added with higher priority (larger integer
177 // value) and will be fetched first below
178 lr->AddRoutingProtocol(aRouting, 10);
179 lr->AddRoutingProtocol(bRouting, 5);
180 int16_t first = 3;
181 int16_t second = 3;
182 uint32_t num = lr->GetNRoutingProtocols();
183 NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
184 Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
185 NS_TEST_ASSERT_MSG_EQ(10, first, "201");
186 NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
187 Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
188 NS_TEST_ASSERT_MSG_EQ(5, second, "203");
189 NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
190}
191
192/**
193 * \ingroup internet-test
194 *
195 * \brief IPv4 ListRouting TestSuite
196 */
207
208static Ipv4ListRoutingTestSuite
209 g_ipv4ListRoutingTestSuite; //!< Static variable for test initialization
210
211} // namespace ns3
IPv4 dummy routing class (A)
void SetIpv4(Ptr< Ipv4 > ipv4) override
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) 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, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
void NotifyInterfaceUp(uint32_t interface) override
void NotifyInterfaceDown(uint32_t interface) override
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
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.
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.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &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)
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 NotifyInterfaceUp(uint32_t interface) override
Packet header for IPv4.
Definition ipv4-header.h:23
a class to store IPv4 address information on an interface
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Abstract base class for IPv4 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 Ipv4ListRoutingTestSuite g_ipv4ListRoutingTestSuite
Static variable for test initialization.