-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmydc3add3core.cc
266 lines (206 loc) · 10.1 KB
/
mydc3add3core.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("DataCenter1");
int main (int argc, char *argv[])
{
bool verbose = true;
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
//Add 3 core switch
//Construct the upper Network coragg11,coragg12,coragg21,coragg22. coragg11:core1->agg1
//ptpNodes
NodeContainer coragg11,coragg12,coragg21,coragg22,coragg31,coragg32,coragg41,coragg42;
coragg11.Create(2);
coragg12.Add(coragg11.Get(0));
coragg12.Create(1);
coragg21.Create(1);
coragg21.Add(coragg11.Get(1));
coragg22.Add(coragg21.Get(0));
coragg22.Add(coragg12.Get(1));
coragg31.Create(1);
coragg31.Add(coragg11.Get(1));
coragg32.Add(coragg31.Get(0));
coragg32.Add(coragg12.Get(1));
coragg41.Create(1);
coragg41.Add(coragg11.Get(1));
coragg42.Add(coragg41.Get(0));
coragg42.Add(coragg12.Get(1));
//Construct the middle Network aggrtoR1: aggregation1->toRswitch1,aggrtoR2:aggregation2->toRswitch2
//Consider preorder
NodeContainer aggrtoR1,aggrtoR2;
aggrtoR1.Add(coragg11.Get(1));
aggrtoR1.Create(2);
aggrtoR2.Add(coragg12.Get(1));
aggrtoR2.Create(2);
//Construct the lower Network:csmaNodes
NodeContainer csmaNodes1,csmaNodes2,csmaNodes3,csmaNodes4;
csmaNodes1.Add(aggrtoR1.Get(1));
csmaNodes1.Create(2);
csmaNodes2.Add(aggrtoR1.Get(2));
csmaNodes2.Create(2);
csmaNodes3.Add(aggrtoR2.Get(1));
csmaNodes3.Create(2);
csmaNodes4.Add(aggrtoR2.Get(2));
csmaNodes4.Create(2);
//Construct ptp topo upper
PointToPointHelper ptp1,ptp2,ptp3,ptp4,ptp5,ptp6,ptp7,ptp8;
ptp1.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp1.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp2.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp2.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp3.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp3.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp4.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp4.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp5.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp5.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp6.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp6.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp7.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp7.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
ptp8.SetDeviceAttribute ("DataRate", StringValue ("1.5Mbps"));
ptp8.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
NetDeviceContainer devicePtp1,devicePtp2,devicePtp3,devicePtp4,devicePtp5,devicePtp6,devicePtp7,devicePtp8;
devicePtp1=ptp1.Install (coragg11);
devicePtp2=ptp2.Install (coragg12);
devicePtp3=ptp3.Install (coragg21);
devicePtp4=ptp4.Install (coragg22);
devicePtp5=ptp5.Install (coragg31);
devicePtp6=ptp6.Install (coragg32);
devicePtp7=ptp7.Install (coragg41);
devicePtp8=ptp8.Install (coragg42);
//Construct csma topo
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("1Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
//middle topo
NetDeviceContainer deviceAggToR1,deviceAggToR2;
deviceAggToR1=csma.Install (aggrtoR1);
deviceAggToR2=csma.Install (aggrtoR2);
//lower topo
NetDeviceContainer deviceCsmaNodes1,deviceCsmaNodes2,deviceCsmaNodes3,deviceCsmaNodes4;
deviceCsmaNodes1=csma.Install (csmaNodes1);
deviceCsmaNodes2=csma.Install (csmaNodes2);
deviceCsmaNodes3=csma.Install (csmaNodes3);
deviceCsmaNodes4=csma.Install (csmaNodes4);
//Install protocol stack
InternetStackHelper stack;
stack.Install (coragg11);
stack.Install (coragg12.Get(1));
stack.Install (coragg21.Get(0));
stack.Install (coragg31.Get(0));
stack.Install (coragg41.Get(0));
stack.Install (aggrtoR1.Get(1));
stack.Install (aggrtoR1.Get(2));
stack.Install (aggrtoR2.Get(1));
stack.Install (aggrtoR2.Get(2));
stack.Install (csmaNodes1.Get(1));
stack.Install (csmaNodes1.Get(2));
stack.Install (csmaNodes2.Get(1));
stack.Install (csmaNodes2.Get(2));
stack.Install (csmaNodes3.Get(1));
stack.Install (csmaNodes3.Get(2));
stack.Install (csmaNodes4.Get(1));
stack.Install (csmaNodes4.Get(2));
//Allocate addresses on the network
Ipv4AddressHelper address;
address.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp1 = address.Assign (devicePtp1);
address.SetBase ("192.168.2.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp2 = address.Assign (devicePtp2);
address.SetBase ("192.168.3.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp3 = address.Assign (devicePtp3);
address.SetBase ("192.168.4.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp4 = address.Assign (devicePtp4);
address.SetBase ("192.168.5.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp5 = address.Assign (devicePtp5);
address.SetBase ("192.168.6.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp6 = address.Assign (devicePtp6);
address.SetBase ("192.168.7.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp7 = address.Assign (devicePtp7);
address.SetBase ("192.168.8.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesPtp8 = address.Assign (devicePtp8);
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesAggToR1 = address.Assign (deviceAggToR1);
address.SetBase ("10.2.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesAggToR2 = address.Assign (deviceAggToR2);
address.SetBase ("10.0.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesCsma1 = address.Assign (deviceCsmaNodes1);
address.SetBase ("10.0.2.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesCsma2 = address.Assign (deviceCsmaNodes2);
address.SetBase ("10.0.3.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesCsma3 = address.Assign (deviceCsmaNodes3);
address.SetBase ("10.0.4.0", "255.255.255.0");
Ipv4InterfaceContainer interfacesCsma4 = address.Assign (deviceCsmaNodes4);
//Set up inter-cluster traffic
//Set up traffic n1 -- n5
PacketSinkHelper packetSinkHelper1("ns3::TcpSocketFactory", InetSocketAddress(interfacesCsma3.GetAddress(1),8080));
ApplicationContainer sinkApp1 = packetSinkHelper1.Install(csmaNodes3.Get(1));
sinkApp1.Start(Seconds(0.0));
sinkApp1.Stop(Seconds(20.0));
OnOffHelper client1("ns3::TcpSocketFactory", InetSocketAddress(interfacesCsma3.GetAddress(1), 8080));
client1.SetAttribute ("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=50]"));
client1.SetAttribute ("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
client1.SetAttribute ("DataRate", DataRateValue (DataRate ("1.0Mbps")));
client1.SetAttribute ("PacketSize", UintegerValue (2000));
ApplicationContainer clientApp1 = client1.Install (csmaNodes1.Get(1));
clientApp1.Start(Seconds (1.0 ));
clientApp1.Stop (Seconds (21.0));
csma.EnablePcap ("Pattern3s n1 to n5", deviceCsmaNodes3.Get (1), true);
//Set up traffic n6 -- n2
PacketSinkHelper packetSinkHelper2("ns3::TcpSocketFactory",InetSocketAddress(interfacesCsma1.GetAddress(2),8081));
ApplicationContainer sinkApp2 = packetSinkHelper2.Install(csmaNodes1.Get(2));
sinkApp2.Start(Seconds(0.0));
sinkApp2.Stop(Seconds(20.0));
OnOffHelper client2("ns3::TcpSocketFactory", InetSocketAddress(interfacesCsma1.GetAddress(2), 8081));
client2.SetAttribute ("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=50]"));
client2.SetAttribute ("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
client2.SetAttribute ("DataRate", DataRateValue (DataRate ("1.0Mbps")));
client2.SetAttribute ("PacketSize", UintegerValue (2000));
ApplicationContainer clientApp2 = client2.Install (csmaNodes3.Get(2));
clientApp2.Start(Seconds (1.0 ));
clientApp2.Stop (Seconds (21.0));
csma.EnablePcap ("Pattern3s n6 to n2", deviceCsmaNodes1.Get (2), true);
//Set up traffic n3 -- n7
PacketSinkHelper packetSinkHelper3("ns3::TcpSocketFactory",InetSocketAddress(interfacesCsma4.GetAddress(1),8082));
ApplicationContainer sinkApp3 = packetSinkHelper3.Install(csmaNodes4.Get(1));
sinkApp3.Start(Seconds(0.0));
sinkApp3.Stop(Seconds(20.0));
OnOffHelper client3("ns3::TcpSocketFactory", InetSocketAddress(interfacesCsma4.GetAddress(1), 8082));
client3.SetAttribute ("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=50]"));
client3.SetAttribute ("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
client3.SetAttribute ("DataRate", DataRateValue (DataRate ("1.0Mbps")));
client3.SetAttribute ("PacketSize", UintegerValue (2000));
ApplicationContainer clientApp3 = client3.Install (csmaNodes2.Get(1));
clientApp3.Start(Seconds (1.0 ));
clientApp3.Stop (Seconds (21.0));
csma.EnablePcap ("Pattern3s n3 to n7", deviceCsmaNodes4.Get (1), true);
//Set up traffic n8 -- n4
PacketSinkHelper packetSinkHelper4("ns3::TcpSocketFactory",InetSocketAddress(interfacesCsma2.GetAddress(2),8083));
ApplicationContainer sinkApp4 = packetSinkHelper4.Install(csmaNodes4.Get(2));
sinkApp4.Start(Seconds(0.0));
sinkApp4.Stop(Seconds(20.0));
OnOffHelper client4("ns3::TcpSocketFactory", InetSocketAddress(interfacesCsma2.GetAddress(2), 8083));
client4.SetAttribute ("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=50]"));
client4.SetAttribute ("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
client4.SetAttribute ("DataRate", DataRateValue (DataRate ("1.0Mbps")));
client4.SetAttribute ("PacketSize", UintegerValue (2000));
ApplicationContainer clientApp4 = client4.Install (csmaNodes4.Get(2));
clientApp4.Start(Seconds (1.0 ));
clientApp4.Stop (Seconds (21.0));
csma.EnablePcap ("Pattern3s n8 to n4", deviceCsmaNodes2.Get (2), true);
Config::SetDefault("ns3::Ipv4GlobalRouting::RandomEcmpRouting",BooleanValue(true));
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Simulator::Run ();
Simulator::Destroy ();
return 0;
}