A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wifi-remote-station-manager.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 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 "wifi-remote-station-manager.h"
22 #include "ns3/simulator.h"
23 #include "ns3/assert.h"
24 #include "ns3/log.h"
25 #include "ns3/tag.h"
26 #include "ns3/boolean.h"
27 #include "ns3/double.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/wifi-phy.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "wifi-mac-header.h"
32 #include "wifi-mac-trailer.h"
33 
34 NS_LOG_COMPONENT_DEFINE ("WifiRemoteStationManager");
35 
36 
37 /***************************************************************
38  * Packet Mode Tagger
39  ***************************************************************/
40 
41 namespace ns3 {
42 
43 class TxModeTag : public Tag
44 {
45 public:
46  TxModeTag ();
47  TxModeTag (WifiMode rtsMode, WifiMode dataMode);
48  WifiMode GetRtsMode (void) const;
49  WifiMode GetDataMode (void) const;
50 
51  static TypeId GetTypeId (void);
52  virtual TypeId GetInstanceTypeId (void) const;
53  virtual uint32_t GetSerializedSize (void) const;
54  virtual void Serialize (TagBuffer i) const;
55  virtual void Deserialize (TagBuffer i);
56  virtual void Print (std::ostream &os) const;
57 private:
58  WifiMode m_rtsMode;
59  WifiMode m_dataMode;
60 };
61 
62 TxModeTag::TxModeTag ()
63 {
64 }
65 TxModeTag::TxModeTag (WifiMode rtsMode, WifiMode dataMode)
66  : m_rtsMode (rtsMode),
67  m_dataMode (dataMode)
68 {
69 }
70 WifiMode
71 TxModeTag::GetRtsMode (void) const
72 {
73  return m_rtsMode;
74 }
75 WifiMode
76 TxModeTag::GetDataMode (void) const
77 {
78  return m_dataMode;
79 }
80 TypeId
81 TxModeTag::GetTypeId (void)
82 {
83  static TypeId tid = TypeId ("ns3::TxModeTag")
84  .SetParent<Tag> ()
85  .AddConstructor<TxModeTag> ()
86  .AddAttribute ("RtsTxMode",
87  "Tx mode of rts to use later",
88  EmptyAttributeValue (),
89  MakeWifiModeAccessor (&TxModeTag::GetRtsMode),
90  MakeWifiModeChecker ())
91  .AddAttribute ("DataTxMode",
92  "Tx mode of data to use later",
93  EmptyAttributeValue (),
94  MakeWifiModeAccessor (&TxModeTag::GetDataMode),
95  MakeWifiModeChecker ())
96  ;
97  return tid;
98 }
99 TypeId
101 {
102  return GetTypeId ();
103 }
104 uint32_t
106 {
107  return sizeof (WifiMode) * 2;
108 }
109 void
111 {
112  i.Write ((uint8_t *)&m_rtsMode, sizeof (WifiMode));
113  i.Write ((uint8_t *)&m_dataMode, sizeof (WifiMode));
114 }
115 void
117 {
118  i.Read ((uint8_t *)&m_rtsMode, sizeof (WifiMode));
119  i.Read ((uint8_t *)&m_dataMode, sizeof (WifiMode));
120 }
121 void
122 TxModeTag::Print (std::ostream &os) const
123 {
124  os << "Rts=" << m_rtsMode << ", Data=" << m_dataMode;
125 }
126 
127 } // namespace ns3
128 
129 
130 namespace ns3 {
131 
132 NS_OBJECT_ENSURE_REGISTERED (WifiRemoteStationManager);
133 
134 TypeId
135 WifiRemoteStationManager::GetTypeId (void)
136 {
137  static TypeId tid = TypeId ("ns3::WifiRemoteStationManager")
138  .SetParent<Object> ()
139  .AddAttribute ("IsLowLatency", "If true, we attempt to modelize a so-called low-latency device: a device"
140  " where decisions about tx parameters can be made on a per-packet basis and feedback about the"
141  " transmission of each packet is obtained before sending the next. Otherwise, we modelize a "
142  " high-latency device, that is a device where we cannot update our decision about tx parameters"
143  " after every packet transmission.",
144  BooleanValue (true), // this value is ignored because there is no setter
145  MakeBooleanAccessor (&WifiRemoteStationManager::IsLowLatency),
146  MakeBooleanChecker ())
147  .AddAttribute ("MaxSsrc", "The maximum number of retransmission attempts for an RTS. This value"
148  " will not have any effect on some rate control algorithms.",
149  UintegerValue (7),
150  MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSsrc),
151  MakeUintegerChecker<uint32_t> ())
152  .AddAttribute ("MaxSlrc", "The maximum number of retransmission attempts for a DATA packet. This value"
153  " will not have any effect on some rate control algorithms.",
154  UintegerValue (7),
155  MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSlrc),
156  MakeUintegerChecker<uint32_t> ())
157  .AddAttribute ("RtsCtsThreshold", "If the size of the data packet + LLC header + MAC header + FCS trailer is bigger than "
158  "this value, we use an RTS/CTS handshake before sending the data, as per IEEE Std. 802.11-2007, Section 9.2.6. "
159  "This value will not have any effect on some rate control algorithms.",
160  UintegerValue (2346),
161  MakeUintegerAccessor (&WifiRemoteStationManager::m_rtsCtsThreshold),
162  MakeUintegerChecker<uint32_t> ())
163  .AddAttribute ("FragmentationThreshold", "If the size of the data packet + LLC header + MAC header + FCS trailer is bigger"
164  "than this value, we fragment it such that the size of the fragments are equal or smaller "
165  "than this value, as per IEEE Std. 802.11-2007, Section 9.4. "
166  "This value will not have any effect on some rate control algorithms.",
167  UintegerValue (2346),
168  MakeUintegerAccessor (&WifiRemoteStationManager::DoSetFragmentationThreshold,
169  &WifiRemoteStationManager::DoGetFragmentationThreshold),
170  MakeUintegerChecker<uint32_t> ())
171  .AddAttribute ("NonUnicastMode", "Wifi mode used for non-unicast transmissions.",
172  WifiModeValue (),
173  MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
174  MakeWifiModeChecker ())
175  .AddTraceSource ("MacTxRtsFailed",
176  "The transmission of a RTS by the MAC layer has failed",
178  .AddTraceSource ("MacTxDataFailed",
179  "The transmission of a data packet by the MAC layer has failed",
181  .AddTraceSource ("MacTxFinalRtsFailed",
182  "The transmission of a RTS has exceeded the maximum number of attempts",
184  .AddTraceSource ("MacTxFinalDataFailed",
185  "The transmission of a data packet has exceeded the maximum number of attempts",
187  ;
188  return tid;
189 }
190 
191 WifiRemoteStationManager::WifiRemoteStationManager ()
192 {
193 }
194 
195 WifiRemoteStationManager::~WifiRemoteStationManager ()
196 {
197 }
198 void
200 {
201  for (StationStates::const_iterator i = m_states.begin (); i != m_states.end (); i++)
202  {
203  delete (*i);
204  }
205  m_states.clear ();
206  for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
207  {
208  delete (*i);
209  }
210  m_stations.clear ();
211 }
212 void
213 WifiRemoteStationManager::SetupPhy (Ptr<WifiPhy> phy)
214 {
215  // We need to track our PHY because it is the object that knows the
216  // full set of transmit rates that are supported. We need to know
217  // this in order to find the relevant mandatory rates when chosing a
218  // transmit rate for automatic control responses like
219  // acknowledgements.
220  m_wifiPhy = phy;
221  m_defaultTxMode = phy->GetMode (0);
222  Reset ();
223 }
224 
225 uint32_t
226 WifiRemoteStationManager::GetMaxSsrc (void) const
227 {
228  return m_maxSsrc;
229 }
230 uint32_t
231 WifiRemoteStationManager::GetMaxSlrc (void) const
232 {
233  return m_maxSlrc;
234 }
235 uint32_t
236 WifiRemoteStationManager::GetRtsCtsThreshold (void) const
237 {
238  return m_rtsCtsThreshold;
239 }
240 uint32_t
241 WifiRemoteStationManager::GetFragmentationThreshold (void) const
242 {
243  return DoGetFragmentationThreshold ();
244 }
245 void
246 WifiRemoteStationManager::SetMaxSsrc (uint32_t maxSsrc)
247 {
248  m_maxSsrc = maxSsrc;
249 }
250 void
251 WifiRemoteStationManager::SetMaxSlrc (uint32_t maxSlrc)
252 {
253  m_maxSlrc = maxSlrc;
254 }
255 void
256 WifiRemoteStationManager::SetRtsCtsThreshold (uint32_t threshold)
257 {
258  m_rtsCtsThreshold = threshold;
259 }
260 void
261 WifiRemoteStationManager::SetFragmentationThreshold (uint32_t threshold)
262 {
263  DoSetFragmentationThreshold (threshold);
264 }
265 
266 void
267 WifiRemoteStationManager::Reset (Mac48Address address)
268 {
269  NS_ASSERT (!address.IsGroup ());
270  WifiRemoteStationState *state = LookupState (address);
271  state->m_operationalRateSet.clear ();
272  AddSupportedMode (address, GetDefaultMode ());
273 }
274 void
276 {
277  NS_ASSERT (!address.IsGroup ());
278  WifiRemoteStationState *state = LookupState (address);
279  for (WifiModeListIterator i = state->m_operationalRateSet.begin (); i != state->m_operationalRateSet.end (); i++)
280  {
281  if ((*i) == mode)
282  {
283  // already in.
284  return;
285  }
286  }
287  state->m_operationalRateSet.push_back (mode);
288 }
289 bool
290 WifiRemoteStationManager::IsBrandNew (Mac48Address address) const
291 {
292  if (address.IsGroup ())
293  {
294  return false;
295  }
296  return LookupState (address)->m_state == WifiRemoteStationState::BRAND_NEW;
297 }
298 bool
299 WifiRemoteStationManager::IsAssociated (Mac48Address address) const
300 {
301  if (address.IsGroup ())
302  {
303  return true;
304  }
305  return LookupState (address)->m_state == WifiRemoteStationState::GOT_ASSOC_TX_OK;
306 }
307 bool
308 WifiRemoteStationManager::IsWaitAssocTxOk (Mac48Address address) const
309 {
310  if (address.IsGroup ())
311  {
312  return false;
313  }
314  return LookupState (address)->m_state == WifiRemoteStationState::WAIT_ASSOC_TX_OK;
315 }
316 void
317 WifiRemoteStationManager::RecordWaitAssocTxOk (Mac48Address address)
318 {
319  NS_ASSERT (!address.IsGroup ());
320  LookupState (address)->m_state = WifiRemoteStationState::WAIT_ASSOC_TX_OK;
321 }
322 void
323 WifiRemoteStationManager::RecordGotAssocTxOk (Mac48Address address)
324 {
325  NS_ASSERT (!address.IsGroup ());
326  LookupState (address)->m_state = WifiRemoteStationState::GOT_ASSOC_TX_OK;
327 }
328 void
329 WifiRemoteStationManager::RecordGotAssocTxFailed (Mac48Address address)
330 {
331  NS_ASSERT (!address.IsGroup ());
332  LookupState (address)->m_state = WifiRemoteStationState::DISASSOC;
333 }
334 void
335 WifiRemoteStationManager::RecordDisassociated (Mac48Address address)
336 {
337  NS_ASSERT (!address.IsGroup ());
338  LookupState (address)->m_state = WifiRemoteStationState::DISASSOC;
339 }
340 void
342  Ptr<const Packet> packet, uint32_t fullPacketSize)
343 {
344  if (IsLowLatency () || address.IsGroup ())
345  {
346  return;
347  }
348  WifiRemoteStation *station = Lookup (address, header);
349  WifiMode rts = DoGetRtsMode (station);
350  WifiMode data = DoGetDataMode (station, fullPacketSize);
351  TxModeTag tag;
352  // first, make sure that the tag is not here anymore.
353  ConstCast<Packet> (packet)->RemovePacketTag (tag);
354  tag = TxModeTag (rts, data);
355  // and then, add it back
356  packet->AddPacketTag (tag);
357 }
358 WifiMode
360  Ptr<const Packet> packet, uint32_t fullPacketSize)
361 {
362  if (address.IsGroup ())
363  {
364  return GetNonUnicastMode ();
365  }
366  if (!IsLowLatency ())
367  {
368  TxModeTag tag;
369  bool found;
370  found = ConstCast<Packet> (packet)->PeekPacketTag (tag);
371  NS_ASSERT (found);
372  return tag.GetDataMode ();
373  }
374  return DoGetDataMode (Lookup (address, header), fullPacketSize);
375 }
376 WifiMode
378  Ptr<const Packet> packet)
379 {
380  NS_ASSERT (!address.IsGroup ());
381  if (!IsLowLatency ())
382  {
383  TxModeTag tag;
384  bool found;
385  found = ConstCast<Packet> (packet)->PeekPacketTag (tag);
386  NS_ASSERT (found);
387  return tag.GetRtsMode ();
388  }
389  return DoGetRtsMode (Lookup (address, header));
390 }
391 void
393 {
394  NS_ASSERT (!address.IsGroup ());
395  WifiRemoteStation *station = Lookup (address, header);
396  station->m_ssrc++;
397  m_macTxRtsFailed (address);
398  DoReportRtsFailed (station);
399 }
400 void
402 {
403  NS_ASSERT (!address.IsGroup ());
404  WifiRemoteStation *station = Lookup (address, header);
405  station->m_slrc++;
406  m_macTxDataFailed (address);
407  DoReportDataFailed (station);
408 }
409 void
411  double ctsSnr, WifiMode ctsMode, double rtsSnr)
412 {
413  NS_ASSERT (!address.IsGroup ());
414  WifiRemoteStation *station = Lookup (address, header);
415  station->m_state->m_info.NotifyTxSuccess (station->m_ssrc);
416  station->m_ssrc = 0;
417  DoReportRtsOk (station, ctsSnr, ctsMode, rtsSnr);
418 }
419 void
421  double ackSnr, WifiMode ackMode, double dataSnr)
422 {
423  NS_ASSERT (!address.IsGroup ());
424  WifiRemoteStation *station = Lookup (address, header);
425  station->m_state->m_info.NotifyTxSuccess (station->m_slrc);
426  station->m_slrc = 0;
427  DoReportDataOk (station, ackSnr, ackMode, dataSnr);
428 }
429 void
431 {
432  NS_ASSERT (!address.IsGroup ());
433  WifiRemoteStation *station = Lookup (address, header);
434  station->m_state->m_info.NotifyTxFailed ();
435  station->m_ssrc = 0;
436  m_macTxFinalRtsFailed (address);
437  DoReportFinalRtsFailed (station);
438 }
439 void
441 {
442  NS_ASSERT (!address.IsGroup ());
443  WifiRemoteStation *station = Lookup (address, header);
444  station->m_state->m_info.NotifyTxFailed ();
445  station->m_slrc = 0;
446  m_macTxFinalDataFailed (address);
447  DoReportFinalDataFailed (station);
448 }
449 void
451  double rxSnr, WifiMode txMode)
452 {
453  if (address.IsGroup ())
454  {
455  return;
456  }
457  WifiRemoteStation *station = Lookup (address, header);
458  DoReportRxOk (station, rxSnr, txMode);
459 }
460 bool
462  Ptr<const Packet> packet)
463 {
464  if (address.IsGroup ())
465  {
466  return false;
467  }
468  bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetRtsCtsThreshold ();
469  return DoNeedRts (Lookup (address, header), packet, normally);
470 }
471 bool
473  Ptr<const Packet> packet)
474 {
475  NS_ASSERT (!address.IsGroup ());
476  WifiRemoteStation *station = Lookup (address, header);
477  bool normally = station->m_ssrc < GetMaxSsrc ();
478  return DoNeedRtsRetransmission (station, packet, normally);
479 }
480 bool
482  Ptr<const Packet> packet)
483 {
484  NS_ASSERT (!address.IsGroup ());
485  WifiRemoteStation *station = Lookup (address, header);
486  bool normally = station->m_slrc < GetMaxSlrc ();
487  return DoNeedDataRetransmission (station, packet, normally);
488 }
489 bool
491  Ptr<const Packet> packet)
492 {
493  if (address.IsGroup ())
494  {
495  return false;
496  }
497  WifiRemoteStation *station = Lookup (address, header);
498  bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetFragmentationThreshold ();
499  return DoNeedFragmentation (station, packet, normally);
500 }
501 
502 void
503 WifiRemoteStationManager::DoSetFragmentationThreshold (uint32_t threshold)
504 {
505  if (threshold < 256)
506  {
507  /*
508  * ASN.1 encoding of the MAC and PHY MIB (256 ... 8000)
509  */
510  NS_LOG_WARN ("Fragmentation threshold should be larger than 256. Setting to 256.");
511  m_fragmentationThreshold = 256;
512  }
513  else
514  {
515  /*
516  * The length of each fragment shall be an even number of octets, except for the last fragment if an MSDU or
517  * MMPDU, which may be either an even or an odd number of octets.
518  */
519  if (threshold % 2 != 0)
520  {
521  NS_LOG_WARN ("Fragmentation threshold should be an even number. Setting to " << threshold - 1);
522  m_fragmentationThreshold = threshold - 1;
523  }
524  else
525  {
526  m_fragmentationThreshold = threshold;
527  }
528  }
529 }
530 
531 uint32_t
532 WifiRemoteStationManager::DoGetFragmentationThreshold (void) const
533 {
534  return m_fragmentationThreshold;
535 }
536 
537 uint32_t
538 WifiRemoteStationManager::GetNFragments (const WifiMacHeader *header, Ptr<const Packet> packet)
539 {
540  //The number of bytes a fragment can support is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
541  uint32_t nFragments = (packet->GetSize () / (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH));
542 
543  //If the size of the last fragment is not 0.
544  if ((packet->GetSize () % (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH)) > 0)
545  {
546  nFragments++;
547  }
548  return nFragments;
549 }
550 
551 uint32_t
553  Ptr<const Packet> packet, uint32_t fragmentNumber)
554 {
555  NS_ASSERT (!address.IsGroup ());
556  uint32_t nFragment = GetNFragments (header, packet);
557  if (fragmentNumber >= nFragment)
558  {
559  return 0;
560  }
561  //Last fragment
562  if (fragmentNumber == nFragment - 1)
563  {
564  uint32_t lastFragmentSize = packet->GetSize () - (fragmentNumber * (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH));
565  return lastFragmentSize;
566  }
567  //All fragments but the last, the number of bytes is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
568  else
569  {
570  return GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH;
571  }
572 }
573 uint32_t
575  Ptr<const Packet> packet, uint32_t fragmentNumber)
576 {
577  NS_ASSERT (!address.IsGroup ());
578  NS_ASSERT (fragmentNumber < GetNFragments (header, packet));
579  uint32_t fragmentOffset = fragmentNumber * (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH);
580  return fragmentOffset;
581 }
582 bool
584  Ptr<const Packet> packet, uint32_t fragmentNumber)
585 {
586  NS_ASSERT (!address.IsGroup ());
587  bool isLast = fragmentNumber == (GetNFragments (header, packet) - 1);
588  return isLast;
589 }
590 WifiMode
592 {
607  WifiMode mode = GetDefaultMode ();
608  bool found = false;
609 
610  // First, search the BSS Basic Rate set
611  for (WifiModeListIterator i = m_bssBasicRateSet.begin ();
612  i != m_bssBasicRateSet.end (); i++)
613  {
614  if ((!found || i->GetPhyRate () > mode.GetPhyRate ())
615  && i->GetPhyRate () <= reqMode.GetPhyRate ()
616  && i->GetModulationClass () == reqMode.GetModulationClass ())
617  {
618  mode = *i;
619  // We've found a potentially-suitable transmit rate, but we
620  // need to continue and consider all the basic rates before
621  // we can be sure we've got the right one.
622  found = true;
623  }
624  }
625 
626  // If we found a suitable rate in the BSSBasicRateSet, then we are
627  // done and can return that mode.
628  if (found)
629  {
630  return mode;
631  }
632 
650  for (uint32_t idx = 0; idx < m_wifiPhy->GetNModes (); idx++)
651  {
652  WifiMode thismode = m_wifiPhy->GetMode (idx);
653 
654  /* If the rate:
655  *
656  * - is a mandatory rate for the PHY, and
657  * - is equal to or faster than our current best choice, and
658  * - is less than or equal to the rate of the received frame, and
659  * - is of the same modulation class as the received frame
660  *
661  * ...then it's our best choice so far.
662  */
663  if (thismode.IsMandatory ()
664  && (!found || thismode.GetPhyRate () > mode.GetPhyRate ())
665  && thismode.GetPhyRate () <= reqMode.GetPhyRate ()
666  && thismode.GetModulationClass () == reqMode.GetModulationClass ())
667  {
668  mode = thismode;
669  // As above; we've found a potentially-suitable transmit
670  // rate, but we need to continue and consider all the
671  // mandatory rates before we can be sure we've got the right
672  // one.
673  found = true;
674  }
675  }
676 
687  if (!found)
688  {
689  NS_FATAL_ERROR ("Can't find response rate for " << reqMode
690  << ". Check standard and selected rates match.");
691  }
692 
693  return mode;
694 }
695 
696 WifiMode
698 {
699  NS_ASSERT (!address.IsGroup ());
700  return GetControlAnswerMode (address, rtsMode);
701 }
702 WifiMode
704 {
705  NS_ASSERT (!address.IsGroup ());
706  return GetControlAnswerMode (address, dataMode);
707 }
708 
710 WifiRemoteStationManager::GetInfo (Mac48Address address)
711 {
712  WifiRemoteStationState *state = LookupState (address);
713  return state->m_info;
714 }
715 
716 WifiRemoteStationState *
717 WifiRemoteStationManager::LookupState (Mac48Address address) const
718 {
719  for (StationStates::const_iterator i = m_states.begin (); i != m_states.end (); i++)
720  {
721  if ((*i)->m_address == address)
722  {
723  return (*i);
724  }
725  }
726  WifiRemoteStationState *state = new WifiRemoteStationState ();
727  state->m_state = WifiRemoteStationState::BRAND_NEW;
728  state->m_address = address;
729  state->m_operationalRateSet.push_back (GetDefaultMode ());
730  const_cast<WifiRemoteStationManager *> (this)->m_states.push_back (state);
731  return state;
732 }
733 WifiRemoteStation *
734 WifiRemoteStationManager::Lookup (Mac48Address address, const WifiMacHeader *header) const
735 {
736  uint8_t tid;
737  if (header->IsQosData ())
738  {
739  tid = header->GetQosTid ();
740  }
741  else
742  {
743  tid = 0;
744  }
745  return Lookup (address, tid);
746 }
748 WifiRemoteStationManager::Lookup (Mac48Address address, uint8_t tid) const
749 {
750  for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
751  {
752  if ((*i)->m_tid == tid
753  && (*i)->m_state->m_address == address)
754  {
755  return (*i);
756  }
757  }
758  WifiRemoteStationState *state = LookupState (address);
759 
760  WifiRemoteStation *station = DoCreateStation ();
761  station->m_state = state;
762  station->m_tid = tid;
763  station->m_ssrc = 0;
764  station->m_slrc = 0;
765  // XXX
766  const_cast<WifiRemoteStationManager *> (this)->m_stations.push_back (station);
767  return station;
768 
769 }
770 
771 WifiMode
772 WifiRemoteStationManager::GetDefaultMode (void) const
773 {
774  return m_defaultTxMode;
775 }
776 void
777 WifiRemoteStationManager::Reset (void)
778 {
779  for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
780  {
781  delete (*i);
782  }
783  m_stations.clear ();
784  m_bssBasicRateSet.clear ();
785  m_bssBasicRateSet.push_back (m_defaultTxMode);
786  NS_ASSERT (m_defaultTxMode.IsMandatory ());
787 }
788 void
789 WifiRemoteStationManager::AddBasicMode (WifiMode mode)
790 {
791  for (uint32_t i = 0; i < GetNBasicModes (); i++)
792  {
793  if (GetBasicMode (i) == mode)
794  {
795  return;
796  }
797  }
798  m_bssBasicRateSet.push_back (mode);
799 }
800 uint32_t
801 WifiRemoteStationManager::GetNBasicModes (void) const
802 {
803  return m_bssBasicRateSet.size ();
804 }
805 WifiMode
806 WifiRemoteStationManager::GetBasicMode (uint32_t i) const
807 {
808  NS_ASSERT (i < m_bssBasicRateSet.size ());
809  return m_bssBasicRateSet[i];
810 }
811 WifiMode
812 WifiRemoteStationManager::GetNonUnicastMode (void) const
813 {
814  if (m_nonUnicastMode == WifiMode ())
815  {
816  return GetBasicMode (0);
817  }
818  else
819  {
820  return m_nonUnicastMode;
821  }
822 }
823 
824 bool
826  Ptr<const Packet> packet, bool normally)
827 {
828  return normally;
829 }
830 bool
832  Ptr<const Packet> packet, bool normally)
833 {
834  return normally;
835 }
836 bool
838  Ptr<const Packet> packet, bool normally)
839 {
840  return normally;
841 }
842 bool
844  Ptr<const Packet> packet, bool normally)
845 {
846  return normally;
847 }
848 
849 WifiMode
850 WifiRemoteStationManager::GetSupported (const WifiRemoteStation *station, uint32_t i) const
851 {
852  NS_ASSERT (i < GetNSupported (station));
853  return station->m_state->m_operationalRateSet[i];
854 }
855 uint32_t
856 WifiRemoteStationManager::GetNSupported (const WifiRemoteStation *station) const
857 {
858  return station->m_state->m_operationalRateSet.size ();
859 }
860 
861 //WifiRemoteStationInfo constructor
862 WifiRemoteStationInfo::WifiRemoteStationInfo ()
863  : m_memoryTime (Seconds (1.0)),
864  m_lastUpdate (Seconds (0.0)),
865  m_failAvg (0.0)
866 {
867 }
868 
869 double
871 {
872  double retval = std::exp ((double)(m_lastUpdate.GetMicroSeconds () - Simulator::Now ().GetMicroSeconds ())
873  / (double)m_memoryTime.GetMicroSeconds ());
875  return retval;
876 }
877 
878 void
880 {
881  double coefficient = CalculateAveragingCoefficient ();
882  m_failAvg = (double)retryCounter / (1 + (double) retryCounter) * (1.0 - coefficient) + coefficient * m_failAvg;
883 }
884 
885 void
887 {
888  double coefficient = CalculateAveragingCoefficient ();
889  m_failAvg = (1.0 - coefficient) + coefficient * m_failAvg;
890 }
891 
892 double
894 {
895  return m_failAvg;
896 }
897 } // namespace ns3
void Write(const uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:125
bool NeedDataRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
WifiMode GetCtsMode(Mac48Address address, WifiMode rtsMode)
void ReportDataFailed(Mac48Address address, const WifiMacHeader *header)
virtual uint32_t GetNModes(void) const =0
virtual void Print(std::ostream &os) const
virtual void Serialize(TagBuffer i) const
void AddPacketTag(const Tag &tag) const
Definition: packet.cc:868
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:93
#define NS_ASSERT(condition)
Definition: assert.h:64
static const uint16_t WIFI_MAC_FCS_LENGTH
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint32_t GetSize(void) const
Definition: packet.h:620
Time m_memoryTime
averaging coefficient depends on the memory time
bool IsLastFragment(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
TracedCallback< Mac48Address > m_macTxFinalRtsFailed
virtual TypeId GetInstanceTypeId(void) const
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
bool IsMandatory(void) const
Definition: wifi-mode.cc:82
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
Tid independent remote station statistics.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
double m_failAvg
moving percentage of failed frames
TracedCallback< Mac48Address > m_macTxFinalDataFailed
virtual bool DoNeedDataRetransmission(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
Time m_lastUpdate
when last update has occured
void ReportFinalDataFailed(Mac48Address address, const WifiMacHeader *header)
int64_t GetMicroSeconds(void) const
Definition: nstime.h:279
double CalculateAveragingCoefficient()
Calculate averaging coefficient for frame error rate. Depends on time of the last update...
void ReportRtsFailed(Mac48Address address, const WifiMacHeader *header)
virtual bool DoNeedRtsRetransmission(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
void NotifyTxSuccess(uint32_t retryCounter)
Updates average frame error rate when data or RTS was transmitted successfully.
WifiMode GetControlAnswerMode(Mac48Address address, WifiMode reqMode)
void ReportDataOk(Mac48Address address, const WifiMacHeader *header, double ackSnr, WifiMode ackMode, double dataSnr)
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)=0
tag a set of bytes in a packet
Definition: tag.h:36
uint32_t GetFragmentOffset(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
void PrepareForQueue(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fullPacketSize)
void AddSupportedMode(Mac48Address address, WifiMode mode)
bool IsGroup(void) const
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
uint64_t GetPhyRate(void) const
Definition: wifi-mode.cc:51
uint32_t GetFragmentSize(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fragmentNumber)
an EUI-48 address
Definition: mac48-address.h:41
TracedCallback< Mac48Address > m_macTxRtsFailed
virtual bool IsLowLatency(void) const =0
virtual WifiMode GetMode(uint32_t mode) const =0
static Time Now(void)
Definition: simulator.cc:179
void ReportRtsOk(Mac48Address address, const WifiMacHeader *header, double ctsSnr, WifiMode ctsMode, double rtsSnr)
WifiMode GetDataMode(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet, uint32_t fullPacketSize)
TracedCallback< Mac48Address > m_macTxDataFailed
double GetFrameErrorRate() const
Returns frame error rate (probability that frame is corrupted due to transmission error)...
virtual bool DoNeedFragmentation(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
void NotifyTxFailed()
Updates average frame error rate when final data or RTS has failed.
read and write tag data
Definition: tag-buffer.h:51
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
WifiMode GetRtsMode(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
virtual uint32_t GetSerializedSize(void) const
#define NS_LOG_WARN(msg)
Definition: log.h:246
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)=0
virtual void Deserialize(TagBuffer i)
WifiMode GetAckMode(Mac48Address address, WifiMode dataMode)
void ReportRxOk(Mac48Address address, const WifiMacHeader *header, double rxSnr, WifiMode txMode)
bool NeedFragmentation(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
void Read(uint8_t *buffer, uint32_t size)
Definition: tag-buffer.cc:176
bool NeedRtsRetransmission(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
bool NeedRts(Mac48Address address, const WifiMacHeader *header, Ptr< const Packet > packet)
a unique identifier for an interface.
Definition: type-id.h:44
void ReportFinalRtsFailed(Mac48Address address, const WifiMacHeader *header)
hold per-remote-station state.
virtual WifiRemoteStation * DoCreateStation(void) const =0