24#include "ns3/ampdu-subframe-header.h"
25#include "ns3/ap-wifi-mac.h"
26#include "ns3/config.h"
27#include "ns3/eht-configuration.h"
28#include "ns3/he-configuration.h"
29#include "ns3/ht-configuration.h"
31#include "ns3/mobility-model.h"
33#include "ns3/net-device-queue-interface.h"
34#include "ns3/obss-pd-algorithm.h"
35#include "ns3/pointer.h"
36#include "ns3/qos-txop.h"
37#include "ns3/qos-utils.h"
38#include "ns3/radiotap-header.h"
39#include "ns3/sta-wifi-mac.h"
40#include "ns3/vht-configuration.h"
41#include "ns3/wifi-mac-queue.h"
42#include "ns3/wifi-mac-trailer.h"
43#include "ns3/wifi-net-device.h"
68 auto pCopy = p->Copy();
70 pCopy->RemoveTrailer(fcs);
72 <<
" " << *pCopy <<
" " << fcs << std::endl;
91 auto pCopy = p->Copy();
93 pCopy->RemoveTrailer(fcs);
95 <<
" " << fcs << std::endl;
116 auto pCopy = p->Copy();
118 pCopy->RemoveTrailer(fcs);
120 <<
" " << *pCopy <<
" " << fcs << std::endl;
139 auto pCopy = p->Copy();
141 pCopy->RemoveTrailer(fcs);
143 <<
" " << fcs << std::endl;
150 m_phy.resize(nLinks);
165 for (
auto& phy :
m_phy)
174 m_phy.at(linkId).Set(name, v);
182 preambleDetectionModel.SetTypeId(
TypeId());
189 uint16_t channelFreqMhz,
194 uint32_t dlt = file->GetDataLinkType();
201 NS_FATAL_ERROR(
"PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
208 p->AddHeader(header);
213 NS_ABORT_MSG(
"PcapSniffTxEvent(): Unexpected data link type " << dlt);
220 uint16_t channelFreqMhz,
226 uint32_t dlt = file->GetDataLinkType();
233 NS_FATAL_ERROR(
"PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
239 GetRadiotapHeader(header, p, channelFreqMhz, txVector, aMpdu, staId, signalNoise);
240 p->AddHeader(header);
245 NS_ABORT_MSG(
"PcapSniffRxEvent(): Unexpected data link type " << dlt);
252 uint16_t channelFreqMhz,
266 uint16_t channelFreqMhz,
299 txVector.
GetNss(staId) / 500000;
300 header.
SetRate(
static_cast<uint8_t
>(rate));
303 uint16_t channelFlags = 0;
317 if (channelFreqMhz < 2500)
377 packet->RemoveHeader(hdr);
379 packet = packet->CreateFragment(0,
static_cast<uint32_t>(extractedLength));
391 uint8_t vhtBandwidth = 0;
392 uint8_t vhtMcsNss[4] = {0, 0, 0, 0};
393 uint8_t vhtCoding = 0;
394 uint8_t vhtGroupId = 0;
395 uint16_t vhtPartialAid = 0;
427 vhtMcsNss[0] |= (txVector.
GetNss(staId) & 0x0f);
474 data4 |= ((staId << 4) & 0x7ff0);
529 header.
SetHeFields(data1, data2, data3, data4, data5, 0);
535 std::array<uint8_t, 4> ruChannel1;
536 std::array<uint8_t, 4> ruChannel2;
557 NS_ABORT_MSG(
"WifiPhyHelper::SetPcapFormat(): Unexpected format");
571 bool explicitFilename)
573 NS_LOG_FUNCTION(
this << prefix << nd << promiscuous << explicitFilename);
581 NS_LOG_INFO(
"WifiHelper::EnablePcapInternal(): Device "
582 << &device <<
" not of type ns3::WifiNetDevice");
587 "WifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
591 std::string filename;
592 if (explicitFilename)
603 auto pos = filename.find_last_of(
'.');
605 pos = (pos == std::string::npos) ? filename.size() : pos;
607 for (
auto& phy : device->GetPhys())
609 std::string tmp = filename;
610 if (device->GetNPhys() > 1)
613 tmp.insert(pos,
"-" + std::to_string(linkId++));
616 phy->TraceConnectWithoutContext(
"MonitorSnifferTx",
618 phy->TraceConnectWithoutContext(
"MonitorSnifferRx",
627 bool explicitFilename)
635 NS_LOG_INFO(
"WifiHelper::EnableAsciiInternal(): Device "
636 << device <<
" not of type ns3::WifiNetDevice");
644 uint32_t nodeid = nd->GetNode()->GetId();
645 uint32_t deviceid = nd->GetIfIndex();
646 std::ostringstream oss;
659 std::string filename;
660 if (explicitFilename)
670 auto pos = filename.find_last_of(
'.');
672 pos = (pos == std::string::npos) ? filename.size() : pos;
674 for (uint8_t linkId = 0; linkId < device->GetNPhys(); linkId++)
676 std::string tmp = filename;
677 if (device->GetNPhys() > 1)
680 tmp.insert(pos,
"-" + std::to_string(linkId));
688 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
689 <<
"/$ns3::WifiNetDevice/Phys/" << +linkId <<
"/State/RxOk";
695 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
696 <<
"/$ns3::WifiNetDevice/Phys/" << +linkId <<
"/State/Tx";
711 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
712 <<
"/$ns3::WifiNetDevice/Phy/State/RxOk";
716 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
717 <<
"/$ns3::WifiNetDevice/Phy/State/Tx";
728 m_enableFlowControl(true)
766 node->AddDevice(device);
776 device->SetHtConfiguration(htConfiguration);
786 device->SetVhtConfiguration(vhtConfiguration);
791 device->SetHeConfiguration(heConfiguration);
796 device->SetEhtConfiguration(ehtConfiguration);
798 std::vector<Ptr<WifiRemoteStationManager>> managers;
799 std::vector<Ptr<WifiPhy>> phys = phyHelper.
Create(node, device);
800 device->SetPhys(phys);
803 if (stationManagers.size() == 1 && phys.size() > 1)
805 stationManagers.resize(phys.size(), stationManagers[0]);
808 "Number of station manager models ("
809 << stationManagers.size() <<
") does not match the number of links ("
810 << phys.size() <<
")");
811 for (std::size_t i = 0; i < phys.size(); i++)
814 managers.push_back(stationManagers[i].Create<WifiRemoteStationManager>());
816 device->SetRemoteStationManagers(managers);
821 device->AggregateObject(obssPdAlgorithm);
822 obssPdAlgorithm->ConnectWifiNetDevice(device);
832 mac->GetAttributeFailSafe(
"QosSupported", qosSupported);
833 if (qosSupported.
Get())
835 ndqi = CreateObjectWithAttributes<NetDeviceQueueInterface>(
"NTxQueues",
840 wmq = qosTxop->GetWifiMacQueue();
841 ndqi->GetTxQueue(
static_cast<std::size_t
>(ac))->ConnectQueueTraces(wmq);
847 ndqi = CreateObject<NetDeviceQueueInterface>();
849 wmq = mac->GetTxop()->GetWifiMacQueue();
850 ndqi->GetTxQueue(0)->ConnectQueueTraces(wmq);
852 device->AggregateObject(ndqi);
875 Ptr<Node> node = Names::Find<Node>(nodeName);
985 int64_t currentStream = stream;
994 currentStream += wifi->GetPhy()->AssignStreams(currentStream);
997 currentStream += wifi->GetRemoteStationManager()->AssignStreams(currentStream);
1002 if (!mac->GetQosSupported())
1004 mac->GetAttribute(
"Txop", ptr);
1006 currentStream += txop->AssignStreams(currentStream);
1010 mac->GetAttribute(
"VO_Txop", ptr);
1012 currentStream += vo_txop->AssignStreams(currentStream);
1014 mac->GetAttribute(
"VI_Txop", ptr);
1016 currentStream += vi_txop->AssignStreams(currentStream);
1018 mac->GetAttribute(
"BE_Txop", ptr);
1020 currentStream += be_txop->AssignStreams(currentStream);
1022 mac->GetAttribute(
"BK_Txop", ptr);
1024 currentStream += bk_txop->AssignStreams(currentStream);
1028 if (
auto apMac = DynamicCast<ApWifiMac>(mac); apMac)
1030 currentStream += apMac->AssignStreams(currentStream);
1033 if (
auto staMac = DynamicCast<StaWifiMac>(mac); staMac)
1035 currentStream += staMac->AssignStreams(currentStream);
1039 return (currentStream - stream);
double f(double x, void *params)
Manage ASCII trace files for device models.
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...
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.
Hold a value for an Attribute.
AttributeValue implementation for Boolean.
std::size_t GetIndex() const
Get the RU index.
RuType GetRuType() const
Get the RU type.
bool GetPrimary80MHz() const
Get the primary 80 MHz flag.
RuType
The different HE Resource Unit (RU) types.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
bool IsTypeIdSet() const
Check if the ObjectFactory has been configured with a TypeId.
OBSS PD algorithm interface.
static void EnablePrinting()
Enable printing packets metadata.
Manage pcap files for device models.
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.
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.
DataLinkType
This enumeration holds the data link types that will be written to the pcap file.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
static Time Now()
Return the current simulation virtual time.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Handle packet fragmentation and retransmissions for data and management frames.
a unique identifier for an interface.
Hold an unsigned integer type.
void SetRemoteStationManager(std::string type, Args &&... args)
Helper function used to set the station manager.
ObjectFactory m_htConfig
HT configuration.
ObjectFactory m_obssPdAlgorithm
OBSS_PD algorithm.
ObjectFactory m_ehtConfig
EHT configuration.
ObjectFactory m_vhtConfig
VHT configuration.
void SetSelectQueueCallback(SelectQueueCallback f)
std::vector< ObjectFactory > m_stationManager
station manager
WifiStandard m_standard
wifi 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 ...
virtual void SetStandard(WifiStandard standard)
ObjectFactory m_heConfig
HE configuration.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
void DisableFlowControl()
Disable flow control only if you know what you are doing.
SelectQueueCallback m_selectQueueCallback
select queue callback
static void EnableLogComponents()
Helper to enable all WifiNetDevice log components with one statement.
bool m_enableFlowControl
whether to enable flow control
WifiHelper()
Create a Wifi helper in an empty state: all its parameters must be set before calling ns3::WifiHelper...
std::function< std::size_t(Ptr< QueueItem >)> SelectQueueCallback
Callback invoked to determine the MAC queue selected for a given packet.
create MAC layers for a ns3::WifiNetDevice.
virtual Ptr< WifiMac > Create(Ptr< WifiNetDevice > device, WifiStandard standard) const
Implements the IEEE 802.11 MAC trailer.
represent a single transmission mode
WifiModulationClass GetModulationClass() const
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
uint8_t GetMcsValue() const
Hold together all Wifi-related objects.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename) override
Enable ASCII trace output on the indicated net device.
WifiPhyHelper(uint8_t nLinks=1)
Constructor.
void Set(std::string name, const AttributeValue &v)
~WifiPhyHelper() override
void DisablePreambleDetectionModel()
Disable the preamble detection model on all links.
void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename) override
Enable pcap output the indicated net device.
PcapHelper::DataLinkType m_pcapDlt
PCAP data link type.
std::vector< ObjectFactory > m_frameCaptureModel
frame capture model
std::vector< ObjectFactory > m_preambleDetectionModel
preamble detection model
PcapHelper::DataLinkType GetPcapDataLinkType() const
Get the data link type of PCAP traces to be used.
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)
std::vector< ObjectFactory > m_phy
PHY object.
void SetPreambleDetectionModel(std::string type, Args &&... args)
Helper function used to set the preamble detection model.
static void PcapSniffTxEvent(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, uint16_t staId=SU_STA_ID)
SupportedPcapDataLinkTypes
An enumeration of the pcap data link types (DLTs) which this helper supports.
@ DLT_IEEE802_11
IEEE 802.11 Wireless LAN headers on packets.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
@ DLT_PRISM_HEADER
Include Prism monitor mode information.
std::vector< ObjectFactory > m_errorRateModel
error rate model
virtual std::vector< Ptr< WifiPhy > > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const =0
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.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint16_t GetGuardInterval() const
uint8_t GetBssColor() const
Get the BSS color.
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
bool IsStbc() const
Check if STBC is used or not.
WifiPreamble GetPreambleType() const
HeMuUserInfo GetHeMuUserInfo(uint16_t staId) const
Get the HE MU user-specific transmission information for the given STA-ID.
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
bool IsAggregation() const
Checks whether the PSDU contains A-MPDU.
uint16_t GetChannelWidth() const
void Connect(std::string path, const CallbackBase &cb)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
uint8_t SelectQueueByDSField(Ptr< QueueItem > item)
Determine the TX queue for a given packet.
@ WIFI_STANDARD_UNSPECIFIED
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
@ LAST_MPDU_IN_AGGREGATE
The MPDU is the last aggregate in an A-MPDU with multiple MPDUs.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
static void AsciiPhyReceiveSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p, double snr, WifiMode mode, WifiPreamble preamble)
ASCII trace PHY receive sink without context.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
static void AsciiPhyReceiveSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, double snr, WifiMode mode, WifiPreamble preamble)
ASCII trace PHY receive sink with context.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
static void AsciiPhyTransmitSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
ASCII trace PHY transmit sink with context.
static void AsciiPhyTransmitSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p, WifiMode mode, WifiPreamble preamble, uint8_t txLevel)
ASCII trace PHY transmit sink without context.
HeRu::RuSpec ru
RU specification.
MpduType type
type of MPDU
uint32_t mpduRefNumber
MPDU ref number.
SignalNoiseDbm structure.
double noise
noise power in dBm
double signal
signal strength in dBm