author | Mitch Watrous |
Mon, 13 Aug 2012 16:08:13 -0700 | |
changeset 8966 | 060dba23e9bb |
parent 7196 | 0f12b1572bca |
child 9000 | 3ec20a64fd08 |
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" |
6823
a27f86fb4e55
Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents:
6821
diff
changeset
|
40 |
#include "ns3/network-module.h" |
6848
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
41 |
#include "ns3/point-to-point-module.h" |
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
42 |
#include "ns3/csma-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
43 |
#include "ns3/applications-module.h" |
7089
ebe626d82692
Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents:
6865
diff
changeset
|
44 |
#include "ns3/internet-module.h" |
1278 | 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 |
{ |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
53 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
54 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); |
1278 | 55 |
|
56 |
// Allow the user to override any of the defaults and the above |
|
57 |
// 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
|
58 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
59 |
cmd.Parse (argc, argv); |
1278 | 60 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
61 |
NS_LOG_INFO ("Create nodes."); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
62 |
NodeContainer c; |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
63 |
c.Create (7); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
|
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
69 |
InternetStackHelper internet; |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2838
diff
changeset
|
70 |
internet.Install (c); |
1278 | 71 |
|
72 |
// 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
|
73 |
NS_LOG_INFO ("Create channels."); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
74 |
PointToPointHelper p2p; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
75 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
76 |
p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2838
diff
changeset
|
77 |
NetDeviceContainer d0d2 = p2p.Install (n0n2); |
1278 | 78 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2838
diff
changeset
|
79 |
NetDeviceContainer d1d2 = p2p.Install (n1n2); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
80 |
|
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
81 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps")); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
82 |
p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2838
diff
changeset
|
83 |
NetDeviceContainer d5d6 = p2p.Install (n5n6); |
1278 | 84 |
|
85 |
// 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
|
86 |
CsmaHelper csma; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
87 |
csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps")); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
88 |
csma.SetChannelAttribute ("Delay", StringValue ("2ms")); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2838
diff
changeset
|
89 |
NetDeviceContainer d2345 = csma.Install (n2345); |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
90 |
|
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
91 |
// Later, we add IP addresses. |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
92 |
NS_LOG_INFO ("Assign IP Addresses."); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
93 |
Ipv4AddressHelper ipv4; |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
94 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
95 |
ipv4.Assign (d0d2); |
1278 | 96 |
|
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
97 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
98 |
ipv4.Assign (d1d2); |
1278 | 99 |
|
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
100 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
101 |
Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6); |
2757
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 |
ipv4.SetBase ("10.250.1.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
104 |
ipv4.Assign (d2345); |
1278 | 105 |
|
106 |
// Create router nodes, initialize routing database and set up the routing |
|
107 |
// tables in the nodes. |
|
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4264
diff
changeset
|
108 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
1278 | 109 |
|
110 |
// Create the OnOff application to send UDP datagrams of size |
|
111 |
// 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
|
112 |
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
|
113 |
uint16_t port = 9; // Discard port (RFC 863) |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
114 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
115 |
InetSocketAddress (i5i6.GetAddress (1), port)); |
8966
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7196
diff
changeset
|
116 |
onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); |
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7196
diff
changeset
|
117 |
onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
118 |
onoff.SetAttribute ("DataRate", StringValue ("300bps")); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
119 |
onoff.SetAttribute ("PacketSize", UintegerValue (50)); |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2888
diff
changeset
|
120 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2838
diff
changeset
|
121 |
ApplicationContainer apps = onoff.Install (c.Get (0)); |
2757
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
122 |
apps.Start (Seconds (1.0)); |
651ceaf0df8f
convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
123 |
apps.Stop (Seconds (10.0)); |
1278 | 124 |
|
6013 | 125 |
AsciiTraceHelper ascii; |
6053
b17ea72acee9
OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6049
diff
changeset
|
126 |
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("mixed-global-routing.tr"); |
6013 | 127 |
p2p.EnableAsciiAll (stream); |
6014 | 128 |
csma.EnableAsciiAll (stream); |
6013 | 129 |
|
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
130 |
p2p.EnablePcapAll ("mixed-global-routing"); |
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
131 |
csma.EnablePcapAll ("mixed-global-routing", false); |
1278 | 132 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
133 |
NS_LOG_INFO ("Run Simulation."); |
1278 | 134 |
Simulator::Run (); |
135 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
136 |
NS_LOG_INFO ("Done."); |
1278 | 137 |
} |