author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Sun, 02 Mar 2008 21:57:28 +0100 | |
changeset 2533 | 80cdc3eec057 |
parent 2502 | 50d0da37f02f |
child 2575 | 1aae382e65e2 |
permissions | -rw-r--r-- |
1278 | 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 |
||
18 |
// This script exercises global routing code in a mixed point-to-point |
|
19 |
// and csma/cd environment |
|
20 |
// |
|
21 |
// Network topology |
|
22 |
// |
|
23 |
// n0 |
|
24 |
// \ p-p |
|
25 |
// \ (shared csma/cd) |
|
26 |
// n2 -------------------------n3 |
|
27 |
// / | | |
|
28 |
// / p-p n4 n5 ---------- n6 |
|
29 |
// n1 p-p |
|
30 |
// |
|
31 |
// - CBR/UDP flows from n0 to n6 |
|
32 |
// - Tracing of queues and packet receptions to file "mixed-global-routing.tr" |
|
33 |
||
34 |
#include <iostream> |
|
35 |
#include <fstream> |
|
36 |
#include <string> |
|
37 |
#include <cassert> |
|
38 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
39 |
#include "ns3/log.h" |
1278 | 40 |
|
41 |
#include "ns3/command-line.h" |
|
42 |
#include "ns3/default-value.h" |
|
43 |
#include "ns3/ptr.h" |
|
44 |
#include "ns3/random-variable.h" |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
45 |
#include "ns3/config.h" |
1278 | 46 |
|
47 |
#include "ns3/simulator.h" |
|
48 |
#include "ns3/nstime.h" |
|
49 |
#include "ns3/data-rate.h" |
|
50 |
||
51 |
#include "ns3/ascii-trace.h" |
|
52 |
#include "ns3/pcap-trace.h" |
|
53 |
#include "ns3/internet-node.h" |
|
54 |
#include "ns3/point-to-point-channel.h" |
|
55 |
#include "ns3/point-to-point-net-device.h" |
|
56 |
#include "ns3/csma-channel.h" |
|
57 |
#include "ns3/csma-net-device.h" |
|
58 |
#include "ns3/csma-topology.h" |
|
59 |
#include "ns3/csma-ipv4-topology.h" |
|
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1433
diff
changeset
|
60 |
#include "ns3/mac48-address.h" |
1278 | 61 |
#include "ns3/ipv4-address.h" |
62 |
#include "ns3/ipv4.h" |
|
63 |
#include "ns3/socket.h" |
|
64 |
#include "ns3/inet-socket-address.h" |
|
65 |
#include "ns3/ipv4-route.h" |
|
66 |
#include "ns3/point-to-point-topology.h" |
|
67 |
#include "ns3/onoff-application.h" |
|
68 |
#include "ns3/global-route-manager.h" |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
69 |
#include "ns3/uinteger.h" |
1278 | 70 |
|
71 |
using namespace ns3; |
|
72 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
73 |
NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample"); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
74 |
|
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
75 |
int |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
76 |
main (int argc, char *argv[]) |
1278 | 77 |
{ |
78 |
||
79 |
// Users may find it convenient to turn on explicit debugging |
|
80 |
// for selected modules; the below lines suggest how to do this |
|
81 |
#if 0 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
82 |
LogComponentEnable ("MixedGlobalRoutingExample", LOG_LEVEL_INFO); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
83 |
|
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
84 |
LogComponentEnable("Object", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
85 |
LogComponentEnable("Queue", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
86 |
LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
87 |
LogComponentEnable("Channel", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
88 |
LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
89 |
LogComponentEnable("NetDevice", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
90 |
LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
91 |
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
92 |
LogComponentEnable("PacketSocket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
93 |
LogComponentEnable("Socket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
94 |
LogComponentEnable("UdpSocket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
95 |
LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
96 |
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
97 |
LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
98 |
LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
99 |
LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
100 |
LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
101 |
LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
102 |
LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
103 |
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
104 |
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL); |
1278 | 105 |
#endif |
106 |
// Set up some default values for the simulation. Use the Bind () |
|
107 |
||
108 |
||
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
109 |
Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210)); |
2502
50d0da37f02f
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
110 |
Config::SetDefault ("OnOffApplication::DataRate", DataRate ("448kb/s")); |
1278 | 111 |
|
112 |
// Allow the user to override any of the defaults and the above |
|
113 |
// Bind ()s at run-time, via command-line arguments |
|
114 |
CommandLine::Parse (argc, argv); |
|
115 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
116 |
NS_LOG_INFO ("Create nodes."); |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
117 |
Ptr<Node> n0 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
118 |
Ptr<Node> n1 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
119 |
Ptr<Node> n2 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
120 |
Ptr<Node> n3 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
121 |
Ptr<Node> n4 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
122 |
Ptr<Node> n5 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
123 |
Ptr<Node> n6 = CreateObject<InternetNode> (); |
1278 | 124 |
|
125 |
// We create the channels first without any IP addressing information |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
126 |
NS_LOG_INFO ("Create channels."); |
1278 | 127 |
Ptr<PointToPointChannel> channel0 = |
128 |
PointToPointTopology::AddPointToPointLink ( |
|
129 |
n0, n2, DataRate (5000000), MilliSeconds (2)); |
|
130 |
||
131 |
Ptr<PointToPointChannel> channel1 = |
|
132 |
PointToPointTopology::AddPointToPointLink ( |
|
133 |
n1, n2, DataRate (5000000), MilliSeconds (2)); |
|
134 |
||
135 |
Ptr<PointToPointChannel> channel2 = |
|
136 |
PointToPointTopology::AddPointToPointLink ( |
|
137 |
n5, n6, DataRate (1500000), MilliSeconds (10)); |
|
138 |
||
139 |
// We create the channels first without any IP addressing information |
|
140 |
Ptr<CsmaChannel> channelc0 = |
|
141 |
CsmaTopology::CreateCsmaChannel( |
|
142 |
DataRate(5000000), MilliSeconds(2)); |
|
143 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
144 |
NS_LOG_INFO ("Build Topology."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1278
diff
changeset
|
145 |
uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, channelc0, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1433
diff
changeset
|
146 |
Mac48Address("10:54:23:54:23:50")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1278
diff
changeset
|
147 |
uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, channelc0, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1433
diff
changeset
|
148 |
Mac48Address("10:54:23:54:23:51")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1278
diff
changeset
|
149 |
uint32_t n4ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, channelc0, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1433
diff
changeset
|
150 |
Mac48Address("10:54:23:54:23:52")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1278
diff
changeset
|
151 |
uint32_t n5ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n5, channelc0, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1433
diff
changeset
|
152 |
Mac48Address("10:54:23:54:23:53")); |
1278 | 153 |
|
154 |
// Later, we add IP addresses. |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
155 |
NS_LOG_INFO ("Assign IP Addresses."); |
1278 | 156 |
PointToPointTopology::AddIpv4Addresses ( |
157 |
channel0, n0, Ipv4Address ("10.1.1.1"), |
|
158 |
n2, Ipv4Address ("10.1.1.2")); |
|
159 |
||
160 |
PointToPointTopology::AddIpv4Addresses ( |
|
161 |
channel1, n1, Ipv4Address ("10.1.2.1"), |
|
162 |
n2, Ipv4Address ("10.1.2.2")); |
|
163 |
||
164 |
PointToPointTopology::AddIpv4Addresses ( |
|
165 |
channel2, n5, Ipv4Address ("10.1.3.1"), |
|
166 |
n6, Ipv4Address ("10.1.3.2")); |
|
167 |
||
168 |
CsmaIpv4Topology::AddIpv4Address ( |
|
169 |
n2, n2ifIndex, Ipv4Address("10.250.1.1"), Ipv4Mask("255.255.255.0")); |
|
170 |
||
171 |
CsmaIpv4Topology::AddIpv4Address ( |
|
172 |
n3, n3ifIndex, Ipv4Address("10.250.1.2"), Ipv4Mask("255.255.255.0")); |
|
173 |
||
174 |
CsmaIpv4Topology::AddIpv4Address ( |
|
175 |
n4, n4ifIndex, Ipv4Address("10.250.1.3"), Ipv4Mask("255.255.255.0")); |
|
176 |
||
177 |
CsmaIpv4Topology::AddIpv4Address ( |
|
178 |
n5, n5ifIndex, Ipv4Address("10.250.1.4"), Ipv4Mask("255.255.255.0")); |
|
179 |
||
180 |
// Create router nodes, initialize routing database and set up the routing |
|
181 |
// tables in the nodes. |
|
182 |
GlobalRouteManager::PopulateRoutingTables (); |
|
183 |
||
184 |
// Create the OnOff application to send UDP datagrams of size |
|
185 |
// 210 bytes at a rate of 448 Kb/s |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
186 |
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
|
187 |
uint16_t port = 9; // Discard port (RFC 863) |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
188 |
Ptr<OnOffApplication> ooff = |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
189 |
CreateObjectWith<OnOffApplication> ( |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
190 |
"Node", n0, |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
191 |
"Remote", Address (InetSocketAddress ("10.1.3.2", port)), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
192 |
"Protocol", TypeId::LookupByName ("Udp"), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
193 |
"OnTime", ConstantVariable (1), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
194 |
"OffTime", ConstantVariable (0), |
2502
50d0da37f02f
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
195 |
"DataRate", DataRate("300bps"), |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
196 |
"PacketSize", Uinteger (50)); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
197 |
n0->AddApplication (ooff); |
1278 | 198 |
// Start the application |
199 |
ooff->Start (Seconds (1.0)); |
|
200 |
ooff->Stop (Seconds (10.0)); |
|
201 |
||
202 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events |
|
203 |
// Trace output will be sent to the simple-global-routing.tr file |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
204 |
NS_LOG_INFO ("Configure Tracing."); |
1278 | 205 |
AsciiTrace asciitrace ("mixed-global-routing.tr"); |
206 |
asciitrace.TraceAllQueues (); |
|
207 |
asciitrace.TraceAllNetDeviceRx (); |
|
208 |
||
209 |
// Also configure some tcpdump traces; each interface will be traced |
|
210 |
// The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId> |
|
211 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
|
212 |
// display timestamps correctly) |
|
213 |
PcapTrace pcaptrace ("mixed-global-routing.pcap"); |
|
214 |
pcaptrace.TraceAllIp (); |
|
215 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
216 |
NS_LOG_INFO ("Run Simulation."); |
1278 | 217 |
Simulator::Run (); |
218 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
219 |
NS_LOG_INFO ("Done."); |
1278 | 220 |
} |