A Discrete-Event Network Simulator
API
supported-rates.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#include "supported-rates.h"
21
22#include "ns3/log.h"
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("SupportedRates");
28
29#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
30#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
31#define BSS_MEMBERSHIP_SELECTOR_HE_PHY 122
32#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY 121 // TODO not defined yet as of 802.11be D1.4
33
35 : extended(this),
36 m_nRates(0)
37{
38 NS_LOG_FUNCTION(this);
39}
40
42{
43 NS_LOG_FUNCTION(this);
44 m_nRates = rates.m_nRates;
45 memcpy(m_rates, rates.m_rates, MAX_SUPPORTED_RATES);
46 // reset the back pointer to this object
48}
49
52{
53 this->m_nRates = rates.m_nRates;
54 memcpy(this->m_rates, rates.m_rates, MAX_SUPPORTED_RATES);
55 // reset the back pointer to this object
57 return (*this);
58}
59
60void
62{
63 NS_LOG_FUNCTION(this << bs);
64 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
66 if (IsSupportedRate(bs))
67 {
68 return;
69 }
70 m_rates[m_nRates] = static_cast<uint8_t>(bs / 500000);
71 m_nRates++;
72 NS_LOG_DEBUG("add rate=" << bs << ", n rates=" << +m_nRates);
73}
74
75void
77{
78 NS_LOG_FUNCTION(this << bs);
79 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
80 uint8_t rate = static_cast<uint8_t>(bs / 500000);
81 for (uint8_t i = 0; i < m_nRates; i++)
82 {
83 if ((rate | 0x80) == m_rates[i])
84 {
85 return;
86 }
87 if (rate == m_rates[i])
88 {
89 NS_LOG_DEBUG("set basic rate=" << bs << ", n rates=" << +m_nRates);
90 m_rates[i] |= 0x80;
91 return;
92 }
93 }
95 SetBasicRate(bs);
96}
97
98void
100{
101 NS_LOG_FUNCTION(this << bs);
104 "Value " << bs << " not a BSS Membership Selector");
105 uint8_t rate = static_cast<uint8_t>(bs / 500000);
106 for (uint8_t i = 0; i < m_nRates; i++)
107 {
108 if (rate == m_rates[i])
109 {
110 return;
111 }
112 }
113 m_rates[m_nRates] = rate;
114 NS_LOG_DEBUG("add BSS membership selector rate " << bs << " as rate " << +rate);
115 m_nRates++;
116}
117
118bool
120{
121 NS_LOG_FUNCTION(this << bs);
122 uint8_t rate = static_cast<uint8_t>(bs / 500000) | 0x80;
123 for (uint8_t i = 0; i < m_nRates; i++)
124 {
125 if (rate == m_rates[i])
126 {
127 return true;
128 }
129 }
130 return false;
131}
132
133bool
135{
136 NS_LOG_FUNCTION(this << bs);
137 uint8_t rate = static_cast<uint8_t>(bs / 500000);
138 for (uint8_t i = 0; i < m_nRates; i++)
139 {
140 if (rate == m_rates[i] || (rate | 0x80) == m_rates[i])
141 {
142 return true;
143 }
144 }
145 return false;
146}
147
148bool
150{
151 NS_LOG_FUNCTION(this << bs);
152 if ((bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY ||
153 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_VHT_PHY ||
154 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HE_PHY ||
155 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_EHT_PHY)
156 {
157 return true;
158 }
159 return false;
160}
161
162uint8_t
164{
165 return m_nRates;
166}
167
170{
171 return (m_rates[i] & 0x7f) * 500000;
172}
173
176{
177 return IE_SUPPORTED_RATES;
178}
179
180uint16_t
182{
183 // The Supported Rates Information Element contains only the first 8
184 // supported rates - the remainder appear in the Extended Supported
185 // Rates Information Element.
186 return m_nRates > 8 ? 8 : m_nRates;
187}
188
189void
191{
192 // The Supported Rates Information Element contains only the first 8
193 // supported rates - the remainder appear in the Extended Supported
194 // Rates Information Element.
195 start.Write(m_rates, m_nRates > 8 ? 8 : m_nRates);
196}
197
198uint16_t
200{
201 NS_ASSERT(length <= 8);
202 m_nRates = length;
203 start.Read(m_rates, m_nRates);
204 return m_nRates;
205}
206
208{
209}
210
212{
213 m_supportedRates = sr;
214}
215
218{
220}
221
222void
224{
225 m_supportedRates = sr;
226}
227
228uint16_t
230{
231 // If there are 8 or fewer rates then we don't need an Extended Supported
232 // Rates, so if this function is invoked in that case then it indicates a
233 // programming error. Hence we have an assertion on that condition.
235
236 // The number of rates we have beyond the initial 8 is the size of
237 // the information field.
238 return (m_supportedRates->m_nRates - 8);
239}
240
241void
243{
244 // If there are 8 or fewer rates then there should be no Extended
245 // Supported Rates Information Element at all so being here would
246 // seemingly indicate a programming error.
249}
250
251uint16_t
253{
254 NS_ASSERT(length > 0);
257 m_supportedRates->m_nRates += length;
258 return length;
259}
260
261std::ostream&
262operator<<(std::ostream& os, const SupportedRates& rates)
263{
264 os << "[";
265 for (uint8_t i = 0; i < rates.GetNRates(); i++)
266 {
267 uint32_t rate = rates.GetRate(i);
268 if (rates.IsBasicRate(rate))
269 {
270 os << "*";
271 }
272 os << rate / 1000000 << "mbs";
273 if (i < rates.GetNRates() - 1)
274 {
275 os << " ";
276 }
277 }
278 os << "]";
279 return os;
280}
281
282} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
SupportedRates * m_supportedRates
This member points to the SupportedRates object that contains the actual rate details.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
void SetSupportedRates(SupportedRates *rates)
Set supported rates.
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
The Supported Rates Information Element.
void SetBasicRate(uint64_t bs)
Set the given rate to basic rates.
void AddBssMembershipSelectorRate(uint64_t bs)
Add a special value to the supported rate set, corresponding to a BSS membership selector.
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
uint8_t m_nRates
Number of supported rates.
uint8_t m_rates[MAX_SUPPORTED_RATES]
List of supported bit rates (divided by 500000)
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
SupportedRates & operator=(const SupportedRates &rates)
Assignment operator.
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
uint8_t GetNRates() const
Return the number of supported rates.
std::optional< ExtendedSupportedRatesIE > extended
extended supported rates info element
bool IsBasicRate(uint64_t bs) const
Check if the given rate is a basic rate.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
bool IsBssMembershipSelectorRate(uint64_t bs) const
Check if the given rate is a BSS membership selector value.
friend class ExtendedSupportedRatesIE
We support the Extended Supported Rates Information Element through the ExtendedSupportedRatesIE obje...
static const uint8_t MAX_SUPPORTED_RATES
This defines the maximum number of supported rates that a STA is allowed to have.
uint32_t GetRate(uint8_t i) const
Return the rate at the given index.
void AddSupportedRate(uint64_t bs)
Add the given rate to the supported rates.
bool IsSupportedRate(uint64_t bs) const
Check if the given rate is supported.
#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_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
@ extended
Definition: ff-mac-common.h:85
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
def start()
Definition: core.py:1861
#define BSS_MEMBERSHIP_SELECTOR_HT_PHY
#define BSS_MEMBERSHIP_SELECTOR_HE_PHY
#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY
#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY
#define IE_EXTENDED_SUPPORTED_RATES
#define IE_SUPPORTED_RATES