A Discrete-Event Network Simulator
API
wifi-manager-example.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Tom Henderson <tomhend@u.washington.edu>
19  * Matías Richart <mrichart@fing.edu.uy>
20  * Sébastien Deronne <sebastien.deronne@gmail.com>
21  */
22 
23 // Test the operation of a wifi manager as the SNR is varied, and create
24 // a gnuplot output file for plotting.
25 //
26 // The test consists of a device acting as server and a device as client generating traffic.
27 //
28 // The output consists of a plot of the rate observed and selected at the client device.
29 //
30 // By default, the 802.11a standard using IdealWifiManager is plotted. Several command line
31 // arguments can change the following options:
32 // --wifiManager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, MinstrelHt, Onoe, Rraa)
33 // --standard (802.11a, 802.11b, 802.11g, 802.11n-5GHz, 802.11n-2.4GHz, 802.11ac, 802.11-holland, 802.11-10MHz, 802.11-5MHz)
34 // --serverShortGuardInterval and --clientShortGuardInterval (for 802.11n/ac)
35 // --serverNss and --clientNss (for 802.11n/ac)
36 // --serverChannelWidth and --clientChannelWidth (for 802.11n/ac)
37 // --broadcast instead of unicast (default is unicast)
38 // --rtsThreshold (by default, value of 99999 disables it)
39 
40 #include "ns3/log.h"
41 #include "ns3/config.h"
42 #include "ns3/uinteger.h"
43 #include "ns3/boolean.h"
44 #include "ns3/double.h"
45 #include "ns3/gnuplot.h"
46 #include "ns3/command-line.h"
47 #include "ns3/yans-wifi-helper.h"
48 #include "ns3/ssid.h"
49 #include "ns3/propagation-loss-model.h"
50 #include "ns3/propagation-delay-model.h"
51 #include "ns3/rng-seed-manager.h"
52 #include "ns3/mobility-helper.h"
53 #include "ns3/wifi-net-device.h"
54 #include "ns3/packet-socket-helper.h"
55 #include "ns3/packet-socket-client.h"
56 #include "ns3/packet-socket-server.h"
57 #include "ns3/ht-configuration.h"
58 #include "ns3/he-configuration.h"
59 
60 using namespace ns3;
61 
62 NS_LOG_COMPONENT_DEFINE ("WifiManagerExample");
63 
64 // 290K @ 20 MHz
65 const double NOISE_DBM_Hz = -174.0;
67 
68 double g_intervalBytes = 0;
69 uint64_t g_intervalRate = 0;
70 
71 void
73 {
74  NS_LOG_DEBUG ("Received size " << pkt->GetSize ());
75  g_intervalBytes += pkt->GetSize ();
76 }
77 
78 void
79 RateChange (uint64_t oldVal, uint64_t newVal)
80 {
81  NS_LOG_DEBUG ("Change from " << oldVal << " to " << newVal);
82  g_intervalRate = newVal;
83 }
84 
86 struct Step
87 {
88  double stepSize;
89  double stepTime;
90 };
91 
94 {
96  {
97  m_name = "none";
98  }
111  StandardInfo (std::string name, WifiPhyStandard standard, uint16_t width, double snrLow, double snrHigh, double xMin, double xMax, double yMax)
112  : m_name (name),
113  m_standard (standard),
114  m_width (width),
115  m_snrLow (snrLow),
116  m_snrHigh (snrHigh),
117  m_xMin (xMin),
118  m_xMax (xMax),
119  m_yMax (yMax)
120  {
121  }
122  std::string m_name;
124  uint16_t m_width;
125  double m_snrLow;
126  double m_snrHigh;
127  double m_xMin;
128  double m_xMax;
129  double m_yMax;
130 };
131 
132 void
133 ChangeSignalAndReportRate (Ptr<FixedRssLossModel> rssModel, struct Step step, double rss, Gnuplot2dDataset& rateDataset, Gnuplot2dDataset& actualDataset)
134 {
135  NS_LOG_FUNCTION (rssModel << step.stepSize << step.stepTime << rss);
136  double snr = rss - noiseDbm;
137  rateDataset.Add (snr, g_intervalRate / 1000000.0);
138  // Calculate received rate since last interval
139  double currentRate = ((g_intervalBytes * 8) / step.stepTime) / 1e6; // Mb/s
140  actualDataset.Add (snr, currentRate);
141  rssModel->SetRss (rss - step.stepSize);
142  NS_LOG_INFO ("At time " << Simulator::Now ().As (Time::S) << "; observed rate " << currentRate << "; setting new power to " << rss - step.stepSize);
143  g_intervalBytes = 0;
144  Simulator::Schedule (Seconds (step.stepTime), &ChangeSignalAndReportRate, rssModel, step, (rss - step.stepSize), rateDataset, actualDataset);
145 }
146 
147 int main (int argc, char *argv[])
148 {
149  std::vector <StandardInfo> serverStandards;
150  std::vector <StandardInfo> clientStandards;
151  uint32_t steps;
152  uint32_t rtsThreshold = 999999; // disabled even for large A-MPDU
153  uint32_t maxAmpduSize = 65535;
154  double stepSize = 1; // dBm
155  double stepTime = 1; // seconds
156  uint32_t packetSize = 1024; // bytes
157  bool broadcast = 0;
158  int ap1_x = 0;
159  int ap1_y = 0;
160  int sta1_x = 5;
161  int sta1_y = 0;
162  uint16_t serverNss = 1;
163  uint16_t clientNss = 1;
164  uint16_t serverShortGuardInterval = 800;
165  uint16_t clientShortGuardInterval = 800;
166  uint16_t serverChannelWidth = 20;
167  uint16_t clientChannelWidth = 20;
168  std::string wifiManager ("Ideal");
169  std::string standard ("802.11a");
170  StandardInfo serverSelectedStandard;
171  StandardInfo clientSelectedStandard;
172  bool infrastructure = false;
173  uint32_t maxSlrc = 7;
174  uint32_t maxSsrc = 7;
175 
177  cmd.AddValue ("maxSsrc", "The maximum number of retransmission attempts for a RTS packet", maxSsrc);
178  cmd.AddValue ("maxSlrc", "The maximum number of retransmission attempts for a DATA packet", maxSlrc);
179  cmd.AddValue ("rtsThreshold", "RTS threshold", rtsThreshold);
180  cmd.AddValue ("maxAmpduSize", "Max A-MPDU size", maxAmpduSize);
181  cmd.AddValue ("stepSize", "Power between steps (dBm)", stepSize);
182  cmd.AddValue ("stepTime", "Time on each step (seconds)", stepTime);
183  cmd.AddValue ("broadcast", "Send broadcast instead of unicast", broadcast);
184  cmd.AddValue ("serverChannelWidth", "Set channel width of the server (valid only for 802.11n or ac)", serverChannelWidth);
185  cmd.AddValue ("clientChannelWidth", "Set channel width of the client (valid only for 802.11n or ac)", clientChannelWidth);
186  cmd.AddValue ("serverNss", "Set nss of the server (valid only for 802.11n or ac)", serverNss);
187  cmd.AddValue ("clientNss", "Set nss of the client (valid only for 802.11n or ac)", clientNss);
188  cmd.AddValue ("serverShortGuardInterval", "Set short guard interval of the server (802.11n/ac/ax) in nanoseconds", serverShortGuardInterval);
189  cmd.AddValue ("clientShortGuardInterval", "Set short guard interval of the client (802.11n/ac/ax) in nanoseconds", clientShortGuardInterval);
190  cmd.AddValue ("standard", "Set standard (802.11a, 802.11b, 802.11g, 802.11n-5GHz, 802.11n-2.4GHz, 802.11ac, 802.11-holland, 802.11-10MHz, 802.11-5MHz, 802.11ax-5GHz, 802.11ax-2.4GHz)", standard);
191  cmd.AddValue ("wifiManager", "Set wifi rate manager (Aarf, Aarfcd, Amrr, Arf, Cara, Ideal, Minstrel, MinstrelHt, Onoe, Rraa)", wifiManager);
192  cmd.AddValue ("infrastructure", "Use infrastructure instead of adhoc", infrastructure);
193  cmd.Parse (argc,argv);
194 
195  // Print out some explanation of what this program does
196  std::cout << std::endl << "This program demonstrates and plots the operation of different " << std::endl;
197  std::cout << "Wi-Fi rate controls on different station configurations," << std::endl;
198  std::cout << "by stepping down the received signal strength across a wide range" << std::endl;
199  std::cout << "and observing the adjustment of the rate." << std::endl;
200  std::cout << "Run 'wifi-manager-example --PrintHelp' to show program options." << std::endl << std::endl;
201 
202  if (infrastructure == false)
203  {
204  NS_ABORT_MSG_IF (serverNss != clientNss, "In ad hoc mode, we assume sender and receiver are similarly configured");
205  }
206 
207  if (standard == "802.11b")
208  {
209  NS_ABORT_MSG_IF (serverChannelWidth != 22 && serverChannelWidth != 22, "Invalid channel width for standard " << standard);
210  NS_ABORT_MSG_IF (serverNss != 1, "Invalid nss for standard " << standard);
211  NS_ABORT_MSG_IF (clientChannelWidth != 22 && clientChannelWidth != 22, "Invalid channel width for standard " << standard);
212  NS_ABORT_MSG_IF (clientNss != 1, "Invalid nss for standard " << standard);
213  }
214  else if (standard == "802.11a" || standard == "802.11g")
215  {
216  NS_ABORT_MSG_IF (serverChannelWidth != 20, "Invalid channel width for standard " << standard);
217  NS_ABORT_MSG_IF (serverNss != 1, "Invalid nss for standard " << standard);
218  NS_ABORT_MSG_IF (clientChannelWidth != 20, "Invalid channel width for standard " << standard);
219  NS_ABORT_MSG_IF (clientNss != 1, "Invalid nss for standard " << standard);
220  }
221  else if (standard == "802.11n-5GHz" || standard == "802.11n-2.4GHz")
222  {
223  NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40, "Invalid channel width for standard " << standard);
224  NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4, "Invalid nss " << serverNss << " for standard " << standard);
225  NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40, "Invalid channel width for standard " << standard);
226  NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4, "Invalid nss " << clientNss << " for standard " << standard);
227  }
228  else if (standard == "802.11ac")
229  {
230  NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40 && serverChannelWidth != 80 && serverChannelWidth != 160, "Invalid channel width for standard " << standard);
231  NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4, "Invalid nss " << serverNss << " for standard " << standard);
232  NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40 && clientChannelWidth != 80 && clientChannelWidth != 160, "Invalid channel width for standard " << standard);
233  NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4, "Invalid nss " << clientNss << " for standard " << standard);
234  }
235  else if (standard == "802.11ax-5GHz" || standard == "802.11ax-2.4GHz")
236  {
237  NS_ABORT_MSG_IF (serverChannelWidth != 20 && serverChannelWidth != 40 && serverChannelWidth != 80 && serverChannelWidth != 160, "Invalid channel width for standard " << standard);
238  NS_ABORT_MSG_IF (serverNss == 0 || serverNss > 4, "Invalid nss " << serverNss << " for standard " << standard);
239  NS_ABORT_MSG_IF (clientChannelWidth != 20 && clientChannelWidth != 40 && clientChannelWidth != 80 && clientChannelWidth != 160, "Invalid channel width for standard " << standard);
240  NS_ABORT_MSG_IF (clientNss == 0 || clientNss > 4, "Invalid nss " << clientNss << " for standard " << standard);
241  }
242 
243  // As channel width increases, scale up plot's yRange value
244  uint32_t channelRateFactor = std::max (clientChannelWidth, serverChannelWidth) / 20;
245  channelRateFactor = channelRateFactor * std::max (clientNss, serverNss);
246 
247  // The first number is channel width, second is minimum SNR, third is maximum
248  // SNR, fourth and fifth provide xrange axis limits, and sixth the yaxis
249  // maximum
250  serverStandards.push_back (StandardInfo ("802.11a", WIFI_PHY_STANDARD_80211a, 20, 3, 27, 0, 30, 60));
251  serverStandards.push_back (StandardInfo ("802.11b", WIFI_PHY_STANDARD_80211b, 22, -5, 11, -6, 15, 15));
252  serverStandards.push_back (StandardInfo ("802.11g", WIFI_PHY_STANDARD_80211g, 20, -5, 27, -6, 30, 60));
253  serverStandards.push_back (StandardInfo ("802.11n-5GHz", WIFI_PHY_STANDARD_80211n_5GHZ, serverChannelWidth, 3, 30, 0, 35, 80 * channelRateFactor));
254  serverStandards.push_back (StandardInfo ("802.11n-2.4GHz", WIFI_PHY_STANDARD_80211n_2_4GHZ, serverChannelWidth, 3, 30, 0, 35, 80 * channelRateFactor));
255  serverStandards.push_back (StandardInfo ("802.11ac", WIFI_PHY_STANDARD_80211ac, serverChannelWidth, 5, 50, 0, 55, 120 * channelRateFactor));
256  serverStandards.push_back (StandardInfo ("802.11-holland", WIFI_PHY_STANDARD_holland, 20, 3, 27, 0, 30, 60));
257  serverStandards.push_back (StandardInfo ("802.11-10MHz", WIFI_PHY_STANDARD_80211_10MHZ, 10, 3, 27, 0, 30, 60));
258  serverStandards.push_back (StandardInfo ("802.11-5MHz", WIFI_PHY_STANDARD_80211_5MHZ, 5, 3, 27, 0, 30, 60));
259  serverStandards.push_back (StandardInfo ("802.11ax-5GHz", WIFI_PHY_STANDARD_80211ax_5GHZ, serverChannelWidth, 5, 55, 0, 60, 120 * channelRateFactor));
260  serverStandards.push_back (StandardInfo ("802.11ax-2.4GHz", WIFI_PHY_STANDARD_80211ax_2_4GHZ, serverChannelWidth, 5, 55, 0, 60, 120 * channelRateFactor));
261 
262  clientStandards.push_back (StandardInfo ("802.11a", WIFI_PHY_STANDARD_80211a, 20, 3, 27, 0, 30, 60));
263  clientStandards.push_back (StandardInfo ("802.11b", WIFI_PHY_STANDARD_80211b, 22, -5, 11, -6, 15, 15));
264  clientStandards.push_back (StandardInfo ("802.11g", WIFI_PHY_STANDARD_80211g, 20, -5, 27, -6, 30, 60));
265  clientStandards.push_back (StandardInfo ("802.11n-5GHz", WIFI_PHY_STANDARD_80211n_5GHZ, clientChannelWidth, 3, 30, 0, 35, 80 * channelRateFactor));
266  clientStandards.push_back (StandardInfo ("802.11n-2.4GHz", WIFI_PHY_STANDARD_80211n_2_4GHZ, clientChannelWidth, 3, 30, 0, 35, 80 * channelRateFactor));
267  clientStandards.push_back (StandardInfo ("802.11ac", WIFI_PHY_STANDARD_80211ac, clientChannelWidth, 5, 50, 0, 55, 120 * channelRateFactor));
268  clientStandards.push_back (StandardInfo ("802.11-holland", WIFI_PHY_STANDARD_holland, 20, 3, 27, 0, 30, 60));
269  clientStandards.push_back (StandardInfo ("802.11-10MHz", WIFI_PHY_STANDARD_80211_10MHZ, 10, 3, 27, 0, 30, 60));
270  clientStandards.push_back (StandardInfo ("802.11-5MHz", WIFI_PHY_STANDARD_80211_5MHZ, 5, 3, 27, 0, 30, 60));
271  clientStandards.push_back (StandardInfo ("802.11ax-5GHz", WIFI_PHY_STANDARD_80211ax_5GHZ, clientChannelWidth, 5, 55, 0, 60, 160 * channelRateFactor));
272  clientStandards.push_back (StandardInfo ("802.11ax-2.4GHz", WIFI_PHY_STANDARD_80211ax_2_4GHZ, clientChannelWidth, 5, 55, 0, 60, 160 * channelRateFactor));
273 
274  for (std::vector<StandardInfo>::size_type i = 0; i != serverStandards.size (); i++)
275  {
276  if (standard == serverStandards[i].m_name)
277  {
278  serverSelectedStandard = serverStandards[i];
279  }
280  }
281  for (std::vector<StandardInfo>::size_type i = 0; i != clientStandards.size (); i++)
282  {
283  if (standard == clientStandards[i].m_name)
284  {
285  clientSelectedStandard = clientStandards[i];
286  }
287  }
288 
289  NS_ABORT_MSG_IF (serverSelectedStandard.m_name == "none", "Standard " << standard << " not found");
290  NS_ABORT_MSG_IF (clientSelectedStandard.m_name == "none", "Standard " << standard << " not found");
291  std::cout << "Testing " << serverSelectedStandard.m_name << " with " << wifiManager << " ..." << std::endl;
292  NS_ABORT_MSG_IF (clientSelectedStandard.m_snrLow >= clientSelectedStandard.m_snrHigh, "SNR values in wrong order");
293  steps = static_cast<uint32_t> (std::abs (static_cast<double> (clientSelectedStandard.m_snrHigh - clientSelectedStandard.m_snrLow ) / stepSize) + 1);
294  NS_LOG_DEBUG ("Using " << steps << " steps for SNR range " << clientSelectedStandard.m_snrLow << ":" << clientSelectedStandard.m_snrHigh);
295  Ptr<Node> clientNode = CreateObject<Node> ();
296  Ptr<Node> serverNode = CreateObject<Node> ();
297 
298  std::string plotName = "wifi-manager-example-";
299  std::string dataName = "wifi-manager-example-";
300  plotName += wifiManager;
301  dataName += wifiManager;
302  plotName += "-";
303  dataName += "-";
304  plotName += standard;
305  dataName += standard;
306  if (standard == "802.11n-5GHz"
307  || standard == "802.11n-2.4GHz"
308  || standard == "802.11ac"
309  || standard == "802.11ax-5GHz"
310  || standard == "802.11ax-2.4GHz")
311  {
312  plotName += "-server_";
313  dataName += "-server_";
314  std::ostringstream oss;
315  oss << serverChannelWidth << "MHz_" << serverShortGuardInterval << "ns_" << serverNss << "SS";
316  plotName += oss.str ();
317  dataName += oss.str ();
318  plotName += "-client_";
319  dataName += "-client_";
320  oss.str ("");
321  oss << clientChannelWidth << "MHz_" << clientShortGuardInterval << "ns_" << clientNss << "SS";
322  plotName += oss.str ();
323  dataName += oss.str ();
324  }
325  plotName += ".eps";
326  dataName += ".plt";
327  std::ofstream outfile (dataName.c_str ());
328  Gnuplot gnuplot = Gnuplot (plotName);
329 
330  Config::SetDefault ("ns3::WifiRemoteStationManager::MaxSlrc", UintegerValue (maxSlrc));
331  Config::SetDefault ("ns3::WifiRemoteStationManager::MaxSsrc", UintegerValue (maxSsrc));
332  Config::SetDefault ("ns3::MinstrelWifiManager::PrintStats", BooleanValue (true));
333  Config::SetDefault ("ns3::MinstrelWifiManager::PrintSamples", BooleanValue (true));
334  Config::SetDefault ("ns3::MinstrelHtWifiManager::PrintStats", BooleanValue (true));
335 
337  wifi.SetStandard (serverSelectedStandard.m_standard);
339 
340  Ptr<YansWifiChannel> wifiChannel = CreateObject<YansWifiChannel> ();
341  Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
342  wifiChannel->SetPropagationDelayModel (delayModel);
343  Ptr<FixedRssLossModel> rssLossModel = CreateObject<FixedRssLossModel> ();
344  wifiChannel->SetPropagationLossModel (rssLossModel);
345  wifiPhy.SetChannel (wifiChannel);
346 
347  wifi.SetRemoteStationManager ("ns3::" + wifiManager + "WifiManager", "RtsCtsThreshold", UintegerValue (rtsThreshold));
348 
349  NetDeviceContainer serverDevice;
350  NetDeviceContainer clientDevice;
351 
352  WifiMacHelper wifiMac;
353  if (infrastructure)
354  {
355  Ssid ssid = Ssid ("ns-3-ssid");
356  wifiMac.SetType ("ns3::StaWifiMac",
357  "Ssid", SsidValue (ssid));
358  serverDevice = wifi.Install (wifiPhy, wifiMac, serverNode);
359  wifiMac.SetType ("ns3::ApWifiMac",
360  "Ssid", SsidValue (ssid));
361  clientDevice = wifi.Install (wifiPhy, wifiMac, clientNode);
362  }
363  else
364  {
365  wifiMac.SetType ("ns3::AdhocWifiMac");
366  serverDevice = wifi.Install (wifiPhy, wifiMac, serverNode);
367  clientDevice = wifi.Install (wifiPhy, wifiMac, clientNode);
368  }
369 
372  wifi.AssignStreams (serverDevice, 100);
373  wifi.AssignStreams (clientDevice, 100);
374 
375  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
376 
377  Config::ConnectWithoutContext ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$ns3::" + wifiManager + "WifiManager/Rate", MakeCallback (&RateChange));
378 
379  // Configure the mobility.
381  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
382  //Initial position of AP and STA
383  positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
384  NS_LOG_INFO ("Setting initial AP position to " << Vector (ap1_x, ap1_y, 0.0));
385  positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
386  NS_LOG_INFO ("Setting initial STA position to " << Vector (sta1_x, sta1_y, 0.0));
387  mobility.SetPositionAllocator (positionAlloc);
388  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
389  mobility.Install (clientNode);
390  mobility.Install (serverNode);
391 
392  Gnuplot2dDataset rateDataset (clientSelectedStandard.m_name + std::string ("-rate selected"));
393  Gnuplot2dDataset actualDataset (clientSelectedStandard.m_name + std::string ("-observed"));
394  struct Step step;
395  step.stepSize = stepSize;
396  step.stepTime = stepTime;
397 
398  // Perform post-install configuration from defaults for channel width,
399  // guard interval, and nss, if necessary
400  // Obtain pointer to the WifiPhy
401  Ptr<NetDevice> ndClient = clientDevice.Get (0);
402  Ptr<NetDevice> ndServer = serverDevice.Get (0);
403  Ptr<WifiNetDevice> wndClient = ndClient->GetObject<WifiNetDevice> ();
404  Ptr<WifiNetDevice> wndServer = ndServer->GetObject<WifiNetDevice> ();
405  Ptr<WifiPhy> wifiPhyPtrClient = wndClient->GetPhy ();
406  Ptr<WifiPhy> wifiPhyPtrServer = wndServer->GetPhy ();
407  uint8_t t_clientNss = static_cast<uint8_t> (clientNss);
408  uint8_t t_serverNss = static_cast<uint8_t> (serverNss);
409  wifiPhyPtrClient->SetNumberOfAntennas (t_clientNss);
410  wifiPhyPtrClient->SetMaxSupportedTxSpatialStreams (t_clientNss);
411  wifiPhyPtrClient->SetMaxSupportedRxSpatialStreams (t_clientNss);
412  wifiPhyPtrServer->SetNumberOfAntennas (t_serverNss);
413  wifiPhyPtrServer->SetMaxSupportedTxSpatialStreams (t_serverNss);
414  wifiPhyPtrServer->SetMaxSupportedRxSpatialStreams (t_serverNss);
415  // Only set the channel width and guard interval for HT and VHT modes
416  if (serverSelectedStandard.m_name == "802.11n-5GHz"
417  || serverSelectedStandard.m_name == "802.11n-2.4GHz"
418  || serverSelectedStandard.m_name == "802.11ac")
419  {
420  wifiPhyPtrServer->SetChannelWidth (serverSelectedStandard.m_width);
421  wifiPhyPtrClient->SetChannelWidth (clientSelectedStandard.m_width);
422  Ptr<HtConfiguration> clientHtConfiguration = wndClient->GetHtConfiguration ();
423  clientHtConfiguration->SetShortGuardIntervalSupported (clientShortGuardInterval == 400);
424  Ptr<HtConfiguration> serverHtConfiguration = wndServer->GetHtConfiguration ();
425  serverHtConfiguration->SetShortGuardIntervalSupported (serverShortGuardInterval == 400);
426  }
427  else if (serverSelectedStandard.m_name == "802.11ax-5GHz"
428  || serverSelectedStandard.m_name == "802.11ax-2.4GHz")
429  {
430  wifiPhyPtrServer->SetChannelWidth (serverSelectedStandard.m_width);
431  wifiPhyPtrClient->SetChannelWidth (clientSelectedStandard.m_width);
432  wndServer->GetHeConfiguration ()->SetGuardInterval (NanoSeconds (clientShortGuardInterval));
433  wndClient->GetHeConfiguration ()->SetGuardInterval (NanoSeconds (clientShortGuardInterval));
434  }
435  NS_LOG_DEBUG ("Channel width " << wifiPhyPtrClient->GetChannelWidth () << " noiseDbm " << noiseDbm);
436  NS_LOG_DEBUG ("NSS " << wifiPhyPtrClient->GetMaxSupportedTxSpatialStreams ());
437 
438  // Configure signal and noise, and schedule first iteration
439  noiseDbm += 10 * log10 (clientSelectedStandard.m_width * 1000000);
440  double rssCurrent = (clientSelectedStandard.m_snrHigh + noiseDbm);
441  rssLossModel->SetRss (rssCurrent);
442  NS_LOG_INFO ("Setting initial Rss to " << rssCurrent);
443  //Move the STA by stepsSize meters every stepTime seconds
444  Simulator::Schedule (Seconds (0.5 + stepTime), &ChangeSignalAndReportRate, rssLossModel, step, rssCurrent, rateDataset, actualDataset);
445 
446  PacketSocketHelper packetSocketHelper;
447  packetSocketHelper.Install (serverNode);
448  packetSocketHelper.Install (clientNode);
449 
450  PacketSocketAddress socketAddr;
451  socketAddr.SetSingleDevice (serverDevice.Get (0)->GetIfIndex ());
452  if (broadcast)
453  {
454  socketAddr.SetPhysicalAddress (serverDevice.Get (0)->GetBroadcast ());
455  }
456  else
457  {
458  socketAddr.SetPhysicalAddress (serverDevice.Get (0)->GetAddress ());
459  }
460  // Arbitrary protocol type.
461  // Note: PacketSocket doesn't have any L4 multiplexing or demultiplexing
462  // The only mux/demux is based on the protocol field
463  socketAddr.SetProtocol (1);
464 
465  Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
466  client->SetRemote (socketAddr);
467  client->SetStartTime (Seconds (0.5)); // allow simulation warmup
468  client->SetAttribute ("MaxPackets", UintegerValue (0)); // unlimited
469  client->SetAttribute ("PacketSize", UintegerValue (packetSize));
470 
471  // Set a maximum rate 10% above the yMax specified for the selected standard
472  double rate = clientSelectedStandard.m_yMax * 1e6 * 1.10;
473  double clientInterval = static_cast<double> (packetSize) * 8 / rate;
474  NS_LOG_DEBUG ("Setting interval to " << clientInterval << " sec for rate of " << rate << " bits/sec");
475 
476  client->SetAttribute ("Interval", TimeValue (Seconds (clientInterval)));
477  clientNode->AddApplication (client);
478 
479  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
480  server->SetLocal (socketAddr);
482  serverNode->AddApplication (server);
483 
484  Simulator::Stop (Seconds ((steps + 1) * stepTime));
485  Simulator::Run ();
487 
488  gnuplot.AddDataset (rateDataset);
489  gnuplot.AddDataset (actualDataset);
490 
491  std::ostringstream xMinStr, xMaxStr, yMaxStr;
492  std::string xRangeStr ("set xrange [");
493  xMinStr << clientSelectedStandard.m_xMin;
494  xRangeStr.append (xMinStr.str ());
495  xRangeStr.append (":");
496  xMaxStr << clientSelectedStandard.m_xMax;
497  xRangeStr.append (xMaxStr.str ());
498  xRangeStr.append ("]");
499  std::string yRangeStr ("set yrange [0:");
500  yMaxStr << clientSelectedStandard.m_yMax;
501  yRangeStr.append (yMaxStr.str ());
502  yRangeStr.append ("]");
503 
504  std::string title ("Results for ");
505  title.append (standard);
506  title.append (" with ");
507  title.append (wifiManager);
508  title.append ("\\n");
509  if (standard == "802.11n-5GHz"
510  || standard == "802.11n-2.4GHz"
511  || standard == "802.11ac"
512  || standard == "802.11n-5GHz"
513  || standard == "802.11ax-2.4GHz")
514  {
515  std::ostringstream serverGiStrStr;
516  std::ostringstream serverWidthStrStr;
517  std::ostringstream serverNssStrStr;
518  title.append ("server: width=");
519  serverWidthStrStr << serverSelectedStandard.m_width;
520  title.append (serverWidthStrStr.str ());
521  title.append ("MHz");
522  title.append (" GI=");
523  serverGiStrStr << serverShortGuardInterval;
524  title.append (serverGiStrStr.str ());
525  title.append ("ns");
526  title.append (" nss=");
527  serverNssStrStr << serverNss;
528  title.append (serverNssStrStr.str ());
529  title.append ("\\n");
530  std::ostringstream clientGiStrStr;
531  std::ostringstream clientWidthStrStr;
532  std::ostringstream clientNssStrStr;
533  title.append ("client: width=");
534  clientWidthStrStr << clientSelectedStandard.m_width;
535  title.append (clientWidthStrStr.str ());
536  title.append ("MHz");
537  title.append (" GI=");
538  clientGiStrStr << clientShortGuardInterval;
539  title.append (clientGiStrStr.str ());
540  title.append ("ns");
541  title.append (" nss=");
542  clientNssStrStr << clientNss;
543  title.append (clientNssStrStr.str ());
544  }
545  gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
546  gnuplot.SetLegend ("SNR (dB)", "Rate (Mb/s)");
547  gnuplot.SetTitle (title);
548  gnuplot.SetExtra (xRangeStr);
549  gnuplot.AppendExtra (yRangeStr);
550  gnuplot.AppendExtra ("set key top left");
551  gnuplot.GenerateOutput (outfile);
552  outfile.close ();
553 
554  return 0;
555 }
556 
ERP-OFDM PHY (Clause 19, Section 19.5)
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:157
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
AttributeValue implementation for Boolean.
Definition: boolean.h:36
Ptr< HeConfiguration > GetHeConfiguration(void) const
void SetLocal(PacketSocketAddress addr)
set the local address and protocol to be used
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
HT PHY for the 5 GHz band (clause 20)
Class to represent a 2D points plot.
Definition: gnuplot.h:117
double m_yMax
Y maximum.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Make it easy to create and manage PHY objects for the yans model.
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:805
static const uint32_t packetSize
void SetShortGuardIntervalSupported(bool enable)
Enable or disable SGI support.
an address for a packet socket
static void Run(void)
Run the simulation.
Definition: simulator.cc:170
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
HE PHY for the 2.4 GHz band (clause 26)
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
double m_snrLow
lowest SNR
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
cmd
Definition: second.py:35
const double NOISE_DBM_Hz
HT PHY for the 2.4 GHz band (clause 20)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
double stepSize
step size in dBm
helps to create WifiNetDevice objects
Definition: wifi-helper.h:299
void ChangeSignalAndReportRate(Ptr< FixedRssLossModel > rssModel, struct Step step, double rss, Gnuplot2dDataset &rateDataset, Gnuplot2dDataset &actualDataset)
Give ns3::PacketSocket powers to ns3::Node.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
static void SetRun(uint64_t run)
Set the run number of simulation.
a polymophic address class
Definition: address.h:90
mobility
Definition: third.py:108
void SetChannel(Ptr< YansWifiChannel > channel)
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
HE PHY for the 5 GHz band (clause 26)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:371
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1124
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1086
Hold an unsigned integer type.
Definition: uinteger.h:44
Step structure.
ssid
Definition: third.py:100
holds a vector of ns3::NetDevice pointers
std::string m_name
name
Hold together all Wifi-related objects.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:860
void Add(double x, double y)
Definition: gnuplot.cc:359
void PacketRx(Ptr< const Packet > pkt, const Address &addr)
Parse command-line arguments.
Definition: command-line.h:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:134
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
double m_snrHigh
highest SNR
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
double noiseDbm
Ptr< WifiPhy > GetPhy(void) const
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPhysicalAddress(const Address address)
Set the destination address.
virtual void SetChannelWidth(uint16_t channelwidth)
Definition: wifi-phy.cc:1343
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void SetMaxSupportedRxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1396
create MAC layers for a ns3::WifiNetDevice.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
StandardInfo(std::string name, WifiPhyStandard standard, uint16_t width, double snrLow, double snrHigh, double xMin, double xMax, double yMax)
Constructor.
double m_xMax
X maximum.
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
static void SetSeed(uint32_t seed)
Set the seed.
StandardInfo structure.
wifi
Definition: third.py:96
Helper class used to assign positions and mobility models to nodes.
uint16_t m_width
channel width
void SetMaxSupportedTxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1377
double m_xMin
X minimum.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
void SetRemote(PacketSocketAddress addr)
set the remote address and protocol to be used
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:178
WifiPhyStandard m_standard
standard
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
double g_intervalBytes
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
AttributeValue implementation for Ssid.
Definition: ssid.h:110
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:810
double stepTime
step size in seconds
void SetProtocol(uint16_t protocol)
Set the protocol.
void Add(Vector v)
Add a position to the list of positions.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
void SetNumberOfAntennas(uint8_t antennas)
Definition: wifi-phy.cc:1363
second
Definition: nstime.h:114
void RateChange(uint64_t oldVal, uint64_t newVal)
uint64_t g_intervalRate
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
Ptr< HtConfiguration > GetHtConfiguration(void) const
void SetStartTime(Time start)
Specify application start time.
Definition: application.cc:69