A Discrete-Event Network Simulator
API
mu-snr-tag.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Universita' degli Studi di Napoli Federico II
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Stefano Avallone <stavallo@unina.it>
18  */
19 
20 #include "mu-snr-tag.h"
21 
22 namespace ns3
23 {
24 
26 
27 TypeId
29 {
30  static TypeId tid =
31  TypeId("ns3::MuSnrTag").SetParent<Tag>().SetGroupName("Wifi").AddConstructor<MuSnrTag>();
32  return tid;
33 }
34 
35 TypeId
37 {
38  return GetTypeId();
39 }
40 
42 {
43 }
44 
45 void
47 {
48  m_snrMap.clear();
49 }
50 
51 void
52 MuSnrTag::Set(uint16_t staId, double snr)
53 {
54  m_snrMap[staId] = snr;
55 }
56 
57 bool
58 MuSnrTag::IsPresent(uint16_t staId) const
59 {
60  return (m_snrMap.find(staId) != m_snrMap.end());
61 }
62 
63 double
64 MuSnrTag::Get(uint16_t staId) const
65 {
66  NS_ASSERT(IsPresent(staId));
67  return m_snrMap.at(staId);
68 }
69 
70 uint32_t
72 {
73  return (sizeof(uint16_t) + sizeof(double)) * m_snrMap.size() + 1;
74 }
75 
76 void
78 {
79  i.WriteU8(m_snrMap.size());
80 
81  for (const auto& staIdSnrPair : m_snrMap)
82  {
83  i.WriteU16(staIdSnrPair.first);
84  i.WriteDouble(staIdSnrPair.second);
85  }
86 }
87 
88 void
90 {
91  uint8_t n = i.ReadU8();
92  for (uint8_t j = 0; j < n; j++)
93  {
94  uint16_t staId = i.ReadU16();
95  double snr = i.ReadDouble();
96  m_snrMap.insert({staId, snr});
97  }
98 }
99 
100 void
101 MuSnrTag::Print(std::ostream& os) const
102 {
103  for (const auto& staIdSnrPair : m_snrMap)
104  {
105  os << "{STA-ID=" << staIdSnrPair.first << " Snr=" << staIdSnrPair.second << "} ";
106  }
107  os << std::endl;
108 }
109 
110 } // namespace ns3
A tag to be attached to a response to a multi-user UL frame, that carries the SNR values with which t...
Definition: mu-snr-tag.h:37
std::map< uint16_t, double > m_snrMap
Map containing (STA-ID, SNR) pairs.
Definition: mu-snr-tag.h:83
void Print(std::ostream &os) const override
Definition: mu-snr-tag.cc:101
void Reset()
Reset the content of the tag.
Definition: mu-snr-tag.cc:46
static TypeId GetTypeId()
Get the type ID.
Definition: mu-snr-tag.cc:28
double Get(uint16_t staId) const
Return the SNR value for the given sender.
Definition: mu-snr-tag.cc:64
bool IsPresent(uint16_t staId) const
Return true if the SNR value for the given STA-ID is present.
Definition: mu-snr-tag.cc:58
void Serialize(TagBuffer i) const override
Definition: mu-snr-tag.cc:77
void Set(uint16_t staId, double snr)
Set the SNR for the given sender to the given value.
Definition: mu-snr-tag.cc:52
uint32_t GetSerializedSize() const override
Definition: mu-snr-tag.cc:71
void Deserialize(TagBuffer i) override
Definition: mu-snr-tag.cc:89
MuSnrTag()
Create an empty MuSnrTag.
Definition: mu-snr-tag.cc:41
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: mu-snr-tag.cc:36
read and write tag data
Definition: tag-buffer.h:52
void WriteDouble(double v)
Definition: tag-buffer.cc:118
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:172
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition: tag-buffer.h:196
TAG_BUFFER_INLINE uint16_t ReadU16()
Definition: tag-buffer.h:206
double ReadDouble()
Definition: tag-buffer.cc:170
TAG_BUFFER_INLINE void WriteU16(uint16_t v)
Definition: tag-buffer.h:180
tag a set of bytes in a packet
Definition: tag.h:39
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.