author | Mitch Watrous |
Mon, 13 Aug 2012 16:08:13 -0700 | |
changeset 8966 | 060dba23e9bb |
parent 7167 | d99ebd08a67c |
child 9000 | 3ec20a64fd08 |
permissions | -rw-r--r-- |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
2 |
/* |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
6 |
* |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
11 |
* |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
15 |
*/ |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
16 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
17 |
// Network topology |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
18 |
// |
7167
d99ebd08a67c
bridge coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
19 |
// n0 n1 |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
20 |
// | | |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
21 |
// ---------- |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
22 |
// | Switch | |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
23 |
// ---------- |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
24 |
// | | |
7167
d99ebd08a67c
bridge coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
25 |
// n2 n3 |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
26 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
27 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
28 |
// - CBR/UDP flows from n0 to n1 and from n3 to n0 |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
29 |
// - DropTail queues |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
30 |
// - Tracing of queues and packet receptions to file "csma-bridge.tr" |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
31 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
32 |
#include <iostream> |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
33 |
#include <fstream> |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
34 |
|
6821
203367ae7433
merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents:
6635
diff
changeset
|
35 |
#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
|
36 |
#include "ns3/network-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
37 |
#include "ns3/applications-module.h" |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
38 |
#include "ns3/bridge-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
|
39 |
#include "ns3/csma-module.h" |
7089
ebe626d82692
Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents:
6865
diff
changeset
|
40 |
#include "ns3/internet-module.h" |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
41 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
42 |
using namespace ns3; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
43 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
44 |
NS_LOG_COMPONENT_DEFINE ("CsmaBridgeExample"); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
45 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
46 |
int |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
47 |
main (int argc, char *argv[]) |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
48 |
{ |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
49 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
50 |
// Users may find it convenient to turn on explicit debugging |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
51 |
// for selected modules; the below lines suggest how to do this |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
52 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
53 |
#if 0 |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
54 |
LogComponentEnable ("CsmaBridgeExample", LOG_LEVEL_INFO); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
55 |
#endif |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
56 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
57 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
58 |
// Allow the user to override any of the defaults and the above Bind() at |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
59 |
// run-time, via command-line arguments |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
60 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
61 |
CommandLine cmd; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
62 |
cmd.Parse (argc, argv); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
63 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
64 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
65 |
// Explicitly create the nodes required by the topology (shown above). |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
66 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
67 |
NS_LOG_INFO ("Create nodes."); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
68 |
NodeContainer terminals; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
69 |
terminals.Create (4); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
70 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
71 |
NodeContainer csmaSwitch; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
72 |
csmaSwitch.Create (1); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
73 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
74 |
NS_LOG_INFO ("Build Topology"); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
75 |
CsmaHelper csma; |
3451
4e4cb6a885ca
Adapt to evil API breakage
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3440
diff
changeset
|
76 |
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); |
4e4cb6a885ca
Adapt to evil API breakage
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3440
diff
changeset
|
77 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
78 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
79 |
// Create the csma links, from each terminal to the switch |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
80 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
81 |
NetDeviceContainer terminalDevices; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
82 |
NetDeviceContainer switchDevices; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
83 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
84 |
for (int i = 0; i < 4; i++) |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
85 |
{ |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
86 |
NetDeviceContainer link = csma.Install (NodeContainer (terminals.Get (i), csmaSwitch)); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
87 |
terminalDevices.Add (link.Get (0)); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
88 |
switchDevices.Add (link.Get (1)); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
89 |
} |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
90 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
91 |
// Create the bridge netdevice, which will do the packet switching |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
92 |
Ptr<Node> switchNode = csmaSwitch.Get (0); |
3524
028b7de98fb1
bug 276: bridge netdevice has no helper class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3451
diff
changeset
|
93 |
BridgeHelper bridge; |
028b7de98fb1
bug 276: bridge netdevice has no helper class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3451
diff
changeset
|
94 |
bridge.Install (switchNode, switchDevices); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
95 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
96 |
// Add internet stack to the terminals |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
97 |
InternetStackHelper internet; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
98 |
internet.Install (terminals); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
99 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
100 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
101 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
102 |
NS_LOG_INFO ("Assign IP Addresses."); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
103 |
Ipv4AddressHelper ipv4; |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
104 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
105 |
ipv4.Assign (terminalDevices); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
106 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
107 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
108 |
// Create an OnOff application to send UDP datagrams from node zero to node 1. |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
109 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
110 |
NS_LOG_INFO ("Create Applications."); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
111 |
uint16_t port = 9; // Discard port (RFC 863) |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
112 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
113 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
114 |
Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); |
8966
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7167
diff
changeset
|
115 |
onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); |
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7167
diff
changeset
|
116 |
onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
117 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
118 |
ApplicationContainer app = onoff.Install (terminals.Get (0)); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
119 |
// Start the application |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
120 |
app.Start (Seconds (1.0)); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
121 |
app.Stop (Seconds (10.0)); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
122 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
123 |
// Create an optional packet sink to receive these packets |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
124 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
125 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
3715
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
126 |
app = sink.Install (terminals.Get (1)); |
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
127 |
app.Start (Seconds (0.0)); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
128 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
129 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
130 |
// Create a similar flow from n3 to n0, starting at time 1.1 seconds |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
131 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
132 |
onoff.SetAttribute ("Remote", |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
133 |
AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.1"), port))); |
3715
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
134 |
app = onoff.Install (terminals.Get (3)); |
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
135 |
app.Start (Seconds (1.1)); |
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
136 |
app.Stop (Seconds (10.0)); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
137 |
|
3715
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
138 |
app = sink.Install (terminals.Get (0)); |
594e2052e5b2
make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3524
diff
changeset
|
139 |
app.Start (Seconds (0.0)); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
140 |
|
6014 | 141 |
NS_LOG_INFO ("Configure Tracing."); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
142 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
143 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
144 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events. |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
145 |
// Trace output will be sent to the file "csma-bridge.tr" |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
146 |
// |
6014 | 147 |
AsciiTraceHelper ascii; |
148 |
csma.EnableAsciiAll (ascii.CreateFileStream ("csma-bridge.tr")); |
|
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
149 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
150 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
151 |
// Also configure some tcpdump traces; each interface will be traced. |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
152 |
// The output files will be named: |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4225
diff
changeset
|
153 |
// csma-bridge-<nodeId>-<interfaceId>.pcap |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
154 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
155 |
// display timestamps correctly) |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
156 |
// |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
157 |
csma.EnablePcapAll ("csma-bridge", false); |
3440
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
158 |
|
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
159 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
160 |
// Now, do the actual simulation. |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
161 |
// |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
162 |
NS_LOG_INFO ("Run Simulation."); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
163 |
Simulator::Run (); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
164 |
Simulator::Destroy (); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
165 |
NS_LOG_INFO ("Done."); |
4cedf996375d
Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
166 |
} |