A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wifi-remote-station-manager.cc
Go to the documentation of this file.
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 
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 
44 {
45 public:
48  WifiTxVector GetDataTxVector (void) const;
49 
50  static TypeId GetTypeId (void);
51  virtual TypeId GetInstanceTypeId (void) const;
52  virtual uint32_t GetSerializedSize (void) const;
53  virtual void Serialize (TagBuffer i) const;
54  virtual void Deserialize (TagBuffer i);
55  virtual void Print (std::ostream &os) const;
56 private:
58 };
59 
61 {
62 }
64  : m_dataTxVector (dataTxVector)
65 {
66 }
67 
70 {
71  return m_dataTxVector;
72 }
73 TypeId
75 {
76  static TypeId tid = TypeId ("ns3::HighLatencyDataTxVectorTag")
77  .SetParent<Tag> ()
78  .AddConstructor<HighLatencyDataTxVectorTag> ()
79  ;
80  return tid;
81 }
82 TypeId
84 {
85  return GetTypeId ();
86 }
87 uint32_t
89 {
90  return sizeof (WifiTxVector);
91 }
92 void
94 {
95  i.Write ((uint8_t *)&m_dataTxVector, sizeof (WifiTxVector));
96 }
97 void
99 {
100  i.Read ((uint8_t *)&m_dataTxVector, sizeof (WifiTxVector));
101 }
102 void
103 HighLatencyDataTxVectorTag::Print (std::ostream &os) const
104 {
105  os << "Data=" << m_dataTxVector;
106 }
107 
109 {
110 public:
113  WifiTxVector GetRtsTxVector (void) const;
114 
115  static TypeId GetTypeId (void);
116  virtual TypeId GetInstanceTypeId (void) const;
117  virtual uint32_t GetSerializedSize (void) const;
118  virtual void Serialize (TagBuffer i) const;
119  virtual void Deserialize (TagBuffer i);
120  virtual void Print (std::ostream &os) const;
121 private:
123 };
124 
126 {
127 }
129  : m_rtsTxVector (rtsTxVector)
130 {
131 }
132 
135 {
136  return m_rtsTxVector;
137 }
138 TypeId
140 {
141  static TypeId tid = TypeId ("ns3::HighLatencyRtsTxVectorTag")
142  .SetParent<Tag> ()
143  .AddConstructor<HighLatencyRtsTxVectorTag> ()
144  ;
145  return tid;
146 }
147 TypeId
149 {
150  return GetTypeId ();
151 }
152 uint32_t
154 {
155  return sizeof (WifiTxVector);
156 }
157 void
159 {
160  i.Write ((uint8_t *)&m_rtsTxVector, sizeof (WifiTxVector));
161 }
162 void
164 {
165  i.Read ((uint8_t *)&m_rtsTxVector, sizeof (WifiTxVector));
166 }
167 void
168 HighLatencyRtsTxVectorTag::Print (std::ostream &os) const
169 {
170  os << "Rts=" << m_rtsTxVector;
171 }
172 
174 {
175 public:
177  HighLatencyCtsToSelfTxVectorTag (WifiTxVector ctsToSelfTxVector);
178  WifiTxVector GetCtsToSelfTxVector (void) const;
179 
180  static TypeId GetTypeId (void);
181  virtual TypeId GetInstanceTypeId (void) const;
182  virtual uint32_t GetSerializedSize (void) const;
183  virtual void Serialize (TagBuffer i) const;
184  virtual void Deserialize (TagBuffer i);
185  virtual void Print (std::ostream &os) const;
186 private:
188 };
189 
191 {
192 }
194  : m_ctsToSelfTxVector (ctsToSelfTxVector)
195 {
196 }
197 
200 {
201  return m_ctsToSelfTxVector;
202 }
203 TypeId
205 {
206  static TypeId tid = TypeId ("ns3::HighLatencyCtsToSelfTxVectorTag")
207  .SetParent<Tag> ()
208  .AddConstructor<HighLatencyCtsToSelfTxVectorTag> ()
209  ;
210  return tid;
211 }
212 TypeId
214 {
215  return GetTypeId ();
216 }
217 uint32_t
219 {
220  return sizeof (WifiTxVector);
221 }
222 void
224 {
225  i.Write ((uint8_t *)&m_ctsToSelfTxVector, sizeof (WifiTxVector));
226 }
227 void
229 {
230  i.Read ((uint8_t *)&m_ctsToSelfTxVector, sizeof (WifiTxVector));
231 }
232 void
234 {
235  os << "Cts To Self=" << m_ctsToSelfTxVector;
236 }
237 
238 } // namespace ns3
239 
240 namespace ns3 {
241 
242 NS_OBJECT_ENSURE_REGISTERED (WifiRemoteStationManager);
243 
244 TypeId
246 {
247  static TypeId tid = TypeId ("ns3::WifiRemoteStationManager")
248  .SetParent<Object> ()
249  .AddAttribute ("IsLowLatency", "If true, we attempt to modelize a so-called low-latency device: a device"
250  " where decisions about tx parameters can be made on a per-packet basis and feedback about the"
251  " transmission of each packet is obtained before sending the next. Otherwise, we modelize a "
252  " high-latency device, that is a device where we cannot update our decision about tx parameters"
253  " after every packet transmission.",
254  BooleanValue (true), // this value is ignored because there is no setter
255  MakeBooleanAccessor (&WifiRemoteStationManager::IsLowLatency),
256  MakeBooleanChecker ())
257  .AddAttribute ("MaxSsrc", "The maximum number of retransmission attempts for an RTS. This value"
258  " will not have any effect on some rate control algorithms.",
259  UintegerValue (7),
260  MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSsrc),
261  MakeUintegerChecker<uint32_t> ())
262  .AddAttribute ("MaxSlrc", "The maximum number of retransmission attempts for a DATA packet. This value"
263  " will not have any effect on some rate control algorithms.",
264  UintegerValue (7),
265  MakeUintegerAccessor (&WifiRemoteStationManager::m_maxSlrc),
266  MakeUintegerChecker<uint32_t> ())
267  .AddAttribute ("RtsCtsThreshold", "If the size of the data packet + LLC header + MAC header + FCS trailer is bigger than "
268  "this value, we use an RTS/CTS handshake before sending the data, as per IEEE Std. 802.11-2007, Section 9.2.6. "
269  "This value will not have any effect on some rate control algorithms.",
270  UintegerValue (2346),
271  MakeUintegerAccessor (&WifiRemoteStationManager::m_rtsCtsThreshold),
272  MakeUintegerChecker<uint32_t> ())
273  .AddAttribute ("FragmentationThreshold", "If the size of the data packet + LLC header + MAC header + FCS trailer is bigger"
274  "than this value, we fragment it such that the size of the fragments are equal or smaller "
275  "than this value, as per IEEE Std. 802.11-2007, Section 9.4. "
276  "This value will not have any effect on some rate control algorithms.",
277  UintegerValue (2346),
280  MakeUintegerChecker<uint32_t> ())
281  .AddAttribute ("NonUnicastMode", "Wifi mode used for non-unicast transmissions.",
282  WifiModeValue (),
283  MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
284  MakeWifiModeChecker ())
285  .AddAttribute ("DefaultTxPowerLevel", "Default power level to be used for transmissions. "
286  "This is the power level that is used by all those WifiManagers that do not"
287  "implement TX power control.",
288  UintegerValue (0),
289  MakeUintegerAccessor (&WifiRemoteStationManager::m_defaultTxPowerLevel),
290  MakeUintegerChecker<uint8_t> ())
291  .AddTraceSource ("MacTxRtsFailed",
292  "The transmission of a RTS by the MAC layer has failed",
294  .AddTraceSource ("MacTxDataFailed",
295  "The transmission of a data packet by the MAC layer has failed",
297  .AddTraceSource ("MacTxFinalRtsFailed",
298  "The transmission of a RTS has exceeded the maximum number of attempts",
300  .AddTraceSource ("MacTxFinalDataFailed",
301  "The transmission of a data packet has exceeded the maximum number of attempts",
303  ;
304  return tid;
305 }
306 
308 {
309 }
310 
312 {
313 }
314 void
316 {
317  for (StationStates::const_iterator i = m_states.begin (); i != m_states.end (); i++)
318  {
319  delete (*i);
320  }
321  m_states.clear ();
322  for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
323  {
324  delete (*i);
325  }
326  m_stations.clear ();
327 }
328 void
330 {
331  // We need to track our PHY because it is the object that knows the
332  // full set of transmit rates that are supported. We need to know
333  // this in order to find the relevant mandatory rates when chosing a
334  // transmit rate for automatic control responses like
335  // acknowledgements.
336  m_wifiPhy = phy;
337  m_defaultTxMode = phy->GetMode (0);
338  if(HasHtSupported())
339  {
340  m_defaultTxMcs = phy->GetMcs (0);
341  }
342  else
343  {
344  m_defaultTxMcs = 0;
345  }
346  Reset ();
347 }
348 void
350 {
351  m_htSupported=enable;
352 }
353 
354 bool
356 {
357  return m_htSupported;
358 }
359 uint32_t
361 {
362  return m_maxSsrc;
363 }
364 uint32_t
366 {
367  return m_maxSlrc;
368 }
369 uint32_t
371 {
372  return m_rtsCtsThreshold;
373 }
374 uint32_t
376 {
377  return DoGetFragmentationThreshold ();
378 }
379 void
381 {
382  m_maxSsrc = maxSsrc;
383 }
384 void
386 {
387  m_maxSlrc = maxSlrc;
388 }
389 void
391 {
392  m_rtsCtsThreshold = threshold;
393 }
394 void
396 {
397  DoSetFragmentationThreshold (threshold);
398 }
399 
400 void
402 {
403  NS_ASSERT (!address.IsGroup ());
404  WifiRemoteStationState *state = LookupState (address);
405  state->m_operationalRateSet.clear ();
406  state->m_operationalMcsSet.clear ();
407  AddSupportedMode (address, GetDefaultMode ());
408  AddSupportedMcs(address,GetDefaultMcs());
409 }
410 void
412 {
413  NS_ASSERT (!address.IsGroup ());
414  WifiRemoteStationState *state = LookupState (address);
415  for (WifiModeListIterator i = state->m_operationalRateSet.begin (); i != state->m_operationalRateSet.end (); i++)
416  {
417  if ((*i) == mode)
418  {
419  // already in.
420  return;
421  }
422  }
423  state->m_operationalRateSet.push_back (mode);
424 }
425 /*void
426 WifiRemoteStationManager::AddBssMembershipParameters(Mac48Address address, uint32_t selector)
427 {
428  NS_ASSERT (!address.IsGroup ());
429  WifiRemoteStationState *state = LookupState (address);
430  WifiMode mode;
431  WifiModeList membershipselectormodes = m_wifiPhy->GetMembershipSelectorModes(selector);
432  for (WifiModeListIterator j = membershipselectormodes.begin (); j != membershipselectormodes.end (); j++)
433  {
434  mode=(*j);
435  for (WifiModeListIterator i = state->m_operationalRateSet.begin (); i != state->m_operationalRateSet.end (); i++)
436  {
437  if ((*i) == mode)
438  {
439  // already in.
440  break;
441  }
442  }
443  state->m_operationalRateSet.push_back (mode);
444  }
445 }*/
446 void
448 {
449  NS_ASSERT (!address.IsGroup ());
450  WifiRemoteStationState *state = LookupState (address);
451  for (WifiMcsListIterator i = state->m_operationalMcsSet.begin (); i != state->m_operationalMcsSet.end (); i++)
452  {
453  if ((*i) == mcs)
454  {
455  // already in.
456  return;
457  }
458  }
459  state->m_operationalMcsSet.push_back (mcs);
460 }
461 bool
463 {
464  if (address.IsGroup ())
465  {
466  return false;
467  }
469 }
470 bool
472 {
473  if (address.IsGroup ())
474  {
475  return true;
476  }
478 }
479 bool
481 {
482  if (address.IsGroup ())
483  {
484  return false;
485  }
487 }
488 void
490 {
491  NS_ASSERT (!address.IsGroup ());
493 }
494 void
496 {
497  NS_ASSERT (!address.IsGroup ());
499 }
500 void
502 {
503  NS_ASSERT (!address.IsGroup ());
505 }
506 void
508 {
509  NS_ASSERT (!address.IsGroup ());
511 }
512 void
514  Ptr<const Packet> packet, uint32_t fullPacketSize)
515 {
516  if (IsLowLatency () || address.IsGroup ())
517  {
518  return;
519  }
520  WifiRemoteStation *station = Lookup (address, header);
521  WifiTxVector rts = DoGetRtsTxVector (station);
522  WifiTxVector data = DoGetDataTxVector (station, fullPacketSize);
523  WifiTxVector ctstoself = DoGetCtsToSelfTxVector ();
526  HighLatencyCtsToSelfTxVectorTag ctstoselftag;
527  // first, make sure that the tag is not here anymore.
528  ConstCast<Packet> (packet)->RemovePacketTag (datatag);
529  ConstCast<Packet> (packet)->RemovePacketTag (rtstag);
530  ConstCast<Packet> (packet)->RemovePacketTag (ctstoselftag);
531  datatag = HighLatencyDataTxVectorTag (data);
532  rtstag = HighLatencyRtsTxVectorTag (rts);
533  ctstoselftag = HighLatencyCtsToSelfTxVectorTag (ctstoself);
534  // and then, add it back
535  packet->AddPacketTag (datatag);
536  packet->AddPacketTag (rtstag);
537  packet->AddPacketTag (ctstoselftag);
538 }
541  Ptr<const Packet> packet, uint32_t fullPacketSize)
542 {
543  if (address.IsGroup ())
544  {
545  WifiTxVector v;
546  v.SetMode (GetNonUnicastMode ());
548  v.SetShortGuardInterval (false);
549  v.SetNss (1);
550  v.SetNess (0);
551  v.SetStbc (false);
552  return v;
553  }
554  if (!IsLowLatency ())
555  {
557  bool found;
558  found = ConstCast<Packet> (packet)->PeekPacketTag (datatag);
559  NS_ASSERT (found);
560  // cast found to void, to suppress 'found' set but not used
561  // compiler warning
562  (void) found;
563  return datatag.GetDataTxVector ();
564  }
565  return DoGetDataTxVector (Lookup (address, header), fullPacketSize);
566 }
569  Ptr<const Packet> packet)
570 {
571 
572  if (!IsLowLatency ())
573  {
574  HighLatencyCtsToSelfTxVectorTag ctstoselftag;
575  bool found;
576  found = ConstCast<Packet> (packet)->PeekPacketTag (ctstoselftag);
577  NS_ASSERT (found);
578  // cast found to void, to suppress 'found' set but not used
579  // compiler warning
580  (void) found;
581  return ctstoselftag.GetCtsToSelfTxVector ();
582  }
583  return DoGetCtsToSelfTxVector ();
584 }
585 
588 {
590 }
591 
594  Ptr<const Packet> packet)
595 {
596  NS_ASSERT (!address.IsGroup ());
597  if (!IsLowLatency ())
598  {
600  bool found;
601  found = ConstCast<Packet> (packet)->PeekPacketTag (rtstag);
602  NS_ASSERT (found);
603  // cast found to void, to suppress 'found' set but not used
604  // compiler warning
605  (void) found;
606  return rtstag.GetRtsTxVector ();
607  }
608  return DoGetRtsTxVector (Lookup (address, header));
609 }
610 void
612 {
613  NS_ASSERT (!address.IsGroup ());
614  WifiRemoteStation *station = Lookup (address, header);
615  station->m_ssrc++;
616  m_macTxRtsFailed (address);
617  DoReportRtsFailed (station);
618 }
619 void
621 {
622  NS_ASSERT (!address.IsGroup ());
623  WifiRemoteStation *station = Lookup (address, header);
624  station->m_slrc++;
625  m_macTxDataFailed (address);
626  DoReportDataFailed (station);
627 }
628 void
630  double ctsSnr, WifiMode ctsMode, double rtsSnr)
631 {
632  NS_ASSERT (!address.IsGroup ());
633  WifiRemoteStation *station = Lookup (address, header);
634  station->m_state->m_info.NotifyTxSuccess (station->m_ssrc);
635  station->m_ssrc = 0;
636  DoReportRtsOk (station, ctsSnr, ctsMode, rtsSnr);
637 }
638 void
640  double ackSnr, WifiMode ackMode, double dataSnr)
641 {
642  NS_ASSERT (!address.IsGroup ());
643  WifiRemoteStation *station = Lookup (address, header);
644  station->m_state->m_info.NotifyTxSuccess (station->m_slrc);
645  station->m_slrc = 0;
646  DoReportDataOk (station, ackSnr, ackMode, dataSnr);
647 }
648 void
650 {
651  NS_ASSERT (!address.IsGroup ());
652  WifiRemoteStation *station = Lookup (address, header);
653  station->m_state->m_info.NotifyTxFailed ();
654  station->m_ssrc = 0;
655  m_macTxFinalRtsFailed (address);
656  DoReportFinalRtsFailed (station);
657 }
658 void
660 {
661  NS_ASSERT (!address.IsGroup ());
662  WifiRemoteStation *station = Lookup (address, header);
663  station->m_state->m_info.NotifyTxFailed ();
664  station->m_slrc = 0;
665  m_macTxFinalDataFailed (address);
666  DoReportFinalDataFailed (station);
667 }
668 void
670  double rxSnr, WifiMode txMode)
671 {
672  if (address.IsGroup ())
673  {
674  return;
675  }
676  WifiRemoteStation *station = Lookup (address, header);
677  DoReportRxOk (station, rxSnr, txMode);
678 }
679 bool
681  Ptr<const Packet> packet)
682 {
683  if (address.IsGroup ())
684  {
685  return false;
686  }
687  bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetRtsCtsThreshold ();
688  return DoNeedRts (Lookup (address, header), packet, normally);
689 }
690 bool
692 {
693  WifiMode mode = txVector.GetMode();
694 
695  // search the BSS Basic Rate set if the used mode in the basic set then no need for Cts to self
696  for (WifiModeListIterator i = m_bssBasicRateSet.begin ();
697  i != m_bssBasicRateSet.end (); i++)
698  {
699  if (mode == *i)
700  {
701  return false;
702  }
703  }
704  if (HasHtSupported())
705  {
706  uint8_t mcs = m_wifiPhy->WifiModeToMcs (mode);
707  for (WifiMcsListIterator i = m_bssBasicMcsSet.begin ();
708  i != m_bssBasicMcsSet.end (); i++)
709  {
710  if (mcs == *i)
711  {
712  return false;
713  }
714  }
715  }
716  return true;
717 }
718 bool
720  Ptr<const Packet> packet)
721 {
722  NS_ASSERT (!address.IsGroup ());
723  WifiRemoteStation *station = Lookup (address, header);
724  bool normally = station->m_ssrc < GetMaxSsrc ();
725  return DoNeedRtsRetransmission (station, packet, normally);
726 }
727 bool
729  Ptr<const Packet> packet)
730 {
731  NS_ASSERT (!address.IsGroup ());
732  WifiRemoteStation *station = Lookup (address, header);
733  bool normally = station->m_slrc < GetMaxSlrc ();
734  return DoNeedDataRetransmission (station, packet, normally);
735 }
736 bool
738  Ptr<const Packet> packet)
739 {
740  if (address.IsGroup ())
741  {
742  return false;
743  }
744  WifiRemoteStation *station = Lookup (address, header);
745  bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetFragmentationThreshold ();
746  return DoNeedFragmentation (station, packet, normally);
747 }
748 
749 void
751 {
752  if (threshold < 256)
753  {
754  /*
755  * ASN.1 encoding of the MAC and PHY MIB (256 ... 8000)
756  */
757  NS_LOG_WARN ("Fragmentation threshold should be larger than 256. Setting to 256.");
759  }
760  else
761  {
762  /*
763  * The length of each fragment shall be an even number of octets, except for the last fragment if an MSDU or
764  * MMPDU, which may be either an even or an odd number of octets.
765  */
766  if (threshold % 2 != 0)
767  {
768  NS_LOG_WARN ("Fragmentation threshold should be an even number. Setting to " << threshold - 1);
769  m_fragmentationThreshold = threshold - 1;
770  }
771  else
772  {
773  m_fragmentationThreshold = threshold;
774  }
775  }
776 }
777 
778 uint32_t
780 {
782 }
783 
784 uint32_t
786 {
787  //The number of bytes a fragment can support is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
788  uint32_t nFragments = (packet->GetSize () / (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH));
789 
790  //If the size of the last fragment is not 0.
791  if ((packet->GetSize () % (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH)) > 0)
792  {
793  nFragments++;
794  }
795  return nFragments;
796 }
797 
798 uint32_t
800  Ptr<const Packet> packet, uint32_t fragmentNumber)
801 {
802  NS_ASSERT (!address.IsGroup ());
803  uint32_t nFragment = GetNFragments (header, packet);
804  if (fragmentNumber >= nFragment)
805  {
806  return 0;
807  }
808  //Last fragment
809  if (fragmentNumber == nFragment - 1)
810  {
811  uint32_t lastFragmentSize = packet->GetSize () - (fragmentNumber * (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH));
812  return lastFragmentSize;
813  }
814  //All fragments but the last, the number of bytes is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
815  else
816  {
817  return GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH;
818  }
819 }
820 uint32_t
822  Ptr<const Packet> packet, uint32_t fragmentNumber)
823 {
824  NS_ASSERT (!address.IsGroup ());
825  NS_ASSERT (fragmentNumber < GetNFragments (header, packet));
826  uint32_t fragmentOffset = fragmentNumber * (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH);
827  return fragmentOffset;
828 }
829 bool
831  Ptr<const Packet> packet, uint32_t fragmentNumber)
832 {
833  NS_ASSERT (!address.IsGroup ());
834  bool isLast = fragmentNumber == (GetNFragments (header, packet) - 1);
835  return isLast;
836 }
837 WifiMode
839 {
854  WifiMode mode = GetDefaultMode ();
855  bool found = false;
856 
857  // First, search the BSS Basic Rate set
858  for (WifiModeListIterator i = m_bssBasicRateSet.begin ();
859  i != m_bssBasicRateSet.end (); i++)
860  {
861  if ((!found || i->GetPhyRate () > mode.GetPhyRate ())
862  && i->GetPhyRate () <= reqMode.GetPhyRate ()
863  && i->GetModulationClass () == reqMode.GetModulationClass ())
864  {
865  mode = *i;
866  // We've found a potentially-suitable transmit rate, but we
867  // need to continue and consider all the basic rates before
868  // we can be sure we've got the right one.
869  found = true;
870  }
871  }
872  if(HasHtSupported())
873  {
874  if (!found)
875  {
876  uint8_t mcs = GetDefaultMcs ();
877  mode= m_wifiPhy->McsToWifiMode (mcs);
878  }
879  for (WifiMcsListIterator i = m_bssBasicMcsSet.begin ();
880  i != m_bssBasicMcsSet.end (); i++)
881  {
882  WifiMode thismode= m_wifiPhy->McsToWifiMode (*i);
883  if ((!found || thismode.GetPhyRate () > mode.GetPhyRate ())
884  && thismode.GetPhyRate () <= reqMode.GetPhyRate ()
885  && thismode.GetModulationClass () == reqMode.GetModulationClass ())
886  {
887  mode = thismode;
888  // We've found a potentially-suitable transmit rate, but we
889  // need to continue and consider all the basic rates before
890  // we can be sure we've got the right one.
891  found = true;
892  }
893  }
894 }
895  // If we found a suitable rate in the BSSBasicRateSet, then we are
896  // done and can return that mode.
897  if (found)
898  {
899  return mode;
900  }
901 
919  for (uint32_t idx = 0; idx < m_wifiPhy->GetNModes (); idx++)
920  {
921  WifiMode thismode = m_wifiPhy->GetMode (idx);
922 
923  /* If the rate:
924  *
925  * - is a mandatory rate for the PHY, and
926  * - is equal to or faster than our current best choice, and
927  * - is less than or equal to the rate of the received frame, and
928  * - is of the same modulation class as the received frame
929  *
930  * ...then it's our best choice so far.
931  */
932  if (thismode.IsMandatory ()
933  && (!found || thismode.GetPhyRate () > mode.GetPhyRate ())
934  && thismode.GetPhyRate () <= reqMode.GetPhyRate ()
935  && thismode.GetModulationClass () == reqMode.GetModulationClass ())
936  {
937  mode = thismode;
938  // As above; we've found a potentially-suitable transmit
939  // rate, but we need to continue and consider all the
940  // mandatory rates before we can be sure we've got the right
941  // one.
942  found = true;
943  }
944  }
945  if(HasHtSupported())
946  {
947  for (uint32_t idx = 0; idx < m_wifiPhy->GetNMcs (); idx++)
948  {
949  uint8_t thismcs = m_wifiPhy->GetMcs (idx);
950  WifiMode thismode= m_wifiPhy->McsToWifiMode (thismcs);
951  if (thismode.IsMandatory ()
952  && (!found || thismode.GetPhyRate () > mode.GetPhyRate ())
953  && thismode.GetPhyRate () <= reqMode.GetPhyRate ()
954  && thismode.GetModulationClass () == reqMode.GetModulationClass ())
955  {
956  mode = thismode;
957  // As above; we've found a potentially-suitable transmit
958  // rate, but we need to continue and consider all the
959  // mandatory rates before we can be sure we've got the right
960  // one.
961  found = true;
962  }
963 
964  }
965  }
966 
977  if (!found)
978  {
979  NS_FATAL_ERROR ("Can't find response rate for " << reqMode
980  << ". Check standard and selected rates match.");
981  }
982 
983  return mode;
984 }
985 
988 {
989  NS_ASSERT (!address.IsGroup ());
990  WifiTxVector v;
991  v.SetMode (GetControlAnswerMode (address, rtsMode));
992  v.SetTxPowerLevel (DoGetCtsTxPowerLevel (address, v.GetMode()));
993  v.SetShortGuardInterval (DoGetCtsTxGuardInterval(address, v.GetMode()));
994  v.SetNss (DoGetCtsTxNss(address, v.GetMode()));
995  v.SetNess (DoGetCtsTxNess(address, v.GetMode()));
996  v.SetStbc (DoGetCtsTxStbc(address, v.GetMode()));
997  return v;
998 }
1001 {
1002  NS_ASSERT (!address.IsGroup ());
1003  WifiTxVector v;
1004  v.SetMode (GetControlAnswerMode (address, dataMode));
1005  v.SetTxPowerLevel (DoGetAckTxPowerLevel (address, v.GetMode()));
1006  v.SetShortGuardInterval(DoGetAckTxGuardInterval(address, v.GetMode()));
1007  v.SetNss(DoGetAckTxNss(address, v.GetMode()));
1008  v.SetNess(DoGetAckTxNess(address, v.GetMode()));
1009  v.SetStbc(DoGetAckTxStbc(address, v.GetMode()));
1010  return v;
1011 }
1014 {
1015  NS_ASSERT (!address.IsGroup ());
1016  WifiTxVector v;
1017  v.SetMode (GetControlAnswerMode (address, blockAckReqMode));
1018  v.SetTxPowerLevel (DoGetBlockAckTxPowerLevel (address, v.GetMode()));
1019  v.SetShortGuardInterval (DoGetBlockAckTxGuardInterval(address, v.GetMode()));
1020  v.SetNss (DoGetBlockAckTxNss(address, v.GetMode()));
1021  v.SetNess (DoGetBlockAckTxNess(address, v.GetMode()));
1022  v.SetStbc (DoGetBlockAckTxStbc(address, v.GetMode()));
1023  return v;
1024 }
1025 
1026 uint8_t
1028 {
1029  return m_defaultTxPowerLevel;
1030 }
1031 
1032 bool
1034 {
1035  return m_wifiPhy->GetGuardInterval();
1036 }
1037 
1038 uint8_t
1040 {
1041  return 1;
1042 }
1043 uint8_t
1045 {
1046  return 0;
1047 }
1048 bool
1050 {
1051  return m_wifiPhy->GetStbc();
1052 }
1053 
1054 uint8_t
1056 {
1057  return m_defaultTxPowerLevel;
1058 }
1059 
1060 bool
1062 {
1063  return m_wifiPhy->GetGuardInterval();
1064 }
1065 
1066 uint8_t
1068 {
1069  return 1;
1070 }
1071 uint8_t
1073 {
1074  return 0;
1075 }
1076 bool
1078 {
1079  return m_wifiPhy->GetStbc();
1080 }
1081 
1082 uint8_t
1084 {
1085  return m_defaultTxPowerLevel;
1086 }
1087 
1088 bool
1090 {
1091  return m_wifiPhy->GetGuardInterval();
1092 }
1093 
1094 uint8_t
1096 {
1097  return 1;
1098 }
1099 uint8_t
1101 {
1102  return 0;
1103 }
1104 bool
1106 {
1107  return m_wifiPhy->GetStbc();
1108 }
1109 
1110 
1111 uint8_t
1113 {
1114  return m_defaultTxPowerLevel;
1115 }
1116 
1117 
1120 {
1121  WifiRemoteStationState *state = LookupState (address);
1122  return state->m_info;
1123 }
1124 
1127 {
1128  for (StationStates::const_iterator i = m_states.begin (); i != m_states.end (); i++)
1129  {
1130  if ((*i)->m_address == address)
1131  {
1132  return (*i);
1133  }
1134  }
1137  state->m_address = address;
1138  state->m_operationalRateSet.push_back (GetDefaultMode ());
1139  state->m_operationalMcsSet.push_back(GetDefaultMcs());
1142  state->m_rx=1;
1143  state->m_tx=1;
1144  state->m_stbc=false;
1145  const_cast<WifiRemoteStationManager *> (this)->m_states.push_back (state);
1146  return state;
1147 }
1150 {
1151  uint8_t tid;
1152  if (header->IsQosData ())
1153  {
1154  tid = header->GetQosTid ();
1155  }
1156  else
1157  {
1158  tid = 0;
1159  }
1160  return Lookup (address, tid);
1161 }
1164 {
1165  for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
1166  {
1167  if ((*i)->m_tid == tid
1168  && (*i)->m_state->m_address == address)
1169  {
1170  return (*i);
1171  }
1172  }
1173  WifiRemoteStationState *state = LookupState (address);
1174 
1175  WifiRemoteStation *station = DoCreateStation ();
1176  station->m_state = state;
1177  station->m_tid = tid;
1178  station->m_ssrc = 0;
1179  station->m_slrc = 0;
1180  // XXX
1181  const_cast<WifiRemoteStationManager *> (this)->m_stations.push_back (station);
1182  return station;
1183 
1184 }
1185 //Used by all stations to record HT capabilities of remote stations
1186 void
1188 {
1189  WifiRemoteStationState *state;
1190  state=LookupState (from);
1191  state->m_shortGuardInterval=htcapabilities.GetShortGuardInterval20();
1192  state->m_greenfield=htcapabilities.GetGreenfield();
1193 
1194 }
1195 //Used by mac low to choose format used GF, MF or Non HT
1196 bool
1198 {
1199  return LookupState(address)->m_greenfield;
1200 }
1201 WifiMode
1203 {
1204  return m_defaultTxMode;
1205 }
1206 uint8_t
1208 {
1209  return m_defaultTxMcs;
1210 }
1211 void
1213 {
1214  for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
1215  {
1216  delete (*i);
1217  }
1218  m_stations.clear ();
1219  m_bssBasicRateSet.clear ();
1220  m_bssBasicRateSet.push_back (m_defaultTxMode);
1221  m_bssBasicMcsSet.clear();
1222  m_bssBasicMcsSet.push_back (m_defaultTxMcs);
1224 }
1225 void
1227 {
1228  for (uint32_t i = 0; i < GetNBasicModes (); i++)
1229  {
1230  if (GetBasicMode (i) == mode)
1231  {
1232  return;
1233  }
1234  }
1235  m_bssBasicRateSet.push_back (mode);
1236 }
1237 uint32_t
1239 {
1240  return m_bssBasicRateSet.size ();
1241 }
1242 WifiMode
1244 {
1245  NS_ASSERT (i < m_bssBasicRateSet.size ());
1246  return m_bssBasicRateSet[i];
1247 }
1248 
1249 void
1251 {
1252  for (uint32_t i = 0; i < GetNBasicMcs (); i++)
1253  {
1254  if (GetBasicMcs (i) == mcs)
1255  {
1256  return;
1257  }
1258  }
1259  m_bssBasicMcsSet.push_back (mcs);
1260 }
1261 
1262 uint32_t
1264 {
1265  return m_bssBasicMcsSet.size ();
1266 }
1267 uint8_t
1269 {
1270  NS_ASSERT (i < m_bssBasicMcsSet.size ());
1271  return m_bssBasicMcsSet[i];
1272 }
1273 
1274 WifiMode
1276 {
1277  if (m_nonUnicastMode == WifiMode ())
1278  {
1279  return GetBasicMode (0);
1280  }
1281  else
1282  {
1283  return m_nonUnicastMode;
1284  }
1285 }
1286 
1287 bool
1289  Ptr<const Packet> packet, bool normally)
1290 {
1291  return normally;
1292 }
1293 bool
1295  Ptr<const Packet> packet, bool normally)
1296 {
1297  return normally;
1298 }
1299 bool
1301  Ptr<const Packet> packet, bool normally)
1302 {
1303  return normally;
1304 }
1305 bool
1307  Ptr<const Packet> packet, bool normally)
1308 {
1309  return normally;
1310 }
1311 
1312 WifiMode
1314 {
1315  NS_ASSERT (i < GetNSupported (station));
1316  return station->m_state->m_operationalRateSet[i];
1317 }
1318 uint8_t
1320 {
1321  NS_ASSERT (i < GetNMcsSupported (station));
1322  return station->m_state->m_operationalMcsSet[i];
1323 }
1324 bool
1326 {
1327  return station->m_state->m_shortGuardInterval;
1328 }
1329 bool
1331 {
1332  return station->m_state->m_greenfield;
1333 }
1334 bool
1336 {
1337  return station->m_state->m_stbc;
1338 }
1339 uint32_t
1341 {
1342  return station->m_state->m_rx;
1343 }
1344 uint32_t
1346 {
1347  return station->m_state->m_tx;
1348 }
1349 uint32_t
1351 {
1352  return station->m_ssrc;
1353 }
1354 uint32_t
1356 {
1357  return station->m_slrc;
1358 }
1359 uint32_t
1361 {
1362  return station->m_state->m_operationalRateSet.size ();
1363 }
1364 uint32_t
1366 {
1367  return station->m_state->m_operationalMcsSet.size ();
1368 }
1369 void
1371 {
1372  m_defaultTxPowerLevel = txPower;
1373 }
1374 
1375 //support 11n
1376 uint32_t
1378 {
1380 }
1381 //WifiRemoteStationInfo constructor
1383  : m_memoryTime (Seconds (1.0)),
1384  m_lastUpdate (Seconds (0.0)),
1385  m_failAvg (0.0)
1386 {
1387 }
1388 
1389 double
1391 {
1392  double retval = std::exp ((double)(m_lastUpdate.GetMicroSeconds () - Simulator::Now ().GetMicroSeconds ())
1393  / (double)m_memoryTime.GetMicroSeconds ());
1395  return retval;
1396 }
1397 
1398 void
1400 {
1401  double coefficient = CalculateAveragingCoefficient ();
1402  m_failAvg = (double)retryCounter / (1 + (double) retryCounter) * (1.0 - coefficient) + coefficient * m_failAvg;
1403 }
1404 
1405 void
1407 {
1408  double coefficient = CalculateAveragingCoefficient ();
1409  m_failAvg = (1.0 - coefficient) + coefficient * m_failAvg;
1410 }
1411 
1412 double
1414 {
1415  return m_failAvg;
1416 }
1417 } // namespace ns3