A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-routing-multi-switch-plus-router.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 - Chip Webb
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Chip Webb <ns3 (at) chipwebb.com>
7 *
8 */
9
10// ###################################################################### //
11// Network topology //
12// ---------------------------------------------------------------------- //
13// //
14// This example shows two L2 LANs connected by a WAN link and illustrates //
15// a network that has multiple L2 switches between L3 routers. //
16// //
17// It serves as a test case to verify a patch to global-router-interface //
18// that fixes a previous bug (#2102 in the ns-3 tracker) but is also //
19// another example program. //
20// //
21// The LANs are "top" [192.168.1/24] and "bottom" [192.168.2/24]. //
22// Each LAN network is interconnected by several L2 switches, and each //
23// LAN has its own router to act as a gateway with the WAN. Each LAN //
24// has two endpoints upon which is installed a UDP echo client or server //
25// that are used to test connectivity over the LANs & WAN. //
26// //
27// One pair of UDP endpoints (t3 and b3) have LAN connections with only //
28// one switch between them and their local routers. This path works with //
29// unpatched ns3 code (3.24 & earlier) as well as with the patch applied. //
30// //
31// Another pair of endpoints (t2 and b2) have LAN connections with //
32// a chain of multiple switches between them and their local router. //
33// This path will only work after applying the associated patch. //
34// //
35// The LAN links are modeled by half-duplex Ethernet CSMA links which //
36// have command-line-configurable data rate and latency. //
37// //
38// There are two types of CSMA links: 100Mbit and 10Mbit. The 100Mbit //
39// links are called csmaX, are denoted by [X] in the diagram and can //
40// be controlled with the --csmaXRate and --csmaXDelay command line args. //
41// The 10Mbit links are called csmaY, are denoted by [Y] in the diagram //
42// and can be controlled with the --csmaYRate and --csmaYDelay command //
43// line arguments. Both the top and bottom LAN have a mixture of //
44// 100Mbit/s and 10Mbit/s links. //
45// //
46// The WAN is modeled by a point-to-point link which has configurable //
47// data rate and latency. Unlike many typical home/work networks, //
48// the routers do not perform NAT. //
49// //
50// The WAN link is denoted by [P] in the diagram, and the //
51// speed and latency can be set from the command line with the //
52// --p2pRate and --p2pDelay options. The default for this link is 5Mbit/s //
53// and 50ms delay //
54// //
55// Note: Names in parenthesis after NetDevices are pcap tap locations. //
56// //
57// ---------------------------------------------------------------------- //
58// //
59// 192.168. 192.168. //
60// .1.2 .1.3 //
61// --------- --------- //
62// | t2 | | t3 | //
63// | UDP | | UDP | //
64// | echo | | echo | Node t2 is a UDP echo client (multi-switch) //
65// | client| | server| Node t3 is a UDP echo server (single-switch) //
66// --------- --------- //
67// CSMA(t2) CSMA(t3) //
68// [X] [X] //
69// [X] [X] //
70// CSMA [X] //
71// --------- [X] //
72// | ts4 | [X] Nodes ts1, ts2, ts3 and ts4 are L2 switches //
73// | (sw) | [X] The top LAN is subnet 192.168.1.* //
74// --------- [X] //
75// CSMA [X] The long chain of switches is designed //
76// [Y] [X] to test whether global-router-interface //
77// [Y] [X] can fully enumerate an IP subnet that has //
78// CSMA [X] multiple interconnected L2 switches. //
79// --------- [X] The problem is documented in Bug #2102. //
80// | ts3 | [X] //
81// | (sw) | [X] //
82// --------- [X] //
83// CSMA [X] //
84// [X] [X] //
85// [X] [X] //
86// CSMA [X] //
87// --------- [X] //
88// | ts2 | [X] //
89// | (sw) | [X] //
90// --------- [X] //
91// CSMA [X] //
92// [Y] [X] //
93// [Y] [X] //
94// CSMA CSMA //
95// ------------------ //
96// | ts1 (switch) | //
97// ------------------ //
98// CSMA //
99// [Y] //
100// [Y] //
101// CSMA(trlan) 192.168.1.1 //
102// ------------------ //
103// | tr (router) | Node tr is an L3 router //
104// ------------------ (between 192.168.1.* & 76.1.1.*) //
105// P2P(trwan) 76.1.1.1 //
106// [P] //
107// [P] //
108// [P] //
109// [P] //
110// [P] The WAN is 76.1.1.* //
111// [P] //
112// [P] //
113// [P] //
114// P2P(brwan) 76.1.1.2 //
115// ------------------ //
116// | br (router) | Node br is an L3 router //
117// ------------------ (between 192.168.2.* & 76.1.1.*) //
118// CSMA(brlan) 192.168.2.1 //
119// [X] //
120// [X] //
121// CSMA //
122// ------------------ Nodes bs1 to bs5 are L2 switches //
123// | bs1 (switch) | The bottom LAN is subnet 192.168.2.* //
124// ------------------ //
125// CSMA CSMA //
126// [Y] [Y] //
127// [Y] [Y] //
128// CSMA [Y] //
129// --------- [Y] //
130// | bs2 | [Y] //
131// | (sw) | [Y] //
132// --------- [Y] //
133// CSMA [Y] //
134// [X] [Y] //
135// [X] [Y] //
136// CSMA [Y] //
137// --------- [Y] //
138// | bs3 | [Y] //
139// | (sw) | [Y] //
140// --------- [Y] //
141// CSMA [Y] //
142// [Y] [Y] //
143// [Y] [Y] //
144// CSMA [Y] //
145// --------- [Y] //
146// | bs4 | [Y] //
147// | (sw) | [Y] //
148// --------- [Y] //
149// CSMA [Y] //
150// [X] [Y] //
151// [X] [Y] //
152// CSMA [Y] //
153// --------- [Y] //
154// | bs5 | [Y] //
155// | (sw) | [Y] //
156// --------- [Y] //
157// CSMA [Y] //
158// [Y] [Y] //
159// [Y] [Y] //
160// CSMA(b2) CSMA(b3) //
161// --------- --------- //
162// | b2 | | b3 | //
163// | UDP | | UDP | //
164// | echo | | echo | Node b2 is a UDP echo server (multi-switch) //
165// | server| | client| Node b3 is a UDP echo client (single-switch) //
166// --------- --------- //
167// 192.168. 192.168. //
168// .2.2 .2.3 //
169// //
170// ---------------------------------------------------------------------- //
171// Explanation //
172// ---------------------------------------------------------------------- //
173// //
174// UDP packet flows are configured between nodes on the top and bottom //
175// LANs (using UDP echo client & server). //
176// //
177// The network carrying the "multi switch" UDP flow is connected with //
178// multiple L2 switches between L3 nodes so it should only work if the //
179// global-router-interface source code properly supports bridging. //
180// //
181// The network carrying the "single switch" UDP flow is connected with //
182// only one L2 switch between L3 nodes so it should work with or //
183// without the patch //
184// //
185// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = //
186// Traffic summary: //
187// ---------------------------------------------------------------------- //
188// //
189// - UDP flow from t2 (192.168.1.2) to b2 (192.168.2.2) [Multi Switch] //
190// from b3 (192.168.2.3) to t3 (192.168.1.3) [Single Switch] //
191// //
192// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = //
193// Node List & IP addresses assigned during simulation //
194// ---------------------------------------------------------------------- //
195// t2 : 192.168.1.2 : Top multi-switch UDP echo client //
196// t3 : 192.168.1.3 : Top single-switch UDP echo server //
197// : //
198// ts1 : <no IP> : Top switch 1 (bridge) //
199// ts2 : <no IP> : Top switch 2 (bridge) //
200// ts3 : <no IP> : Top switch 3 (bridge) //
201// ts4 : <no IP> : Top switch 4 (bridge) //
202// : //
203// tr : 192.168.1.1 : Router connecting top LAN (192.168.1.*) //
204// : 76.1.1.1 : to the WAN //
205// : //
206// br : 76.1.1.2 : Router connecting the WAN //
207// : 192.168.2.1 : to bot LAN (192.168.2.*) //
208// : //
209// bs1 : <no IP> : Bottom switch 1 (bridge) //
210// bs2 : <no IP> : Bottom switch 2 (bridge) //
211// bs3 : <no IP> : Bottom switch 3 (bridge) //
212// bs4 : <no IP> : Bottom switch 4 (bridge) //
213// bs5 : <no IP> : Bottom switch 5 (bridge) //
214// : //
215// b2 : 192.168.2.2 : Bottom multi-switch UDP echo server //
216// b3 : 192.168.2.3 : Bottom single-switch UDP echo client //
217// : //
218// ---------------------------------------------------------------------- //
219// Author: Chip Webb <ns3 (a) chipwebb dot com> //
220// ###################################################################### //
221
222#include "ns3/applications-module.h"
223#include "ns3/bridge-module.h"
224#include "ns3/core-module.h"
225#include "ns3/csma-module.h"
226#include "ns3/internet-module.h"
227#include "ns3/network-module.h"
228#include "ns3/point-to-point-module.h"
229
230#include <fstream>
231#include <iostream>
232
233using namespace ns3;
234
235// ########################################################################
236// Main routine
237// ########################################################################
238NS_LOG_COMPONENT_DEFINE("GlobalRoutingMultiSwitchPlusRouter");
239
240#define vssearch(loc, vec) std::find((vec).begin(), (vec).end(), (loc)) != (vec).end()
241
242int
243main(int argc, char* argv[])
244{
245 // ----------------------------------------------------------------------
246 // Default values for command line arguments
247 // ----------------------------------------------------------------------
248 bool verbose = true;
249
250 int simDurationSeconds = 60;
251
252 bool enableUdpMultiSW = true;
253 bool enableUdpSingleSW = true;
254
255 std::string pcapLocations = "";
257
258 std::string csmaXLinkDataRate = "100Mbps";
259 std::string csmaXLinkDelay = "500ns";
260
261 std::string csmaYLinkDataRate = "10Mbps";
262 std::string csmaYLinkDelay = "500ns";
263
264 std::string p2pLinkDataRate = "5Mbps";
265 std::string p2pLinkDelay = "50ms";
266
267 uint16_t udpEchoPort = 9; // The well-known UDP echo port
268
269 // ----------------------------------------------------------------------
270 // Create command line options and get them
271 // ----------------------------------------------------------------------
272 CommandLine cmd(__FILE__);
273
274 cmd.Usage("NOTE: valid --pcap arguments are: 't2,t3,b2,b3,trlan,trwan,brlan,brwan'");
275
276 cmd.AddValue("verbose", "Enable printing informational messages", verbose);
277
278 cmd.AddValue("duration", "Duration of simulation.", simDurationSeconds);
279
280 cmd.AddValue("udpMultiSW", "Enable udp over multi-switch links", enableUdpMultiSW);
281 cmd.AddValue("udpSingleSW", "Enable udp over single-switch links", enableUdpSingleSW);
282
283 cmd.AddValue("pcap", "Comma separated list of PCAP Locations to tap", pcapLocations);
284 cmd.AddValue("snapLen", "PCAP packet capture length", snapLen);
285
286 cmd.AddValue("csmaXRate", "CSMA X Link data rate", csmaXLinkDataRate);
287 cmd.AddValue("csmaXDelay", "CSMA X Link delay", csmaXLinkDelay);
288
289 cmd.AddValue("csmaYRate", "CSMA Y Link data rate", csmaYLinkDataRate);
290 cmd.AddValue("csmaYDelay", "CSMA Y Link delay", csmaYLinkDelay);
291
292 cmd.AddValue("p2pRate", "P2P Link data rate", p2pLinkDataRate);
293 cmd.AddValue("p2pDelay", "P2P Link delay", p2pLinkDelay);
294
295 cmd.Parse(argc, argv);
296
297 // --------------------------------------------------------------------
298 // Users may find it convenient to turn on explicit debugging
299 // for selected modules; the below lines suggest how to do this
300 // --------------------------------------------------------------------
301 if (verbose)
302 {
303 LogComponentEnable("GlobalRoutingMultiSwitchPlusRouter", LOG_LEVEL_INFO);
304 }
305
306 // ======================================================================
307 // Define the list of valid PCAP taps
308 // ----------------------------------------------------------------------
309 const std::vector<std::string> pcapTaps{
310 "t2", // multi-switch UDP echo client
311 "t3", // single-switch UDP echo server
312 "b2", // multi-switch UDP echo server
313 "b3", // single-switch UDP echo client
314 "trlan", // top router LAN side
315 "trwan", // top router WAN side
316 "brlan", // bottom router LAN side
317 "brwan", // bottom router WAN side
318 };
319
320 // ----------------------------------------------------------------------
321 // Parse the pcapLocations string into pcapLocationVec
322 // ----------------------------------------------------------------------
323 std::vector<std::string> pcapLocationVec;
324 if (!pcapLocations.empty())
325 {
326 std::stringstream sStream(pcapLocations);
327
328 while (sStream.good())
329 {
330 std::string substr;
331 getline(sStream, substr, ',');
332 if (vssearch(substr, pcapTaps))
333 {
334 pcapLocationVec.push_back(substr);
335 }
336 else
337 {
338 NS_LOG_ERROR("WARNING: Unrecognized PCAP location: <" + substr + ">");
339 }
340 }
341
342 for (auto ploc = pcapLocationVec.begin(); ploc != pcapLocationVec.end(); ++ploc)
343 {
344 NS_LOG_INFO("PCAP capture at: <" + *ploc + ">");
345 }
346 }
347
348 // ======================================================================
349 // Set some simulator-wide values
350 // ======================================================================
351
352 // ----------------------------------------------------------------------
353 // Set PCAP packet capture maximum packet length
354 // ----------------------------------------------------------------------
355 if (snapLen != PcapFile::SNAPLEN_DEFAULT)
356 {
357 Config::SetDefault("ns3::PcapFileWrapper::CaptureSize", UintegerValue(snapLen));
358 }
359
360 // ======================================================================
361 // Create the nodes & links required for the topology shown in comments above.
362 // ----------------------------------------------------------------------
363 NS_LOG_INFO("INFO: Create nodes."); // - - - - - - - - - - - - - - - -
364 // Node IP : Description
365 // - - - - - - - - - - - - - - - -
366 Ptr<Node> t2 = CreateObject<Node>(); // 192.168.1.2 : Top multi-switch udp echo client
367 Ptr<Node> t3 = CreateObject<Node>(); // 192.168.1.3 : Top single-switch udp echo server
368 // :
369 Ptr<Node> ts1 = CreateObject<Node>(); // <no IP> : Top switch #1 (bridge)
370 Ptr<Node> ts2 = CreateObject<Node>(); // <no IP> : Top switch #2 (bridge)
371 Ptr<Node> ts3 = CreateObject<Node>(); // <no IP> : Top switch #3 (bridge)
372 Ptr<Node> ts4 = CreateObject<Node>(); // <no IP> : Top switch #4 (bridge)
373 // :
374 Ptr<Node> tr = CreateObject<Node>(); // 192.168.1.1 : Router connecting top LAN & WAN
375 // 76.1.1.1 :
376 // :
377 Ptr<Node> br = CreateObject<Node>(); // 76.1.1.2 : Router connecting WAN & bottom LANs
378 // 192.168.2.1 :
379 // :
380 Ptr<Node> bs1 = CreateObject<Node>(); // <no IP> : Bottom switch #1 (bridge)
381 Ptr<Node> bs2 = CreateObject<Node>(); // <no IP> : Bottom switch #2 (bridge)
382 Ptr<Node> bs3 = CreateObject<Node>(); // <no IP> : Bottom switch #3 (bridge)
383 Ptr<Node> bs4 = CreateObject<Node>(); // <no IP> : Bottom switch #4 (bridge)
384 Ptr<Node> bs5 = CreateObject<Node>(); // <no IP> : Bottom switch #5 (bridge)
385 // :
386 Ptr<Node> b2 = CreateObject<Node>(); // 192.168.2.2 : Bottom multi-switch udp echo server
387
388 Ptr<Node> b3 = CreateObject<Node>(); // 192.168.2.3 : Bottom single-switch udp echo client
389 // - - - - - - - - - - - - - - - -
390
391 // ----------------------------------------------------------------------
392 // Give the nodes names
393 // ----------------------------------------------------------------------
394 Names::Add("t2", t2);
395 Names::Add("t3", t3);
396 Names::Add("ts1", ts1);
397 Names::Add("ts2", ts2);
398 Names::Add("ts3", ts3);
399 Names::Add("ts4", ts4);
400 Names::Add("tr", tr);
401 Names::Add("br", br);
402 Names::Add("bs1", bs1);
403 Names::Add("bs2", bs2);
404 Names::Add("bs3", bs3);
405 Names::Add("bs4", bs4);
406 Names::Add("bs5", bs5);
407 Names::Add("b2", b2);
408 Names::Add("b3", b3);
409
410 // ======================================================================
411 // Create CSMA links to use for connecting LAN nodes together
412 // ----------------------------------------------------------------------
413
414 // ----------------------------------------
415 // CSMA [X]
416 // ----------------------------------------
417 NS_LOG_INFO("L2: Create a " << csmaXLinkDataRate << " " << csmaXLinkDelay
418 << " CSMA link for csmaX for LANs.");
419 CsmaHelper csmaX;
420 csmaX.SetChannelAttribute("DataRate", StringValue(csmaXLinkDataRate));
421 csmaX.SetChannelAttribute("Delay", StringValue(csmaXLinkDelay));
422
423 // ----------------------------------------
424 // CSMA [Y]
425 // ----------------------------------------
426 NS_LOG_INFO("L2: Create a " << csmaYLinkDataRate << " " << csmaYLinkDelay
427 << " CSMA link for csmaY for LANs.");
428 CsmaHelper csmaY;
429 csmaY.SetChannelAttribute("DataRate", StringValue(csmaYLinkDataRate));
430 csmaY.SetChannelAttribute("Delay", StringValue(csmaYLinkDelay));
431
432 // ----------------------------------------------------------------------
433 // Now, connect the top LAN nodes together with csma links.
434 // ----------------------------------------------------------------------
435 NS_LOG_INFO("L2: Connect nodes on top LAN together with half-duplex CSMA links.");
436
437 // Multi-switch top LAN chain: t2-ts4-ts3-ts2-ts1-tr
438 NetDeviceContainer link_t2_ts4 = csmaX.Install(NodeContainer(t2, ts4));
439 NetDeviceContainer link_ts4_ts3 = csmaY.Install(NodeContainer(ts4, ts3));
440 NetDeviceContainer link_ts3_ts2 = csmaX.Install(NodeContainer(ts3, ts2));
441 NetDeviceContainer link_ts2_ts1 = csmaY.Install(NodeContainer(ts2, ts1));
442
443 // Single-switch top LAN link: t3-ts1-tr
444 NetDeviceContainer link_t3_ts1 = csmaX.Install(NodeContainer(t3, ts1));
445
446 // Common link for top LAN between ts1 and tr (for t2 and t3 to get to tr)
447 NetDeviceContainer link_tr_ts1 = csmaY.Install(NodeContainer(tr, ts1));
448
449 // ----------------------------------------------------------------------
450 // And repeat above steps to connect the bottom LAN nodes together
451 // ----------------------------------------------------------------------
452 NS_LOG_INFO("L2: Connect nodes on bottom LAN together with half-duplex CSMA links.");
453
454 // Multi-switch bottom LAN chain: b2-bs5-bs4-bs3-bs2-bs1-br
455 NetDeviceContainer link_b2_bs5 = csmaY.Install(NodeContainer(b2, bs5));
456 NetDeviceContainer link_bs5_bs4 = csmaX.Install(NodeContainer(bs5, bs4));
457 NetDeviceContainer link_bs4_bs3 = csmaY.Install(NodeContainer(bs4, bs3));
458 NetDeviceContainer link_bs3_bs2 = csmaX.Install(NodeContainer(bs3, bs2));
459 NetDeviceContainer link_bs2_bs1 = csmaY.Install(NodeContainer(bs2, bs1));
460
461 // Single-switch bottom LAN link: b3-bs1-br
462 NetDeviceContainer link_b3_bs1 = csmaY.Install(NodeContainer(b3, bs1));
463
464 // Common link for bottom LAN between bs1 and br (for b2 and b3 to get to br)
465 NetDeviceContainer link_br_bs1 = csmaX.Install(NodeContainer(br, bs1));
466
467 // ======================================================================
468 // Create a point-to-point link for connecting WAN nodes together
469 // (this type of link is full-duplex)
470 // ----------------------------------------------------------------------
471 NS_LOG_INFO("L2: Create a " << p2pLinkDataRate << " " << p2pLinkDelay
472 << " Point-to-Point link for the WAN.");
473
475 p2p.SetDeviceAttribute("DataRate", StringValue(p2pLinkDataRate));
476 p2p.SetChannelAttribute("Delay", StringValue(p2pLinkDelay));
477
478 // ----------------------------------------------------------------------
479 // Now, connect top router to bottom router with a p2p WAN link
480 // ----------------------------------------------------------------------
481 NS_LOG_INFO("L2: Connect the routers together with the Point-to-Point WAN link.");
482
483 NetDeviceContainer link_tr_br;
484 link_tr_br = p2p.Install(NodeContainer(tr, br));
485
486 // ======================================================================
487 // Manually create the list of NetDevices for each switch
488 // ----------------------------------------------------------------------
489
490 // Top Switch 4 NetDevices
491 NetDeviceContainer ts4nd;
492 ts4nd.Add(link_t2_ts4.Get(1));
493 ts4nd.Add(link_ts4_ts3.Get(0));
494
495 // Top Switch 3 NetDevices
496 NetDeviceContainer ts3nd;
497 ts3nd.Add(link_ts4_ts3.Get(1));
498 ts3nd.Add(link_ts3_ts2.Get(0));
499
500 // Top Switch 2 NetDevices
501 NetDeviceContainer ts2nd;
502 ts2nd.Add(link_ts3_ts2.Get(1));
503 ts2nd.Add(link_ts2_ts1.Get(0));
504
505 // Top Switch 1 NetDevices
506 NetDeviceContainer ts1nd;
507 ts1nd.Add(link_ts2_ts1.Get(1));
508 ts1nd.Add(link_t3_ts1.Get(1));
509 ts1nd.Add(link_tr_ts1.Get(1));
510
511 // Bottom Switch 1 NetDevices
512 NetDeviceContainer bs1nd;
513 bs1nd.Add(link_br_bs1.Get(1));
514 bs1nd.Add(link_bs2_bs1.Get(1));
515 bs1nd.Add(link_b3_bs1.Get(1));
516
517 // Bottom Switch 2 NetDevices
518 NetDeviceContainer bs2nd;
519 bs2nd.Add(link_bs2_bs1.Get(0));
520 bs2nd.Add(link_bs3_bs2.Get(1));
521
522 // Bottom Switch 3 NetDevices
523 NetDeviceContainer bs3nd;
524 bs3nd.Add(link_bs3_bs2.Get(0));
525 bs3nd.Add(link_bs4_bs3.Get(1));
526
527 // Bottom Switch 4 NetDevices
528 NetDeviceContainer bs4nd;
529 bs4nd.Add(link_bs4_bs3.Get(0));
530 bs4nd.Add(link_bs5_bs4.Get(1));
531
532 // Bottom Switch 5 NetDevices
533 NetDeviceContainer bs5nd;
534 bs5nd.Add(link_bs5_bs4.Get(0));
535 bs5nd.Add(link_b2_bs5.Get(1));
536
537 // ======================================================================
538 // Install bridging code on each switch
539 // ----------------------------------------------------------------------
540 BridgeHelper bridge;
541
542 bridge.Install(ts1, ts1nd);
543 bridge.Install(ts2, ts2nd);
544 bridge.Install(ts3, ts3nd);
545 bridge.Install(ts4, ts4nd);
546
547 bridge.Install(bs1, bs1nd);
548 bridge.Install(bs2, bs2nd);
549 bridge.Install(bs3, bs3nd);
550 bridge.Install(bs4, bs4nd);
551 bridge.Install(bs5, bs5nd);
552
553 // ======================================================================
554 // Install the L3 internet stack (TCP/IP)
555 // ----------------------------------------------------------------------
556 InternetStackHelper ns3IpStack;
557
558 // ----------------------------------------------------------------------
559 // Install the L3 internet stack on UDP endpoints
560 // ----------------------------------------------------------------------
561 NS_LOG_INFO("L3: Install the ns3 IP stack on udp client and server nodes.");
562 NodeContainer endpointNodes(t2, t3, b2, b3);
563 ns3IpStack.Install(endpointNodes);
564
565 // ----------------------------------------------------------------------
566 // Install the L3 internet stack on routers.
567 // ----------------------------------------------------------------------
568 NS_LOG_INFO("L3: Install the ns3 IP stack on routers.");
569 NodeContainer routerNodes(tr, br);
570 ns3IpStack.Install(routerNodes);
571
572 // ======================================================================
573 // Assign top LAN IP addresses
574 // ----------------------------------------------------------------------
575 NS_LOG_INFO("L3: Assign top LAN IP Addresses.");
576
577 NetDeviceContainer topLanIpDevices; // - - - - - -- - - - - - -
578 topLanIpDevices.Add(link_tr_ts1.Get(0)); // NOTE: order matters here
579 topLanIpDevices.Add(link_t2_ts4.Get(0)); // for IP address
580 topLanIpDevices.Add(link_t3_ts1.Get(0)); // assignment
581 // - - - - - -- - - - - - -
583 ipv4.SetBase("192.168.1.0", "255.255.255.0");
584 ipv4.Assign(topLanIpDevices);
585
586 // ----------------------------------------------------------------------
587 // Assign bottom LAN IP addresses
588 // ----------------------------------------------------------------------
589 NS_LOG_INFO("L3: Assign bottom LAN IP Addresses.");
590
591 NetDeviceContainer botLanIpDevices; // - - - - - -- - - - - - -
592 botLanIpDevices.Add(link_br_bs1.Get(0)); // NOTE: order matters here
593 botLanIpDevices.Add(link_b2_bs5.Get(0)); // for IP address
594 botLanIpDevices.Add(link_b3_bs1.Get(0)); // assignment
595 // - - - - - -- - - - - - -
596
597 ipv4.SetBase("192.168.2.0", "255.255.255.0");
598 ipv4.Assign(botLanIpDevices);
599
600 // ----------------------------------------------------------------------
601 // Assign WAN IP addresses
602 // ----------------------------------------------------------------------
603 NS_LOG_INFO("L3: Assign WAN IP Addresses.");
604
605 ipv4.SetBase("76.1.1.0", "255.255.255.0");
606 ipv4.Assign(link_tr_br);
607
608 // ======================================================================
609 // Calculate and populate routing tables
610 // ----------------------------------------------------------------------
611 NS_LOG_INFO("L3: Populate routing tables.");
613
614 // ======================================================================
615 // Multi-Switch UDP traffic generation
616 // ----------------------------------------------------------------------
618
619 if (enableUdpMultiSW)
620 {
621 // ------------------------------------------------------------------
622 // Install multi-switch UDP echo server on b2
623 // ------------------------------------------------------------------
624 NS_LOG_INFO("APP: Multi-Switch UDP server (on node b2 of bottom LAN)");
625
626 UdpEchoServerHelper server(udpEchoPort);
627
628 ApplicationContainer serverApp = server.Install(b2);
629 serverApp.Start(Seconds(0.5));
630 serverApp.Stop(Seconds(simDurationSeconds));
631
632 // ------------------------------------------------------------------
633 // Install multi-switch UDP echo client on t2
634 // ------------------------------------------------------------------
635 NS_LOG_INFO("APP: Multi-Switch UDP client (on node t2 of top LAN)");
636
637 Time interPacketInterval = Seconds(0.005);
638 uint32_t packetSize = 1000;
639 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
640
641 UdpEchoClientHelper client(Ipv4Address("192.168.2.2"), udpEchoPort);
642
643 client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
644 client.SetAttribute("Interval", TimeValue(interPacketInterval));
645 client.SetAttribute("PacketSize", UintegerValue(packetSize));
646
647 ApplicationContainer clientApp = client.Install(t2);
648 clientApp.Start(Seconds(0.5));
649 clientApp.Stop(Seconds(simDurationSeconds));
650 }
651
652 // ======================================================================
653 // Single-Switch UDP traffic generation
654 // ----------------------------------------------------------------------
655 if (enableUdpSingleSW)
656 {
657 // ------------------------------------------------------------------
658 // Install single-switch UDP echo server on t3
659 // ------------------------------------------------------------------
660 NS_LOG_INFO("APP: Single-Switch UDP server (on node t3 of top LAN)");
661
662 UdpEchoServerHelper server(udpEchoPort);
663
664 ApplicationContainer serverApp = server.Install(t3);
665 serverApp.Start(Seconds(0.5));
666 serverApp.Stop(Seconds(simDurationSeconds));
667
668 // ------------------------------------------------------------------
669 // Install single-switch UDP echo client on b3
670 // ------------------------------------------------------------------
671 NS_LOG_INFO("APP: Single-Switch UDP client (on node b3 bottom LAN)");
672
673 Time interPacketInterval = Seconds(0.005);
674 uint32_t packetSize = 1000;
675 uint32_t maxPacketCount = (simDurationSeconds - 2.0) / 0.005;
676
677 UdpEchoClientHelper client(Ipv4Address("192.168.1.3"), udpEchoPort);
678
679 client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
680 client.SetAttribute("Interval", TimeValue(interPacketInterval));
681 client.SetAttribute("PacketSize", UintegerValue(packetSize));
682
683 ApplicationContainer clientApp = client.Install(b3);
684 clientApp.Start(Seconds(0.5));
685 clientApp.Stop(Seconds(simDurationSeconds));
686 }
687
688 // ======================================================================
689 // Print routing tables at T=0.1
690 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
691 // NOTE: Node 0 and Node 13 must have non-empty tables (except for local
692 // loopback and local LAN) if routing is operating correctly.
693 // ----------------------------------------------------------------------
694 NS_LOG_INFO("Set up to print routing tables at T=0.1s");
695
696 Ptr<OutputStreamWrapper> routingStream =
697 Create<OutputStreamWrapper>("global-routing-multi-switch-plus-router.routes",
698 std::ios::out);
699
701
702 // ======================================================================
703 // Configure PCAP traces
704 // ----------------------------------------------------------------------
705 NS_LOG_INFO("Configure PCAP Tracing (if any configured).");
706
707 // - - - - - - - - - - - - - -
708 // multi-switch UDP echo client
709 // - - - - - - - - - - - - - -
710 if (vssearch("t2", pcapLocationVec))
711 {
712 csmaX.EnablePcap("t2.pcap", topLanIpDevices.Get(1), true, true);
713 }
714
715 // - - - - - - - - - - - - - -
716 // multi-switch UDP echo server
717 // - - - - - - - - - - - - - -
718 if (vssearch("b2", pcapLocationVec))
719 {
720 csmaY.EnablePcap("b2.pcap", botLanIpDevices.Get(1), true, true);
721 }
722
723 // - - - - - - - - - - - - - -
724 // single-switch UDP echo client
725 // - - - - - - - - - - - - - -
726 if (vssearch("b3", pcapLocationVec))
727 {
728 csmaY.EnablePcap("b3.pcap", botLanIpDevices.Get(2), true, true);
729 }
730
731 // - - - - - - - - - - - - - -
732 // single-switch UDP echo server
733 // - - - - - - - - - - - - - -
734 if (vssearch("t3", pcapLocationVec))
735 {
736 csmaX.EnablePcap("t3.pcap", topLanIpDevices.Get(2), true, true);
737 }
738
739 // - - - - - - - - - - - - - -
740 // top router, LAN side
741 // - - - - - - - - - - - - - -
742 if (vssearch("trlan", pcapLocationVec))
743 {
744 csmaY.EnablePcap("trlan.pcap", topLanIpDevices.Get(0), true, true);
745 }
746
747 // - - - - - - - - - - - - - -
748 // bottom router, LAN side
749 // - - - - - - - - - - - - - -
750 if (vssearch("brlan", pcapLocationVec))
751 {
752 csmaX.EnablePcap("brlan.pcap", botLanIpDevices.Get(0), true, true);
753 }
754
755 // - - - - - - - - - - - - - -
756 // top router, WAN side
757 // - - - - - - - - - - - - - -
758 if (vssearch("trwan", pcapLocationVec))
759 {
760 p2p.EnablePcap("trwan.pcap", link_tr_br.Get(0), true, true);
761 }
762
763 // - - - - - - - - - - - - - -
764 // bottom router, WAN side
765 // - - - - - - - - - - - - - -
766 if (vssearch("brwan", pcapLocationVec))
767 {
768 p2p.EnablePcap("brwan.pcap", link_tr_br.Get(1), true, true);
769 }
770
771 // ======================================================================
772 // Now, do the actual simulation.
773 // ----------------------------------------------------------------------
774 NS_LOG_INFO("Run Simulation for " << simDurationSeconds << " seconds.");
775
776 Simulator::Stop(Seconds(simDurationSeconds));
778
780 NS_LOG_INFO("Done.");
781
782 return 0;
783}
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
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...
Parse command-line arguments.
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
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 void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition names.cc:764
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.
static const uint32_t SNAPLEN_DEFAULT
Default value for maximum octets to save per packet.
Definition pcap-file.h:35
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
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
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Hold an unsigned integer type.
Definition uinteger.h:34
#define vssearch(loc, vec)
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
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:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:291
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:93
bool verbose
static const uint32_t packetSize
Packet size generated at the AP.