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/minstrel-wifi-manager.h"
26 #include "ns3/minstrel-ht-wifi-manager.h"
27 #include "ns3/ap-wifi-mac.h"
28 #include "ns3/ampdu-subframe-header.h"
29 #include "ns3/log.h"
30 #include "ns3/pointer.h"
31 #include "ns3/radiotap-header.h"
32 #include "ns3/config.h"
33 #include "ns3/names.h"
34 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("WifiHelper");
38 
48 static void
51  std::string context,
53  WifiMode mode,
54  WifiPreamble preamble,
55  uint8_t txLevel)
56 {
57  NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
58  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
59 }
60 
69 static void
73  WifiMode mode,
74  WifiPreamble preamble,
75  uint8_t txLevel)
76 {
77  NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
78  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
79 }
80 
90 static void
93  std::string context,
95  double snr,
96  WifiMode mode,
97  WifiPreamble preamble)
98 {
99  NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
100  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
101 }
102 
111 static void
115  double snr,
116  WifiMode mode,
117  WifiPreamble preamble)
118 {
119  NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
120  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
121 }
122 
124  : m_pcapDlt (PcapHelper::DLT_IEEE802_11)
125 {
126 }
127 
129 {
130 }
131 
132 void
133 WifiPhyHelper::Set (std::string name, const AttributeValue &v)
134 {
135  m_phy.Set (name, v);
136 }
137 
138 void
140  std::string n0, const AttributeValue &v0,
141  std::string n1, const AttributeValue &v1,
142  std::string n2, const AttributeValue &v2,
143  std::string n3, const AttributeValue &v3,
144  std::string n4, const AttributeValue &v4,
145  std::string n5, const AttributeValue &v5,
146  std::string n6, const AttributeValue &v6,
147  std::string n7, const AttributeValue &v7)
148 {
151  m_errorRateModel.Set (n0, v0);
152  m_errorRateModel.Set (n1, v1);
153  m_errorRateModel.Set (n2, v2);
154  m_errorRateModel.Set (n3, v3);
155  m_errorRateModel.Set (n4, v4);
156  m_errorRateModel.Set (n5, v5);
157  m_errorRateModel.Set (n6, v6);
158  m_errorRateModel.Set (n7, v7);
159 }
160 
161 void
164  Ptr<const Packet> packet,
165  uint16_t channelFreqMhz,
166  WifiTxVector txVector,
167  MpduInfo aMpdu)
168 {
169  uint32_t dlt = file->GetDataLinkType ();
170  WifiPreamble preamble = txVector.GetPreambleType ();
171 
172  switch (dlt)
173  {
175  file->Write (Simulator::Now (), packet);
176  return;
178  {
179  NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
180  return;
181  }
183  {
184  Ptr<Packet> p = packet->Copy ();
185  RadiotapHeader header;
186  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
187  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
188 
189  //Our capture includes the FCS, so we set the flag to say so.
191 
192  if (preamble == WIFI_PREAMBLE_SHORT)
193  {
195  }
196 
197  if (txVector.GetGuardInterval () == 400)
198  {
200  }
201 
202  header.SetFrameFlags (frameFlags);
203 
204  uint64_t rate = 0;
206  {
207  rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000;
208  header.SetRate (static_cast<uint8_t> (rate));
209  }
210 
211  uint16_t channelFlags = 0;
212  switch (rate)
213  {
214  case 2: //1Mbps
215  case 4: //2Mbps
216  case 10: //5Mbps
217  case 22: //11Mbps
218  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
219  break;
220  default:
221  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
222  break;
223  }
224 
225  if (channelFreqMhz < 2500)
226  {
228  }
229  else
230  {
232  }
233 
234  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
235 
236  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT)
237  {
238  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
239  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
240 
242 
244  if (txVector.GetChannelWidth () == 40)
245  {
247  }
248 
250  if (txVector.GetGuardInterval () == 400)
251  {
253  }
254 
256  if (preamble == WIFI_PREAMBLE_HT_GF)
257  {
259  }
260 
261  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
262  if (txVector.GetNess () & 0x01) //bit 1
263  {
265  }
266  if (txVector.GetNess () & 0x02) //bit 2
267  {
269  }
270 
271  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
272 
273  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
274  if (txVector.IsStbc ())
275  {
277  }
278 
279  header.SetMcsFields (mcsKnown, mcsFlags, txVector.GetMode ().GetMcsValue ());
280  }
281 
282  if (txVector.IsAggregation ())
283  {
284  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
285  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
286  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
288  uint32_t extractedLength;
289  p->RemoveHeader (hdr);
290  extractedLength = hdr.GetLength ();
291  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
292  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
293  {
294  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
295  }
296  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
297  }
298 
299  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_VHT)
300  {
301  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
302  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
303  uint8_t vhtBandwidth = 0;
304  uint8_t vhtMcsNss[4] = {0,0,0,0};
305  uint8_t vhtCoding = 0;
306  uint8_t vhtGroupId = 0;
307  uint16_t vhtPartialAid = 0;
308 
309  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
310  if (txVector.IsStbc ())
311  {
312  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
313  }
314 
316  if (txVector.GetGuardInterval () == 400)
317  {
319  }
320 
321  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
322 
324  //not all bandwidth values are currently supported
325  if (txVector.GetChannelWidth () == 40)
326  {
327  vhtBandwidth = 1;
328  }
329  else if (txVector.GetChannelWidth () == 80)
330  {
331  vhtBandwidth = 4;
332  }
333  else if (txVector.GetChannelWidth () == 160)
334  {
335  vhtBandwidth = 11;
336  }
337 
338  //only SU PPDUs are currently supported
339  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
340  vhtMcsNss[0] |= ((txVector.GetMode ().GetMcsValue () << 4) & 0xf0);
341 
342  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
343  }
344 
345  p->AddHeader (header);
346  file->Write (Simulator::Now (), p);
347  return;
348  }
349  default:
350  NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
351  }
352 }
353 
354 void
357  Ptr<const Packet> packet,
358  uint16_t channelFreqMhz,
359  WifiTxVector txVector,
360  MpduInfo aMpdu,
361  SignalNoiseDbm signalNoise)
362 {
363  uint32_t dlt = file->GetDataLinkType ();
364  WifiPreamble preamble = txVector.GetPreambleType ();
365 
366  switch (dlt)
367  {
369  file->Write (Simulator::Now (), packet);
370  return;
372  {
373  NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
374  return;
375  }
377  {
378  Ptr<Packet> p = packet->Copy ();
379  RadiotapHeader header;
380  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
381  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
382 
383  //Our capture includes the FCS, so we set the flag to say so.
385 
386  if (preamble == WIFI_PREAMBLE_SHORT)
387  {
389  }
390 
391  if (txVector.GetGuardInterval () == 400)
392  {
394  }
395 
396  header.SetFrameFlags (frameFlags);
397 
398  uint64_t rate = 0;
400  {
401  rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000;
402  header.SetRate (static_cast<uint8_t> (rate));
403  }
404 
405  uint16_t channelFlags = 0;
406  switch (rate)
407  {
408  case 2: //1Mbps
409  case 4: //2Mbps
410  case 10: //5Mbps
411  case 22: //11Mbps
412  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
413  break;
414  default:
415  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
416  break;
417  }
418 
419  if (channelFreqMhz < 2500)
420  {
422  }
423  else
424  {
426  }
427 
428  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
429 
430  header.SetAntennaSignalPower (signalNoise.signal);
431  header.SetAntennaNoisePower (signalNoise.noise);
432 
433  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT)
434  {
435  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
436  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
437 
439 
441  if (txVector.GetChannelWidth () == 40)
442  {
444  }
445 
447  if (txVector.GetGuardInterval () == 400)
448  {
450  }
451 
453  if (preamble == WIFI_PREAMBLE_HT_GF)
454  {
456  }
457 
458  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
459  if (txVector.GetNess () & 0x01) //bit 1
460  {
462  }
463  if (txVector.GetNess () & 0x02) //bit 2
464  {
466  }
467 
468  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
469 
470  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
471  if (txVector.IsStbc ())
472  {
474  }
475 
476  header.SetMcsFields (mcsKnown, mcsFlags, txVector.GetMode ().GetMcsValue ());
477  }
478 
479  if (txVector.IsAggregation ())
480  {
481  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
483  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
484  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
486  uint32_t extractedLength;
487  p->RemoveHeader (hdr);
488  extractedLength = hdr.GetLength ();
489  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
490  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
491  {
492  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
493  }
494  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
495  }
496 
497  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_VHT)
498  {
499  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
500  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
501  uint8_t vhtBandwidth = 0;
502  uint8_t vhtMcsNss[4] = {0,0,0,0};
503  uint8_t vhtCoding = 0;
504  uint8_t vhtGroupId = 0;
505  uint16_t vhtPartialAid = 0;
506 
507  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
508  if (txVector.IsStbc ())
509  {
510  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
511  }
512 
514  if (txVector.GetGuardInterval () == 400)
515  {
517  }
518 
519  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
520 
522  //not all bandwidth values are currently supported
523  if (txVector.GetChannelWidth () == 40)
524  {
525  vhtBandwidth = 1;
526  }
527  else if (txVector.GetChannelWidth () == 80)
528  {
529  vhtBandwidth = 4;
530  }
531  else if (txVector.GetChannelWidth () == 160)
532  {
533  vhtBandwidth = 11;
534  }
535 
536  //only SU PPDUs are currently supported
537  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
538  vhtMcsNss[0] |= ((txVector.GetMode ().GetMcsValue () << 4) & 0xf0);
539 
540  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
541  }
542 
543  p->AddHeader (header);
544  file->Write (Simulator::Now (), p);
545  return;
546  }
547  default:
548  NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
549  }
550 }
551 
552 void
554 {
555  switch (dlt)
556  {
557  case DLT_IEEE802_11:
559  return;
560  case DLT_PRISM_HEADER:
562  return;
565  return;
566  default:
567  NS_ABORT_MSG ("WifiPhyHelper::SetPcapFormat(): Unexpected format");
568  }
569 }
570 
573 {
574  return m_pcapDlt;
575 }
576 
577 void
578 WifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
579 {
580  NS_LOG_FUNCTION (this << prefix << nd << promiscuous << explicitFilename);
581 
582  //All of the Pcap enable functions vector through here including the ones
583  //that are wandering through all of devices on perhaps all of the nodes in
584  //the system. We can only deal with devices of type WifiNetDevice.
585  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
586  if (device == 0)
587  {
588  NS_LOG_INFO ("WifiHelper::EnablePcapInternal(): Device " << &device << " not of type ns3::WifiNetDevice");
589  return;
590  }
591 
592  Ptr<WifiPhy> phy = device->GetPhy ();
593  NS_ABORT_MSG_IF (phy == 0, "WifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
594 
595  PcapHelper pcapHelper;
596 
597  std::string filename;
598  if (explicitFilename)
599  {
600  filename = prefix;
601  }
602  else
603  {
604  filename = pcapHelper.GetFilenameFromDevice (prefix, device);
605  }
606 
607  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
608 
611 }
612 
613 void
616  std::string prefix,
617  Ptr<NetDevice> nd,
618  bool explicitFilename)
619 {
620  //All of the ascii enable functions vector through here including the ones
621  //that are wandering through all of devices on perhaps all of the nodes in
622  //the system. We can only deal with devices of type WifiNetDevice.
623  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
624  if (device == 0)
625  {
626  NS_LOG_INFO ("WifiHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::WifiNetDevice");
627  return;
628  }
629 
630  //Our trace sinks are going to use packet printing, so we have to make sure
631  //that is turned on.
633 
634  uint32_t nodeid = nd->GetNode ()->GetId ();
635  uint32_t deviceid = nd->GetIfIndex ();
636  std::ostringstream oss;
637 
638  //If we are not provided an OutputStreamWrapper, we are expected to create
639  //one using the usual trace filename conventions and write our traces
640  //without a context since there will be one file per context and therefore
641  //the context would be redundant.
642  if (stream == 0)
643  {
644  //Set up an output stream object to deal with private ofstream copy
645  //constructor and lifetime issues. Let the helper decide the actual
646  //name of the file given the prefix.
647  AsciiTraceHelper asciiTraceHelper;
648 
649  std::string filename;
650  if (explicitFilename)
651  {
652  filename = prefix;
653  }
654  else
655  {
656  filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
657  }
658 
659  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
660  //We could go poking through the phy and the state looking for the
661  //correct trace source, but we can let Config deal with that with
662  //some search cost. Since this is presumably happening at topology
663  //creation time, it doesn't seem much of a price to pay.
664  oss.str ("");
665  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
667 
668  oss.str ("");
669  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
671 
672  return;
673  }
674 
675  //If we are provided an OutputStreamWrapper, we are expected to use it, and
676  //to provide a context. We are free to come up with our own context if we
677  //want, and use the AsciiTraceHelper Hook*WithContext functions, but for
678  //compatibility and simplicity, we just use Config::Connect and let it deal
679  //with coming up with a context.
680  oss.str ("");
681  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
683 
684  oss.str ("");
685  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
687 }
688 
690 {
691 }
692 
694  : m_standard (WIFI_PHY_STANDARD_80211a)
695 {
696  SetRemoteStationManager ("ns3::ArfWifiManager");
697 }
698 
699 void
701  std::string n0, const AttributeValue &v0,
702  std::string n1, const AttributeValue &v1,
703  std::string n2, const AttributeValue &v2,
704  std::string n3, const AttributeValue &v3,
705  std::string n4, const AttributeValue &v4,
706  std::string n5, const AttributeValue &v5,
707  std::string n6, const AttributeValue &v6,
708  std::string n7, const AttributeValue &v7)
709 {
712  m_stationManager.Set (n0, v0);
713  m_stationManager.Set (n1, v1);
714  m_stationManager.Set (n2, v2);
715  m_stationManager.Set (n3, v3);
716  m_stationManager.Set (n4, v4);
717  m_stationManager.Set (n5, v5);
718  m_stationManager.Set (n6, v6);
719  m_stationManager.Set (n7, v7);
720 }
721 
722 void
724 {
725  m_standard = standard;
726 }
727 
730  const WifiMacHelper &macHelper,
732  NodeContainer::Iterator last) const
733 {
735  for (NodeContainer::Iterator i = first; i != last; ++i)
736  {
737  Ptr<Node> node = *i;
738  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
740  Ptr<WifiMac> mac = macHelper.Create ();
741  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
742  mac->SetAddress (Mac48Address::Allocate ());
745  device->SetMac (mac);
746  device->SetPhy (phy);
747  device->SetRemoteStationManager (manager);
748  node->AddDevice (device);
749  devices.Add (device);
750  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
751  }
752  return devices;
753 }
754 
757  const WifiMacHelper &macHelper, NodeContainer c) const
758 {
759  return Install (phyHelper, macHelper, c.Begin (), c.End ());
760 }
761 
764  const WifiMacHelper &mac, Ptr<Node> node) const
765 {
766  return Install (phy, mac, NodeContainer (node));
767 }
768 
771  const WifiMacHelper &mac, std::string nodeName) const
772 {
773  Ptr<Node> node = Names::Find<Node> (nodeName);
774  return Install (phy, mac, NodeContainer (node));
775 }
776 
777 void
779 {
780  LogComponentEnable ("AarfWifiManager", LOG_LEVEL_ALL);
781  LogComponentEnable ("AarfcdWifiManager", LOG_LEVEL_ALL);
782  LogComponentEnable ("AdhocWifiMac", LOG_LEVEL_ALL);
783  LogComponentEnable ("AmrrWifiManager", LOG_LEVEL_ALL);
784  LogComponentEnable ("ApWifiMac", LOG_LEVEL_ALL);
785  LogComponentEnable ("AparfWifiManager", LOG_LEVEL_ALL);
786  LogComponentEnable ("ArfWifiManager", LOG_LEVEL_ALL);
787  LogComponentEnable ("BlockAckAgreement", LOG_LEVEL_ALL);
788  LogComponentEnable ("BlockAckCache", LOG_LEVEL_ALL);
789  LogComponentEnable ("BlockAckManager", LOG_LEVEL_ALL);
790  LogComponentEnable ("CaraWifiManager", LOG_LEVEL_ALL);
791  LogComponentEnable ("ConstantRateWifiManager", LOG_LEVEL_ALL);
792  LogComponentEnable ("DcaTxop", LOG_LEVEL_ALL);
793  LogComponentEnable ("DcfManager", LOG_LEVEL_ALL);
794  LogComponentEnable ("DcfState", LOG_LEVEL_ALL);
795  LogComponentEnable ("DsssErrorRateModel", LOG_LEVEL_ALL);
796  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_ALL);
797  LogComponentEnable ("IdealWifiManager", LOG_LEVEL_ALL);
798  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
799  LogComponentEnable ("MacLow", LOG_LEVEL_ALL);
800  LogComponentEnable ("MacRxMiddle", LOG_LEVEL_ALL);
801  LogComponentEnable ("MacTxMiddle", LOG_LEVEL_ALL);
802  LogComponentEnable ("MinstrelHtWifiManager", LOG_LEVEL_ALL);
803  LogComponentEnable ("MinstrelWifiManager", LOG_LEVEL_ALL);
804  LogComponentEnable ("MpduAggregator", LOG_LEVEL_ALL);
805  LogComponentEnable ("MsduAggregator", LOG_LEVEL_ALL);
806  LogComponentEnable ("NistErrorRateModel", LOG_LEVEL_ALL);
807  LogComponentEnable ("OnoeWifiManager", LOG_LEVEL_ALL);
808  LogComponentEnable ("ParfWifiManager", LOG_LEVEL_ALL);
809  LogComponentEnable ("RegularWifiMac", LOG_LEVEL_ALL);
810  LogComponentEnable ("RraaWifiManager", LOG_LEVEL_ALL);
811  LogComponentEnable ("RrpaaWifiManager", LOG_LEVEL_ALL);
812  LogComponentEnable ("SpectrumWifiPhy", LOG_LEVEL_ALL);
813  LogComponentEnable ("StaWifiMac", LOG_LEVEL_ALL);
814  LogComponentEnable ("SupportedRates", LOG_LEVEL_ALL);
815  LogComponentEnable ("WifiMac", LOG_LEVEL_ALL);
816  LogComponentEnable ("WifiMacQueueItem", LOG_LEVEL_ALL);
817  LogComponentEnable ("WifiNetDevice", LOG_LEVEL_ALL);
818  LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL);
819  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
820  LogComponentEnable ("WifiRadioEnergyModel", LOG_LEVEL_ALL);
821  LogComponentEnable ("WifiRemoteStationManager", LOG_LEVEL_ALL);
822  LogComponentEnable ("WifiSpectrumPhyInterface", LOG_LEVEL_ALL);
823  LogComponentEnable ("WifiSpectrumSignalParameters", LOG_LEVEL_ALL);
824  LogComponentEnable ("WifiTxCurrentModel", LOG_LEVEL_ALL);
825  LogComponentEnable ("YansErrorRateModel", LOG_LEVEL_ALL);
826  LogComponentEnable ("YansWifiChannel", LOG_LEVEL_ALL);
827  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
828 }
829 
830 int64_t
832 {
833  int64_t currentStream = stream;
834  Ptr<NetDevice> netDevice;
835  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
836  {
837  netDevice = (*i);
838  Ptr<WifiNetDevice> wifi = DynamicCast<WifiNetDevice> (netDevice);
839  if (wifi)
840  {
841  //Handle any random numbers in the PHY objects.
842  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
843 
844  //Handle any random numbers in the station managers.
845  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
846  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
847  if (minstrel)
848  {
849  currentStream += minstrel->AssignStreams (currentStream);
850  }
851 
852  Ptr<MinstrelHtWifiManager> minstrelHt = DynamicCast<MinstrelHtWifiManager> (manager);
853  if (minstrelHt)
854  {
855  currentStream += minstrelHt->AssignStreams (currentStream);
856  }
857 
858  //Handle any random numbers in the MAC objects.
859  Ptr<WifiMac> mac = wifi->GetMac ();
860  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
861  if (rmac)
862  {
863  PointerValue ptr;
864  rmac->GetAttribute ("DcaTxop", ptr);
865  Ptr<DcaTxop> dcaTxop = ptr.Get<DcaTxop> ();
866  currentStream += dcaTxop->AssignStreams (currentStream);
867 
868  rmac->GetAttribute ("VO_EdcaTxopN", ptr);
869  Ptr<EdcaTxopN> vo_edcaTxopN = ptr.Get<EdcaTxopN> ();
870  currentStream += vo_edcaTxopN->AssignStreams (currentStream);
871 
872  rmac->GetAttribute ("VI_EdcaTxopN", ptr);
873  Ptr<EdcaTxopN> vi_edcaTxopN = ptr.Get<EdcaTxopN> ();
874  currentStream += vi_edcaTxopN->AssignStreams (currentStream);
875 
876  rmac->GetAttribute ("BE_EdcaTxopN", ptr);
877  Ptr<EdcaTxopN> be_edcaTxopN = ptr.Get<EdcaTxopN> ();
878  currentStream += be_edcaTxopN->AssignStreams (currentStream);
879 
880  rmac->GetAttribute ("BK_EdcaTxopN", ptr);
881  Ptr<EdcaTxopN> bk_edcaTxopN = ptr.Get<EdcaTxopN> ();
882  currentStream += bk_edcaTxopN->AssignStreams (currentStream);
883 
884  //if an AP, handle any beacon jitter
885  Ptr<ApWifiMac> apmac = DynamicCast<ApWifiMac> (rmac);
886  if (apmac)
887  {
888  currentStream += apmac->AssignStreams (currentStream);
889  }
890  }
891  }
892  }
893  return (currentStream - stream);
894 }
895 
896 } //namespace ns3
virtual ~WifiPhyHelper()
Definition: wifi-helper.cc:128
MpduInfo structure.
Definition: wifi-phy.h:79
uint16_t GetLength(void) const
Return the length field.
WifiPhyStandard m_standard
wifi standard
Definition: wifi-helper.h:345
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
Frame used short guard interval (HT)
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:133
uint16_t GetGuardInterval(void) const
double signal
in dBm
Definition: wifi-phy.h:74
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)
ASCII Phy receive sink without context.
Definition: wave-helper.cc:112
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:700
Radiotap header implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
virtual ~WifiHelper()
Definition: wifi-helper.cc:689
Hold a value for an Attribute.
Definition: attribute.h:68
Manage pcap files for device models.
Definition: trace-helper.h:38
create PHY objects
Definition: wifi-helper.h:42
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1686
PcapHelper::DataLinkType m_pcapDlt
PCAP data link type.
Definition: wifi-helper.h:202
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
The MPDU is the last aggregate in an A-MPDU.
Definition: wifi-phy.h:68
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
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)
ASCII Phy receive sink with context.
Definition: wave-helper.cc:91
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
#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...
VHT PHY (Clause 22)
Definition: wifi-mode.h:60
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: dca-txop.cc:228
ObjectFactory m_errorRateModel
error rate model
Definition: wifi-helper.h:167
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
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
WifiHelper()
Create a Wifi helper in an empty state: all its parameters must be set before calling ns3::WifiHelper...
Definition: wifi-helper.cc:693
Delimiter CRC value known: the delimiter CRC value field is valid.
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:614
uint8_t GetChannelWidth(void) const
static void PcapSniffTxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu)
Definition: wifi-helper.cc:162
DataLinkType
This enumeration holds the data link types that will be written to the pcap file. ...
Definition: trace-helper.h:50
virtual void SetStandard(WifiPhyStandard standard)
Definition: wifi-helper.cc:723
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:227
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:355
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:68
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:369
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:572
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.
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
holds a vector of ns3::NetDevice pointers
Ness - bit 0 (LSB) of Number of extension spatial streams.
static void PcapSniffRxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise)
Definition: wifi-helper.cc:355
uint8_t GetNess(void) const
uint8_t GetCrc(void) const
Return the CRC field.
Introspection did not find any typical Config paths.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:729
HT PHY (Clause 20)
Definition: wifi-mode.h:58
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:831
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:465
Hold together all Wifi-related objects.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:832
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:843
Include Prism monitor mode information.
Definition: wifi-helper.h:110
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:121
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:293
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
station manager
Definition: wifi-helper.h:344
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:249
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:553
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:139
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:578
WifiPreamble GetPreambleType(void) const
ObjectFactory m_phy
PHY object.
Definition: wifi-helper.h:166
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:778
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
SignalNoiseDbm structure.
Definition: wifi-phy.h:72
uint32_t mpduRefNumber
MPDU ref number.
Definition: wifi-phy.h:82
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:269
IEEE 802.11 Wireless LAN headers on packets.
Definition: wifi-helper.h:109
Last subframe is known (should be set for all subframes in an A-MPDU)
Print everything.
Definition: log.h:112
double noise
in dBm
Definition: wifi-phy.h:75
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:107
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1137
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:487
WifiMode GetMode(void) const
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:58
Definition: first.py:1
MpduType type
type
Definition: wifi-phy.h:81
void SetAmpduStatus(uint32_t referenceNumber, uint16_t flags, uint8_t crc)
Set the A-MPDU status fields.
Include Radiotap link layer information.
Definition: wifi-helper.h:111
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:572
static void AsciiPhyTransmitSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
ASCII Phy transmit sink with context.
Definition: wave-helper.cc:49
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
HE PHY (Clause 26)
Definition: wifi-mode.h:62
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
void SetAntennaSignalPower(double signal)
Set the RF signal power at the antenna as a decibel difference from an arbitrary, fixed reference...
static void AsciiPhyTransmitSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
ASCII Phy transmit sink without context.
Definition: wave-helper.cc:70