author | Tom Henderson <tomh@tomh.org> |
Mon, 28 Sep 2015 20:27:25 -0700 | |
changeset 11676 | 05ea1489e509 |
parent 9000 | 3ec20a64fd08 |
permissions | -rw-r--r-- |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
* |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
* Contributed by: Luis Cortes (cortes@gatech.edu) |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
*/ |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
// This script exercises global routing code in a mixed point-to-point |
6317
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
21 |
// and csma/cd environment. We bring up and down interfaces and observe |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
22 |
// the effect on global routing. We explicitly enable the attribute |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
23 |
// to respond to interface events, so that routes are recomputed |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
24 |
// automatically. |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
// |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
// Network topology |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
// |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
// n0 |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
// \ p-p |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
// \ (shared csma/cd) |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
// n2 -------------------------n3 |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
// / | | |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
// / p-p n4 n5 ---------- n6 |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
// n1 p-p |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
// | | |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
// ---------------------------------------- |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
// p-p |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
// |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
// - at time 1 CBR/UDP flow from n1 to n6's IP address on the n5/n6 link |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
// - at time 10, start similar flow from n1 to n6's address on the n1/n6 link |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
// |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
// Order of events |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
// At pre-simulation time, configure global routes. Shortest path from |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
44 |
// n1 to n6 is via the direct point-to-point link |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
45 |
// At time 1s, start CBR traffic flow from n1 to n6 |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
46 |
// At time 2s, set the n1 point-to-point interface to down. Packets |
6317
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
47 |
// will be diverted to the n1-n2-n5-n6 path |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
48 |
// At time 4s, re-enable the n1/n6 interface to up. n1-n6 route restored. |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
// At time 6s, set the n6-n1 point-to-point Ipv4 interface to down (note, this |
6317
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
50 |
// keeps the point-to-point link "up" from n1's perspective). Traffic will |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
51 |
// flow through the path n1-n2-n5-n6 |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
52 |
// At time 8s, bring the interface back up. Path n1-n6 is restored |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
53 |
// At time 10s, stop the first flow. |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
// At time 11s, start a new flow, but to n6's other IP address (the one |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
// on the n1/n6 p2p link) |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
// At time 12s, bring the n1 interface down between n1 and n6. Packets |
6317
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
57 |
// will be diverted to the alternate path |
4619
aacea61f422f
Fix comments on dynamic-global-routing.cc example
Tom Henderson <tomh@tomh.org>
parents:
4616
diff
changeset
|
58 |
// At time 14s, re-enable the n1/n6 interface to up. This will change |
aacea61f422f
Fix comments on dynamic-global-routing.cc example
Tom Henderson <tomh@tomh.org>
parents:
4616
diff
changeset
|
59 |
// routing back to n1-n6 since the interface up notification will cause |
aacea61f422f
Fix comments on dynamic-global-routing.cc example
Tom Henderson <tomh@tomh.org>
parents:
4616
diff
changeset
|
60 |
// a new local interface route, at higher priority than global routing |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
61 |
// At time 16s, stop the second flow. |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
// - Tracing of queues and packet receptions to file "dynamic-global-routing.tr" |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
#include <iostream> |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
#include <fstream> |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
#include <string> |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
#include <cassert> |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
70 |
#include "ns3/core-module.h" |
6823
a27f86fb4e55
Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents:
6821
diff
changeset
|
71 |
#include "ns3/network-module.h" |
6848
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
72 |
#include "ns3/csma-module.h" |
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
73 |
#include "ns3/internet-module.h" |
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
74 |
#include "ns3/point-to-point-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
75 |
#include "ns3/applications-module.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6317
diff
changeset
|
76 |
#include "ns3/ipv4-global-routing-helper.h" |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
using namespace ns3; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
NS_LOG_COMPONENT_DEFINE ("DynamicGlobalRoutingExample"); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
int |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
83 |
main (int argc, char *argv[]) |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
{ |
6317
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
85 |
// The below value configures the default behavior of global routing. |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
86 |
// By default, it is disabled. To respond to interface events, set to true |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
87 |
Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); |
e4a750adf12c
bug 702: make global routing robust to link/device events
Tom Henderson <tomh@tomh.org>
parents:
6053
diff
changeset
|
88 |
|
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
89 |
// Allow the user to override any of the defaults and the above |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
90 |
// Bind ()s at run-time, via command-line arguments |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
91 |
CommandLine cmd; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
92 |
cmd.Parse (argc, argv); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
93 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
94 |
NS_LOG_INFO ("Create nodes."); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
95 |
NodeContainer c; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
96 |
c.Create (7); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
97 |
NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
98 |
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
99 |
NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
100 |
NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
102 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
103 |
InternetStackHelper internet; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
internet.Install (c); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
// We create the channels first without any IP addressing information |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
NS_LOG_INFO ("Create channels."); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
108 |
PointToPointHelper p2p; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
109 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
111 |
NetDeviceContainer d0d2 = p2p.Install (n0n2); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
112 |
NetDeviceContainer d1d6 = p2p.Install (n1n6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
114 |
NetDeviceContainer d1d2 = p2p.Install (n1n2); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
115 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
116 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
117 |
p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
118 |
NetDeviceContainer d5d6 = p2p.Install (n5n6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
119 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
// We create the channels first without any IP addressing information |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
CsmaHelper csma; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |
csma.SetChannelAttribute ("Delay", StringValue ("2ms")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
124 |
NetDeviceContainer d2345 = csma.Install (n2345); |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
125 |
|
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
126 |
// Later, we add IP addresses. |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
127 |
NS_LOG_INFO ("Assign IP Addresses."); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
128 |
Ipv4AddressHelper ipv4; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
129 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
130 |
ipv4.Assign (d0d2); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
131 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
132 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
ipv4.Assign (d1d2); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
134 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
135 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
136 |
Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
137 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
138 |
ipv4.SetBase ("10.250.1.0", "255.255.255.0"); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
139 |
ipv4.Assign (d2345); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
140 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
141 |
ipv4.SetBase ("172.16.1.0", "255.255.255.0"); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
142 |
Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
143 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
144 |
// Create router nodes, initialize routing database and set up the routing |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
145 |
// tables in the nodes. |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4435
diff
changeset
|
146 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
147 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
148 |
// Create the OnOff application to send UDP datagrams of size |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
149 |
// 210 bytes at a rate of 448 Kb/s |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
150 |
NS_LOG_INFO ("Create Applications."); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
151 |
uint16_t port = 9; // Discard port (RFC 863) |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
152 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
153 |
InetSocketAddress (i5i6.GetAddress (1), port)); |
9000
3ec20a64fd08
Add a constant rate setting function to the on-off helper
Mitch Watrous
parents:
8966
diff
changeset
|
154 |
onoff.SetConstantRate (DataRate ("2kbps")); |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
onoff.SetAttribute ("PacketSize", UintegerValue (50)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
157 |
ApplicationContainer apps = onoff.Install (c.Get (1)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
apps.Start (Seconds (1.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
159 |
apps.Stop (Seconds (10.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
160 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
161 |
// Create a second OnOff application to send UDP datagrams of size |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
162 |
// 210 bytes at a rate of 448 Kb/s |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
163 |
OnOffHelper onoff2 ("ns3::UdpSocketFactory", |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
164 |
InetSocketAddress (i1i6.GetAddress (1), port)); |
8966
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7196
diff
changeset
|
165 |
onoff2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); |
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7196
diff
changeset
|
166 |
onoff2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
167 |
onoff2.SetAttribute ("DataRate", StringValue ("2kbps")); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
168 |
onoff2.SetAttribute ("PacketSize", UintegerValue (50)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
169 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
170 |
ApplicationContainer apps2 = onoff2.Install (c.Get (1)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
171 |
apps2.Start (Seconds (11.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
172 |
apps2.Stop (Seconds (16.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
173 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
174 |
// Create an optional packet sink to receive these packets |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
175 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
176 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
177 |
apps = sink.Install (c.Get (6)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
178 |
apps.Start (Seconds (1.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
179 |
apps.Stop (Seconds (10.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
180 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
181 |
PacketSinkHelper sink2 ("ns3::UdpSocketFactory", |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
182 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
183 |
apps2 = sink2.Install (c.Get (6)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
184 |
apps2.Start (Seconds (11.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
185 |
apps2.Stop (Seconds (16.0)); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
186 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
187 |
|
6013 | 188 |
AsciiTraceHelper ascii; |
6053
b17ea72acee9
OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6049
diff
changeset
|
189 |
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("dynamic-global-routing.tr"); |
6013 | 190 |
p2p.EnableAsciiAll (stream); |
191 |
csma.EnableAsciiAll (stream); |
|
6027 | 192 |
internet.EnableAsciiIpv4All (stream); |
6013 | 193 |
|
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
194 |
p2p.EnablePcapAll ("dynamic-global-routing"); |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
195 |
csma.EnablePcapAll ("dynamic-global-routing", false); |
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
196 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
197 |
Ptr<Node> n1 = c.Get (1); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
198 |
Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> (); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
199 |
// The first ifIndex is 0 for loopback, then the first p2p is numbered 1, |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
200 |
// then the next p2p is numbered 2 |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
201 |
uint32_t ipv4ifIndex1 = 2; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
202 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
203 |
Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
204 |
Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
205 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
206 |
Ptr<Node> n6 = c.Get (6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
207 |
Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> (); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
208 |
// The first ifIndex is 0 for loopback, then the first p2p is numbered 1, |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
209 |
// then the next p2p is numbered 2 |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
210 |
uint32_t ipv4ifIndex6 = 2; |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
211 |
Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
212 |
Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
213 |
|
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
214 |
Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
215 |
Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
216 |
|
6701
a590022a1536
[bug 947] Pretty-print IPv4 routing tables (patch originated by Hemanth Narra)
Tom Henderson <tomh@tomh.org>
parents:
6649
diff
changeset
|
217 |
// Trace routing tables |
a590022a1536
[bug 947] Pretty-print IPv4 routing tables (patch originated by Hemanth Narra)
Tom Henderson <tomh@tomh.org>
parents:
6649
diff
changeset
|
218 |
Ipv4GlobalRoutingHelper g; |
a590022a1536
[bug 947] Pretty-print IPv4 routing tables (patch originated by Hemanth Narra)
Tom Henderson <tomh@tomh.org>
parents:
6649
diff
changeset
|
219 |
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("dynamic-global-routing.routes", std::ios::out); |
a590022a1536
[bug 947] Pretty-print IPv4 routing tables (patch originated by Hemanth Narra)
Tom Henderson <tomh@tomh.org>
parents:
6649
diff
changeset
|
220 |
g.PrintRoutingTableAllAt (Seconds (12), routingStream); |
a590022a1536
[bug 947] Pretty-print IPv4 routing tables (patch originated by Hemanth Narra)
Tom Henderson <tomh@tomh.org>
parents:
6649
diff
changeset
|
221 |
|
4012
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
222 |
NS_LOG_INFO ("Run Simulation."); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
223 |
Simulator::Run (); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
224 |
Simulator::Destroy (); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
225 |
NS_LOG_INFO ("Done."); |
7dc122811f0c
add dynamic global routing example script
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
226 |
} |