author | Mitch Watrous |
Mon, 13 Aug 2012 16:08:13 -0700 | |
changeset 8966 | 060dba23e9bb |
parent 7256 | b04ba6772f8c |
child 9000 | 3ec20a64fd08 |
permissions | -rw-r--r-- |
987 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
*/ |
|
16 |
||
17 |
// Network topology |
|
18 |
// |
|
19 |
// n0 n1 n2 n3 |
|
20 |
// | | | | |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
21 |
// ================= |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
22 |
// LAN |
987 | 23 |
// |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
24 |
// - CBR/UDP flows from n0 to n1 and from n3 to n0 |
987 | 25 |
// - DropTail queues |
1272 | 26 |
// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" |
987 | 27 |
|
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
28 |
#include <iostream> |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
29 |
#include <fstream> |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
30 |
|
6821
203367ae7433
merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents:
6014
diff
changeset
|
31 |
#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
|
32 |
#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
|
33 |
#include "ns3/csma-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
34 |
#include "ns3/applications-module.h" |
7089
ebe626d82692
Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents:
6865
diff
changeset
|
35 |
#include "ns3/internet-module.h" |
987 | 36 |
|
37 |
using namespace ns3; |
|
38 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
39 |
NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample"); |
987 | 40 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
41 |
int |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
42 |
main (int argc, char *argv[]) |
987 | 43 |
{ |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
44 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
45 |
// Users may find it convenient to turn on explicit debugging |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
46 |
// for selected modules; the below lines suggest how to do this |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
47 |
// |
991 | 48 |
#if 0 |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
49 |
LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
50 |
#endif |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
51 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
52 |
// Allow the user to override any of the defaults and the above Bind() at |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
53 |
// run-time, via command-line arguments |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
54 |
// |
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
55 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
56 |
cmd.Parse (argc, argv); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
57 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
58 |
// Explicitly create the nodes required by the topology (shown above). |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
59 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
60 |
NS_LOG_INFO ("Create nodes."); |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
61 |
NodeContainer nodes; |
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
62 |
nodes.Create (4); |
987 | 63 |
|
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
64 |
NS_LOG_INFO ("Build Topology"); |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
65 |
CsmaHelper csma; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
66 |
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
67 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
68 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
69 |
// Now fill out the topology by creating the net devices required to connect |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
70 |
// the nodes to the channels and hooking them up. |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
71 |
// |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
72 |
NetDeviceContainer devices = csma.Install (nodes); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
73 |
|
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
74 |
InternetStackHelper internet; |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
75 |
internet.Install (nodes); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
76 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
77 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
78 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
79 |
NS_LOG_INFO ("Assign IP Addresses."); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
80 |
Ipv4AddressHelper ipv4; |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
81 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
82 |
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
987 | 83 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
84 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
85 |
// Create an OnOff application to send UDP datagrams from node zero to node 1. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
86 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
87 |
NS_LOG_INFO ("Create Applications."); |
1514
addb79f47ba5
change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
88 |
uint16_t port = 9; // Discard port (RFC 863) |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
89 |
|
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
90 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
91 |
Address (InetSocketAddress (interfaces.GetAddress (1), port))); |
8966
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7256
diff
changeset
|
92 |
onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); |
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7256
diff
changeset
|
93 |
onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
94 |
|
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
95 |
ApplicationContainer app = onoff.Install (nodes.Get (0)); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
96 |
// Start the application |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
97 |
app.Start (Seconds (1.0)); |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
98 |
app.Stop (Seconds (10.0)); |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
99 |
|
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
100 |
// Create an optional packet sink to receive these packets |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
101 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
7170
8417cff6e353
csma coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
102 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
103 |
app = sink.Install (nodes.Get (1)); |
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
104 |
app.Start (Seconds (0.0)); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
105 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
106 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
107 |
// Create a similar flow from n3 to n0, starting at time 1.1 seconds |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
108 |
// |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
109 |
onoff.SetAttribute ("Remote", |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
110 |
AddressValue (InetSocketAddress (interfaces.GetAddress (0), port))); |
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
111 |
app = onoff.Install (nodes.Get (3)); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7170
diff
changeset
|
112 |
app.Start (Seconds (1.1)); |
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
113 |
app.Stop (Seconds (10.0)); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
114 |
|
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
115 |
app = sink.Install (nodes.Get (0)); |
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
116 |
app.Start (Seconds (0.0)); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
117 |
|
6014 | 118 |
NS_LOG_INFO ("Configure Tracing."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
119 |
// |
6014 | 120 |
// Configure ascii tracing of all enqueue, dequeue, and NetDevice receive |
121 |
// events on all devices. Trace output will be sent to the file |
|
122 |
// "csma-one-subnet.tr" |
|
123 |
// |
|
124 |
AsciiTraceHelper ascii; |
|
125 |
csma.EnableAsciiAll (ascii.CreateFileStream ("csma-one-subnet.tr")); |
|
6011
3fd7841b9c20
ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents:
6009
diff
changeset
|
126 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
127 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
128 |
// Also configure some tcpdump traces; each interface will be traced. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
129 |
// The output files will be named: |
6014 | 130 |
// |
131 |
// csma-one-subnet-<node ID>-<device's interface index>.pcap |
|
132 |
// |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
133 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
134 |
// display timestamps correctly) |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
135 |
// |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
136 |
csma.EnablePcapAll ("csma-one-subnet", false); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
137 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
138 |
// Now, do the actual simulation. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
139 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
140 |
NS_LOG_INFO ("Run Simulation."); |
987 | 141 |
Simulator::Run (); |
142 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
143 |
NS_LOG_INFO ("Done."); |
987 | 144 |
} |