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 "supported-rates.h"
22 #include "ns3/log.h"
23 
24 namespace ns3 {
25 
26 NS_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 125
31 
33  : extended (this),
34  m_nRates (0)
35 {
36  NS_LOG_FUNCTION (this);
37 }
38 
40 {
41  NS_LOG_FUNCTION (this);
42  m_nRates = rates.m_nRates;
43  memcpy (m_rates, rates.m_rates, MAX_SUPPORTED_RATES);
44  //reset the back pointer to this object
46 }
47 
50 {
51  this->m_nRates = rates.m_nRates;
52  memcpy (this->m_rates, rates.m_rates, MAX_SUPPORTED_RATES);
53  //reset the back pointer to this object
54  this->extended.SetSupportedRates (this);
55  return (*this);
56 }
57 
58 void
60 {
61  NS_LOG_FUNCTION (this << bs);
62  NS_ASSERT_MSG (IsBssMembershipSelectorRate (bs) == false, "Invalid rate");
65  {
66  // Encoding defined in Sec. 8.4.2.3, IEEE 802.11-2012
68  m_nRates++;
69  NS_LOG_DEBUG ("add HT_PHY membership selector");
70  }
71  else if (bs == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
72  {
73  // Encoding defined in Sec. 8.4.2.3, IEEE 802.11-2012
75  m_nRates++;
76  NS_LOG_DEBUG ("add VHT_PHY membership selector");
77  }
78  else if (bs == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
79  {
80  // Encoding defined in Sec. 8.4.2.3, IEEE 802.11-2012
82  m_nRates++;
83  NS_LOG_DEBUG ("add HE_PHY membership selector");
84  }
85  else
86  {
87  if (IsSupportedRate (bs))
88  {
89  return;
90  }
91  m_rates[m_nRates] = bs / 500000;
92  m_nRates++;
93  NS_LOG_DEBUG ("add rate=" << bs << ", n rates=" << (uint32_t)m_nRates);
94  }
95 }
96 
97 void
99 {
100  NS_LOG_FUNCTION (this << bs);
101  NS_ASSERT_MSG (IsBssMembershipSelectorRate (bs) == false, "Invalid rate");
102  uint8_t rate = bs / 500000;
103  for (uint8_t i = 0; i < m_nRates; i++)
104  {
105  if ((rate | 0x80) == m_rates[i])
106  {
107  return;
108  }
109  if (rate == m_rates[i])
110  {
111  NS_LOG_DEBUG ("set basic rate=" << bs << ", n rates=" << (uint32_t)m_nRates);
112  m_rates[i] |= 0x80;
113  return;
114  }
115  }
116  AddSupportedRate (bs);
117  SetBasicRate (bs);
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION (this << bs);
125  {
126  NS_ASSERT_MSG (false, "Value " << bs << " not a BSS Membership Selector");
127  }
128  uint32_t rate = (bs | 0x80);
129  for (uint8_t i = 0; i < m_nRates; i++)
130  {
131  if (rate == m_rates[i])
132  {
133  return;
134  }
135  }
136  m_rates[m_nRates] = rate;
137  NS_LOG_DEBUG ("add BSS membership selector rate " << bs << " as rate " << m_nRates);
138  m_nRates++;
139 }
140 
141 bool
142 SupportedRates::IsBasicRate (uint32_t bs) const
143 {
144  NS_LOG_FUNCTION (this << bs);
145  uint8_t rate = (bs / 500000) | 0x80;
146  for (uint8_t i = 0; i < m_nRates; i++)
147  {
148  if (rate == m_rates[i])
149  {
150  return true;
151  }
152  }
153  return false;
154 }
155 
156 bool
158 {
159  NS_LOG_FUNCTION (this << bs);
160  uint8_t rate = bs / 500000;
161  for (uint8_t i = 0; i < m_nRates; i++)
162  {
163  if (rate == m_rates[i]
164  || (rate | 0x80) == m_rates[i])
165  {
166  return true;
167  }
168  }
169  return false;
170 }
171 
172 bool
174 {
175  NS_LOG_FUNCTION (this << bs);
176  if ((bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY
177  || (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
178  || (bs & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
179  {
180  return true;
181  }
182  return false;
183 }
184 
185 uint8_t
187 {
188  return m_nRates;
189 }
190 
191 uint32_t
192 SupportedRates::GetRate (uint8_t i) const
193 {
194  return (m_rates[i] & 0x7f) * 500000;
195 }
196 
199 {
200  return IE_SUPPORTED_RATES;
201 }
202 
203 uint8_t
205 {
206  //The Supported Rates Information Element contains only the first 8
207  //supported rates - the remainder appear in the Extended Supported
208  //Rates Information Element.
209  return m_nRates > 8 ? 8 : m_nRates;
210 }
211 
212 void
214 {
215  //The Supported Rates Information Element contains only the first 8
216  //supported rates - the remainder appear in the Extended Supported
217  //Rates Information Element.
218  start.Write (m_rates, m_nRates > 8 ? 8 : m_nRates);
219 }
220 
221 uint8_t
223  uint8_t length)
224 {
225  NS_ASSERT (length <= 8);
226  m_nRates = length;
227  start.Read (m_rates, m_nRates);
228  return m_nRates;
229 }
230 
232 {
233 }
234 
236 {
237  m_supportedRates = sr;
238 }
239 
242 {
244 }
245 
246 void
248 {
249  m_supportedRates = sr;
250 }
251 
252 uint8_t
254 {
255  //If there are 8 or fewer rates then we don't need an Extended
256  //Supported Rates IE and so could return zero here, but we're
257  //overriding the GetSerializedSize() method, so if this function is
258  //invoked in that case then it indicates a programming error. Hence
259  //we have an assertion on that condition.
261 
262  //The number of rates we have beyond the initial 8 is the size of
263  //the information field.
264  return (m_supportedRates->m_nRates - 8);
265 }
266 
267 void
269 {
270  //If there are 8 or fewer rates then there should be no Extended
271  //Supported Rates Information Element at all so being here would
272  //seemingly indicate a programming error.
273  //
274  //Our overridden version of the Serialize() method should ensure
275  //that this routine is never invoked in that case (by ensuring that
276  //WifiInformationElement::Serialize() is not invoked).
279 }
280 
283 {
284  //If there are 8 or fewer rates then we don't need an Extended
285  //Supported Rates IE, so we don't serialise anything.
286  if (m_supportedRates->m_nRates <= 8)
287  {
288  return start;
289  }
290 
291  //If there are more than 8 rates then we serialise as per normal.
292  return WifiInformationElement::Serialize (start);
293 }
294 
295 uint16_t
297 {
298  //If there are 8 or fewer rates then we don't need an Extended
299  //Supported Rates IE, so it's serialised length will be zero.
300  if (m_supportedRates->m_nRates <= 8)
301  {
302  return 0;
303  }
304 
305  //Otherwise, the size of it will be the number of supported rates
306  //beyond 8, plus 2 for the Element ID and Length.
308 }
309 
310 uint8_t
312  uint8_t length)
313 {
314  NS_ASSERT (length > 0);
317  m_supportedRates->m_nRates += length;
318  return length;
319 }
320 
329 std::ostream &operator << (std::ostream &os, const SupportedRates &rates)
330 {
331  os << "[";
332  for (uint8_t i = 0; i < rates.GetNRates (); i++)
333  {
334  uint32_t rate = rates.GetRate (i);
335  if (rates.IsBasicRate (rate))
336  {
337  os << "*";
338  }
339  os << rate / 1000000 << "mbs";
340  if (i < rates.GetNRates () - 1)
341  {
342  os << " ";
343  }
344  }
345  os << "]";
346  return os;
347 }
348 
349 } //namespace ns3
uint32_t GetRate(uint8_t i) const
Return the rate at the given index.
void AddSupportedRate(uint32_t bs)
Add the given rate to the supported rates.
SupportedRates & operator=(const SupportedRates &rates)
assignment operator
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information field.
def start()
Definition: core.py:1790
uint16_t GetSerializedSize() const
Return the serialized size of this supported rates information element.
#define BSS_MEMBERSHIP_SELECTOR_HT_PHY
#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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint8_t GetNRates(void) const
Return the number of supported rates.
void SerializeInformationField(Buffer::Iterator start) const
Get the information field size.
The Supported Rates Information ElementThis class knows how to serialise and deserialise the Supporte...
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields.
iterator in a Buffer instance
Definition: buffer.h:98
ExtendedSupportedRatesIE extended
extended suppoted rates info element
Buffer::Iterator Serialize(Buffer::Iterator start) const
This information element is a bit special in that it is only included if there are more than 8 rates...
WifiInformationElementId ElementId() const
Get element ID.
uint8_t GetInformationFieldSize() const
Get information field size.
#define IE_SUPPORTED_RATES
void SetSupportedRates(SupportedRates *rates)
Set supported rates.
void SetBasicRate(uint32_t bs)
Set the given rate to basic rates.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
bool IsBasicRate(uint32_t bs) const
Check if the given rate is a basic rate.
uint8_t m_nRates
Number of supported rates.
#define BSS_MEMBERSHIP_SELECTOR_HE_PHY
void AddBssMembershipSelectorRate(uint32_t bs)
Add a special value to the supported rate set, corresponding to a BSS membership selector.
#define IE_EXTENDED_SUPPORTED_RATES
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t m_rates[MAX_SUPPORTED_RATES]
List of supported bitrate (divided by 500000)
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1126
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Get the information field size.
#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY
#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:90
SupportedRates * m_supportedRates
This member points to the SupportedRates object that contains the actual rate details.
WifiInformationElementId ElementId() const
Get the ElementID.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:956
bool IsSupportedRate(uint32_t bs) const
Check if the given rate is supported.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint8_t GetInformationFieldSize() const
Get the information field size.
void SerializeInformationField(Buffer::Iterator start) const
Serialize information field.
static const uint8_t MAX_SUPPORTED_RATES
This defines the maximum number of supported rates that a STA is allowed to have. ...
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.
bool IsBssMembershipSelectorRate(uint32_t bs) const
Check if the given rate is a BSS membership selector value.