A Discrete-Event Network Simulator
API
supported-rates.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2006 INRIA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20
21#include "ns3/log.h"
22#include "supported-rates.h"
23
24namespace ns3 {
25
26NS_LOG_COMPONENT_DEFINE ("SupportedRates");
27
28#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
29#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
30#define BSS_MEMBERSHIP_SELECTOR_HE_PHY 122
31#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY 121 // TODO not defined yet as of 802.11be D1.4
32
34 : extended (this),
35 m_nRates (0)
36{
37 NS_LOG_FUNCTION (this);
38}
39
41{
42 NS_LOG_FUNCTION (this);
43 m_nRates = rates.m_nRates;
44 memcpy (m_rates, rates.m_rates, MAX_SUPPORTED_RATES);
45 //reset the back pointer to this object
47}
48
51{
52 this->m_nRates = rates.m_nRates;
53 memcpy (this->m_rates, rates.m_rates, MAX_SUPPORTED_RATES);
54 //reset the back pointer to this object
56 return (*this);
57}
58
59void
61{
62 NS_LOG_FUNCTION (this << bs);
63 NS_ASSERT_MSG (IsBssMembershipSelectorRate (bs) == false, "Invalid rate");
65 if (IsSupportedRate (bs))
66 {
67 return;
68 }
69 m_rates[m_nRates] = static_cast<uint8_t> (bs / 500000);
70 m_nRates++;
71 NS_LOG_DEBUG ("add rate=" << bs << ", n rates=" << +m_nRates);
72}
73
74void
76{
77 NS_LOG_FUNCTION (this << bs);
78 NS_ASSERT_MSG (IsBssMembershipSelectorRate (bs) == false, "Invalid rate");
79 uint8_t rate = static_cast<uint8_t> (bs / 500000);
80 for (uint8_t i = 0; i < m_nRates; i++)
81 {
82 if ((rate | 0x80) == m_rates[i])
83 {
84 return;
85 }
86 if (rate == m_rates[i])
87 {
88 NS_LOG_DEBUG ("set basic rate=" << bs << ", n rates=" << +m_nRates);
89 m_rates[i] |= 0x80;
90 return;
91 }
92 }
94 SetBasicRate (bs);
95}
96
97void
99{
100 NS_LOG_FUNCTION (this << bs);
105 "Value " << bs << " not a BSS Membership Selector");
106 uint8_t rate = static_cast<uint8_t> (bs / 500000);
107 for (uint8_t i = 0; i < m_nRates; i++)
108 {
109 if (rate == m_rates[i])
110 {
111 return;
112 }
113 }
114 m_rates[m_nRates] = rate;
115 NS_LOG_DEBUG ("add BSS membership selector rate " << bs << " as rate " << +rate);
116 m_nRates++;
117}
118
119bool
121{
122 NS_LOG_FUNCTION (this << bs);
123 uint8_t rate = static_cast<uint8_t> (bs / 500000) | 0x80;
124 for (uint8_t i = 0; i < m_nRates; i++)
125 {
126 if (rate == m_rates[i])
127 {
128 return true;
129 }
130 }
131 return false;
132}
133
134bool
136{
137 NS_LOG_FUNCTION (this << bs);
138 uint8_t rate = static_cast<uint8_t> (bs / 500000);
139 for (uint8_t i = 0; i < m_nRates; i++)
140 {
141 if (rate == m_rates[i]
142 || (rate | 0x80) == m_rates[i])
143 {
144 return true;
145 }
146 }
147 return false;
148}
149
150bool
152{
153 NS_LOG_FUNCTION (this << bs);
154 if ((bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY
155 || (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
156 || (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HE_PHY
157 || (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_EHT_PHY)
158 {
159 return true;
160 }
161 return false;
162}
163
164uint8_t
166{
167 return m_nRates;
168}
169
171SupportedRates::GetRate (uint8_t i) const
172{
173 return (m_rates[i] & 0x7f) * 500000;
174}
175
178{
179 return IE_SUPPORTED_RATES;
180}
181
182uint16_t
184{
185 //The Supported Rates Information Element contains only the first 8
186 //supported rates - the remainder appear in the Extended Supported
187 //Rates Information Element.
188 return m_nRates > 8 ? 8 : m_nRates;
189}
190
191void
193{
194 //The Supported Rates Information Element contains only the first 8
195 //supported rates - the remainder appear in the Extended Supported
196 //Rates Information Element.
197 start.Write (m_rates, m_nRates > 8 ? 8 : m_nRates);
198}
199
200uint16_t
202 uint16_t length)
203{
204 NS_ASSERT (length <= 8);
205 m_nRates = length;
206 start.Read (m_rates, m_nRates);
207 return m_nRates;
208}
209
211{
212}
213
215{
216 m_supportedRates = sr;
217}
218
221{
223}
224
225void
227{
228 m_supportedRates = sr;
229}
230
231uint16_t
233{
234 // If there are 8 or fewer rates then we don't need an Extended Supported
235 // Rates, so if this function is invoked in that case then it indicates a
236 // programming error. Hence we have an assertion on that condition.
238
239 //The number of rates we have beyond the initial 8 is the size of
240 //the information field.
241 return (m_supportedRates->m_nRates - 8);
242}
243
244void
246{
247 //If there are 8 or fewer rates then there should be no Extended
248 //Supported Rates Information Element at all so being here would
249 //seemingly indicate a programming error.
252}
253
254uint16_t
256 uint16_t length)
257{
258 NS_ASSERT (length > 0);
261 m_supportedRates->m_nRates += length;
262 return length;
263}
264
265std::ostream &operator << (std::ostream &os, const SupportedRates &rates)
266{
267 os << "[";
268 for (uint8_t i = 0; i < rates.GetNRates (); i++)
269 {
270 uint32_t rate = rates.GetRate (i);
271 if (rates.IsBasicRate (rate))
272 {
273 os << "*";
274 }
275 os << rate / 1000000 << "mbs";
276 if (i < rates.GetNRates () - 1)
277 {
278 os << " ";
279 }
280 }
281 os << "]";
282 return os;
283}
284
285} //namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
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(void) 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:67
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:139
@ 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:1852
#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