From 2eff9a30a9cffb95eabcaac2e0506dfb4a7a5902 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Tue, 17 Nov 2020 23:31:30 +0100 Subject: [PATCH] wifi: Add a class hierarchy for acknowledgment methods --- src/wifi/helper/wifi-helper.cc | 5 + src/wifi/model/wifi-acknowledgment.cc | 115 +++++++++++++++++++ src/wifi/model/wifi-acknowledgment.h | 152 ++++++++++++++++++++++++++ src/wifi/wscript | 2 + 4 files changed, 274 insertions(+) create mode 100644 src/wifi/model/wifi-acknowledgment.cc create mode 100644 src/wifi/model/wifi-acknowledgment.h diff --git a/src/wifi/helper/wifi-helper.cc b/src/wifi/helper/wifi-helper.cc index 4c004d549..fb4232456 100644 --- a/src/wifi/helper/wifi-helper.cc +++ b/src/wifi/helper/wifi-helper.cc @@ -1026,7 +1026,10 @@ WifiHelper::EnableLogComponents (void) LogComponentEnable ("ThresholdPreambleDetectionModel", LOG_LEVEL_ALL); LogComponentEnable ("Txop", LOG_LEVEL_ALL); LogComponentEnable ("VhtConfiguration", LOG_LEVEL_ALL); + LogComponentEnable ("WifiAckManager", LOG_LEVEL_ALL); LogComponentEnable ("WifiAckPolicySelector", LOG_LEVEL_ALL); + LogComponentEnable ("WifiDefaultAckManager", LOG_LEVEL_ALL); + LogComponentEnable ("WifiDefaultProtectionManager", LOG_LEVEL_ALL); LogComponentEnable ("WifiMac", LOG_LEVEL_ALL); LogComponentEnable ("WifiMacQueue", LOG_LEVEL_ALL); LogComponentEnable ("WifiMacQueueItem", LOG_LEVEL_ALL); @@ -1034,12 +1037,14 @@ WifiHelper::EnableLogComponents (void) LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL); LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL); LogComponentEnable ("WifiPpdu", LOG_LEVEL_ALL); + LogComponentEnable ("WifiProtectionManager", LOG_LEVEL_ALL); LogComponentEnable ("WifiPsdu", LOG_LEVEL_ALL); LogComponentEnable ("WifiRadioEnergyModel", LOG_LEVEL_ALL); LogComponentEnable ("WifiRemoteStationManager", LOG_LEVEL_ALL); LogComponentEnable ("WifiSpectrumPhyInterface", LOG_LEVEL_ALL); LogComponentEnable ("WifiSpectrumSignalParameters", LOG_LEVEL_ALL); LogComponentEnable ("WifiTxCurrentModel", LOG_LEVEL_ALL); + LogComponentEnable ("WifiTxParameters", LOG_LEVEL_ALL); LogComponentEnable ("YansErrorRateModel", LOG_LEVEL_ALL); LogComponentEnable ("YansWifiChannel", LOG_LEVEL_ALL); LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL); diff --git a/src/wifi/model/wifi-acknowledgment.cc b/src/wifi/model/wifi-acknowledgment.cc new file mode 100644 index 000000000..429c7306c --- /dev/null +++ b/src/wifi/model/wifi-acknowledgment.cc @@ -0,0 +1,115 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Stefano Avallone + */ + +#include "wifi-acknowledgment.h" +#include "wifi-utils.h" +#include "ns3/mac48-address.h" + +namespace ns3 { + +/* + * WifiAcknowledgment + */ + +WifiAcknowledgment::WifiAcknowledgment (Method m) + : method (m), + acknowledgmentTime (Time::Min ()) // uninitialized +{ +} + +WifiAcknowledgment::~WifiAcknowledgment () +{ +} + +WifiMacHeader::QosAckPolicy +WifiAcknowledgment::GetQosAckPolicy (Mac48Address receiver, uint8_t tid) const +{ + auto it = m_ackPolicy.find ({receiver, tid}); + NS_ASSERT (it != m_ackPolicy.end ()); + return it->second; +} + +void +WifiAcknowledgment::SetQosAckPolicy (Mac48Address receiver, uint8_t tid, + WifiMacHeader::QosAckPolicy ackPolicy) +{ + NS_ABORT_MSG_IF (!CheckQosAckPolicy (receiver, tid, ackPolicy), "QoS Ack policy not admitted"); + m_ackPolicy[{receiver, tid}] = ackPolicy; +} + +/* + * WifiNoAck + */ + +WifiNoAck::WifiNoAck () + : WifiAcknowledgment (NONE) +{ + acknowledgmentTime = Seconds (0); +} + +bool +WifiNoAck::CheckQosAckPolicy (Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const +{ + if (ackPolicy == WifiMacHeader::NO_ACK || ackPolicy == WifiMacHeader::BLOCK_ACK) + { + return true; + } + return false; +} + +void +WifiNoAck::Print (std::ostream &os) const +{ + os << "NONE"; +} + + +/* + * WifiNormalAck + */ + +WifiNormalAck::WifiNormalAck () + : WifiAcknowledgment (NORMAL_ACK) +{ +} + +bool +WifiNormalAck::CheckQosAckPolicy (Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const +{ + if (ackPolicy == WifiMacHeader::NORMAL_ACK) + { + return true; + } + return false; +} + +void +WifiNormalAck::Print (std::ostream &os) const +{ + os << "NORMAL_ACK"; +} + +std::ostream & operator << (std::ostream &os, const WifiAcknowledgment* acknowledgment) +{ + acknowledgment->Print (os); + return os; +} + +} //namespace ns3 diff --git a/src/wifi/model/wifi-acknowledgment.h b/src/wifi/model/wifi-acknowledgment.h new file mode 100644 index 000000000..ba5f25395 --- /dev/null +++ b/src/wifi/model/wifi-acknowledgment.h @@ -0,0 +1,152 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Stefano Avallone + */ + +#ifndef WIFI_ACKNOWLEDGMENT_H +#define WIFI_ACKNOWLEDGMENT_H + +#include "ns3/nstime.h" +#include "wifi-tx-vector.h" +#include "wifi-mac-header.h" +#include "ctrl-headers.h" +#include + + +namespace ns3 { + +class Mac48Address; + +/** + * \ingroup wifi + * + * WifiAcknowledgment is an abstract base struct. Each derived struct defines an acknowledgment + * method and stores the information needed to perform acknowledgment according to + * that method. + */ +struct WifiAcknowledgment +{ + /** + * \enum Method + * \brief Available acknowledgment methods + */ + enum Method + { + NONE = 0, + NORMAL_ACK + }; + + /** + * Constructor. + * \param m the acknowledgment method for this object + */ + WifiAcknowledgment (Method m); + virtual ~WifiAcknowledgment (); + + /** + * Get the QoS Ack policy to use for the MPDUs addressed to the given receiver + * and belonging to the given TID. + * + * \param receiver the MAC address of the receiver + * \param tid the TID + * \return the QoS Ack policy to use + */ + WifiMacHeader::QosAckPolicy GetQosAckPolicy (Mac48Address receiver, uint8_t tid) const; + + /** + * Set the QoS Ack policy to use for the MPDUs addressed to the given receiver + * and belonging to the given TID. If the pair (receiver, TID) already exists, + * it is overwritten with the given QoS Ack policy. + * + * \param receiver the MAC address of the receiver + * \param tid the TID + * \param ackPolicy the QoS Ack policy to use + */ + void SetQosAckPolicy (Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy); + + /** + * \brief Print the object contents. + * \param os output stream in which the data should be printed. + */ + virtual void Print (std::ostream &os) const = 0; + + const Method method; //!< acknowledgment method + Time acknowledgmentTime; //!< time required by the acknowledgment method + +private: + /** + * Check whether the given QoS Ack policy can be used for the MPDUs addressed + * to the given receiver and belonging to the given TID. + * + * \param receiver the MAC address of the receiver + * \param tid the TID + * \param ackPolicy the QoS Ack policy to use + * \return true if the given QoS Ack policy can be used, false otherwise + */ + virtual bool CheckQosAckPolicy (Mac48Address receiver, uint8_t tid, + WifiMacHeader::QosAckPolicy ackPolicy) const = 0; + + /// Qos Ack Policy to set for MPDUs addressed to a given receiver and having a given TID + std::map, WifiMacHeader::QosAckPolicy> m_ackPolicy; +}; + + +/** + * \ingroup wifi + * + * WifiNoAck specifies that no acknowledgment is required. + */ +struct WifiNoAck : public WifiAcknowledgment +{ + WifiNoAck (); + + // Overridden from WifiAcknowledgment + bool CheckQosAckPolicy (Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override; + void Print (std::ostream &os) const override; +}; + + +/** + * \ingroup wifi + * + * WifiNormalAck specifies that acknowledgment via Normal Ack is required. + */ +struct WifiNormalAck : public WifiAcknowledgment +{ + WifiNormalAck (); + + // Overridden from WifiAcknowledgment + bool CheckQosAckPolicy (Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override; + void Print (std::ostream &os) const override; + + WifiTxVector ackTxVector; //!< Ack TXVECTOR +}; + + +/** + * \brief Stream insertion operator. + * + * \param os the output stream + * \param acknowledgment the acknowledgment method + * \returns a reference to the stream + */ +std::ostream& operator<< (std::ostream& os, const WifiAcknowledgment* acknowledgment); + +} //namespace ns3 + +#endif /* WIFI_ACKNOWLEDGMENT_H */ diff --git a/src/wifi/wscript b/src/wifi/wscript index 4cbe72605..180ae1def 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -26,6 +26,7 @@ def build(bld): 'model/wifi-mac-trailer.cc', 'model/wifi-tx-timer.cc', 'model/wifi-protection.cc', + 'model/wifi-acknowledgment.cc', 'model/mac-low.cc', 'model/mac-low-transmission-parameters.cc', 'model/wifi-mac-queue.cc', @@ -198,6 +199,7 @@ def build(bld): 'model/mac-rx-middle.h', 'model/wifi-tx-timer.h', 'model/wifi-protection.h', + 'model/wifi-acknowledgment.h', 'model/mac-low.h', 'model/mac-low-transmission-parameters.h', 'model/originator-block-ack-agreement.h',