From f8ac6f61cf7ad69eda69b56dfa7d6e8d9f539dfa Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Tue, 17 Nov 2020 23:26:44 +0100 Subject: [PATCH] wifi: Add a class hierarchy for protection methods --- src/wifi/model/wifi-protection.cc | 96 ++++++++++++++++++++++ src/wifi/model/wifi-protection.h | 127 ++++++++++++++++++++++++++++++ src/wifi/wscript | 2 + 3 files changed, 225 insertions(+) create mode 100644 src/wifi/model/wifi-protection.cc create mode 100644 src/wifi/model/wifi-protection.h diff --git a/src/wifi/model/wifi-protection.cc b/src/wifi/model/wifi-protection.cc new file mode 100644 index 000000000..162154176 --- /dev/null +++ b/src/wifi/model/wifi-protection.cc @@ -0,0 +1,96 @@ +/* -*- 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-protection.h" +#include "wifi-utils.h" + +namespace ns3 { + +/* + * WifiProtection + */ + +WifiProtection::WifiProtection (Method m) + : method (m), + protectionTime (Time::Min ()) // uninitialized +{ +} + +WifiProtection::~WifiProtection () +{ +} + + +/* + * WifiNoProtection + */ + +WifiNoProtection::WifiNoProtection () + : WifiProtection (NONE) +{ + protectionTime = Seconds (0); +} + +void +WifiNoProtection::Print (std::ostream &os) const +{ + os << "NONE"; +} + + +/* + * WifiRtsCtsProtection + */ + +WifiRtsCtsProtection::WifiRtsCtsProtection () + : WifiProtection (RTS_CTS) +{ +} + +void +WifiRtsCtsProtection::Print (std::ostream &os) const +{ + os << "RTS_CTS"; +} + + +/* + * WifiCtsToSelfProtection + */ + +WifiCtsToSelfProtection::WifiCtsToSelfProtection () + : WifiProtection (CTS_TO_SELF) +{ +} + +void +WifiCtsToSelfProtection::Print (std::ostream &os) const +{ + os << "CTS_TO_SELF"; +} + + +std::ostream & operator << (std::ostream &os, const WifiProtection* protection) +{ + protection->Print (os); + return os; +} + +} //namespace ns3 diff --git a/src/wifi/model/wifi-protection.h b/src/wifi/model/wifi-protection.h new file mode 100644 index 000000000..1f0d385bf --- /dev/null +++ b/src/wifi/model/wifi-protection.h @@ -0,0 +1,127 @@ +/* -*- 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_PROTECTION_H +#define WIFI_PROTECTION_H + +#include "ns3/nstime.h" +#include "wifi-tx-vector.h" +#include "ctrl-headers.h" + + +namespace ns3 { + +/** + * \ingroup wifi + * + * WifiProtection is an abstract base struct. Each derived struct defines a protection + * method and stores the information needed to perform protection according to + * that method. + */ +struct WifiProtection +{ + /** + * \enum Method + * \brief Available protection methods + */ + enum Method + { + NONE = 0, + RTS_CTS, + CTS_TO_SELF + }; + + /** + * Constructor. + * \param m the protection method for this object + */ + WifiProtection (Method m); + virtual ~WifiProtection (); + + /** + * \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; //!< protection method + Time protectionTime; //!< time required by the protection method +}; + + +/** + * \ingroup wifi + * + * WifiNoProtection specifies that no protection method is used. + */ +struct WifiNoProtection : public WifiProtection +{ + WifiNoProtection (); + + // Overridden from WifiProtection + void Print (std::ostream &os) const override; +}; + + +/** + * \ingroup wifi + * + * WifiRtsCtsProtection specifies that RTS/CTS protection method is used. + */ +struct WifiRtsCtsProtection : public WifiProtection +{ + WifiRtsCtsProtection (); + + // Overridden from WifiProtection + void Print (std::ostream &os) const override; + + WifiTxVector rtsTxVector; //!< RTS TXVECTOR + WifiTxVector ctsTxVector; //!< CTS TXVECTOR +}; + + +/** + * \ingroup wifi + * + * WifiCtsToSelfProtection specifies that CTS-to-self protection method is used. + */ +struct WifiCtsToSelfProtection : public WifiProtection +{ + WifiCtsToSelfProtection (); + + // Overridden from WifiProtection + void Print (std::ostream &os) const override; + + WifiTxVector ctsTxVector; //!< CTS TXVECTOR +}; + + +/** + * \brief Stream insertion operator. + * + * \param os the output stream + * \param protection the protection method + * \returns a reference to the stream + */ +std::ostream& operator<< (std::ostream& os, const WifiProtection* protection); + +} //namespace ns3 + +#endif /* WIFI_PROTECTION_H */ diff --git a/src/wifi/wscript b/src/wifi/wscript index beb7a8f02..4cbe72605 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -25,6 +25,7 @@ def build(bld): 'model/wifi-mac-header.cc', 'model/wifi-mac-trailer.cc', 'model/wifi-tx-timer.cc', + 'model/wifi-protection.cc', 'model/mac-low.cc', 'model/mac-low-transmission-parameters.cc', 'model/wifi-mac-queue.cc', @@ -196,6 +197,7 @@ def build(bld): 'model/mac-tx-middle.h', 'model/mac-rx-middle.h', 'model/wifi-tx-timer.h', + 'model/wifi-protection.h', 'model/mac-low.h', 'model/mac-low-transmission-parameters.h', 'model/originator-block-ack-agreement.h',