A Discrete-Event Network Simulator
API
wave-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: Junling Bu <linlinjavaer@gmail.com>
17  */
18 #include "ns3/wifi-mac.h"
19 #include "ns3/wifi-phy.h"
20 #include "ns3/log.h"
21 #include "ns3/pointer.h"
22 #include "ns3/string.h"
23 #include "ns3/wifi-mode.h"
24 #include "ns3/config.h"
25 #include "ns3/names.h"
26 #include "ns3/abort.h"
27 #include "ns3/ampdu-subframe-header.h"
28 #include "ns3/wave-net-device.h"
29 #include "ns3/minstrel-wifi-manager.h"
30 #include "ns3/radiotap-header.h"
31 #include "ns3/unused.h"
32 #include "wave-mac-helper.h"
33 #include "wave-helper.h"
34 
35 NS_LOG_COMPONENT_DEFINE ("WaveHelper");
36 
37 namespace ns3 {
38 
39 static void
42  std::string context,
44  WifiMode mode,
45  WifiPreamble preamble,
46  uint8_t txLevel)
47 {
48  NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
49  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
50 }
51 
52 static void
56  WifiMode mode,
57  WifiPreamble preamble,
58  uint8_t txLevel)
59 {
60  NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
61  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
62 }
63 
64 static void
67  std::string context,
69  double snr,
70  WifiMode mode,
71  enum WifiPreamble preamble)
72 {
73  NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
74  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
75 }
76 
77 static void
81  double snr,
82  WifiMode mode,
83  enum WifiPreamble preamble)
84 {
85  NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
86  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
87 }
88 
89 static void
92  Ptr<const Packet> packet,
93  uint16_t channelFreqMhz,
94  uint16_t channelNumber,
95  uint32_t rate,
96  WifiPreamble preamble,
97  WifiTxVector txVector,
98  struct mpduInfo aMpdu)
99 {
100  uint32_t dlt = file->GetDataLinkType ();
101 
102  switch (dlt)
103  {
105  file->Write (Simulator::Now (), packet);
106  return;
108  {
109  NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
110  return;
111  }
113  {
114  Ptr<Packet> p = packet->Copy ();
115  RadiotapHeader header;
116  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
117  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
118 
119  //Our capture includes the FCS, so we set the flag to say so.
121 
122  if (preamble == WIFI_PREAMBLE_SHORT)
123  {
125  }
126 
127  if (txVector.IsShortGuardInterval ())
128  {
130  }
131 
132  header.SetFrameFlags (frameFlags);
133  header.SetRate (rate);
134 
135  uint16_t channelFlags = 0;
136  switch (rate)
137  {
138  case 2: //1Mbps
139  case 4: //2Mbps
140  case 10: //5Mbps
141  case 22: //11Mbps
142  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
143  break;
144 
145  default:
146  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
147  break;
148  }
149 
150  if (channelFreqMhz < 2500)
151  {
153  }
154  else
155  {
157  }
158 
159  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
160 
161  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
162  {
163  uint8_t mcsRate = 0;
164  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
165  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
166 
168  mcsRate = rate - 128;
169 
171  if (txVector.GetChannelWidth () == 40000000)
172  {
174  }
175 
177  if (txVector.IsShortGuardInterval ())
178  {
180  }
181 
183  if (preamble == WIFI_PREAMBLE_HT_GF)
184  {
186  }
187 
188  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
189  if (txVector.GetNess () & 0x01) //bit 1
190  {
192  }
193  if (txVector.GetNess () & 0x02) //bit 2
194  {
196  }
197 
198  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
199 
200  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
201  if (txVector.IsStbc ())
202  {
204  }
205 
206  header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
207  }
208 
209  if (txVector.IsAggregation ())
210  {
211  uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
213  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
214  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
216  uint32_t extractedLength;
217  p->RemoveHeader (hdr);
218  extractedLength = hdr.GetLength ();
219  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
220  if (aMpdu.packetType == 2 || (hdr.GetEof () == true && hdr.GetLength () > 0))
221  {
222  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
223  }
224  header.SetAmpduStatus (aMpdu.referenceNumber, ampduStatusFlags, hdr.GetCrc ());
225  }
226 
227  if (preamble == WIFI_PREAMBLE_VHT)
228  {
229  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
230  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
231  uint8_t vhtBandwidth = 0;
232  uint8_t vhtMcsNss[4] = {0,0,0,0};
233  uint8_t vhtCoding = 0;
234  uint8_t vhtGroupId = 0;
235  uint16_t vhtPartialAid = 0;
236 
237  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
238  if (txVector.IsStbc ())
239  {
240  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
241  }
242 
244  if (txVector.IsShortGuardInterval ())
245  {
247  }
248 
249  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
250 
252  //not all bandwidth values are currently supported
253  if (txVector.GetChannelWidth () == 40000000)
254  {
255  vhtBandwidth = 1;
256  }
257  else if (txVector.GetChannelWidth () == 80000000)
258  {
259  vhtBandwidth = 4;
260  }
261  else if (txVector.GetChannelWidth () == 160000000)
262  {
263  vhtBandwidth = 11;
264  }
265 
266  //only SU PPDUs are currently supported
267  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
268  vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
269 
270  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
271  }
272 
273  p->AddHeader (header);
274  file->Write (Simulator::Now (), p);
275  return;
276  }
277  default:
278  NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
279  }
280 }
281 
282 static void
285  Ptr<const Packet> packet,
286  uint16_t channelFreqMhz,
287  uint16_t channelNumber,
288  uint32_t rate,
289  WifiPreamble preamble,
290  WifiTxVector txVector,
291  struct mpduInfo aMpdu,
292  struct signalNoiseDbm signalNoise)
293 {
294  uint32_t dlt = file->GetDataLinkType ();
295 
296  switch (dlt)
297  {
299  file->Write (Simulator::Now (), packet);
300  return;
302  {
303  NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
304  return;
305  }
307  {
308  Ptr<Packet> p = packet->Copy ();
309  RadiotapHeader header;
310  uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
311  header.SetTsft (Simulator::Now ().GetMicroSeconds ());
312 
313  //Our capture includes the FCS, so we set the flag to say so.
315 
316  if (preamble == WIFI_PREAMBLE_SHORT)
317  {
319  }
320 
321  if (txVector.IsShortGuardInterval ())
322  {
324  }
325 
326  header.SetFrameFlags (frameFlags);
327  header.SetRate (rate);
328 
329  uint16_t channelFlags = 0;
330  switch (rate)
331  {
332  case 2: //1Mbps
333  case 4: //2Mbps
334  case 10: //5Mbps
335  case 22: //11Mbps
336  channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
337  break;
338 
339  default:
340  channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
341  break;
342  }
343 
344  if (channelFreqMhz < 2500)
345  {
347  }
348  else
349  {
351  }
352 
353  header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
354 
355  header.SetAntennaSignalPower (signalNoise.signal);
356  header.SetAntennaNoisePower (signalNoise.noise);
357 
358  if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
359  {
360  uint8_t mcsRate = 0;
361  uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
362  uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
363 
365  mcsRate = rate - 128;
366 
368  if (txVector.GetChannelWidth () == 40000000)
369  {
371  }
372 
374  if (txVector.IsShortGuardInterval ())
375  {
377  }
378 
380  if (preamble == WIFI_PREAMBLE_HT_GF)
381  {
383  }
384 
385  mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
386  if (txVector.GetNess () & 0x01) //bit 1
387  {
389  }
390  if (txVector.GetNess () & 0x02) //bit 2
391  {
393  }
394 
395  mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
396 
397  mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
398  if (txVector.IsStbc ())
399  {
401  }
402 
403  header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
404  }
405 
406  if (txVector.IsAggregation ())
407  {
408  uint16_t ampduStatusFlags = 0;
410  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
411  /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
413  uint32_t extractedLength;
414  p->RemoveHeader (hdr);
415  extractedLength = hdr.GetLength ();
416  p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
417  if (aMpdu.packetType == 2 || (hdr.GetEof () == true && hdr.GetLength () > 0))
418  {
419  ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
420  }
421  header.SetAmpduStatus (aMpdu.referenceNumber, ampduStatusFlags, hdr.GetCrc ());
422  }
423 
424  if (preamble == WIFI_PREAMBLE_VHT)
425  {
426  uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
427  uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
428  uint8_t vhtBandwidth = 0;
429  uint8_t vhtMcsNss[4] = {0,0,0,0};
430  uint8_t vhtCoding = 0;
431  uint8_t vhtGroupId = 0;
432  uint16_t vhtPartialAid = 0;
433 
434  vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
435  if (txVector.IsStbc ())
436  {
437  vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
438  }
439 
441  if (txVector.IsShortGuardInterval ())
442  {
444  }
445 
446  vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
447 
449  //not all bandwidth values are currently supported
450  if (txVector.GetChannelWidth () == 40000000)
451  {
452  vhtBandwidth = 1;
453  }
454  else if (txVector.GetChannelWidth () == 80000000)
455  {
456  vhtBandwidth = 4;
457  }
458  else if (txVector.GetChannelWidth () == 160000000)
459  {
460  vhtBandwidth = 11;
461  }
462 
463  //only SU PPDUs are currently supported
464  vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
465  vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
466 
467  header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
468  }
469 
470  p->AddHeader (header);
471  file->Write (Simulator::Now (), p);
472  return;
473  }
474  default:
475  NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
476  }
477 }
478 
479 /****************************** YansWavePhyHelper ***********************************/
480 YansWavePhyHelper
482 {
483  YansWavePhyHelper helper;
484  helper.SetErrorRateModel ("ns3::NistErrorRateModel");
485  return helper;
486 }
487 
488 void
489 YansWavePhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
490 {
491  //
492  // All of the Pcap enable functions vector through here including the ones
493  // that are wandering through all of devices on perhaps all of the nodes in
494  // the system. We can only deal with devices of type WaveNetDevice.
495  //
496  Ptr<WaveNetDevice> device = nd->GetObject<WaveNetDevice> ();
497  if (device == 0)
498  {
499  NS_LOG_INFO ("YansWavePhyHelper::EnablePcapInternal(): Device " << &device << " not of type ns3::WaveNetDevice");
500  return;
501  }
502 
503  std::vector<Ptr<WifiPhy> > phys = device->GetPhys ();
504  NS_ABORT_MSG_IF (phys.size () == 0, "EnablePcapInternal(): Phy layer in WaveNetDevice must be set");
505 
506  PcapHelper pcapHelper;
507 
508  std::string filename;
509  if (explicitFilename)
510  {
511  filename = prefix;
512  }
513  else
514  {
515  filename = pcapHelper.GetFilenameFromDevice (prefix, device);
516  }
517 
518  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, GetPcapDataLinkType ());
519 
520  std::vector<Ptr<WifiPhy> >::iterator i;
521  for (i = phys.begin (); i != phys.end (); ++i)
522  {
523  Ptr<WifiPhy> phy = (*i);
524  phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
525  phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
526  }
527 }
528 
529 void
532  std::string prefix,
533  Ptr<NetDevice> nd,
534  bool explicitFilename)
535 {
536  //
537  // All of the ascii enable functions vector through here including the ones
538  // that are wandering through all of devices on perhaps all of the nodes in
539  // the system. We can only deal with devices of type WaveNetDevice.
540  //
541  Ptr<WaveNetDevice> device = nd->GetObject<WaveNetDevice> ();
542  if (device == 0)
543  {
544  NS_LOG_INFO ("EnableAsciiInternal(): Device " << device << " not of type ns3::WaveNetDevice");
545  return;
546  }
547 
548  //
549  // Our trace sinks are going to use packet printing, so we have to make sure
550  // that is turned on.
551  //
553 
554  uint32_t nodeid = nd->GetNode ()->GetId ();
555  uint32_t deviceid = nd->GetIfIndex ();
556  std::ostringstream oss;
557 
558  //
559  // If we are not provided an OutputStreamWrapper, we are expected to create
560  // one using the usual trace filename conventions and write our traces
561  // without a context since there will be one file per context and therefore
562  // the context would be redundant.
563  //
564  if (stream == 0)
565  {
566  //
567  // Set up an output stream object to deal with private ofstream copy
568  // constructor and lifetime issues. Let the helper decide the actual
569  // name of the file given the prefix.
570  //
571  AsciiTraceHelper asciiTraceHelper;
572 
573  std::string filename;
574  if (explicitFilename)
575  {
576  filename = prefix;
577  }
578  else
579  {
580  filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
581  }
582 
583  Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
584  //
585  // We could go poking through the phy and the state looking for the
586  // correct trace source, but we can let Config deal with that with
587  // some search cost. Since this is presumably happening at topology
588  // creation time, it doesn't seem much of a price to pay.
589  //
590  oss.str ("");
591  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/State/RxOk";
593 
594  oss.str ("");
595  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/State/Tx";
597 
598  return;
599  }
600 
601  //
602  // If we are provided an OutputStreamWrapper, we are expected to use it, and
603  // to provide a context. We are free to come up with our own context if we
604  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for
605  // compatibility and simplicity, we just use Config::Connect and let it deal
606  // with coming up with a context.
607  //
608  oss.str ("");
609  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/RxOk";
611 
612  oss.str ("");
613  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/State/Tx";
615 }
616 
617 /********************************** WaveHelper ******************************************/
619 {
620 }
621 
623 {
624 }
625 
628 {
629  WaveHelper helper;
630  // default 7 MAC entities and single PHY device.
632  helper.CreatePhys (1);
633  helper.SetChannelScheduler ("ns3::DefaultChannelScheduler");
634  helper.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
635  "DataMode", StringValue ("OfdmRate6MbpsBW10MHz"),
636  "ControlMode",StringValue ("OfdmRate6MbpsBW10MHz"),
637  "NonUnicastMode", StringValue ("OfdmRate6MbpsBW10MHz"));
638  return helper;
639 }
640 
641 void
642 WaveHelper::CreateMacForChannel (std::vector<uint32_t> channelNumbers)
643 {
644  if (channelNumbers.size () == 0)
645  {
646  NS_FATAL_ERROR ("the WAVE MAC entities is at least one");
647  }
648  for (std::vector<uint32_t>::iterator i = channelNumbers.begin (); i != channelNumbers.end (); ++i)
649  {
651  {
652  NS_FATAL_ERROR ("the channel number " << (*i) << " is not a valid WAVE channel number");
653  }
654  }
655  m_macsForChannelNumber = channelNumbers;
656 }
657 
658 void
659 WaveHelper::CreatePhys (uint32_t phys)
660 {
661  if (phys == 0)
662  {
663  NS_FATAL_ERROR ("the WAVE PHY entities is at least one");
664  }
666  {
667  NS_FATAL_ERROR ("the number of assigned WAVE PHY entities is more than the number of valid WAVE channels");
668  }
669  m_physNumber = phys;
670 }
671 
672 void
674  std::string n0, const AttributeValue &v0,
675  std::string n1, const AttributeValue &v1,
676  std::string n2, const AttributeValue &v2,
677  std::string n3, const AttributeValue &v3,
678  std::string n4, const AttributeValue &v4,
679  std::string n5, const AttributeValue &v5,
680  std::string n6, const AttributeValue &v6,
681  std::string n7, const AttributeValue &v7)
682 {
685  m_stationManager.Set (n0, v0);
686  m_stationManager.Set (n1, v1);
687  m_stationManager.Set (n2, v2);
688  m_stationManager.Set (n3, v3);
689  m_stationManager.Set (n4, v4);
690  m_stationManager.Set (n5, v5);
691  m_stationManager.Set (n6, v6);
692  m_stationManager.Set (n7, v7);
693 }
694 
695 void
697  std::string n0, const AttributeValue &v0,
698  std::string n1, const AttributeValue &v1,
699  std::string n2, const AttributeValue &v2,
700  std::string n3, const AttributeValue &v3,
701  std::string n4, const AttributeValue &v4,
702  std::string n5, const AttributeValue &v5,
703  std::string n6, const AttributeValue &v6,
704  std::string n7, const AttributeValue &v7)
705 {
708  m_channelScheduler.Set (n0, v0);
709  m_channelScheduler.Set (n1, v1);
710  m_channelScheduler.Set (n2, v2);
711  m_channelScheduler.Set (n3, v3);
712  m_channelScheduler.Set (n4, v4);
713  m_channelScheduler.Set (n5, v5);
714  m_channelScheduler.Set (n6, v6);
715  m_channelScheduler.Set (n7, v7);
716 }
717 
719 WaveHelper::Install (const WifiPhyHelper &phyHelper, const WifiMacHelper &macHelper, NodeContainer c) const
720 {
721  try
722  {
723  const QosWaveMacHelper& qosMac = dynamic_cast<const QosWaveMacHelper&> (macHelper);
724  NS_UNUSED (qosMac);
725  }
726  catch (const std::bad_cast &)
727  {
728  NS_FATAL_ERROR ("WifiMacHelper should be the class or subclass of QosWaveMacHelper");
729  }
730 
732  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
733  {
734  Ptr<Node> node = *i;
735  Ptr<WaveNetDevice> device = CreateObject<WaveNetDevice> ();
736 
737  device->SetChannelManager (CreateObject<ChannelManager> ());
738  device->SetChannelCoordinator (CreateObject<ChannelCoordinator> ());
739  device->SetVsaManager (CreateObject<VsaManager> ());
741 
742  for (uint32_t j = 0; j != m_physNumber; ++j)
743  {
744  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
747  device->AddPhy (phy);
748  }
749 
750  for (std::vector<uint32_t>::const_iterator k = m_macsForChannelNumber.begin ();
751  k != m_macsForChannelNumber.end (); ++k)
752  {
753  Ptr<WifiMac> wifiMac = macHelper.Create ();
754  Ptr<OcbWifiMac> ocbMac = DynamicCast<OcbWifiMac> (wifiMac);
755  // we use WaveMacLow to replace original MacLow
756  ocbMac->EnableForWave (device);
759  device->AddMac (*k, ocbMac);
760  }
761 
762  device->SetAddress (Mac48Address::Allocate ());
763 
764  node->AddDevice (device);
765  devices.Add (device);
766  }
767  return devices;
768 }
769 
772 {
773  return Install (phy, mac, NodeContainer (node));
774 }
775 
777 WaveHelper::Install (const WifiPhyHelper &phy, const WifiMacHelper &mac, std::string nodeName) const
778 {
779  Ptr<Node> node = Names::Find<Node> (nodeName);
780  return Install (phy, mac, NodeContainer (node));
781 }
782 
783 void
785 {
787 
788  LogComponentEnable ("WaveNetDevice", LOG_LEVEL_ALL);
789  LogComponentEnable ("ChannelCoordinator", LOG_LEVEL_ALL);
790  LogComponentEnable ("ChannelManager", LOG_LEVEL_ALL);
791  LogComponentEnable ("ChannelScheduler", LOG_LEVEL_ALL);
792  LogComponentEnable ("DefaultChannelScheduler", LOG_LEVEL_ALL);
793  LogComponentEnable ("VsaManager", LOG_LEVEL_ALL);
794  LogComponentEnable ("OcbWifiMac", LOG_LEVEL_ALL);
795  LogComponentEnable ("VendorSpecificAction", LOG_LEVEL_ALL);
796  LogComponentEnable ("WaveMacLow", LOG_LEVEL_ALL);
797  LogComponentEnable ("HigherLayerTxVectorTag", LOG_LEVEL_ALL);
798 }
799 
800 int64_t
802 {
803  int64_t currentStream = stream;
804  Ptr<NetDevice> netDevice;
805  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
806  {
807  netDevice = (*i);
808  Ptr<WaveNetDevice> wave = DynamicCast<WaveNetDevice> (netDevice);
809  if (wave)
810  {
811  // Handle any random numbers in the PHY objects.
812  std::vector<Ptr<WifiPhy> > phys = wave->GetPhys ();
813  for (std::vector<Ptr<WifiPhy> >::iterator j = phys.begin (); j != phys.end (); ++i)
814  {
815  currentStream += (*j)->AssignStreams (currentStream);
816  }
817 
818  // Handle any random numbers in the MAC objects.
819  std::map<uint32_t, Ptr<OcbWifiMac> > macs = wave->GetMacs ();
820  for ( std::map<uint32_t, Ptr<OcbWifiMac> >::iterator k = macs.begin (); k != macs.end (); ++k)
821  {
822  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (k->second);
823 
824  // Handle any random numbers in the station managers.
825  Ptr<WifiRemoteStationManager> manager = rmac->GetWifiRemoteStationManager ();
826  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
827  if (minstrel)
828  {
829  currentStream += minstrel->AssignStreams (currentStream);
830  }
831 
832  PointerValue ptr;
833  rmac->GetAttribute ("DcaTxop", ptr);
834  Ptr<DcaTxop> dcaTxop = ptr.Get<DcaTxop> ();
835  currentStream += dcaTxop->AssignStreams (currentStream);
836 
837  rmac->GetAttribute ("VO_EdcaTxopN", ptr);
838  Ptr<EdcaTxopN> vo_edcaTxopN = ptr.Get<EdcaTxopN> ();
839  currentStream += vo_edcaTxopN->AssignStreams (currentStream);
840 
841  rmac->GetAttribute ("VI_EdcaTxopN", ptr);
842  Ptr<EdcaTxopN> vi_edcaTxopN = ptr.Get<EdcaTxopN> ();
843  currentStream += vi_edcaTxopN->AssignStreams (currentStream);
844 
845  rmac->GetAttribute ("BE_EdcaTxopN", ptr);
846  Ptr<EdcaTxopN> be_edcaTxopN = ptr.Get<EdcaTxopN> ();
847  currentStream += be_edcaTxopN->AssignStreams (currentStream);
848 
849  rmac->GetAttribute ("BK_EdcaTxopN", ptr);
850  Ptr<EdcaTxopN> bk_edcaTxopN = ptr.Get<EdcaTxopN> ();
851  currentStream += bk_edcaTxopN->AssignStreams (currentStream);
852  }
853  }
854  }
855  return (currentStream - stream);
856 }
857 } // namespace ns3
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:266
uint32_t GetPcapDataLinkType(void) const
Get the data link type of PCAP traces to be used.
static void EnableLogComponents(void)
Helper to enable all WaveNetDevice log components with one statement.
Definition: wave-helper.cc:784
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
void CreateMacForChannel(std::vector< uint32_t > channelNumbers)
Definition: wave-helper.cc:642
ObjectFactory m_channelScheduler
Definition: wave-helper.h:246
Ptr< T > Get(void) const
Definition: pointer.h:194
Manage ASCII trace files for device models.
Definition: trace-helper.h:155
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static std::vector< uint32_t > GetWaveChannels(void)
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())
tuple devices
Definition: first.py:32
virtual void ConfigureStandard(enum WifiPhyStandard standard)=0
Configure the PHY-level parameters for different Wi-Fi standard.
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: wave-helper.cc:801
#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...
bool IsAggregation(void) const
Checks whether the PSDU contains A-MPDU.
static void AsciiPhyReceiveSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p, double snr, WifiMode mode, enum WifiPreamble preamble)
Definition: wave-helper.cc:78
virtual void SetWifiRemoteStationManager(Ptr< WifiRemoteStationManager > stationManager)
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Radiotap header implementation.
Hold variables of type string.
Definition: string.h:41
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:47
void Write(Time t, Ptr< const Packet > p)
Write the next packet to file.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1677
virtual Ptr< WifiMac > Create(void) const =0
void ConfigureStandard(enum WifiPhyStandard standard)
Definition: wifi-mac.cc:289
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
static bool IsWaveChannel(uint32_t channelNumber)
This frame is the last subframe.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
bool IsShortGuardInterval(void) const
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
This class holds together multiple, ns3::WifiPhy, and ns3::OcbWifiMac (including ns3::WifiRemoteStati...
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
static void AsciiPhyReceiveSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, double snr, WifiMode mode, enum WifiPreamble preamble)
Definition: wave-helper.cc:65
static WaveHelper Default(void)
Definition: wave-helper.cc:627
void EnableForWave(Ptr< WaveNetDevice > device)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
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...
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...
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wave-helper.cc:719
void SetTsft(uint64_t tsft)
Set the Time Synchronization Function Timer (TSFT) value.
virtual void SetAddress(Address address)
Set the address of this interface.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
Set if all spatial streams of all users have space-time block coding.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:228
Frame sent/received with short preamble.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
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: wave-helper.cc:673
This queue contains packets for a particular access class.
Definition: edca-txop-n.h:82
static uint32_t GetNumberOfWaveChannels(void)
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
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
std::vector< uint32_t > m_macsForChannelNumber
Definition: wave-helper.h:247
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
tuple phy
Definition: third.py:86
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:533
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)
Enable pcap output the indicated net device.
Definition: wave-helper.cc:489
uint8_t packetType
Definition: wifi-phy.h:50
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
void SetChannelScheduler(Ptr< ChannelScheduler > channelScheduler)
helps to create WaveNetDevice objects
Definition: wave-helper.h:110
void SetChannelFrequencyAndFlags(uint16_t frequency, uint16_t flags)
Set the transmit/receive channel frequency and flags.
virtual ~WaveHelper()
Definition: wave-helper.cc:622
void SetChannelManager(Ptr< ChannelManager > channelManager)
holds a vector of ns3::NetDevice pointers
uint8_t GetNess(void) const
uint32_t GetChannelWidth(void) const
uint8_t GetCrc(void) const
Return the CRC field.
Introspection did not find any typical Config paths.
void SetChannelScheduler(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: wave-helper.cc:696
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:824
Ness known (Number of extension spatial streams)
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Beamformed known/applicable (this flag should be set to zero for MU PPDUs).
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.
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)
Enable ascii trace output on the indicated net device.
Definition: wave-helper.cc:530
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
void SetFrameFlags(uint8_t flags)
Set the frame flags of the transmitted or received frame.
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:122
void SetRate(uint8_t rate)
Set the transmit/receive channel frequency in units of megahertz.
Space-time block coding (1 if all spatial streams of all users have STBC, 0 otherwise).
static void PcapSniffRxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, struct signalNoiseDbm signalNoise)
Definition: wave-helper.cc:283
static uint32_t GetCch(void)
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:299
std::map< uint32_t, Ptr< OcbWifiMac > > GetMacs(void) const
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
void CreatePhys(uint32_t phys)
Definition: wave-helper.cc:659
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Delimiter CRC value known: the delimiter CRC value field is valid.
Frame used short guard interval (HT)
Last subframe is known (should be set for all subframes in an A-MPDU)
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.
create MAC objects
Definition: wifi-helper.h:75
To trace WaveNetDevice, we have to overwrite the trace functions of class YansWifiPhyHelper.
Definition: wave-helper.h:39
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
virtual void SetChannelNumber(uint16_t id)=0
Set channel number.
std::vector< Ptr< WifiPhy > > GetPhys(void) const
void AddPhy(Ptr< WifiPhy > phy)
ObjectFactory m_stationManager
Definition: wave-helper.h:245
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.
static void EnableLogComponents(void)
Helper to enable all WifiNetDevice log components with one statement.
Definition: wifi-helper.cc:143
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:121
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
static YansWavePhyHelper Default(void)
Create a phy helper in a default working state.
Definition: wave-helper.cc:481
void SetVsaManager(Ptr< VsaManager > vsaManager)
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
void AddMac(uint32_t channelNumber, Ptr< OcbWifiMac > mac)
Default: 20 MHz, long guard interval, mixed HT format and BCC FEC type.
Print everything.
Definition: log.h:112
static void PcapSniffTxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu)
Definition: wave-helper.cc:90
Ness - bit 0 (LSB) of Number of extension spatial streams.
void SetChannelCoordinator(Ptr< ChannelCoordinator > channelCoordinator)
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
handle packet fragmentation and retransmissions.
Definition: dca-txop.h:67
void SetAmpduStatus(uint32_t referenceNumber, uint16_t flags, uint8_t crc)
Set the A-MPDU status fields.
bool GetEof(void) const
Return the EOF field.
static void AsciiPhyTransmitSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
Definition: wave-helper.cc:40
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:255
This class will assign channel access for requests from higher layers.
uint32_t referenceNumber
Definition: wifi-phy.h:51
uint32_t m_physNumber
Definition: wave-helper.h:248
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)
Definition: wave-helper.cc:53