A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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/qos-utils.h"
28#include "ns3/trace-helper.h"
29#include "ns3/wifi-phy.h"
30
31#include <functional>
32#include <vector>
33
34namespace ns3
35{
36
37class WifiNetDevice;
38class Node;
39class RadiotapHeader;
40class QueueItem;
41
49{
50 public:
56 WifiPhyHelper(uint8_t nLinks = 1);
57 ~WifiPhyHelper() override;
58
68 virtual std::vector<Ptr<WifiPhy>> Create(Ptr<Node> node, Ptr<WifiNetDevice> device) const = 0;
69
76 void Set(std::string name, const AttributeValue& v);
77
85 void Set(uint8_t linkId, std::string name, const AttributeValue& v);
86
94 template <typename... Args>
95 void SetInterferenceHelper(std::string type, Args&&... args);
96
104 template <typename... Args>
105 void SetErrorRateModel(std::string type, Args&&... args);
106
115 template <typename... Args>
116 void SetErrorRateModel(uint8_t linkId, std::string type, Args&&... args);
117
125 template <typename... Args>
126 void SetFrameCaptureModel(std::string type, Args&&... args);
127
137 template <typename... Args>
138 void SetFrameCaptureModel(uint8_t linkId, std::string type, Args&&... args);
139
147 template <typename... Args>
148 void SetPreambleDetectionModel(std::string type, Args&&... args);
149
159 template <typename... Args>
160 void SetPreambleDetectionModel(uint8_t linkId, std::string type, Args&&... args);
161
166
173 {
180 };
181
192
201
202 protected:
213 static void PcapSniffTxEvent(Ptr<PcapFileWrapper> file,
214 Ptr<const Packet> packet,
215 uint16_t channelFreqMhz,
216 WifiTxVector txVector,
217 MpduInfo aMpdu,
218 uint16_t staId = SU_STA_ID);
230 static void PcapSniffRxEvent(Ptr<PcapFileWrapper> file,
231 Ptr<const Packet> packet,
232 uint16_t channelFreqMhz,
233 WifiTxVector txVector,
234 MpduInfo aMpdu,
235 SignalNoiseDbm signalNoise,
236 uint16_t staId = SU_STA_ID);
237
238 std::vector<ObjectFactory> m_phys;
240 std::vector<ObjectFactory> m_errorRateModel;
241 std::vector<ObjectFactory> m_frameCaptureModel;
242 std::vector<ObjectFactory> m_preambleDetectionModel;
243
244 private:
255 static void GetRadiotapHeader(RadiotapHeader& header,
256 Ptr<Packet> packet,
257 uint16_t channelFreqMhz,
258 WifiTxVector txVector,
259 MpduInfo aMpdu,
260 uint16_t staId);
261
273 static void GetRadiotapHeader(RadiotapHeader& header,
274 Ptr<Packet> packet,
275 uint16_t channelFreqMhz,
276 WifiTxVector txVector,
277 MpduInfo aMpdu,
278 uint16_t staId,
279 SignalNoiseDbm signalNoise);
280
292 void EnablePcapInternal(std::string prefix,
294 bool promiscuous,
295 bool explicitFilename) override;
296
309 std::string prefix,
311 bool explicitFilename) override;
312
314};
315
324{
325 public:
326 virtual ~WifiHelper();
327
336 WifiHelper();
337
345 template <typename... Args>
346 void SetRemoteStationManager(std::string type, Args&&... args);
347
360 template <typename... Args>
361 void SetRemoteStationManager(uint8_t linkId, std::string type, Args&&... args);
362
370 template <typename... Args>
371 void SetObssPdAlgorithm(std::string type, Args&&... args);
372
374 typedef std::function<std::size_t(Ptr<QueueItem>)> SelectQueueCallback;
375
383
392 void DisableFlowControl();
393
401 NetDeviceContainer virtual Install(const WifiPhyHelper& phy,
402 const WifiMacHelper& mac,
404 NodeContainer::Iterator last) const;
411 virtual NetDeviceContainer Install(const WifiPhyHelper& phy,
412 const WifiMacHelper& mac,
413 NodeContainer c) const;
420 virtual NetDeviceContainer Install(const WifiPhyHelper& phy,
421 const WifiMacHelper& mac,
422 Ptr<Node> node) const;
429 virtual NetDeviceContainer Install(const WifiPhyHelper& phy,
430 const WifiMacHelper& mac,
431 std::string nodeName) const;
456 virtual void SetStandard(WifiStandard standard);
457
465 template <typename... Args>
466 void ConfigHtOptions(Args&&... args);
467
475 template <typename... Args>
476 void ConfigVhtOptions(Args&&... args);
477
485 template <typename... Args>
486 void ConfigHeOptions(Args&&... args);
487
495 template <typename... Args>
496 void ConfigEhtOptions(Args&&... args);
497
501 static void EnableLogComponents();
502
517 int64_t AssignStreams(NetDeviceContainer c, int64_t stream);
518
519 protected:
520 mutable std::vector<ObjectFactory> m_stationManager;
529};
530
531} // namespace ns3
532
533/***************************************************************
534 * Implementation of the templates declared above.
535 ***************************************************************/
536
537namespace ns3
538{
539
540template <typename... Args>
541void
542WifiPhyHelper::SetInterferenceHelper(std::string type, Args&&... args)
543{
545 m_interferenceHelper.Set(args...);
546}
547
548template <typename... Args>
549void
550WifiPhyHelper::SetErrorRateModel(std::string type, Args&&... args)
551{
552 for (std::size_t linkId = 0; linkId < m_phys.size(); linkId++)
553 {
554 SetErrorRateModel(linkId, type, std::forward<Args>(args)...);
555 }
556}
557
558template <typename... Args>
559void
560WifiPhyHelper::SetErrorRateModel(uint8_t linkId, std::string type, Args&&... args)
561{
562 m_errorRateModel.at(linkId).SetTypeId(type);
563 m_errorRateModel.at(linkId).Set(args...);
564}
565
566template <typename... Args>
567void
568WifiPhyHelper::SetFrameCaptureModel(std::string type, Args&&... args)
569{
570 for (std::size_t linkId = 0; linkId < m_phys.size(); linkId++)
571 {
572 SetFrameCaptureModel(linkId, type, std::forward<Args>(args)...);
573 }
574}
575
576template <typename... Args>
577void
578WifiPhyHelper::SetFrameCaptureModel(uint8_t linkId, std::string type, Args&&... args)
579{
580 m_frameCaptureModel.at(linkId).SetTypeId(type);
581 m_frameCaptureModel.at(linkId).Set(args...);
582}
583
584template <typename... Args>
585void
586WifiPhyHelper::SetPreambleDetectionModel(std::string type, Args&&... args)
587{
588 for (std::size_t linkId = 0; linkId < m_phys.size(); linkId++)
589 {
590 SetPreambleDetectionModel(linkId, type, std::forward<Args>(args)...);
591 }
592}
593
594template <typename... Args>
595void
596WifiPhyHelper::SetPreambleDetectionModel(uint8_t linkId, std::string type, Args&&... args)
597{
598 m_preambleDetectionModel.at(linkId).SetTypeId(type);
599 m_preambleDetectionModel.at(linkId).Set(args...);
600}
601
602template <typename... Args>
603void
604WifiHelper::SetRemoteStationManager(std::string type, Args&&... args)
605{
606 SetRemoteStationManager(0, type, std::forward<Args>(args)...);
607}
608
609template <typename... Args>
610void
611WifiHelper::SetRemoteStationManager(uint8_t linkId, std::string type, Args&&... args)
612{
613 if (m_stationManager.size() > linkId)
614 {
615 m_stationManager[linkId] = ObjectFactory(type, std::forward<Args>(args)...);
616 }
617 else
618 {
619 m_stationManager.resize(linkId + 1, ObjectFactory(type, std::forward<Args>(args)...));
620 }
621}
622
623template <typename... Args>
624void
625WifiHelper::SetObssPdAlgorithm(std::string type, Args&&... args)
626{
628 m_obssPdAlgorithm.Set(args...);
629}
630
631template <typename... Args>
632void
634{
635 m_htConfig.Set(args...);
636}
637
638template <typename... Args>
639void
641{
642 m_vhtConfig.Set(args...);
643}
644
645template <typename... Args>
646void
648{
649 m_heConfig.Set(args...);
650}
651
652template <typename... Args>
653void
655{
656 m_ehtConfig.Set(args...);
657}
658
659} // namespace ns3
660
661#endif /* WIFI_HELPER_H */
Base class providing common user-level ascii trace operations for helpers representing net devices.
Definition: trace-helper.h:729
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:624
DataLinkType
This enumeration holds the data link types that will be written to the pcap file.
Definition: trace-helper.h:52
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Radiotap header implementation.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
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:604
void ConfigEhtOptions(Args &&... args)
Helper function used to configure the EHT options listed as attributes of the EhtConfiguration class.
Definition: wifi-helper.h:654
void SetObssPdAlgorithm(std::string type, Args &&... args)
Helper function used to set the OBSS-PD algorithm.
Definition: wifi-helper.h:625
void ConfigHtOptions(Args &&... args)
Helper function used to configure the HT options listed as attributes of the HtConfiguration class.
Definition: wifi-helper.h:633
ObjectFactory m_htConfig
HT configuration.
Definition: wifi-helper.h:522
void ConfigHeOptions(Args &&... args)
Helper function used to configure the HE options listed as attributes of the HeConfiguration class.
Definition: wifi-helper.h:647
ObjectFactory m_obssPdAlgorithm
OBSS_PD algorithm.
Definition: wifi-helper.h:527
ObjectFactory m_ehtConfig
EHT configuration.
Definition: wifi-helper.h:525
void ConfigVhtOptions(Args &&... args)
Helper function used to configure the VHT options listed as attributes of the VhtConfiguration class.
Definition: wifi-helper.h:640
ObjectFactory m_vhtConfig
VHT configuration.
Definition: wifi-helper.h:523
void SetSelectQueueCallback(SelectQueueCallback f)
Definition: wifi-helper.cc:750
std::vector< ObjectFactory > m_stationManager
station manager
Definition: wifi-helper.h:520
WifiStandard m_standard
wifi standard
Definition: wifi-helper.h:521
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:988
virtual void SetStandard(WifiStandard standard)
Definition: wifi-helper.cc:738
ObjectFactory m_heConfig
HE configuration.
Definition: wifi-helper.h:524
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:526
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:528
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:374
create MAC layers for a ns3::WifiNetDevice.
create PHY objects
Definition: wifi-helper.h:49
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
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:550
void SetInterferenceHelper(std::string type, Args &&... args)
Helper function used to set the interference helper.
Definition: wifi-helper.h:542
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:313
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
Definition: wifi-helper.h:241
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
Definition: wifi-helper.h:242
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:568
std::vector< ObjectFactory > m_phys
PHY objects.
Definition: wifi-helper.h:238
void SetPreambleDetectionModel(std::string type, Args &&... args)
Helper function used to set the preamble detection model.
Definition: wifi-helper.h:586
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:173
@ DLT_IEEE802_11
IEEE 802.11 Wireless LAN headers on packets.
Definition: wifi-helper.h:174
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:178
@ DLT_PRISM_HEADER
Include Prism monitor mode information.
Definition: wifi-helper.h:176
std::vector< ObjectFactory > m_errorRateModel
error rate model
Definition: wifi-helper.h:240
virtual std::vector< Ptr< WifiPhy > > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const =0
ObjectFactory m_interferenceHelper
interference helper
Definition: wifi-helper.h:239
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.
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition: wifi-mode.h:35
MpduInfo structure.
Definition: phy-entity.h:62
SignalNoiseDbm structure.
Definition: phy-entity.h:55