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/ap-wifi-mac.h"
27 #include "ns3/ampdu-subframe-header.h"
28 #include "ns3/log.h"
29 #include "ns3/pointer.h"
30 #include "ns3/radiotap-header.h"
31 #include "ns3/config.h"
32 #include "ns3/names.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("WifiHelper");
37 
47 static void
50  std::string context,
52  WifiMode mode,
53  WifiPreamble preamble,
54  uint8_t txLevel)
55 {
56  NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
57  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
58 }
59 
68 static void
72  WifiMode mode,
73  WifiPreamble preamble,
74  uint8_t txLevel)
75 {
76  NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
77  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
78 }
79 
89 static void
92  std::string context,
94  double snr,
95  WifiMode mode,
96  enum WifiPreamble preamble)
97 {
98  NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
99  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
100 }
101 
110 static void
114  double snr,
115  WifiMode mode,
116  enum WifiPreamble preamble)
117 {
118  NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
119  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
120 }
121 
123  : m_pcapDlt (PcapHelper::DLT_IEEE802_11)
124 {
125 }
126 
128 {
129 }
130 
131 void
132 WifiPhyHelper::Set (std::string name, const AttributeValue &v)
133 {
134  m_phy.Set (name, v);
135 }
136 
137 void
139  std::string n0, const AttributeValue &v0,
140  std::string n1, const AttributeValue &v1,
141  std::string n2, const AttributeValue &v2,
142  std::string n3, const AttributeValue &v3,
143  std::string n4, const AttributeValue &v4,
144  std::string n5, const AttributeValue &v5,
145  std::string n6, const AttributeValue &v6,
146  std::string n7, const AttributeValue &v7)
147 {
150  m_errorRateModel.Set (n0, v0);
151  m_errorRateModel.Set (n1, v1);
152  m_errorRateModel.Set (n2, v2);
153  m_errorRateModel.Set (n3, v3);
154  m_errorRateModel.Set (n4, v4);
155  m_errorRateModel.Set (n5, v5);
156  m_errorRateModel.Set (n6, v6);
157  m_errorRateModel.Set (n7, v7);
158 }
159 
160 void
163  Ptr<const Packet> packet,
164  uint16_t channelFreqMhz,
165  WifiTxVector txVector,
166  MpduInfo aMpdu)
167 {
168  uint32_t dlt = file->GetDataLinkType ();
169  WifiPreamble preamble = txVector.GetPreambleType ();
170 
171  switch (dlt)
172  {
174  file->Write (Simulator::Now (), packet);
175  return;
177  {
178  NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
179  return;
180  }
182  {
183  Ptr<Packet> p = packet->Copy ();
184  RadiotapHeader header;
185  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
186  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
187 
188  //Our capture includes the FCS, so we set the flag to say so.
190 
191  if (preamble == WIFI_PREAMBLE_SHORT)
192  {
194  }
195 
196  if (txVector.GetGuardInterval () == 400)
197  {
199  }
200 
201  header.SetFrameFlags (frameFlags);
202 
203  uint32_t rate;
205  {
206  rate = 128 + txVector.GetMode ().GetMcsValue ();
207  }
208  else
209  {
210  rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000;
211  }
212  header.SetRate (rate);
213 
214  uint16_t channelFlags = 0;
215  switch (rate)
216  {
217  case 2: //1Mbps
218  case 4: //2Mbps
219  case 10: //5Mbps
220  case 22: //11Mbps
221  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
222  break;
223 
224  default:
225  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
226  break;
227  }
228 
229  if (channelFreqMhz < 2500)
230  {
232  }
233  else
234  {
236  }
237 
238  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
239 
240  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
241  {
242  uint8_t mcsRate = 0;
243  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
244  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
245 
247  mcsRate = rate - 128;
248 
250  if (txVector.GetChannelWidth () == 40)
251  {
253  }
254 
256  if (txVector.GetGuardInterval () == 400)
257  {
259  }
260 
262  if (preamble == WIFI_PREAMBLE_HT_GF)
263  {
265  }
266 
267  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
268  if (txVector.GetNess () & 0x01) //bit 1
269  {
271  }
272  if (txVector.GetNess () & 0x02) //bit 2
273  {
275  }
276 
277  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
278 
279  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
280  if (txVector.IsStbc ())
281  {
283  }
284 
285  header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
286  }
287 
288  if (txVector.IsAggregation ())
289  {
290  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
291  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
292  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
294  uint32_t extractedLength;
295  p->RemoveHeader (hdr);
296  extractedLength = hdr.GetLength ();
297  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
298  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
299  {
300  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
301  }
302  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
303  }
304 
305  if (preamble == WIFI_PREAMBLE_VHT)
306  {
307  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
308  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
309  uint8_t vhtBandwidth = 0;
310  uint8_t vhtMcsNss[4] = {0,0,0,0};
311  uint8_t vhtCoding = 0;
312  uint8_t vhtGroupId = 0;
313  uint16_t vhtPartialAid = 0;
314 
315  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
316  if (txVector.IsStbc ())
317  {
318  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
319  }
320 
322  if (txVector.GetGuardInterval () == 400)
323  {
325  }
326 
327  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
328 
330  //not all bandwidth values are currently supported
331  if (txVector.GetChannelWidth () == 40)
332  {
333  vhtBandwidth = 1;
334  }
335  else if (txVector.GetChannelWidth () == 80)
336  {
337  vhtBandwidth = 4;
338  }
339  else if (txVector.GetChannelWidth () == 160)
340  {
341  vhtBandwidth = 11;
342  }
343 
344  //only SU PPDUs are currently supported
345  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
346  vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
347 
348  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
349  }
350 
351  p->AddHeader (header);
352  file->Write (Simulator::Now (), p);
353  return;
354  }
355  default:
356  NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
357  }
358 }
359 
360 void
363  Ptr<const Packet> packet,
364  uint16_t channelFreqMhz,
365  WifiTxVector txVector,
366  MpduInfo aMpdu,
367  SignalNoiseDbm signalNoise)
368 {
369  uint32_t dlt = file->GetDataLinkType ();
370  WifiPreamble preamble = txVector.GetPreambleType ();
371 
372  switch (dlt)
373  {
375  file->Write (Simulator::Now (), packet);
376  return;
378  {
379  NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
380  return;
381  }
383  {
384  Ptr<Packet> p = packet->Copy ();
385  RadiotapHeader header;
386  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
387  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
388 
389  //Our capture includes the FCS, so we set the flag to say so.
391 
392  if (preamble == WIFI_PREAMBLE_SHORT)
393  {
395  }
396 
397  if (txVector.GetGuardInterval () == 400)
398  {
400  }
401 
402  header.SetFrameFlags (frameFlags);
403 
404  uint32_t rate;
406  {
407  rate = 128 + txVector.GetMode ().GetMcsValue ();
408  }
409  else
410  {
411  rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000;
412  }
413  header.SetRate (rate);
414 
415  uint16_t channelFlags = 0;
416  switch (rate)
417  {
418  case 2: //1Mbps
419  case 4: //2Mbps
420  case 10: //5Mbps
421  case 22: //11Mbps
422  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
423  break;
424 
425  default:
426  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
427  break;
428  }
429 
430  if (channelFreqMhz < 2500)
431  {
433  }
434  else
435  {
437  }
438 
439  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
440 
441  header.SetAntennaSignalPower (signalNoise.signal);
442  header.SetAntennaNoisePower (signalNoise.noise);
443 
444  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
445  {
446  uint8_t mcsRate = 0;
447  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
448  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
449 
451  mcsRate = rate - 128;
452 
454  if (txVector.GetChannelWidth () == 40)
455  {
457  }
458 
460  if (txVector.GetGuardInterval () == 400)
461  {
463  }
464 
466  if (preamble == WIFI_PREAMBLE_HT_GF)
467  {
469  }
470 
471  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
472  if (txVector.GetNess () & 0x01) //bit 1
473  {
475  }
476  if (txVector.GetNess () & 0x02) //bit 2
477  {
479  }
480 
481  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
482 
483  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
484  if (txVector.IsStbc ())
485  {
487  }
488 
489  header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
490  }
491 
492  if (txVector.IsAggregation ())
493  {
494  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
496  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
497  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
499  uint32_t extractedLength;
500  p->RemoveHeader (hdr);
501  extractedLength = hdr.GetLength ();
502  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
503  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
504  {
505  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
506  }
507  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
508  }
509 
510  if (preamble == WIFI_PREAMBLE_VHT)
511  {
512  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
513  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
514  uint8_t vhtBandwidth = 0;
515  uint8_t vhtMcsNss[4] = {0,0,0,0};
516  uint8_t vhtCoding = 0;
517  uint8_t vhtGroupId = 0;
518  uint16_t vhtPartialAid = 0;
519 
520  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
521  if (txVector.IsStbc ())
522  {
523  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
524  }
525 
527  if (txVector.GetGuardInterval () == 400)
528  {
530  }
531 
532  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
533 
535  //not all bandwidth values are currently supported
536  if (txVector.GetChannelWidth () == 40)
537  {
538  vhtBandwidth = 1;
539  }
540  else if (txVector.GetChannelWidth () == 80)
541  {
542  vhtBandwidth = 4;
543  }
544  else if (txVector.GetChannelWidth () == 160)
545  {
546  vhtBandwidth = 11;
547  }
548 
549  //only SU PPDUs are currently supported
550  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
551  vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
552 
553  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
554  }
555 
556  p->AddHeader (header);
557  file->Write (Simulator::Now (), p);
558  return;
559  }
560  default:
561  NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
562  }
563 }
564 
565 void
567 {
568  switch (dlt)
569  {
570  case DLT_IEEE802_11:
572  return;
573  case DLT_PRISM_HEADER:
575  return;
578  return;
579  default:
580  NS_ABORT_MSG ("WifiPhyHelper::SetPcapFormat(): Unexpected format");
581  }
582 }
583 
586 {
587  return m_pcapDlt;
588 }
589 
590 void
591 WifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
592 {
593  //All of the Pcap enable functions vector through here including the ones
594  //that are wandering through all of devices on perhaps all of the nodes in
595  //the system. We can only deal with devices of type WifiNetDevice.
596  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
597  if (device == 0)
598  {
599  NS_LOG_INFO ("WifiHelper::EnablePcapInternal(): Device " << &device << " not of type ns3::WifiNetDevice");
600  return;
601  }
602 
603  Ptr<WifiPhy> phy = device->GetPhy ();
604  NS_ABORT_MSG_IF (phy == 0, "WifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
605 
606  PcapHelper pcapHelper;
607 
608  std::string filename;
609  if (explicitFilename)
610  {
611  filename = prefix;
612  }
613  else
614  {
615  filename = pcapHelper.GetFilenameFromDevice (prefix, device);
616  }
617 
618  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
619 
622 }
623 
624 void
627  std::string prefix,
628  Ptr<NetDevice> nd,
629  bool explicitFilename)
630 {
631  //All of the ascii enable functions vector through here including the ones
632  //that are wandering through all of devices on perhaps all of the nodes in
633  //the system. We can only deal with devices of type WifiNetDevice.
634  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
635  if (device == 0)
636  {
637  NS_LOG_INFO ("WifiHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::WifiNetDevice");
638  return;
639  }
640 
641  //Our trace sinks are going to use packet printing, so we have to make sure
642  //that is turned on.
644 
645  uint32_t nodeid = nd->GetNode ()->GetId ();
646  uint32_t deviceid = nd->GetIfIndex ();
647  std::ostringstream oss;
648 
649  //If we are not provided an OutputStreamWrapper, we are expected to create
650  //one using the usual trace filename conventions and write our traces
651  //without a context since there will be one file per context and therefore
652  //the context would be redundant.
653  if (stream == 0)
654  {
655  //Set up an output stream object to deal with private ofstream copy
656  //constructor and lifetime issues. Let the helper decide the actual
657  //name of the file given the prefix.
658  AsciiTraceHelper asciiTraceHelper;
659 
660  std::string filename;
661  if (explicitFilename)
662  {
663  filename = prefix;
664  }
665  else
666  {
667  filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
668  }
669 
670  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
671  //We could go poking through the phy and the state looking for the
672  //correct trace source, but we can let Config deal with that with
673  //some search cost. Since this is presumably happening at topology
674  //creation time, it doesn't seem much of a price to pay.
675  oss.str ("");
676  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
678 
679  oss.str ("");
680  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
682 
683  return;
684  }
685 
686  //If we are provided an OutputStreamWrapper, we are expected to use it, and
687  //to provide a context. We are free to come up with our own context if we
688  //want, and use the AsciiTraceHelper Hook*WithContext functions, but for
689  //compatibility and simplicity, we just use Config::Connect and let it deal
690  //with coming up with a context.
691  oss.str ("");
692  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
694 
695  oss.str ("");
696  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
698 }
699 
701 {
702 }
703 
705  : m_standard (WIFI_PHY_STANDARD_80211a)
706 {
707  SetRemoteStationManager ("ns3::ArfWifiManager");
708 }
709 
712 {
713  WifiHelper helper;
714  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
715  return helper;
716 }
717 
718 void
720  std::string n0, const AttributeValue &v0,
721  std::string n1, const AttributeValue &v1,
722  std::string n2, const AttributeValue &v2,
723  std::string n3, const AttributeValue &v3,
724  std::string n4, const AttributeValue &v4,
725  std::string n5, const AttributeValue &v5,
726  std::string n6, const AttributeValue &v6,
727  std::string n7, const AttributeValue &v7)
728 {
731  m_stationManager.Set (n0, v0);
732  m_stationManager.Set (n1, v1);
733  m_stationManager.Set (n2, v2);
734  m_stationManager.Set (n3, v3);
735  m_stationManager.Set (n4, v4);
736  m_stationManager.Set (n5, v5);
737  m_stationManager.Set (n6, v6);
738  m_stationManager.Set (n7, v7);
739 }
740 
741 void
743 {
744  m_standard = standard;
745 }
746 
749  const WifiMacHelper &macHelper,
751  NodeContainer::Iterator last) const
752 {
754  for (NodeContainer::Iterator i = first; i != last; ++i)
755  {
756  Ptr<Node> node = *i;
757  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
759  Ptr<WifiMac> mac = macHelper.Create ();
760  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
761  mac->SetAddress (Mac48Address::Allocate ());
764  device->SetMac (mac);
765  device->SetPhy (phy);
766  device->SetRemoteStationManager (manager);
767  node->AddDevice (device);
768  devices.Add (device);
769  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
770  }
771  return devices;
772 }
773 
776  const WifiMacHelper &macHelper, NodeContainer c) const
777 {
778  return Install (phyHelper, macHelper, c.Begin (), c.End ());
779 }
780 
783  const WifiMacHelper &mac, Ptr<Node> node) const
784 {
785  return Install (phy, mac, NodeContainer (node));
786 }
787 
790  const WifiMacHelper &mac, std::string nodeName) const
791 {
792  Ptr<Node> node = Names::Find<Node> (nodeName);
793  return Install (phy, mac, NodeContainer (node));
794 }
795 
796 void
798 {
799  LogComponentEnable ("AarfWifiManager", LOG_LEVEL_ALL);
800  LogComponentEnable ("AarfcdWifiManager", LOG_LEVEL_ALL);
801  LogComponentEnable ("AdhocWifiMac", LOG_LEVEL_ALL);
802  LogComponentEnable ("AmrrWifiManager", LOG_LEVEL_ALL);
803  LogComponentEnable ("ApWifiMac", LOG_LEVEL_ALL);
804  LogComponentEnable ("AparfWifiManager", LOG_LEVEL_ALL);
805  LogComponentEnable ("ArfWifiManager", LOG_LEVEL_ALL);
806  LogComponentEnable ("BlockAckAgreement", LOG_LEVEL_ALL);
807  LogComponentEnable ("BlockAckCache", LOG_LEVEL_ALL);
808  LogComponentEnable ("BlockAckManager", LOG_LEVEL_ALL);
809  LogComponentEnable ("CaraWifiManager", LOG_LEVEL_ALL);
810  LogComponentEnable ("ConstantRateWifiManager", LOG_LEVEL_ALL);
811  LogComponentEnable ("DcaTxop", LOG_LEVEL_ALL);
812  LogComponentEnable ("DcfManager", LOG_LEVEL_ALL);
813  LogComponentEnable ("DsssErrorRateModel", LOG_LEVEL_ALL);
814  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_ALL);
815  LogComponentEnable ("IdealWifiManager", LOG_LEVEL_ALL);
816  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
817  LogComponentEnable ("MacLow", LOG_LEVEL_ALL);
818  LogComponentEnable ("MacRxMiddle", LOG_LEVEL_ALL);
819  LogComponentEnable ("MacTxMiddle", LOG_LEVEL_ALL);
820  LogComponentEnable ("MinstrelHtWifiManager", LOG_LEVEL_ALL);
821  LogComponentEnable ("MinstrelWifiManager", LOG_LEVEL_ALL);
822  LogComponentEnable ("MpduAggregator", LOG_LEVEL_ALL);
823  LogComponentEnable ("MpduStandardAggregator", LOG_LEVEL_ALL);
824  LogComponentEnable ("MsduAggregator", LOG_LEVEL_ALL);
825  LogComponentEnable ("MsduStandardAggregator", LOG_LEVEL_ALL);
826  LogComponentEnable ("NistErrorRateModel", LOG_LEVEL_ALL);
827  LogComponentEnable ("OnoeWifiManager", LOG_LEVEL_ALL);
828  LogComponentEnable ("ParfWifiManager", LOG_LEVEL_ALL);
829  LogComponentEnable ("RegularWifiMac", LOG_LEVEL_ALL);
830  LogComponentEnable ("RraaWifiManager", LOG_LEVEL_ALL);
831  LogComponentEnable ("SpectrumWifiPhy", LOG_LEVEL_ALL);
832  LogComponentEnable ("StaWifiMac", LOG_LEVEL_ALL);
833  LogComponentEnable ("SupportedRates", LOG_LEVEL_ALL);
834  LogComponentEnable ("WifiMac", LOG_LEVEL_ALL);
835  LogComponentEnable ("WifiNetDevice", LOG_LEVEL_ALL);
836  LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL);
837  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
838  LogComponentEnable ("WifiRadioEnergyModel", LOG_LEVEL_ALL);
839  LogComponentEnable ("WifiRemoteStationManager", LOG_LEVEL_ALL);
840  LogComponentEnable ("WifiSpectrumPhyInterface", LOG_LEVEL_ALL);
841  LogComponentEnable ("WifiSpectrumSignalParameters", LOG_LEVEL_ALL);
842  LogComponentEnable ("WifiTxCurrentModel", LOG_LEVEL_ALL);
843  LogComponentEnable ("YansErrorRateModel", LOG_LEVEL_ALL);
844  LogComponentEnable ("YansWifiChannel", LOG_LEVEL_ALL);
845  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
846 }
847 
848 int64_t
850 {
851  int64_t currentStream = stream;
852  Ptr<NetDevice> netDevice;
853  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
854  {
855  netDevice = (*i);
856  Ptr<WifiNetDevice> wifi = DynamicCast<WifiNetDevice> (netDevice);
857  if (wifi)
858  {
859  //Handle any random numbers in the PHY objects.
860  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
861 
862  //Handle any random numbers in the station managers.
863  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
864  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
865  if (minstrel)
866  {
867  currentStream += minstrel->AssignStreams (currentStream);
868  }
869 
870  //Handle any random numbers in the MAC objects.
871  Ptr<WifiMac> mac = wifi->GetMac ();
872  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
873  if (rmac)
874  {
875  PointerValue ptr;
876  rmac->GetAttribute ("DcaTxop", ptr);
877  Ptr<DcaTxop> dcaTxop = ptr.Get<DcaTxop> ();
878  currentStream += dcaTxop->AssignStreams (currentStream);
879 
880  rmac->GetAttribute ("VO_EdcaTxopN", ptr);
881  Ptr<EdcaTxopN> vo_edcaTxopN = ptr.Get<EdcaTxopN> ();
882  currentStream += vo_edcaTxopN->AssignStreams (currentStream);
883 
884  rmac->GetAttribute ("VI_EdcaTxopN", ptr);
885  Ptr<EdcaTxopN> vi_edcaTxopN = ptr.Get<EdcaTxopN> ();
886  currentStream += vi_edcaTxopN->AssignStreams (currentStream);
887 
888  rmac->GetAttribute ("BE_EdcaTxopN", ptr);
889  Ptr<EdcaTxopN> be_edcaTxopN = ptr.Get<EdcaTxopN> ();
890  currentStream += be_edcaTxopN->AssignStreams (currentStream);
891 
892  rmac->GetAttribute ("BK_EdcaTxopN", ptr);
893  Ptr<EdcaTxopN> bk_edcaTxopN = ptr.Get<EdcaTxopN> ();
894  currentStream += bk_edcaTxopN->AssignStreams (currentStream);
895 
896  //if an AP, handle any beacon jitter
897  Ptr<ApWifiMac> apmac = DynamicCast<ApWifiMac> (rmac);
898  if (apmac)
899  {
900  currentStream += apmac->AssignStreams (currentStream);
901  }
902  }
903  }
904  }
905  return (currentStream - stream);
906 }
907 
908 } //namespace ns3
virtual ~WifiPhyHelper()
Definition: wifi-helper.cc:127
MpduInfo structure.
Definition: wifi-phy.h:74
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:267
Frame used short guard interval (HT)
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:132
uint16_t GetGuardInterval(void) const
double signal
in dBm
Definition: wifi-phy.h:69
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:719
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:700
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:63
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
helps to create WifiNetDevice objects
Definition: wifi-helper.h:213
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:704
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:566
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:625
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:161
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: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: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: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:534
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.
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:742
static void PcapSniffRxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise)
Definition: wifi-helper.cc:361
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:748
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:849
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
uint64_t mpduRefNumber
MPDU ref number.
Definition: wifi-phy.h:77
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:357
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 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:138
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:591
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:797
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:67
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
enum WifiPhyStandard m_standard
wifi standard
Definition: wifi-helper.h:358
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:70
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:1147
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:76
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:585
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 NS_DEPRECATED WifiHelper Default(void)
Definition: wifi-helper.cc:711
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