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
24#include <algorithm>
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("SupportedRates");
30
31#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
32#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
33#define BSS_MEMBERSHIP_SELECTOR_HE_PHY 122
34#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY 121 // TODO not defined yet as of 802.11be D1.4
35
37{
38 NS_LOG_FUNCTION(this);
39}
40
41void
42SupportedRates::Print(std::ostream& os) const
43{
44 os << "rates=[";
45 for (std::size_t i = 0; i < m_rates.size(); i++)
46 {
47 if ((m_rates[i] & 0x80) > 0)
48 {
49 os << "*";
50 }
51 os << GetRate(i) / 1000000 << "mbs";
52 if (i < m_rates.size() - 1)
53 {
54 os << " ";
55 }
56 }
57 os << "]";
58}
59
60bool
62{
63 NS_LOG_FUNCTION(this << bs);
64 uint8_t rate = static_cast<uint8_t>(bs / 500000) | 0x80;
65 return std::find(rates.m_rates.cbegin(), rates.m_rates.cend(), rate) != rates.m_rates.cend() ||
67 std::find(extendedRates->m_rates.cbegin(), extendedRates->m_rates.cend(), rate) !=
68 extendedRates->m_rates.cend());
69}
70
71void
73{
74 NS_LOG_FUNCTION(this << bs);
75 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
76 if (IsSupportedRate(bs))
77 {
78 return;
79 }
80 if (rates.m_rates.size() < 8)
81 {
82 rates.m_rates.emplace_back(static_cast<uint8_t>(bs / 500000));
83 }
84 else
85 {
86 if (!extendedRates)
87 {
88 extendedRates.emplace();
89 }
90 extendedRates->m_rates.emplace_back(static_cast<uint8_t>(bs / 500000));
91 }
92 NS_LOG_DEBUG("add rate=" << bs << ", n rates=" << +GetNRates());
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << bs);
99 NS_ASSERT_MSG(IsBssMembershipSelectorRate(bs) == false, "Invalid rate");
100 auto rate = static_cast<uint8_t>(bs / 500000);
101 for (uint8_t i = 0; i < GetNRates(); i++)
102 {
103 auto& currRate = i < 8 ? rates.m_rates[i] : extendedRates->m_rates[i - 8];
104 if ((rate | 0x80) == currRate)
105 {
106 return;
107 }
108 if (rate == currRate)
109 {
110 NS_LOG_DEBUG("set basic rate=" << bs << ", n rates=" << +GetNRates());
111 currRate |= 0x80;
112 return;
113 }
114 }
116 SetBasicRate(bs);
117}
118
119void
121{
122 NS_LOG_FUNCTION(this << bs);
125 "Value " << bs << " not a BSS Membership Selector");
126 auto rate = static_cast<uint8_t>(bs / 500000);
127 for (std::size_t i = 0; i < rates.m_rates.size(); i++)
128 {
129 if (rate == rates.m_rates[i])
130 {
131 return;
132 }
133 }
134 if (extendedRates)
135 {
136 for (std::size_t i = 0; i < extendedRates->m_rates.size(); i++)
137 {
138 if (rate == extendedRates->m_rates[i])
139 {
140 return;
141 }
142 }
143 }
144 if (rates.m_rates.size() < 8)
145 {
146 rates.m_rates.emplace_back(rate);
147 }
148 else
149 {
150 if (!extendedRates)
151 {
152 extendedRates.emplace();
153 }
154 extendedRates->m_rates.emplace_back(rate);
155 }
156 NS_LOG_DEBUG("add BSS membership selector rate " << bs << " as rate " << +rate);
157}
158
159bool
161{
162 NS_LOG_FUNCTION(this << bs);
163 auto rate = static_cast<uint8_t>(bs / 500000);
164 for (std::size_t i = 0; i < rates.m_rates.size(); i++)
165 {
166 if (rate == rates.m_rates[i] || (rate | 0x80) == rates.m_rates[i])
167 {
168 return true;
169 }
170 }
171 if (extendedRates)
172 {
173 for (std::size_t i = 0; i < extendedRates->m_rates.size(); i++)
174 {
175 if (rate == extendedRates->m_rates[i] || (rate | 0x80) == extendedRates->m_rates[i])
176 {
177 return true;
178 }
179 }
180 }
181 return false;
182}
183
184bool
186{
187 NS_LOG_FUNCTION(this << bs);
188 return (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY ||
189 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_VHT_PHY ||
190 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HE_PHY ||
191 (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_EHT_PHY;
192}
193
194uint8_t
196{
197 return rates.m_rates.size() + (extendedRates ? extendedRates->m_rates.size() : 0);
198}
199
202{
203 return (m_rates[i] & 0x7f) * 500000;
204}
205
208{
209 return IE_SUPPORTED_RATES;
210}
211
212uint16_t
214{
215 return m_rates.size();
216}
217
218void
220{
221 for (const uint8_t rate : m_rates)
222 {
223 start.WriteU8(rate);
224 }
225}
226
227uint16_t
229{
230 NS_ASSERT(length <= 8);
231 for (uint16_t i = 0; i < length; i++)
232 {
233 m_rates.push_back(start.ReadU8());
234 }
235 return length;
236}
237
240{
242}
243
244} // 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