-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmesh-internet-handoff.cc
536 lines (446 loc) · 18 KB
/
mesh-internet-handoff.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mesh-module.h"
#include "ns3/mobility-module.h"
#include "ns3/mesh-helper.h"
#include "ns3/flow-monitor-module.h"
#include <iomanip>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <ns3/flow-monitor-helper.h>
#include "ns3/gnuplot.h"
#include "ns3/netanim-module.h"
#include "src/point-to-point/helper/point-to-point-helper.h"
#include "src/csma/helper/csma-helper.h"
#include "ns3/olsr-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/netanim-module.h"
#include "src/network/model/packet-metadata.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("mesh-internet-handoff");
void
ThroughputMonitor (FlowMonitorHelper *fmhelper, Ptr<FlowMonitor> flowMon, Gnuplot2dDataset DataSet);
//NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
// Method for setting mobility using (x,y) position for the nodes
class MeshTest
{
public:
/// Init test
MeshTest ();
/// Configure test from command line arguments
void Configure (int argc, char ** argv);
/// Run test
int Run ();
private:
int m_sta1, m_sta2, m_gw1, m_gw2, m_bb1;
int m_xSize;
int m_ySize;
int m_maxStaNum;
double m_step;
double m_randomStart;
double m_totalTime;
double m_packetInterval;
uint16_t m_packetSize;
uint32_t m_nIfaces;
bool m_chan;
bool m_pcap;
std::string m_stack;
std::string m_root;
Ptr<FlowMonitor> flowMon;
/// NodeContainer for individual nodes
NodeContainer nc_sta1, nc_sta2;
NodeContainer nc_mbb1, nc_mbb2;
NodeContainer nc_gw1, nc_gw2;
NodeContainer nc_bb1;
// NodeContainer for categorical nodes
NodeContainer nc_sta, nc_mesh1, nc_mesh2;
// NodeContainer for connected nodes
NodeContainer nc_sta1Mbb1, nc_sta2Mbb2;
NodeContainer nc_mbb1Gw1, nc_mbb2Gw2;
NodeContainer nc_gw1Bb1, nc_gw2Bb1;
// List of categorical NetDevice Container
NetDeviceContainer de_sta1, de_sta2, de_ap1, de_ap2;
// List of WiFi NetDevice Container
NetDeviceContainer de_wifi_sta1Ap1;
NetDeviceContainer de_wifi_sta2Ap2;
// List of mesh NetDevice Container
NetDeviceContainer de_mesh1;
NetDeviceContainer de_mesh2;
// List of p2p NetDevice Container
NetDeviceContainer de_p2p_gw1Bb1;
NetDeviceContainer de_p2p_gw2Bb1;
// List of interface container
Ipv4InterfaceContainer if_mesh1;
Ipv4InterfaceContainer if_mesh2;
Ipv4InterfaceContainer if_p2p_gw1Bb1;
Ipv4InterfaceContainer if_p2p_gw2Bb1;
// Helper
MeshHelper meshHelper1, meshHelper2;
PointToPointHelper p2pHelper;
Ipv4AddressHelper address;
FlowMonitorHelper fmHelper;
private:
/// Create nodes and setup their mobility
void CreateNodes ();
/// Install internet m_stack on nodes
void InstallInternetStack ();
/// Install applications
void InstallApplication ();
/// Setup mobility
void SetupMobility ();
/// Print mesh devices diagnostics
void Report ();
/// Setup FlowMonitor
void InstallFlowMonitor ();
};
MeshTest::MeshTest () :
// Set up node numbers on the network.
m_sta1 (1), // Number of station nodes in the first network.
m_sta2 (1), // Number of station nodes in the second network.
m_gw1 (1),
m_gw2 (1),
m_bb1 (1),
m_xSize (2),
m_ySize (2),
//m_ap (2),
m_maxStaNum (1), // Contains the largest number of station nodes between two networks.
m_step (50.0),
m_randomStart (0.1),
m_totalTime (100.0),
m_packetInterval (0.1),
m_packetSize (1024),
m_nIfaces (1),
m_chan (true),
m_pcap (false),
m_stack ("ns3::Dot11sStack"),
m_root ("ff:ff:ff:ff:ff:ff") { }
void
MeshTest::Configure (int argc, char *argv[])
{
CommandLine cmd;
cmd.AddValue ("sta1", "Number of station nodes in network 1", m_sta1);
cmd.AddValue ("sta2", "Number of station nodes in network 2", m_sta2);
//
cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]", m_xSize);
cmd.AddValue ("y-size", "Number of rows in a grid. [6]", m_ySize);
cmd.AddValue ("step", "Size of edge in our grid, meters. [100 m]", m_step);
/*
* As soon as starting node means that it sends a beacon,
* simultaneous start is not good.
*/
cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1 s]", m_randomStart);
cmd.AddValue ("time", "Simulation time, seconds [100 s]", m_totalTime);
cmd.AddValue ("packet-interval", "Interval between packets in UDP ping, seconds [0.001 s]", m_packetInterval);
cmd.AddValue ("packet-size", "Size of packets in UDP ping", m_packetSize);
cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh point. [1]", m_nIfaces);
cmd.AddValue ("channels", "Use different frequency channels for different interfaces. [0]", m_chan);
cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]", m_pcap);
cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by default", m_stack);
cmd.AddValue ("root", "Mac address of root mesh point in HWMP", m_root);
cmd.Parse (argc, argv);
NS_LOG_DEBUG ("Grid:" << m_xSize << "*" << m_ySize);
NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s");
}
void
MeshTest::CreateNodes ()
{
// Station nodes
nc_sta1.Create (m_sta1);
nc_sta2.Create (m_sta2);
// Mesh Backbone nodes
nc_mbb1.Create (m_ySize * m_xSize);
nc_mbb2.Create (m_ySize * m_xSize);
// Gateway mesh nodes
nc_gw1.Create (m_gw1);
nc_gw2.Create (m_gw2);
// Internet node
nc_bb1.Create (m_bb1);
// Contains all the station nodes in network 1 and network 2
nc_sta = NodeContainer (nc_sta1, nc_sta2);
// Contains station nodes and mesh backbone nodes.
nc_sta1Mbb1 = NodeContainer (nc_sta1, nc_mbb1);
nc_sta2Mbb2 = NodeContainer (nc_sta2, nc_mbb2);
// Contains gateway and internet nodes.
nc_gw1Bb1 = NodeContainer (nc_gw1, nc_bb1);
nc_gw2Bb1 = NodeContainer (nc_gw2, nc_bb1);
// Contains all mesh nodes including STA, Backbone and Gateway.
nc_mesh1 = NodeContainer (nc_sta1, nc_mbb1, nc_gw1);
nc_mesh2 = NodeContainer (nc_sta2, nc_mbb2, nc_gw2);
// Create p2p links between gateways (gw1, gw2) and Internet node
p2pHelper.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
p2pHelper.SetChannelAttribute ("Delay", StringValue ("10ms"));
de_p2p_gw1Bb1 = p2pHelper.Install (nc_gw1Bb1);
de_p2p_gw2Bb1 = p2pHelper.Install (nc_gw2Bb1);
// Configure YansWifiChannel
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
meshHelper1 = MeshHelper::Default ();
if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
{
meshHelper1.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_root.c_str ())));
}
else
{
//If root is not set, we do not use "Root" attribute, because it
//is specified only for 11s
meshHelper1.SetStackInstaller (m_stack);
}
if (m_chan)
{
meshHelper1.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
}
else
{
meshHelper1.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
}
meshHelper1.SetMacType ("RandomStart", TimeValue (Seconds (m_randomStart)));
// Set number of interfaces - default is single-interface mesh point
meshHelper1.SetNumberOfInterfaces (m_nIfaces);
// Install protocols and return container if MeshPointDevices
de_mesh1 = meshHelper1.Install (wifiPhy, nc_mesh1);
meshHelper2 = MeshHelper::Default ();
if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
{
meshHelper2.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_root.c_str ())));
}
else
{
//If root is not set, we do not use "Root" attribute, because it
//is specified only for 11s
meshHelper2.SetStackInstaller (m_stack);
}
if (m_chan)
{
meshHelper2.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
}
else
{
meshHelper2.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
}
meshHelper2.SetMacType ("RandomStart", TimeValue (Seconds (m_randomStart)));
// Set number of interfaces - default is single-interface mesh point
meshHelper2.SetNumberOfInterfaces (m_nIfaces);
de_mesh2 = meshHelper2.Install (wifiPhy, nc_mesh2);
// Setup WiFi for network 1
WifiHelper wifi1 = WifiHelper::Default ();
wifi1.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi1.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac1 = NqosWifiMacHelper::Default ();
// Station nodes are initialized for network 1
Ssid ssid1 = Ssid ("network-1");
mac1.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid1),
"ActiveProbing", BooleanValue (true));
de_sta1 = wifi1.Install (wifiPhy, mac1, nc_sta1);
// Setup AP for network 1
mac1.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid1));
// Creates APs among the mesh nodes, selects the nodes of first column as AP, determined by the m_xSize.
for (int i = 0; i < (m_xSize * m_ySize); i += m_xSize)
{
de_ap1.Add (wifi1.Install (wifiPhy, mac1, nc_mbb1.Get (i)));
}
// Setup WiFi for network 2
WifiHelper wifi2 = WifiHelper::Default ();
wifi2.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi2.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac2 = NqosWifiMacHelper::Default ();
// Station nodes are initialized for network 2
Ssid ssid2 = Ssid ("network-2");
mac2.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid2),
"ActiveProbing", BooleanValue (true));
de_sta2 = wifi2.Install (wifiPhy, mac2, nc_sta2);
// Setup AP for network 2
mac2.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid2));
// Creates APs among the mesh nodes, selects the nodes of first column as AP, determined by the m_xSize.
for (int i = 0; i < (m_xSize * m_ySize); i += m_xSize)
{
de_ap2.Add (wifi1.Install (wifiPhy, mac1, nc_mbb2.Get (i)));
}
// Net Device container for STA and AP in network 1
de_wifi_sta1Ap1.Add (de_sta1);
de_wifi_sta1Ap1.Add (de_ap1);
// Net Device container for STA and AP in network 2
de_wifi_sta2Ap2.Add (de_sta2);
de_wifi_sta2Ap2.Add (de_ap2);
}
void
MeshTest::SetupMobility ()
{
// Stores the larger number of station nodes in m_maxStaNum, required for alignment.
if (m_sta1 >= m_sta2)
m_maxStaNum = m_sta1;
else
m_maxStaNum = m_sta2;
// Setup mobility for the nodes
MobilityHelper mobility1;
mobility1.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue ((m_maxStaNum - m_sta1) * m_step),
"MinY", DoubleValue ((m_xSize - 1)*.5 * m_step),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (m_sta1),
"LayoutType", StringValue ("RowFirst"));
mobility1.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-500, 500, -500, 500)),
"Speed", StringValue ("ns3::UniformRandomVariable[Min=20.0|Max=50.0]"),
"Direction", StringValue ("ns3::UniformRandomVariable[Min=10.0|Max=26.283184]"));
// Creates RandomWalk2DMobility model for the station nodes.
mobility1.Install (nc_sta1);
// Setup mobility for the nodes
MobilityHelper mobility2;
mobility2.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue ((m_maxStaNum) * m_step),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (m_xSize),
"LayoutType", StringValue ("RowFirst"));
mobility2.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
// Create constant positions for mesh backbone nodes.
mobility2.Install (nc_mbb1);
MobilityHelper mobility3;
mobility3.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue ((m_maxStaNum + m_xSize) * m_step),
"MinY", DoubleValue ((m_xSize - 1)*.5 * m_step),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (2),
"LayoutType", StringValue ("RowFirst"));
mobility3.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
// Create constant positions for gateway nodes.
mobility3.Install (nc_gw1);
// Setup mobility for the nodes
MobilityHelper mobility4;
mobility4.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue ((m_maxStaNum - m_sta2) * m_step),
"MinY", DoubleValue (((m_xSize - 1)*.5 * m_step)+(m_xSize + 1) * m_step),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (m_maxStaNum),
"LayoutType", StringValue ("RowFirst"));
mobility4.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
// Creates RandomWalk2DMobility model for the station nodes.
mobility4.Install (nc_sta2);
MobilityHelper mobility5;
mobility5.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (((m_maxStaNum) * m_step)),
"MinY", DoubleValue ((m_xSize + 1) * m_step),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (m_xSize),
"LayoutType", StringValue ("RowFirst"));
mobility5.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
// Create constant positions for mesh backbone nodes.
mobility5.Install (nc_mbb2);
//SetPosition (nc_gw1.Get (0),(m_sta1+m_ap1+m_xSize)*m_step , ((m_xSize-1)/2)*m_step);
MobilityHelper mobility6;
mobility6.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue ((m_maxStaNum + m_xSize) * m_step),
"MinY", DoubleValue (((m_xSize - 1)*.5 * m_step)+(m_xSize + 1) * m_step),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (2),
"LayoutType", StringValue ("RowFirst"));
mobility6.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
// Create constant positions for gateway nodes.
mobility6.Install (nc_gw2);
MobilityHelper mobility7;
mobility7.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue ((m_maxStaNum + m_xSize + m_gw1) * m_step),
"MinY", DoubleValue ((m_xSize + m_ySize)*.5 * m_step),
"DeltaX", DoubleValue (m_step),
"DeltaY", DoubleValue (m_step),
"GridWidth", UintegerValue (2),
"LayoutType", StringValue ("RowFirst"));
mobility7.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
// Constant position for Internet node.
mobility7.Install (nc_bb1);
}
void
MeshTest::InstallInternetStack ()
{
InternetStackHelper internetStackHelper;
OlsrHelper routingProtocol;
internetStackHelper.SetRoutingHelper (routingProtocol);
// Setup internet stack on the nodes
internetStackHelper.Install (nc_sta1);
internetStackHelper.Install (nc_sta2);
internetStackHelper.Install (nc_mbb1);
internetStackHelper.Install (nc_mbb2);
internetStackHelper.Install (nc_gw1);
internetStackHelper.Install (nc_gw2);
internetStackHelper.Install (nc_bb1);
// Network 1
address.SetBase ("10.1.1.0", "255.255.255.0");
if_mesh1 = address.Assign (de_mesh1);
address.SetBase ("10.1.2.0", "255.255.255.0");
if_p2p_gw1Bb1 = address.Assign (de_p2p_gw1Bb1);
// Network 2
address.SetBase ("20.1.1.0", "255.255.255.0");
if_mesh2 = address.Assign (de_mesh2);
address.SetBase ("20.1.2.0", "255.255.255.0");
if_p2p_gw2Bb1 = address.Assign (de_p2p_gw2Bb1);
}
void
MeshTest::InstallApplication ()
{
// Setup server
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nc_sta2.Get (0));
serverApps.Start (Seconds (0.0));
serverApps.Stop (Seconds (m_totalTime));
// Setup client
UdpEchoClientHelper echoClient (if_mesh2.GetAddress (0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t) (m_totalTime * (1 / m_packetInterval))));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (m_packetInterval)));
echoClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
ApplicationContainer clientApps = echoClient.Install (nc_sta1.Get (0));
clientApps.Start (Seconds (0.0));
clientApps.Stop (Seconds (m_totalTime));
}
int
MeshTest::Run ()
{
CreateNodes ();
InstallInternetStack ();
SetupMobility ();
InstallApplication ();
Simulator::Stop (Seconds (m_totalTime));
// Flow Monitor
InstallFlowMonitor ();
// Net Anim
AnimationInterface animation ("mesh-internet-handoff.xml");
animation.EnablePacketMetadata (false);
Simulator::Run ();
flowMon->SerializeToXmlFile ("mesh-internet-handoff-flowmon.xml", true, true);
Simulator::Destroy ();
return 0;
}
void
MeshTest::InstallFlowMonitor ()
{
flowMon = fmHelper.Install (nc_sta2.Get (0));
flowMon = fmHelper.Install (nc_sta1.Get (0));
}
int
main (int argc, char *argv[])
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
ns3::PacketMetadata::Enable ();
MeshTest t;
t.Configure (argc, argv);
return t.Run ();
}