author | Tom Henderson <tomh@tomh.org> |
Fri, 20 Aug 2010 12:17:19 -0700 | |
changeset 6589 | 9c325569fb01 |
parent 6014 | d251d4a44fde |
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 |
|
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
31 |
#include "ns3/simulator-module.h" |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
32 |
#include "ns3/node-module.h" |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
33 |
#include "ns3/core-module.h" |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
34 |
#include "ns3/helper-module.h" |
987 | 35 |
|
36 |
using namespace ns3; |
|
37 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
38 |
NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample"); |
987 | 39 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
40 |
int |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
41 |
main (int argc, char *argv[]) |
987 | 42 |
{ |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
43 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
44 |
// 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
|
45 |
// 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
|
46 |
// |
991 | 47 |
#if 0 |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
48 |
LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
49 |
#endif |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
50 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
51 |
// 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
|
52 |
// run-time, via command-line arguments |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
53 |
// |
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
54 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
55 |
cmd.Parse (argc, argv); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
56 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
57 |
// 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
|
58 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
59 |
NS_LOG_INFO ("Create nodes."); |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
60 |
NodeContainer nodes; |
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
61 |
nodes.Create (4); |
987 | 62 |
|
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
63 |
NS_LOG_INFO ("Build Topology"); |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
64 |
CsmaHelper csma; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
65 |
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
66 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
67 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
68 |
// 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
|
69 |
// 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
|
70 |
// |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
71 |
NetDeviceContainer devices = csma.Install (nodes); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
72 |
|
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
73 |
InternetStackHelper internet; |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
74 |
internet.Install (nodes); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
75 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
76 |
// 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
|
77 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
78 |
NS_LOG_INFO ("Assign IP Addresses."); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
79 |
Ipv4AddressHelper ipv4; |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
80 |
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
|
81 |
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
987 | 82 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
83 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
84 |
// 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
|
85 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
|
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
89 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
90 |
Address (InetSocketAddress (interfaces.GetAddress (1), port))); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
91 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
92 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
93 |
|
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
94 |
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
|
95 |
// Start the application |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
96 |
app.Start (Seconds (1.0)); |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
97 |
app.Stop (Seconds (10.0)); |
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
98 |
|
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
99 |
// 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
|
100 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
101 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
102 |
app = sink.Install (nodes.Get (1)); |
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
103 |
app.Start (Seconds (0.0)); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
104 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
105 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
106 |
// 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
|
107 |
// |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
108 |
onoff.SetAttribute ("Remote", |
3714
249ec8d21b24
use better variable names.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3381
diff
changeset
|
109 |
AddressValue (InetSocketAddress (interfaces.GetAddress (0), port))); |
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
110 |
app = onoff.Install (nodes.Get (3)); |
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
111 |
app.Start(Seconds (1.1)); |
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
112 |
app.Stop (Seconds (10.0)); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
113 |
|
3716
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
114 |
app = sink.Install (nodes.Get (0)); |
458bc4845806
make sure sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3714
diff
changeset
|
115 |
app.Start (Seconds (0.0)); |
2801
edbd094336b5
Move csma-one-subnet to helper api
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
116 |
|
6014 | 117 |
NS_LOG_INFO ("Configure Tracing."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
118 |
// |
6014 | 119 |
// Configure ascii tracing of all enqueue, dequeue, and NetDevice receive |
120 |
// events on all devices. Trace output will be sent to the file |
|
121 |
// "csma-one-subnet.tr" |
|
122 |
// |
|
123 |
AsciiTraceHelper ascii; |
|
124 |
csma.EnableAsciiAll (ascii.CreateFileStream ("csma-one-subnet.tr")); |
|
6011
3fd7841b9c20
ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents:
6009
diff
changeset
|
125 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
126 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
127 |
// 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
|
128 |
// The output files will be named: |
6014 | 129 |
// |
130 |
// csma-one-subnet-<node ID>-<device's interface index>.pcap |
|
131 |
// |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
132 |
// 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
|
133 |
// display timestamps correctly) |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
134 |
// |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
135 |
csma.EnablePcapAll ("csma-one-subnet", false); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
136 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
137 |
// Now, do the actual simulation. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
138 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
139 |
NS_LOG_INFO ("Run Simulation."); |
987 | 140 |
Simulator::Run (); |
141 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
142 |
NS_LOG_INFO ("Done."); |
987 | 143 |
} |