EMANE  1.2.1
modetimingparameters.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008-2009 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "modetimingparameters.h"
35 #include "macconfig.h"
36 #include "macstatistics.h"
37 #include "maclayer.h"
38 
39 #include "emane/packetinfo.h"
40 #include "emane/constants.h"
41 
42 #include "utils.h"
43 
44 namespace {
45  const std::uint8_t RTS_BIT_LENGTH_DEFAULT {160};
46  const std::uint8_t RTS_BIT_LENGTH_80211A {160};
47  const std::uint8_t RTS_BIT_LENGTH_80211B {160};
48  const std::uint8_t RTS_BIT_LENGTH_80211BG {160};
49 
50  const std::uint8_t CTS_BIT_LENGTH_DEFAULT {112};
51  const std::uint8_t CTS_BIT_LENGTH_80211A {112};
52  const std::uint8_t CTS_BIT_LENGTH_80211B {112};
53  const std::uint8_t CTS_BIT_LENGTH_80211BG {112};
54 
55  const std::uint8_t ACK_BIT_LENGTH_DEFAULT {112};
56  const std::uint8_t ACK_BIT_LENGTH_80211A {112};
57  const std::uint8_t ACK_BIT_LENGTH_80211B {112};
58  const std::uint8_t ACK_BIT_LENGTH_80211BG {112};
59 
60  const EMANE::Microseconds SLOT_TIME_USEC_DEFAULT {9};
61  const EMANE::Microseconds SLOT_TIME_USEC_80211A {9};
62  const EMANE::Microseconds SLOT_TIME_USEC_80211B {20};
63  const EMANE::Microseconds SLOT_TIME_USEC_80211BG {20};
64 
65  const EMANE::Microseconds SIFS_TIME_USEC_DEFAULT {10};
66  const EMANE::Microseconds SIFS_TIME_USEC_80211A {16};
67  const EMANE::Microseconds SIFS_TIME_USEC_80211B {10};
68  const EMANE::Microseconds SIFS_TIME_USEC_80211BG {16};
69 
70  const EMANE::Microseconds PREAMBLE_TIME_USEC_DEFAULT {192};
71  const EMANE::Microseconds PREAMBLE_TIME_USEC_80211A {20};
72  const EMANE::Microseconds PREAMBLE_TIME_USEC_80211B {192};
73  const EMANE::Microseconds PREAMBLE_TIME_USEC_80211BG {192};
74 
75 
76  const std::uint16_t IEEE_80211MAC_DATAHEADER_BITLEN {272};
77  const std::uint16_t IEEE_80211MAC_CTRLHEADER_BITLEN {160};
78 
79  const float SLOT_TIME_DISTANCE_DIVISOR_SEC_F {299792458.0f};
80 }
81 
88  macConfig_(macConfig)
89 {
90  // default
91  timingParams_[MODULATION_TYPE_DEFAULT].u16RtsBitLength_ = RTS_BIT_LENGTH_DEFAULT;
92  timingParams_[MODULATION_TYPE_DEFAULT].u16CtsBitLength_ = CTS_BIT_LENGTH_DEFAULT;
93  timingParams_[MODULATION_TYPE_DEFAULT].u16AckBitLength_ = ACK_BIT_LENGTH_DEFAULT;
94  timingParams_[MODULATION_TYPE_DEFAULT].slotMicroseconds_ = SLOT_TIME_USEC_DEFAULT;
95  timingParams_[MODULATION_TYPE_DEFAULT].sifsMicroseconds_ = SIFS_TIME_USEC_DEFAULT;
96  timingParams_[MODULATION_TYPE_DEFAULT].preambleMicroseconds_ = PREAMBLE_TIME_USEC_DEFAULT;
97 
98  // 802.11a (OFDM)
99  timingParams_[MODULATION_TYPE_80211A].u16RtsBitLength_ = RTS_BIT_LENGTH_80211A;
100  timingParams_[MODULATION_TYPE_80211A].u16CtsBitLength_ = CTS_BIT_LENGTH_80211A;
101  timingParams_[MODULATION_TYPE_80211A].u16AckBitLength_ = ACK_BIT_LENGTH_80211A;
102  timingParams_[MODULATION_TYPE_80211A].slotMicroseconds_ = SLOT_TIME_USEC_80211A;
103  timingParams_[MODULATION_TYPE_80211A].sifsMicroseconds_ = SIFS_TIME_USEC_80211A;
104  timingParams_[MODULATION_TYPE_80211A].preambleMicroseconds_ = PREAMBLE_TIME_USEC_80211A;
105 
106  // 802.11b (DSS)
107  timingParams_[MODULATION_TYPE_80211B].u16RtsBitLength_ = RTS_BIT_LENGTH_80211B;
108  timingParams_[MODULATION_TYPE_80211B].u16CtsBitLength_ = CTS_BIT_LENGTH_80211B;
109  timingParams_[MODULATION_TYPE_80211B].u16AckBitLength_ = ACK_BIT_LENGTH_80211B;
110  timingParams_[MODULATION_TYPE_80211B].slotMicroseconds_ = SLOT_TIME_USEC_80211B;
111  timingParams_[MODULATION_TYPE_80211B].sifsMicroseconds_ = SIFS_TIME_USEC_80211B;
112  timingParams_[MODULATION_TYPE_80211B].preambleMicroseconds_ = PREAMBLE_TIME_USEC_80211B;
113 
114  // 802.11b/g (MIXED)
115  timingParams_[MODULATION_TYPE_80211BG].u16RtsBitLength_ = RTS_BIT_LENGTH_80211BG;
116  timingParams_[MODULATION_TYPE_80211BG].u16CtsBitLength_ = CTS_BIT_LENGTH_80211BG;
117  timingParams_[MODULATION_TYPE_80211BG].u16AckBitLength_ = ACK_BIT_LENGTH_80211BG;
118  timingParams_[MODULATION_TYPE_80211BG].slotMicroseconds_ = SLOT_TIME_USEC_80211BG;
119  timingParams_[MODULATION_TYPE_80211BG].sifsMicroseconds_ = SIFS_TIME_USEC_80211BG;
120  timingParams_[MODULATION_TYPE_80211BG].preambleMicroseconds_ = PREAMBLE_TIME_USEC_80211BG;
121 }
122 
123 
130 { }
131 
132 
142 std::uint16_t EMANE::Models::IEEE80211ABG::ModeTimingParameters::getRtsBitLength(MODULATION_TYPE mode) const
143 {
144  switch(mode)
145  {
146  case MODULATION_TYPE_80211A: // 80211.a (OFDM)
147  return timingParams_[MODULATION_TYPE_80211A].u16RtsBitLength_;
148 
149  case MODULATION_TYPE_80211B: // 802.11b (DSS)
150  return timingParams_[MODULATION_TYPE_80211B].u16RtsBitLength_;
151 
152  case MODULATION_TYPE_80211BG: // 802.11b/g (MIXED)
153  return timingParams_[MODULATION_TYPE_80211BG].u16RtsBitLength_;
154 
155  default: // default
156  return timingParams_[MODULATION_TYPE_DEFAULT].u16RtsBitLength_;
157  }
158 }
159 
160 
170 std::uint16_t
171 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getCtsBitLength(MODULATION_TYPE mode) const
172 {
173  switch(mode)
174  {
175  case MODULATION_TYPE_80211A: // 80211.a (OFDM)
176  return timingParams_[MODULATION_TYPE_80211A].u16CtsBitLength_;
177 
178  case MODULATION_TYPE_80211B: // 802.11b (DSS)
179  return timingParams_[MODULATION_TYPE_80211B].u16CtsBitLength_;
180 
181  case MODULATION_TYPE_80211BG: // 802.11b/g (MIXED)
182  return timingParams_[MODULATION_TYPE_80211BG].u16CtsBitLength_;
183 
184  default: // default
185  return timingParams_[MODULATION_TYPE_DEFAULT].u16CtsBitLength_;
186  }
187 }
188 
189 
199 std::uint16_t
200 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getAckBitLength(MODULATION_TYPE mode) const
201 {
202  switch(mode)
203  {
204  case MODULATION_TYPE_80211A: // 80211.a (OFDM)
205  return timingParams_[MODULATION_TYPE_80211A].u16AckBitLength_;
206 
207  case MODULATION_TYPE_80211B: // 802.11b (DSS)
208  return timingParams_[MODULATION_TYPE_80211B].u16AckBitLength_;
209 
210  case MODULATION_TYPE_80211BG: // 802.11b/g (MIXED)
211  return timingParams_[MODULATION_TYPE_80211BG].u16AckBitLength_;
212 
213  default: // default
214  return timingParams_[MODULATION_TYPE_DEFAULT].u16AckBitLength_;
215  }
216 }
217 
218 
228 {
229  const MODULATION_TYPE mode{macConfig_.getModulationType()};
230 
231  const std::uint32_t dist{macConfig_.getMaxP2pDistance()};
232 
233  switch(mode)
234  {
235  case MODULATION_TYPE_80211A: // 80211.a (OFDM)
236  return timingParams_[MODULATION_TYPE_80211A].slotMicroseconds_ + getPropagationMicroseconds(dist);
237 
238  case MODULATION_TYPE_80211B: // 802.11b (DSS)
239  return timingParams_[MODULATION_TYPE_80211B].slotMicroseconds_ + getPropagationMicroseconds(dist);
240 
241  case MODULATION_TYPE_80211BG: // 802.11b/g (MIXED)
242  return timingParams_[MODULATION_TYPE_80211BG].slotMicroseconds_ + getPropagationMicroseconds(dist);
243 
244  default: // default
245  return timingParams_[MODULATION_TYPE_DEFAULT].slotMicroseconds_ + getPropagationMicroseconds(dist);
246  }
247 }
248 
249 
260 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getSifsMicroseconds(MODULATION_TYPE mode) const
261 {
262  switch(mode)
263  {
264  case MODULATION_TYPE_80211A: // 80211.a (OFDM)
265  return timingParams_[MODULATION_TYPE_80211A].sifsMicroseconds_;
266 
267  case MODULATION_TYPE_80211B: // 802.11b (DSS)
268  return timingParams_[MODULATION_TYPE_80211B].sifsMicroseconds_;
269 
270  case MODULATION_TYPE_80211BG: // 802.11b/g (MIXED)
271  return timingParams_[MODULATION_TYPE_80211BG].sifsMicroseconds_;
272 
273  default: // default
274  return timingParams_[MODULATION_TYPE_DEFAULT].sifsMicroseconds_;
275  }
276 }
277 
278 
289 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getPreambleMicroseconds(MODULATION_TYPE mode) const
290 {
291  switch(mode)
292  {
293  case MODULATION_TYPE_80211A: // 80211.a (OFDM)
294  return timingParams_[MODULATION_TYPE_80211A].preambleMicroseconds_;
295 
296  case MODULATION_TYPE_80211B: // 802.11b (DSS)
297  return timingParams_[MODULATION_TYPE_80211B].preambleMicroseconds_;
298 
299  case MODULATION_TYPE_80211BG: // 802.11b/g (MIXED)
300  return timingParams_[MODULATION_TYPE_80211BG].preambleMicroseconds_;
301 
302  default: // default
303  return timingParams_[MODULATION_TYPE_DEFAULT].preambleMicroseconds_;
304  }
305 }
306 
307 
318 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getPropagationMicroseconds(std::uint32_t dist) const
319 {
320  return std::chrono::duration_cast<Microseconds>(DoubleSeconds{dist / SLOT_TIME_DISTANCE_DIVISOR_SEC_F});
321 }
322 
323 
335 {
336  const MODULATION_TYPE mode {macConfig_.getModulationType()};
337 
338  const Microseconds m{macConfig_.getAifsMicroseconds(u8Category).count() *
339  getSlotSizeMicroseconds().count() +
340  getSifsMicroseconds(mode).count()};
341 
342  return m;
343 }
344 
356 {
357  const MODULATION_TYPE mode {macConfig_.getModulationType()};
358 
359  DoubleSeconds doubleSeconds{(getSlotSizeMicroseconds().count() *
360  (macConfig_.getAifsMicroseconds(u8Category).count() + (macConfig_.getCWMin(u8Category) / 2.0f)) +
361  getSifsMicroseconds(mode).count()) / USEC_PER_SEC_F};
362 
363  return std::chrono::duration_cast<Microseconds>(doubleSeconds);
364 }
365 
366 
367 
368 
369 
380 bool
382  const TimePoint & rxTime) const
383 {
384  // txop is enabled when non zero
385  if(txOpMicroseconds.count() != 0)
386  {
387  // timed out if sent time plus txop is in the past
388  return(rxTime + txOpMicroseconds) < Clock::now();
389  }
390 
391  return false;
392 }
393 
394 
395 
396 
409 {
410  switch(type)
411  {
412  // cts
414  return getCtsMessageDurationMicroseconds();
415 
416  // unicast data
418  return getUnicastMessageDurationMicroseconds(numBytes);
419 
420  // unicast data rst-cts
422  return getUnicastMessageDurationMicroseconds(numBytes) +
423  getRtsMessageDurationMicroseconds() +
424  getCtsMessageDurationMicroseconds();
425 
426  // broadcast data
428  return getBroadcastMessageDurationMicroseconds(numBytes);
429 
430  default:
431  return Microseconds::zero();
432  }
433 }
434 
435 
437 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getBroadcastMessageDurationMicroseconds(size_t numBytes) const
438 {
439  const MODULATION_TYPE mode {macConfig_.getModulationType()};
440 
441  DoubleSeconds doubleSeconds{(getPreambleMicroseconds(mode).count() +
442  ((IEEE_80211MAC_DATAHEADER_BITLEN + (numBytes * 8)) /
443  (macConfig_.getBroadcastDataRateKbps() / 1000.0f))) / USEC_PER_SEC_F};
444 
445  return std::chrono::duration_cast<Microseconds>(doubleSeconds);
446 }
447 
448 
449 
451 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getUnicastMessageDurationMicroseconds(size_t numBytes) const
452 {
453  const MODULATION_TYPE mode {macConfig_.getModulationType()};
454 
455  DoubleSeconds doubleSeconds{(getSifsMicroseconds(mode).count() + (2 * getPreambleMicroseconds(mode).count()) +
456  ((IEEE_80211MAC_DATAHEADER_BITLEN + getAckBitLength(mode) + (numBytes * 8)) /
457  (macConfig_.getUnicastDataRateKbps() / 1000.0f))) / USEC_PER_SEC_F};
458 
459  return std::chrono::duration_cast<Microseconds>(doubleSeconds);
460 }
461 
462 
463 
465 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getCtsMessageDurationMicroseconds() const
466 {
467  const MODULATION_TYPE mode {macConfig_.getModulationType()};
468 
469  DoubleSeconds doubleSeconds{(getPreambleMicroseconds(mode).count() +
470  (IEEE_80211MAC_CTRLHEADER_BITLEN / (macConfig_.getUnicastDataRateKbps() / 1000.0f))) / USEC_PER_SEC_F};
471 
472  return std::chrono::duration_cast<Microseconds>(doubleSeconds);
473 }
474 
475 
476 
478 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getRtsMessageDurationMicroseconds() const
479 {
480  const MODULATION_TYPE mode {macConfig_.getModulationType()};
481 
482  DoubleSeconds doubleSeconds{(getPreambleMicroseconds(mode).count() +
483  (IEEE_80211MAC_CTRLHEADER_BITLEN / (macConfig_.getUnicastDataRateKbps() / 1000.0f))) / USEC_PER_SEC_F};
484 
485  return std::chrono::duration_cast<Microseconds>(doubleSeconds);
486 }
487 
488 
489 
490 
501 int
502 EMANE::Models::IEEE80211ABG::ModeTimingParameters::getContentionWindow(std::uint8_t u8Category, std::uint8_t tries) const
503 {
504  const int min{macConfig_.getCWMin(u8Category)};
505  const int max{macConfig_.getCWMax(u8Category)};
506 
507  int cw{min * static_cast<int>(powf(2.0f, tries))};
508 
509  if(cw > max)
510  {
511  cw = max;
512  }
513  else if(cw < min)
514  {
515  cw = min;
516  }
517 
518  return cw;
519 }
const std::uint8_t MSG_TYPE_UNICAST_CTS_CTRL
Definition: msgtypes.h:48
class used to define the mac layer configuration items
Definition: macconfig.h:152
std::uint32_t getBroadcastDataRateKbps() const
get the broadcast datarate
Definition: macconfig.cc:548
int getContentionWindow(std::uint8_t, std::uint8_t) const
get the contention window
bool packetTimedOut(const Microseconds &txOpMicroseconds, const TimePoint &) const
check if a packet has timed out
Microseconds getAifsMicroseconds(std::uint8_t) const
get the aifs for a given queue index
Definition: macconfig.cc:806
ModeTimingParameters(const MACConfig &macConfig)
constructor
std::uint16_t getCWMin(std::uint8_t) const
get the min contention window size for a given queue index
Definition: macconfig.cc:680
Microseconds getOverheadMicroseconds(std::uint8_t u8Category) const
get the overhead time
const std::uint8_t MSG_TYPE_BROADCAST_DATA
Definition: msgtypes.h:45
std::uint32_t getUnicastDataRateKbps() const
get the unicast datarate
Definition: macconfig.cc:523
std::chrono::microseconds Microseconds
Definition: types.h:45
std::chrono::duration< double > DoubleSeconds
Definition: types.h:47
const float USEC_PER_SEC_F
Definition: constants.h:61
const std::uint8_t MSG_TYPE_UNICAST_DATA
Definition: msgtypes.h:46
MODULATION_TYPE getModulationType() const
get the modulation type
Definition: macconfig.cc:468
Microseconds getSlotSizeMicroseconds() const
get the slot duration for a given mode and distance
Clock::time_point TimePoint
Definition: types.h:50
std::uint16_t getCWMax(std::uint8_t) const
get the max contention window size for a given queue index
Definition: macconfig.cc:709
Microseconds getDeferIntervalMicroseconds(std::uint8_t) const
get the defer time
Microseconds getMessageDurationMicroseconds(std::uint8_t, size_t) const
get the message duration
std::uint32_t getMaxP2pDistance() const
get the max ptp distance
Definition: macconfig.cc:591
const std::uint8_t MSG_TYPE_UNICAST_RTS_CTS_DATA
Definition: msgtypes.h:47