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 <fstream> |
|
18 |
|
19 #include "ns3/core-module.h" |
|
20 #include "ns3/node-module.h" |
|
21 #include "ns3/helper-module.h" |
|
22 #include "ns3/simulator-module.h" |
|
23 #include "ns3/global-route-manager.h" |
|
24 |
|
25 |
|
26 NS_LOG_COMPONENT_DEFINE ("DumbbellSimulation"); |
|
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 // ================ ================ |
|
38 // lan1 lan2 |
|
39 // |
|
40 int |
|
41 main (int argc, char *argv[]) |
|
42 { |
|
43 LogComponentEnable ("DumbbellSimulation", LOG_LEVEL_INFO); |
|
44 |
|
45 NS_LOG_INFO ("Dumbbell Topology Simulation"); |
|
46 // |
|
47 // Create the lan on the left side of the dumbbell. |
|
48 // |
|
49 NodeContainer lan1; |
|
50 lan1.Create (4); |
|
51 |
|
52 InternetStackHelper internet; |
|
53 internet.Install (lan1); |
|
54 |
|
55 CsmaHelper csma; |
|
56 csma.SetChannelParameter ("DataRate", StringValue ("10Mbps")); |
|
57 csma.SetChannelParameter ("Delay", StringValue ("2ms")); |
|
58 NetDeviceContainer dev1 = csma.Install (lan1); |
|
59 Ipv4AddressHelper ipv4; |
|
60 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
|
61 Ipv4InterfaceContainer i1 = ipv4.Assign (dev1); |
|
62 |
|
63 |
|
64 // |
|
65 // Create the lan on the right side of the dumbbell. |
|
66 // |
|
67 NodeContainer lan2; |
|
68 lan2.Create (4); |
|
69 internet.Install (lan2); |
|
70 |
|
71 NetDeviceContainer dev2 = csma.Install (lan2); |
|
72 ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
|
73 Ipv4InterfaceContainer i2 = ipv4.Assign (dev2); |
|
74 |
|
75 |
|
76 // |
|
77 // Create the point-to-point link to connect the two lans. |
|
78 // |
|
79 NodeContainer backbone = NodeContainer (lan1.Get (3), lan2.Get (0)); |
|
80 PointToPointHelper p2p; |
|
81 p2p.SetChannelParameter ("DataRate", StringValue ("38400bps")); |
|
82 p2p.SetChannelParameter ("Delay", StringValue ("20ms")); |
|
83 NetDeviceContainer dev3 = p2p.Install (backbone); |
|
84 ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
|
85 ipv4.Assign (dev3); |
|
86 |
|
87 // |
|
88 // Create data flows across the link: |
|
89 // n0 ==> n4 ==> n0 |
|
90 // n1 ==> n5 ==> n1 |
|
91 // n2 ==> n6 ==> n2 |
|
92 // n3 ==> n7 ==> n3 |
|
93 // |
|
94 uint16_t port = 7; |
|
95 |
|
96 UdpEchoClientHelper client; |
|
97 client.SetRemote (i2.GetAddress (0), port); |
|
98 client.SetAppAttribute ("MaxPackets", UintegerValue (100)); |
|
99 client.SetAppAttribute ("Interval", StringValue ("10ms")); |
|
100 client.SetAppAttribute ("PacketSize", UintegerValue (1024)); |
|
101 ApplicationContainer apps = client.Install (lan1.Get (0)); |
|
102 apps.Start (Seconds(2.)); |
|
103 apps.Stop (Seconds (10.0)); |
|
104 |
|
105 client.SetRemote (i2.GetAddress (1), port); |
|
106 apps = client.Install (lan1.Get (1)); |
|
107 apps.Start (Seconds(2.1)); |
|
108 apps.Stop (Seconds (10.0)); |
|
109 |
|
110 client.SetRemote (i2.GetAddress (2), port); |
|
111 apps = client.Install (lan1.Get (2)); |
|
112 apps.Start (Seconds(2.2)); |
|
113 apps.Stop (Seconds (10.0)); |
|
114 |
|
115 client.SetRemote (i2.GetAddress (3), port); |
|
116 apps = client.Install (lan1.Get (3)); |
|
117 apps.Start (Seconds(2.3)); |
|
118 apps.Stop (Seconds (10.0)); |
|
119 |
|
120 |
|
121 UdpEchoServerHelper server; |
|
122 server.SetPort (port); |
|
123 apps = server.Install (lan2.Get (0)); |
|
124 apps.Start (Seconds (1.0)); |
|
125 apps.Stop (Seconds (10.0)); |
|
126 apps = server.Install (lan2.Get (1)); |
|
127 apps.Start (Seconds (1.0)); |
|
128 apps.Stop (Seconds (10.0)); |
|
129 apps = server.Install (lan2.Get (2)); |
|
130 apps.Start (Seconds (1.0)); |
|
131 apps.Stop (Seconds (10.0)); |
|
132 apps = server.Install (lan2.Get (3)); |
|
133 apps.Start (Seconds (1.0)); |
|
134 apps.Stop (Seconds (10.0)); |
|
135 |
|
136 GlobalRouteManager::PopulateRoutingTables (); |
|
137 |
|
138 std::ofstream os; |
|
139 os.open ("tutorial.tr"); |
|
140 PointToPointHelper::EnableAsciiAll (os); |
|
141 CsmaHelper::EnableAsciiAll (os); |
|
142 |
|
143 PointToPointHelper::EnablePcapAll ("tutorial"); |
|
144 CsmaHelper::EnablePcapAll ("tutorial"); |
|
145 |
|
146 Simulator::Run (); |
|
147 Simulator::Destroy (); |
|
148 } |
|