wifi: Add a class hierarchy for protection methods

This commit is contained in:
Stefano Avallone
2020-11-17 23:26:44 +01:00
parent ab5a1c53f6
commit f8ac6f61cf
3 changed files with 225 additions and 0 deletions

View File

@@ -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 <stavallo@unina.it>
*/
#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

View File

@@ -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 <stavallo@unina.it>
*/
#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 */

View File

@@ -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',