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 * 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{
36 NS_LOG_FUNCTION(this);
37}
38
39void
40SupportedRates::Print(std::ostream& os) const
41{
42 os << "rates=[";
43 for (std::size_t i = 0; i < m_rates.size(); i++)
44 {
45 if ((m_rates[i] & 0x80) > 0)
46 {
47 os << "*";
48 }
49 os << GetRate(i) / 1000000 << "mbs";
50 if (i < m_rates.size() - 1)
51 {
52 os << " ";
53 }
54 }
55 os << "]";
56}
57
58bool
60{
61 NS_LOG_FUNCTION(this << bs);
62 uint8_t rate = static_cast<uint8_t>(bs / 500000) | 0x80;
63 return std::find(rates.m_rates.cbegin(), rates.m_rates.cend(), rate) != rates.m_rates.cend() ||
65 std::find(extendedRates->m_rates.cbegin(), extendedRates->m_rates.cend(), rate) !=
66 extendedRates->m_rates.cend());
67}
68
69void
71{
72 NS_LOG_FUNCTION(this << bs);
73 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
74 if (IsSupportedRate(bs))
75 {
76 return;
77 }
78 if (rates.m_rates.size() < 8)
79 {
80 rates.m_rates.emplace_back(static_cast<uint8_t>(bs / 500000));
81 }
82 else
83 {
84 if (!extendedRates)
85 {
86 extendedRates.emplace();
87 }
88 extendedRates->m_rates.emplace_back(static_cast<uint8_t>(bs / 500000));
89 }
90 NS_LOG_DEBUG("add rate=" << bs << ", n rates=" << +GetNRates());
91}
92
93void
95{
96 NS_LOG_FUNCTION(this << bs);
97 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
98 uint8_t rate = static_cast<uint8_t>(bs / 500000);
99 for (uint8_t i = 0; i < GetNRates(); i++)
100 {
101 auto& currRate = i < 8 ? rates.m_rates[i] : extendedRates->m_rates[i - 8];
102 if ((rate | 0x80) == currRate)
103 {
104 return;
105 }
106 if (rate == currRate)
107 {
108 NS_LOG_DEBUG("set basic rate=" << bs << ", n rates=" << +GetNRates());
109 currRate |= 0x80;
110 return;
111 }
112 }
114 SetBasicRate(bs);
115}
116
117void
119{
120 NS_LOG_FUNCTION(this << bs);
123 "Value " << bs << " not a BSS Membership Selector");
124 uint8_t rate = static_cast<uint8_t>(bs / 500000);
125 for (std::size_t i = 0; i < rates.m_rates.size(); i++)
126 {
127 if (rate == rates.m_rates[i])
128 {
129 return;
130 }
131 }
132 if (extendedRates)
133 {
134 for (std::size_t i = 0; i < extendedRates->m_rates.size(); i++)
135 {
136 if (rate == extendedRates->m_rates[i])
137 {
138 return;
139 }
140 }
141 }
142 if (rates.m_rates.size() < 8)
143 {
144 rates.m_rates.emplace_back(rate);
145 }
146 else
147 {
148 if (!extendedRates)
149 {
150 extendedRates.emplace();
151 }
152 extendedRates->m_rates.emplace_back(rate);
153 }
154 NS_LOG_DEBUG("add BSS membership selector rate " << bs << " as rate " << +rate);
155}
156
157bool
159{
160 NS_LOG_FUNCTION(this << bs);
161 uint8_t rate = static_cast<uint8_t>(bs / 500000);
162 for (std::size_t i = 0; i < rates.m_rates.size(); i++)
163 {
164 if (rate == rates.m_rates[i] || (rate | 0x80) == rates.m_rates[i])
165 {
166 return true;
167 }
168 }
169 if (extendedRates)
170 {
171 for (std::size_t i = 0; i < extendedRates->m_rates.size(); i++)
172 {
173 if (rate == extendedRates->m_rates[i] || (rate | 0x80) == extendedRates->m_rates[i])
174 {
175 return true;
176 }
177 }
178 }
179 return false;
180}
181
182bool
184{
185 NS_LOG_FUNCTION(this << bs);
186 return (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY ||
187 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_VHT_PHY ||
188 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HE_PHY ||
189 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_EHT_PHY;
190}
191
192uint8_t
194{
195 return rates.m_rates.size() + (extendedRates ? extendedRates->m_rates.size() : 0);
196}
197
200{
201 return (m_rates[i] & 0x7f) * 500000;
202}
203
206{
207 return IE_SUPPORTED_RATES;
208}
209
210uint16_t
212{
213 return m_rates.size();
214}
215
216void
218{
219 for (const uint8_t rate : m_rates)
220 {
221 start.WriteU8(rate);
222 }
223}
224
225uint16_t
227{
228 NS_ASSERT(length <= 8);
229 for (uint16_t i = 0; i < length; i++)
230 {
231 m_rates.push_back(start.ReadU8());
232 }
233 return length;
234}
235
238{
240}
241
242} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
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: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.
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