A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-routing-test-suite.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "ns3/boolean.h"
6#include "ns3/bridge-helper.h"
7#include "ns3/config.h"
8#include "ns3/global-route-manager.h"
9#include "ns3/global-routing.h"
10#include "ns3/inet-socket-address.h"
11#include "ns3/internet-stack-helper.h"
12#include "ns3/ipv4-address-helper.h"
13#include "ns3/ipv4-global-routing-helper.h"
14#include "ns3/ipv4-interface.h"
15#include "ns3/ipv4-l3-protocol.h"
16#include "ns3/ipv4-packet-info-tag.h"
17#include "ns3/ipv4-routing-protocol.h"
18#include "ns3/ipv4-routing-table-entry.h"
19#include "ns3/ipv4-static-routing-helper.h"
20#include "ns3/ipv6-address-helper.h"
21#include "ns3/ipv6-global-routing-helper.h"
22#include "ns3/ipv6-packet-info-tag.h"
23#include "ns3/ipv6-route.h"
24#include "ns3/log.h"
25#include "ns3/neighbor-cache-helper.h"
26#include "ns3/node-container.h"
27#include "ns3/node.h"
28#include "ns3/packet.h"
29#include "ns3/pointer.h"
30#include "ns3/simple-channel.h"
31#include "ns3/simple-net-device-helper.h"
32#include "ns3/simple-net-device.h"
33#include "ns3/simulator.h"
34#include "ns3/socket-factory.h"
35#include "ns3/string.h"
36#include "ns3/test.h"
37#include "ns3/udp-socket-factory.h"
38#include "ns3/uinteger.h"
39
40#include <vector>
41using namespace ns3;
42
43NS_LOG_COMPONENT_DEFINE("GlobalRoutingTestSuite");
44
45// This test suite tests the operation of global routing on a few sample
46// networks to ensure that routes are built correctly
47//
48// Link test:
49// n0 <--------> n1 (point-to-point link)
50// 10.1.1.1 10.1.1.2
51// Expected routes:
52// n0: route to 0.0.0.0 gw 10.1.1.2
53// n1: route to 0.0.0.0 gw 10.1.1.1
54// Note: These default routes to 0.0.0.0 are generated by the extension
55// in the global route manager to install default routes via the
56// peer node on a point-to-point link, when the node is on a
57// stub link
58//
59// LAN test:
60// n0 <--------> n1 (broadcast link on subnet 10.1.1.0/24)
61// Expected routes:
62// n0: route to 10.1.1.0 gw 0.0.0.0
63// n1: route to 10.1.1.0 gw 0.0.0.0
64// Two link test:
65// n0 <--------> n1 <--------> n2 (point-to-point links)
66// 10.1.1.1 10.1.1.2/ 10.1.2.2
67// 10.1.2.1
68// Expected routes:
69// n0: route to 0.0.0.0 gw 10.1.1.2
70// n1: route to 10.1.1.1 gw 10.1.1.1
71// route to 10.1.2.2 gw 10.1.2.2
72// route to 10.1.1.0 gw 10.1.1.1
73// route to 10.1.2.0 gw 10.1.2.2
74// n2: route to 0.0.0.0 gw 10.1.2.1
75// Note: These default routes to 0.0.0.0 are generated by the extension
76// in the global route manager to install default routes via the
77// peer node on a point-to-point link, when the node is on a
78// stub link
79// Two LANs test:
80// n0 <--------> n1 <--------> n2 (broadcast links)
81// Expected routes:
82// n0: route to 10.1.1.0 gw 0.0.0.0
83// route to 0.0.0.0 gw 10.1.1.2
84// n1: route to 10.1.1.1 gw 10.1.1.1
85// route to 10.1.2.2 gw 10.1.2.2
86// route to 10.1.1.0 gw 10.1.1.1
87// route to 10.1.2.0 gw 10.1.2.2
88// n2: route to 0.0.0.0 gw 10.1.2.1
89// Bridge test:
90// n0 <--------> n1 <---> Bridge-n2 <---> n3 <-------> n4 (broadcast links)
91// 10.1.1.0/24 10.1.2.0/24 10.1.3.0/24
92// Expected routes:
93// n0: route to 10.1.1.0 gw 0.0.0.0
94// route to 10.1.2.0 gw 10.1.1.2
95// route to 10.1.3.0 gw 10.1.1.2
96// n1: route to 10.1.1.0 gw 0.0.0.0
97// route to 10.1.2.0 gw 0.0.0.0
98// route to 10.1.3.0 gw 10.1.2.2
99// n3: route to 10.1.1.0 gw 10.1.2.1
100// route to 10.1.2.0 gw 0.0.0.0
101// route to 10.1.3.0 gw 0.0.0.0
102// n4: route to 10.1.3.0 gw 0.0.0.0
103// route to 10.1.2.0 gw 10.1.3.1
104// route to 10.1.1.0 gw 10.1.3.1
105// Two Bridge test:
106// n0 <------> n1 <---> Bridge-n2 <---> Bridge-n3 <---> n4 (broadcast links)
107// 10.1.1.0/24 10.1.2.0/24
108// Expected routes:
109// n0: route to 10.1.1.0 gw 0.0.0.0
110// route to 10.1.2.0 gw 10.1.1.2
111// n4: route to 10.1.2.0 gw 0.0.0.0
112// route to 10.1.1.0 gw 10.1.2.1
113
114/**
115 * @ingroup internet-test
116 *
117 * @brief GlobalRouting Link test
118 */
119class LinkTest : public TestCase
120{
121 public:
122 void DoSetup() override;
123 void DoRun() override;
124 LinkTest();
125
126 private:
127 NodeContainer m_nodes; //!< Nodes used in the test.
128};
129
131 : TestCase("Global routing on point-to-point link")
132{
133}
134
135void
137{
138 m_nodes.Create(2);
140 SimpleNetDeviceHelper simpleHelper;
141 simpleHelper.SetNetDevicePointToPointMode(true);
142 NetDeviceContainer net = simpleHelper.Install(m_nodes, channel);
143
144 InternetStackHelper internet;
145 // By default, InternetStackHelper adds a static and global routing
146 // implementation. We just want the global for this test.
147 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
148 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
149 internet.SetRoutingHelper(ipv4RoutingHelper);
150 internet.SetRoutingHelper(ipv6RoutingHelper);
151 internet.Install(m_nodes);
152
154 ipv4.SetBase("10.1.1.0", "255.255.255.252");
155 Ipv4InterfaceContainer iv4 = ipv4.Assign(net);
156
158 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
159 Ipv6InterfaceContainer iv6 = ipv6.Assign(net);
160}
161
162void
164{
167
168 //----------Ipv4 Tests-------------------------
169 Ptr<Ipv4L3Protocol> ipv40 = m_nodes.Get(0)->GetObject<Ipv4L3Protocol>();
170 NS_TEST_ASSERT_MSG_NE(ipv40, nullptr, "Error-- no Ipv4 object");
171 Ptr<Ipv4L3Protocol> ipv41 = m_nodes.Get(1)->GetObject<Ipv4L3Protocol>();
172 NS_TEST_ASSERT_MSG_NE(ipv41, nullptr, "Error-- no Ipv4 object");
173 Ptr<Ipv4RoutingProtocol> routing0 = ipv40->GetRoutingProtocol();
174 Ptr<Ipv4GlobalRouting> globalRoutingV40 = routing0->GetObject<Ipv4GlobalRouting>();
175 NS_TEST_ASSERT_MSG_NE(globalRoutingV40, nullptr, "Error-- no Ipv4GlobalRouting object");
176 Ptr<Ipv4RoutingProtocol> routingV41 = ipv41->GetRoutingProtocol();
177 Ptr<Ipv4GlobalRouting> globalRoutingV41 = routingV41->GetObject<Ipv4GlobalRouting>();
178 NS_TEST_ASSERT_MSG_NE(globalRoutingV41, nullptr, "Error-- no Ipv4GlobalRouting object");
179
180 // Test that the right number of routes found
181 uint32_t nRoutesV40 = globalRoutingV40->GetNRoutes();
182 NS_LOG_DEBUG("LinkTest nRoutes0 " << nRoutesV40);
183 NS_TEST_ASSERT_MSG_EQ(nRoutesV40, 1, "Error-- not one route");
184 Ipv4RoutingTableEntry* routeV4 = globalRoutingV40->GetRoute(0);
185 NS_LOG_DEBUG("entry dest " << routeV4->GetDest() << " gw " << routeV4->GetGateway());
186 NS_TEST_ASSERT_MSG_EQ(routeV4->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
187 NS_TEST_ASSERT_MSG_EQ(routeV4->GetGateway(), Ipv4Address("10.1.1.2"), "Error-- wrong gateway");
188
189 // Test that the right number of routes found
190 uint32_t nRoutesV41 = globalRoutingV41->GetNRoutes();
191 NS_TEST_ASSERT_MSG_EQ(nRoutesV41, 1, "Error-- not one route");
192 NS_LOG_DEBUG("LinkTest nRoutes1 " << nRoutesV41);
193 routeV4 = globalRoutingV41->GetRoute(0);
194 NS_LOG_DEBUG("entry dest " << routeV4->GetDest() << " gw " << routeV4->GetGateway());
195 NS_TEST_ASSERT_MSG_EQ(routeV4->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
196 NS_TEST_ASSERT_MSG_EQ(routeV4->GetGateway(), Ipv4Address("10.1.1.1"), "Error-- wrong gateway");
197
198 //-------------Ipv6 Tests---------------------
199 Ptr<Ipv6L3Protocol> ipv60 = m_nodes.Get(0)->GetObject<Ipv6L3Protocol>();
200 NS_TEST_ASSERT_MSG_NE(ipv60, nullptr, "Error-- no Ipv6 object");
201 Ptr<Ipv6L3Protocol> ipv61 = m_nodes.Get(1)->GetObject<Ipv6L3Protocol>();
202 NS_TEST_ASSERT_MSG_NE(ipv61, nullptr, "Error-- no Ipv6 object");
203 Ptr<Ipv6RoutingProtocol> routingV60 = ipv60->GetRoutingProtocol();
204 Ptr<Ipv6GlobalRouting> globalRoutingV60 = routingV60->GetObject<Ipv6GlobalRouting>();
205 NS_TEST_ASSERT_MSG_NE(globalRoutingV60, nullptr, "Error-- no Ipv6GlobalRouting object");
206 Ptr<Ipv6RoutingProtocol> routingV61 = ipv61->GetRoutingProtocol();
207 Ptr<Ipv6GlobalRouting> globalRoutingV61 = routingV61->GetObject<Ipv6GlobalRouting>();
208 NS_TEST_ASSERT_MSG_NE(globalRoutingV61, nullptr, "Error-- no Ipv6GlobalRouting object");
209
210 // Test that the right number of routes found
211 uint32_t nRoutesV60 = globalRoutingV60->GetNRoutes();
212 NS_LOG_DEBUG("LinkTest nRoutes0 " << nRoutesV60);
213 NS_TEST_ASSERT_MSG_EQ(nRoutesV60, 1, "Error-- not one route");
214 Ipv6RoutingTableEntry* routeV6 = globalRoutingV60->GetRoute(0);
215 NS_LOG_DEBUG("entry dest " << routeV6->GetDest() << " gw " << routeV6->GetGateway());
216 NS_TEST_ASSERT_MSG_EQ(routeV6->GetDest(), Ipv6Address("::"), "Error-- wrong destination");
219 "Error-- wrong destination mask");
221 Ipv6Address("fe80::200:ff:fe00:2"),
222 "Error-- wrong gateway");
223
224 // Test that the right number of routes found
225 uint32_t nRoutesV61 = globalRoutingV61->GetNRoutes();
226 NS_TEST_ASSERT_MSG_EQ(nRoutesV61, 1, "Error-- not one route");
227 NS_LOG_DEBUG("LinkTest nRoutes1 " << nRoutesV61);
228 routeV6 = globalRoutingV61->GetRoute(0);
229 NS_LOG_DEBUG("entry dest " << routeV6->GetDest() << " gw " << routeV6->GetGateway());
230 NS_TEST_ASSERT_MSG_EQ(routeV6->GetDest(), Ipv6Address("::"), "Error-- wrong destination");
233 "Error-- wrong destination mask");
235 Ipv6Address("fe80::200:ff:fe00:1"),
236 "Error-- wrong gateway");
237
241}
242
243/**
244 * @ingroup internet-test
245 *
246 * @brief GlobalRouting LAN test
247 */
248class LanTest : public TestCase
249{
250 public:
251 void DoSetup() override;
252 void DoRun() override;
253 LanTest();
254
255 private:
256 NodeContainer m_nodes; //!< Nodes used in the test.
257};
258
260 : TestCase("Global routing on broadcast link")
261{
262}
263
264void
266{
267 m_nodes.Create(2);
268
270 SimpleNetDeviceHelper simpleHelper;
271 NetDeviceContainer net = simpleHelper.Install(m_nodes, channel);
272
273 InternetStackHelper internet;
274 // By default, InternetStackHelper adds a static and global routing
275 // implementation. We just want the global for this test.
276 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
277 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
278 internet.SetRoutingHelper(ipv4RoutingHelper);
279 internet.SetRoutingHelper(ipv6RoutingHelper);
280 internet.Install(m_nodes);
281
283 ipv4.SetBase("10.1.1.0", "255.255.255.0");
284 Ipv4InterfaceContainer i = ipv4.Assign(net);
285
287 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
288 Ipv6InterfaceContainer iv6 = ipv6.Assign(net);
289}
290
291void
293{
296
297 //----------Ipv4 Tests-------------------------------
298 Ptr<Ipv4L3Protocol> ipv40 = m_nodes.Get(0)->GetObject<Ipv4L3Protocol>();
299 NS_TEST_ASSERT_MSG_NE(ipv40, nullptr, "Error-- no Ipv4 object");
300 Ptr<Ipv4L3Protocol> ipv41 = m_nodes.Get(1)->GetObject<Ipv4L3Protocol>();
301 NS_TEST_ASSERT_MSG_NE(ipv41, nullptr, "Error-- no Ipv4 object");
302 Ptr<Ipv4RoutingProtocol> routingv40 = ipv40->GetRoutingProtocol();
303 Ptr<Ipv4GlobalRouting> globalRoutingv40 = routingv40->GetObject<Ipv4GlobalRouting>();
304 NS_TEST_ASSERT_MSG_NE(globalRoutingv40, nullptr, "Error-- no Ipv4GlobalRouting object");
305 Ptr<Ipv4RoutingProtocol> routingv41 = ipv41->GetRoutingProtocol();
306 Ptr<Ipv4GlobalRouting> globalRoutingv41 = routingv41->GetObject<Ipv4GlobalRouting>();
307 NS_TEST_ASSERT_MSG_NE(globalRoutingv41, nullptr, "Error-- no Ipv4GlobalRouting object");
308
309 // Test that the right number of routes found
310 uint32_t nRoutesv40 = globalRoutingv40->GetNRoutes();
311 NS_LOG_DEBUG("LanTest nRoutes0 " << nRoutesv40);
312 NS_TEST_ASSERT_MSG_EQ(nRoutesv40, 1, "Error-- more than one entry");
313 for (uint32_t i = 0; i < globalRoutingv40->GetNRoutes(); i++)
314 {
315 Ipv4RoutingTableEntry* routev4 = globalRoutingv40->GetRoute(i);
316 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
317 }
318
319 // Test that the right number of routes found
320 uint32_t nRoutesv41 = globalRoutingv41->GetNRoutes();
321 NS_LOG_DEBUG("LanTest nRoutes1 " << nRoutesv41);
322 NS_TEST_ASSERT_MSG_EQ(nRoutesv41, 1, "Error-- more than one entry");
323 for (uint32_t i = 0; i < globalRoutingv40->GetNRoutes(); i++)
324 {
325 Ipv4RoutingTableEntry* routev4 = globalRoutingv41->GetRoute(i);
326 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
327 }
328
329 //-------------Ipv6 Tests----------------------
330 Ptr<Ipv6L3Protocol> ipv60 = m_nodes.Get(0)->GetObject<Ipv6L3Protocol>();
331 NS_TEST_ASSERT_MSG_NE(ipv60, nullptr, "Error-- no Ipv6 object");
332 Ptr<Ipv6L3Protocol> ipv61 = m_nodes.Get(1)->GetObject<Ipv6L3Protocol>();
333 NS_TEST_ASSERT_MSG_NE(ipv61, nullptr, "Error-- no Ipv6 object");
334 Ptr<Ipv6RoutingProtocol> routingv60 = ipv60->GetRoutingProtocol();
335 Ptr<Ipv6GlobalRouting> globalRoutingv60 = routingv60->GetObject<Ipv6GlobalRouting>();
336 NS_TEST_ASSERT_MSG_NE(globalRoutingv60, nullptr, "Error-- no Ipv6GlobalRouting object");
337 Ptr<Ipv6RoutingProtocol> routingv61 = ipv61->GetRoutingProtocol();
338 Ptr<Ipv6GlobalRouting> globalRoutingv61 = routingv61->GetObject<Ipv6GlobalRouting>();
339 NS_TEST_ASSERT_MSG_NE(globalRoutingv61, nullptr, "Error-- no Ipv6GlobalRouting object");
340
341 // Test that the right number of routes found
342 uint32_t nRoutesv60 = globalRoutingv60->GetNRoutes();
343 NS_LOG_DEBUG("LanTest nRoutes0 " << nRoutesv60);
344 NS_TEST_ASSERT_MSG_EQ(nRoutesv60, 1, "Error-- more than one entry");
345 for (uint32_t i = 0; i < globalRoutingv60->GetNRoutes(); i++)
346 {
347 Ipv6RoutingTableEntry* routev6 = globalRoutingv60->GetRoute(i);
348 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << routev6->GetDestNetworkPrefix()
349 << " gw " << routev6->GetGateway());
350 }
351
352 // Test that the right number of routes found
353 uint32_t nRoutesv61 = globalRoutingv61->GetNRoutes();
354 NS_LOG_DEBUG("LanTest nRoutes1 " << nRoutesv61);
355 NS_TEST_ASSERT_MSG_EQ(nRoutesv61, 1, "Error-- more than one entry");
356 for (uint32_t i = 0; i < globalRoutingv60->GetNRoutes(); i++)
357 {
358 Ipv6RoutingTableEntry* routev6 = globalRoutingv61->GetRoute(i);
359 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << routev6->GetDestNetworkPrefix()
360 << " gw " << routev6->GetGateway());
361 }
362
365}
366
367/**
368 * @ingroup internet-test
369 *
370 * @brief GlobalRouting Two Link test
371 */
372class TwoLinkTest : public TestCase
373{
374 public:
375 void DoSetup() override;
376 void DoRun() override;
377 TwoLinkTest();
378
379 private:
380 NodeContainer m_nodes; //!< Nodes used in the test.
381};
382
384 : TestCase("Global routing across two hops (point-to-point links)")
385{
386}
387
388void
390{
391 m_nodes.Create(3);
392
394 SimpleNetDeviceHelper simpleHelper;
395 simpleHelper.SetNetDevicePointToPointMode(true);
396 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
397 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
398
400 SimpleNetDeviceHelper simpleHelper2;
401 simpleHelper2.SetNetDevicePointToPointMode(true);
402 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
403 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
404
405 InternetStackHelper internet;
406 // By default, InternetStackHelper adds a static and global routing
407 // implementation. We just want the global for this test.
408 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
409 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
410 internet.SetRoutingHelper(ipv4RoutingHelper);
411 internet.SetRoutingHelper(ipv6RoutingHelper);
412
413 internet.Install(m_nodes);
414
416 ipv4.SetBase("10.1.1.0", "255.255.255.252");
417 Ipv4InterfaceContainer i = ipv4.Assign(net);
418 ipv4.SetBase("10.1.2.0", "255.255.255.252");
419 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
420
422 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
423 ipv6.Assign(net);
424 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
425 ipv6.Assign(net2);
426}
427
428void
430{
433
434 //-----Ipv4 Tests-----------------
435 Ptr<Ipv4L3Protocol> ipv40 = m_nodes.Get(0)->GetObject<Ipv4L3Protocol>();
436 NS_TEST_ASSERT_MSG_NE(ipv40, nullptr, "Error-- no Ipv4 object");
437 Ptr<Ipv4L3Protocol> ipv41 = m_nodes.Get(1)->GetObject<Ipv4L3Protocol>();
438 NS_TEST_ASSERT_MSG_NE(ipv41, nullptr, "Error-- no Ipv4 object");
439 Ptr<Ipv4L3Protocol> ipv42 = m_nodes.Get(2)->GetObject<Ipv4L3Protocol>();
440 NS_TEST_ASSERT_MSG_NE(ipv42, nullptr, "Error-- no Ipv4 object");
441 Ptr<Ipv4RoutingProtocol> routingv40 = ipv40->GetRoutingProtocol();
442 Ptr<Ipv4GlobalRouting> globalRoutingv40 = routingv40->GetObject<Ipv4GlobalRouting>();
443 NS_TEST_ASSERT_MSG_NE(globalRoutingv40, nullptr, "Error-- no Ipv4GlobalRouting object");
444 Ptr<Ipv4RoutingProtocol> routingv41 = ipv41->GetRoutingProtocol();
445 Ptr<Ipv4GlobalRouting> globalRoutingv41 = routingv41->GetObject<Ipv4GlobalRouting>();
446 NS_TEST_ASSERT_MSG_NE(globalRoutingv41, nullptr, "Error-- no Ipv4GlobalRouting object");
447 Ptr<Ipv4RoutingProtocol> routingv42 = ipv42->GetRoutingProtocol();
448 Ptr<Ipv4GlobalRouting> globalRoutingv42 = routingv42->GetObject<Ipv4GlobalRouting>();
449 NS_TEST_ASSERT_MSG_NE(globalRoutingv42, nullptr, "Error-- no Ipv4GlobalRouting object");
450
451 // node n0
452 // Test that the right number of routes found
453 uint32_t nRoutesv40 = globalRoutingv40->GetNRoutes();
454 NS_LOG_DEBUG("TwoLinkTest nRoutes0 " << nRoutesv40);
455 NS_TEST_ASSERT_MSG_EQ(nRoutesv40, 1, "Error-- wrong number of links");
456
457 Ipv4RoutingTableEntry* routev4 = globalRoutingv40->GetRoute(0);
458 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
459 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
460 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.1.2"), "Error-- wrong gateway");
461
462 // node n1
463 // Test that the right number of routes found
464 uint32_t nRoutesv41 = globalRoutingv41->GetNRoutes();
465 NS_LOG_DEBUG("TwoLinkTest nRoutes1 " << nRoutesv41);
466 NS_TEST_ASSERT_MSG_EQ(nRoutesv41, 4, "Error-- not one route");
467
468 routev4 = globalRoutingv41->GetRoute(0);
469 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev4->GetDest() << " gw "
470 << routev4->GetGateway());
471 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.1.1"), "Error-- wrong destination");
472 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.1.1"), "Error-- wrong gateway");
473 routev4 = globalRoutingv41->GetRoute(1);
474 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev4->GetDest() << " gw "
475 << routev4->GetGateway());
476 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.2.2"), "Error-- wrong destination");
477 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.2.2"), "Error-- wrong gateway");
478 routev4 = globalRoutingv41->GetRoute(2);
479 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev4->GetDest() << " gw "
480 << routev4->GetGateway());
481 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.1.0"), "Error-- wrong destination");
482 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.1.1"), "Error-- wrong gateway");
483 routev4 = globalRoutingv41->GetRoute(3);
484 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev4->GetDest() << " gw "
485 << routev4->GetGateway());
486 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.2.0"), "Error-- wrong destination");
487 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.2.2"), "Error-- wrong gateway");
488
489 // node n2
490 // Test that the right number of routes found
491 uint32_t nRoutesv42 = globalRoutingv42->GetNRoutes();
492 NS_LOG_DEBUG("TwoLinkTest nRoutes2 " << nRoutesv42);
493 NS_TEST_ASSERT_MSG_EQ(nRoutesv42, 1, "Error-- wrong number of links");
494
495 routev4 = globalRoutingv42->GetRoute(0);
496 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
497 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
498 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.2.1"), "Error-- wrong gateway");
499
500 //--------------Ipv6 Tests-------------
501 Ptr<Ipv6L3Protocol> ipv60 = m_nodes.Get(0)->GetObject<Ipv6L3Protocol>();
502 NS_TEST_ASSERT_MSG_NE(ipv60, nullptr, "Error-- no Ipv6 object");
503 Ptr<Ipv6L3Protocol> ipv61 = m_nodes.Get(1)->GetObject<Ipv6L3Protocol>();
504 NS_TEST_ASSERT_MSG_NE(ipv61, nullptr, "Error-- no Ipv6 object");
505 Ptr<Ipv6L3Protocol> ipv62 = m_nodes.Get(2)->GetObject<Ipv6L3Protocol>();
506 NS_TEST_ASSERT_MSG_NE(ipv62, nullptr, "Error-- no Ipv6 object");
507 Ptr<Ipv6RoutingProtocol> routingv60 = ipv60->GetRoutingProtocol();
508 Ptr<Ipv6GlobalRouting> globalRoutingv60 = routingv60->GetObject<Ipv6GlobalRouting>();
509 NS_TEST_ASSERT_MSG_NE(globalRoutingv60, nullptr, "Error-- no Ipv6GlobalRouting object");
510 Ptr<Ipv6RoutingProtocol> routingv61 = ipv61->GetRoutingProtocol();
511 Ptr<Ipv6GlobalRouting> globalRoutingv61 = routingv61->GetObject<Ipv6GlobalRouting>();
512 NS_TEST_ASSERT_MSG_NE(globalRoutingv61, nullptr, "Error-- no Ipv6GlobalRouting object");
513 Ptr<Ipv6RoutingProtocol> routingv62 = ipv62->GetRoutingProtocol();
514 Ptr<Ipv6GlobalRouting> globalRoutingv62 = routingv62->GetObject<Ipv6GlobalRouting>();
515 NS_TEST_ASSERT_MSG_NE(globalRoutingv62, nullptr, "Error-- no Ipv4GlobalRouting object");
516
517 // node n0
518 // Test that the right number of routes found
519 uint32_t nRoutesv60 = globalRoutingv60->GetNRoutes();
520 NS_LOG_DEBUG("TwoLinkTest nRoutes0 " << nRoutesv60);
521 NS_TEST_ASSERT_MSG_EQ(nRoutesv60, 1, "Error-- wrong number of links");
522
523 Ipv6RoutingTableEntry* routev6 = globalRoutingv60->GetRoute(0);
524 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
525 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("::"), "Error-- wrong destination");
528 "Error-- wrong destination mask");
530 Ipv6Address("fe80::200:ff:fe00:2"),
531 "Error-- wrong gateway");
532
533 // node n1
534 // Test that the right number of routes found
535 uint32_t nRoutesv61 = globalRoutingv61->GetNRoutes();
536 NS_LOG_DEBUG("TwoLinkTest nRoutes1 " << nRoutesv61);
537 NS_TEST_ASSERT_MSG_EQ(nRoutesv61, 4, "Error-- not one route");
538
539 routev6 = globalRoutingv61->GetRoute(0);
540 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev6->GetDest() << " gw "
541 << routev6->GetGateway());
543 Ipv6Address("2001::200:ff:fe00:1"),
544 "Error-- wrong destination");
546 Ipv6Prefix(128),
547 "Error-- wrong destination mask");
549 Ipv6Address("fe80::200:ff:fe00:1"),
550 "Error-- wrong gateway");
551
552 routev6 = globalRoutingv61->GetRoute(1);
553 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev6->GetDest() << " gw "
554 << routev6->GetGateway());
556 Ipv6Address("2001:1::200:ff:fe00:4"),
557 "Error-- wrong destination");
559 Ipv6Prefix(128),
560 "Error-- wrong destination mask");
562 Ipv6Address("fe80::200:ff:fe00:4"),
563 "Error-- wrong gateway");
564
565 routev6 = globalRoutingv61->GetRoute(2);
566 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev6->GetDest() << " gw "
567 << routev6->GetGateway());
568 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("2001::"), "Error-- wrong destination");
570 Ipv6Prefix(64),
571 "Error-- wrong destination mask");
573 Ipv6Address("fe80::200:ff:fe00:1"),
574 "Error-- wrong gateway");
575
576 routev6 = globalRoutingv61->GetRoute(3);
577 NS_LOG_DEBUG("TwoLinkTest entry dest " << routev6->GetDest() << " gw "
578 << routev6->GetGateway());
579 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("2001:1::"), "Error-- wrong destination");
581 Ipv6Prefix(64),
582 "Error-- wrong destination mask");
584 Ipv6Address("fe80::200:ff:fe00:4"),
585 "Error-- wrong gateway");
586
587 // node n2
588 // Test that the right number of routes found
589 uint32_t nRoutesv62 = globalRoutingv62->GetNRoutes();
590 NS_LOG_DEBUG("TwoLinkTest nRoutes2 " << nRoutesv62);
591 NS_TEST_ASSERT_MSG_EQ(nRoutesv62, 1, "Error-- wrong number of links");
592
593 routev6 = globalRoutingv62->GetRoute(0);
594 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
595 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("::"), "Error-- wrong destination");
598 "Error-- wrong destination mask");
600 Ipv6Address("fe80::200:ff:fe00:3"),
601 "Error-- wrong gateway");
602
605}
606
607/**
608 * @ingroup internet-test
609 *
610 * @brief GlobalRouting Two LAN test
611 */
612class TwoLanTest : public TestCase
613{
614 public:
615 void DoSetup() override;
616 void DoRun() override;
617 TwoLanTest();
618
619 private:
620 NodeContainer m_nodes; //!< Nodes used in the test.
621};
622
624 : TestCase("Global routing across two hops (broadcast links)")
625{
626}
627
628void
630{
631 m_nodes.Create(3);
632
634 SimpleNetDeviceHelper simpleHelper;
635 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
636 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
637
639 SimpleNetDeviceHelper simpleHelper2;
640 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
641 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
642
643 InternetStackHelper internet;
644 // By default, InternetStackHelper adds a static and global routing
645 // implementation. We just want the global for this test.
646 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
647 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
648 internet.SetRoutingHelper(ipv4RoutingHelper);
649 internet.SetRoutingHelper(ipv6RoutingHelper);
650 internet.Install(m_nodes);
651
653 ipv4.SetBase("10.1.1.0", "255.255.255.0");
654 Ipv4InterfaceContainer i = ipv4.Assign(net);
655 ipv4.SetBase("10.1.2.0", "255.255.255.0");
656 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
657
659 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
660 ipv6.Assign(net);
661 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
662 ipv6.Assign(net2);
663}
664
665void
667{
670
671 //----------Ipv4 Tests------------
672 Ptr<Ipv4L3Protocol> ipv40 = m_nodes.Get(0)->GetObject<Ipv4L3Protocol>();
673 NS_TEST_ASSERT_MSG_NE(ipv40, nullptr, "Error-- no Ipv4 object");
674 Ptr<Ipv4L3Protocol> ipv41 = m_nodes.Get(1)->GetObject<Ipv4L3Protocol>();
675 NS_TEST_ASSERT_MSG_NE(ipv41, nullptr, "Error-- no Ipv4 object");
676 Ptr<Ipv4L3Protocol> ipv42 = m_nodes.Get(2)->GetObject<Ipv4L3Protocol>();
677 NS_TEST_ASSERT_MSG_NE(ipv42, nullptr, "Error-- no Ipv4 object");
678 Ptr<Ipv4RoutingProtocol> routingv40 = ipv40->GetRoutingProtocol();
679 Ptr<Ipv4GlobalRouting> globalRoutingv40 = routingv40->GetObject<Ipv4GlobalRouting>();
680 NS_TEST_ASSERT_MSG_NE(globalRoutingv40, nullptr, "Error-- no Ipv4GlobalRouting object");
681 Ptr<Ipv4RoutingProtocol> routingv41 = ipv41->GetRoutingProtocol();
682 Ptr<Ipv4GlobalRouting> globalRoutingv41 = routingv41->GetObject<Ipv4GlobalRouting>();
683 NS_TEST_ASSERT_MSG_NE(globalRoutingv41, nullptr, "Error-- no Ipv4GlobalRouting object");
684 Ptr<Ipv4RoutingProtocol> routingv42 = ipv42->GetRoutingProtocol();
685 Ptr<Ipv4GlobalRouting> globalRoutingv42 = routingv42->GetObject<Ipv4GlobalRouting>();
686 NS_TEST_ASSERT_MSG_NE(globalRoutingv42, nullptr, "Error-- no Ipv4GlobalRouting object");
687
688 // Test that the right number of routes found
689 uint32_t nRoutesv40 = globalRoutingv40->GetNRoutes();
690 NS_LOG_DEBUG("TwoLanTest nRoutes0 " << nRoutesv40);
691 NS_TEST_ASSERT_MSG_EQ(nRoutesv40, 2, "Error-- not two entries");
692 Ipv4RoutingTableEntry* routev4 = globalRoutingv40->GetRoute(0);
693 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
694 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.1.0"), "Error-- wrong destination");
695 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("0.0.0.0"), "Error-- wrong gateway");
696 routev4 = globalRoutingv40->GetRoute(1);
697 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
698 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.2.0"), "Error-- wrong destination");
699 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("10.1.1.2"), "Error-- wrong gateway");
700
701 // Test that the right number of routes found
702 uint32_t nRoutesv41 = globalRoutingv41->GetNRoutes();
703 NS_LOG_DEBUG("TwoLanTest nRoutes1 " << nRoutesv41);
704 NS_TEST_ASSERT_MSG_EQ(nRoutesv41, 2, "Error-- not two entries");
705 routev4 = globalRoutingv41->GetRoute(0);
706 NS_LOG_DEBUG("TwoLanTest entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
707 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.1.0"), "Error-- wrong destination");
708 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("0.0.0.0"), "Error-- wrong gateway");
709 routev4 = globalRoutingv41->GetRoute(1);
710 NS_LOG_DEBUG("TwoLanTest entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
711 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(), Ipv4Address("10.1.2.0"), "Error-- wrong destination");
712 NS_TEST_ASSERT_MSG_EQ(routev4->GetGateway(), Ipv4Address("0.0.0.0"), "Error-- wrong gateway");
713
714 //-------------Ipv6 Tests------------
715 Ptr<Ipv6L3Protocol> ipv60 = m_nodes.Get(0)->GetObject<Ipv6L3Protocol>();
716 NS_TEST_ASSERT_MSG_NE(ipv60, nullptr, "Error-- no Ipv4 object");
717 Ptr<Ipv6L3Protocol> ipv61 = m_nodes.Get(1)->GetObject<Ipv6L3Protocol>();
718 NS_TEST_ASSERT_MSG_NE(ipv61, nullptr, "Error-- no Ipv4 object");
719 Ptr<Ipv6L3Protocol> ipv62 = m_nodes.Get(2)->GetObject<Ipv6L3Protocol>();
720 NS_TEST_ASSERT_MSG_NE(ipv62, nullptr, "Error-- no Ipv4 object");
721 Ptr<Ipv6RoutingProtocol> routingv60 = ipv60->GetRoutingProtocol();
722 Ptr<Ipv6GlobalRouting> globalRoutingv60 = routingv60->GetObject<Ipv6GlobalRouting>();
723 NS_TEST_ASSERT_MSG_NE(globalRoutingv60, nullptr, "Error-- no Ipv4GlobalRouting object");
724 Ptr<Ipv6RoutingProtocol> routingv61 = ipv61->GetRoutingProtocol();
725 Ptr<Ipv6GlobalRouting> globalRoutingv61 = routingv61->GetObject<Ipv6GlobalRouting>();
726 NS_TEST_ASSERT_MSG_NE(globalRoutingv61, nullptr, "Error-- no Ipv4GlobalRouting object");
727 Ptr<Ipv6RoutingProtocol> routingv62 = ipv62->GetRoutingProtocol();
728 Ptr<Ipv6GlobalRouting> globalRoutingv62 = routingv62->GetObject<Ipv6GlobalRouting>();
729 NS_TEST_ASSERT_MSG_NE(globalRoutingv62, nullptr, "Error-- no Ipv4GlobalRouting object");
730
731 // Test that the right number of routes found
732 uint32_t nRoutesv60 = globalRoutingv60->GetNRoutes();
733 NS_LOG_DEBUG("TwoLanTest nRoutes0 " << nRoutesv60);
734 NS_TEST_ASSERT_MSG_EQ(nRoutesv60, 2, "Error-- not two entries");
735
736 Ipv6RoutingTableEntry* routev6 = globalRoutingv60->GetRoute(0);
737 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
738 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("2001::"), "Error-- wrong destination");
740 Ipv6Prefix(64),
741 "Error-- wrong destination mask");
742 NS_TEST_ASSERT_MSG_EQ(routev6->GetGateway(), Ipv6Address("::"), "Error-- wrong gateway");
743
744 routev6 = globalRoutingv60->GetRoute(1);
745 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
746 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("2001:1::"), "Error-- wrong destination");
748 Ipv6Prefix(64),
749 "Error-- wrong destination mask");
751 Ipv6Address("fe80::200:ff:fe00:2"),
752 "Error-- wrong gateway");
753
754 // Test that the right number of routes found
755 uint32_t nRoutesv61 = globalRoutingv61->GetNRoutes();
756 NS_LOG_DEBUG("TwoLanTest nRoutes1 " << nRoutesv61);
757 NS_TEST_ASSERT_MSG_EQ(nRoutesv61, 2, "Error-- not two entries");
758
759 routev6 = globalRoutingv61->GetRoute(0);
760 NS_LOG_DEBUG("TwoLanTest entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
761 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("2001::"), "Error-- wrong destination");
763 Ipv6Prefix(64),
764 "Error-- wrong destination mask");
765 NS_TEST_ASSERT_MSG_EQ(routev6->GetGateway(), Ipv6Address("::"), "Error-- wrong gateway");
766
767 routev6 = globalRoutingv61->GetRoute(1);
768 NS_LOG_DEBUG("TwoLanTest entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
769 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(), Ipv6Address("2001:1::"), "Error-- wrong destination");
771 Ipv6Prefix(64),
772 "Error-- wrong destination mask");
773 NS_TEST_ASSERT_MSG_EQ(routev6->GetGateway(), Ipv6Address("::"), "Error-- wrong gateway");
774
777}
778
779/**
780 * @ingroup internet-test
781 *
782 * @brief GlobalRouting Bridge test
783 */
784class BridgeTest : public TestCase
785{
786 public:
787 void DoSetup() override;
788 void DoRun() override;
789 BridgeTest();
790
791 private:
792 NodeContainer m_nodes; //!< Nodes used in the test.
793};
794
796 : TestCase("Global routing across bridging topology (bug 2102)")
797{
798}
799
800void
802{
803 m_nodes.Create(5);
804
805 // connect node0 to node1
807 SimpleNetDeviceHelper simpleHelper;
808 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
809 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
810
811 NetDeviceContainer bridgeFacingDevices;
812 NetDeviceContainer switchDevices;
813
814 // connect node1 to node2 (switch)
816 SimpleNetDeviceHelper simpleHelper2;
817 NetDeviceContainer net2 = simpleHelper2.Install(m_nodes.Get(1), channel2);
818 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
819 bridgeFacingDevices.Add(net2.Get(0));
820 switchDevices.Add(net2.Get(1));
821
822 // connect node2 (switch) to node3
824 SimpleNetDeviceHelper simpleHelper3;
825 NetDeviceContainer net3 = simpleHelper3.Install(m_nodes.Get(2), channel3);
826 net3.Add(simpleHelper3.Install(m_nodes.Get(3), channel3));
827 bridgeFacingDevices.Add(net3.Get(1));
828 switchDevices.Add(net3.Get(0));
829
830 // connect node3 to node4
832 SimpleNetDeviceHelper simpleHelper4;
833 NetDeviceContainer net4 = simpleHelper4.Install(m_nodes.Get(3), channel4);
834 net4.Add(simpleHelper4.Install(m_nodes.Get(4), channel4));
835
836 Ptr<Node> switchNode = m_nodes.Get(2);
837 BridgeHelper bridge;
838 bridge.Install(switchNode, switchDevices);
839
840 InternetStackHelper internet;
841 // By default, InternetStackHelper adds a static and global routing
842 // implementation. We just want the global for this test.
843 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
844 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
845 internet.SetRoutingHelper(ipv4RoutingHelper);
846 internet.SetRoutingHelper(ipv6RoutingHelper);
847
848 internet.Install(m_nodes.Get(0));
849 internet.Install(m_nodes.Get(1));
850 // m_nodes.Get (2) is bridge node
851 internet.Install(m_nodes.Get(3));
852 internet.Install(m_nodes.Get(4));
853
854 Ipv4AddressHelper address;
855 address.SetBase("10.1.1.0", "255.255.255.0");
856 address.Assign(net);
857
858 address.SetBase("10.1.2.0", "255.255.255.0");
859 address.Assign(bridgeFacingDevices);
860
861 address.SetBase("10.1.3.0", "255.255.255.0");
862 address.Assign(net4);
863
865 ipv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
866 ipv6.Assign(net);
867 ipv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
868 ipv6.Assign(bridgeFacingDevices);
869 ipv6.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
870 ipv6.Assign(net4);
871}
872
873void
875{
878
879 //------------Ipv4 Tests--------------------
880 Ptr<Ipv4L3Protocol> ipv40 = m_nodes.Get(0)->GetObject<Ipv4L3Protocol>();
881 NS_TEST_ASSERT_MSG_NE(ipv40, nullptr, "Error-- no Ipv4 object");
882 Ptr<Ipv4RoutingProtocol> routingv40 = ipv40->GetRoutingProtocol();
883 NS_TEST_ASSERT_MSG_NE(routingv40, nullptr, "Error-- no Ipv4 routing protocol object");
884 Ptr<Ipv4GlobalRouting> globalRoutingv40 = routingv40->GetObject<Ipv4GlobalRouting>();
885 NS_TEST_ASSERT_MSG_NE(globalRoutingv40, nullptr, "Error-- no Ipv4GlobalRouting object");
886
887 Ptr<Ipv4L3Protocol> ipv41 = m_nodes.Get(1)->GetObject<Ipv4L3Protocol>();
888 NS_TEST_ASSERT_MSG_NE(ipv41, nullptr, "Error-- no Ipv4 object");
889 Ptr<Ipv4RoutingProtocol> routingv41 = ipv41->GetRoutingProtocol();
890 NS_TEST_ASSERT_MSG_NE(routingv41, nullptr, "Error-- no Ipv4 routing protocol object");
891 Ptr<Ipv4GlobalRouting> globalRoutingv41 = routingv41->GetObject<Ipv4GlobalRouting>();
892 NS_TEST_ASSERT_MSG_NE(globalRoutingv41, nullptr, "Error-- no Ipv4GlobalRouting object");
893
894 // Skip to n4
895 Ptr<Ipv4L3Protocol> ipv44 = m_nodes.Get(4)->GetObject<Ipv4L3Protocol>();
896 NS_TEST_ASSERT_MSG_NE(ipv44, nullptr, "Error-- no Ipv4 object");
897 Ptr<Ipv4RoutingProtocol> routingv44 = ipv44->GetRoutingProtocol();
898 NS_TEST_ASSERT_MSG_NE(routingv44, nullptr, "Error-- no Ipv4 routing protocol object");
899 Ptr<Ipv4GlobalRouting> globalRoutingv44 = routingv44->GetObject<Ipv4GlobalRouting>();
900 NS_TEST_ASSERT_MSG_NE(globalRoutingv44, nullptr, "Error-- no Ipv4GlobalRouting object");
901
902 Ipv4RoutingTableEntry* routev4 = nullptr;
903 // n0
904 // Test that the right number of routes found
905 uint32_t nRoutesv40 = globalRoutingv40->GetNRoutes();
906 NS_LOG_DEBUG("BridgeTest nRoutes0 " << nRoutesv40);
907 NS_TEST_ASSERT_MSG_EQ(nRoutesv40, 3, "Error-- not three entries");
908 for (uint32_t i = 0; i < globalRoutingv40->GetNRoutes(); i++)
909 {
910 routev4 = globalRoutingv40->GetRoute(i);
911 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
912 }
913 // Spot check the last route
914 if (routev4)
915 {
917 Ipv4Address("10.1.3.0"),
918 "Error-- wrong destination");
920 Ipv4Address("10.1.1.2"),
921 "Error-- wrong gateway");
922 }
923
924 // n1
925 // Test that the right number of routes found
926 routev4 = nullptr;
927 uint32_t nRoutesv41 = globalRoutingv41->GetNRoutes();
928 NS_LOG_DEBUG("BridgeTest nRoutes1 " << nRoutesv41);
929 NS_TEST_ASSERT_MSG_EQ(nRoutesv41, 3, "Error-- not three entries");
930 for (uint32_t i = 0; i < globalRoutingv41->GetNRoutes(); i++)
931 {
932 routev4 = globalRoutingv41->GetRoute(i);
933 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
934 }
935 // Spot check the last route
936 if (routev4)
937 {
939 Ipv4Address("10.1.3.0"),
940 "Error-- wrong destination");
942 Ipv4Address("10.1.2.2"),
943 "Error-- wrong gateway");
944 }
945
946 // skip n2 and n3, just verify n4
947 NS_LOG_DEBUG("BridgeTest skip print out of n2 and n3, go next to node n4");
948
949 // n4
950 routev4 = nullptr;
951 // Test that the right number of routes found
952 uint32_t nRoutesv44 = globalRoutingv44->GetNRoutes();
953 NS_LOG_DEBUG("BridgeTest nRoutes4 " << nRoutesv44);
954 NS_TEST_ASSERT_MSG_EQ(nRoutesv44, 3, "Error-- not three entries");
955 for (uint32_t i = 0; i < globalRoutingv44->GetNRoutes(); i++)
956 {
957 routev4 = globalRoutingv44->GetRoute(i);
958 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
959 }
960 // Spot check the last route
961 if (routev4)
962 {
964 Ipv4Address("10.1.1.0"),
965 "Error-- wrong destination");
967 Ipv4Address("10.1.3.1"),
968 "Error-- wrong gateway");
969 }
970
971 //------------------Ipv6 Tests----------------
972 Ptr<Ipv6L3Protocol> ipv60 = m_nodes.Get(0)->GetObject<Ipv6L3Protocol>();
973 NS_TEST_ASSERT_MSG_NE(ipv60, nullptr, "Error-- no Ipv4 object");
974 Ptr<Ipv6RoutingProtocol> routingv60 = ipv60->GetRoutingProtocol();
975 NS_TEST_ASSERT_MSG_NE(routingv60, nullptr, "Error-- no Ipv4 routing protocol object");
976 Ptr<Ipv6GlobalRouting> globalRoutingv60 = routingv60->GetObject<Ipv6GlobalRouting>();
977 NS_TEST_ASSERT_MSG_NE(globalRoutingv60, nullptr, "Error-- no Ipv4GlobalRouting object");
978
979 Ptr<Ipv6L3Protocol> ipv61 = m_nodes.Get(1)->GetObject<Ipv6L3Protocol>();
980 NS_TEST_ASSERT_MSG_NE(ipv61, nullptr, "Error-- no Ipv4 object");
981 Ptr<Ipv6RoutingProtocol> routingv61 = ipv61->GetRoutingProtocol();
982 NS_TEST_ASSERT_MSG_NE(routingv61, nullptr, "Error-- no Ipv4 routing protocol object");
983 Ptr<Ipv6GlobalRouting> globalRoutingv61 = routingv61->GetObject<Ipv6GlobalRouting>();
984 NS_TEST_ASSERT_MSG_NE(globalRoutingv61, nullptr, "Error-- no Ipv4GlobalRouting object");
985
986 // Skip to n4
987 Ptr<Ipv6L3Protocol> ipv64 = m_nodes.Get(4)->GetObject<Ipv6L3Protocol>();
988 NS_TEST_ASSERT_MSG_NE(ipv64, nullptr, "Error-- no Ipv4 object");
989 Ptr<Ipv6RoutingProtocol> routingv64 = ipv64->GetRoutingProtocol();
990 NS_TEST_ASSERT_MSG_NE(routingv64, nullptr, "Error-- no Ipv4 routing protocol object");
991 Ptr<Ipv6GlobalRouting> globalRoutingv64 = routingv64->GetObject<Ipv6GlobalRouting>();
992 NS_TEST_ASSERT_MSG_NE(globalRoutingv64, nullptr, "Error-- no Ipv4GlobalRouting object");
993
994 Ipv6RoutingTableEntry* routev6 = nullptr;
995 // n0
996 // Test that the right number of routes found
997 uint32_t nRoutesv60 = globalRoutingv60->GetNRoutes();
998 NS_LOG_DEBUG("BridgeTest nRoutes0 " << nRoutesv60);
999 NS_TEST_ASSERT_MSG_EQ(nRoutesv60, 3, "Error-- not three entries");
1000 for (uint32_t i = 0; i < globalRoutingv60->GetNRoutes(); i++)
1001 {
1002 routev6 = globalRoutingv60->GetRoute(i);
1003 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
1004 }
1005 // Spot check the last route
1006 if (routev6)
1007 {
1008 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(),
1009 Ipv6Address("2001:2::"),
1010 "Error-- wrong destination");
1012 Ipv6Prefix(64),
1013 "Error-- wrong destination mask");
1015 Ipv6Address("fe80::200:ff:fe00:2"),
1016 "Error-- wrong gateway");
1017 }
1018
1019 // n1
1020 // Test that the right number of routes found
1021 routev6 = nullptr;
1022 uint32_t nRoutesv61 = globalRoutingv61->GetNRoutes();
1023 NS_LOG_DEBUG("BridgeTest nRoutes1 " << nRoutesv61);
1024 NS_TEST_ASSERT_MSG_EQ(nRoutesv61, 3, "Error-- not three entries");
1025 for (uint32_t i = 0; i < globalRoutingv61->GetNRoutes(); i++)
1026 {
1027 routev6 = globalRoutingv61->GetRoute(i);
1028 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
1029 }
1030 // Spot check the last route
1031 if (routev6)
1032 {
1033 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(),
1034 Ipv6Address("2001:2::"),
1035 "Error-- wrong destination");
1037 Ipv6Prefix(64),
1038 "Error-- wrong destination mask");
1040 Ipv6Address("fe80::200:ff:fe00:6"),
1041 "Error-- wrong gateway");
1042 }
1043
1044 // skip n2 and n3, just verify n4
1045 NS_LOG_DEBUG("BridgeTest skip print out of n2 and n3, go next to node n4");
1046
1047 // n4
1048 routev6 = nullptr;
1049 // Test that the right number of routes found
1050 uint32_t nRoutesv64 = globalRoutingv64->GetNRoutes();
1051 NS_LOG_DEBUG("BridgeTest nRoutes4 " << nRoutesv64);
1052 NS_TEST_ASSERT_MSG_EQ(nRoutesv64, 3, "Error-- not three entries");
1053 for (uint32_t i = 0; i < globalRoutingv64->GetNRoutes(); i++)
1054 {
1055 routev6 = globalRoutingv64->GetRoute(i);
1056 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
1057 }
1058 // Spot check the last route
1059 if (routev6)
1060 {
1061 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(),
1062 Ipv6Address("2001::"),
1063 "Error-- wrong destination");
1065 Ipv6Prefix(64),
1066 "Error-- wrong destination mask");
1068 Ipv6Address("fe80::200:ff:fe00:7"),
1069 "Error-- wrong gateway");
1070 }
1073}
1074
1075/**
1076 * @ingroup internet-test
1077 *
1078 * @brief GlobalRouting Two bridges test
1079 */
1081{
1082 public:
1083 void DoSetup() override;
1084 void DoRun() override;
1085 TwoBridgeTest();
1086
1087 private:
1088 NodeContainer m_nodes; //!< Nodes used in the test.
1089};
1090
1092 : TestCase("Global routing across two bridges")
1093{
1094}
1095
1096void
1098{
1099 m_nodes.Create(5);
1100
1101 // connect node0 to node1
1103 SimpleNetDeviceHelper simpleHelper;
1104 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
1105 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
1106
1107 NetDeviceContainer bridgeFacingDevices;
1108 NetDeviceContainer switchn2Devices;
1109 NetDeviceContainer switchn3Devices;
1110
1111 // connect node1 to node2 (switch)
1113 SimpleNetDeviceHelper simpleHelper2;
1114 NetDeviceContainer net2 = simpleHelper2.Install(m_nodes.Get(1), channel2);
1115 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
1116 bridgeFacingDevices.Add(net2.Get(0));
1117 switchn2Devices.Add(net2.Get(1));
1118
1119 // connect node2 (switch) to node3
1121 SimpleNetDeviceHelper simpleHelper3;
1122 NetDeviceContainer net3 = simpleHelper3.Install(m_nodes.Get(2), channel3);
1123 net3.Add(simpleHelper3.Install(m_nodes.Get(3), channel3));
1124 switchn2Devices.Add(net3.Get(0));
1125 switchn3Devices.Add(net3.Get(1));
1126
1127 // connect node3 to node4
1129 SimpleNetDeviceHelper simpleHelper4;
1130 NetDeviceContainer net4 = simpleHelper4.Install(m_nodes.Get(3), channel4);
1131 net4.Add(simpleHelper4.Install(m_nodes.Get(4), channel4));
1132 switchn3Devices.Add(net4.Get(0));
1133 bridgeFacingDevices.Add(net4.Get(1));
1134
1135 Ptr<Node> switchn2Node = m_nodes.Get(2);
1136 BridgeHelper bridgen2Helper;
1137 bridgen2Helper.Install(switchn2Node, switchn2Devices);
1138
1139 Ptr<Node> switchn3Node = m_nodes.Get(3);
1140 BridgeHelper bridgen3Helper;
1141 bridgen3Helper.Install(switchn3Node, switchn3Devices);
1142
1143 InternetStackHelper internet;
1144 // By default, InternetStackHelper adds a static and global routing
1145 // implementation. We just want the global for this test.
1146 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
1147 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
1148 internet.SetRoutingHelper(ipv4RoutingHelper);
1149 internet.SetRoutingHelper(ipv6RoutingHelper);
1150
1151 internet.Install(m_nodes.Get(0));
1152 internet.Install(m_nodes.Get(1));
1153 // m_nodes.Get (2) is bridge node
1154 // m_nodes.Get (3) is bridge node
1155 internet.Install(m_nodes.Get(4));
1156
1157 Ipv4AddressHelper addressv4;
1158 addressv4.SetBase("10.1.1.0", "255.255.255.0");
1159 addressv4.Assign(net);
1160
1161 addressv4.SetBase("10.1.2.0", "255.255.255.0");
1162 addressv4.Assign(bridgeFacingDevices);
1163
1164 Ipv6AddressHelper addressv6;
1165 addressv6.SetBase(Ipv6Address("2001:0::"), Ipv6Prefix(64));
1166 addressv6.Assign(net);
1167
1168 addressv6.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
1169 addressv6.Assign(bridgeFacingDevices);
1170}
1171
1172void
1174{
1177 //------------Ipv4 Tests-------------------
1178 Ptr<Ipv4L3Protocol> ipv40 = m_nodes.Get(0)->GetObject<Ipv4L3Protocol>();
1179 NS_TEST_ASSERT_MSG_NE(ipv40, nullptr, "Error-- no Ipv4 object");
1180 Ptr<Ipv4RoutingProtocol> routingv40 = ipv40->GetRoutingProtocol();
1181 NS_TEST_ASSERT_MSG_NE(routingv40, nullptr, "Error-- no Ipv4 routing protocol object");
1182 Ptr<Ipv4GlobalRouting> globalRoutingv40 = routingv40->GetObject<Ipv4GlobalRouting>();
1183 NS_TEST_ASSERT_MSG_NE(globalRoutingv40, nullptr, "Error-- no Ipv4GlobalRouting object");
1184
1185 // Skip to n4
1186 Ptr<Ipv4L3Protocol> ipv44 = m_nodes.Get(4)->GetObject<Ipv4L3Protocol>();
1187 NS_TEST_ASSERT_MSG_NE(ipv44, nullptr, "Error-- no Ipv4 object");
1188 Ptr<Ipv4RoutingProtocol> routingv44 = ipv44->GetRoutingProtocol();
1189 NS_TEST_ASSERT_MSG_NE(routingv44, nullptr, "Error-- no Ipv4 routing protocol object");
1190 Ptr<Ipv4GlobalRouting> globalRoutingv44 = routingv44->GetObject<Ipv4GlobalRouting>();
1191 NS_TEST_ASSERT_MSG_NE(globalRoutingv44, nullptr, "Error-- no Ipv4GlobalRouting object");
1192
1193 Ipv4RoutingTableEntry* routev4 = nullptr;
1194 // n0
1195 // Test that the right number of routes found
1196 uint32_t nRoutesv40 = globalRoutingv40->GetNRoutes();
1197 NS_LOG_DEBUG("BridgeTest nRoutes0 " << nRoutesv40);
1198 NS_TEST_ASSERT_MSG_EQ(nRoutesv40, 2, "Error-- not two entries");
1199 for (uint32_t i = 0; i < globalRoutingv40->GetNRoutes(); i++)
1200 {
1201 routev4 = globalRoutingv40->GetRoute(i);
1202 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
1203 }
1204 // Spot check the last route
1205 if (routev4)
1206 {
1207 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(),
1208 Ipv4Address("10.1.2.0"),
1209 "Error-- wrong destination");
1211 Ipv4Address("10.1.1.2"),
1212 "Error-- wrong gateway");
1213 }
1214 // skip n2 and n3, just verify n4
1215 NS_LOG_DEBUG("BridgeTest skip print out of n1-n3, go next to node n4");
1216
1217 // n4
1218 // Test that the right number of routes found
1219 routev4 = nullptr;
1220 uint32_t nRoutesv44 = globalRoutingv44->GetNRoutes();
1221 NS_LOG_DEBUG("BridgeTest nRoutes4 " << nRoutesv44);
1222 NS_TEST_ASSERT_MSG_EQ(nRoutesv44, 2, "Error-- not two entries");
1223 for (uint32_t i = 0; i < globalRoutingv44->GetNRoutes(); i++)
1224 {
1225 routev4 = globalRoutingv44->GetRoute(i);
1226 NS_LOG_DEBUG("entry dest " << routev4->GetDest() << " gw " << routev4->GetGateway());
1227 }
1228 // Spot check the last route
1229 if (routev4)
1230 {
1231 NS_TEST_ASSERT_MSG_EQ(routev4->GetDest(),
1232 Ipv4Address("10.1.1.0"),
1233 "Error-- wrong destination");
1235 Ipv4Address("10.1.2.1"),
1236 "Error-- wrong gateway");
1237 }
1238
1239 //----------Ipv6 Tests--------------
1240 Ptr<Ipv6L3Protocol> ipv60 = m_nodes.Get(0)->GetObject<Ipv6L3Protocol>();
1241 NS_TEST_ASSERT_MSG_NE(ipv60, nullptr, "Error-- no Ipv4 object");
1242 Ptr<Ipv6RoutingProtocol> routingv60 = ipv60->GetRoutingProtocol();
1243 NS_TEST_ASSERT_MSG_NE(routingv60, nullptr, "Error-- no Ipv4 routing protocol object");
1244 Ptr<Ipv6GlobalRouting> globalRoutingv60 = routingv60->GetObject<Ipv6GlobalRouting>();
1245 NS_TEST_ASSERT_MSG_NE(globalRoutingv60, nullptr, "Error-- no Ipv4GlobalRouting object");
1246
1247 // Skip to n4
1248 Ptr<Ipv6L3Protocol> ipv64 = m_nodes.Get(4)->GetObject<Ipv6L3Protocol>();
1249 NS_TEST_ASSERT_MSG_NE(ipv64, nullptr, "Error-- no Ipv4 object");
1250 Ptr<Ipv6RoutingProtocol> routingv64 = ipv64->GetRoutingProtocol();
1251 NS_TEST_ASSERT_MSG_NE(routingv64, nullptr, "Error-- no Ipv4 routing protocol object");
1252 Ptr<Ipv6GlobalRouting> globalRoutingv64 = routingv64->GetObject<Ipv6GlobalRouting>();
1253 NS_TEST_ASSERT_MSG_NE(globalRoutingv64, nullptr, "Error-- no Ipv4GlobalRouting object");
1254
1255 Ipv6RoutingTableEntry* routev6 = nullptr;
1256 // n0
1257 // Test that the right number of routes found
1258 uint32_t nRoutesv60 = globalRoutingv60->GetNRoutes();
1259 NS_LOG_DEBUG("BridgeTest nRoutes0 " << nRoutesv60);
1260 NS_TEST_ASSERT_MSG_EQ(nRoutesv60, 2, "Error-- not two entries");
1261 for (uint32_t i = 0; i < globalRoutingv60->GetNRoutes(); i++)
1262 {
1263 routev6 = globalRoutingv60->GetRoute(i);
1264 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
1265 }
1266 // Spot check the last route
1267 if (routev6)
1268 {
1269 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(),
1270 Ipv6Address("2001:1::"),
1271 "Error-- wrong destination");
1273 Ipv6Prefix(64),
1274 "Error-- wrong destination mask");
1276 Ipv6Address("fe80::200:ff:fe00:2"),
1277 "Error-- wrong gateway");
1278 }
1279 // skip n2 and n3, just verify n4
1280 NS_LOG_DEBUG("BridgeTest skip print out of n1-n3, go next to node n4");
1281
1282 // n4
1283 // Test that the right number of routes found
1284 routev6 = nullptr;
1285 uint32_t nRoutesv64 = globalRoutingv64->GetNRoutes();
1286 NS_LOG_DEBUG("BridgeTest nRoutes4 " << nRoutesv44);
1287 NS_TEST_ASSERT_MSG_EQ(nRoutesv64, 2, "Error-- not two entries");
1288 for (uint32_t i = 0; i < globalRoutingv64->GetNRoutes(); i++)
1289 {
1290 routev6 = globalRoutingv64->GetRoute(i);
1291 NS_LOG_DEBUG("entry dest " << routev6->GetDest() << " gw " << routev6->GetGateway());
1292 }
1293 // Spot check the last route
1294 if (routev6)
1295 {
1296 NS_TEST_ASSERT_MSG_EQ(routev6->GetDest(),
1297 Ipv6Address("2001::"),
1298 "Error-- wrong destination");
1300 Ipv6Prefix(64),
1301 "Error-- wrong destination mask");
1303 Ipv6Address("fe80::200:ff:fe00:3"),
1304 "Error-- wrong gateway");
1305 }
1306
1308}
1309
1310/**
1311 * @ingroup internet-test
1312 *
1313 * @brief IPv4 Dynamic GlobalRouting test
1314 */
1316{
1317 public:
1320
1321 private:
1322 /**
1323 * @brief Send some data
1324 * @param index Index of the socket to use.
1325 */
1326 void SendData(uint8_t index);
1327
1328 /**
1329 * @brief Shutdown a socket
1330 * @param index Index of the socket to close.
1331 */
1332 void ShutDownSock(uint8_t index);
1333
1334 /**
1335 * Handle an incoming packet
1336 * @param socket The input socket.
1337 */
1338 void HandleRead(Ptr<Socket> socket);
1339 void DoRun() override;
1340
1341 uint16_t m_count; //!< Number of packets received.
1342 std::vector<std::pair<Ptr<Socket>, bool>> m_sendSocks; //!< Sending sockets.
1343 DataRate m_dataRate; //!< Data rate.
1344 uint16_t m_packetSize; //!< Packet size.
1345 std::vector<uint8_t>
1346 m_firstInterface; //!< Packets received on the 1st interface at a given time.
1347 std::vector<uint8_t>
1348 m_secondInterface; //!< Packets received on the 2nd interface at a given time.
1349 NodeContainer c; //!< nodes in the topology
1350};
1351
1352// Add some help text to this case to describe what it is intended to test
1354 : TestCase("Ipv4 Dynamic global routing example"),
1355 m_count(0)
1356{
1357 m_firstInterface.resize(16, 0);
1358 m_secondInterface.resize(16, 0);
1359 m_dataRate = DataRate("2kbps");
1360 m_packetSize = 50;
1361}
1362
1364{
1365 for (auto iter = m_sendSocks.begin(); iter != m_sendSocks.end(); iter++)
1366 {
1367 if (iter->second)
1368 {
1369 iter->second = false;
1370 iter->first->Close();
1371 iter->first = nullptr;
1372 }
1373 }
1374}
1375
1376void
1378{
1379 Ptr<Packet> packet;
1380 Address from;
1381 while ((packet = socket->RecvFrom(from)))
1382 {
1383 if (packet->GetSize() == 0)
1384 { // EOF
1385 break;
1386 }
1388 bool found;
1389 found = packet->PeekPacketTag(tag);
1390 uint8_t now = static_cast<uint8_t>(Simulator::Now().GetSeconds());
1391 if (found)
1392 {
1393 if (tag.GetRecvIf() == 1)
1394 {
1395 m_firstInterface[now]++;
1396 }
1397 if (tag.GetRecvIf() == 2)
1398 {
1399 m_secondInterface[now]++;
1400 }
1401 m_count++;
1402 }
1403 }
1404}
1405
1406void
1408{
1409 if (!m_sendSocks[index].second)
1410 {
1411 return;
1412 }
1414 m_sendSocks[index].first->Send(packet);
1415
1416 Time tNext(MicroSeconds(m_packetSize * 8 * 1e6 / m_dataRate.GetBitRate()));
1418}
1419
1420void
1422{
1423 m_sendSocks[index].second = false;
1424 m_sendSocks[index].first->Close();
1425 m_sendSocks[index].first = nullptr;
1426}
1427
1428// Test derived from examples/routing/dynamic-global-routing.cc
1429//
1430// Network topology
1431//
1432// n0
1433// \ p-p
1434// \ (shared csma/cd)
1435// n2 -------------------------n3
1436// / | |
1437// / p-p n4 n5 ---------- n6
1438// n1 p-p
1439// | |
1440// ----------------------------------------
1441// p-p
1442//
1443// Test that for node n6, the interface facing n5 receives packets at
1444// times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
1445// facing n1 receives packets at times (2-4), (6-8), (12-13)
1446//
1447void
1449{
1450 // The below value configures the default behavior of global routing.
1451 // By default, it is disabled. To respond to interface events, set to true
1452 Config::SetDefault("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue(true));
1453
1454 c.Create(7);
1455 NodeContainer n0n2 = NodeContainer(c.Get(0), c.Get(2));
1456 NodeContainer n1n2 = NodeContainer(c.Get(1), c.Get(2));
1457 NodeContainer n5n6 = NodeContainer(c.Get(5), c.Get(6));
1458 NodeContainer n1n6 = NodeContainer(c.Get(1), c.Get(6));
1459 NodeContainer n2345 = NodeContainer(c.Get(2), c.Get(3), c.Get(4), c.Get(5));
1460
1461 InternetStackHelper internet;
1462 Ipv4GlobalRoutingHelper routingHelper;
1463 internet.SetRoutingHelper(routingHelper);
1464 internet.Install(c);
1465
1466 // We create the channels first without any IP addressing information
1467 SimpleNetDeviceHelper devHelper;
1468
1469 devHelper.SetNetDevicePointToPointMode(true);
1470 NetDeviceContainer d0d2 = devHelper.Install(n0n2);
1471 NetDeviceContainer d1d6 = devHelper.Install(n1n6);
1472 NetDeviceContainer d1d2 = devHelper.Install(n1n2);
1473 NetDeviceContainer d5d6 = devHelper.Install(n5n6);
1474
1475 devHelper.SetNetDevicePointToPointMode(false);
1476 NetDeviceContainer d2345 = devHelper.Install(n2345);
1477
1478 // Later, we add IP addresses.
1479 Ipv4AddressHelper ipv4;
1480 ipv4.SetBase("10.1.1.0", "255.255.255.0");
1481 ipv4.Assign(d0d2);
1482
1483 ipv4.SetBase("10.1.2.0", "255.255.255.0");
1484 ipv4.Assign(d1d2);
1485
1486 ipv4.SetBase("10.1.3.0", "255.255.255.0");
1487 Ipv4InterfaceContainer i5i6 = ipv4.Assign(d5d6);
1488
1489 ipv4.SetBase("10.250.1.0", "255.255.255.0");
1490 ipv4.Assign(d2345);
1491
1492 ipv4.SetBase("172.16.1.0", "255.255.255.0");
1493 Ipv4InterfaceContainer i1i6 = ipv4.Assign(d1d6);
1494
1495 // Create router nodes, initialize routing database and set up the routing
1496 // tables in the nodes.
1498
1499 // Create the applications to send UDP datagrams of size
1500 // 50 bytes at a rate of 2 Kb/s
1501 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
1502 uint16_t port = 9; // Discard port (RFC 863)
1503
1504 std::pair<Ptr<Socket>, bool> sendSockA;
1505 sendSockA.first = Socket::CreateSocket(c.Get(1), tid);
1506 sendSockA.first->Bind();
1507 sendSockA.first->Connect(InetSocketAddress(i5i6.GetAddress(1), port));
1508 sendSockA.second = true;
1509 m_sendSocks.push_back(sendSockA);
1512
1513 std::pair<Ptr<Socket>, bool> sendSockB;
1514 sendSockB.first = Socket::CreateSocket(c.Get(1), tid);
1515 sendSockB.first->Bind();
1516 sendSockB.first->Connect(InetSocketAddress(i1i6.GetAddress(1), port));
1517 sendSockB.second = true;
1518 m_sendSocks.push_back(sendSockB);
1521
1522 // Create an optional packet sink to receive these packets
1523 Ptr<Socket> sink2 = Socket::CreateSocket(c.Get(6), tid);
1525 sink2->Listen();
1526 sink2->ShutdownSend();
1527
1528 sink2->SetRecvPktInfo(true);
1529 sink2->SetRecvCallback(MakeCallback(&Ipv4DynamicGlobalRoutingTestCase::HandleRead, this));
1530
1531 Ptr<Node> n1 = c.Get(1);
1532 Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4>();
1533 // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
1534 // then the next p2p is numbered 2
1535 uint32_t ipv4ifIndex1 = 2;
1536
1537 Simulator::Schedule(Seconds(2), &Ipv4::SetDown, ipv41, ipv4ifIndex1);
1538 Simulator::Schedule(Seconds(4), &Ipv4::SetUp, ipv41, ipv4ifIndex1);
1539
1540 Ptr<Node> n6 = c.Get(6);
1541 Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4>();
1542 // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
1543 // then the next p2p is numbered 2
1544 uint32_t ipv4ifIndex6 = 2;
1545 Simulator::Schedule(Seconds(6), &Ipv4::SetDown, ipv46, ipv4ifIndex6);
1546 Simulator::Schedule(Seconds(8), &Ipv4::SetUp, ipv46, ipv4ifIndex6);
1547
1548 Simulator::Schedule(Seconds(12), &Ipv4::SetDown, ipv41, ipv4ifIndex1);
1549 Simulator::Schedule(Seconds(14), &Ipv4::SetUp, ipv41, ipv4ifIndex1);
1550
1552
1553 NS_TEST_ASSERT_MSG_EQ(m_count, 70, "Dynamic global routing did not deliver all packets");
1554 // Test that for node n6, the interface facing n1 receives packets at
1555 // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
1556 // facing n5 receives packets at times (2-4), (6-8), (12-13)
1557
1558 // Note: there are two sending sockets, both on n1.
1559 // The first socket sends packets at time (1-10), the second at time (11, 16).
1560 // The first socket sends packets to n6, targeting the address facing n5.
1561 // The second socket sends packets to n6, targeting the address facing n1.
1562 // This actually doesn't matter, as n6 will accept packets sent to the "wrong" address.
1563 //
1564 // The shortest path netween n1 and n6 is the direct one, but the topology changes during the
1565 // simulation:
1566 // - (2-4): removal from n1 of the interface toward n6
1567 // - (6-8): removal from n6 of the interface toward n1
1568 // - (12-14): removal from n1 of the interface toward n6
1569 // When the link is broken, packets are rerouted though the longest (and only) path, reaching
1570 // n6 though n5.
1571
1572 std::vector<uint8_t> firstInterfaceTest{0, 5, 0, 0, 5, 5, 0, 0, 5, 5, 0, 5, 0, 0, 5, 5};
1573 std::vector<uint8_t> secondInterfaceTest{0, 0, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 0, 0};
1574
1575 for (uint32_t index = 0; index < firstInterfaceTest.size(); index++)
1576 {
1577 NS_TEST_ASSERT_MSG_EQ(firstInterfaceTest[index],
1578 m_firstInterface[index],
1579 "Dynamic global routing did deliver the wrong number of packets "
1580 "to the first interface at time "
1581 << index);
1582 }
1583
1584 for (uint32_t index = 0; index < secondInterfaceTest.size(); index++)
1585 {
1586 NS_TEST_ASSERT_MSG_EQ(secondInterfaceTest[index],
1587 m_secondInterface[index],
1588 "Dynamic global routing did deliver the wrong number of packets "
1589 "to the second interface at time "
1590 << index);
1591 }
1592
1594}
1595
1596/**
1597 * @ingroup internet-test
1598 *
1599 * @brief IPv6 Dynamic GlobalRouting test
1600 */
1602{
1603 public:
1606
1607 private:
1608 /**
1609 * @brief Send some data
1610 * @param index Index of the socket to use.
1611 */
1612 void SendData(uint8_t index);
1613
1614 /**
1615 * @brief Shutdown a socket
1616 * @param index Index of the socket to close.
1617 */
1618 void ShutDownSock(uint8_t index);
1619
1620 /**
1621 * Handle an incoming packet
1622 * @param socket The input socket.
1623 */
1624 void HandleRead(Ptr<Socket> socket);
1625 /**
1626 * @brief This function does two things, set the specified ipv6 interface as up and
1627 * Adds the specified Ipv6Address to the interface.
1628 * @param ipv6 The Ipv6 object
1629 * @param ifIndex The index of the interface
1630 * @param address The Ipv6Address to be added to the interface
1631 */
1632 void SetInterfaceUp(Ptr<Ipv6> ipv6, uint32_t ifIndex, Ipv6InterfaceAddress address);
1633
1634 void DoRun() override;
1635
1636 uint16_t m_count; //!< Number of packets received.
1637 std::vector<std::pair<Ptr<Socket>, bool>> m_sendSocks; //!< Sending sockets.
1638 DataRate m_dataRate; //!< Data rate.
1639 uint16_t m_packetSize; //!< Packet size.
1640 std::vector<uint8_t>
1641 m_firstInterface; //!< Packets received on the 1st interface at a given time.
1642 std::vector<uint8_t>
1643 m_secondInterface; //!< Packets received on the 2nd interface at a given time.
1644 NodeContainer c; //!< nodes in the topology
1645};
1646
1647// Add some help text to this case to describe what it is intended to test
1649 : TestCase("Ipv6 Dynamic global routing example"),
1650 m_count(0)
1651{
1652 m_firstInterface.resize(16, 0);
1653 m_secondInterface.resize(16, 0);
1654 m_dataRate = DataRate("2kbps");
1655 m_packetSize = 50;
1656}
1657
1659{
1660 for (auto iter = m_sendSocks.begin(); iter != m_sendSocks.end(); iter++)
1661 {
1662 if (iter->second)
1663 {
1664 iter->second = false;
1665 iter->first->Close();
1666 iter->first = nullptr;
1667 }
1668 }
1669}
1670
1671void
1673{
1674 Ptr<Packet> packet;
1675 Address from;
1676
1677 while ((packet = socket->RecvFrom(from)))
1678 {
1679 if (packet->GetSize() == 0)
1680 { // EOF
1681 break;
1682 }
1684 bool found;
1685 found = packet->PeekPacketTag(tag);
1686 uint8_t now = static_cast<uint8_t>(Simulator::Now().GetSeconds());
1687 if (found)
1688 {
1689 if (tag.GetRecvIf() == 1)
1690 {
1691 m_firstInterface[now]++;
1692 }
1693 if (tag.GetRecvIf() == 2)
1694 {
1695 m_secondInterface[now]++;
1696 }
1697 m_count++;
1698 }
1699 }
1700}
1701
1702void
1704{
1705 if (!m_sendSocks[index].second)
1706 {
1707 return;
1708 }
1710 m_sendSocks[index].first->Send(packet);
1711
1712 Time tNext(MicroSeconds(m_packetSize * 8 * 1e6 / m_dataRate.GetBitRate()));
1714}
1715
1716void
1718{
1719 m_sendSocks[index].second = false;
1720 m_sendSocks[index].first->Close();
1721 m_sendSocks[index].first = nullptr;
1722}
1723
1724void
1726 uint32_t ifIndex,
1727 Ipv6InterfaceAddress address)
1728{
1729 ipv6->SetUp(ifIndex);
1730 ipv6->AddAddress(ifIndex, address);
1731}
1732
1733// Test derived from examples/routing/dynamic-global-routing.cc
1734//
1735// Network topology
1736//
1737// n0
1738// \ p-p
1739// \ (shared csma/cd)
1740// n2 -------------------------n3
1741// / | |
1742// / p-p n4 n5 ---------- n6
1743// n1 p-p
1744// | |
1745// ----------------------------------------
1746// p-p
1747//
1748// Test that for node n6, the interface facing n5 receives packets at
1749// times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
1750// facing n1 receives packets at times (2-4), (6-8), (12-13)
1751//
1752void
1754{
1755 // The below value configures the default behavior of global routing.
1756 // By default, it is disabled. To respond to interface events, set to true
1757 Config::SetDefault("ns3::Ipv6GlobalRouting::RespondToInterfaceEvents", BooleanValue(true));
1758
1759 c.Create(7);
1760 NodeContainer n0n2 = NodeContainer(c.Get(0), c.Get(2));
1761 NodeContainer n1n2 = NodeContainer(c.Get(1), c.Get(2));
1762 NodeContainer n5n6 = NodeContainer(c.Get(5), c.Get(6));
1763 NodeContainer n1n6 = NodeContainer(c.Get(1), c.Get(6));
1764 NodeContainer n2345 = NodeContainer(c.Get(2), c.Get(3), c.Get(4), c.Get(5));
1765
1766 Ipv6GlobalRoutingHelper ipv6RoutingHelper;
1767 InternetStackHelper internet;
1768 internet.SetRoutingHelper(ipv6RoutingHelper);
1769
1770 internet.Install(c);
1771
1772 // We create the channels first without any IP addressing information
1773 SimpleNetDeviceHelper devHelper;
1774
1775 devHelper.SetNetDevicePointToPointMode(true);
1776 NetDeviceContainer d0d2 = devHelper.Install(n0n2);
1777 NetDeviceContainer d1d6 = devHelper.Install(n1n6);
1778 NetDeviceContainer d1d2 = devHelper.Install(n1n2);
1779 NetDeviceContainer d5d6 = devHelper.Install(n5n6);
1780
1781 devHelper.SetNetDevicePointToPointMode(false);
1782 NetDeviceContainer d2345 = devHelper.Install(n2345);
1783
1784 // Later, we add IP addresses.
1785 Ipv6AddressHelper ipv6;
1786 ipv6.SetBase("2001:1::", Ipv6Prefix(64));
1787 ipv6.Assign(d0d2);
1788 ipv6.SetBase("2001:2::", Ipv6Prefix(64));
1789 ipv6.Assign(d1d2);
1790 ipv6.SetBase("2001:3::", Ipv6Prefix(64));
1791 Ipv6InterfaceContainer i5i6 = ipv6.Assign(d5d6);
1792 ipv6.SetBase("2001:4::", Ipv6Prefix(64));
1793 ipv6.Assign(d2345);
1794 ipv6.SetBase("2001:5::", Ipv6Prefix(64));
1795 Ipv6InterfaceContainer i1i6 = ipv6.Assign(d1d6);
1796
1797 // Create router nodes, initialize routing database and set up the routing
1798 // tables in the nodes.
1800
1801 NeighborCacheHelper neighborCache;
1802 neighborCache.SetDynamicNeighborCache(true);
1803 neighborCache.PopulateNeighborCache();
1804
1805 // Create the applications to send UDP datagrams of size
1806 // 50 bytes at a rate of 2 Kb/s
1807 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
1808 uint16_t port = 9; // Discard port (RFC 863)
1809
1810 std::pair<Ptr<Socket>, bool> sendSockA;
1811 sendSockA.first = Socket::CreateSocket(c.Get(1), tid);
1812 sendSockA.first->Bind();
1813 sendSockA.first->Connect(Inet6SocketAddress(i5i6.GetAddress(1, 1), port));
1814 sendSockA.second = true;
1815 m_sendSocks.push_back(sendSockA);
1818
1819 std::pair<Ptr<Socket>, bool> sendSockB;
1820 sendSockB.first = Socket::CreateSocket(c.Get(1), tid);
1821 sendSockB.first->Bind();
1822 sendSockB.first->Connect(Inet6SocketAddress(i1i6.GetAddress(1, 1), port));
1823 sendSockB.second = true;
1824 m_sendSocks.push_back(sendSockB);
1827
1828 // Create an optional packet sink to receive these packets
1829 Ptr<Socket> sink2 = Socket::CreateSocket(c.Get(6), tid);
1831 sink2->Listen();
1832 sink2->ShutdownSend();
1833
1834 sink2->SetRecvPktInfo(true);
1835 sink2->SetRecvCallback(MakeCallback(&Ipv6DynamicGlobalRoutingTestCase::HandleRead, this));
1836
1837 Ptr<Node> n1 = c.Get(1);
1838 Ptr<Ipv6> ipv41 = n1->GetObject<Ipv6>();
1839 // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
1840 // then the next p2p is numbered 2
1841 uint32_t ipv4ifIndex1 = 2;
1842
1843 Simulator::Schedule(Seconds(2), &Ipv6::SetDown, ipv41, ipv4ifIndex1);
1846 this,
1847 ipv41,
1848 ipv4ifIndex1,
1849 Ipv6InterfaceAddress(Ipv6Address("2001:5::200:ff:fe00:3"), Ipv6Prefix(64)));
1850
1851 Ptr<Node> n6 = c.Get(6);
1852 Ptr<Ipv6> ipv46 = n6->GetObject<Ipv6>();
1853 // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
1854 // then the next p2p is numbered 2
1855 uint32_t ipv4ifIndex6 = 2;
1856 Simulator::Schedule(Seconds(6), &Ipv6::SetDown, ipv46, ipv4ifIndex6);
1859 this,
1860 ipv46,
1861 ipv4ifIndex6,
1862 Ipv6InterfaceAddress(Ipv6Address("2001:5::200:ff:fe00:4"), Ipv6Prefix(64)));
1863
1864 Simulator::Schedule(Seconds(12), &Ipv6::SetDown, ipv41, ipv4ifIndex1);
1867 this,
1868 ipv41,
1869 ipv4ifIndex1,
1870 Ipv6InterfaceAddress(Ipv6Address("2001:5::200:ff:fe00:3"), Ipv6Prefix(64)));
1871
1873
1874 NS_TEST_ASSERT_MSG_EQ(m_count, 70, "Dynamic global routing did not deliver all packets");
1875 // Test that for node n6, the interface facing n1 receives packets at
1876 // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
1877 // facing n5 receives packets at times (2-4), (6-8), (12-13)
1878
1879 // Note: there are two sending sockets, both on n1.
1880 // The first socket sends packets at time (1-10), the second at time (11, 16).
1881 // The first socket sends packets to n6, targeting the address facing n5.
1882 // The second socket sends packets to n6, targeting the address facing n1.
1883 // This actually doesn't matter, as n6 will accept packets sent to the "wrong" address.
1884 //
1885 // The shortest path netween n1 and n6 is the direct one, but the topology changes during the
1886 // simulation:
1887 // - (2-4): removal from n1 of the interface toward n6
1888 // - (6-8): removal from n6 of the interface toward n1
1889 // - (12-14): removal from n1 of the interface toward n6
1890 // When the link is broken, packets are rerouted though the longest (and only) path, reaching
1891 // n6 though n5.
1892
1893 std::vector<uint8_t> firstInterfaceTest{0, 5, 0, 0, 5, 5, 0, 0, 5, 5, 0, 5, 0, 0, 5, 5};
1894 std::vector<uint8_t> secondInterfaceTest{0, 0, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 0, 0};
1895
1896 for (uint32_t index = 0; index < firstInterfaceTest.size(); index++)
1897 {
1898 NS_TEST_ASSERT_MSG_EQ(firstInterfaceTest[index],
1899 m_firstInterface[index],
1900 "Dynamic global routing did deliver the wrong number of packets "
1901 "to the first interface at time "
1902 << index);
1903 }
1904
1905 for (uint32_t index = 0; index < secondInterfaceTest.size(); index++)
1906 {
1907 NS_TEST_ASSERT_MSG_EQ(secondInterfaceTest[index],
1908 m_secondInterface[index],
1909 "Dynamic global routing did deliver the wrong number of packets "
1910 "to the second interface at time "
1911 << index);
1912 }
1913
1915}
1916
1917/**
1918 * @ingroup internet-test
1919 *
1920 * @brief IPv4 Dynamic GlobalRouting /32 test
1921 */
1923{
1924 public:
1927
1928 Ptr<Packet> m_receivedPacket; //!< number of received packets
1929
1930 /**
1931 * @brief Receive a packet.
1932 * @param socket The receiving socket.
1933 */
1934 void ReceivePkt(Ptr<Socket> socket);
1935 /**
1936 * @brief Send a packet.
1937 * @param socket The sending socket.
1938 * @param to The address of the receiver.
1939 */
1940 void DoSendData(Ptr<Socket> socket, std::string to);
1941 /**
1942 * @brief Send a packet.
1943 * @param socket The sending socket.
1944 * @param to The address of the receiver.
1945 */
1946 void SendData(Ptr<Socket> socket, std::string to);
1947
1948 private:
1949 void DoRun() override;
1950};
1951
1952// Add some help text to this case to describe what it is intended to test
1954 : TestCase("Slash 32 global routing example")
1955{
1956}
1957
1961
1962void
1964{
1965 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
1966 m_receivedPacket = socket->Recv(std::numeric_limits<uint32_t>::max(), 0);
1967 NS_TEST_ASSERT_MSG_EQ(availableData,
1968 m_receivedPacket->GetSize(),
1969 "Received packet size is not equal to Rx buffer size");
1970}
1971
1972void
1974{
1975 Address realTo = InetSocketAddress(Ipv4Address(to.c_str()), 1234);
1976 NS_TEST_EXPECT_MSG_EQ(socket->SendTo(Create<Packet>(123), 0, realTo), 123, "100");
1977}
1978
1979void
1981{
1983 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
1984 Seconds(60),
1986 this,
1987 socket,
1988 to);
1991}
1992
1993// Test program for this 3-router scenario, using global routing
1994//
1995// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
1996//
1997void
1999{
2003
2004 NodeContainer c = NodeContainer(nA, nB, nC);
2005
2006 InternetStackHelper internet;
2007 internet.Install(c);
2008
2009 // simple links
2010 NodeContainer nAnB = NodeContainer(nA, nB);
2011 NodeContainer nBnC = NodeContainer(nB, nC);
2012
2013 SimpleNetDeviceHelper devHelper;
2014
2016 deviceA->SetAddress(Mac48Address::Allocate());
2017 nA->AddDevice(deviceA);
2018
2019 NetDeviceContainer dAdB = devHelper.Install(nAnB);
2020 NetDeviceContainer dBdC = devHelper.Install(nBnC);
2021
2023 deviceC->SetAddress(Mac48Address::Allocate());
2024 nC->AddDevice(deviceC);
2025
2026 // Later, we add IP addresses.
2027 Ipv4AddressHelper ipv4;
2028 ipv4.SetBase("10.1.1.0", "255.255.255.252");
2029 Ipv4InterfaceContainer iAiB = ipv4.Assign(dAdB);
2030
2031 ipv4.SetBase("10.1.1.4", "255.255.255.252");
2032 Ipv4InterfaceContainer iBiC = ipv4.Assign(dBdC);
2033
2034 Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4>();
2035 Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4>();
2036 Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4>();
2037
2038 int32_t ifIndexA = ipv4A->AddInterface(deviceA);
2039 int32_t ifIndexC = ipv4C->AddInterface(deviceC);
2040
2041 Ipv4InterfaceAddress ifInAddrA =
2042 Ipv4InterfaceAddress(Ipv4Address("172.16.1.1"), Ipv4Mask("/32"));
2043 ipv4A->AddAddress(ifIndexA, ifInAddrA);
2044 ipv4A->SetMetric(ifIndexA, 1);
2045 ipv4A->SetUp(ifIndexA);
2046
2047 Ipv4InterfaceAddress ifInAddrC =
2048 Ipv4InterfaceAddress(Ipv4Address("192.168.1.1"), Ipv4Mask("/32"));
2049 ipv4C->AddAddress(ifIndexC, ifInAddrC);
2050 ipv4C->SetMetric(ifIndexC, 1);
2051 ipv4C->SetUp(ifIndexC);
2052
2053 // Create router nodes, initialize routing database and set up the routing
2054 // tables in the nodes.
2056
2057 // Create the UDP sockets
2058 Ptr<SocketFactory> rxSocketFactory = nC->GetObject<UdpSocketFactory>();
2059 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
2060 NS_TEST_EXPECT_MSG_EQ(rxSocket->Bind(InetSocketAddress(Ipv4Address("192.168.1.1"), 1234)),
2061 0,
2062 "trivial");
2063 rxSocket->SetRecvCallback(MakeCallback(&Ipv4GlobalRoutingSlash32TestCase::ReceivePkt, this));
2064
2065 Ptr<SocketFactory> txSocketFactory = nA->GetObject<UdpSocketFactory>();
2066 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
2067 txSocket->SetAllowBroadcast(true);
2068
2069 // ------ Now the tests ------------
2070
2071 // Unicast test
2072 SendData(txSocket, "192.168.1.1");
2074 123,
2075 "Static routing with /32 did not deliver all packets.");
2076
2078}
2079
2080/**
2081 * @ingroup internet-test
2082 *
2083 * @brief This TestCase tests if ECMP Route Calculation works. It does not check the
2084 * correctness of the routes.
2085 */
2087{
2088 public:
2090 void DoSetup() override;
2091 void DoRun() override;
2092
2093 private:
2094 NodeContainer nodes; //!< Nodes used in the test.
2095};
2096
2098 : TestCase("ECMP Route Calculation TestCase")
2099{
2100}
2101
2102void
2104{
2105 /*
2106 This TestCase checks the resolution of issue #1243 in the issue tracker.
2107 The problem was that Global Routing failed to calculate next hops when going from a
2108 network vertex to a router vertex when ECMP Routes were involved.
2109
2110 // Network Topology
2111 //
2112 //
2113 // ------n1------
2114 // / \
2115 // / \
2116 // n0 n3----n4----n5
2117 // \ /
2118 // \ /
2119 // ------n2------
2120 //
2121 // Link n0-n1: 10.1.1.1/30,10.1.1.2/30
2122 // Link n0-n2: 10.1.2.1/30,10.1.2.2/30
2123 // Link n1-n3: 10.1.3.1/30,10.1.3.2/30
2124 // Link n2-n3: 10.1.4.1/30,10.1.4.2/30
2125 // Link n3-n4: 10.1.5.1/24,10.1.5.2/24
2126 // Link n4-n5: 10.1.6.1/24,10.1.6.2/24
2127 //
2128 // Note: Link n4-n5 is a LAN LINK. All others are simple P2P links.
2129 */
2130
2131 nodes.Create(6);
2132
2133 Ipv4GlobalRoutingHelper globalhelperv4;
2134 Ipv6GlobalRoutingHelper globalhelperv6;
2135
2136 InternetStackHelper stack;
2137 stack.SetRoutingHelper(globalhelperv4);
2138 stack.SetRoutingHelper(globalhelperv6);
2139 stack.Install(nodes);
2140 SimpleNetDeviceHelper devHelper;
2141 devHelper.SetNetDevicePointToPointMode(true);
2142
2144 NetDeviceContainer d01 = devHelper.Install(nodes.Get(0), channel1);
2145 d01.Add(devHelper.Install(nodes.Get(1), channel1));
2146
2148 NetDeviceContainer d23 = devHelper.Install(nodes.Get(2), channel2);
2149 d23.Add(devHelper.Install(nodes.Get(3), channel2));
2150
2152 NetDeviceContainer d02 = devHelper.Install(nodes.Get(0), channel3);
2153 d02.Add(devHelper.Install(nodes.Get(2), channel3));
2154
2156 NetDeviceContainer d34 = devHelper.Install(nodes.Get(3), channel4);
2157 d34.Add(devHelper.Install(nodes.Get(4), channel4));
2158
2160 NetDeviceContainer d13 = devHelper.Install(nodes.Get(1), channel5);
2161 d13.Add(devHelper.Install(nodes.Get(3), channel5));
2162
2163 devHelper.SetNetDevicePointToPointMode(false);
2164
2166 NetDeviceContainer d45 = devHelper.Install(nodes.Get(4), channel6);
2167 d45.Add(devHelper.Install(nodes.Get(5), channel6));
2168
2169 // Assign IP addresses to the devices
2170 Ipv4AddressHelper address;
2171 address.SetBase("10.1.1.0", "255.255.255.252");
2172 Ipv4InterfaceContainer i01 = address.Assign(d01);
2173
2174 address.SetBase("10.1.2.0", "255.255.255.252");
2175 Ipv4InterfaceContainer i02 = address.Assign(d02);
2176
2177 address.SetBase("10.1.3.0", "255.255.255.252");
2178 Ipv4InterfaceContainer i13 = address.Assign(d13);
2179
2180 address.SetBase("10.1.4.0", "255.255.255.224");
2181 Ipv4InterfaceContainer i23 = address.Assign(d23);
2182
2183 address.SetBase("10.1.5.0", "255.255.255.0");
2184 Ipv4InterfaceContainer i34 = address.Assign(d34);
2185
2186 address.SetBase("10.1.6.0", "255.255.255.0");
2187 Ipv4InterfaceContainer i45 = address.Assign(d45);
2188
2189 Ipv6AddressHelper ipv6;
2190 ipv6.SetBase("2001:1::", Ipv6Prefix(64));
2191 ipv6.Assign(d01);
2192 ipv6.SetBase("2001:2::", Ipv6Prefix(64));
2193 ipv6.Assign(d02);
2194 ipv6.SetBase("2001:3::", Ipv6Prefix(64));
2195 ipv6.Assign(d13);
2196 ipv6.SetBase("2001:4::", Ipv6Prefix(64));
2197 ipv6.Assign(d23);
2198 ipv6.SetBase("2001:5::", Ipv6Prefix(64));
2199 ipv6.Assign(d34);
2200 ipv6.SetBase("2001:6::", Ipv6Prefix(64));
2201 ipv6.Assign(d45);
2202}
2203
2204void
2206{
2207 // The purpose of this test is to make sure the code doesn't crash when calculating ECMP routes
2208 // with a topology described in issue #1243. It does not look into the correctness of the
2209 // routes. We have other tests to make sure the routes are correct.
2212
2216}
2217
2218/**
2219 * @ingroup internet-test
2220 *
2221 * @brief TestCase to check calls to GlobalRoutingProtocol API. This TestCase Checks the output
2222 * returned by the GlobalRoutingProtocol API to Ipv4L3 Layer.
2223 */
2225{
2226 public:
2229
2230 private:
2231 void DoSetup() override;
2232 void DoRun() override;
2233 /**
2234 * @brief Checks the Path taken by packets by calling RouteInput() and RouteOutput() APIs of
2235 * GlobalRoutingProtocol. This mimics how Ipv4L3Protocol calls these APIs.
2236 * @param pathNodes Vector of nodes in the path. This includes the source node,Intermediate
2237 * nextHop nodes and the destination node.
2238 * @param path Vector of Ipv4Addresses in the path. This includes the source egress IpAddress,
2239 * destination ingress IpAddress and intermediate nextHop Node's ingress Ipaddress that we need
2240 * to check.It does not include the egress addresses for intermediate nodes.
2241 */
2242 void CheckPath(std::vector<Ptr<Node>> pathNodes, std::vector<Ipv4Address> path);
2243
2244 /**
2245 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
2246 * @param route Route to be used for forwarding
2247 * @param packet Packet to be forwarded
2248 * @param header IPv4 header of the packet
2249 */
2251 Ptr<const Packet> packet,
2252 const Ipv4Header& header);
2253 /**
2254 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
2255 * @param packet Packet to be locally delivered
2256 * @param header IPv4 header of the packet
2257 * @param iif Ingress Interface index
2258 */
2259 void MyLocalDeliverCallback(Ptr<const Packet> packet, const Ipv4Header& header, uint32_t iif);
2260 /**
2261 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
2262 * @param packet Packet to be locally delivered
2263 * @param header IPv4 header of the packet
2264 * @param errno_ Socket error number
2265 */
2267 const Ipv4Header& header,
2268 Socket::SocketErrno errno_);
2269
2270 NodeContainer nodes; //!< Nodes used in the test.
2271 Ptr<Ipv4Route> m_lastRoute; //!< Route to be tested.
2276};
2277
2278// Signature: void (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header &header)
2279void
2281 Ptr<const Packet> packet,
2282 const Ipv4Header& header)
2283{
2284 NS_LOG_DEBUG("Unicast Forward Callback called.");
2285 m_lastRoute = route;
2286}
2287
2288// Signature: void (Ptr<const Packet>, const Ipv4Header&, uint32_t)
2289void
2291 const Ipv4Header& header,
2292 uint32_t iif)
2293{
2294 NS_LOG_DEBUG("Local Deliver Callback called.");
2295}
2296
2297// Signature: void (Ptr<const Packet>, const Ipv4Header&, Socket::SocketErrno)
2298void
2300 const Ipv4Header& header,
2301 Socket::SocketErrno errno_)
2302{
2303 NS_LOG_DEBUG("Error Callback called.");
2304 // Fail the test if this callback is called
2305 NS_TEST_ASSERT_MSG_EQ(1, 1, "Error Callback called in RouteInput");
2306}
2307
2317
2321
2322void
2324 std::vector<Ipv4Address> path)
2325{
2326 uint32_t pathSize = path.size();
2327
2328 Ptr<Ipv4L3Protocol> ip = pathNodes[0]->GetObject<Ipv4L3Protocol>();
2329 NS_TEST_ASSERT_MSG_NE(ip, nullptr, "Error-- no Ipv4 object at source node");
2330 Ptr<Ipv4RoutingProtocol> routing = ip->GetRoutingProtocol();
2331 NS_TEST_ASSERT_MSG_NE(routing,
2332 nullptr,
2333 "Error-- no Ipv4 routing protocol object at source node");
2334 Ptr<Ipv4GlobalRouting> globalRouting = routing->GetObject<Ipv4GlobalRouting>();
2335 NS_TEST_ASSERT_MSG_NE(globalRouting,
2336 nullptr,
2337 "Error-- no Ipv4GlobalRouting object at source node");
2338
2339 Socket::SocketErrno errno_;
2340 Ptr<NetDevice> oif(nullptr);
2341 Ptr<Packet> packet = Create<Packet>();
2342 Ipv4Header ipHeader;
2343 ipHeader.SetSource(path[0]);
2344 ipHeader.SetDestination(path[pathSize - 1]);
2345
2346 // for the source node we need to call RouteOutput()
2347 m_lastRoute = globalRouting->RouteOutput(packet, ipHeader, oif, errno_);
2348 // for the rest of the nodes we need to call RouteInput()
2349 for (uint32_t i = 1; i < pathSize; i++)
2350 {
2351 // for each iteration except the last one check that the UnicastForward Callback is called.
2352 // For the last node that is the destination node LocalDelivery Callback will be called.
2353 if (i != pathSize - 1)
2354 {
2355 NS_TEST_ASSERT_MSG_EQ(m_lastRoute->GetGateway(), path[i], "Error-- wrong gateway");
2356 }
2357
2358 ip = pathNodes[i]->GetObject<Ipv4L3Protocol>();
2359 NS_TEST_ASSERT_MSG_NE(ip, nullptr, "Error-- no Ipv4 object at node");
2360 routing = ip->GetRoutingProtocol();
2361 NS_TEST_ASSERT_MSG_NE(routing, nullptr, "Error-- no Ipv4 routing protocol object at node");
2362 globalRouting = routing->GetObject<Ipv4GlobalRouting>();
2363 NS_TEST_ASSERT_MSG_NE(globalRouting,
2364 nullptr,
2365 "Error-- no Ipv4GlobalRouting object at node");
2366
2367 Ptr<Ipv4Interface> interf = ip->GetInterface(ip->GetInterfaceForAddress(path[i]));
2368 Ptr<NetDevice> idevice = interf->GetDevice();
2369
2370 // call RouteInput() for the next node in the path
2371 globalRouting->RouteInput(packet, ipHeader, idevice, m_ucb, m_mcb, m_lcb, m_ecb);
2372 }
2373}
2374
2375void
2377{
2378 /**
2379 * This test case is designed to test the overall functionality of the GlobalRoutingProtocol.
2380 * It tests the calls to the GlobalRoutingProtocol's RouteOutput() and RouteInput() APIs.
2381 * It mimics how Ipv4L3Protocol calls these APIs. The topology covers most of the cases
2382 * that are expected to be handled by the GlobalRoutingProtocol.
2383 */
2384
2385 //
2386 //
2387 // Network topology
2388 //
2389 // n0
2390 // \ p-p
2391 // \ (shared csma/cd)
2392 // n2 -------------------------n3
2393 // / | |
2394 // / p-p n4 n5 ---------- n6-------n7----Bridge-n8--------n9
2395 // n1 p-p | 10.1.4.0/24
2396 // | |
2397 // ----------------------------------------
2398 // p-p
2399 //
2400 //
2401 //
2402
2403 nodes.Create(10);
2404 NodeContainer n2345 = NodeContainer(nodes.Get(2), nodes.Get(3), nodes.Get(4), nodes.Get(5));
2405
2406 // We create the channels first without any IP addressing information
2407 SimpleNetDeviceHelper devHelper;
2408
2409 devHelper.SetNetDevicePointToPointMode(true);
2410
2412 NetDeviceContainer d0d2 = devHelper.Install(nodes.Get(0), channel1);
2413 d0d2.Add(devHelper.Install(nodes.Get(2), channel1));
2414
2416 NetDeviceContainer d1d6 = devHelper.Install(nodes.Get(1), channel2);
2417 d1d6.Add(devHelper.Install(nodes.Get(6), channel2));
2418
2420 NetDeviceContainer d1d2 = devHelper.Install(nodes.Get(1), channel3);
2421 d1d2.Add(devHelper.Install(nodes.Get(2), channel3));
2422
2424 NetDeviceContainer d5d6 = devHelper.Install(nodes.Get(5), channel4);
2425 d5d6.Add(devHelper.Install(nodes.Get(6), channel4));
2426
2428 devHelper.SetNetDevicePointToPointMode(false);
2429 NetDeviceContainer d6d7 = devHelper.Install(nodes.Get(6), channel5);
2430 d6d7.Add(devHelper.Install(nodes.Get(7), channel5));
2431
2432 devHelper.SetNetDevicePointToPointMode(false);
2433 NetDeviceContainer d2345 = devHelper.Install(n2345);
2434
2435 // handle the bridge
2436 // connect node 7 to node 8(Switch)
2438 NetDeviceContainer d78 = devHelper.Install(nodes.Get(7), channel6);
2439 d78.Add(devHelper.Install(nodes.Get(8), channel6));
2440
2441 // connect node 8(switch) to node 9
2443 NetDeviceContainer d89 = devHelper.Install(nodes.Get(8), channel7);
2444 d89.Add(devHelper.Install(nodes.Get(9), channel7));
2445
2446 NetDeviceContainer bridgeFacingDevices;
2447 NetDeviceContainer switchDevices;
2448 bridgeFacingDevices.Add(d78.Get(0));
2449 switchDevices.Add(d78.Get(1));
2450 bridgeFacingDevices.Add(d89.Get(1));
2451 switchDevices.Add(d89.Get(0));
2452
2453 Ptr<Node> switchNode = nodes.Get(8);
2454 BridgeHelper bridge;
2455 bridge.Install(switchNode, switchDevices);
2456
2457 InternetStackHelper internet;
2458 Ipv4GlobalRoutingHelper glbrouting;
2459 internet.SetRoutingHelper(glbrouting);
2460 internet.Install(nodes.Get(0));
2461 internet.Install(nodes.Get(1));
2462 internet.Install(nodes.Get(2));
2463 internet.Install(nodes.Get(3));
2464 internet.Install(nodes.Get(4));
2465 internet.Install(nodes.Get(5));
2466 internet.Install(nodes.Get(6));
2467 internet.Install(nodes.Get(7));
2468 // node 8 is a bridge node
2469 internet.Install(nodes.Get(9));
2470
2471 // Later, we add IP addresses.
2472 Ipv4AddressHelper ipv4;
2473 ipv4.SetBase("10.1.1.0", "255.255.255.0");
2474 Ipv4InterfaceContainer i0d2 = ipv4.Assign(d0d2);
2475
2476 ipv4.SetBase("10.1.2.0", "255.255.255.0");
2477 Ipv4InterfaceContainer i1d2 = ipv4.Assign(d1d2);
2478
2479 ipv4.SetBase("10.1.3.0", "255.255.255.0");
2480 Ipv4InterfaceContainer i5i6 = ipv4.Assign(d5d6);
2481
2482 ipv4.SetBase("10.250.1.0", "255.255.255.0");
2483 Ipv4InterfaceContainer i2345 = ipv4.Assign(d2345);
2484
2485 ipv4.SetBase("172.16.1.0", "255.255.255.0");
2486 Ipv4InterfaceContainer i1i6 = ipv4.Assign(d1d6);
2487
2488 ipv4.SetBase("10.1.4.0", "255.255.255.0");
2489 Ipv4InterfaceContainer i67 = ipv4.Assign(d6d7);
2490
2491 ipv4.SetBase("10.1.5.0", "255.255.255.0");
2492 Ipv4InterfaceContainer i79 = ipv4.Assign(bridgeFacingDevices);
2493}
2494
2495void
2497{
2498 // Create router nodes, initialize routing database and set up the routing
2499 // tables in the nodes.
2501
2503
2504 // tests-------------------------
2505 // test 1:check path from n0 to n6
2506 // test 2:check path from n1 to n5
2507 // test 3:check path from n1 to n9
2508 // test 4:check path from n8 to n0
2509
2510 // Test 1: check path from n0 to n6
2511 std::vector<Ipv4Address>
2512 pathToCheck1; // includes the source egress destination ingress and intermediate next hops
2513 // addresses that we need to check.It does not include the egress addresses
2514 // for intermediate nodes.
2515 pathToCheck1.emplace_back("10.1.1.1");
2516 pathToCheck1.emplace_back("10.1.1.2");
2517 pathToCheck1.emplace_back("10.1.2.1");
2518 pathToCheck1.emplace_back("172.16.1.2");
2519
2520 std::vector<Ptr<Node>>
2521 pathNodes1; // nodes in the path. Includes the source node and the destination node.
2522 pathNodes1.push_back(nodes.Get(0));
2523 pathNodes1.push_back(nodes.Get(2));
2524 pathNodes1.push_back(nodes.Get(1));
2525 pathNodes1.push_back(nodes.Get(6));
2526
2527 CheckPath(pathNodes1, pathToCheck1);
2528
2529 // Test 2:check path from n1 to n5
2530 std::vector<Ipv4Address> pathToCheck2;
2531 pathToCheck2.emplace_back("10.1.2.1");
2532 pathToCheck2.emplace_back("10.1.2.2");
2533 pathToCheck2.emplace_back("10.250.1.4");
2534
2535 std::vector<Ptr<Node>> pathNodes2;
2536 pathNodes2.push_back(nodes.Get(1));
2537 pathNodes2.push_back(nodes.Get(2));
2538 pathNodes2.push_back(nodes.Get(5));
2539
2540 CheckPath(pathNodes2, pathToCheck2);
2541
2542 // Test 3:check path from n1 to n9
2543 std::vector<Ipv4Address> pathToCheck3;
2544 pathToCheck3.emplace_back("172.16.1.1");
2545 pathToCheck3.emplace_back("172.16.1.2");
2546 pathToCheck3.emplace_back("10.1.4.2");
2547 pathToCheck3.emplace_back("10.1.5.2");
2548
2549 std::vector<Ptr<Node>> pathNodes3;
2550 pathNodes3.push_back(nodes.Get(1));
2551 pathNodes3.push_back(nodes.Get(6));
2552 pathNodes3.push_back(nodes.Get(7));
2553 pathNodes3.push_back(nodes.Get(9));
2554
2555 CheckPath(pathNodes3, pathToCheck3);
2556
2557 // Test 4:check path from n9 to n0
2558 std::vector<Ipv4Address> pathToCheck4;
2559 pathToCheck4.emplace_back("10.1.5.2");
2560 pathToCheck4.emplace_back("10.1.5.1");
2561 pathToCheck4.emplace_back("10.1.4.1");
2562 pathToCheck4.emplace_back("10.1.3.1");
2563 pathToCheck4.emplace_back("10.250.1.1");
2564 pathToCheck4.emplace_back("10.1.1.1");
2565
2566 std::vector<Ptr<Node>> pathNodes4;
2567 pathNodes4.push_back(nodes.Get(9));
2568 pathNodes4.push_back(nodes.Get(7));
2569 pathNodes4.push_back(nodes.Get(6));
2570 pathNodes4.push_back(nodes.Get(5));
2571 pathNodes4.push_back(nodes.Get(2));
2572 pathNodes4.push_back(nodes.Get(0));
2573
2574 CheckPath(pathNodes4, pathToCheck4);
2575
2579}
2580
2581/**
2582 * @ingroup internet-test
2583 *
2584 * @brief TestCase to check calls to GlobalRoutingProtocol API. This TestCase Checks the output
2585 * returned by the GlobalRoutingProtocol API to Ipv4L3 Layer.
2586 */
2588{
2589 public:
2592
2593 private:
2594 void DoSetup() override;
2595 void DoRun() override;
2596 /**
2597 * @brief Checks the Path taken by packets by calling RouteInput() and RouteOutput() APIs of
2598 * GlobalRoutingProtocol. This mimics how Ipv4L3Protocol calls these APIs.
2599 * @param pathNodes Vector of nodes in the path. This includes the source node,Intermediate
2600 * nextHop nodes and the destination node.
2601 * @param path Vector of Ipv4Addresses in the path. This includes the source egress IpAddress,
2602 * destination ingress IpAddress and intermediate nextHop Node's ingress Ipaddress that we need
2603 * to check.It does not include the egress addresses for intermediate nodes.
2604 */
2605 void CheckPath(std::vector<Ptr<Node>> pathNodes, std::vector<Ipv6Address> path);
2606
2607 /**
2608 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
2609 *
2610 * @param idev The ingress netdevice
2611 * @param rtentry The route entry
2612 * @param p The packet
2613 * @param header The IPv6 header of the packet
2614 */
2616 Ptr<Ipv6Route> rtentry,
2618 const Ipv6Header& header);
2619 /**
2620 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
2621 * @param packet Packet to be locally delivered
2622 * @param header IPv6 header of the packet
2623 * @param iif Ingress Interface index
2624 */
2625 void MyLocalDeliverCallback(Ptr<const Packet> packet, const Ipv6Header& header, uint32_t iif);
2626 /**
2627 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
2628 * @param packet Packet to be locally delivered
2629 * @param header IPv6 header of the packet
2630 * @param errno_ Socket error number
2631 */
2633 const Ipv6Header& header,
2634 Socket::SocketErrno errno_);
2635
2636 NodeContainer nodes; //!< Nodes used in the test.
2637 Ptr<Ipv6Route> m_lastRoute; //!< Route to be tested.
2642};
2643
2644// Signature: void (Ptr<Ipv6Route> route, Ptr<const Packet> packet, const Ipv4Header &header)
2645void
2647 Ptr<Ipv6Route> rtentry,
2649 const Ipv6Header& header)
2650{
2651 NS_LOG_DEBUG("Unicast Forward Callback called.");
2652 m_lastRoute = rtentry;
2653}
2654
2655// Signature: void (Ptr<const Packet>, const Ipv4Header&, uint32_t)
2656void
2658 const Ipv6Header& header,
2659 uint32_t iif)
2660{
2661 NS_LOG_DEBUG("Local Deliver Callback called.");
2662}
2663
2664// Signature: void (Ptr<const Packet>, const Ipv4Header&, Socket::SocketErrno)
2665void
2667 const Ipv6Header& header,
2668 Socket::SocketErrno errno_)
2669{
2670 NS_LOG_DEBUG("Error Callback called.");
2671 // Fail the test if this callback is called
2672 NS_TEST_ASSERT_MSG_EQ(1, 1, "Error Callback called in RouteInput");
2673}
2674
2684
2688
2689void
2691 std::vector<Ipv6Address> path)
2692{
2693 uint32_t pathSize = path.size();
2694
2695 Ptr<Ipv6L3Protocol> ip = pathNodes[0]->GetObject<Ipv6L3Protocol>();
2696 NS_TEST_ASSERT_MSG_NE(ip, nullptr, "Error-- no Ipv4 object at source node");
2697 Ptr<Ipv6RoutingProtocol> routing = ip->GetRoutingProtocol();
2698 NS_TEST_ASSERT_MSG_NE(routing,
2699 nullptr,
2700 "Error-- no Ipv4 routing protocol object at source node");
2701 Ptr<Ipv6GlobalRouting> globalRouting = routing->GetObject<Ipv6GlobalRouting>();
2702 NS_TEST_ASSERT_MSG_NE(globalRouting,
2703 nullptr,
2704 "Error-- no Ipv4GlobalRouting object at source node");
2705
2706 Socket::SocketErrno errno_;
2707 Ptr<NetDevice> oif(nullptr);
2708 Ptr<Packet> packet = Create<Packet>();
2709 Ipv6Header ipHeader;
2710 ipHeader.SetSource(path[0]);
2711
2712 ipHeader.SetDestination(path[pathSize - 1]);
2713
2714 // for the source node we need to call RouteOutput()
2715 m_lastRoute = globalRouting->RouteOutput(packet, ipHeader, oif, errno_);
2716 // for the rest of the nodes we need to call RouteInput()
2717 for (uint32_t i = 1; i < pathSize; i++)
2718 {
2719 // for each iteration except the last one check that the UnicastForward Callback is called.
2720 // For the last node that is the destination node LocalDelivery Callback will be called.
2721 if (i != pathSize - 1)
2722 {
2723 NS_TEST_ASSERT_MSG_EQ(m_lastRoute->GetGateway(), path[i], "Error-- wrong gateway");
2724 }
2725
2726 ip = pathNodes[i]->GetObject<Ipv6L3Protocol>();
2727 NS_TEST_ASSERT_MSG_NE(ip, nullptr, "Error-- no Ipv6 object at node");
2728 routing = ip->GetRoutingProtocol();
2729 NS_TEST_ASSERT_MSG_NE(routing, nullptr, "Error-- no Ipv6 routing protocol object at node");
2730 globalRouting = routing->GetObject<Ipv6GlobalRouting>();
2731 NS_TEST_ASSERT_MSG_NE(globalRouting,
2732 nullptr,
2733 "Error-- no Ipv4GlobalRouting object at node");
2734
2735 Ptr<Ipv6Interface> interf = ip->GetInterface(ip->GetInterfaceForAddress(path[i]));
2736 Ptr<NetDevice> idevice = interf->GetDevice();
2737
2738 // call RouteInput() for the next node in the path
2739 globalRouting->RouteInput(packet, ipHeader, idevice, m_ucb, m_mcb, m_lcb, m_ecb);
2740 }
2741}
2742
2743void
2745{
2746 /**
2747 * This test case is designed to test the overall functionality of the GlobalRoutingProtocol.
2748 * It tests the calls to the GlobalRoutingProtocol's RouteOutput() and RouteInput() APIs.
2749 * It mimics how Ipv4L3Protocol calls these APIs. The topology covers most of the cases
2750 * that are expected to be handled by the GlobalRoutingProtocol.
2751 */
2752
2753 //
2754 //
2755 // Network topology
2756 //
2757 // n0
2758 // \ p-p
2759 // \ (shared csma/cd)
2760 // n2 -------------------------n3
2761 // / | |
2762 // / p-p n4 n5 ---------- n6-------n7----Bridge-n8--------n9
2763 // n1 p-p | 10.1.4.0/24
2764 // | |
2765 // ----------------------------------------
2766 // p-p
2767 //
2768 //
2769 //
2770
2771 nodes.Create(10);
2772 NodeContainer n2345 = NodeContainer(nodes.Get(2), nodes.Get(3), nodes.Get(4), nodes.Get(5));
2773
2774 // We create the channels first without any IP addressing information
2775 SimpleNetDeviceHelper devHelper;
2776
2777 devHelper.SetNetDevicePointToPointMode(true);
2778
2780 NetDeviceContainer d0d2 = devHelper.Install(nodes.Get(0), channel1);
2781 d0d2.Add(devHelper.Install(nodes.Get(2), channel1));
2782
2784 NetDeviceContainer d1d6 = devHelper.Install(nodes.Get(1), channel2);
2785 d1d6.Add(devHelper.Install(nodes.Get(6), channel2));
2786
2788 NetDeviceContainer d1d2 = devHelper.Install(nodes.Get(1), channel3);
2789 d1d2.Add(devHelper.Install(nodes.Get(2), channel3));
2790
2792 NetDeviceContainer d5d6 = devHelper.Install(nodes.Get(5), channel4);
2793 d5d6.Add(devHelper.Install(nodes.Get(6), channel4));
2794
2796 devHelper.SetNetDevicePointToPointMode(false);
2797 NetDeviceContainer d6d7 = devHelper.Install(nodes.Get(6), channel5);
2798 d6d7.Add(devHelper.Install(nodes.Get(7), channel5));
2799
2800 devHelper.SetNetDevicePointToPointMode(false);
2801 NetDeviceContainer d2345 = devHelper.Install(n2345);
2802
2803 // handle the bridge
2804 // connect node 7 to node 8(Switch)
2806 NetDeviceContainer d78 = devHelper.Install(nodes.Get(7), channel6);
2807 d78.Add(devHelper.Install(nodes.Get(8), channel6));
2808
2809 // connect node 8(switch) to node 9
2811 NetDeviceContainer d89 = devHelper.Install(nodes.Get(8), channel7);
2812 d89.Add(devHelper.Install(nodes.Get(9), channel7));
2813
2814 NetDeviceContainer bridgeFacingDevices;
2815 NetDeviceContainer switchDevices;
2816 bridgeFacingDevices.Add(d78.Get(0));
2817 switchDevices.Add(d78.Get(1));
2818 bridgeFacingDevices.Add(d89.Get(1));
2819 switchDevices.Add(d89.Get(0));
2820
2821 Ptr<Node> switchNode = nodes.Get(8);
2822 BridgeHelper bridge;
2823 bridge.Install(switchNode, switchDevices);
2824
2825 InternetStackHelper internet;
2826 Ipv6GlobalRoutingHelper glbrouting;
2827 internet.SetRoutingHelper(glbrouting);
2828 internet.Install(nodes.Get(0));
2829 internet.Install(nodes.Get(1));
2830 internet.Install(nodes.Get(2));
2831 internet.Install(nodes.Get(3));
2832 internet.Install(nodes.Get(4));
2833 internet.Install(nodes.Get(5));
2834 internet.Install(nodes.Get(6));
2835 internet.Install(nodes.Get(7));
2836 // node 8 is a bridge node
2837 internet.Install(nodes.Get(9));
2838
2839 // Later, we add IP addresses.
2840 Ipv6AddressHelper ipv6;
2841 ipv6.SetBase("2001:1::", Ipv6Prefix(64));
2842 Ipv6InterfaceContainer i0d2 = ipv6.Assign(d0d2);
2843
2844 ipv6.SetBase("2001:2::", Ipv6Prefix(64));
2845 Ipv6InterfaceContainer i1d2 = ipv6.Assign(d1d2);
2846
2847 ipv6.SetBase("2001:3::", Ipv6Prefix(64));
2848 Ipv6InterfaceContainer i5i6 = ipv6.Assign(d5d6);
2849
2850 ipv6.SetBase("2001:4::", Ipv6Prefix(64));
2851 Ipv6InterfaceContainer i2345 = ipv6.Assign(d2345);
2852
2853 ipv6.SetBase("2001:5::", Ipv6Prefix(64));
2854 Ipv6InterfaceContainer i1i6 = ipv6.Assign(d1d6);
2855
2856 ipv6.SetBase("2001:6::", Ipv6Prefix(64));
2857 Ipv6InterfaceContainer i67 = ipv6.Assign(d6d7);
2858
2859 ipv6.SetBase("2001:7::", Ipv6Prefix(64));
2860 Ipv6InterfaceContainer i79 = ipv6.Assign(bridgeFacingDevices);
2861}
2862
2863void
2865{
2866 // Create router nodes, initialize routing database and set up the routing
2867 // tables in the nodes.
2869
2871
2872 // tests-------------------------
2873 // test 1:check path from n0 to n6
2874 // test 2:check path from n1 to n5
2875 // test 3:check path from n1 to n9
2876 // test 4:check path from n8 to n0
2877
2878 // Test 1: check path from n0 to n6
2879 std::vector<Ipv6Address>
2880 pathToCheck1; // includes the source egress destination ingress and intermediate next hops
2881 // addresses that we need to check.It does not include the egress addresses
2882 // for intermediate nodes.
2883 pathToCheck1.emplace_back("2001:1::200:ff:fe00:1");
2884 pathToCheck1.emplace_back("fe80::200:ff:fe00:2");
2885 pathToCheck1.emplace_back("fe80::200:ff:fe00:5");
2886 pathToCheck1.emplace_back("2001:5::200:ff:fe00:4");
2887
2888 std::vector<Ptr<Node>>
2889 pathNodes1; // nodes in the path. Includes the source node and the destination node.
2890 pathNodes1.push_back(nodes.Get(0));
2891 pathNodes1.push_back(nodes.Get(2));
2892 pathNodes1.push_back(nodes.Get(1));
2893 pathNodes1.push_back(nodes.Get(6));
2894 CheckPath(pathNodes1, pathToCheck1);
2895
2896 // Test 2:check path from n1 to n5
2897 std::vector<Ipv6Address> pathToCheck2;
2898 pathToCheck2.emplace_back("2001:2::200:ff:fe00:5");
2899 pathToCheck2.emplace_back("fe80::200:ff:fe00:4");
2900 pathToCheck2.emplace_back("2001:3::200:ff:fe00:7");
2901 std::vector<Ptr<Node>> pathNodes2;
2902 pathNodes2.push_back(nodes.Get(1));
2903 pathNodes2.push_back(nodes.Get(6));
2904 pathNodes2.push_back(nodes.Get(5));
2905
2906 CheckPath(pathNodes2, pathToCheck2);
2907 // Test 3:check path from n1 to n9
2908 std::vector<Ipv6Address> pathToCheck3;
2909 pathToCheck3.emplace_back("2001:2::200:ff:fe00:6");
2910 pathToCheck3.emplace_back("fe80::200:ff:fe00:4");
2911 pathToCheck3.emplace_back("fe80::200:ff:fe00:a");
2912 pathToCheck3.emplace_back("2001:7::200:ff:fe00:12");
2913
2914 std::vector<Ptr<Node>> pathNodes3;
2915 pathNodes3.push_back(nodes.Get(1));
2916 pathNodes3.push_back(nodes.Get(6));
2917 pathNodes3.push_back(nodes.Get(7));
2918 pathNodes3.push_back(nodes.Get(9));
2919
2920 CheckPath(pathNodes3, pathToCheck3);
2921
2922 // Test 4:check path from n9 to n0
2923 std::vector<Ipv6Address> pathToCheck4;
2924 pathToCheck4.emplace_back("2001:7::200:ff:fe00:12");
2925 pathToCheck4.emplace_back("fe80::200:ff:fe00:f");
2926 pathToCheck4.emplace_back("fe80::200:ff:fe00:9");
2927 pathToCheck4.emplace_back("fe80::200:ff:fe00:3");
2928 pathToCheck4.emplace_back("fe80::200:ff:fe00:6");
2929 pathToCheck4.emplace_back("2001:1::200:ff:fe00:1");
2930
2931 std::vector<Ptr<Node>> pathNodes4;
2932 pathNodes4.push_back(nodes.Get(9));
2933 pathNodes4.push_back(nodes.Get(7));
2934 pathNodes4.push_back(nodes.Get(6));
2935 pathNodes4.push_back(nodes.Get(1));
2936 pathNodes4.push_back(nodes.Get(2));
2937 pathNodes4.push_back(nodes.Get(0));
2938 CheckPath(pathNodes4, pathToCheck4);
2939
2943}
2944
2945/**
2946 * @ingroup internet-test
2947 *
2948 * @brief IPv4 GlobalRouting TestSuite
2949 */
2951{
2952 public:
2954};
2955
2972
2974 g_globalRoutingTestSuite; //!< Static variable for test initialization
NodeContainer n1n2
Nodecontainer n1 + n2.
NodeContainer n0n2
Nodecontainer n0 + n2.
GlobalRouting Bridge test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
This TestCase tests if ECMP Route Calculation works.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
NodeContainer nodes
Nodes used in the test.
TestCase to check calls to GlobalRoutingProtocol API.
void DoRun() override
Implementation to actually run this TestCase.
Ipv4RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void MyErrorCallback(Ptr< const Packet > packet, const Ipv4Header &header, Socket::SocketErrno errno_)
Callback function for RouteInput() API of GlobalRoutingProtocol.
NodeContainer nodes
Nodes used in the test.
void MyLocalDeliverCallback(Ptr< const Packet > packet, const Ipv4Header &header, uint32_t iif)
Callback function for RouteInput() API of GlobalRoutingProtocol.
void MyUnicastCallback(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Callback function for RouteInput() API of GlobalRoutingProtocol.
Ipv4RoutingProtocol::LocalDeliverCallback m_lcb
Local delivery callback.
void CheckPath(std::vector< Ptr< Node > > pathNodes, std::vector< Ipv4Address > path)
Checks the Path taken by packets by calling RouteInput() and RouteOutput() APIs of GlobalRoutingProto...
Ipv4RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
Ptr< Ipv4Route > m_lastRoute
Route to be tested.
Ipv4RoutingProtocol::ErrorCallback m_ecb
Error callback.
TestCase to check calls to GlobalRoutingProtocol API.
Ptr< Ipv6Route > m_lastRoute
Route to be tested.
void CheckPath(std::vector< Ptr< Node > > pathNodes, std::vector< Ipv6Address > path)
Checks the Path taken by packets by calling RouteInput() and RouteOutput() APIs of GlobalRoutingProto...
Ipv6RoutingProtocol::LocalDeliverCallback m_lcb
Local delivery callback.
void MyUnicastCallback(Ptr< const NetDevice > idev, Ptr< Ipv6Route > rtentry, Ptr< const Packet > p, const Ipv6Header &header)
Callback function for RouteInput() API of GlobalRoutingProtocol.
NodeContainer nodes
Nodes used in the test.
void MyErrorCallback(Ptr< const Packet > packet, const Ipv6Header &header, Socket::SocketErrno errno_)
Callback function for RouteInput() API of GlobalRoutingProtocol.
void MyLocalDeliverCallback(Ptr< const Packet > packet, const Ipv6Header &header, uint32_t iif)
Callback function for RouteInput() API of GlobalRoutingProtocol.
Ipv6RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Ipv6RoutingProtocol::ErrorCallback m_ecb
Error callback.
Ipv6RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
void DoRun() override
Implementation to actually run this TestCase.
std::vector< uint8_t > m_secondInterface
Packets received on the 2nd interface at a given time.
void HandleRead(Ptr< Socket > socket)
Handle an incoming packet.
uint16_t m_count
Number of packets received.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Sending sockets.
std::vector< uint8_t > m_firstInterface
Packets received on the 1st interface at a given time.
NodeContainer c
nodes in the topology
void ShutDownSock(uint8_t index)
Shutdown a socket.
void SendData(uint8_t index)
Send some data.
IPv4 Dynamic GlobalRouting /32 test.
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
void SendData(Ptr< Socket > socket, std::string to)
Send a packet.
void DoRun() override
Implementation to actually run this TestCase.
void DoSendData(Ptr< Socket > socket, std::string to)
Send a packet.
Ptr< Packet > m_receivedPacket
number of received packets
IPv4 GlobalRouting TestSuite.
uint16_t m_count
Number of packets received.
std::vector< std::pair< Ptr< Socket >, bool > > m_sendSocks
Sending sockets.
void SendData(uint8_t index)
Send some data.
std::vector< uint8_t > m_secondInterface
Packets received on the 2nd interface at a given time.
void ShutDownSock(uint8_t index)
Shutdown a socket.
std::vector< uint8_t > m_firstInterface
Packets received on the 1st interface at a given time.
void DoRun() override
Implementation to actually run this TestCase.
void HandleRead(Ptr< Socket > socket)
Handle an incoming packet.
NodeContainer c
nodes in the topology
void SetInterfaceUp(Ptr< Ipv6 > ipv6, uint32_t ifIndex, Ipv6InterfaceAddress address)
This function does two things, set the specified ipv6 interface as up and Adds the specified Ipv6Addr...
GlobalRouting LAN test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
GlobalRouting Two bridges test.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
NodeContainer m_nodes
Nodes used in the test.
GlobalRouting Two LAN test.
NodeContainer m_nodes
Nodes used in the test.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
a polymophic address class
Definition address.h:114
AttributeValue implementation for Boolean.
Definition boolean.h:26
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging).
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
Class for representing data rates.
Definition data-rate.h:78
static void ResetRouterId()
Reset the router ID counter to zero.
An Inet6 address class.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Helper class that adds ns3::Ipv4GlobalRouting objects.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
Packet header for IPv4.
Definition ipv4-header.h:23
void SetDestination(Ipv4Address destination)
void SetSource(Ipv4Address source)
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
virtual void SetUp(uint32_t interface)=0
virtual void SetDown(uint32_t interface)=0
a class to store IPv4 address information on an interface
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Implement the IPv4 layer.
a class to represent an Ipv4 address mask
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
uint32_t GetRecvIf() const
Get the tag's receiving interface.
Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const Ipv4Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv4Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
Callback< void, Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found).
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Helper class that adds ns3::Ipv4GlobalRouting objects.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
Packet header for IPv6.
Definition ipv6-header.h:24
void SetDestination(Ipv6Address dst)
Set the "Destination address" field.
void SetSource(Ipv6Address src)
Set the "Source address" field.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
virtual void SetDown(uint32_t interface)=0
Set the interface into the "down" state.
IPv6 address associated with an interface.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
IPv6 layer implementation.
This class implements a tag that carries socket ancillary data to the socket interface.
uint32_t GetRecvIf() const
Get the tag's receiving interface.
Describes an IPv6 prefix.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
Callback< void, Ptr< const Packet >, const Ipv6Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found).
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6MulticastRoute >, Ptr< const Packet >, const Ipv6Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv6Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6Route >, Ptr< const Packet >, const Ipv6Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
A record of an IPv6 route.
Ipv6Address GetDest() const
Get the destination.
Ipv6Prefix GetDestNetworkPrefix() const
Get the destination prefix.
Ipv6Address GetGateway() const
Get the gateway.
static Mac48Address Allocate()
Allocate a new Mac48Address.
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
void SetDynamicNeighborCache(bool enable)
Enable/disable dynamic neighbor cache, auto-generated neighbor cache will update by IP addresses chan...
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:597
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition socket.cc:61
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:398
a unique identifier for an interface.
Definition type-id.h:50
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:870
API to create UDP socket instances.
uint16_t port
Definition dsdv-manet.cc:33
static Ipv4GlobalRoutingTestSuite g_globalRoutingTestSuite
Static variable for test initialization.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:690
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
GlobalRouting< Ipv4RoutingProtocol > Ipv4GlobalRouting
Create the typedef Ipv4GlobalRouting with T as Ipv4RoutingProtocol.
GlobalRouting< Ipv6RoutingProtocol > Ipv6GlobalRouting
Create the typedef Ipv6GlobalRouting with T as Ipv6RoutingProtocol.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
#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:133
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:240
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition test.h:553
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1307
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Every class exported by the ns3 library is enclosed in the ns3 namespace.