From b04bb017d944abd1b96dae5ed6b3743e46dbbc48 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Tue, 27 Apr 2021 23:39:35 +0200 Subject: [PATCH] wifi: Add an SnrTag for responses to MU frames --- src/wifi/model/he/mu-snr-tag.cc | 113 ++++++++++++++++++++++++++++++++ src/wifi/model/he/mu-snr-tag.h | 87 ++++++++++++++++++++++++ src/wifi/wscript | 2 + 3 files changed, 202 insertions(+) create mode 100644 src/wifi/model/he/mu-snr-tag.cc create mode 100644 src/wifi/model/he/mu-snr-tag.h diff --git a/src/wifi/model/he/mu-snr-tag.cc b/src/wifi/model/he/mu-snr-tag.cc new file mode 100644 index 000000000..bedfbea8d --- /dev/null +++ b/src/wifi/model/he/mu-snr-tag.cc @@ -0,0 +1,113 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2021 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 "mu-snr-tag.h" + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (MuSnrTag); + +TypeId +MuSnrTag::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::MuSnrTag") + .SetParent () + .SetGroupName ("Wifi") + .AddConstructor () + ; + return tid; +} + +TypeId +MuSnrTag::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} + +MuSnrTag::MuSnrTag () +{ +} + +void +MuSnrTag::Reset (void) +{ + m_snrMap.clear (); +} + +void +MuSnrTag::Set (uint16_t staId, double snr) +{ + m_snrMap[staId] = snr; +} + +bool +MuSnrTag::IsPresent (uint16_t staId) const +{ + return (m_snrMap.find (staId) != m_snrMap.end ()); +} + +double +MuSnrTag::Get (uint16_t staId) const +{ + NS_ASSERT (IsPresent (staId)); + return m_snrMap.at (staId); +} + +uint32_t +MuSnrTag::GetSerializedSize (void) const +{ + return (sizeof (uint16_t) + sizeof (double)) * m_snrMap.size () + 1; +} + +void +MuSnrTag::Serialize (TagBuffer i) const +{ + i.WriteU8 (m_snrMap.size ()); + + for (const auto& staIdSnrPair : m_snrMap) + { + i.WriteU16 (staIdSnrPair.first); + i.WriteDouble (staIdSnrPair.second); + } +} + +void +MuSnrTag::Deserialize (TagBuffer i) +{ + uint8_t n = i.ReadU8 (); + for (uint8_t j = 0; j < n; j++) + { + uint16_t staId = i.ReadU16 (); + double snr = i.ReadDouble (); + m_snrMap.insert ({staId, snr}); + } +} + +void +MuSnrTag::Print (std::ostream &os) const +{ + for (const auto& staIdSnrPair : m_snrMap) + { + os << "{STA-ID=" << staIdSnrPair.first << " Snr=" << staIdSnrPair.second << "} "; + } + os << std::endl; +} + +} diff --git a/src/wifi/model/he/mu-snr-tag.h b/src/wifi/model/he/mu-snr-tag.h new file mode 100644 index 000000000..2a892b744 --- /dev/null +++ b/src/wifi/model/he/mu-snr-tag.h @@ -0,0 +1,87 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2021 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 MU_SNR_TAG_H +#define MU_SNR_TAG_H + +#include "ns3/tag.h" +#include + +namespace ns3 { + +/** + * \ingroup wifi + * + * A tag to be attached to a response to a multi-user UL frame, that carries the SNR + * values with which the individual frames have been received. + */ +class MuSnrTag : public Tag +{ +public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ + static TypeId GetTypeId (void); + TypeId GetInstanceTypeId (void) const override; + + /** + * Create an empty MuSnrTag + */ + MuSnrTag (); + + uint32_t GetSerializedSize (void) const override; + void Serialize (TagBuffer i) const override; + void Deserialize (TagBuffer i) override; + void Print (std::ostream &os) const override; + + /** + * Reset the content of the tag. + */ + void Reset (void); + /** + * Set the SNR for the given sender to the given value. + * + * \param staId the STA-ID of the given sender + * \param snr the value of the SNR to set in linear scale + */ + void Set (uint16_t staId, double snr); + /** + * Return true if the SNR value for the given STA-ID is present + * + * \return true if the SNR value for the given STA-ID is present + */ + bool IsPresent (uint16_t staId) const; + /** + * Return the SNR value for the given sender. + * + * \param staId the STA-ID of the given sender + * \return the SNR value in linear scale + */ + double Get (uint16_t staId) const; + + +private: + std::map m_snrMap; //!< Map containing (STA-ID, SNR) pairs +}; + +} + +#endif /* MU_SNR_TAG_H */ diff --git a/src/wifi/wscript b/src/wifi/wscript index eb2f4053b..3f156f98d 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -79,6 +79,7 @@ def build(bld): 'model/block-ack-window.cc', 'model/block-ack-type.cc', 'model/snr-tag.cc', + 'model/he/mu-snr-tag.cc', 'model/ht/ht-capabilities.cc', 'model/wifi-tx-vector.cc', 'model/rate-control/parf-wifi-manager.cc', @@ -240,6 +241,7 @@ def build(bld): 'model/block-ack-manager.h', 'model/block-ack-window.h', 'model/snr-tag.h', + 'model/he/mu-snr-tag.h', 'model/ht/ht-capabilities.h', 'model/rate-control/parf-wifi-manager.h', 'model/rate-control/aparf-wifi-manager.h',