author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 31 Mar 2008 15:19:08 -0700 | |
changeset 2837 | 67b88d7bad6c |
parent 2812 | 5f2d7dcb31d2 |
child 2887 | 9a637e6daee0 |
permissions | -rw-r--r-- |
1529 | 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 |
||
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
17 |
#include <fstream> |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
18 |
|
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
19 |
#include "ns3/core-module.h" |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
20 |
#include "ns3/node-module.h" |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
21 |
#include "ns3/helper-module.h" |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
22 |
#include "ns3/simulator-module.h" |
1529 | 23 |
#include "ns3/global-route-manager.h" |
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
24 |
|
1529 | 25 |
|
1539 | 26 |
NS_LOG_COMPONENT_DEFINE ("DumbbellSimulation"); |
1529 | 27 |
|
28 |
using namespace ns3; |
|
29 |
||
30 |
// Network topology |
|
31 |
// |
|
32 |
// point to point |
|
33 |
// +--------------+ |
|
34 |
// | | |
|
35 |
// n0 n1 n2 n3 n4 n5 n6 n7 |
|
36 |
// | | | | | | | | |
|
37 |
// ================ ================ |
|
1539 | 38 |
// lan1 lan2 |
1529 | 39 |
// |
40 |
int |
|
41 |
main (int argc, char *argv[]) |
|
42 |
{ |
|
1539 | 43 |
LogComponentEnable ("DumbbellSimulation", LOG_LEVEL_INFO); |
1529 | 44 |
|
1539 | 45 |
NS_LOG_INFO ("Dumbbell Topology Simulation"); |
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
46 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
47 |
// Create the lan on the left side of the dumbbell. |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
48 |
// |
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
49 |
NodeContainer lan1; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
50 |
lan1.Create (4); |
1529 | 51 |
|
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
52 |
InternetStackHelper internet; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
53 |
internet.Build (lan1); |
1529 | 54 |
|
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
55 |
CsmaHelper csma; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
56 |
csma.SetChannelParameter ("BitRate", DataRate (10000000)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
57 |
csma.SetChannelParameter ("Delay", MilliSeconds (2)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
58 |
NetDeviceContainer dev1 = csma.Build (lan1); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
59 |
Ipv4AddressHelper ipv4; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
60 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
61 |
Ipv4InterfaceContainer i1 = ipv4.Allocate (dev1); |
1529 | 62 |
|
63 |
||
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
64 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
65 |
// Create the lan on the right side of the dumbbell. |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
66 |
// |
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
67 |
NodeContainer lan2; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
68 |
lan2.Create (4); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
69 |
internet.Build (lan2); |
1529 | 70 |
|
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
71 |
NetDeviceContainer dev2 = csma.Build (lan2); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
72 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
73 |
Ipv4InterfaceContainer i2 = ipv4.Allocate (dev2); |
1529 | 74 |
|
75 |
||
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
76 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
77 |
// Create the point-to-point link to connect the two lans. |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
78 |
// |
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
79 |
NodeContainer backbone = NodeContainer (lan1.Get (3), lan2.Get (0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
80 |
PointToPointHelper p2p; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
81 |
p2p.SetChannelParameter ("BitRate", DataRate (38400)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
82 |
p2p.SetChannelParameter ("Delay", MilliSeconds (20)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
83 |
NetDeviceContainer dev3 = p2p.Build (backbone); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
84 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
85 |
ipv4.Allocate (dev3); |
1529 | 86 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
87 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
88 |
// Create data flows across the link: |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
89 |
// n0 ==> n4 ==> n0 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
90 |
// n1 ==> n5 ==> n1 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
91 |
// n2 ==> n6 ==> n2 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
92 |
// n3 ==> n7 ==> n3 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
93 |
// |
1529 | 94 |
uint16_t port = 7; |
95 |
||
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
96 |
UdpEchoClientHelper client; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
97 |
client.SetRemote (i2.GetAddress (0), port); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
98 |
client.SetAppAttribute ("MaxPackets", Uinteger (100)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
99 |
client.SetAppAttribute ("Interval", Seconds (0.01)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
100 |
client.SetAppAttribute ("PacketSize", Uinteger (1024)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
101 |
ApplicationContainer apps = client.Build (lan1.Get (0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
102 |
apps.Start (Seconds(2.)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
103 |
apps.Stop (Seconds (10.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
104 |
|
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
105 |
client.SetRemote (i2.GetAddress (1), port); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
106 |
apps = client.Build (lan1.Get (1)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
107 |
apps.Start (Seconds(2.1)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
108 |
apps.Stop (Seconds (10.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
109 |
|
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
110 |
client.SetRemote (i2.GetAddress (2), port); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
111 |
apps = client.Build (lan1.Get (2)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
112 |
apps.Start (Seconds(2.2)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
113 |
apps.Stop (Seconds (10.0)); |
1529 | 114 |
|
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
115 |
client.SetRemote (i2.GetAddress (3), port); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
116 |
apps = client.Build (lan1.Get (3)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
117 |
apps.Start (Seconds(2.3)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
118 |
apps.Stop (Seconds (10.0)); |
1529 | 119 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
120 |
|
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
121 |
UdpEchoServerHelper server; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
122 |
server.SetPort (port); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
123 |
apps = server.Build (lan2.Get (0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
124 |
apps.Start (Seconds (1.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
125 |
apps.Stop (Seconds (10.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
126 |
apps = server.Build (lan2.Get (1)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
127 |
apps.Start (Seconds (1.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
128 |
apps.Stop (Seconds (10.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
129 |
apps = server.Build (lan2.Get (2)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
130 |
apps.Start (Seconds (1.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
131 |
apps.Stop (Seconds (10.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
132 |
apps = server.Build (lan2.Get (3)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
133 |
apps.Start (Seconds (1.0)); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
134 |
apps.Stop (Seconds (10.0)); |
1529 | 135 |
|
136 |
GlobalRouteManager::PopulateRoutingTables (); |
|
137 |
||
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
138 |
std::ofstream os; |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
139 |
os.open ("tutorial.tr"); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
140 |
PointToPointHelper::EnableAscii (os); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
141 |
CsmaHelper::EnableAscii (os); |
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
142 |
|
2837
67b88d7bad6c
change pcap filename template to be slightly more coherent.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2812
diff
changeset
|
143 |
PointToPointHelper::EnablePcap ("tutorial"); |
67b88d7bad6c
change pcap filename template to be slightly more coherent.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2812
diff
changeset
|
144 |
CsmaHelper::EnablePcap ("tutorial"); |
2812
5f2d7dcb31d2
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
145 |
|
1529 | 146 |
Simulator::Run (); |
147 |
Simulator::Destroy (); |
|
148 |
} |