-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixed.cc~
executable file
·319 lines (277 loc) · 9.88 KB
/
mixed.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
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008,2009 IITP RAS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Kirill Andreev <[email protected]>
*
* n1
*
*
*
* n0 n3 n4 n5
*
*
*
*
* n2
*
* See also MeshTest::Configure to read more about configurable
* parameters.
*/
#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mesh-module.h"
#include "ns3/mesh-helper.h"
#include "ns3/wifi-phy.h"
#include "ns3/random-variable-stream.h"
#include "ns3/netanim-module.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/v4ping-helper.h"
#include "ns3/flow-monitor-helper.h"
#include <iostream>
#include <sstream>
#include <fstream>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
class MeshTest
{
public:
MeshTest ();
void Configure (int argc, char ** argv);
/// Run test
int Run ();
private:
double m_randomStart;
double m_totalTime;
double m_packetInterval;
uint16_t m_packetSize;
uint32_t m_nIfaces;
bool m_chan;
std::string m_stack;
std::string m_root;
/////////////for mesh nodes///////////////////////
NodeContainer nodes;
NetDeviceContainer meshDevices;
Ipv4InterfaceContainer interfaces;
MeshHelper mesh;
///for local 802.11 wifi nodes /////////////////
NodeContainer wifiStaNode;
NodeContainer wifiApNode;
NetDeviceContainer staDevice;
NetDeviceContainer apDevice;
Ipv4InterfaceContainer staNodeInterface;
Ipv4InterfaceContainer apNodeInterface;
private:
void CreateNodes ();
void InstallInternetStack ();
void InstallApplication ();
void Report ();
};
MeshTest::MeshTest () :
m_randomStart (0.1),
m_totalTime (100.0),
m_packetInterval (0.1),
m_packetSize (1024),
m_nIfaces (1),
m_chan (true),
m_stack ("ns3::Dot11sStack"),
m_root ("ff:ff:ff:ff:ff:ff")
{
}
void
MeshTest::Configure (int argc, char *argv[])
{
CommandLine cmd;
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 ("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 ("Simulation time: " << m_totalTime << " s");
}
void
MeshTest::CreateNodes ()
{
/////////for mesh node /////////////////
nodes.Create (5); //created 5 mesh node
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
mesh = MeshHelper::Default ();
if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
{
mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_root.c_str ())));
}
else
{
mesh.SetStackInstaller (m_stack);
}
if (m_chan)
{
mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
}
else
{
mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
}
mesh.SetMacType ("RandomStart", TimeValue (Seconds (m_randomStart)));
mesh.SetNumberOfInterfaces (m_nIfaces);
// Install protocols and return container if MeshPointDevices
meshDevices = mesh.Install (wifiPhy, nodes);
// Setup mobility - static grid topology
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc =
CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 95.0, 0.0));
positionAlloc->Add (Vector (95.0, 0.0, 0.0));
positionAlloc->Add (Vector (95.0, 190.0, 0.0));
positionAlloc->Add (Vector (95.0, 95.0, 0.0));
//positionAlloc->Add (Vector (200.0, 95.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
///////////////////////////////////////////////////////////////////////
wifiPhy.EnablePcapAll("pcap/mixed");
///////////////////for local 802.11 wifi network/////////////////
wifiStaNode.Create (1);
//NodeContainer wifiApNode;
wifiApNode=nodes.Get(4);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
phy.Set ("ShortGuardEnabled", BooleanValue (false));
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
HtWifiMacHelper mac = HtWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns380211n");
//double datarate = 0;
StringValue DataRate;
DataRate = StringValue ("OfdmRate27MbpsBW10MHz");
//datarate = 26;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate, "ControlMode", DataRate);
mac.SetType ("ns3::StaWifiMac","Ssid", SsidValue (ssid),"ActiveProbing", BooleanValue (false));
staDevice = wifi.Install (phy, mac, wifiStaNode);
mac.SetType ("ns3::ApWifiMac","Ssid", SsidValue (ssid));
apDevice = wifi.Install (phy, mac, wifiApNode);
// mobility.
MobilityHelper mobility_wifi;
Ptr<ListPositionAllocator> positionAlloc_wifi = CreateObject<ListPositionAllocator> ();
positionAlloc_wifi->Add (Vector (110.0, 95.0, 0.0));
positionAlloc_wifi->Add (Vector (120, 95.0, 0.0));
mobility_wifi.SetPositionAllocator (positionAlloc_wifi);
mobility_wifi.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility_wifi.Install (wifiApNode);
mobility_wifi.Install (wifiStaNode);
///////////////////////////////////////////////////////////////////////////
phy.EnablePcapAll("pcap/mixed");
}
void
MeshTest::InstallInternetStack ()
{
//////////for mesh node ///////////////////////////////
InternetStackHelper internetStack;
internetStack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
interfaces = address.Assign (meshDevices);
//////////////////////////////////////////////////////
///////////////////for local 802.11 wifi network/////////////////
InternetStackHelper stack;
stack.Install (wifiStaNode);
Ipv4AddressHelper address_wifi;
address_wifi.SetBase ("192.168.1.0", "255.255.255.0");
staNodeInterface = address_wifi.Assign (staDevice);
apNodeInterface = address_wifi.Assign (apDevice);
////////////////////////////////////////////////////////////////
}
void
MeshTest::InstallApplication ()
{
//V4PingHelper ping2 (interfaces.GetAddress(0));
V4PingHelper ping2 (staNodeInterface.GetAddress(0));
ping2.SetAttribute ("Verbose", BooleanValue (true));
ping2.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
ApplicationContainer appPingInternet2 = ping2.Install (nodes.Get(2));
appPingInternet2.Start (Seconds (0));
appPingInternet2.Stop (Seconds (98 - 1));
}
int
MeshTest::Run ()
{
CreateNodes ();
InstallInternetStack ();
InstallApplication ();
Simulator::Schedule (Seconds (m_totalTime), &MeshTest::Report, this);
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
AnimationInterface anim("xml/mixed.xml");
/////flow monitor
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Simulator::Stop (Seconds (m_totalTime));
Simulator::Run ();
monitor->SerializeToXmlFile("topology.xml",true,true);
// 10. Print per flow statistics
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i =stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
std::cout << "Flow " << i->first << " (" << t.sourceAddress<< " -> " << t.destinationAddress << ")\n";
std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
std::cout << " Throughput: " << i->second.rxBytes * 8.0 / 1024 / 1024 << " Mbps\n";
}
Simulator::Destroy ();
return 0;
}
void
MeshTest::Report ()
{
unsigned n (0);
for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i != meshDevices.End (); ++i, ++n)
{
std::ostringstream os;
os << "mp-report-" << n << ".xml";
//std::cerr << "Printing mesh point device #" << n << " diagnostics to " << os.str () << "\n";
std::ofstream of;
of.open (os.str ().c_str ());
if (!of.is_open ())
{
std::cerr << "Error: Can't open file " << os.str () << "\n";
return;
}
mesh.Report (*i, of);
of.close ();
}
}
int
main (int argc, char *argv[])
{
ns3::PacketMetadata::Enable ();
MeshTest t;
t.Configure (argc, argv);
return t.Run ();
}