A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
supported-rates.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "supported-rates.h"
10
11#include "ns3/log.h"
12
13#include <algorithm>
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("SupportedRates");
19
20#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
21#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
22#define BSS_MEMBERSHIP_SELECTOR_HE_PHY 122
23#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY 121 // TODO not defined yet as of 802.11be D1.4
24
29
30void
31SupportedRates::Print(std::ostream& os) const
32{
33 os << "rates=[";
34 for (std::size_t i = 0; i < m_rates.size(); i++)
35 {
36 if ((m_rates[i] & 0x80) > 0)
37 {
38 os << "*";
39 }
40 os << GetRate(i) / 1000000 << "mbs";
41 if (i < m_rates.size() - 1)
42 {
43 os << " ";
44 }
45 }
46 os << "]";
47}
48
49bool
51{
52 NS_LOG_FUNCTION(this << bs);
53 uint8_t rate = static_cast<uint8_t>(bs / 500000) | 0x80;
54 return std::find(rates.m_rates.cbegin(), rates.m_rates.cend(), rate) != rates.m_rates.cend() ||
56 std::find(extendedRates->m_rates.cbegin(), extendedRates->m_rates.cend(), rate) !=
57 extendedRates->m_rates.cend());
58}
59
60void
62{
63 NS_LOG_FUNCTION(this << bs);
64 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
65 if (IsSupportedRate(bs))
66 {
67 return;
68 }
69 if (rates.m_rates.size() < 8)
70 {
71 rates.m_rates.emplace_back(static_cast<uint8_t>(bs / 500000));
72 }
73 else
74 {
75 if (!extendedRates)
76 {
77 extendedRates.emplace();
78 }
79 extendedRates->m_rates.emplace_back(static_cast<uint8_t>(bs / 500000));
80 }
81 NS_LOG_DEBUG("add rate=" << bs << ", n rates=" << +GetNRates());
82}
83
84void
86{
87 NS_LOG_FUNCTION(this << bs);
88 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
89 auto rate = static_cast<uint8_t>(bs / 500000);
90 for (uint8_t i = 0; i < GetNRates(); i++)
91 {
92 auto& currRate = i < 8 ? rates.m_rates[i] : extendedRates->m_rates[i - 8];
93 if ((rate | 0x80) == currRate)
94 {
95 return;
96 }
97 if (rate == currRate)
98 {
99 NS_LOG_DEBUG("set basic rate=" << bs << ", n rates=" << +GetNRates());
100 currRate |= 0x80;
101 return;
102 }
103 }
105 SetBasicRate(bs);
106}
107
108void
110{
111 NS_LOG_FUNCTION(this << bs);
114 "Value " << bs << " not a BSS Membership Selector");
115 auto rate = static_cast<uint8_t>(bs / 500000);
116 for (std::size_t i = 0; i < rates.m_rates.size(); i++)
117 {
118 if (rate == rates.m_rates[i])
119 {
120 return;
121 }
122 }
123 if (extendedRates)
124 {
125 for (std::size_t i = 0; i < extendedRates->m_rates.size(); i++)
126 {
127 if (rate == extendedRates->m_rates[i])
128 {
129 return;
130 }
131 }
132 }
133 if (rates.m_rates.size() < 8)
134 {
135 rates.m_rates.emplace_back(rate);
136 }
137 else
138 {
139 if (!extendedRates)
140 {
141 extendedRates.emplace();
142 }
143 extendedRates->m_rates.emplace_back(rate);
144 }
145 NS_LOG_DEBUG("add BSS membership selector rate " << bs << " as rate " << +rate);
146}
147
148bool
150{
151 NS_LOG_FUNCTION(this << bs);
152 auto rate = static_cast<uint8_t>(bs / 500000);
153 for (std::size_t i = 0; i < rates.m_rates.size(); i++)
154 {
155 if (rate == rates.m_rates[i] || (rate | 0x80) == rates.m_rates[i])
156 {
157 return true;
158 }
159 }
160 if (extendedRates)
161 {
162 for (std::size_t i = 0; i < extendedRates->m_rates.size(); i++)
163 {
164 if (rate == extendedRates->m_rates[i] || (rate | 0x80) == extendedRates->m_rates[i])
165 {
166 return true;
167 }
168 }
169 }
170 return false;
171}
172
173bool
175{
176 NS_LOG_FUNCTION(this << bs);
177 return (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY ||
178 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_VHT_PHY ||
179 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HE_PHY ||
180 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_EHT_PHY;
181}
182
183uint8_t
185{
186 return rates.m_rates.size() + (extendedRates ? extendedRates->m_rates.size() : 0);
187}
188
191{
192 return (m_rates[i] & 0x7f) * 500000;
193}
194
197{
198 return IE_SUPPORTED_RATES;
199}
200
201uint16_t
203{
204 return m_rates.size();
205}
206
207void
209{
210 for (const uint8_t rate : m_rates)
211 {
212 start.WriteU8(rate);
213 }
214}
215
216uint16_t
218{
219 NS_ASSERT(length <= 8);
220 for (uint16_t i = 0; i < length; i++)
221 {
222 m_rates.push_back(start.ReadU8());
223 }
224 return length;
225}
226
232
233} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
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)
std::vector< uint8_t > m_rates
List of supported bit rates (divided by 500000)
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint32_t GetRate(uint8_t i) const
Return the rate (converted back to raw value) at the given index.
#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_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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
SupportedRates rates
supported rates
void SetBasicRate(uint64_t bs)
Set the given rate to basic rates.
bool IsBssMembershipSelectorRate(uint64_t bs) const
Check if the given rate is a BSS membership selector value.
std::optional< ExtendedSupportedRatesIE > extendedRates
supported extended rates
void AddBssMembershipSelectorRate(uint64_t bs)
Add a special value to the supported rate set, corresponding to a BSS membership selector.
uint8_t GetNRates() const
Return the number of supported rates.
bool IsBasicRate(uint64_t bs) const
Check if the given rate is a basic rate.
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 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