author | Tom Henderson <tomh@tomh.org> |
Fri, 27 Jul 2007 14:43:56 -0700 | |
changeset 990 | 44a604ad18cc |
parent 987 | 3f469377ff30 |
child 991 | e05514a93564 |
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" |
|
53 |
#include "ns3/mac-address.h" |
|
54 |
#include "ns3/ipv4-address.h" |
|
55 |
#include "ns3/ipv4.h" |
|
56 |
#include "ns3/socket.h" |
|
57 |
#include "ns3/ipv4-route.h" |
|
58 |
#include "ns3/onoff-application.h" |
|
59 |
||
60 |
#include "ns3/ascii-trace.h" |
|
61 |
||
62 |
#include "ns3/trace-context.h" |
|
63 |
#include "ns3/trace-root.h" |
|
64 |
||
65 |
||
66 |
using namespace ns3; |
|
67 |
||
68 |
||
69 |
int main (int argc, char *argv[]) |
|
70 |
{ |
|
71 |
||
72 |
// Users may find it convenient to turn on explicit debugging |
|
73 |
// for selected modules; the below lines suggest how to do this |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
74 |
DebugComponentEnable("CsmaCdNetDevice"); |
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
75 |
DebugComponentEnable("Ipv4L3Protocol"); |
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
76 |
DebugComponentEnable("NetDevice"); |
987 | 77 |
#if 0 |
78 |
DebugComponentEnable("Channel"); |
|
79 |
DebugComponentEnable("CsmaCdChannel"); |
|
80 |
DebugComponentEnable("PacketSocket"); |
|
81 |
#endif |
|
82 |
||
83 |
// Set up some default values for the simulation. Use the Bind() |
|
84 |
// technique to tell the system what subclass of Queue to use, |
|
85 |
// and what the queue limit is |
|
86 |
||
87 |
// The below Bind command tells the queue factory which class to |
|
88 |
// instantiate, when the queue factory is invoked in the topology code |
|
89 |
Bind ("Queue", "DropTailQueue"); |
|
90 |
||
91 |
// Allow the user to override any of the defaults and the above |
|
92 |
// Bind()s at run-time, via command-line arguments |
|
93 |
CommandLine::Parse (argc, argv); |
|
94 |
||
95 |
// Here, we will explicitly create four nodes. In more sophisticated |
|
96 |
// topologies, we could configure a node factory. |
|
97 |
Ptr<Node> n0 = Create<InternetNode> (); |
|
98 |
Ptr<Node> n1 = Create<InternetNode> (); |
|
99 |
Ptr<Node> n2 = Create<InternetNode> (); |
|
100 |
Ptr<Node> n3 = Create<InternetNode> (); |
|
101 |
||
102 |
// We create the channels first without any IP addressing information |
|
103 |
Ptr<CsmaCdChannel> channel0 = |
|
104 |
CsmaCdTopology::CreateCsmaCdChannel( |
|
105 |
DataRate(5000000), MilliSeconds(2)); |
|
106 |
||
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
107 |
uint32_t n0ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n0, channel0, |
987 | 108 |
MacAddress("10:54:23:54:23:50")); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
109 |
uint32_t n1ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n1, channel0, |
987 | 110 |
MacAddress("10:54:23:54:23:51")); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
111 |
uint32_t n2ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n2, channel0, |
987 | 112 |
MacAddress("10:54:23:54:23:52")); |
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
113 |
uint32_t n3ifIndex = CsmaCdIpv4Topology::AddIpv4CsmaCdNode (n3, channel0, |
987 | 114 |
MacAddress("10:54:23:54:23:53")); |
115 |
||
116 |
// Later, we add IP addresses. |
|
117 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
118 |
n0, n0ifIndex, Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")); |
987 | 119 |
|
120 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
121 |
n1, n1ifIndex, Ipv4Address("10.1.1.2"), Ipv4Mask("255.255.255.0")); |
987 | 122 |
|
123 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
124 |
n2, n2ifIndex, Ipv4Address("10.1.1.3"), Ipv4Mask("255.255.255.0")); |
987 | 125 |
|
126 |
CsmaCdIpv4Topology::AddIpv4Address ( |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
127 |
n3, n3ifIndex, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0")); |
987 | 128 |
|
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, |
|
135 |
Ipv4Address("10.1.1.2"), |
|
136 |
80, |
|
137 |
"Udp", |
|
138 |
ConstantVariable(1), |
|
139 |
ConstantVariable(0)); |
|
140 |
// Start the application |
|
141 |
ooff->Start(Seconds(1.0)); |
|
142 |
ooff->Stop (Seconds(10.0)); |
|
143 |
||
144 |
// Create a similar flow from n3 to n0, starting at time 1.1 seconds |
|
145 |
ooff = Create<OnOffApplication> ( |
|
146 |
n3, |
|
147 |
Ipv4Address("10.1.1.1"), |
|
148 |
80, |
|
149 |
"Udp", |
|
150 |
ConstantVariable(1), |
|
151 |
ConstantVariable(0)); |
|
152 |
// Start the application |
|
153 |
ooff->Start(Seconds(1.1)); |
|
154 |
ooff->Stop (Seconds(10.0)); |
|
155 |
||
156 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events |
|
157 |
// Trace output will be sent to the csma-cd-one-subnet.tr file |
|
990
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
158 |
// AsciiTrace asciitrace ("csma-cd-one-subnet.tr"); |
44a604ad18cc
disable tracing; fix ifIndex assignment
Tom Henderson <tomh@tomh.org>
parents:
987
diff
changeset
|
159 |
// asciitrace.TraceAllNetDeviceRx (); |
987 | 160 |
// asciitrace.TraceAllQueues (); |
161 |
||
162 |
Simulator::Run (); |
|
163 |
||
164 |
Simulator::Destroy (); |
|
165 |
} |