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 "ns3/wifi-net-device.h"
24 #include "ns3/minstrel-wifi-manager.h"
25 #include "ns3/minstrel-ht-wifi-manager.h"
26 #include "ns3/ap-wifi-mac.h"
27 #include "ns3/ampdu-subframe-header.h"
28 #include "ns3/mobility-model.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 #include "wifi-helper.h"
35 
36 namespace ns3 {
37 
38 NS_LOG_COMPONENT_DEFINE ("WifiHelper");
39 
49 static void
52  std::string context,
54  WifiMode mode,
55  WifiPreamble preamble,
56  uint8_t txLevel)
57 {
58  NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
59  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << mode << " " << *p << std::endl;
60 }
61 
70 static void
74  WifiMode mode,
75  WifiPreamble preamble,
76  uint8_t txLevel)
77 {
78  NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
79  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << mode << " " << *p << std::endl;
80 }
81 
91 static void
94  std::string context,
96  double snr,
97  WifiMode mode,
98  WifiPreamble preamble)
99 {
100  NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
101  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << mode << "" << context << " " << *p << std::endl;
102 }
103 
112 static void
116  double snr,
117  WifiMode mode,
118  WifiPreamble preamble)
119 {
120  NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
121  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << mode << " " << *p << std::endl;
122 }
123 
125  : m_pcapDlt (PcapHelper::DLT_IEEE802_11)
126 {
127 }
128 
130 {
131 }
132 
133 void
134 WifiPhyHelper::Set (std::string name, const AttributeValue &v)
135 {
136  m_phy.Set (name, v);
137 }
138 
139 void
141  std::string n0, const AttributeValue &v0,
142  std::string n1, const AttributeValue &v1,
143  std::string n2, const AttributeValue &v2,
144  std::string n3, const AttributeValue &v3,
145  std::string n4, const AttributeValue &v4,
146  std::string n5, const AttributeValue &v5,
147  std::string n6, const AttributeValue &v6,
148  std::string n7, const AttributeValue &v7)
149 {
152  m_errorRateModel.Set (n0, v0);
153  m_errorRateModel.Set (n1, v1);
154  m_errorRateModel.Set (n2, v2);
155  m_errorRateModel.Set (n3, v3);
156  m_errorRateModel.Set (n4, v4);
157  m_errorRateModel.Set (n5, v5);
158  m_errorRateModel.Set (n6, v6);
159  m_errorRateModel.Set (n7, v7);
160 }
161 
162 void
165  Ptr<const Packet> packet,
166  uint16_t channelFreqMhz,
167  WifiTxVector txVector,
168  MpduInfo aMpdu)
169 {
170  uint32_t dlt = file->GetDataLinkType ();
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 = GetRadiotapHeader (p, channelFreqMhz, txVector, aMpdu);
185  p->AddHeader (header);
186  file->Write (Simulator::Now (), p);
187  return;
188  }
189  default:
190  NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
191  }
192 }
193 
194 void
197  Ptr<const Packet> packet,
198  uint16_t channelFreqMhz,
199  WifiTxVector txVector,
200  MpduInfo aMpdu,
201  SignalNoiseDbm signalNoise)
202 {
203  uint32_t dlt = file->GetDataLinkType ();
204  switch (dlt)
205  {
207  file->Write (Simulator::Now (), packet);
208  return;
210  {
211  NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
212  return;
213  }
215  {
216  Ptr<Packet> p = packet->Copy ();
217  RadiotapHeader header = GetRadiotapHeader (p, channelFreqMhz, txVector, aMpdu);
218  header.SetAntennaSignalPower (signalNoise.signal);
219  header.SetAntennaNoisePower (signalNoise.noise);
220  p->AddHeader (header);
221  file->Write (Simulator::Now (), p);
222  return;
223  }
224  default:
225  NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
226  }
227 }
228 
231  Ptr<Packet> packet,
232  uint16_t channelFreqMhz,
233  WifiTxVector txVector,
234  MpduInfo aMpdu)
235 {
236  RadiotapHeader header;
237  WifiPreamble preamble = txVector.GetPreambleType ();
238 
239  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
240  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
241 
242  //Our capture includes the FCS, so we set the flag to say so.
244 
245  if (preamble == WIFI_PREAMBLE_SHORT)
246  {
248  }
249 
250  if (txVector.GetGuardInterval () == 400)
251  {
253  }
254 
255  header.SetFrameFlags (frameFlags);
256 
257  uint64_t rate = 0;
258  if (txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT
259  && txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_VHT
260  && txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HE)
261  {
262  rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000;
263  header.SetRate (static_cast<uint8_t> (rate));
264  }
265 
266  uint16_t channelFlags = 0;
267  switch (rate)
268  {
269  case 2: //1Mbps
270  case 4: //2Mbps
271  case 10: //5Mbps
272  case 22: //11Mbps
273  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
274  break;
275  default:
276  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
277  break;
278  }
279 
280  if (channelFreqMhz < 2500)
281  {
283  }
284  else
285  {
287  }
288 
289  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
290 
291  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT)
292  {
293  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
294  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
295 
297 
299  if (txVector.GetChannelWidth () == 40)
300  {
302  }
303 
305  if (txVector.GetGuardInterval () == 400)
306  {
308  }
309 
311  if (preamble == WIFI_PREAMBLE_HT_GF)
312  {
314  }
315 
316  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
317  if (txVector.GetNess () & 0x01) //bit 1
318  {
320  }
321  if (txVector.GetNess () & 0x02) //bit 2
322  {
324  }
325 
326  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
327 
328  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
329  if (txVector.IsStbc ())
330  {
332  }
333 
334  header.SetMcsFields (mcsKnown, mcsFlags, txVector.GetMode ().GetMcsValue ());
335  }
336 
337  if (txVector.IsAggregation ())
338  {
339  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
340  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
341  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
343  uint32_t extractedLength;
344  packet->RemoveHeader (hdr);
345  extractedLength = hdr.GetLength ();
346  packet = packet->CreateFragment (0, static_cast<uint32_t> (extractedLength));
347  if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
348  {
349  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
350  }
351  header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, 1 /*CRC*/);
352  }
353 
354  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_VHT)
355  {
356  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
357  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
358  uint8_t vhtBandwidth = 0;
359  uint8_t vhtMcsNss[4] = {0,0,0,0};
360  uint8_t vhtCoding = 0;
361  uint8_t vhtGroupId = 0;
362  uint16_t vhtPartialAid = 0;
363 
364  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
365  if (txVector.IsStbc ())
366  {
367  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
368  }
369 
371  if (txVector.GetGuardInterval () == 400)
372  {
374  }
375 
376  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
377 
379  //not all bandwidth values are currently supported
380  if (txVector.GetChannelWidth () == 40)
381  {
382  vhtBandwidth = 1;
383  }
384  else if (txVector.GetChannelWidth () == 80)
385  {
386  vhtBandwidth = 4;
387  }
388  else if (txVector.GetChannelWidth () == 160)
389  {
390  vhtBandwidth = 11;
391  }
392 
393  //only SU PPDUs are currently supported
394  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
395  vhtMcsNss[0] |= ((txVector.GetMode ().GetMcsValue () << 4) & 0xf0);
396 
397  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
398  }
399 
400  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HE)
401  {
403  if (preamble == WIFI_PREAMBLE_HE_ER_SU)
404  {
406  }
407  else if (preamble == WIFI_PREAMBLE_HE_MU)
408  {
410  }
411  else if (preamble == WIFI_PREAMBLE_HE_TB)
412  {
414  }
415 
417 
418  uint16_t data3 = 0;
419  if (txVector.IsStbc ())
420  {
422  }
423 
424  uint16_t data5 = 0;
425  if (txVector.GetChannelWidth () == 40)
426  {
428  }
429  else if (txVector.GetChannelWidth () == 80)
430  {
432  }
433  else if (txVector.GetChannelWidth () == 160)
434  {
436  }
437  if (txVector.GetGuardInterval () == 1600)
438  {
440  }
441  else if (txVector.GetGuardInterval () == 3200)
442  {
444  }
445 
446  header.SetHeFields (data1, data2, data3, data5);
447  }
448 
449  return header;
450 }
451 
452 void
454 {
455  switch (dlt)
456  {
457  case DLT_IEEE802_11:
459  return;
460  case DLT_PRISM_HEADER:
462  return;
465  return;
466  default:
467  NS_ABORT_MSG ("WifiPhyHelper::SetPcapFormat(): Unexpected format");
468  }
469 }
470 
473 {
474  return m_pcapDlt;
475 }
476 
477 void
478 WifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
479 {
480  NS_LOG_FUNCTION (this << prefix << nd << promiscuous << explicitFilename);
481 
482  //All of the Pcap enable functions vector through here including the ones
483  //that are wandering through all of devices on perhaps all of the nodes in
484  //the system. We can only deal with devices of type WifiNetDevice.
485  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
486  if (device == 0)
487  {
488  NS_LOG_INFO ("WifiHelper::EnablePcapInternal(): Device " << &device << " not of type ns3::WifiNetDevice");
489  return;
490  }
491 
492  Ptr<WifiPhy> phy = device->GetPhy ();
493  NS_ABORT_MSG_IF (phy == 0, "WifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
494 
495  PcapHelper pcapHelper;
496 
497  std::string filename;
498  if (explicitFilename)
499  {
500  filename = prefix;
501  }
502  else
503  {
504  filename = pcapHelper.GetFilenameFromDevice (prefix, device);
505  }
506 
507  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
508 
509  phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&WifiPhyHelper::PcapSniffTxEvent, file));
510  phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&WifiPhyHelper::PcapSniffRxEvent, file));
511 }
512 
513 void
516  std::string prefix,
517  Ptr<NetDevice> nd,
518  bool explicitFilename)
519 {
520  //All of the ascii enable functions vector through here including the ones
521  //that are wandering through all of devices on perhaps all of the nodes in
522  //the system. We can only deal with devices of type WifiNetDevice.
523  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
524  if (device == 0)
525  {
526  NS_LOG_INFO ("WifiHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::WifiNetDevice");
527  return;
528  }
529 
530  //Our trace sinks are going to use packet printing, so we have to make sure
531  //that is turned on.
533 
534  uint32_t nodeid = nd->GetNode ()->GetId ();
535  uint32_t deviceid = nd->GetIfIndex ();
536  std::ostringstream oss;
537 
538  //If we are not provided an OutputStreamWrapper, we are expected to create
539  //one using the usual trace filename conventions and write our traces
540  //without a context since there will be one file per context and therefore
541  //the context would be redundant.
542  if (stream == 0)
543  {
544  //Set up an output stream object to deal with private ofstream copy
545  //constructor and lifetime issues. Let the helper decide the actual
546  //name of the file given the prefix.
547  AsciiTraceHelper asciiTraceHelper;
548 
549  std::string filename;
550  if (explicitFilename)
551  {
552  filename = prefix;
553  }
554  else
555  {
556  filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
557  }
558 
559  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
560  //We could go poking through the phy and the state looking for the
561  //correct trace source, but we can let Config deal with that with
562  //some search cost. Since this is presumably happening at topology
563  //creation time, it doesn't seem much of a price to pay.
564  oss.str ("");
565  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
567 
568  oss.str ("");
569  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
571 
572  return;
573  }
574 
575  //If we are provided an OutputStreamWrapper, we are expected to use it, and
576  //to provide a context. We are free to come up with our own context if we
577  //want, and use the AsciiTraceHelper Hook*WithContext functions, but for
578  //compatibility and simplicity, we just use Config::Connect and let it deal
579  //with coming up with a context.
580  oss.str ("");
581  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
583 
584  oss.str ("");
585  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
587 }
588 
590 {
591 }
592 
594  : m_standard (WIFI_PHY_STANDARD_80211a)
595 {
596  SetRemoteStationManager ("ns3::ArfWifiManager");
597 }
598 
599 void
601  std::string n0, const AttributeValue &v0,
602  std::string n1, const AttributeValue &v1,
603  std::string n2, const AttributeValue &v2,
604  std::string n3, const AttributeValue &v3,
605  std::string n4, const AttributeValue &v4,
606  std::string n5, const AttributeValue &v5,
607  std::string n6, const AttributeValue &v6,
608  std::string n7, const AttributeValue &v7)
609 {
612  m_stationManager.Set (n0, v0);
613  m_stationManager.Set (n1, v1);
614  m_stationManager.Set (n2, v2);
615  m_stationManager.Set (n3, v3);
616  m_stationManager.Set (n4, v4);
617  m_stationManager.Set (n5, v5);
618  m_stationManager.Set (n6, v6);
619  m_stationManager.Set (n7, v7);
620 }
621 
622 void
624 {
625  m_standard = standard;
626 }
627 
630  const WifiMacHelper &macHelper,
632  NodeContainer::Iterator last) const
633 {
635  for (NodeContainer::Iterator i = first; i != last; ++i)
636  {
637  Ptr<Node> node = *i;
638  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
640  Ptr<WifiMac> mac = macHelper.Create ();
641  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
642  mac->SetAddress (Mac48Address::Allocate ());
643  mac->ConfigureStandard (m_standard);
644  phy->ConfigureStandard (m_standard);
645  device->SetMac (mac);
646  device->SetPhy (phy);
647  device->SetRemoteStationManager (manager);
648  node->AddDevice (device);
649  devices.Add (device);
650  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
651  }
652  return devices;
653 }
654 
657  const WifiMacHelper &macHelper, NodeContainer c) const
658 {
659  return Install (phyHelper, macHelper, c.Begin (), c.End ());
660 }
661 
664  const WifiMacHelper &mac, Ptr<Node> node) const
665 {
666  return Install (phy, mac, NodeContainer (node));
667 }
668 
671  const WifiMacHelper &mac, std::string nodeName) const
672 {
673  Ptr<Node> node = Names::Find<Node> (nodeName);
674  return Install (phy, mac, NodeContainer (node));
675 }
676 
677 void
679 {
680  LogComponentEnable ("AarfWifiManager", LOG_LEVEL_ALL);
681  LogComponentEnable ("AarfcdWifiManager", LOG_LEVEL_ALL);
682  LogComponentEnable ("AdhocWifiMac", LOG_LEVEL_ALL);
683  LogComponentEnable ("AmrrWifiManager", LOG_LEVEL_ALL);
684  LogComponentEnable ("ApWifiMac", LOG_LEVEL_ALL);
685  LogComponentEnable ("AparfWifiManager", LOG_LEVEL_ALL);
686  LogComponentEnable ("ArfWifiManager", LOG_LEVEL_ALL);
687  LogComponentEnable ("BlockAckAgreement", LOG_LEVEL_ALL);
688  LogComponentEnable ("BlockAckCache", LOG_LEVEL_ALL);
689  LogComponentEnable ("BlockAckManager", LOG_LEVEL_ALL);
690  LogComponentEnable ("CaraWifiManager", LOG_LEVEL_ALL);
691  LogComponentEnable ("ConstantRateWifiManager", LOG_LEVEL_ALL);
693  LogComponentEnable ("ChannelAccessManager", LOG_LEVEL_ALL);
694  LogComponentEnable ("DsssErrorRateModel", LOG_LEVEL_ALL);
695  LogComponentEnable ("QosTxop", LOG_LEVEL_ALL);
696  LogComponentEnable ("IdealWifiManager", LOG_LEVEL_ALL);
697  LogComponentEnable ("InfrastructureWifiMac", LOG_LEVEL_ALL);
698  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
699  LogComponentEnable ("MacLow", LOG_LEVEL_ALL);
700  LogComponentEnable ("MacRxMiddle", LOG_LEVEL_ALL);
701  LogComponentEnable ("MacTxMiddle", LOG_LEVEL_ALL);
702  LogComponentEnable ("MinstrelHtWifiManager", LOG_LEVEL_ALL);
703  LogComponentEnable ("MinstrelWifiManager", LOG_LEVEL_ALL);
704  LogComponentEnable ("MpduAggregator", LOG_LEVEL_ALL);
705  LogComponentEnable ("MsduAggregator", LOG_LEVEL_ALL);
706  LogComponentEnable ("NistErrorRateModel", LOG_LEVEL_ALL);
707  LogComponentEnable ("OnoeWifiManager", LOG_LEVEL_ALL);
708  LogComponentEnable ("ParfWifiManager", LOG_LEVEL_ALL);
709  LogComponentEnable ("RegularWifiMac", LOG_LEVEL_ALL);
710  LogComponentEnable ("RraaWifiManager", LOG_LEVEL_ALL);
711  LogComponentEnable ("RrpaaWifiManager", LOG_LEVEL_ALL);
712  LogComponentEnable ("SpectrumWifiPhy", LOG_LEVEL_ALL);
713  LogComponentEnable ("StaWifiMac", LOG_LEVEL_ALL);
714  LogComponentEnable ("SupportedRates", LOG_LEVEL_ALL);
715  LogComponentEnable ("WifiMac", LOG_LEVEL_ALL);
716  LogComponentEnable ("WifiMacQueueItem", LOG_LEVEL_ALL);
717  LogComponentEnable ("WifiNetDevice", LOG_LEVEL_ALL);
718  LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL);
719  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
720  LogComponentEnable ("WifiRadioEnergyModel", LOG_LEVEL_ALL);
721  LogComponentEnable ("WifiRemoteStationManager", LOG_LEVEL_ALL);
722  LogComponentEnable ("WifiSpectrumPhyInterface", LOG_LEVEL_ALL);
723  LogComponentEnable ("WifiSpectrumSignalParameters", LOG_LEVEL_ALL);
724  LogComponentEnable ("WifiTxCurrentModel", LOG_LEVEL_ALL);
725  LogComponentEnable ("YansErrorRateModel", LOG_LEVEL_ALL);
726  LogComponentEnable ("YansWifiChannel", LOG_LEVEL_ALL);
727  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
728 }
729 
730 int64_t
732 {
733  int64_t currentStream = stream;
734  Ptr<NetDevice> netDevice;
735  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
736  {
737  netDevice = (*i);
738  Ptr<WifiNetDevice> wifi = DynamicCast<WifiNetDevice> (netDevice);
739  if (wifi)
740  {
741  //Handle any random numbers in the PHY objects.
742  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
743 
744  //Handle any random numbers in the station managers.
745  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
746  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
747  if (minstrel)
748  {
749  currentStream += minstrel->AssignStreams (currentStream);
750  }
751 
752  Ptr<MinstrelHtWifiManager> minstrelHt = DynamicCast<MinstrelHtWifiManager> (manager);
753  if (minstrelHt)
754  {
755  currentStream += minstrelHt->AssignStreams (currentStream);
756  }
757 
758  //Handle any random numbers in the MAC objects.
759  Ptr<WifiMac> mac = wifi->GetMac ();
760  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
761  if (rmac)
762  {
763  PointerValue ptr;
764  rmac->GetAttribute ("Txop", ptr);
765  Ptr<Txop> txop = ptr.Get<Txop> ();
766  currentStream += txop->AssignStreams (currentStream);
767 
768  rmac->GetAttribute ("VO_Txop", ptr);
769  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
770  currentStream += vo_txop->AssignStreams (currentStream);
771 
772  rmac->GetAttribute ("VI_Txop", ptr);
773  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
774  currentStream += vi_txop->AssignStreams (currentStream);
775 
776  rmac->GetAttribute ("BE_Txop", ptr);
777  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
778  currentStream += be_txop->AssignStreams (currentStream);
779 
780  rmac->GetAttribute ("BK_Txop", ptr);
781  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
782  currentStream += bk_txop->AssignStreams (currentStream);
783 
784  //if an AP, handle any beacon jitter
785  Ptr<ApWifiMac> apmac = DynamicCast<ApWifiMac> (rmac);
786  if (apmac)
787  {
788  currentStream += apmac->AssignStreams (currentStream);
789  }
790  }
791  }
792  }
793  return (currentStream - stream);
794 }
795 
796 } //namespace ns3
virtual ~WifiPhyHelper()
Definition: wifi-helper.cc:129
MpduInfo structure.
Definition: wifi-phy.h:53
WifiPhyStandard m_standard
wifi standard
Definition: wifi-helper.h:362
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:134
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.
double signal
in dBm
Definition: wifi-phy.h:48
bool IsAggregation(void) const
Checks whether the PSDU contains A-MPDU.
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 "...
#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).
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:629
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:109
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:600
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Radiotap header implementation.
virtual ~WifiHelper()
Definition: wifi-helper.cc:589
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:219
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:90
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
bool IsStbc(void) const
Check if STBC is used or not.
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:88
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
uint8_t GetNess(void) const
uint16_t GetGuardInterval(void) const
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we&#39;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
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
ObjectFactory m_errorRateModel
error rate model
Definition: wifi-helper.h:168
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:593
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:514
phy
Definition: third.py:86
static void PcapSniffTxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu)
Definition: wifi-helper.cc:163
WifiPreamble GetPreambleType(void) const
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:623
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
Keep track of the current position and velocity of an object.
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
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
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
bool GetEof(void) const
Return the EOF field.
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.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:305
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
This frame is the last subframe.
void SetChannelFrequencyAndFlags(uint16_t frequency, uint16_t flags)
Set the transmit/receive channel frequency and flags.
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:92
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:195
WifiMode GetMode(void) const
Introspection did not find any typical Config paths.
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:731
Hold together all Wifi-related objects.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:832
PcapHelper::DataLinkType GetPcapDataLinkType(void) const
Get the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:472
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:500
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< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
void SetRate(uint8_t rate)
Set the transmit/receive channel frequency in units of megahertz.
static RadiotapHeader GetRadiotapHeader(Ptr< Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu)
Get the radiotap header.
Definition: wifi-helper.cc:230
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<T>.
Definition: pointer.h:36
Ness data - bit 1 (MSB) of Number of extension spatial streams.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
virtual Ptr< WifiMac > Create(void) const
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:361
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:453
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:140
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)
Enable pcap output the indicated net device.
Definition: wifi-helper.cc:478
ObjectFactory m_phy
PHY object.
Definition: wifi-helper.h:167
Space-time block coding (1 if all spatial streams of all users have STBC, 0 otherwise).
wifi
Definition: third.py:89
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:678
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:46
uint32_t mpduRefNumber
MPDU ref number.
Definition: wifi-phy.h:56
The MPDU is the last aggregate in an A-MPDU.
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:270
IEEE 802.11 Wireless LAN headers on packets.
Definition: wifi-helper.h:109
Ptr< T > Get(void) const
Definition: pointer.h:194
uint16_t GetLength(void) const
Return the length field.
Last subframe is known (should be set for all subframes in an A-MPDU)
Print everything.
Definition: log.h:113
double noise
in dBm
Definition: wifi-phy.h:49
uint16_t GetChannelWidth(void) const
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
devices
Definition: first.py:32
Definition: first.py:1
MpduType type
type
Definition: wifi-phy.h:55
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:478
void SetAmpduStatus(uint32_t referenceNumber, uint16_t flags, uint8_t crc)
Set the A-MPDU status fields.
void SetHeFields(uint16_t data1, uint16_t data2, uint16_t data3, uint16_t data5)
Set the HE fields.
Include Radiotap link layer information.
Definition: wifi-helper.h:111
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:46
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
HE PHY (Clause 26)
Definition: wifi-mode.h:62
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
uint8_t GetNss(void) const
void SetAntennaSignalPower(double signal)
Set the RF signal power at the antenna as a decibel difference from an arbitrary, fixed reference...
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:64
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:67