author | Craig Dowell <craigdo@ee.washington.edu> |
Tue, 09 Oct 2007 18:02:32 -0700 | |
changeset 1843 | 1267bcc23b04 |
parent 1839 | 0c65f73153ea |
child 2230 | 9f13ac3291e0 |
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 |
||
17 |
#include "ns3/log.h" |
|
18 |
#include "ns3/ptr.h" |
|
19 |
#include "ns3/internet-node.h" |
|
20 |
#include "ns3/point-to-point-channel.h" |
|
21 |
#include "ns3/csma-channel.h" |
|
22 |
#include "ns3/mac48-address.h" |
|
23 |
#include "ns3/point-to-point-net-device.h" |
|
24 |
#include "ns3/csma-net-device.h" |
|
25 |
#include "ns3/point-to-point-topology.h" |
|
26 |
#include "ns3/csma-topology.h" |
|
27 |
#include "ns3/csma-ipv4-topology.h" |
|
28 |
#include "ns3/udp-echo-client.h" |
|
29 |
#include "ns3/udp-echo-server.h" |
|
30 |
#include "ns3/simulator.h" |
|
31 |
#include "ns3/nstime.h" |
|
32 |
#include "ns3/ascii-trace.h" |
|
33 |
#include "ns3/pcap-trace.h" |
|
34 |
#include "ns3/global-route-manager.h" |
|
35 |
||
1539 | 36 |
NS_LOG_COMPONENT_DEFINE ("DumbbellSimulation"); |
1529 | 37 |
|
38 |
using namespace ns3; |
|
39 |
||
40 |
// Network topology |
|
41 |
// |
|
42 |
// point to point |
|
43 |
// +--------------+ |
|
44 |
// | | |
|
45 |
// n0 n1 n2 n3 n4 n5 n6 n7 |
|
46 |
// | | | | | | | | |
|
47 |
// ================ ================ |
|
1539 | 48 |
// lan1 lan2 |
1529 | 49 |
// |
50 |
int |
|
51 |
main (int argc, char *argv[]) |
|
52 |
{ |
|
1539 | 53 |
LogComponentEnable ("DumbbellSimulation", LOG_LEVEL_INFO); |
1529 | 54 |
|
1539 | 55 |
NS_LOG_INFO ("Dumbbell Topology Simulation"); |
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
56 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
57 |
// Create the lan on the left side of the dumbbell. |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
58 |
// |
1529 | 59 |
Ptr<Node> n0 = Create<InternetNode> (); |
60 |
Ptr<Node> n1 = Create<InternetNode> (); |
|
61 |
Ptr<Node> n2 = Create<InternetNode> (); |
|
62 |
Ptr<Node> n3 = Create<InternetNode> (); |
|
63 |
||
64 |
Ptr<CsmaChannel> lan1 = |
|
1539 | 65 |
CsmaTopology::CreateCsmaChannel (DataRate (10000000), MilliSeconds (2)); |
1529 | 66 |
|
67 |
uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan1, |
|
68 |
"08:00:2e:00:00:00"); |
|
69 |
||
70 |
uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan1, |
|
71 |
"08:00:2e:00:00:01"); |
|
72 |
||
73 |
uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1, |
|
74 |
"08:00:2e:00:00:02"); |
|
75 |
||
76 |
uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1, |
|
77 |
"08:00:2e:00:00:03"); |
|
78 |
||
79 |
CsmaIpv4Topology::AddIpv4Address (n0, nd0, "10.1.1.1", "255.255.255.0"); |
|
80 |
CsmaIpv4Topology::AddIpv4Address (n1, nd1, "10.1.1.2", "255.255.255.0"); |
|
81 |
CsmaIpv4Topology::AddIpv4Address (n2, nd2, "10.1.1.3", "255.255.255.0"); |
|
82 |
CsmaIpv4Topology::AddIpv4Address (n3, nd3, "10.1.1.4", "255.255.255.0"); |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
83 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
84 |
// Create the lan on the right side of the dumbbell. |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
85 |
// |
1539 | 86 |
Ptr<Node> n4 = Create<InternetNode> (); |
87 |
Ptr<Node> n5 = Create<InternetNode> (); |
|
88 |
Ptr<Node> n6 = Create<InternetNode> (); |
|
89 |
Ptr<Node> n7 = Create<InternetNode> (); |
|
90 |
||
1529 | 91 |
Ptr<CsmaChannel> lan2 = |
1539 | 92 |
CsmaTopology::CreateCsmaChannel (DataRate (10000000), MilliSeconds (2)); |
1529 | 93 |
|
94 |
uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan2, |
|
95 |
"08:00:2e:00:00:04"); |
|
96 |
||
97 |
uint32_t nd5 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n5, lan2, |
|
98 |
"08:00:2e:00:00:05"); |
|
99 |
||
100 |
uint32_t nd6 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n6, lan2, |
|
101 |
"08:00:2e:00:00:06"); |
|
102 |
||
103 |
uint32_t nd7 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n7, lan2, |
|
104 |
"08:00:2e:00:00:07"); |
|
105 |
||
106 |
CsmaIpv4Topology::AddIpv4Address (n4, nd4, "10.1.2.1", "255.255.255.0"); |
|
107 |
CsmaIpv4Topology::AddIpv4Address (n5, nd5, "10.1.2.2", "255.255.255.0"); |
|
108 |
CsmaIpv4Topology::AddIpv4Address (n6, nd6, "10.1.2.3", "255.255.255.0"); |
|
109 |
CsmaIpv4Topology::AddIpv4Address (n7, nd7, "10.1.2.4", "255.255.255.0"); |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
110 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
111 |
// Create the point-to-point link to connect the two lans. |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
112 |
// |
1529 | 113 |
Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink ( |
1539 | 114 |
n3, n4, DataRate (38400), MilliSeconds (20)); |
1529 | 115 |
|
116 |
PointToPointTopology::AddIpv4Addresses (link, n3, "10.1.3.1", |
|
117 |
n4, "10.1.3.2"); |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
118 |
// |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
119 |
// Create data flows across the link: |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
120 |
// n0 ==> n4 ==> n0 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
121 |
// n1 ==> n5 ==> n1 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
122 |
// n2 ==> n6 ==> n2 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
123 |
// n3 ==> n7 ==> n3 |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
124 |
// |
1529 | 125 |
uint16_t port = 7; |
126 |
||
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
127 |
Ptr<UdpEchoClient> client0 = Create<UdpEchoClient> (n0, "10.1.2.1", port, |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
128 |
100, Seconds(.01), 1024); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
129 |
Ptr<UdpEchoClient> client1 = Create<UdpEchoClient> (n1, "10.1.2.2", port, |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
130 |
100, Seconds(.01), 1024); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
131 |
Ptr<UdpEchoClient> client2 = Create<UdpEchoClient> (n2, "10.1.2.3", port, |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
132 |
100, Seconds(.01), 1024); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
133 |
Ptr<UdpEchoClient> client3 = Create<UdpEchoClient> (n3, "10.1.2.4", port, |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
134 |
100, Seconds(.01), 1024); |
1529 | 135 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
136 |
Ptr<UdpEchoServer> server4 = Create<UdpEchoServer> (n4, port); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
137 |
Ptr<UdpEchoServer> server5 = Create<UdpEchoServer> (n5, port); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
138 |
Ptr<UdpEchoServer> server6 = Create<UdpEchoServer> (n6, port); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
139 |
Ptr<UdpEchoServer> server7 = Create<UdpEchoServer> (n7, port); |
1529 | 140 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
141 |
server4->Start(Seconds(1.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
142 |
server5->Start(Seconds(1.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
143 |
server6->Start(Seconds(1.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
144 |
server7->Start(Seconds(1.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
145 |
|
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
146 |
client0->Start(Seconds(2.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
147 |
client1->Start(Seconds(2.1)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
148 |
client2->Start(Seconds(2.2)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
149 |
client3->Start(Seconds(2.3)); |
1529 | 150 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
151 |
server4->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
152 |
server5->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
153 |
server6->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
154 |
server7->Stop (Seconds(10.)); |
1529 | 155 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
156 |
client0->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
157 |
client1->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
158 |
client2->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
159 |
client3->Stop (Seconds(10.)); |
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
160 |
|
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
161 |
AsciiTrace asciitrace ("tutorial.tr"); |
1529 | 162 |
asciitrace.TraceAllQueues (); |
163 |
asciitrace.TraceAllNetDeviceRx (); |
|
164 |
||
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1839
diff
changeset
|
165 |
PcapTrace pcaptrace ("tutorial.pcap"); |
1529 | 166 |
pcaptrace.TraceAllIp (); |
167 |
||
168 |
GlobalRouteManager::PopulateRoutingTables (); |
|
169 |
||
170 |
Simulator::Run (); |
|
171 |
Simulator::Destroy (); |
|
172 |
} |