author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Fri, 03 Jul 2009 14:12:28 +0100 | |
changeset 4649 | 189238bfdc7f |
parent 4616 | a84f60b6cd12 |
permissions | -rw-r--r-- |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
*/ |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
// Network topology |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
// |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
19 |
// bridge1 The node named bridge1 (node 5 in the nodelist) |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
20 |
// ------------------ has three CMSA net devices that are bridged |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
21 |
// CSMA CSMA CSMA together using a BridgeNetDevice. |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
22 |
// | | | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
23 |
// | | | The bridge node talks over three CSMA channels |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
24 |
// | | | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
25 |
// CSMA CSMA CSMA to three other CSMA net devices |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
26 |
// ---- ---- ---- |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
27 |
// n0 n1 n2 Node two acts as a router and talks to another |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
28 |
// ---- bridge that connects the remaining nodes. |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
29 |
// CSMA |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
30 |
// | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
31 |
// n3 n4 | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
32 |
// ---- ---- | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
33 |
// CSMA CSMA | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
34 |
// | | | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
35 |
// | | | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
36 |
// | | | |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
37 |
// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist) |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
38 |
// ------------------ has three CMSA net devices that are bridged |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
39 |
// bridge2 together using a BridgeNetDevice. |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
40 |
// |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
41 |
// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
42 |
// with three net devices: |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
43 |
// |
3942
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
44 |
// n0 n1 (n0 = 10.1.1.2) |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
45 |
// | | (n1 = 10.1.1.3) Note odd addressing |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
46 |
// ----------- (n2 = 10.1.1.1) |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
47 |
// | bridge1 | <- n5 |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
// ----------- |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
// | |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
50 |
// router <- n2 |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
// | |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
// ----------- |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
53 |
// | bridge2 | <- n6 |
3942
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
54 |
// ----------- (n2 = 10.1.2.1) |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
55 |
// | | (n3 = 10.1.2.2) |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
56 |
// n3 n4 (n4 = 10.1.2.3) |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
// |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
58 |
// So, this example shows two broadcast domains, each interconnected by a bridge |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
// with a router node (n2) interconnecting the layer-2 broadcast domains |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
// It is meant to mirror somewhat the csma-bridge example but adds another |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
// bridged link separated by a router. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
// |
3942
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
64 |
// - CBR/UDP flows from n0 (10.1.1.2) to n1 (10.1.1.3) and from n3 (10.1.2.2) to n0 (10.1.1.3) |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
// - DropTail queues |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
// - Global static routing |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
#include <iostream> |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
#include <fstream> |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
#include "ns3/simulator-module.h" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
#include "ns3/node-module.h" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
#include "ns3/core-module.h" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
#include "ns3/helper-module.h" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
#include "ns3/bridge-module.h" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
using namespace ns3; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample"); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
int |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
main (int argc, char *argv[]) |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
{ |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
// Users may find it convenient to turn on explicit debugging |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
// for selected modules; the below lines suggest how to do this |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
#if 0 |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
#endif |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
// Allow the user to override any of the defaults and the above Bind() at |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
// run-time, via command-line arguments |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
CommandLine cmd; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
cmd.Parse (argc, argv); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
// Explicitly create the nodes required by the topology (shown above). |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
NS_LOG_INFO ("Create nodes."); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
Ptr<Node> n0 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
Ptr<Node> n1 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
Ptr<Node> n2 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
Ptr<Node> n3 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
Ptr<Node> n4 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
Ptr<Node> bridge1 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
Ptr<Node> bridge2 = CreateObject<Node> (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
NS_LOG_INFO ("Build Topology"); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
CsmaHelper csma; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
// Create the csma links, from each terminal to the bridge |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
// This will create six network devices; we'll keep track separately |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
// of the devices on and off the bridge respectively, for later configuration |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
NetDeviceContainer topLanDevices; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
NetDeviceContainer topBridgeDevices; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
// It is easier to iterate the nodes in C++ if we put them into a container |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
NodeContainer topLan (n2, n0, n1); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
for (int i = 0; i < 3; i++) |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
{ |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
130 |
// install a csma channel between the ith toplan node and the bridge node |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
topLanDevices.Add (link.Get (0)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
topBridgeDevices.Add (link.Get (1)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
} |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
|
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
136 |
// |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
137 |
// Now, Create the bridge netdevice, which will do the packet switching. The |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
138 |
// bridge lives on the node bridge1 and bridges together the topBridgeDevices |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
139 |
// which are the three CSMA net devices on the node in the diagram above. |
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
140 |
// |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
BridgeHelper bridge; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
bridge.Install (bridge1, topBridgeDevices); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
|
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4264
diff
changeset
|
144 |
// Add internet stack to the router nodes |
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4264
diff
changeset
|
145 |
NodeContainer routerNodes (n0, n1, n2, n3, n4); |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
InternetStackHelper internet; |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4264
diff
changeset
|
147 |
internet.Install (routerNodes); |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
// Repeat for bottom bridged LAN |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
NetDeviceContainer bottomLanDevices; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
NetDeviceContainer bottomBridgeDevices; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
NodeContainer bottomLan (n2, n3, n4); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
for (int i = 0; i < 3; i++) |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
{ |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
bottomLanDevices.Add (link.Get (0)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
bottomBridgeDevices.Add (link.Get (1)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
} |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
bridge.Install (bridge2, bottomBridgeDevices); |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
160 |
|
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
162 |
NS_LOG_INFO ("Assign IP Addresses."); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
Ipv4AddressHelper ipv4; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
165 |
ipv4.Assign (topLanDevices); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
166 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
167 |
ipv4.Assign (bottomLanDevices); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
168 |
|
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
169 |
// |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
170 |
// Create router nodes, initialize routing database and set up the routing |
3938
972310213d07
Admit possibility that not all nodes are routers.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
171 |
// tables in the nodes. We excuse the bridge nodes from having to serve as |
972310213d07
Admit possibility that not all nodes are routers.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3937
diff
changeset
|
172 |
// routers, since they don't even have internet stacks on them. |
3937
04f9377661b8
convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents:
3935
diff
changeset
|
173 |
// |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4264
diff
changeset
|
174 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
176 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
// Create an OnOff application to send UDP datagrams from node zero to node 1. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
178 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
179 |
NS_LOG_INFO ("Create Applications."); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
180 |
uint16_t port = 9; // Discard port (RFC 863) |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
181 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port))); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
186 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
ApplicationContainer app = onoff.Install (n0); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
// Start the application |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
app.Start (Seconds (1.0)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
app.Stop (Seconds (10.0)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
// Create an optional packet sink to receive these packets |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
193 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
194 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
3942
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
195 |
ApplicationContainer sink1 = sink.Install (n1); |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
196 |
sink1.Start (Seconds (1.0)); |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
197 |
sink1.Stop (Seconds (10.0)); |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
200 |
// Create a similar flow from n3 to n0, starting at time 1.1 seconds |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
201 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
202 |
onoff.SetAttribute ("Remote", |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
203 |
AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
204 |
ApplicationContainer app2 = onoff.Install (n3); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
205 |
app2.Start (Seconds (1.1)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
206 |
app2.Stop (Seconds (10.0)); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
207 |
|
3942
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
208 |
ApplicationContainer sink2 = sink.Install (n0); |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
209 |
sink2.Start (Seconds (1.1)); |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
210 |
sink2.Stop (Seconds (10.0)); |
eef10dbce686
fix bug 114 and bug 66
Craig Dowell <craigdo@ee.washington.edu>
parents:
3938
diff
changeset
|
211 |
|
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
212 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
213 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
214 |
// Trace output will be sent to the file "csma-bridge-one-hop.tr" |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
215 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
216 |
NS_LOG_INFO ("Configure Tracing."); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
217 |
std::ofstream ascii; |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
218 |
ascii.open ("csma-bridge-one-hop.tr"); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
CsmaHelper::EnableAsciiAll (ascii); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
220 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
221 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
222 |
// Also configure some tcpdump traces; each interface will be traced. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
223 |
// The output files will be named: |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4225
diff
changeset
|
224 |
// csma-bridge-<nodeId>-<interfaceId>.pcap |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
225 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
226 |
// display timestamps correctly) |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
227 |
// |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4225
diff
changeset
|
228 |
CsmaHelper::EnablePcapAll ("csma-bridge-one-hop", false); |
3935
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
229 |
|
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
230 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
231 |
// Now, do the actual simulation. |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
232 |
// |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
233 |
NS_LOG_INFO ("Run Simulation."); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
234 |
Simulator::Run (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
Simulator::Destroy (); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
NS_LOG_INFO ("Done."); |
4b18d1e1e2e5
add bridged routing example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
237 |
} |