author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 30 Jul 2007 14:07:39 +0200 | |
changeset 1204 | d40723d53e3d |
parent 1171 | 335886fe4ddd |
child 1208 | ad83a13631c1 |
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 |
// Port of ns-2/tcl/ex/simple.tcl to ns-3 |
|
18 |
// |
|
19 |
// Network topology |
|
20 |
// |
|
21 |
// n0 n1 n2 n3 |
|
22 |
// | | | | |
|
23 |
// ===================== |
|
24 |
// |
|
25 |
// - CBR/UDP flows from n0 to n1, and from n3 to n0 |
|
26 |
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. |
|
27 |
// (i.e., DataRate of 448,000 bps) |
|
28 |
// - DropTail queues |
|
29 |
// - Tracing of queues and packet receptions to file "csma-cd-one-subnet.tr" |
|
30 |
||
31 |
#include <iostream> |
|
32 |
#include <fstream> |
|
33 |
#include <string> |
|
34 |
#include <cassert> |
|
35 |
||
36 |
#include "ns3/command-line.h" |
|
37 |
#include "ns3/default-value.h" |
|
38 |
#include "ns3/ptr.h" |
|
39 |
#include "ns3/random-variable.h" |
|
40 |
#include "ns3/debug.h" |
|
41 |
||
42 |
#include "ns3/simulator.h" |
|
43 |
#include "ns3/nstime.h" |
|
44 |
#include "ns3/data-rate.h" |
|
45 |
||
46 |
#include "ns3/ascii-trace.h" |
|
47 |
#include "ns3/pcap-trace.h" |
|
48 |
#include "ns3/internet-node.h" |
|
49 |
#include "ns3/csma-cd-channel.h" |
|
50 |
#include "ns3/csma-cd-net-device.h" |
|
51 |
#include "ns3/csma-cd-topology.h" |
|
52 |
#include "ns3/csma-cd-ipv4-topology.h" |
|
1167 | 53 |
#include "ns3/eui48-address.h" |
987 | 54 |
#include "ns3/ipv4-address.h" |
1171
335886fe4ddd
InetAddress -> InetSocketAddress
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
55 |
#include "ns3/inet-socket-address.h" |
987 | 56 |
#include "ns3/ipv4.h" |
57 |
#include "ns3/socket.h" |
|
58 |
#include "ns3/ipv4-route.h" |
|
59 |
#include "ns3/onoff-application.h" |
|
60 |
||
61 |
#include "ns3/ascii-trace.h" |
|
62 |
||
63 |
#include "ns3/trace-context.h" |
|
64 |
#include "ns3/trace-root.h" |
|
65 |
||
66 |
||
67 |
using namespace ns3; |
|
68 |
||
69 |
||
70 |
int main (int argc, char *argv[]) |
|
71 |
{ |
|
72 |
||
73 |
// Users may find it convenient to turn on explicit debugging |
|
74 |
// for selected modules; the below lines suggest how to do this |
|
991 | 75 |
#if 0 |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
76 |
DebugComponentEnable("CsmaCdNetDevice"); |
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
77 |
DebugComponentEnable("Ipv4L3Protocol"); |
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
78 |
DebugComponentEnable("NetDevice"); |
987 | 79 |
DebugComponentEnable("Channel"); |
80 |
DebugComponentEnable("CsmaCdChannel"); |
|
81 |
DebugComponentEnable("PacketSocket"); |
|
82 |
#endif |
|
83 |
||
84 |
// Set up some default values for the simulation. Use the Bind() |
|
85 |
// technique to tell the system what subclass of Queue to use, |
|
86 |
// and what the queue limit is |
|
87 |
||
88 |
// The below Bind command tells the queue factory which class to |
|
89 |
// instantiate, when the queue factory is invoked in the topology code |
|
90 |
Bind ("Queue", "DropTailQueue"); |
|
91 |
||
92 |
// Allow the user to override any of the defaults and the above |
|
93 |
// Bind()s at run-time, via command-line arguments |
|
94 |
CommandLine::Parse (argc, argv); |
|
95 |
||
96 |
// Here, we will explicitly create four nodes. In more sophisticated |
|
97 |
// topologies, we could configure a node factory. |
|
98 |
Ptr<Node> n0 = Create<InternetNode> (); |
|
99 |
Ptr<Node> n1 = Create<InternetNode> (); |
|
100 |
Ptr<Node> n2 = Create<InternetNode> (); |
|
101 |
Ptr<Node> n3 = Create<InternetNode> (); |
|
102 |
||
103 |
// We create the channels first without any IP addressing information |
|
104 |
Ptr<CsmaCdChannel> channel0 = |
|
105 |
CsmaCdTopology::CreateCsmaCdChannel( |
|
106 |
DataRate(5000000), MilliSeconds(2)); |
|
107 |
||
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
108 |
uint32_t n0ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n0, channel0, |
1167 | 109 |
Eui48Address("10:54:23:54:23:50")); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
110 |
uint32_t n1ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n1, channel0, |
1167 | 111 |
Eui48Address("10:54:23:54:23:51")); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
112 |
uint32_t n2ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n2, channel0, |
1167 | 113 |
Eui48Address("10:54:23:54:23:52")); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
114 |
uint32_t n3ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n3, channel0, |
1167 | 115 |
Eui48Address("10:54:23:54:23:53")); |
987 | 116 |
|
117 |
// Later, we add IP addresses. |
|
118 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
119 |
n0, n0ifIndex, Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")); |
987 | 120 |
|
121 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
122 |
n1, n1ifIndex, Ipv4Address("10.1.1.2"), Ipv4Mask("255.255.255.0")); |
987 | 123 |
|
124 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
125 |
n2, n2ifIndex, Ipv4Address("10.1.1.3"), Ipv4Mask("255.255.255.0")); |
987 | 126 |
|
127 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
128 |
n3, n3ifIndex, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0")); |
987 | 129 |
|
130 |
// Create the OnOff application to send UDP datagrams of size |
|
131 |
// 210 bytes at a rate of 448 Kb/s |
|
132 |
// from n0 to n1 |
|
133 |
Ptr<OnOffApplication> ooff = Create<OnOffApplication> ( |
|
134 |
n0, |
|
1204
d40723d53e3d
InetSocketAddress: replace explicit conversion to implicit conversion
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1171
diff
changeset
|
135 |
InetSocketAddress ("10.1.1.2", 80), |
987 | 136 |
"Udp", |
137 |
ConstantVariable(1), |
|
138 |
ConstantVariable(0)); |
|
139 |
// Start the application |
|
140 |
ooff->Start(Seconds(1.0)); |
|
141 |
ooff->Stop (Seconds(10.0)); |
|
142 |
||
143 |
// Create a similar flow from n3 to n0, starting at time 1.1 seconds |
|
144 |
ooff = Create<OnOffApplication> ( |
|
145 |
n3, |
|
1204
d40723d53e3d
InetSocketAddress: replace explicit conversion to implicit conversion
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1171
diff
changeset
|
146 |
InetSocketAddress ("10.1.1.1", 80), |
987 | 147 |
"Udp", |
148 |
ConstantVariable(1), |
|
149 |
ConstantVariable(0)); |
|
150 |
// Start the application |
|
151 |
ooff->Start(Seconds(1.1)); |
|
152 |
ooff->Stop (Seconds(10.0)); |
|
153 |
||
154 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events |
|
155 |
// Trace output will be sent to the csma-cd-one-subnet.tr file |
|
991 | 156 |
AsciiTrace asciitrace ("csma-cd-one-subnet.tr"); |
157 |
asciitrace.TraceAllNetDeviceRx (); |
|
158 |
asciitrace.TraceAllQueues (); |
|
159 |
||
160 |
// Also configure some tcpdump traces; each interface will be traced |
|
161 |
// The output files will be named |
|
162 |
// simple-point-to-point.pcap-<nodeId>-<interfaceId> |
|
163 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
|
164 |
// display timestamps correctly) |
|
165 |
PcapTrace pcaptrace ("csma-cd-one-subnet.pcap"); |
|
166 |
pcaptrace.TraceAllIp (); |
|
987 | 167 |
|
168 |
Simulator::Run (); |
|
169 |
||
170 |
Simulator::Destroy (); |
|
171 |
} |