A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#include "mu-snr-tag.h"
10
11namespace ns3
12{
13
15
16TypeId
18{
19 static TypeId tid =
20 TypeId("ns3::MuSnrTag").SetParent<Tag>().SetGroupName("Wifi").AddConstructor<MuSnrTag>();
21 return tid;
22}
23
26{
27 return GetTypeId();
28}
29
33
34void
36{
37 m_snrMap.clear();
38}
39
40void
41MuSnrTag::Set(uint16_t staId, double snr)
42{
43 m_snrMap[staId] = snr;
44}
45
46bool
47MuSnrTag::IsPresent(uint16_t staId) const
48{
49 return m_snrMap.contains(staId);
50}
51
52double
53MuSnrTag::Get(uint16_t staId) const
54{
55 NS_ASSERT(IsPresent(staId));
56 return m_snrMap.at(staId);
57}
58
61{
62 return (sizeof(uint16_t) + sizeof(double)) * m_snrMap.size() + 1;
63}
64
65void
67{
68 i.WriteU8(m_snrMap.size());
69
70 for (const auto& staIdSnrPair : m_snrMap)
71 {
72 i.WriteU16(staIdSnrPair.first);
73 i.WriteDouble(staIdSnrPair.second);
74 }
75}
76
77void
79{
80 uint8_t n = i.ReadU8();
81 for (uint8_t j = 0; j < n; j++)
82 {
83 uint16_t staId = i.ReadU16();
84 double snr = i.ReadDouble();
85 m_snrMap.insert({staId, snr});
86 }
87}
88
89void
90MuSnrTag::Print(std::ostream& os) const
91{
92 for (const auto& staIdSnrPair : m_snrMap)
93 {
94 os << "{STA-ID=" << staIdSnrPair.first << " Snr=" << staIdSnrPair.second << "} ";
95 }
96 os << std::endl;
97}
98
99} // 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:26
std::map< uint16_t, double > m_snrMap
Map containing (STA-ID, SNR) pairs.
Definition mu-snr-tag.h:72
void Print(std::ostream &os) const override
Definition mu-snr-tag.cc:90
void Reset()
Reset the content of the tag.
Definition mu-snr-tag.cc:35
static TypeId GetTypeId()
Get the type ID.
Definition mu-snr-tag.cc:17
double Get(uint16_t staId) const
Return the SNR value for the given sender.
Definition mu-snr-tag.cc:53
bool IsPresent(uint16_t staId) const
Return true if the SNR value for the given STA-ID is present.
Definition mu-snr-tag.cc:47
void Serialize(TagBuffer i) const override
Definition mu-snr-tag.cc:66
void Set(uint16_t staId, double snr)
Set the SNR for the given sender to the given value.
Definition mu-snr-tag.cc:41
uint32_t GetSerializedSize() const override
Definition mu-snr-tag.cc:60
void Deserialize(TagBuffer i) override
Definition mu-snr-tag.cc:78
MuSnrTag()
Create an empty MuSnrTag.
Definition mu-snr-tag.cc:30
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition mu-snr-tag.cc:25
read and write tag data
Definition tag-buffer.h:41
void WriteDouble(double v)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition tag-buffer.h:161
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition tag-buffer.h:185
TAG_BUFFER_INLINE uint16_t ReadU16()
Definition tag-buffer.h:195
double ReadDouble()
TAG_BUFFER_INLINE void WriteU16(uint16_t v)
Definition tag-buffer.h:169
tag a set of bytes in a packet
Definition tag.h:28
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.