A Discrete-Event Network Simulator
API
wifi-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  */
22 
23 #include "wifi-helper.h"
24 #include "ns3/wifi-net-device.h"
25 #include "ns3/wifi-mac.h"
26 #include "ns3/regular-wifi-mac.h"
27 #include "ns3/dca-txop.h"
28 #include "ns3/edca-txop-n.h"
29 #include "ns3/minstrel-wifi-manager.h"
30 #include "ns3/ap-wifi-mac.h"
31 #include "ns3/wifi-phy.h"
32 #include "ns3/ampdu-subframe-header.h"
33 #include "ns3/wifi-remote-station-manager.h"
34 #include "ns3/wifi-channel.h"
35 #include "ns3/yans-wifi-channel.h"
36 #include "ns3/propagation-delay-model.h"
37 #include "ns3/propagation-loss-model.h"
38 #include "ns3/mobility-model.h"
39 #include "ns3/log.h"
40 #include "ns3/pointer.h"
41 #include "ns3/radiotap-header.h"
42 #include "ns3/pcap-file-wrapper.h"
43 #include "ns3/abort.h"
44 #include "ns3/config.h"
45 #include "ns3/simulator.h"
46 #include "ns3/names.h"
47 
48 namespace ns3 {
49 
50 NS_LOG_COMPONENT_DEFINE ("WifiHelper");
51 
52 static void
55  std::string context,
57  WifiMode mode,
58  WifiPreamble preamble,
59  uint8_t txLevel)
60 {
61  NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
62  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
63 }
64 
65 static void
69  WifiMode mode,
70  WifiPreamble preamble,
71  uint8_t txLevel)
72 {
73  NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
74  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
75 }
76 
77 static void
80  std::string context,
82  double snr,
83  WifiMode mode,
84  enum WifiPreamble preamble)
85 {
86  NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
87  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
88 }
89 
90 static void
94  double snr,
95  WifiMode mode,
96  enum WifiPreamble preamble)
97 {
98  NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
99  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
100 }
101 
103  : m_pcapDlt (PcapHelper::DLT_IEEE802_11)
104 {
105 }
106 
108 {
109 }
110 
111 void
112 WifiPhyHelper::Set (std::string name, const AttributeValue &v)
113 {
114  m_phy.Set (name, v);
115 }
116 
117 void
119  std::string n0, const AttributeValue &v0,
120  std::string n1, const AttributeValue &v1,
121  std::string n2, const AttributeValue &v2,
122  std::string n3, const AttributeValue &v3,
123  std::string n4, const AttributeValue &v4,
124  std::string n5, const AttributeValue &v5,
125  std::string n6, const AttributeValue &v6,
126  std::string n7, const AttributeValue &v7)
127 {
130  m_errorRateModel.Set (n0, v0);
131  m_errorRateModel.Set (n1, v1);
132  m_errorRateModel.Set (n2, v2);
133  m_errorRateModel.Set (n3, v3);
134  m_errorRateModel.Set (n4, v4);
135  m_errorRateModel.Set (n5, v5);
136  m_errorRateModel.Set (n6, v6);
137  m_errorRateModel.Set (n7, v7);
138 }
139 
140 void
143  Ptr<const Packet> packet,
144  uint16_t channelFreqMhz,
145  uint16_t channelNumber,
146  uint32_t rate,
147  WifiPreamble preamble,
148  WifiTxVector txVector,
149  struct mpduInfo aMpdu)
150 {
151  uint32_t dlt = file->GetDataLinkType ();
152 
153  switch (dlt)
154  {
156  file->Write (Simulator::Now (), packet);
157  return;
159  {
160  NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
161  return;
162  }
164  {
165  Ptr<Packet> p = packet->Copy ();
166  RadiotapHeader header;
167  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
168  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
169 
170  //Our capture includes the FCS, so we set the flag to say so.
172 
173  if (preamble == WIFI_PREAMBLE_SHORT)
174  {
176  }
177 
178  if (txVector.IsShortGuardInterval ())
179  {
181  }
182 
183  header.SetFrameFlags (frameFlags);
184  header.SetRate (rate);
185 
186  uint16_t channelFlags = 0;
187  switch (rate)
188  {
189  case 2: //1Mbps
190  case 4: //2Mbps
191  case 10: //5Mbps
192  case 22: //11Mbps
193  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
194  break;
195 
196  default:
197  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
198  break;
199  }
200 
201  if (channelFreqMhz < 2500)
202  {
204  }
205  else
206  {
208  }
209 
210  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
211 
212  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
213  {
214  uint8_t mcsRate = 0;
215  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
216  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
217 
219  mcsRate = rate - 128;
220 
222  if (txVector.GetChannelWidth () == 40)
223  {
225  }
226 
228  if (txVector.IsShortGuardInterval ())
229  {
231  }
232 
234  if (preamble == WIFI_PREAMBLE_HT_GF)
235  {
237  }
238 
239  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
240  if (txVector.GetNess () & 0x01) //bit 1
241  {
243  }
244  if (txVector.GetNess () & 0x02) //bit 2
245  {
247  }
248 
249  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
250 
251  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
252  if (txVector.IsStbc ())
253  {
255  }
256 
257  header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
258  }
259 
260  if (txVector.IsAggregation ())
261  {
262  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
263  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
264  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
266  uint32_t extractedLength;
267  p->RemoveHeader (hdr);
268  extractedLength = hdr.GetLength ();
269  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
270  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
271  {
272  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
273  }
274  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
275  }
276 
277  if (preamble == WIFI_PREAMBLE_VHT)
278  {
279  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
280  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
281  uint8_t vhtBandwidth = 0;
282  uint8_t vhtMcsNss[4] = {0,0,0,0};
283  uint8_t vhtCoding = 0;
284  uint8_t vhtGroupId = 0;
285  uint16_t vhtPartialAid = 0;
286 
287  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
288  if (txVector.IsStbc ())
289  {
290  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
291  }
292 
294  if (txVector.IsShortGuardInterval ())
295  {
297  }
298 
299  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
300 
302  //not all bandwidth values are currently supported
303  if (txVector.GetChannelWidth () == 40)
304  {
305  vhtBandwidth = 1;
306  }
307  else if (txVector.GetChannelWidth () == 80)
308  {
309  vhtBandwidth = 4;
310  }
311  else if (txVector.GetChannelWidth () == 160)
312  {
313  vhtBandwidth = 11;
314  }
315 
316  //only SU PPDUs are currently supported
317  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
318  vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
319 
320  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
321  }
322 
323  p->AddHeader (header);
324  file->Write (Simulator::Now (), p);
325  return;
326  }
327  default:
328  NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
329  }
330 }
331 
332 void
335  Ptr<const Packet> packet,
336  uint16_t channelFreqMhz,
337  uint16_t channelNumber,
338  uint32_t rate,
339  WifiPreamble preamble,
340  WifiTxVector txVector,
341  struct mpduInfo aMpdu,
342  struct signalNoiseDbm signalNoise)
343 {
344  uint32_t dlt = file->GetDataLinkType ();
345 
346  switch (dlt)
347  {
349  file->Write (Simulator::Now (), packet);
350  return;
352  {
353  NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
354  return;
355  }
357  {
358  Ptr<Packet> p = packet->Copy ();
359  RadiotapHeader header;
360  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
361  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
362 
363  //Our capture includes the FCS, so we set the flag to say so.
365 
366  if (preamble == WIFI_PREAMBLE_SHORT)
367  {
369  }
370 
371  if (txVector.IsShortGuardInterval ())
372  {
374  }
375 
376  header.SetFrameFlags (frameFlags);
377  header.SetRate (rate);
378 
379  uint16_t channelFlags = 0;
380  switch (rate)
381  {
382  case 2: //1Mbps
383  case 4: //2Mbps
384  case 10: //5Mbps
385  case 22: //11Mbps
386  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
387  break;
388 
389  default:
390  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
391  break;
392  }
393 
394  if (channelFreqMhz < 2500)
395  {
397  }
398  else
399  {
401  }
402 
403  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
404 
405  header.SetAntennaSignalPower (signalNoise.signal);
406  header.SetAntennaNoisePower (signalNoise.noise);
407 
408  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
409  {
410  uint8_t mcsRate = 0;
411  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
412  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
413 
415  mcsRate = rate - 128;
416 
418  if (txVector.GetChannelWidth () == 40)
419  {
421  }
422 
424  if (txVector.IsShortGuardInterval ())
425  {
427  }
428 
430  if (preamble == WIFI_PREAMBLE_HT_GF)
431  {
433  }
434 
435  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
436  if (txVector.GetNess () & 0x01) //bit 1
437  {
439  }
440  if (txVector.GetNess () & 0x02) //bit 2
441  {
443  }
444 
445  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
446 
447  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
448  if (txVector.IsStbc ())
449  {
451  }
452 
453  header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
454  }
455 
456  if (txVector.IsAggregation ())
457  {
458  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
460  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
461  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
463  uint32_t extractedLength;
464  p->RemoveHeader (hdr);
465  extractedLength = hdr.GetLength ();
466  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
467  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
468  {
469  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
470  }
471  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
472  }
473 
474  if (preamble == WIFI_PREAMBLE_VHT)
475  {
476  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
477  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
478  uint8_t vhtBandwidth = 0;
479  uint8_t vhtMcsNss[4] = {0,0,0,0};
480  uint8_t vhtCoding = 0;
481  uint8_t vhtGroupId = 0;
482  uint16_t vhtPartialAid = 0;
483 
484  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
485  if (txVector.IsStbc ())
486  {
487  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
488  }
489 
491  if (txVector.IsShortGuardInterval ())
492  {
494  }
495 
496  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
497 
499  //not all bandwidth values are currently supported
500  if (txVector.GetChannelWidth () == 40)
501  {
502  vhtBandwidth = 1;
503  }
504  else if (txVector.GetChannelWidth () == 80)
505  {
506  vhtBandwidth = 4;
507  }
508  else if (txVector.GetChannelWidth () == 160)
509  {
510  vhtBandwidth = 11;
511  }
512 
513  //only SU PPDUs are currently supported
514  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
515  vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
516 
517  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
518  }
519 
520  p->AddHeader (header);
521  file->Write (Simulator::Now (), p);
522  return;
523  }
524  default:
525  NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
526  }
527 }
528 
529 void
531 {
532  switch (dlt)
533  {
534  case DLT_IEEE802_11:
536  return;
537  case DLT_PRISM_HEADER:
539  return;
542  return;
543  default:
544  NS_ABORT_MSG ("WifiPhyHelper::SetPcapFormat(): Unexpected format");
545  }
546 }
547 
550 {
551  return m_pcapDlt;
552 }
553 
554 void
555 WifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
556 {
557  //All of the Pcap enable functions vector through here including the ones
558  //that are wandering through all of devices on perhaps all of the nodes in
559  //the system. We can only deal with devices of type WifiNetDevice.
560  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
561  if (device == 0)
562  {
563  NS_LOG_INFO ("WifiHelper::EnablePcapInternal(): Device " << &device << " not of type ns3::WifiNetDevice");
564  return;
565  }
566 
567  Ptr<WifiPhy> phy = device->GetPhy ();
568  NS_ABORT_MSG_IF (phy == 0, "WifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
569 
570  PcapHelper pcapHelper;
571 
572  std::string filename;
573  if (explicitFilename)
574  {
575  filename = prefix;
576  }
577  else
578  {
579  filename = pcapHelper.GetFilenameFromDevice (prefix, device);
580  }
581 
582  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
583 
586 }
587 
588 void
591  std::string prefix,
592  Ptr<NetDevice> nd,
593  bool explicitFilename)
594 {
595  //All of the ascii enable functions vector through here including the ones
596  //that are wandering through all of devices on perhaps all of the nodes in
597  //the system. We can only deal with devices of type WifiNetDevice.
598  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
599  if (device == 0)
600  {
601  NS_LOG_INFO ("WifiHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::WifiNetDevice");
602  return;
603  }
604 
605  //Our trace sinks are going to use packet printing, so we have to make sure
606  //that is turned on.
608 
609  uint32_t nodeid = nd->GetNode ()->GetId ();
610  uint32_t deviceid = nd->GetIfIndex ();
611  std::ostringstream oss;
612 
613  //If we are not provided an OutputStreamWrapper, we are expected to create
614  //one using the usual trace filename conventions and write our traces
615  //without a context since there will be one file per context and therefore
616  //the context would be redundant.
617  if (stream == 0)
618  {
619  //Set up an output stream object to deal with private ofstream copy
620  //constructor and lifetime issues. Let the helper decide the actual
621  //name of the file given the prefix.
622  AsciiTraceHelper asciiTraceHelper;
623 
624  std::string filename;
625  if (explicitFilename)
626  {
627  filename = prefix;
628  }
629  else
630  {
631  filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
632  }
633 
634  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
635  //We could go poking through the phy and the state looking for the
636  //correct trace source, but we can let Config deal with that with
637  //some search cost. Since this is presumably happening at topology
638  //creation time, it doesn't seem much of a price to pay.
639  oss.str ("");
640  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
642 
643  oss.str ("");
644  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
646 
647  return;
648  }
649 
650  //If we are provided an OutputStreamWrapper, we are expected to use it, and
651  //to provide a context. We are free to come up with our own context if we
652  //want, and use the AsciiTraceHelper Hook*WithContext functions, but for
653  //compatibility and simplicity, we just use Config::Connect and let it deal
654  //with coming up with a context.
655  oss.str ("");
656  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
658 
659  oss.str ("");
660  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
662 }
663 
665 {
666 }
667 
669  : m_standard (WIFI_PHY_STANDARD_80211a)
670 {
671  SetRemoteStationManager ("ns3::ArfWifiManager");
672 }
673 
676 {
677  WifiHelper helper;
678  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
679  return helper;
680 }
681 
682 void
684  std::string n0, const AttributeValue &v0,
685  std::string n1, const AttributeValue &v1,
686  std::string n2, const AttributeValue &v2,
687  std::string n3, const AttributeValue &v3,
688  std::string n4, const AttributeValue &v4,
689  std::string n5, const AttributeValue &v5,
690  std::string n6, const AttributeValue &v6,
691  std::string n7, const AttributeValue &v7)
692 {
695  m_stationManager.Set (n0, v0);
696  m_stationManager.Set (n1, v1);
697  m_stationManager.Set (n2, v2);
698  m_stationManager.Set (n3, v3);
699  m_stationManager.Set (n4, v4);
700  m_stationManager.Set (n5, v5);
701  m_stationManager.Set (n6, v6);
702  m_stationManager.Set (n7, v7);
703 }
704 
705 void
707 {
708  m_standard = standard;
709 }
710 
713  const WifiMacHelper &macHelper, NodeContainer c) const
714 {
716  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
717  {
718  Ptr<Node> node = *i;
719  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
721  Ptr<WifiMac> mac = macHelper.Create ();
722  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
723  mac->SetAddress (Mac48Address::Allocate ());
726  device->SetMac (mac);
727  device->SetPhy (phy);
728  device->SetRemoteStationManager (manager);
729  node->AddDevice (device);
730  devices.Add (device);
731  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
732  }
733  return devices;
734 }
735 
738  const WifiMacHelper &mac, Ptr<Node> node) const
739 {
740  return Install (phy, mac, NodeContainer (node));
741 }
742 
745  const WifiMacHelper &mac, std::string nodeName) const
746 {
747  Ptr<Node> node = Names::Find<Node> (nodeName);
748  return Install (phy, mac, NodeContainer (node));
749 }
750 
751 void
753 {
754  LogComponentEnable ("Aarfcd", LOG_LEVEL_ALL);
755  LogComponentEnable ("AdhocWifiMac", LOG_LEVEL_ALL);
756  LogComponentEnable ("AmrrWifiRemoteStation", LOG_LEVEL_ALL);
757  LogComponentEnable ("ApWifiMac", LOG_LEVEL_ALL);
758  LogComponentEnable ("ArfWifiManager", LOG_LEVEL_ALL);
760  LogComponentEnable ("DcaTxop", LOG_LEVEL_ALL);
761  LogComponentEnable ("DcfManager", LOG_LEVEL_ALL);
762  LogComponentEnable ("DsssErrorRateModel", LOG_LEVEL_ALL);
763  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_ALL);
764  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
766  LogComponentEnable ("MacLow", LOG_LEVEL_ALL);
767  LogComponentEnable ("MacRxMiddle", LOG_LEVEL_ALL);
768  LogComponentEnable ("MsduAggregator", LOG_LEVEL_ALL);
769  LogComponentEnable ("MsduStandardAggregator", LOG_LEVEL_ALL);
770  LogComponentEnable ("NistErrorRateModel", LOG_LEVEL_ALL);
771  LogComponentEnable ("OnoeWifiRemoteStation", LOG_LEVEL_ALL);
772  LogComponentEnable ("PropagationLossModel", LOG_LEVEL_ALL);
773  LogComponentEnable ("RegularWifiMac", LOG_LEVEL_ALL);
774  LogComponentEnable ("RraaWifiManager", LOG_LEVEL_ALL);
775  LogComponentEnable ("StaWifiMac", LOG_LEVEL_ALL);
776  LogComponentEnable ("SupportedRates", LOG_LEVEL_ALL);
777  LogComponentEnable ("WifiChannel", LOG_LEVEL_ALL);
778  LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL);
779  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
780  LogComponentEnable ("WifiRemoteStationManager", LOG_LEVEL_ALL);
781  LogComponentEnable ("YansErrorRateModel", LOG_LEVEL_ALL);
782  LogComponentEnable ("YansWifiChannel", LOG_LEVEL_ALL);
783  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
784 }
785 
786 int64_t
788 {
789  int64_t currentStream = stream;
790  Ptr<NetDevice> netDevice;
791  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
792  {
793  netDevice = (*i);
794  Ptr<WifiNetDevice> wifi = DynamicCast<WifiNetDevice> (netDevice);
795  if (wifi)
796  {
797  //Handle any random numbers in the PHY objects.
798  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
799 
800  //Handle any random numbers in the station managers.
801  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
802  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
803  if (minstrel)
804  {
805  currentStream += minstrel->AssignStreams (currentStream);
806  }
807 
808  //Handle any random numbers in the MAC objects.
809  Ptr<WifiMac> mac = wifi->GetMac ();
810  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
811  if (rmac)
812  {
813  PointerValue ptr;
814  rmac->GetAttribute ("DcaTxop", ptr);
815  Ptr<DcaTxop> dcaTxop = ptr.Get<DcaTxop> ();
816  currentStream += dcaTxop->AssignStreams (currentStream);
817 
818  rmac->GetAttribute ("VO_EdcaTxopN", ptr);
819  Ptr<EdcaTxopN> vo_edcaTxopN = ptr.Get<EdcaTxopN> ();
820  currentStream += vo_edcaTxopN->AssignStreams (currentStream);
821 
822  rmac->GetAttribute ("VI_EdcaTxopN", ptr);
823  Ptr<EdcaTxopN> vi_edcaTxopN = ptr.Get<EdcaTxopN> ();
824  currentStream += vi_edcaTxopN->AssignStreams (currentStream);
825 
826  rmac->GetAttribute ("BE_EdcaTxopN", ptr);
827  Ptr<EdcaTxopN> be_edcaTxopN = ptr.Get<EdcaTxopN> ();
828  currentStream += be_edcaTxopN->AssignStreams (currentStream);
829 
830  rmac->GetAttribute ("BK_EdcaTxopN", ptr);
831  Ptr<EdcaTxopN> bk_edcaTxopN = ptr.Get<EdcaTxopN> ();
832  currentStream += bk_edcaTxopN->AssignStreams (currentStream);
833 
834  //if an AP, handle any beacon jitter
835  Ptr<ApWifiMac> apmac = DynamicCast<ApWifiMac> (rmac);
836  if (apmac)
837  {
838  currentStream += apmac->AssignStreams (currentStream);
839  }
840  }
841  }
842  }
843  return (currentStream - stream);
844 }
845 
846 } //namespace ns3
virtual ~WifiPhyHelper()
Definition: wifi-helper.cc:107
uint16_t GetLength(void) const
Return the length field.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
Frame used short guard interval (HT)
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:112
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
Ptr< T > Get(void) const
Definition: pointer.h:194
Manage ASCII trace files for device models.
Definition: trace-helper.h:161
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
tuple devices
Definition: first.py:32
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Beamformed known/applicable (this flag should be set to zero for MU PPDUs).
bool IsAggregation(void) const
Checks whether the PSDU contains A-MPDU.
static void AsciiPhyReceiveSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p, double snr, WifiMode mode, enum WifiPreamble preamble)
Definition: wave-helper.cc:78
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void SetRemoteStationManager(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())
Definition: wifi-helper.cc:683
Radiotap header implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
virtual ~WifiHelper()
Definition: wifi-helper.cc:664
Hold a value for an Attribute.
Definition: attribute.h:68
enum mpduType type
Definition: wifi-phy.h:74
Manage pcap files for device models.
Definition: trace-helper.h:38
create PHY objects
Definition: wifi-helper.h:48
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1686
PcapHelper::DataLinkType m_pcapDlt
Definition: wifi-helper.h:220
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
bool IsShortGuardInterval(void) const
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
static void AsciiPhyReceiveSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, double snr, WifiMode mode, enum WifiPreamble preamble)
Definition: wave-helper.cc:65
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits. ...
void SetAntennaNoisePower(double noise)
Set the RF noise power at the antenna as a decibel difference from an arbitrary, fixed reference...
ObjectFactory m_errorRateModel
Definition: wifi-helper.h:185
std::string GetFilenameFromDevice(std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true)
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated...
Frame sent/received with short preamble.
void SetTsft(uint64_t tsft)
Set the Time Synchronization Function Timer (TSFT) value.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, DataLinkType dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
Definition: trace-helper.cc:49
helps to create WifiNetDevice objects
Definition: wifi-helper.h:231
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
WifiHelper()
Create a Wifi helper in an empty state: all its parameters must be set before calling ns3::WifiHelper...
Definition: wifi-helper.cc:668
Delimiter CRC value known: the delimiter CRC value field is valid.
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:530
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:712
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)
Enable ascii trace output on the indicated net device.
Definition: wifi-helper.cc:589
DataLinkType
This enumeration holds the data link types that will be written to the pcap file. ...
Definition: trace-helper.h:50
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:228
Keep track of the current position and velocity of an object.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
This queue contains packets for a particular access class.
Definition: edca-txop-n.h:86
static void PcapSniffTxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu)
Definition: wifi-helper.cc:141
std::string GetFilenameFromDevice(std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true)
Let the pcap helper figure out a reasonable filename to use for a pcap file associated with a device...
Definition: trace-helper.cc:80
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
tuple phy
Definition: third.py:86
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:535
uint32_t mpduRefNumber
Definition: wifi-phy.h:75
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
This frame is the last subframe.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
void SetChannelFrequencyAndFlags(uint16_t frequency, uint16_t flags)
Set the transmit/receive channel frequency and flags.
holds a vector of ns3::NetDevice pointers
Ness - bit 0 (LSB) of Number of extension spatial streams.
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:706
uint8_t GetNess(void) const
uint32_t GetChannelWidth(void) const
uint8_t GetCrc(void) const
Return the CRC field.
Introspection did not find any typical Config paths.
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the Phy and Mac aspects ...
Definition: wifi-helper.cc:787
Hold together all Wifi-related objects.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:824
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
tuple mac
Definition: third.py:92
bool IsStbc(void) const
Check if STBC is used or not.
hold a list of per-remote-station state.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
Include Prism monitor mode information.
Definition: wifi-helper.h:116
void SetFrameFlags(uint8_t flags)
Set the frame flags of the transmitted or received frame.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
void SetRate(uint8_t rate)
Set the transmit/receive channel frequency in units of megahertz.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:299
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr.
Definition: pointer.h:36
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Ness data - bit 1 (MSB) of Number of extension spatial streams.
void SetMcsFields(uint8_t known, uint8_t flags, uint8_t mcs)
Set the MCS fields.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
ObjectFactory m_stationManager
Definition: wifi-helper.h:363
create MAC layers for a ns3::WifiNetDevice.
Ness known (Number of extension spatial streams)
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
void SetErrorRateModel(std::string name, 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())
Definition: wifi-helper.cc:118
virtual Ptr< WifiMac > Create(void) const
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)
Enable pcap output the indicated net device.
Definition: wifi-helper.cc:555
ObjectFactory m_phy
Definition: wifi-helper.h:184
virtual void ConfigureStandard(enum WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1026
Space-time block coding (1 if all spatial streams of all users have STBC, 0 otherwise).
void SetVhtFields(uint16_t known, uint8_t flags, uint8_t bandwidth, uint8_t mcs_nss[4], uint8_t coding, uint8_t group_id, uint16_t partial_aid)
Set the VHT fields.
Instantiate subclasses of ns3::Object.
Set if all spatial streams of all users have space-time block coding.
static void EnableLogComponents(void)
Helper to enable all WifiNetDevice log components with one statement.
Definition: wifi-helper.cc:752
uint8_t GetNss(void) const
virtual Ptr< WifiPhy > Create(Ptr< Node > node, Ptr< NetDevice > device) const =0
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:128
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
IEEE 802.11 Wireless LAN headers on packets.
Definition: wifi-helper.h:115
enum WifiPhyStandard m_standard
Definition: wifi-helper.h:364
Last subframe is known (should be set for all subframes in an A-MPDU)
Print everything.
Definition: log.h:112
tuple wifi
Definition: third.py:89
Default: 20 MHz, long guard interval, mixed HT format and BCC FEC type.
SupportedPcapDataLinkTypes
An enumeration of the pcap data link types (DLTs) which this helper supports.
Definition: wifi-helper.h:113
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
handle packet fragmentation and retransmissions.
Definition: dca-txop.h:67
void SetAmpduStatus(uint32_t referenceNumber, uint16_t flags, uint8_t crc)
Set the A-MPDU status fields.
static void PcapSniffRxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, struct signalNoiseDbm signalNoise)
Definition: wifi-helper.cc:333
Include Radiotap link layer information.
Definition: wifi-helper.h:117
bool GetEof(void) const
Return the EOF field.
PcapHelper::DataLinkType GetPcapDataLinkType(void) const
Get the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:549
static void AsciiPhyTransmitSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
Definition: wave-helper.cc:40
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
void SetAntennaSignalPower(double signal)
Set the RF signal power at the antenna as a decibel difference from an arbitrary, fixed reference...
The MPDU is the last aggregate in an A-MPDU.
Definition: wifi-phy.h:63
static NS_DEPRECATED WifiHelper Default(void)
Definition: wifi-helper.cc:675
static void AsciiPhyTransmitSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
Definition: wave-helper.cc:53