A Discrete-Event Network Simulator
API
wifi-helper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  * Copyright (c) 2009 MIRKO BANCHI
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Mirko Banchi <mk.banchi@gmail.com>
20  */
21 
22 #ifndef WIFI_HELPER_H
23 #define WIFI_HELPER_H
24 
25 #include "wifi-mac-helper.h"
26 
27 #include "ns3/deprecated.h"
28 #include "ns3/qos-utils.h"
29 #include "ns3/trace-helper.h"
30 #include "ns3/wifi-phy.h"
31 
32 #include <functional>
33 #include <vector>
34 
35 namespace ns3
36 {
37 
38 class WifiNetDevice;
39 class Node;
40 class RadiotapHeader;
41 class QueueItem;
42 
50 {
51  public:
57  WifiPhyHelper(uint8_t nLinks = 1);
58  ~WifiPhyHelper() override;
59 
69  virtual std::vector<Ptr<WifiPhy>> Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const = 0;
70 
77  void Set(std::string name, const AttributeValue& v);
78 
86  void Set(uint8_t linkId, std::string name, const AttributeValue& v);
87 
95  template <typename... Args>
96  void SetInterferenceHelper(std::string type, Args&&... args);
97 
105  template <typename... Args>
106  void SetErrorRateModel(std::string type, Args&&... args);
107 
116  template <typename... Args>
117  void SetErrorRateModel(uint8_t linkId, std::string type, Args&&... args);
118 
126  template <typename... Args>
127  void SetFrameCaptureModel(std::string type, Args&&... args);
128 
138  template <typename... Args>
139  void SetFrameCaptureModel(uint8_t linkId, std::string type, Args&&... args);
140 
148  template <typename... Args>
149  void SetPreambleDetectionModel(std::string type, Args&&... args);
150 
160  template <typename... Args>
161  void SetPreambleDetectionModel(uint8_t linkId, std::string type, Args&&... args);
162 
167 
174  {
181  };
182 
193 
202 
203  protected:
215  Ptr<const Packet> packet,
216  uint16_t channelFreqMhz,
217  WifiTxVector txVector,
218  MpduInfo aMpdu,
219  uint16_t staId = SU_STA_ID);
232  Ptr<const Packet> packet,
233  uint16_t channelFreqMhz,
234  WifiTxVector txVector,
235  MpduInfo aMpdu,
236  SignalNoiseDbm signalNoise,
237  uint16_t staId = SU_STA_ID);
238 
239  std::vector<ObjectFactory> m_phy;
241  std::vector<ObjectFactory> m_errorRateModel;
242  std::vector<ObjectFactory> m_frameCaptureModel;
243  std::vector<ObjectFactory> m_preambleDetectionModel;
244 
245  private:
256  static void GetRadiotapHeader(RadiotapHeader& header,
257  Ptr<Packet> packet,
258  uint16_t channelFreqMhz,
259  WifiTxVector txVector,
260  MpduInfo aMpdu,
261  uint16_t staId);
262 
274  static void GetRadiotapHeader(RadiotapHeader& header,
275  Ptr<Packet> packet,
276  uint16_t channelFreqMhz,
277  WifiTxVector txVector,
278  MpduInfo aMpdu,
279  uint16_t staId,
280  SignalNoiseDbm signalNoise);
281 
293  void EnablePcapInternal(std::string prefix,
294  Ptr<NetDevice> nd,
295  bool promiscuous,
296  bool explicitFilename) override;
297 
310  std::string prefix,
311  Ptr<NetDevice> nd,
312  bool explicitFilename) override;
313 
315 };
316 
325 {
326  public:
327  virtual ~WifiHelper();
328 
337  WifiHelper();
338 
346  template <typename... Args>
347  void SetRemoteStationManager(std::string type, Args&&... args);
348 
361  template <typename... Args>
362  void SetRemoteStationManager(uint8_t linkId, std::string type, Args&&... args);
363 
371  template <typename... Args>
372  void SetObssPdAlgorithm(std::string type, Args&&... args);
373 
375  typedef std::function<std::size_t(Ptr<QueueItem>)> SelectQueueCallback;
376 
384 
393  void DisableFlowControl();
394 
403  const WifiMacHelper& mac,
405  NodeContainer::Iterator last) const;
413  const WifiMacHelper& mac,
414  NodeContainer c) const;
422  const WifiMacHelper& mac,
423  Ptr<Node> node) const;
431  const WifiMacHelper& mac,
432  std::string nodeName) const;
457  virtual void SetStandard(WifiStandard standard);
458 
466  template <typename... Args>
467  void ConfigHtOptions(Args&&... args);
468 
476  template <typename... Args>
477  void ConfigVhtOptions(Args&&... args);
478 
486  template <typename... Args>
487  void ConfigHeOptions(Args&&... args);
488 
496  template <typename... Args>
497  void ConfigEhtOptions(Args&&... args);
498 
502  static void EnableLogComponents();
503 
518  int64_t AssignStreams(NetDeviceContainer c, int64_t stream);
519 
520  protected:
521  mutable std::vector<ObjectFactory> m_stationManager;
530 };
531 
532 } // namespace ns3
533 
534 /***************************************************************
535  * Implementation of the templates declared above.
536  ***************************************************************/
537 
538 namespace ns3
539 {
540 
541 template <typename... Args>
542 void
544 {
547 }
548 
549 template <typename... Args>
550 void
552 {
553  for (std::size_t linkId = 0; linkId < m_phy.size(); linkId++)
554  {
555  SetErrorRateModel(linkId, type, std::forward<Args>(args)...);
556  }
557 }
558 
559 template <typename... Args>
560 void
561 WifiPhyHelper::SetErrorRateModel(uint8_t linkId, std::string type, Args&&... args)
562 {
563  m_errorRateModel.at(linkId).SetTypeId(type);
564  m_errorRateModel.at(linkId).Set(args...);
565 }
566 
567 template <typename... Args>
568 void
570 {
571  for (std::size_t linkId = 0; linkId < m_phy.size(); linkId++)
572  {
573  SetFrameCaptureModel(linkId, type, std::forward<Args>(args)...);
574  }
575 }
576 
577 template <typename... Args>
578 void
579 WifiPhyHelper::SetFrameCaptureModel(uint8_t linkId, std::string type, Args&&... args)
580 {
581  m_frameCaptureModel.at(linkId).SetTypeId(type);
582  m_frameCaptureModel.at(linkId).Set(args...);
583 }
584 
585 template <typename... Args>
586 void
588 {
589  for (std::size_t linkId = 0; linkId < m_phy.size(); linkId++)
590  {
591  SetPreambleDetectionModel(linkId, type, std::forward<Args>(args)...);
592  }
593 }
594 
595 template <typename... Args>
596 void
597 WifiPhyHelper::SetPreambleDetectionModel(uint8_t linkId, std::string type, Args&&... args)
598 {
599  m_preambleDetectionModel.at(linkId).SetTypeId(type);
600  m_preambleDetectionModel.at(linkId).Set(args...);
601 }
602 
603 template <typename... Args>
604 void
606 {
607  SetRemoteStationManager(0, type, std::forward<Args>(args)...);
608 }
609 
610 template <typename... Args>
611 void
612 WifiHelper::SetRemoteStationManager(uint8_t linkId, std::string type, Args&&... args)
613 {
614  if (m_stationManager.size() > linkId)
615  {
616  m_stationManager[linkId] = ObjectFactory(type, std::forward<Args>(args)...);
617  }
618  else
619  {
620  m_stationManager.resize(linkId + 1, ObjectFactory(type, std::forward<Args>(args)...));
621  }
622 }
623 
624 template <typename... Args>
625 void
626 WifiHelper::SetObssPdAlgorithm(std::string type, Args&&... args)
627 {
630 }
631 
632 template <typename... Args>
633 void
635 {
636  m_htConfig.Set(args...);
637 }
638 
639 template <typename... Args>
640 void
642 {
643  m_vhtConfig.Set(args...);
644 }
645 
646 template <typename... Args>
647 void
649 {
650  m_heConfig.Set(args...);
651 }
652 
653 template <typename... Args>
654 void
656 {
657  m_ehtConfig.Set(args...);
658 }
659 
660 } // namespace ns3
661 
662 #endif /* WIFI_HELPER_H */
double f(double x, void *params)
Definition: 80211b.c:71
Base class providing common user-level ascii trace operations for helpers representing net devices.
Definition: trace-helper.h:728
Hold a value for an Attribute.
Definition: attribute.h:70
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Instantiate subclasses of ns3::Object.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Base class providing common user-level pcap operations for helpers representing net devices.
Definition: trace-helper.h:623
DataLinkType
This enumeration holds the data link types that will be written to the pcap file.
Definition: trace-helper.h:51
Radiotap header implementation.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:325
virtual ~WifiHelper()
Definition: wifi-helper.cc:721
void SetRemoteStationManager(std::string type, Args &&... args)
Helper function used to set the station manager.
Definition: wifi-helper.h:605
void ConfigEhtOptions(Args &&... args)
Helper function used to configure the EHT options listed as attributes of the EhtConfiguration class.
Definition: wifi-helper.h:655
void SetObssPdAlgorithm(std::string type, Args &&... args)
Helper function used to set the OBSS-PD algorithm.
Definition: wifi-helper.h:626
void ConfigHtOptions(Args &&... args)
Helper function used to configure the HT options listed as attributes of the HtConfiguration class.
Definition: wifi-helper.h:634
ObjectFactory m_htConfig
HT configuration.
Definition: wifi-helper.h:523
void ConfigHeOptions(Args &&... args)
Helper function used to configure the HE options listed as attributes of the HeConfiguration class.
Definition: wifi-helper.h:648
ObjectFactory m_obssPdAlgorithm
OBSS_PD algorithm.
Definition: wifi-helper.h:528
ObjectFactory m_ehtConfig
EHT configuration.
Definition: wifi-helper.h:526
void ConfigVhtOptions(Args &&... args)
Helper function used to configure the VHT options listed as attributes of the VhtConfiguration class.
Definition: wifi-helper.h:641
ObjectFactory m_vhtConfig
VHT configuration.
Definition: wifi-helper.h:524
void SetSelectQueueCallback(SelectQueueCallback f)
Definition: wifi-helper.cc:750
std::vector< ObjectFactory > m_stationManager
station manager
Definition: wifi-helper.h:521
WifiStandard m_standard
wifi standard
Definition: wifi-helper.h:522
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:982
virtual void SetStandard(WifiStandard standard)
Definition: wifi-helper.cc:738
ObjectFactory m_heConfig
HE configuration.
Definition: wifi-helper.h:525
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:756
void DisableFlowControl()
Disable flow control only if you know what you are doing.
Definition: wifi-helper.cc:744
SelectQueueCallback m_selectQueueCallback
select queue callback
Definition: wifi-helper.h:527
static void EnableLogComponents()
Helper to enable all WifiNetDevice log components with one statement.
Definition: wifi-helper.cc:880
bool m_enableFlowControl
whether to enable flow control
Definition: wifi-helper.h:529
WifiHelper()
Create a Wifi helper in an empty state: all its parameters must be set before calling ns3::WifiHelper...
Definition: wifi-helper.cc:725
std::function< std::size_t(Ptr< QueueItem >)> SelectQueueCallback
Callback invoked to determine the MAC queue selected for a given packet.
Definition: wifi-helper.h:375
create MAC layers for a ns3::WifiNetDevice.
create PHY objects
Definition: wifi-helper.h:50
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:543
void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename) override
Enable ASCII trace output on the indicated net device.
Definition: wifi-helper.cc:624
WifiPhyHelper(uint8_t nLinks=1)
Constructor.
Definition: wifi-helper.cc:146
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:163
~WifiPhyHelper() override
Definition: wifi-helper.cc:158
void DisablePreambleDetectionModel()
Disable the preamble detection model on all links.
Definition: wifi-helper.cc:178
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
Definition: wifi-helper.h:551
void SetInterferenceHelper(std::string type, Args &&... args)
Helper function used to set the interference helper.
Definition: wifi-helper.h:543
void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename) override
Enable pcap output the indicated net device.
Definition: wifi-helper.cc:568
PcapHelper::DataLinkType m_pcapDlt
PCAP data link type.
Definition: wifi-helper.h:314
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
Definition: wifi-helper.h:242
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
Definition: wifi-helper.h:243
PcapHelper::DataLinkType GetPcapDataLinkType() const
Get the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:562
static void PcapSniffRxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId=SU_STA_ID)
Definition: wifi-helper.cc:218
void SetFrameCaptureModel(std::string type, Args &&... args)
Helper function used to set the frame capture model.
Definition: wifi-helper.h:569
std::vector< ObjectFactory > m_phy
PHY object.
Definition: wifi-helper.h:239
virtual std::vector< Ptr< WifiPhy > > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const =0
void SetPreambleDetectionModel(std::string type, Args &&... args)
Helper function used to set the preamble detection model.
Definition: wifi-helper.h:587
static void PcapSniffTxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, uint16_t staId=SU_STA_ID)
Definition: wifi-helper.cc:187
SupportedPcapDataLinkTypes
An enumeration of the pcap data link types (DLTs) which this helper supports.
Definition: wifi-helper.h:174
@ DLT_IEEE802_11
IEEE 802.11 Wireless LAN headers on packets.
Definition: wifi-helper.h:175
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:179
@ DLT_PRISM_HEADER
Include Prism monitor mode information.
Definition: wifi-helper.h:177
std::vector< ObjectFactory > m_errorRateModel
error rate model
Definition: wifi-helper.h:241
ObjectFactory m_interferenceHelper
interference helper
Definition: wifi-helper.h:240
static void GetRadiotapHeader(RadiotapHeader &header, Ptr< Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, uint16_t staId)
Get the Radiotap header for a transmitted packet.
Definition: wifi-helper.cc:264
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:85
phy
Definition: third.py:82
MpduInfo structure.
Definition: phy-entity.h:63
SignalNoiseDbm structure.
Definition: phy-entity.h:56
#define SU_STA_ID
Definition: wifi-mode.h:34