author | Craig Dowell <craigdo@ee.washington.edu> |
Thu, 13 Sep 2007 10:53:24 -0700 | |
changeset 1501 | 665e07dbd919 |
parent 1499 | 93d51d757afa |
parent 1494 | c2985e1cd091 |
child 1504 | 36ecc970ba96 |
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 |
|
28 |
#include "ns3/command-line.h" |
|
29 |
#include "ns3/default-value.h" |
|
30 |
#include "ns3/ptr.h" |
|
31 |
#include "ns3/random-variable.h" |
|
32 |
#include "ns3/debug.h" |
|
33 |
#include "ns3/simulator.h" |
|
34 |
#include "ns3/nstime.h" |
|
35 |
#include "ns3/data-rate.h" |
|
36 |
#include "ns3/ascii-trace.h" |
|
37 |
#include "ns3/pcap-trace.h" |
|
38 |
#include "ns3/internet-node.h" |
|
1272 | 39 |
#include "ns3/csma-channel.h" |
40 |
#include "ns3/csma-net-device.h" |
|
41 |
#include "ns3/csma-topology.h" |
|
42 |
#include "ns3/csma-ipv4-topology.h" |
|
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
43 |
#include "ns3/mac48-address.h" |
987 | 44 |
#include "ns3/ipv4-address.h" |
1171
335886fe4ddd
InetAddress -> InetSocketAddress
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
45 |
#include "ns3/inet-socket-address.h" |
987 | 46 |
#include "ns3/ipv4.h" |
47 |
#include "ns3/socket.h" |
|
48 |
#include "ns3/ipv4-route.h" |
|
49 |
#include "ns3/onoff-application.h" |
|
50 |
||
51 |
using namespace ns3; |
|
52 |
||
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
53 |
NS_DEBUG_COMPONENT_DEFINE ("CsmaOneSubnet"); |
987 | 54 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
55 |
int |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
56 |
main (int argc, char *argv[]) |
987 | 57 |
{ |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
58 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
59 |
// 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
|
60 |
// 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
|
61 |
// |
991 | 62 |
#if 0 |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
63 |
DebugComponentEnable("CsmaOneSubnet"); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
64 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
65 |
DebugComponentEnable("Object"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
66 |
DebugComponentEnable("Queue"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
67 |
DebugComponentEnable("DropTailQueue"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
68 |
DebugComponentEnable("Channel"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
69 |
DebugComponentEnable("CsmaChannel"); |
1272 | 70 |
DebugComponentEnable("CsmaNetDevice"); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
71 |
DebugComponentEnable("Ipv4L3Protocol"); |
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
72 |
DebugComponentEnable("NetDevice"); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
73 |
DebugComponentEnable("PacketSocket"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
74 |
DebugComponentEnable("OnOffApplication"); |
1499
93d51d757afa
working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents:
1435
diff
changeset
|
75 |
DebugComponentEnable("Socket"); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
76 |
DebugComponentEnable("UdpSocket"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
77 |
DebugComponentEnable("UdpL4Protocol"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
78 |
DebugComponentEnable("Ipv4L3Protocol"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
79 |
DebugComponentEnable("Ipv4StaticRouting"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
80 |
DebugComponentEnable("Ipv4Interface"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
81 |
DebugComponentEnable("ArpIpv4Interface"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
82 |
DebugComponentEnable("Ipv4LoopbackInterface"); |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
83 |
#endif |
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 |
// Set up default values for the simulation. Use the DefaultValue::Bind() |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
86 |
// technique to tell the system what subclass of Queue to use. The Bind |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
87 |
// command command tells the queue factory which class to instantiate when the |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
88 |
// queue factory is invoked in the topology code |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
89 |
// |
1224
7cbc1d661b89
rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1208
diff
changeset
|
90 |
DefaultValue::Bind ("Queue", "DropTailQueue"); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
91 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
92 |
// 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
|
93 |
// run-time, via command-line arguments |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
94 |
// |
987 | 95 |
CommandLine::Parse (argc, argv); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
96 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
97 |
// 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
|
98 |
// |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
99 |
NS_DEBUG("Create nodes."); |
987 | 100 |
Ptr<Node> n0 = Create<InternetNode> (); |
101 |
Ptr<Node> n1 = Create<InternetNode> (); |
|
102 |
Ptr<Node> n2 = Create<InternetNode> (); |
|
103 |
Ptr<Node> n3 = Create<InternetNode> (); |
|
104 |
||
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
105 |
NS_DEBUG("Create channels."); |
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 |
// Explicitly create the channels required by the topology (shown above). |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
108 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
109 |
Ptr<CsmaChannel> lan = CsmaTopology::CreateCsmaChannel( |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
110 |
DataRate(5000000), MilliSeconds(2)); |
987 | 111 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
112 |
NS_DEBUG("Build Topology."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
113 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
114 |
// Now fill out the topology by creating the net devices required to connect |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
115 |
// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
116 |
// create a net device, add a MAC address (in memory of the pink flamingo) and |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
117 |
// connect the net device to a nodes and also to a channel. the |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
118 |
// AddIpv4CsmaNetDevice method returns a net device index for the net device |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
119 |
// created on the node. Interpret nd0 as the net device we created for node |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
120 |
// zero. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
121 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
122 |
uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
123 |
Mac48Address("08:00:2e:00:00:00")); |
987 | 124 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
125 |
uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
126 |
Mac48Address("08:00:2e:00:00:01")); |
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 |
uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
129 |
Mac48Address("08:00:2e:00:00:02")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
130 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
131 |
uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
132 |
Mac48Address("08:00:2e:00:00:03")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
133 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
134 |
NS_DEBUG ("nd0 = " << nd0); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
135 |
NS_DEBUG ("nd1 = " << nd1); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
136 |
NS_DEBUG ("nd2 = " << nd2); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
137 |
NS_DEBUG ("nd3 = " << nd3); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
138 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
139 |
// 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
|
140 |
// |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
141 |
NS_DEBUG("Assign IP Addresses."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
142 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
143 |
// XXX BUGBUG |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
144 |
// Need a better way to get the interface index. The point-to-point topology |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
145 |
// as implemented can't return the index since it creates interfaces on both |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
146 |
// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
147 |
// method on Ipv4 to find the interface index corresponding to a given ipv4 |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
148 |
// address. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
149 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
150 |
// Assign IP addresses to the net devices and associated interfaces |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
151 |
// on the lan. The AddIpv4Address method returns an Ipv4 interface index |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
152 |
// which we do not need here. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
153 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
154 |
CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
155 |
Ipv4Mask("255.255.255.0")); |
987 | 156 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
157 |
CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
158 |
Ipv4Mask("255.255.255.0")); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
159 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
160 |
CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
161 |
Ipv4Mask("255.255.255.0")); |
987 | 162 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
163 |
CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
164 |
Ipv4Mask("255.255.255.0")); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
165 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
166 |
// 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
|
167 |
// |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
168 |
NS_DEBUG("Create Applications."); |
987 | 169 |
Ptr<OnOffApplication> ooff = Create<OnOffApplication> ( |
170 |
n0, |
|
1204
d40723d53e3d
InetSocketAddress: replace explicit conversion to implicit conversion
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1171
diff
changeset
|
171 |
InetSocketAddress ("10.1.1.2", 80), |
987 | 172 |
"Udp", |
173 |
ConstantVariable(1), |
|
174 |
ConstantVariable(0)); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
175 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
176 |
// Tell the application when to start and stop. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
177 |
// |
987 | 178 |
ooff->Start(Seconds(1.0)); |
179 |
ooff->Stop (Seconds(10.0)); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
180 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
181 |
// 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
|
182 |
// |
987 | 183 |
ooff = Create<OnOffApplication> ( |
184 |
n3, |
|
1204
d40723d53e3d
InetSocketAddress: replace explicit conversion to implicit conversion
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1171
diff
changeset
|
185 |
InetSocketAddress ("10.1.1.1", 80), |
987 | 186 |
"Udp", |
187 |
ConstantVariable(1), |
|
188 |
ConstantVariable(0)); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
189 |
|
987 | 190 |
ooff->Start(Seconds(1.1)); |
191 |
ooff->Stop (Seconds(10.0)); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
192 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
193 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
194 |
// Trace output will be sent to the file "csma-one-subnet.tr" |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
195 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
196 |
NS_DEBUG("Configure Tracing."); |
1272 | 197 |
AsciiTrace asciitrace ("csma-one-subnet.tr"); |
991 | 198 |
asciitrace.TraceAllNetDeviceRx (); |
199 |
asciitrace.TraceAllQueues (); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
200 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
201 |
// 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
|
202 |
// The output files will be named: |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
203 |
// csma-one-subnet.pcap-<nodeId>-<interfaceId> |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
204 |
// 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
|
205 |
// display timestamps correctly) |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
206 |
// |
1272 | 207 |
PcapTrace pcaptrace ("csma-one-subnet.pcap"); |
991 | 208 |
pcaptrace.TraceAllIp (); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
209 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
210 |
// Now, do the actual simulation. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
211 |
// |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
212 |
NS_DEBUG("Run Simulation."); |
987 | 213 |
Simulator::Run (); |
214 |
Simulator::Destroy (); |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
215 |
NS_DEBUG("Done."); |
987 | 216 |
} |