A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-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/inet-socket-address.h"
10#include "ns3/internet-stack-helper.h"
11#include "ns3/ipv4-address-helper.h"
12#include "ns3/ipv4-global-routing-helper.h"
13#include "ns3/ipv4-global-routing.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/log.h"
21#include "ns3/node-container.h"
22#include "ns3/node.h"
23#include "ns3/packet.h"
24#include "ns3/pointer.h"
25#include "ns3/simple-channel.h"
26#include "ns3/simple-net-device-helper.h"
27#include "ns3/simple-net-device.h"
28#include "ns3/simulator.h"
29#include "ns3/socket-factory.h"
30#include "ns3/string.h"
31#include "ns3/test.h"
32#include "ns3/udp-socket-factory.h"
33#include "ns3/uinteger.h"
34
35#include <vector>
36using namespace ns3;
37
38NS_LOG_COMPONENT_DEFINE("Ipv4GlobalRoutingTestSuite");
39
40// This test suite tests the operation of global routing on a few sample
41// networks to ensure that routes are built correctly
42//
43// Link test:
44// n0 <--------> n1 (point-to-point link)
45// 10.1.1.1 10.1.1.2
46// Expected routes:
47// n0: route to 0.0.0.0 gw 10.1.1.2
48// n1: route to 0.0.0.0 gw 10.1.1.1
49// Note: These default routes to 0.0.0.0 are generated by the extension
50// in the global route manager to install default routes via the
51// peer node on a point-to-point link, when the node is on a
52// stub link
53//
54// LAN test:
55// n0 <--------> n1 (broadcast link on subnet 10.1.1.0/24)
56// Expected routes:
57// n0: route to 10.1.1.0 gw 0.0.0.0
58// n1: route to 10.1.1.0 gw 0.0.0.0
59// Two link test:
60// n0 <--------> n1 <--------> n2 (point-to-point links)
61// 10.1.1.1 10.1.1.2/ 10.1.2.2
62// 10.1.2.1
63// Expected routes:
64// n0: route to 0.0.0.0 gw 10.1.1.2
65// n1: route to 10.1.1.1 gw 10.1.1.1
66// route to 10.1.2.2 gw 10.1.2.2
67// route to 10.1.1.0 gw 10.1.1.1
68// route to 10.1.2.0 gw 10.1.2.2
69// n2: route to 0.0.0.0 gw 10.1.2.1
70// Note: These default routes to 0.0.0.0 are generated by the extension
71// in the global route manager to install default routes via the
72// peer node on a point-to-point link, when the node is on a
73// stub link
74// Two LANs test:
75// n0 <--------> n1 <--------> n2 (broadcast links)
76// Expected routes:
77// n0: route to 10.1.1.0 gw 0.0.0.0
78// route to 0.0.0.0 gw 10.1.1.2
79// n1: route to 10.1.1.1 gw 10.1.1.1
80// route to 10.1.2.2 gw 10.1.2.2
81// route to 10.1.1.0 gw 10.1.1.1
82// route to 10.1.2.0 gw 10.1.2.2
83// n2: route to 0.0.0.0 gw 10.1.2.1
84// Bridge test:
85// n0 <--------> n1 <---> Bridge-n2 <---> n3 <-------> n4 (broadcast links)
86// 10.1.1.0/24 10.1.2.0/24 10.1.3.0/24
87// Expected routes:
88// n0: route to 10.1.1.0 gw 0.0.0.0
89// route to 10.1.2.0 gw 10.1.1.2
90// route to 10.1.3.0 gw 10.1.1.2
91// n1: route to 10.1.1.0 gw 0.0.0.0
92// route to 10.1.2.0 gw 0.0.0.0
93// route to 10.1.3.0 gw 10.1.2.2
94// n3: route to 10.1.1.0 gw 10.1.2.1
95// route to 10.1.2.0 gw 0.0.0.0
96// route to 10.1.3.0 gw 0.0.0.0
97// n4: route to 10.1.3.0 gw 0.0.0.0
98// route to 10.1.2.0 gw 10.1.3.1
99// route to 10.1.1.0 gw 10.1.3.1
100// Two Bridge test:
101// n0 <------> n1 <---> Bridge-n2 <---> Bridge-n3 <---> n4 (broadcast links)
102// 10.1.1.0/24 10.1.2.0/24
103// Expected routes:
104// n0: route to 10.1.1.0 gw 0.0.0.0
105// route to 10.1.2.0 gw 10.1.1.2
106// n4: route to 10.1.2.0 gw 0.0.0.0
107// route to 10.1.1.0 gw 10.1.2.1
108
109/**
110 * @ingroup internet-test
111 *
112 * @brief IPv4 GlobalRouting Link test
113 */
114class LinkTest : public TestCase
115{
116 public:
117 void DoSetup() override;
118 void DoRun() override;
119 LinkTest();
120
121 private:
122 NodeContainer m_nodes; //!< Nodes used in the test.
123};
124
126 : TestCase("Global routing on point-to-point link")
127{
128}
129
130void
132{
133 m_nodes.Create(2);
134
136 SimpleNetDeviceHelper simpleHelper;
137 simpleHelper.SetNetDevicePointToPointMode(true);
138 NetDeviceContainer net = simpleHelper.Install(m_nodes, channel);
139
140 InternetStackHelper internet;
141 // By default, InternetStackHelper adds a static and global routing
142 // implementation. We just want the global for this test.
143 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
144 internet.SetRoutingHelper(ipv4RoutingHelper);
145 internet.Install(m_nodes);
146
148 ipv4.SetBase("10.1.1.0", "255.255.255.252");
149 Ipv4InterfaceContainer i = ipv4.Assign(net);
150}
151
152void
154{
156
158 NS_TEST_ASSERT_MSG_NE(ip0, nullptr, "Error-- no Ipv4 object");
160 NS_TEST_ASSERT_MSG_NE(ip1, nullptr, "Error-- no Ipv4 object");
161 Ptr<Ipv4RoutingProtocol> routing0 = ip0->GetRoutingProtocol();
162 Ptr<Ipv4GlobalRouting> globalRouting0 = routing0->GetObject<Ipv4GlobalRouting>();
163 NS_TEST_ASSERT_MSG_NE(globalRouting0, nullptr, "Error-- no Ipv4GlobalRouting object");
164 Ptr<Ipv4RoutingProtocol> routing1 = ip1->GetRoutingProtocol();
165 Ptr<Ipv4GlobalRouting> globalRouting1 = routing1->GetObject<Ipv4GlobalRouting>();
166 NS_TEST_ASSERT_MSG_NE(globalRouting1, nullptr, "Error-- no Ipv4GlobalRouting object");
167
168 // Test that the right number of routes found
169 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
170 NS_LOG_DEBUG("LinkTest nRoutes0 " << nRoutes0);
171 NS_TEST_ASSERT_MSG_EQ(nRoutes0, 1, "Error-- not one route");
172 Ipv4RoutingTableEntry* route = globalRouting0->GetRoute(0);
173 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
174 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
175 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.1.2"), "Error-- wrong gateway");
176
177 // Test that the right number of routes found
178 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
179 NS_TEST_ASSERT_MSG_EQ(nRoutes1, 1, "Error-- not one route");
180 NS_LOG_DEBUG("LinkTest nRoutes1 " << nRoutes1);
181 route = globalRouting1->GetRoute(0);
182 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
183 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
184 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.1.1"), "Error-- wrong gateway");
185
186 bool result = true;
187
188 NS_TEST_ASSERT_MSG_EQ(result, true, "Message");
191}
192
193/**
194 * @ingroup internet-test
195 *
196 * @brief IPv4 GlobalRouting LAN test
197 */
198class LanTest : public TestCase
199{
200 public:
201 void DoSetup() override;
202 void DoRun() override;
203 LanTest();
204
205 private:
206 NodeContainer m_nodes; //!< Nodes used in the test.
207};
208
210 : TestCase("Global routing on broadcast link")
211{
212}
213
214void
216{
217 m_nodes.Create(2);
218
220 SimpleNetDeviceHelper simpleHelper;
221 NetDeviceContainer net = simpleHelper.Install(m_nodes, channel);
222
223 InternetStackHelper internet;
224 // By default, InternetStackHelper adds a static and global routing
225 // implementation. We just want the global for this test.
226 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
227 internet.SetRoutingHelper(ipv4RoutingHelper);
228 internet.Install(m_nodes);
229
231 ipv4.SetBase("10.1.1.0", "255.255.255.0");
232 Ipv4InterfaceContainer i = ipv4.Assign(net);
233}
234
235void
237{
239
241 NS_TEST_ASSERT_MSG_NE(ip0, nullptr, "Error-- no Ipv4 object");
243 NS_TEST_ASSERT_MSG_NE(ip1, nullptr, "Error-- no Ipv4 object");
244 Ptr<Ipv4RoutingProtocol> routing0 = ip0->GetRoutingProtocol();
245 Ptr<Ipv4GlobalRouting> globalRouting0 = routing0->GetObject<Ipv4GlobalRouting>();
246 NS_TEST_ASSERT_MSG_NE(globalRouting0, nullptr, "Error-- no Ipv4GlobalRouting object");
247 Ptr<Ipv4RoutingProtocol> routing1 = ip1->GetRoutingProtocol();
248 Ptr<Ipv4GlobalRouting> globalRouting1 = routing1->GetObject<Ipv4GlobalRouting>();
249 NS_TEST_ASSERT_MSG_NE(globalRouting1, nullptr, "Error-- no Ipv4GlobalRouting object");
250
251 // Test that the right number of routes found
252 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
253 NS_LOG_DEBUG("LanTest nRoutes0 " << nRoutes0);
254 NS_TEST_ASSERT_MSG_EQ(nRoutes0, 1, "Error-- more than one entry");
255 for (uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
256 {
257 Ipv4RoutingTableEntry* route = globalRouting0->GetRoute(i);
258 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
259 }
260
261 // Test that the right number of routes found
262 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
263 NS_LOG_DEBUG("LanTest nRoutes1 " << nRoutes1);
264 NS_TEST_ASSERT_MSG_EQ(nRoutes1, 1, "Error-- more than one entry");
265 for (uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
266 {
267 Ipv4RoutingTableEntry* route = globalRouting1->GetRoute(i);
268 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
269 }
270
272}
273
274/**
275 * @ingroup internet-test
276 *
277 * @brief IPv4 GlobalRouting Two Link test
278 */
279class TwoLinkTest : public TestCase
280{
281 public:
282 void DoSetup() override;
283 void DoRun() override;
284 TwoLinkTest();
285
286 private:
287 NodeContainer m_nodes; //!< Nodes used in the test.
288};
289
291 : TestCase("Global routing across two hops (point-to-point links)")
292{
293}
294
295void
297{
298 m_nodes.Create(3);
299
301 SimpleNetDeviceHelper simpleHelper;
302 simpleHelper.SetNetDevicePointToPointMode(true);
303 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
304 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
305
307 SimpleNetDeviceHelper simpleHelper2;
308 simpleHelper2.SetNetDevicePointToPointMode(true);
309 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
310 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
311
312 InternetStackHelper internet;
313 // By default, InternetStackHelper adds a static and global routing
314 // implementation. We just want the global for this test.
315 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
316 internet.SetRoutingHelper(ipv4RoutingHelper);
317 internet.Install(m_nodes);
318
320 ipv4.SetBase("10.1.1.0", "255.255.255.252");
321 Ipv4InterfaceContainer i = ipv4.Assign(net);
322 ipv4.SetBase("10.1.2.0", "255.255.255.252");
323 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
324}
325
326void
328{
330
332 NS_TEST_ASSERT_MSG_NE(ip0, nullptr, "Error-- no Ipv4 object");
334 NS_TEST_ASSERT_MSG_NE(ip1, nullptr, "Error-- no Ipv4 object");
336 NS_TEST_ASSERT_MSG_NE(ip2, nullptr, "Error-- no Ipv4 object");
337 Ptr<Ipv4RoutingProtocol> routing0 = ip0->GetRoutingProtocol();
338 Ptr<Ipv4GlobalRouting> globalRouting0 = routing0->GetObject<Ipv4GlobalRouting>();
339 NS_TEST_ASSERT_MSG_NE(globalRouting0, nullptr, "Error-- no Ipv4GlobalRouting object");
340 Ptr<Ipv4RoutingProtocol> routing1 = ip1->GetRoutingProtocol();
341 Ptr<Ipv4GlobalRouting> globalRouting1 = routing1->GetObject<Ipv4GlobalRouting>();
342 NS_TEST_ASSERT_MSG_NE(globalRouting1, nullptr, "Error-- no Ipv4GlobalRouting object");
343 Ptr<Ipv4RoutingProtocol> routing2 = ip2->GetRoutingProtocol();
344 Ptr<Ipv4GlobalRouting> globalRouting2 = routing2->GetObject<Ipv4GlobalRouting>();
345 NS_TEST_ASSERT_MSG_NE(globalRouting2, nullptr, "Error-- no Ipv4GlobalRouting object");
346
347 // node n0
348 // Test that the right number of routes found
349 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
350 NS_LOG_DEBUG("TwoLinkTest nRoutes0 " << nRoutes0);
351 NS_TEST_ASSERT_MSG_EQ(nRoutes0, 1, "Error-- wrong number of links");
352
353 Ipv4RoutingTableEntry* route = globalRouting0->GetRoute(0);
354 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
355 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
356 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.1.2"), "Error-- wrong gateway");
357
358 // node n1
359 // Test that the right number of routes found
360 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
361 NS_LOG_DEBUG("TwoLinkTest nRoutes1 " << nRoutes1);
362 route = globalRouting1->GetRoute(0);
363 NS_LOG_DEBUG("TwoLinkTest entry dest " << route->GetDest() << " gw " << route->GetGateway());
364 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.1.1"), "Error-- wrong destination");
365 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.1.1"), "Error-- wrong gateway");
366 route = globalRouting1->GetRoute(1);
367 NS_LOG_DEBUG("TwoLinkTest entry dest " << route->GetDest() << " gw " << route->GetGateway());
368 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.2.2"), "Error-- wrong destination");
369 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.2.2"), "Error-- wrong gateway");
370 route = globalRouting1->GetRoute(2);
371 NS_LOG_DEBUG("TwoLinkTest entry dest " << route->GetDest() << " gw " << route->GetGateway());
372 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.1.0"), "Error-- wrong destination");
373 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.1.1"), "Error-- wrong gateway");
374 route = globalRouting1->GetRoute(3);
375 NS_LOG_DEBUG("TwoLinkTest entry dest " << route->GetDest() << " gw " << route->GetGateway());
376 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.2.0"), "Error-- wrong destination");
377 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.2.2"), "Error-- wrong gateway");
378
379 // node n2
380 // Test that the right number of routes found
381 uint32_t nRoutes2 = globalRouting2->GetNRoutes();
382 NS_LOG_DEBUG("TwoLinkTest nRoutes2 " << nRoutes2);
383 NS_TEST_ASSERT_MSG_EQ(nRoutes2, 1, "Error-- wrong number of links");
384
385 route = globalRouting2->GetRoute(0);
386 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
387 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("0.0.0.0"), "Error-- wrong destination");
388 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.2.1"), "Error-- wrong gateway");
389
391}
392
393/**
394 * @ingroup internet-test
395 *
396 * @brief IPv4 GlobalRouting Two LAN test
397 */
398class TwoLanTest : public TestCase
399{
400 public:
401 void DoSetup() override;
402 void DoRun() override;
403 TwoLanTest();
404
405 private:
406 NodeContainer m_nodes; //!< Nodes used in the test.
407};
408
410 : TestCase("Global routing across two hops (broadcast links)")
411{
412}
413
414void
416{
417 m_nodes.Create(3);
418
420 SimpleNetDeviceHelper simpleHelper;
421 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
422 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
423
425 SimpleNetDeviceHelper simpleHelper2;
426 NetDeviceContainer net2 = simpleHelper.Install(m_nodes.Get(1), channel2);
427 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
428
429 InternetStackHelper internet;
430 // By default, InternetStackHelper adds a static and global routing
431 // implementation. We just want the global for this test.
432 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
433 internet.SetRoutingHelper(ipv4RoutingHelper);
434 internet.Install(m_nodes);
435
437 ipv4.SetBase("10.1.1.0", "255.255.255.0");
438 Ipv4InterfaceContainer i = ipv4.Assign(net);
439 ipv4.SetBase("10.1.2.0", "255.255.255.0");
440 Ipv4InterfaceContainer i2 = ipv4.Assign(net2);
441}
442
443void
445{
447
449 NS_TEST_ASSERT_MSG_NE(ip0, nullptr, "Error-- no Ipv4 object");
451 NS_TEST_ASSERT_MSG_NE(ip1, nullptr, "Error-- no Ipv4 object");
453 NS_TEST_ASSERT_MSG_NE(ip2, nullptr, "Error-- no Ipv4 object");
454 Ptr<Ipv4RoutingProtocol> routing0 = ip0->GetRoutingProtocol();
455 Ptr<Ipv4GlobalRouting> globalRouting0 = routing0->GetObject<Ipv4GlobalRouting>();
456 NS_TEST_ASSERT_MSG_NE(globalRouting0, nullptr, "Error-- no Ipv4GlobalRouting object");
457 Ptr<Ipv4RoutingProtocol> routing1 = ip1->GetRoutingProtocol();
458 Ptr<Ipv4GlobalRouting> globalRouting1 = routing1->GetObject<Ipv4GlobalRouting>();
459 NS_TEST_ASSERT_MSG_NE(globalRouting1, nullptr, "Error-- no Ipv4GlobalRouting object");
460 Ptr<Ipv4RoutingProtocol> routing2 = ip2->GetRoutingProtocol();
461 Ptr<Ipv4GlobalRouting> globalRouting2 = routing2->GetObject<Ipv4GlobalRouting>();
462 NS_TEST_ASSERT_MSG_NE(globalRouting2, nullptr, "Error-- no Ipv4GlobalRouting object");
463
464 // Test that the right number of routes found
465 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
466 NS_LOG_DEBUG("TwoLanTest nRoutes0 " << nRoutes0);
467 NS_TEST_ASSERT_MSG_EQ(nRoutes0, 2, "Error-- not two entries");
468 Ipv4RoutingTableEntry* route = globalRouting0->GetRoute(0);
469 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
470 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.1.0"), "Error-- wrong destination");
471 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("0.0.0.0"), "Error-- wrong gateway");
472 route = globalRouting0->GetRoute(1);
473 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
474 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.2.0"), "Error-- wrong destination");
475 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("10.1.1.2"), "Error-- wrong gateway");
476
477 // Test that the right number of routes found
478 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
479 NS_LOG_DEBUG("TwoLanTest nRoutes1 " << nRoutes1);
480 NS_TEST_ASSERT_MSG_EQ(nRoutes1, 2, "Error-- not two entries");
481 route = globalRouting1->GetRoute(0);
482 NS_LOG_DEBUG("TwoLanTest entry dest " << route->GetDest() << " gw " << route->GetGateway());
483 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.1.0"), "Error-- wrong destination");
484 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("0.0.0.0"), "Error-- wrong gateway");
485 route = globalRouting1->GetRoute(1);
486 NS_LOG_DEBUG("TwoLanTest entry dest " << route->GetDest() << " gw " << route->GetGateway());
487 NS_TEST_ASSERT_MSG_EQ(route->GetDest(), Ipv4Address("10.1.2.0"), "Error-- wrong destination");
488 NS_TEST_ASSERT_MSG_EQ(route->GetGateway(), Ipv4Address("0.0.0.0"), "Error-- wrong gateway");
489
491}
492
493/**
494 * @ingroup internet-test
495 *
496 * @brief IPv4 GlobalRouting Bridge test
497 */
498class BridgeTest : public TestCase
499{
500 public:
501 void DoSetup() override;
502 void DoRun() override;
503 BridgeTest();
504
505 private:
506 NodeContainer m_nodes; //!< Nodes used in the test.
507};
508
510 : TestCase("Global routing across bridging topology (bug 2102)")
511{
512}
513
514void
516{
517 m_nodes.Create(5);
518
519 // connect node0 to node1
521 SimpleNetDeviceHelper simpleHelper;
522 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
523 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
524
525 NetDeviceContainer bridgeFacingDevices;
526 NetDeviceContainer switchDevices;
527
528 // connect node1 to node2 (switch)
530 SimpleNetDeviceHelper simpleHelper2;
531 NetDeviceContainer net2 = simpleHelper2.Install(m_nodes.Get(1), channel2);
532 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
533 bridgeFacingDevices.Add(net2.Get(0));
534 switchDevices.Add(net2.Get(1));
535
536 // connect node2 (switch) to node3
538 SimpleNetDeviceHelper simpleHelper3;
539 NetDeviceContainer net3 = simpleHelper3.Install(m_nodes.Get(2), channel3);
540 net3.Add(simpleHelper3.Install(m_nodes.Get(3), channel3));
541 bridgeFacingDevices.Add(net3.Get(1));
542 switchDevices.Add(net3.Get(0));
543
544 // connect node3 to node4
546 SimpleNetDeviceHelper simpleHelper4;
547 NetDeviceContainer net4 = simpleHelper4.Install(m_nodes.Get(3), channel4);
548 net4.Add(simpleHelper4.Install(m_nodes.Get(4), channel4));
549
550 Ptr<Node> switchNode = m_nodes.Get(2);
551 BridgeHelper bridge;
552 bridge.Install(switchNode, switchDevices);
553
554 InternetStackHelper internet;
555 // By default, InternetStackHelper adds a static and global routing
556 // implementation. We just want the global for this test.
557 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
558 internet.SetRoutingHelper(ipv4RoutingHelper);
559
560 internet.Install(m_nodes.Get(0));
561 internet.Install(m_nodes.Get(1));
562 // m_nodes.Get (2) is bridge node
563 internet.Install(m_nodes.Get(3));
564 internet.Install(m_nodes.Get(4));
565
566 Ipv4AddressHelper address;
567 address.SetBase("10.1.1.0", "255.255.255.0");
568 address.Assign(net);
569
570 address.SetBase("10.1.2.0", "255.255.255.0");
571 address.Assign(bridgeFacingDevices);
572
573 address.SetBase("10.1.3.0", "255.255.255.0");
574 address.Assign(net4);
575}
576
577void
579{
581
583 NS_TEST_ASSERT_MSG_NE(ip0, nullptr, "Error-- no Ipv4 object");
584 Ptr<Ipv4RoutingProtocol> routing0 = ip0->GetRoutingProtocol();
585 NS_TEST_ASSERT_MSG_NE(routing0, nullptr, "Error-- no Ipv4 routing protocol object");
586 Ptr<Ipv4GlobalRouting> globalRouting0 = routing0->GetObject<Ipv4GlobalRouting>();
587 NS_TEST_ASSERT_MSG_NE(globalRouting0, nullptr, "Error-- no Ipv4GlobalRouting object");
588
590 NS_TEST_ASSERT_MSG_NE(ip1, nullptr, "Error-- no Ipv4 object");
591 Ptr<Ipv4RoutingProtocol> routing1 = ip1->GetRoutingProtocol();
592 NS_TEST_ASSERT_MSG_NE(routing1, nullptr, "Error-- no Ipv4 routing protocol object");
593 Ptr<Ipv4GlobalRouting> globalRouting1 = routing1->GetObject<Ipv4GlobalRouting>();
594 NS_TEST_ASSERT_MSG_NE(globalRouting1, nullptr, "Error-- no Ipv4GlobalRouting object");
595
596 // Skip to n4
598 NS_TEST_ASSERT_MSG_NE(ip4, nullptr, "Error-- no Ipv4 object");
599 Ptr<Ipv4RoutingProtocol> routing4 = ip4->GetRoutingProtocol();
600 NS_TEST_ASSERT_MSG_NE(routing4, nullptr, "Error-- no Ipv4 routing protocol object");
601 Ptr<Ipv4GlobalRouting> globalRouting4 = routing4->GetObject<Ipv4GlobalRouting>();
602 NS_TEST_ASSERT_MSG_NE(globalRouting4, nullptr, "Error-- no Ipv4GlobalRouting object");
603
604 Ipv4RoutingTableEntry* route = nullptr;
605 // n0
606 // Test that the right number of routes found
607 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
608 NS_LOG_DEBUG("BridgeTest nRoutes0 " << nRoutes0);
609 NS_TEST_ASSERT_MSG_EQ(nRoutes0, 3, "Error-- not three entries");
610 for (uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
611 {
612 route = globalRouting0->GetRoute(i);
613 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
614 }
615 // Spot check the last route
616 if (route)
617 {
619 Ipv4Address("10.1.3.0"),
620 "Error-- wrong destination");
622 Ipv4Address("10.1.1.2"),
623 "Error-- wrong gateway");
624 }
625
626 // n1
627 // Test that the right number of routes found
628 route = nullptr;
629 uint32_t nRoutes1 = globalRouting1->GetNRoutes();
630 NS_LOG_DEBUG("BridgeTest nRoutes1 " << nRoutes1);
631 NS_TEST_ASSERT_MSG_EQ(nRoutes1, 3, "Error-- not three entries");
632 for (uint32_t i = 0; i < globalRouting1->GetNRoutes(); i++)
633 {
634 route = globalRouting1->GetRoute(i);
635 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
636 }
637 // Spot check the last route
638 if (route)
639 {
641 Ipv4Address("10.1.3.0"),
642 "Error-- wrong destination");
644 Ipv4Address("10.1.2.2"),
645 "Error-- wrong gateway");
646 }
647
648 // skip n2 and n3, just verify n4
649 NS_LOG_DEBUG("BridgeTest skip print out of n2 and n3, go next to node n4");
650
651 // n4
652 route = nullptr;
653 // Test that the right number of routes found
654 uint32_t nRoutes4 = globalRouting4->GetNRoutes();
655 NS_LOG_DEBUG("BridgeTest nRoutes4 " << nRoutes4);
656 NS_TEST_ASSERT_MSG_EQ(nRoutes4, 3, "Error-- not three entries");
657 for (uint32_t i = 0; i < globalRouting4->GetNRoutes(); i++)
658 {
659 route = globalRouting4->GetRoute(i);
660 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
661 }
662 // Spot check the last route
663 if (route)
664 {
666 Ipv4Address("10.1.1.0"),
667 "Error-- wrong destination");
669 Ipv4Address("10.1.3.1"),
670 "Error-- wrong gateway");
671 }
672
674}
675
676/**
677 * @ingroup internet-test
678 *
679 * @brief IPv4 GlobalRouting Two bridges test
680 */
682{
683 public:
684 void DoSetup() override;
685 void DoRun() override;
687
688 private:
689 NodeContainer m_nodes; //!< Nodes used in the test.
690};
691
693 : TestCase("Global routing across two bridges")
694{
695}
696
697void
699{
700 m_nodes.Create(5);
701
702 // connect node0 to node1
704 SimpleNetDeviceHelper simpleHelper;
705 NetDeviceContainer net = simpleHelper.Install(m_nodes.Get(0), channel);
706 net.Add(simpleHelper.Install(m_nodes.Get(1), channel));
707
708 NetDeviceContainer bridgeFacingDevices;
709 NetDeviceContainer switchn2Devices;
710 NetDeviceContainer switchn3Devices;
711
712 // connect node1 to node2 (switch)
714 SimpleNetDeviceHelper simpleHelper2;
715 NetDeviceContainer net2 = simpleHelper2.Install(m_nodes.Get(1), channel2);
716 net2.Add(simpleHelper2.Install(m_nodes.Get(2), channel2));
717 bridgeFacingDevices.Add(net2.Get(0));
718 switchn2Devices.Add(net2.Get(1));
719
720 // connect node2 (switch) to node3
722 SimpleNetDeviceHelper simpleHelper3;
723 NetDeviceContainer net3 = simpleHelper3.Install(m_nodes.Get(2), channel3);
724 net3.Add(simpleHelper3.Install(m_nodes.Get(3), channel3));
725 switchn2Devices.Add(net3.Get(0));
726 switchn3Devices.Add(net3.Get(1));
727
728 // connect node3 to node4
730 SimpleNetDeviceHelper simpleHelper4;
731 NetDeviceContainer net4 = simpleHelper4.Install(m_nodes.Get(3), channel4);
732 net4.Add(simpleHelper4.Install(m_nodes.Get(4), channel4));
733 switchn3Devices.Add(net4.Get(0));
734 bridgeFacingDevices.Add(net4.Get(1));
735
736 Ptr<Node> switchn2Node = m_nodes.Get(2);
737 BridgeHelper bridgen2Helper;
738 bridgen2Helper.Install(switchn2Node, switchn2Devices);
739
740 Ptr<Node> switchn3Node = m_nodes.Get(3);
741 BridgeHelper bridgen3Helper;
742 bridgen3Helper.Install(switchn3Node, switchn3Devices);
743
744 InternetStackHelper internet;
745 // By default, InternetStackHelper adds a static and global routing
746 // implementation. We just want the global for this test.
747 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
748 internet.SetRoutingHelper(ipv4RoutingHelper);
749
750 internet.Install(m_nodes.Get(0));
751 internet.Install(m_nodes.Get(1));
752 // m_nodes.Get (2) is bridge node
753 // m_nodes.Get (3) is bridge node
754 internet.Install(m_nodes.Get(4));
755
756 Ipv4AddressHelper address;
757 address.SetBase("10.1.1.0", "255.255.255.0");
758 address.Assign(net);
759
760 address.SetBase("10.1.2.0", "255.255.255.0");
761 address.Assign(bridgeFacingDevices);
762}
763
764void
766{
768
770 NS_TEST_ASSERT_MSG_NE(ip0, nullptr, "Error-- no Ipv4 object");
771 Ptr<Ipv4RoutingProtocol> routing0 = ip0->GetRoutingProtocol();
772 NS_TEST_ASSERT_MSG_NE(routing0, nullptr, "Error-- no Ipv4 routing protocol object");
773 Ptr<Ipv4GlobalRouting> globalRouting0 = routing0->GetObject<Ipv4GlobalRouting>();
774 NS_TEST_ASSERT_MSG_NE(globalRouting0, nullptr, "Error-- no Ipv4GlobalRouting object");
775
776 // Skip to n4
778 NS_TEST_ASSERT_MSG_NE(ip4, nullptr, "Error-- no Ipv4 object");
779 Ptr<Ipv4RoutingProtocol> routing4 = ip4->GetRoutingProtocol();
780 NS_TEST_ASSERT_MSG_NE(routing4, nullptr, "Error-- no Ipv4 routing protocol object");
781 Ptr<Ipv4GlobalRouting> globalRouting4 = routing4->GetObject<Ipv4GlobalRouting>();
782 NS_TEST_ASSERT_MSG_NE(globalRouting4, nullptr, "Error-- no Ipv4GlobalRouting object");
783
784 Ipv4RoutingTableEntry* route = nullptr;
785 // n0
786 // Test that the right number of routes found
787 uint32_t nRoutes0 = globalRouting0->GetNRoutes();
788 NS_LOG_DEBUG("BridgeTest nRoutes0 " << nRoutes0);
789 NS_TEST_ASSERT_MSG_EQ(nRoutes0, 2, "Error-- not two entries");
790 for (uint32_t i = 0; i < globalRouting0->GetNRoutes(); i++)
791 {
792 route = globalRouting0->GetRoute(i);
793 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
794 }
795 // Spot check the last route
796 if (route)
797 {
799 Ipv4Address("10.1.2.0"),
800 "Error-- wrong destination");
802 Ipv4Address("10.1.1.2"),
803 "Error-- wrong gateway");
804 }
805 // skip n2 and n3, just verify n4
806 NS_LOG_DEBUG("BridgeTest skip print out of n1-n3, go next to node n4");
807
808 // n4
809 // Test that the right number of routes found
810 route = nullptr;
811 uint32_t nRoutes4 = globalRouting4->GetNRoutes();
812 NS_LOG_DEBUG("BridgeTest nRoutes4 " << nRoutes4);
813 NS_TEST_ASSERT_MSG_EQ(nRoutes4, 2, "Error-- not two entries");
814 for (uint32_t i = 0; i < globalRouting4->GetNRoutes(); i++)
815 {
816 route = globalRouting4->GetRoute(i);
817 NS_LOG_DEBUG("entry dest " << route->GetDest() << " gw " << route->GetGateway());
818 }
819 // Spot check the last route
820 if (route)
821 {
823 Ipv4Address("10.1.1.0"),
824 "Error-- wrong destination");
826 Ipv4Address("10.1.2.1"),
827 "Error-- wrong gateway");
828 }
829
831}
832
833/**
834 * @ingroup internet-test
835 *
836 * @brief IPv4 Dynamic GlobalRouting test
837 */
839{
840 public:
843
844 private:
845 /**
846 * @brief Send some data
847 * @param index Index of the socket to use.
848 */
849 void SendData(uint8_t index);
850
851 /**
852 * @brief Shutdown a socket
853 * @param index Index of the socket to close.
854 */
855 void ShutDownSock(uint8_t index);
856
857 /**
858 * Handle an incoming packet
859 * @param socket The input socket.
860 */
861 void HandleRead(Ptr<Socket> socket);
862 void DoRun() override;
863
864 uint16_t m_count; //!< Number of packets received.
865 std::vector<std::pair<Ptr<Socket>, bool>> m_sendSocks; //!< Sending sockets.
866 DataRate m_dataRate; //!< Data rate.
867 uint16_t m_packetSize; //!< Packet size.
868 std::vector<uint8_t>
869 m_firstInterface; //!< Packets received on the 1st interface at a given time.
870 std::vector<uint8_t>
871 m_secondInterface; //!< Packets received on the 2nd interface at a given time.
872};
873
874// Add some help text to this case to describe what it is intended to test
876 : TestCase("Dynamic global routing example"),
877 m_count(0)
878{
879 m_firstInterface.resize(16, 0);
880 m_secondInterface.resize(16, 0);
881 m_dataRate = DataRate("2kbps");
882 m_packetSize = 50;
883}
884
886{
887 for (auto iter = m_sendSocks.begin(); iter != m_sendSocks.end(); iter++)
888 {
889 if (iter->second)
890 {
891 iter->second = false;
892 iter->first->Close();
893 iter->first = nullptr;
894 }
895 }
896}
897
898void
900{
901 Ptr<Packet> packet;
902 Address from;
903 while ((packet = socket->RecvFrom(from)))
904 {
905 if (packet->GetSize() == 0)
906 { // EOF
907 break;
908 }
910 bool found;
911 found = packet->PeekPacketTag(tag);
912 uint8_t now = static_cast<uint8_t>(Simulator::Now().GetSeconds());
913 if (found)
914 {
915 if (tag.GetRecvIf() == 1)
916 {
917 m_firstInterface[now]++;
918 }
919 if (tag.GetRecvIf() == 2)
920 {
921 m_secondInterface[now]++;
922 }
923 m_count++;
924 }
925 }
926}
927
928void
930{
931 if (!m_sendSocks[index].second)
932 {
933 return;
934 }
936 m_sendSocks[index].first->Send(packet);
937
938 Time tNext(MicroSeconds(m_packetSize * 8 * 1e6 / m_dataRate.GetBitRate()));
940}
941
942void
944{
945 m_sendSocks[index].second = false;
946 m_sendSocks[index].first->Close();
947 m_sendSocks[index].first = nullptr;
948}
949
950// Test derived from examples/routing/dynamic-global-routing.cc
951//
952// Network topology
953//
954// n0
955// \ p-p
956// \ (shared csma/cd)
957// n2 -------------------------n3
958// / | |
959// / p-p n4 n5 ---------- n6
960// n1 p-p
961// | |
962// ----------------------------------------
963// p-p
964//
965// Test that for node n6, the interface facing n5 receives packets at
966// times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
967// facing n1 receives packets at times (2-4), (6-8), (12-13)
968//
969void
971{
972 // The below value configures the default behavior of global routing.
973 // By default, it is disabled. To respond to interface events, set to true
974 Config::SetDefault("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue(true));
975
977 c.Create(7);
978 NodeContainer n0n2 = NodeContainer(c.Get(0), c.Get(2));
979 NodeContainer n1n2 = NodeContainer(c.Get(1), c.Get(2));
980 NodeContainer n5n6 = NodeContainer(c.Get(5), c.Get(6));
981 NodeContainer n1n6 = NodeContainer(c.Get(1), c.Get(6));
982 NodeContainer n2345 = NodeContainer(c.Get(2), c.Get(3), c.Get(4), c.Get(5));
983
984 InternetStackHelper internet;
985 internet.Install(c);
986
987 // We create the channels first without any IP addressing information
988 SimpleNetDeviceHelper devHelper;
989
990 devHelper.SetNetDevicePointToPointMode(true);
991 NetDeviceContainer d0d2 = devHelper.Install(n0n2);
992 NetDeviceContainer d1d6 = devHelper.Install(n1n6);
993 NetDeviceContainer d1d2 = devHelper.Install(n1n2);
994 NetDeviceContainer d5d6 = devHelper.Install(n5n6);
995
996 devHelper.SetNetDevicePointToPointMode(false);
997 NetDeviceContainer d2345 = devHelper.Install(n2345);
998
999 // Later, we add IP addresses.
1000 Ipv4AddressHelper ipv4;
1001 ipv4.SetBase("10.1.1.0", "255.255.255.0");
1002 ipv4.Assign(d0d2);
1003
1004 ipv4.SetBase("10.1.2.0", "255.255.255.0");
1005 ipv4.Assign(d1d2);
1006
1007 ipv4.SetBase("10.1.3.0", "255.255.255.0");
1008 Ipv4InterfaceContainer i5i6 = ipv4.Assign(d5d6);
1009
1010 ipv4.SetBase("10.250.1.0", "255.255.255.0");
1011 ipv4.Assign(d2345);
1012
1013 ipv4.SetBase("172.16.1.0", "255.255.255.0");
1014 Ipv4InterfaceContainer i1i6 = ipv4.Assign(d1d6);
1015
1016 // Create router nodes, initialize routing database and set up the routing
1017 // tables in the nodes.
1019
1020 // Create the applications to send UDP datagrams of size
1021 // 50 bytes at a rate of 2 Kb/s
1022 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
1023 uint16_t port = 9; // Discard port (RFC 863)
1024
1025 std::pair<Ptr<Socket>, bool> sendSockA;
1026 sendSockA.first = Socket::CreateSocket(c.Get(1), tid);
1027 sendSockA.first->Bind();
1028 sendSockA.first->Connect(InetSocketAddress(i5i6.GetAddress(1), port));
1029 sendSockA.second = true;
1030 m_sendSocks.push_back(sendSockA);
1033
1034 std::pair<Ptr<Socket>, bool> sendSockB;
1035 sendSockB.first = Socket::CreateSocket(c.Get(1), tid);
1036 sendSockB.first->Bind();
1037 sendSockB.first->Connect(InetSocketAddress(i1i6.GetAddress(1), port));
1038 sendSockB.second = true;
1039 m_sendSocks.push_back(sendSockB);
1042
1043 // Create an optional packet sink to receive these packets
1044 Ptr<Socket> sink2 = Socket::CreateSocket(c.Get(6), tid);
1046 sink2->Listen();
1047 sink2->ShutdownSend();
1048
1049 sink2->SetRecvPktInfo(true);
1050 sink2->SetRecvCallback(MakeCallback(&Ipv4DynamicGlobalRoutingTestCase::HandleRead, this));
1051
1052 Ptr<Node> n1 = c.Get(1);
1053 Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4>();
1054 // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
1055 // then the next p2p is numbered 2
1056 uint32_t ipv4ifIndex1 = 2;
1057
1058 Simulator::Schedule(Seconds(2), &Ipv4::SetDown, ipv41, ipv4ifIndex1);
1059 Simulator::Schedule(Seconds(4), &Ipv4::SetUp, ipv41, ipv4ifIndex1);
1060
1061 Ptr<Node> n6 = c.Get(6);
1062 Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4>();
1063 // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
1064 // then the next p2p is numbered 2
1065 uint32_t ipv4ifIndex6 = 2;
1066 Simulator::Schedule(Seconds(6), &Ipv4::SetDown, ipv46, ipv4ifIndex6);
1067 Simulator::Schedule(Seconds(8), &Ipv4::SetUp, ipv46, ipv4ifIndex6);
1068
1069 Simulator::Schedule(Seconds(12), &Ipv4::SetDown, ipv41, ipv4ifIndex1);
1070 Simulator::Schedule(Seconds(14), &Ipv4::SetUp, ipv41, ipv4ifIndex1);
1071
1073
1074 NS_TEST_ASSERT_MSG_EQ(m_count, 70, "Dynamic global routing did not deliver all packets");
1075 // Test that for node n6, the interface facing n1 receives packets at
1076 // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface
1077 // facing n5 receives packets at times (2-4), (6-8), (12-13)
1078
1079 // Note: there are two sending sockets, both on n1.
1080 // The first socket sends packets at time (1-10), the second at time (11, 16).
1081 // The first socket sends packets to n6, targeting the address facing n5.
1082 // The second socket sends packets to n6, targeting the address facing n1.
1083 // This actually doesn't matter, as n6 will accept packets sent to the "wrong" address.
1084 //
1085 // The shortest path netween n1 and n6 is the direct one, but the topology changes during the
1086 // simulation:
1087 // - (2-4): removal from n1 of the interface toward n6
1088 // - (6-8): removal from n6 of the interface toward n1
1089 // - (12-14): removal from n1 of the interface toward n6
1090 // When the link is broken, packets are rerouted though the longest (and only) path, reaching
1091 // n6 though n5.
1092
1093 std::vector<uint8_t> firstInterfaceTest{0, 5, 0, 0, 5, 5, 0, 0, 5, 5, 0, 5, 0, 0, 5, 5};
1094 std::vector<uint8_t> secondInterfaceTest{0, 0, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 0, 0};
1095
1096 for (uint32_t index = 0; index < firstInterfaceTest.size(); index++)
1097 {
1098 NS_TEST_ASSERT_MSG_EQ(firstInterfaceTest[index],
1099 m_firstInterface[index],
1100 "Dynamic global routing did deliver the wrong number of packets "
1101 "to the first interface at time "
1102 << index);
1103 }
1104
1105 for (uint32_t index = 0; index < secondInterfaceTest.size(); index++)
1106 {
1107 NS_TEST_ASSERT_MSG_EQ(secondInterfaceTest[index],
1108 m_secondInterface[index],
1109 "Dynamic global routing did deliver the wrong number of packets "
1110 "to the second interface at time "
1111 << index);
1112 }
1113
1115}
1116
1117/**
1118 * @ingroup internet-test
1119 *
1120 * @brief IPv4 Dynamic GlobalRouting /32 test
1121 */
1123{
1124 public:
1127
1128 Ptr<Packet> m_receivedPacket; //!< number of received packets
1129
1130 /**
1131 * @brief Receive a packet.
1132 * @param socket The receiving socket.
1133 */
1134 void ReceivePkt(Ptr<Socket> socket);
1135 /**
1136 * @brief Send a packet.
1137 * @param socket The sending socket.
1138 * @param to The address of the receiver.
1139 */
1140 void DoSendData(Ptr<Socket> socket, std::string to);
1141 /**
1142 * @brief Send a packet.
1143 * @param socket The sending socket.
1144 * @param to The address of the receiver.
1145 */
1146 void SendData(Ptr<Socket> socket, std::string to);
1147
1148 private:
1149 void DoRun() override;
1150};
1151
1152// Add some help text to this case to describe what it is intended to test
1154 : TestCase("Slash 32 global routing example")
1155{
1156}
1157
1161
1162void
1164{
1165 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
1166 m_receivedPacket = socket->Recv(std::numeric_limits<uint32_t>::max(), 0);
1167 NS_TEST_ASSERT_MSG_EQ(availableData,
1169 "Received packet size is not equal to Rx buffer size");
1170}
1171
1172void
1174{
1175 Address realTo = InetSocketAddress(Ipv4Address(to.c_str()), 1234);
1176 NS_TEST_EXPECT_MSG_EQ(socket->SendTo(Create<Packet>(123), 0, realTo), 123, "100");
1177}
1178
1179void
1181{
1183 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
1184 Seconds(60),
1186 this,
1187 socket,
1188 to);
1191}
1192
1193// Test program for this 3-router scenario, using global routing
1194//
1195// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
1196//
1197void
1199{
1203
1204 NodeContainer c = NodeContainer(nA, nB, nC);
1205
1206 InternetStackHelper internet;
1207 internet.Install(c);
1208
1209 // simple links
1210 NodeContainer nAnB = NodeContainer(nA, nB);
1211 NodeContainer nBnC = NodeContainer(nB, nC);
1212
1213 SimpleNetDeviceHelper devHelper;
1214
1216 deviceA->SetAddress(Mac48Address::Allocate());
1217 nA->AddDevice(deviceA);
1218
1219 NetDeviceContainer dAdB = devHelper.Install(nAnB);
1220 NetDeviceContainer dBdC = devHelper.Install(nBnC);
1221
1223 deviceC->SetAddress(Mac48Address::Allocate());
1224 nC->AddDevice(deviceC);
1225
1226 // Later, we add IP addresses.
1227 Ipv4AddressHelper ipv4;
1228 ipv4.SetBase("10.1.1.0", "255.255.255.252");
1229 Ipv4InterfaceContainer iAiB = ipv4.Assign(dAdB);
1230
1231 ipv4.SetBase("10.1.1.4", "255.255.255.252");
1232 Ipv4InterfaceContainer iBiC = ipv4.Assign(dBdC);
1233
1234 Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4>();
1235 Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4>();
1236 Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4>();
1237
1238 int32_t ifIndexA = ipv4A->AddInterface(deviceA);
1239 int32_t ifIndexC = ipv4C->AddInterface(deviceC);
1240
1241 Ipv4InterfaceAddress ifInAddrA =
1242 Ipv4InterfaceAddress(Ipv4Address("172.16.1.1"), Ipv4Mask("/32"));
1243 ipv4A->AddAddress(ifIndexA, ifInAddrA);
1244 ipv4A->SetMetric(ifIndexA, 1);
1245 ipv4A->SetUp(ifIndexA);
1246
1247 Ipv4InterfaceAddress ifInAddrC =
1248 Ipv4InterfaceAddress(Ipv4Address("192.168.1.1"), Ipv4Mask("/32"));
1249 ipv4C->AddAddress(ifIndexC, ifInAddrC);
1250 ipv4C->SetMetric(ifIndexC, 1);
1251 ipv4C->SetUp(ifIndexC);
1252
1253 // Create router nodes, initialize routing database and set up the routing
1254 // tables in the nodes.
1256
1257 // Create the UDP sockets
1258 Ptr<SocketFactory> rxSocketFactory = nC->GetObject<UdpSocketFactory>();
1259 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
1260 NS_TEST_EXPECT_MSG_EQ(rxSocket->Bind(InetSocketAddress(Ipv4Address("192.168.1.1"), 1234)),
1261 0,
1262 "trivial");
1263 rxSocket->SetRecvCallback(MakeCallback(&Ipv4GlobalRoutingSlash32TestCase::ReceivePkt, this));
1264
1265 Ptr<SocketFactory> txSocketFactory = nA->GetObject<UdpSocketFactory>();
1266 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
1267 txSocket->SetAllowBroadcast(true);
1268
1269 // ------ Now the tests ------------
1270
1271 // Unicast test
1272 SendData(txSocket, "192.168.1.1");
1274 123,
1275 "Static routing with /32 did not deliver all packets.");
1276
1278}
1279
1280/**
1281 * @ingroup internet-test
1282 *
1283 * @brief This TestCase tests if ECMP Route Calculation works. It does not check the
1284 * correctness of the routes.
1285 */
1287{
1288 public:
1290 void DoSetup() override;
1291 void DoRun() override;
1292
1293 private:
1294 NodeContainer nodes; //!< Nodes used in the test.
1295};
1296
1298 : TestCase("ECMP Route Calculation TestCase")
1299{
1300}
1301
1302void
1304{
1305 /*
1306 This TestCase checks the resolution of issue #1243 in the issue tracker.
1307 The problem was that Global Routing failed to calculate next hops when going from a
1308 network vertex to a router vertex when ECMP Routes were involved.
1309
1310 // Network Topology
1311 //
1312 //
1313 // ------n1------
1314 // / \
1315 // / \
1316 // n0 n3----n4----n5
1317 // \ /
1318 // \ /
1319 // ------n2------
1320 //
1321 // Link n0-n1: 10.1.1.1/30,10.1.1.2/30
1322 // Link n0-n2: 10.1.2.1/30,10.1.2.2/30
1323 // Link n1-n3: 10.1.3.1/30,10.1.3.2/30
1324 // Link n2-n3: 10.1.4.1/30,10.1.4.2/30
1325 // Link n3-n4: 10.1.5.1/24,10.1.5.2/24
1326 // Link n4-n5: 10.1.6.1/24,10.1.6.2/24
1327 //
1328 // Note: Link n4-n5 is a LAN LINK. All others are simple P2P links.
1329 */
1330
1331 nodes.Create(6);
1332
1333 Ipv4GlobalRoutingHelper globalhelper;
1334 InternetStackHelper stack;
1335 stack.SetRoutingHelper(globalhelper);
1336 stack.Install(nodes);
1337 SimpleNetDeviceHelper devHelper;
1338 devHelper.SetNetDevicePointToPointMode(true);
1339
1341 NetDeviceContainer d01 = devHelper.Install(nodes.Get(0), channel1);
1342 d01.Add(devHelper.Install(nodes.Get(1), channel1));
1343
1345 NetDeviceContainer d23 = devHelper.Install(nodes.Get(2), channel2);
1346 d23.Add(devHelper.Install(nodes.Get(3), channel2));
1347
1349 NetDeviceContainer d02 = devHelper.Install(nodes.Get(0), channel3);
1350 d02.Add(devHelper.Install(nodes.Get(2), channel3));
1351
1353 NetDeviceContainer d34 = devHelper.Install(nodes.Get(3), channel4);
1354 d34.Add(devHelper.Install(nodes.Get(4), channel4));
1355
1357 NetDeviceContainer d13 = devHelper.Install(nodes.Get(1), channel5);
1358 d13.Add(devHelper.Install(nodes.Get(3), channel5));
1359
1360 devHelper.SetNetDevicePointToPointMode(false);
1361
1363 NetDeviceContainer d45 = devHelper.Install(nodes.Get(4), channel6);
1364 d45.Add(devHelper.Install(nodes.Get(5), channel6));
1365
1366 // Assign IP addresses to the devices
1367 Ipv4AddressHelper address;
1368 address.SetBase("10.1.1.0", "255.255.255.252");
1369 Ipv4InterfaceContainer i01 = address.Assign(d01);
1370
1371 address.SetBase("10.1.2.0", "255.255.255.252");
1372 Ipv4InterfaceContainer i02 = address.Assign(d02);
1373
1374 address.SetBase("10.1.3.0", "255.255.255.252");
1375 Ipv4InterfaceContainer i13 = address.Assign(d13);
1376
1377 address.SetBase("10.1.4.0", "255.255.255.224");
1378 Ipv4InterfaceContainer i23 = address.Assign(d23);
1379
1380 address.SetBase("10.1.5.0", "255.255.255.0");
1381 Ipv4InterfaceContainer i34 = address.Assign(d34);
1382
1383 address.SetBase("10.1.6.0", "255.255.255.0");
1384 Ipv4InterfaceContainer i45 = address.Assign(d45);
1385}
1386
1387void
1389{
1390 // The purpose of this test is to make sure the code doesn't crash when calculating ECMP routes
1391 // with a topology described in issue #1243. It does not look into the correctness of the
1392 // routes. We have other tests to make sure the routes are correct.
1394
1398}
1399
1400/**
1401 * @ingroup internet-test
1402 *
1403 * @brief TestCase to check calls to GlobalRoutingProtocol API. This TestCase Checks the output
1404 * returned by the GlobalRoutingProtocol API to Ipv4L3 Layer.
1405 */
1407{
1408 public:
1411
1412 private:
1413 void DoSetup() override;
1414 void DoRun() override;
1415 /**
1416 * @brief Checks the Path taken by packets by calling RouteInput() and RouteOutput() APIs of
1417 * GlobalRoutingProtocol. This mimics how Ipv4L3Protocol calls these APIs.
1418 * @param pathNodes Vector of nodes in the path. This includes the source node,Intermediate
1419 * nextHop nodes and the destination node.
1420 * @param path Vector of Ipv4Addresses in the path. This includes the source egress IpAddress,
1421 * destination ingress IpAddress and intermediate nextHop Node's ingress Ipaddress that we need
1422 * to check.It does not include the egress addresses for intermediate nodes.
1423 */
1424 void CheckPath(std::vector<Ptr<Node>> pathNodes, std::vector<Ipv4Address> path);
1425
1426 /**
1427 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
1428 * @param route Route to be used for forwarding
1429 * @param packet Packet to be forwarded
1430 * @param header IPv4 header of the packet
1431 */
1433 Ptr<const Packet> packet,
1434 const Ipv4Header& header);
1435 /**
1436 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
1437 * @param packet Packet to be locally delivered
1438 * @param header IPv4 header of the packet
1439 * @param iif Ingress Interface index
1440 */
1441 void MyLocalDeliverCallback(Ptr<const Packet> packet, const Ipv4Header& header, uint32_t iif);
1442 /**
1443 * @brief Callback function for RouteInput() API of GlobalRoutingProtocol.
1444 * @param packet Packet to be locally delivered
1445 * @param header IPv4 header of the packet
1446 * @param errno_ Socket error number
1447 */
1449 const Ipv4Header& header,
1450 Socket::SocketErrno errno_);
1451
1452 NodeContainer nodes; //!< Nodes used in the test.
1453 Ptr<Ipv4Route> m_lastRoute; //!< Route to be tested.
1458};
1459
1460// Signature: void (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header &header)
1461void
1463 Ptr<const Packet> packet,
1464 const Ipv4Header& header)
1465{
1466 NS_LOG_DEBUG("Unicast Forward Callback called.");
1467 m_lastRoute = route;
1468}
1469
1470// Signature: void (Ptr<const Packet>, const Ipv4Header&, uint32_t)
1471void
1473 const Ipv4Header& header,
1474 uint32_t iif)
1475{
1476 NS_LOG_DEBUG("Local Deliver Callback called.");
1477}
1478
1479// Signature: void (Ptr<const Packet>, const Ipv4Header&, Socket::SocketErrno)
1480void
1482 const Ipv4Header& header,
1483 Socket::SocketErrno errno_)
1484{
1485 NS_LOG_DEBUG("Error Callback called.");
1486 // Fail the test if this callback is called
1487 NS_TEST_ASSERT_MSG_EQ(1, 1, "Error Callback called in RouteInput");
1488}
1489
1491 : TestCase("Test API calls to GlobalRoutingProtocol")
1492{
1496 // Multicast callback is not used in unicast test, can bind to null or dummy
1498}
1499
1503
1504void
1506 std::vector<Ipv4Address> path)
1507{
1508 uint32_t pathSize = path.size();
1509
1510 Ptr<Ipv4L3Protocol> ip = pathNodes[0]->GetObject<Ipv4L3Protocol>();
1511 NS_TEST_ASSERT_MSG_NE(ip, nullptr, "Error-- no Ipv4 object at source node");
1512 Ptr<Ipv4RoutingProtocol> routing = ip->GetRoutingProtocol();
1513 NS_TEST_ASSERT_MSG_NE(routing,
1514 nullptr,
1515 "Error-- no Ipv4 routing protocol object at source node");
1516 Ptr<Ipv4GlobalRouting> globalRouting = routing->GetObject<Ipv4GlobalRouting>();
1517 NS_TEST_ASSERT_MSG_NE(globalRouting,
1518 nullptr,
1519 "Error-- no Ipv4GlobalRouting object at source node");
1520
1521 Socket::SocketErrno errno_;
1522 Ptr<NetDevice> oif(nullptr);
1523 Ptr<Packet> packet = Create<Packet>();
1524 Ipv4Header ipHeader;
1525 ipHeader.SetSource(path[0]);
1526 ipHeader.SetDestination(path[pathSize - 1]);
1527
1528 // for the source node we need to call RouteOutput()
1529 m_lastRoute = globalRouting->RouteOutput(packet, ipHeader, oif, errno_);
1530 // for the rest of the nodes we need to call RouteInput()
1531 for (uint32_t i = 1; i < pathSize; i++)
1532 {
1533 // for each iteration except the last one check that the UnicastForward Callback is called.
1534 // For the last node that is the destination node LocalDelivery Callback will be called.
1535 if (i != pathSize - 1)
1536 {
1537 NS_TEST_ASSERT_MSG_EQ(m_lastRoute->GetGateway(), path[i], "Error-- wrong gateway");
1538 }
1539
1540 ip = pathNodes[i]->GetObject<Ipv4L3Protocol>();
1541 NS_TEST_ASSERT_MSG_NE(ip, nullptr, "Error-- no Ipv4 object at node");
1542 routing = ip->GetRoutingProtocol();
1543 NS_TEST_ASSERT_MSG_NE(routing, nullptr, "Error-- no Ipv4 routing protocol object at node");
1544 globalRouting = routing->GetObject<Ipv4GlobalRouting>();
1545 NS_TEST_ASSERT_MSG_NE(globalRouting,
1546 nullptr,
1547 "Error-- no Ipv4GlobalRouting object at node");
1548
1549 Ptr<Ipv4Interface> interf = ip->GetInterface(ip->GetInterfaceForAddress(path[i]));
1550 Ptr<NetDevice> idevice = interf->GetDevice();
1551
1552 // call RouteInput() for the next node in the path
1553 globalRouting->RouteInput(packet, ipHeader, idevice, m_ucb, m_mcb, m_lcb, m_ecb);
1554 }
1555}
1556
1557void
1559{
1560 /**
1561 * This test case is designed to test the overall functionality of the GlobalRoutingProtocol.
1562 * It tests the calls to the GlobalRoutingProtocol's RouteOutput() and RouteInput() APIs.
1563 * It mimics how Ipv4L3Protocol calls these APIs. The topology covers most of the cases
1564 * that are expected to be handled by the GlobalRoutingProtocol.
1565 */
1566
1567 //
1568 //
1569 // Network topology
1570 //
1571 // n0
1572 // \ p-p
1573 // \ (shared csma/cd)
1574 // n2 -------------------------n3
1575 // / | |
1576 // / p-p n4 n5 ---------- n6-------n7----Bridge-n8--------n9
1577 // n1 p-p | 10.1.4.0/24
1578 // | |
1579 // ----------------------------------------
1580 // p-p
1581 //
1582 //
1583 //
1584
1585 nodes.Create(10);
1586 NodeContainer n2345 = NodeContainer(nodes.Get(2), nodes.Get(3), nodes.Get(4), nodes.Get(5));
1587
1588 // We create the channels first without any IP addressing information
1589 SimpleNetDeviceHelper devHelper;
1590
1591 devHelper.SetNetDevicePointToPointMode(true);
1592
1594 NetDeviceContainer d0d2 = devHelper.Install(nodes.Get(0), channel1);
1595 d0d2.Add(devHelper.Install(nodes.Get(2), channel1));
1596
1598 NetDeviceContainer d1d6 = devHelper.Install(nodes.Get(1), channel2);
1599 d1d6.Add(devHelper.Install(nodes.Get(6), channel2));
1600
1602 NetDeviceContainer d1d2 = devHelper.Install(nodes.Get(1), channel3);
1603 d1d2.Add(devHelper.Install(nodes.Get(2), channel3));
1604
1606 NetDeviceContainer d5d6 = devHelper.Install(nodes.Get(5), channel4);
1607 d5d6.Add(devHelper.Install(nodes.Get(6), channel4));
1608
1610 devHelper.SetNetDevicePointToPointMode(false);
1611 NetDeviceContainer d6d7 = devHelper.Install(nodes.Get(6), channel5);
1612 d6d7.Add(devHelper.Install(nodes.Get(7), channel5));
1613
1614 devHelper.SetNetDevicePointToPointMode(false);
1615 NetDeviceContainer d2345 = devHelper.Install(n2345);
1616
1617 // handle the bridge
1618 // connect node 7 to node 8(Switch)
1620 NetDeviceContainer d78 = devHelper.Install(nodes.Get(7), channel6);
1621 d78.Add(devHelper.Install(nodes.Get(8), channel6));
1622
1623 // connect node 8(switch) to node 9
1625 NetDeviceContainer d89 = devHelper.Install(nodes.Get(8), channel7);
1626 d89.Add(devHelper.Install(nodes.Get(9), channel7));
1627
1628 NetDeviceContainer bridgeFacingDevices;
1629 NetDeviceContainer switchDevices;
1630 bridgeFacingDevices.Add(d78.Get(0));
1631 switchDevices.Add(d78.Get(1));
1632 bridgeFacingDevices.Add(d89.Get(1));
1633 switchDevices.Add(d89.Get(0));
1634
1635 Ptr<Node> switchNode = nodes.Get(8);
1636 BridgeHelper bridge;
1637 bridge.Install(switchNode, switchDevices);
1638
1639 InternetStackHelper internet;
1640 Ipv4GlobalRoutingHelper glbrouting;
1641 internet.SetRoutingHelper(glbrouting);
1642 internet.Install(nodes.Get(0));
1643 internet.Install(nodes.Get(1));
1644 internet.Install(nodes.Get(2));
1645 internet.Install(nodes.Get(3));
1646 internet.Install(nodes.Get(4));
1647 internet.Install(nodes.Get(5));
1648 internet.Install(nodes.Get(6));
1649 internet.Install(nodes.Get(7));
1650 // node 8 is a bridge node
1651 internet.Install(nodes.Get(9));
1652
1653 // Later, we add IP addresses.
1654 Ipv4AddressHelper ipv4;
1655 ipv4.SetBase("10.1.1.0", "255.255.255.0");
1656 Ipv4InterfaceContainer i0d2 = ipv4.Assign(d0d2);
1657
1658 ipv4.SetBase("10.1.2.0", "255.255.255.0");
1659 Ipv4InterfaceContainer i1d2 = ipv4.Assign(d1d2);
1660
1661 ipv4.SetBase("10.1.3.0", "255.255.255.0");
1662 Ipv4InterfaceContainer i5i6 = ipv4.Assign(d5d6);
1663
1664 ipv4.SetBase("10.250.1.0", "255.255.255.0");
1665 Ipv4InterfaceContainer i2345 = ipv4.Assign(d2345);
1666
1667 ipv4.SetBase("172.16.1.0", "255.255.255.0");
1668 Ipv4InterfaceContainer i1i6 = ipv4.Assign(d1d6);
1669
1670 ipv4.SetBase("10.1.4.0", "255.255.255.0");
1671 Ipv4InterfaceContainer i67 = ipv4.Assign(d6d7);
1672
1673 ipv4.SetBase("10.1.5.0", "255.255.255.0");
1674 Ipv4InterfaceContainer i79 = ipv4.Assign(bridgeFacingDevices);
1675}
1676
1677void
1679{
1680 // Create router nodes, initialize routing database and set up the routing
1681 // tables in the nodes.
1683
1685
1686 // tests-------------------------
1687 // test 1:check path from n0 to n6
1688 // test 2:check path from n1 to n5
1689 // test 3:check path from n1 to n9
1690 // test 4:check path from n8 to n0
1691
1692 // Test 1: check path from n0 to n6
1693 std::vector<Ipv4Address>
1694 pathToCheck1; // includes the source egress destination ingress and intermediate next hops
1695 // addresses that we need to check.It does not include the egress addresses
1696 // for intermediate nodes.
1697 pathToCheck1.emplace_back("10.1.1.1");
1698 pathToCheck1.emplace_back("10.1.1.2");
1699 pathToCheck1.emplace_back("10.1.2.1");
1700 pathToCheck1.emplace_back("172.16.1.2");
1701
1702 std::vector<Ptr<Node>>
1703 pathNodes1; // nodes in the path. Includes the source node and the destination node.
1704 pathNodes1.push_back(nodes.Get(0));
1705 pathNodes1.push_back(nodes.Get(2));
1706 pathNodes1.push_back(nodes.Get(1));
1707 pathNodes1.push_back(nodes.Get(6));
1708
1709 CheckPath(pathNodes1, pathToCheck1);
1710
1711 // Test 2:check path from n1 to n5
1712 std::vector<Ipv4Address> pathToCheck2;
1713 pathToCheck2.emplace_back("10.1.2.1");
1714 pathToCheck2.emplace_back("10.1.2.2");
1715 pathToCheck2.emplace_back("10.250.1.4");
1716
1717 std::vector<Ptr<Node>> pathNodes2;
1718 pathNodes2.push_back(nodes.Get(1));
1719 pathNodes2.push_back(nodes.Get(2));
1720 pathNodes2.push_back(nodes.Get(5));
1721
1722 CheckPath(pathNodes2, pathToCheck2);
1723
1724 // Test 3:check path from n1 to n9
1725 std::vector<Ipv4Address> pathToCheck3;
1726 pathToCheck3.emplace_back("172.16.1.1");
1727 pathToCheck3.emplace_back("172.16.1.2");
1728 pathToCheck3.emplace_back("10.1.4.2");
1729 pathToCheck3.emplace_back("10.1.5.2");
1730
1731 std::vector<Ptr<Node>> pathNodes3;
1732 pathNodes3.push_back(nodes.Get(1));
1733 pathNodes3.push_back(nodes.Get(6));
1734 pathNodes3.push_back(nodes.Get(7));
1735 pathNodes3.push_back(nodes.Get(9));
1736
1737 CheckPath(pathNodes3, pathToCheck3);
1738
1739 // Test 4:check path from n9 to n0
1740 std::vector<Ipv4Address> pathToCheck4;
1741 pathToCheck4.emplace_back("10.1.5.2");
1742 pathToCheck4.emplace_back("10.1.5.1");
1743 pathToCheck4.emplace_back("10.1.4.1");
1744 pathToCheck4.emplace_back("10.1.3.1");
1745 pathToCheck4.emplace_back("10.250.1.1");
1746 pathToCheck4.emplace_back("10.1.1.1");
1747
1748 std::vector<Ptr<Node>> pathNodes4;
1749 pathNodes4.push_back(nodes.Get(9));
1750 pathNodes4.push_back(nodes.Get(7));
1751 pathNodes4.push_back(nodes.Get(6));
1752 pathNodes4.push_back(nodes.Get(5));
1753 pathNodes4.push_back(nodes.Get(2));
1754 pathNodes4.push_back(nodes.Get(0));
1755
1756 CheckPath(pathNodes4, pathToCheck4);
1757
1761}
1762
1763/**
1764 * @ingroup internet-test
1765 *
1766 * @brief IPv4 GlobalRouting TestSuite
1767 */
1769{
1770 public:
1772};
1773
1775 : TestSuite("ipv4-global-routing", Type::UNIT)
1776{
1777 AddTestCase(new LinkTest, TestCase::Duration::QUICK);
1778 AddTestCase(new LanTest, TestCase::Duration::QUICK);
1779 AddTestCase(new TwoLinkTest, TestCase::Duration::QUICK);
1780 AddTestCase(new TwoLanTest, TestCase::Duration::QUICK);
1781 AddTestCase(new BridgeTest, TestCase::Duration::QUICK);
1782 AddTestCase(new TwoBridgeTest, TestCase::Duration::QUICK);
1783 AddTestCase(new Ipv4DynamicGlobalRoutingTestCase, TestCase::Duration::QUICK);
1784 AddTestCase(new Ipv4GlobalRoutingSlash32TestCase, TestCase::Duration::QUICK);
1785 AddTestCase(new EcmpRouteCalculationTestCase, TestCase::Duration::QUICK);
1786 AddTestCase(new GlobalRoutingProtocolTestCase, TestCase::Duration::QUICK);
1787}
1788
1790 g_globalRoutingTestSuite; //!< Static variable for test initialization
NodeContainer n1n2
Nodecontainer n1 + n2.
NodeContainer n0n2
Nodecontainer n0 + n2.
IPv4 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.
Ipv4RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
void MyLocalDeliverCallback(Ptr< const Packet > packet, const Ipv4Header &header, uint32_t iif)
Callback function for RouteInput() API of GlobalRoutingProtocol.
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::ErrorCallback m_ecb
Error 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.
Ipv4RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
Ptr< Ipv4Route > m_lastRoute
Route to be tested.
void DoRun() override
Implementation to actually run this TestCase.
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 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.
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 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.
IPv4 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.
IPv4 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:90
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
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition data-rate.cc:234
static void ResetRouterId()
Reset the router ID counter to zero.
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.
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.
Global routing protocol for IPv4 stacks.
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.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
static Mac48Address Allocate()
Allocate a new Mac48Address.
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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition packet.h:850
Smart pointer class similar to boost::intrusive_ptr.
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:561
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:578
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
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
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:394
a unique identifier for an interface.
Definition type-id.h:49
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:872
API to create UDP socket instances.
uint16_t port
Definition dsdv-manet.cc:33
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:439
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:134
#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:241
#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:554
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1393
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
static Ipv4GlobalRoutingTestSuite g_globalRoutingTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:684