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 
24 using namespace ns3;
25 
32 {
33  public:
35  const Ipv6Header& header,
36  Ptr<NetDevice> oif,
37  Socket::SocketErrno& sockerr) override
38  {
39  return nullptr;
40  }
41 
43  const Ipv6Header& header,
48  ErrorCallback ecb) override
49  {
50  return false;
51  }
52 
53  void NotifyInterfaceUp(uint32_t interface) override
54  {
55  }
56 
57  void NotifyInterfaceDown(uint32_t interface) override
58  {
59  }
60 
61  void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
62  {
63  }
64 
65  void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
66  {
67  }
68 
70  Ipv6Prefix mask,
71  Ipv6Address nextHop,
72  uint32_t interface,
73  Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
74  {
75  }
76 
78  Ipv6Prefix mask,
79  Ipv6Address nextHop,
80  uint32_t interface,
81  Ipv6Address prefixToUse) override
82  {
83  }
84 
85  void SetIpv6(Ptr<Ipv6> ipv6) override
86  {
87  }
88 
89  void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override{};
90 };
91 
98 {
99  public:
101  const Ipv6Header& header,
102  Ptr<NetDevice> oif,
103  Socket::SocketErrno& sockerr) override
104  {
105  return nullptr;
106  }
107 
109  const Ipv6Header& header,
114  ErrorCallback ecb) override
115  {
116  return false;
117  }
118 
119  void NotifyInterfaceUp(uint32_t interface) override
120  {
121  }
122 
123  void NotifyInterfaceDown(uint32_t interface) override
124  {
125  }
126 
127  void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
128  {
129  }
130 
131  void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
132  {
133  }
134 
136  Ipv6Prefix mask,
137  Ipv6Address nextHop,
138  uint32_t interface,
139  Ipv6Address prefixToUse = Ipv6Address::GetZero()) override
140  {
141  }
142 
144  Ipv6Prefix mask,
145  Ipv6Address nextHop,
146  uint32_t interface,
147  Ipv6Address prefixToUse) override
148  {
149  }
150 
151  void SetIpv6(Ptr<Ipv6> ipv6) override
152  {
153  }
154 
155  void PrintRoutingTable(Ptr<OutputStreamWrapper> stream, Time::Unit unit) const override{};
156 };
157 
164 {
165  public:
167  void DoRun() override;
168 };
169 
171  : TestCase("Check negative priorities")
172 {
173 }
174 
175 void
177 {
178  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting>();
179  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting>();
180  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting>();
181  // The Ipv6BRouting should be added with higher priority (larger integer value)
182  lr->AddRoutingProtocol(aRouting, -10);
183  lr->AddRoutingProtocol(bRouting, -5);
184  int16_t first = 3;
185  uint32_t num = lr->GetNRoutingProtocols();
186  NS_TEST_ASSERT_MSG_EQ(num, 2, "100");
187  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
188  NS_TEST_ASSERT_MSG_EQ(-5, first, "101");
189  NS_TEST_ASSERT_MSG_EQ(firstRp, bRouting, "102");
190 }
191 
198 {
199  public:
201  void DoRun() override;
202 };
203 
205  : TestCase("Check positive priorities")
206 {
207 }
208 
209 void
211 {
212  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting>();
213  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting>();
214  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting>();
215  // The Ipv6ARouting should be added with higher priority (larger integer
216  // value) and will be fetched first below
217  lr->AddRoutingProtocol(aRouting, 10);
218  lr->AddRoutingProtocol(bRouting, 5);
219  int16_t first = 3;
220  int16_t second = 3;
221  uint32_t num = lr->GetNRoutingProtocols();
222  NS_TEST_ASSERT_MSG_EQ(num, 2, "200");
223  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol(0, first);
224  NS_TEST_ASSERT_MSG_EQ(10, first, "201");
225  NS_TEST_ASSERT_MSG_EQ(firstRp, aRouting, "202");
226  Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol(1, second);
227  NS_TEST_ASSERT_MSG_EQ(5, second, "203");
228  NS_TEST_ASSERT_MSG_EQ(secondRp, bRouting, "204");
229 }
230 
237 {
238  public:
240  : TestSuite("ipv6-list-routing", UNIT)
241  {
242  AddTestCase(new Ipv6ListRoutingPositiveTestCase(), TestCase::QUICK);
243  AddTestCase(new Ipv6ListRoutingNegativeTestCase(), TestCase::QUICK);
244  }
245 };
246 
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)
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.
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 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
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
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