author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Fri, 28 Mar 2008 13:19:14 -0700 | |
changeset 2787 | 83b3e68557e1 |
parent 2757 | 651ceaf0df8f |
child 2789 | 47e92324cf4b |
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 |
||
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
39 |
#include "ns3/core-module.h" |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
40 |
#include "ns3/helper-module.h" |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
41 |
#include "ns3/simulator-module.h" |
1278 | 42 |
#include "ns3/ascii-trace.h" |
43 |
#include "ns3/pcap-trace.h" |
|
44 |
#include "ns3/global-route-manager.h" |
|
45 |
||
46 |
using namespace ns3; |
|
47 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
48 |
NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample"); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
49 |
|
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
50 |
int |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
51 |
main (int argc, char *argv[]) |
1278 | 52 |
{ |
53 |
||
54 |
// Users may find it convenient to turn on explicit debugging |
|
55 |
// for selected modules; the below lines suggest how to do this |
|
56 |
#if 0 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
57 |
LogComponentEnable ("MixedGlobalRoutingExample", LOG_LEVEL_INFO); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
58 |
|
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
59 |
LogComponentEnable("Object", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
60 |
LogComponentEnable("Queue", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
61 |
LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
62 |
LogComponentEnable("Channel", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
63 |
LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
64 |
LogComponentEnable("NetDevice", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
65 |
LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
66 |
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
67 |
LogComponentEnable("PacketSocket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
68 |
LogComponentEnable("Socket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
69 |
LogComponentEnable("UdpSocket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
70 |
LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
71 |
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
72 |
LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
73 |
LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
74 |
LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
75 |
LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
76 |
LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
77 |
LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
78 |
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
79 |
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL); |
1278 | 80 |
#endif |
81 |
// Set up some default values for the simulation. Use the Bind () |
|
82 |
||
83 |
||
2613
0e1267814e1c
need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
84 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); |
0e1267814e1c
need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
85 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s")); |
1278 | 86 |
|
87 |
// Allow the user to override any of the defaults and the above |
|
88 |
// Bind ()s at run-time, via command-line arguments |
|
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
89 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
90 |
cmd.Parse (argc, argv); |
1278 | 91 |
|
2787
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
92 |
std::ofstream ascii; |
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
93 |
ascii.open ("mixed-global-routing.tr"); |
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
94 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
95 |
NS_LOG_INFO ("Create nodes."); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
96 |
NodeContainer c; |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
97 |
c.Create (7); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
98 |
NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
99 |
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
100 |
NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
101 |
NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
102 |
|
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
103 |
InternetStackHelper internet; |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
104 |
internet.Build (c); |
1278 | 105 |
|
106 |
// 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
|
107 |
NS_LOG_INFO ("Create channels."); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
108 |
PointToPointHelper p2p; |
2787
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
109 |
p2p.EnablePcap ("mixed-global-routing.pcap"); |
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
110 |
p2p.EnableAscii (ascii); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
111 |
p2p.SetChannelParameter ("BitRate", DataRate (5000000)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
112 |
p2p.SetChannelParameter ("Delay", MilliSeconds (2)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
113 |
NetDeviceContainer d0d2 = p2p.Build (n0n2); |
1278 | 114 |
|
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
115 |
NetDeviceContainer d1d2 = p2p.Build (n1n2); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
116 |
|
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
117 |
p2p.SetChannelParameter ("BitRate", DataRate (1500000)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
118 |
p2p.SetChannelParameter ("Delay", MilliSeconds (10)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
119 |
NetDeviceContainer d5d6 = p2p.Build (n5n6); |
1278 | 120 |
|
121 |
// We create the channels first without any IP addressing information |
|
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
122 |
CsmaHelper csma; |
2787
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
123 |
csma.EnablePcap ("mixed-global-routing.pcap"); |
83b3e68557e1
use new pcap/ascii api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2757
diff
changeset
|
124 |
csma.EnableAscii (ascii); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
125 |
csma.SetChannelParameter ("BitRate", DataRate (5000000)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
126 |
csma.SetChannelParameter ("Delay", MilliSeconds (2)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
127 |
NetDeviceContainer d2345 = csma.Build (n2345); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
128 |
|
1278 | 129 |
// Later, we add IP addresses. |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
130 |
NS_LOG_INFO ("Assign IP Addresses."); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
131 |
Ipv4AddressHelper ipv4; |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
132 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
133 |
ipv4.Allocate (d0d2); |
1278 | 134 |
|
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
135 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
136 |
ipv4.Allocate (d1d2); |
1278 | 137 |
|
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
138 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
139 |
Ipv4InterfaceContainer i5i6 = ipv4.Allocate (d5d6); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
140 |
|
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
141 |
ipv4.SetBase ("10.250.1.0", "255.255.255.0"); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
142 |
ipv4.Allocate (d2345); |
1278 | 143 |
|
144 |
// Create router nodes, initialize routing database and set up the routing |
|
145 |
// tables in the nodes. |
|
146 |
GlobalRouteManager::PopulateRoutingTables (); |
|
147 |
||
148 |
// Create the OnOff application to send UDP datagrams of size |
|
149 |
// 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
|
150 |
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
|
151 |
uint16_t port = 9; // Discard port (RFC 863) |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
152 |
OnOffHelper onoff; |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
153 |
onoff.SetAppAttribute ("OnTime", ConstantVariable (1)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
154 |
onoff.SetAppAttribute ("OffTime", ConstantVariable (0)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
155 |
onoff.SetAppAttribute ("DataRate", DataRate("300bps")); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
156 |
onoff.SetAppAttribute ("PacketSize", Uinteger (50)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
157 |
onoff.SetUdpRemote (i5i6.GetAddress (1), port); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
158 |
ApplicationContainer apps = onoff.Build (c.Get (0)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
159 |
apps.Start (Seconds (1.0)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
160 |
apps.Stop (Seconds (10.0)); |
1278 | 161 |
|
162 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
163 |
NS_LOG_INFO ("Run Simulation."); |
1278 | 164 |
Simulator::Run (); |
165 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
166 |
NS_LOG_INFO ("Done."); |
1278 | 167 |
} |