-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsimple-wifi-mobility.cpp
272 lines (228 loc) · 11.1 KB
/
simple-wifi-mobility.cpp
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
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Md Ashiqur Rahman: University of Arizona.
*
**/
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/ndnSIM-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/netanim-module.h"
#include "ns3/constant-velocity-mobility-model.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
NS_LOG_COMPONENT_DEFINE ("simple-wifi-mobility");
using namespace std;
namespace ns3 {
/**
* DESCRIPTION:
* This scenario provides a basic Wifi AP (as infrastucture) and two mobile STA nodes
* which do active association to an AP node when within the AP's range. Association
* is done by fetching the Bssid of current AP. After association, mobile STA will
* send unicast unicast interests to AP which reaches the producer ans fetches data back.
* Data is broadcast by AP, so other STA asking for same data will also receive. A global
* Routing is used, as Default routing doesn't forward interest from AP to producer. This
* is expected to be fixed later.
*
* The scenario simulates a tree topology (using topology reader module)
*
* /--------\
* +------->| root |<--------+
* | \--------/ | 10Mbps 100ms
* | |
* v v
* /-------\ /-------\
* +------>| rtr-4 |<-------+ +------>| rtr-5 |<--------+
* | \-------/ | | \-------/ |
* | | | | 10Mbps 50ms
* v v v v
* /-------\ /-------\ /-------\
* +->| rtr-1 |<-+ +->| rtr-2 |<-+ +->| rtr-3 |<-+
* | \-------/ | | \-------/ | | \-------/ |
* | | | | | | 10Mbps 2ms
* v v v v v v
* /------\ /------\ /------\ /------\ /------\ /------\
* |wifi-1| |wifi-2| |wifi-3| |wifi-4| |wifi-5| |wifi-6|
* \------/ \------/ \------/ \------/ \------/ \------/
*
*
* |m2|--> |m1|--->
*
*
* To run scenario and see what is happening, use the following command:
*
* ./waf --run=simple-wifi-mobility
*
* With LOGGING: e.g.
*
* NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=simple-wifi-mobility 2>&1 | tee log.txt
*/
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
uint32_t wifiSta = 2;
int bottomrow = 6; // number of AP nodes
int spacing = 200; // between bottom-row nodes
int range = 110;
double endtime = 20.0;
double speed = (double)(bottomrow*spacing)/endtime; //setting speed to span full sim time
string animFile = "ap-mobility-animation.xml";
CommandLine cmd;
cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
cmd.Parse (argc, argv);
////// Reading file for topology setup
AnnotatedTopologyReader topologyReader("", 1);
topologyReader.SetFileName("src/ndnSIM/examples/x-topo.txt");
topologyReader.Read();
////// Getting containers for the producer/wifi-ap
Ptr<Node> producer = Names::Find<Node>("root");
Ptr<Node> wifiApNodes[6] = {Names::Find<Node>("ap1"),
Names::Find<Node>("ap2"),
Names::Find<Node>("ap3"),
Names::Find<Node>("ap4"),
Names::Find<Node>("ap5"),
Names::Find<Node>("ap6")};
Ptr<Node> routers[5] = {Names::Find<Node>("r1"),
Names::Find<Node>("r2"),
Names::Find<Node>("r3"),
Names::Find<Node>("r4"),
Names::Find<Node>("r5"),};
////// disable fragmentation, RTS/CTS for frames below 2200 bytes and fix non-unicast data rate
Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
////// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
////// This is one parameter that matters when using FixedRssLossModel
////// set it to zero; otherwise, gain will be added
// wifiPhy.Set ("RxGain", DoubleValue (0) );
////// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
// wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");
////// The below FixedRssLossModel will cause the rss to be fixed regardless
////// of the distance between the two stations, and the transmit power
// wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
////// the following has an absolute cutoff at distance > range (range == radius)
wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel",
"MaxRange", DoubleValue(range));
wifiPhy.SetChannel (wifiChannel.Create ());
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue (phyMode),
"ControlMode", StringValue (phyMode));
////// Setup the rest of the upper mac
////// Setting SSID, optional. Modified net-device to get Bssid, mandatory for AP unicast
Ssid ssid = Ssid ("wifi-default");
// wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
////// Add a non-QoS upper mac of STAs, and disable rate control
NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default ();
////// Active associsation of STA to AP via probing.
wifiMacHelper.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (true),
"ProbeRequestTimeout", TimeValue(Seconds(0.25)));
////// Creating 2 mobile nodes
NodeContainer consumers;
consumers.Create(wifiSta);
NetDeviceContainer staDevice = wifi.Install (wifiPhy, wifiMacHelper, consumers);
NetDeviceContainer devices = staDevice;
////// Setup AP.
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid),
"BeaconGeneration", BooleanValue(false));
for (int i = 0; i < bottomrow; i++)
{
NetDeviceContainer apDevice = wifi.Install (wifiPhy, wifiMac, wifiApNodes[i]);
devices.Add (apDevice);
}
////// Note that with FixedRssLossModel, the positions below are not
////// used for received signal strength.
////// set positions for APs
MobilityHelper sessile;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
int Xpos = 0;
for (int i=0; i < bottomrow; i++) {
positionAlloc->Add(Vector(100+Xpos, 0.0, 0.0));
Xpos += spacing;
}
sessile.SetPositionAllocator (positionAlloc);
for (int i = 0; i < bottomrow; i++) {
sessile.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
sessile.Install (wifiApNodes[i]);
}
////// Setting mobility model and movement parameters for mobile nodes
////// ConstantVelocityMobilityModel is a subclass of MobilityModel
MobilityHelper mobile;
mobile.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
mobile.Install(consumers);
////// Setting each mobile consumer 100m apart from each other
int nxt = 0;
for (uint32_t i=0; i<wifiSta ; i++) {
Ptr<ConstantVelocityMobilityModel> cvmm = consumers.Get(i)->GetObject<ConstantVelocityMobilityModel> ();
Vector pos (0-nxt, 0, 0);
Vector vel (speed, 0, 0);
cvmm->SetPosition(pos);
cvmm->SetVelocity(vel);
nxt += 100;
}
// std::cout << "position: " << cvmm->GetPosition() << " velocity: " << cvmm->GetVelocity() << std::endl;
// std::cout << "mover mobility model: " << mobile.GetMobilityModelType() << std::endl; // just for confirmation
// 3. Install NDN stack on all nodes
NS_LOG_INFO("Installing NDN stack");
ndn::StackHelper ndnHelper;
//ndnHelper.InstallAll();
ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "1000");
//ndnHelper.SetDefaultRoutes(true);
//ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache");
ndnHelper.InstallAll();
// Choosing forwarding strategy
ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
//ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");
// Installing global routing interface on all nodes
ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
ndnGlobalRoutingHelper.InstallAll();
// 4. Set up applications
NS_LOG_INFO("Installing Applications");
// Consumer Helpers
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
consumerHelper.SetPrefix("/root/prefix");
//consumerHelper.SetPrefix("/test/prefix");
consumerHelper.SetAttribute("Frequency", DoubleValue(10.0));
consumerHelper.Install(consumers.Get(0)).Start(Seconds(0.0));
consumerHelper.Install(consumers.Get(1)).Start(Seconds(0.0));
// Producer Helpers
ndn::AppHelper producerHelper("ns3::ndn::Producer");
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
// Register /root prefix with global routing controller and
// install producer that will satisfy Interests in /root namespace
ndnGlobalRoutingHelper.AddOrigins("/root", producer);
producerHelper.SetPrefix("/root");
producerHelper.Install(producer);
// Calculate and install FIBs
ndn::GlobalRoutingHelper::CalculateRoutes();
// Tracing
wifiPhy.EnablePcap ("simple-wifi-mobility", devices);
Simulator::Stop (Seconds (endtime));
AnimationInterface anim (animFile);
for (uint32_t i=0; i<wifiSta ; i++) {
string str = "simple-wifi-trace" + std::to_string(i+1) + ".txt";
ndn::L3RateTracer::Install(consumers.Get(i), str, Seconds(endtime-0.5));
}
//ndn::CsTracer::Install(routers[0],"simple-wifi-mobility-trace.txt", Seconds(1.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
}
int main(int argc, char* argv[])
{
return ns3::main(argc, argv);
}