src/wifi/model/wifi-remote-station-manager.cc
changeset 10139 17a71cd49da3
parent 9870 6543f3876ff5
child 10207 4c42c64f7ea8
equal deleted inserted replaced
10138:2f8e35b43d11 10139:17a71cd49da3
    38  *           Packet Mode Tagger
    38  *           Packet Mode Tagger
    39  ***************************************************************/
    39  ***************************************************************/
    40 
    40 
    41 namespace ns3 {
    41 namespace ns3 {
    42 
    42 
    43 class TxModeTag : public Tag
    43 class HighLatencyDataTxVectorTag : public Tag
    44 {
    44 {
    45 public:
    45 public:
    46   TxModeTag ();
    46   HighLatencyDataTxVectorTag ();
    47   TxModeTag (WifiMode rtsMode, WifiMode dataMode);
    47   HighLatencyDataTxVectorTag (WifiTxVector dataTxVector);
    48   WifiMode GetRtsMode (void) const;
    48   WifiTxVector GetDataTxVector (void) const;
    49   WifiMode GetDataMode (void) const;
       
    50 
    49 
    51   static TypeId GetTypeId (void);
    50   static TypeId GetTypeId (void);
    52   virtual TypeId GetInstanceTypeId (void) const;
    51   virtual TypeId GetInstanceTypeId (void) const;
    53   virtual uint32_t GetSerializedSize (void) const;
    52   virtual uint32_t GetSerializedSize (void) const;
    54   virtual void Serialize (TagBuffer i) const;
    53   virtual void Serialize (TagBuffer i) const;
    55   virtual void Deserialize (TagBuffer i);
    54   virtual void Deserialize (TagBuffer i);
    56   virtual void Print (std::ostream &os) const;
    55   virtual void Print (std::ostream &os) const;
    57 private:
    56 private:
    58   WifiMode m_rtsMode;
    57   WifiTxVector m_dataTxVector;
    59   WifiMode m_dataMode;
       
    60 };
    58 };
    61 
    59 
    62 TxModeTag::TxModeTag ()
    60 HighLatencyDataTxVectorTag::HighLatencyDataTxVectorTag ()
    63 {
    61 {
    64 }
    62 }
    65 TxModeTag::TxModeTag (WifiMode rtsMode, WifiMode dataMode)
    63 HighLatencyDataTxVectorTag::HighLatencyDataTxVectorTag ( WifiTxVector dataTxVector)
    66   : m_rtsMode (rtsMode),
    64   : m_dataTxVector (dataTxVector)
    67     m_dataMode (dataMode)
    65 {
    68 {
    66 }
    69 }
    67 
    70 WifiMode
    68 WifiTxVector 
    71 TxModeTag::GetRtsMode (void) const
    69 HighLatencyDataTxVectorTag::GetDataTxVector (void) const
    72 {
    70 {
    73   return m_rtsMode;
    71   return m_dataTxVector;
    74 }
       
    75 WifiMode
       
    76 TxModeTag::GetDataMode (void) const
       
    77 {
       
    78   return m_dataMode;
       
    79 }
    72 }
    80 TypeId
    73 TypeId
    81 TxModeTag::GetTypeId (void)
    74 HighLatencyDataTxVectorTag::GetTypeId (void)
    82 {
    75 {
    83   static TypeId tid = TypeId ("ns3::TxModeTag")
    76   static TypeId tid = TypeId ("ns3::HighLatencyDataTxVectorTag")
    84     .SetParent<Tag> ()
    77     .SetParent<Tag> ()
    85     .AddConstructor<TxModeTag> ()
    78     .AddConstructor<HighLatencyDataTxVectorTag> ()  
    86     .AddAttribute ("RtsTxMode",
    79     ;
    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;
    80   return tid;
    98 }
    81 }
    99 TypeId
    82 TypeId
   100 TxModeTag::GetInstanceTypeId (void) const
    83 HighLatencyDataTxVectorTag::GetInstanceTypeId (void) const
   101 {
    84 {
   102   return GetTypeId ();
    85   return GetTypeId ();
   103 }
    86 }
   104 uint32_t
    87 uint32_t
   105 TxModeTag::GetSerializedSize (void) const
    88 HighLatencyDataTxVectorTag::GetSerializedSize (void) const
   106 {
    89 {
   107   return sizeof (WifiMode) * 2;
    90   return sizeof (WifiTxVector);
   108 }
    91 }
   109 void
    92 void
   110 TxModeTag::Serialize (TagBuffer i) const
    93 HighLatencyDataTxVectorTag::Serialize (TagBuffer i) const
   111 {
    94 {
   112   i.Write ((uint8_t *)&m_rtsMode, sizeof (WifiMode));
    95   i.Write ((uint8_t *)&m_dataTxVector, sizeof (WifiTxVector));
   113   i.Write ((uint8_t *)&m_dataMode, sizeof (WifiMode));
    96 }
   114 }
    97 void
   115 void
    98 HighLatencyDataTxVectorTag::Deserialize (TagBuffer i)
   116 TxModeTag::Deserialize (TagBuffer i)
    99 {
   117 {
   100   i.Read ((uint8_t *)&m_dataTxVector, sizeof (WifiTxVector));
   118   i.Read ((uint8_t *)&m_rtsMode, sizeof (WifiMode));
   101 }
   119   i.Read ((uint8_t *)&m_dataMode, sizeof (WifiMode));
   102 void
   120 }
   103 HighLatencyDataTxVectorTag::Print (std::ostream &os) const
   121 void
   104 {
   122 TxModeTag::Print (std::ostream &os) const
   105   os << "Data=" << m_dataTxVector;
   123 {
   106 }
   124   os << "Rts=" << m_rtsMode << ", Data=" << m_dataMode;
   107 
       
   108 class HighLatencyRtsTxVectorTag : public Tag
       
   109 {
       
   110 public:
       
   111   HighLatencyRtsTxVectorTag ();
       
   112   HighLatencyRtsTxVectorTag (WifiTxVector rtsTxVector);
       
   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:
       
   122   WifiTxVector m_rtsTxVector;
       
   123 };
       
   124 
       
   125 HighLatencyRtsTxVectorTag::HighLatencyRtsTxVectorTag ()
       
   126 {
       
   127 }
       
   128 HighLatencyRtsTxVectorTag::HighLatencyRtsTxVectorTag ( WifiTxVector rtsTxVector)
       
   129   : m_rtsTxVector (rtsTxVector)
       
   130 {
       
   131 }
       
   132 
       
   133 WifiTxVector 
       
   134 HighLatencyRtsTxVectorTag::GetRtsTxVector (void) const
       
   135 {
       
   136   return m_rtsTxVector;
       
   137 }
       
   138 TypeId
       
   139 HighLatencyRtsTxVectorTag::GetTypeId (void)
       
   140 {
       
   141   static TypeId tid = TypeId ("ns3::HighLatencyRtsTxVectorTag")
       
   142     .SetParent<Tag> ()
       
   143     .AddConstructor<HighLatencyRtsTxVectorTag> ()  
       
   144     ;
       
   145   return tid;
       
   146 }
       
   147 TypeId
       
   148 HighLatencyRtsTxVectorTag::GetInstanceTypeId (void) const
       
   149 {
       
   150   return GetTypeId ();
       
   151 }
       
   152 uint32_t
       
   153 HighLatencyRtsTxVectorTag::GetSerializedSize (void) const
       
   154 {
       
   155   return sizeof (WifiTxVector);
       
   156 }
       
   157 void
       
   158 HighLatencyRtsTxVectorTag::Serialize (TagBuffer i) const
       
   159 {
       
   160   i.Write ((uint8_t *)&m_rtsTxVector, sizeof (WifiTxVector));
       
   161 }
       
   162 void
       
   163 HighLatencyRtsTxVectorTag::Deserialize (TagBuffer i)
       
   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 
       
   173 class HighLatencyCtsToSelfTxVectorTag : public Tag
       
   174 {
       
   175 public:
       
   176   HighLatencyCtsToSelfTxVectorTag ();
       
   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:
       
   187   WifiTxVector m_ctsToSelfTxVector;
       
   188 };
       
   189 
       
   190 HighLatencyCtsToSelfTxVectorTag::HighLatencyCtsToSelfTxVectorTag ()
       
   191 {
       
   192 }
       
   193 HighLatencyCtsToSelfTxVectorTag::HighLatencyCtsToSelfTxVectorTag ( WifiTxVector ctsToSelfTxVector)
       
   194   : m_ctsToSelfTxVector (ctsToSelfTxVector)
       
   195 {
       
   196 }
       
   197 
       
   198 WifiTxVector 
       
   199 HighLatencyCtsToSelfTxVectorTag::GetCtsToSelfTxVector (void) const
       
   200 {
       
   201   return m_ctsToSelfTxVector;
       
   202 }
       
   203 TypeId
       
   204 HighLatencyCtsToSelfTxVectorTag::GetTypeId (void)
       
   205 {
       
   206   static TypeId tid = TypeId ("ns3::HighLatencyCtsToSelfTxVectorTag")
       
   207     .SetParent<Tag> ()
       
   208     .AddConstructor<HighLatencyCtsToSelfTxVectorTag> ()  
       
   209     ;
       
   210   return tid;
       
   211 }
       
   212 TypeId
       
   213 HighLatencyCtsToSelfTxVectorTag::GetInstanceTypeId (void) const
       
   214 {
       
   215   return GetTypeId ();
       
   216 }
       
   217 uint32_t
       
   218 HighLatencyCtsToSelfTxVectorTag::GetSerializedSize (void) const
       
   219 {
       
   220   return sizeof (WifiTxVector);
       
   221 }
       
   222 void
       
   223 HighLatencyCtsToSelfTxVectorTag::Serialize (TagBuffer i) const
       
   224 {
       
   225   i.Write ((uint8_t *)&m_ctsToSelfTxVector, sizeof (WifiTxVector));
       
   226 }
       
   227 void
       
   228 HighLatencyCtsToSelfTxVectorTag::Deserialize (TagBuffer i)
       
   229 {
       
   230   i.Read ((uint8_t *)&m_ctsToSelfTxVector, sizeof (WifiTxVector));
       
   231 }
       
   232 void
       
   233 HighLatencyCtsToSelfTxVectorTag::Print (std::ostream &os) const
       
   234 {
       
   235   os << "Cts To Self=" << m_ctsToSelfTxVector;
   125 }
   236 }
   126 
   237 
   127 } // namespace ns3
   238 } // namespace ns3
   128 
       
   129 
   239 
   130 namespace ns3 {
   240 namespace ns3 {
   131 
   241 
   132 NS_OBJECT_ENSURE_REGISTERED (WifiRemoteStationManager);
   242 NS_OBJECT_ENSURE_REGISTERED (WifiRemoteStationManager);
   133 
   243 
   170                    MakeUintegerChecker<uint32_t> ())
   280                    MakeUintegerChecker<uint32_t> ())
   171     .AddAttribute ("NonUnicastMode", "Wifi mode used for non-unicast transmissions.",
   281     .AddAttribute ("NonUnicastMode", "Wifi mode used for non-unicast transmissions.",
   172                    WifiModeValue (),
   282                    WifiModeValue (),
   173                    MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
   283                    MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
   174                    MakeWifiModeChecker ())
   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> ())
   175     .AddTraceSource ("MacTxRtsFailed",
   291     .AddTraceSource ("MacTxRtsFailed",
   176                      "The transmission of a RTS by the MAC layer has failed",
   292                      "The transmission of a RTS by the MAC layer has failed",
   177                      MakeTraceSourceAccessor (&WifiRemoteStationManager::m_macTxRtsFailed))
   293                      MakeTraceSourceAccessor (&WifiRemoteStationManager::m_macTxRtsFailed))
   178     .AddTraceSource ("MacTxDataFailed",
   294     .AddTraceSource ("MacTxDataFailed",
   179                      "The transmission of a data packet by the MAC layer has failed",
   295                      "The transmission of a data packet by the MAC layer has failed",
   217   // this in order to find the relevant mandatory rates when chosing a
   333   // this in order to find the relevant mandatory rates when chosing a
   218   // transmit rate for automatic control responses like
   334   // transmit rate for automatic control responses like
   219   // acknowledgements.
   335   // acknowledgements.
   220   m_wifiPhy = phy;
   336   m_wifiPhy = phy;
   221   m_defaultTxMode = phy->GetMode (0);
   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     }
   222   Reset ();
   346   Reset ();
   223 }
   347 }
   224 
   348 void
       
   349 WifiRemoteStationManager::SetHtSupported (bool enable)
       
   350 {
       
   351   m_htSupported=enable;
       
   352 }
       
   353 
       
   354 bool
       
   355 WifiRemoteStationManager::HasHtSupported (void) const
       
   356 {
       
   357   return m_htSupported;
       
   358 }
   225 uint32_t
   359 uint32_t
   226 WifiRemoteStationManager::GetMaxSsrc (void) const
   360 WifiRemoteStationManager::GetMaxSsrc (void) const
   227 {
   361 {
   228   return m_maxSsrc;
   362   return m_maxSsrc;
   229 }
   363 }
   267 WifiRemoteStationManager::Reset (Mac48Address address)
   401 WifiRemoteStationManager::Reset (Mac48Address address)
   268 {
   402 {
   269   NS_ASSERT (!address.IsGroup ());
   403   NS_ASSERT (!address.IsGroup ());
   270   WifiRemoteStationState *state = LookupState (address);
   404   WifiRemoteStationState *state = LookupState (address);
   271   state->m_operationalRateSet.clear ();
   405   state->m_operationalRateSet.clear ();
       
   406   state->m_operationalMcsSet.clear ();
   272   AddSupportedMode (address, GetDefaultMode ());
   407   AddSupportedMode (address, GetDefaultMode ());
       
   408   AddSupportedMcs(address,GetDefaultMcs());
   273 }
   409 }
   274 void
   410 void
   275 WifiRemoteStationManager::AddSupportedMode (Mac48Address address, WifiMode mode)
   411 WifiRemoteStationManager::AddSupportedMode (Mac48Address address, WifiMode mode)
   276 {
   412 {
   277   NS_ASSERT (!address.IsGroup ());
   413   NS_ASSERT (!address.IsGroup ());
   284           return;
   420           return;
   285         }
   421         }
   286     }
   422     }
   287   state->m_operationalRateSet.push_back (mode);
   423   state->m_operationalRateSet.push_back (mode);
   288 }
   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 
       
   447 WifiRemoteStationManager::AddSupportedMcs (Mac48Address address, uint8_t mcs)
       
   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 }
   289 bool
   461 bool
   290 WifiRemoteStationManager::IsBrandNew (Mac48Address address) const
   462 WifiRemoteStationManager::IsBrandNew (Mac48Address address) const
   291 {
   463 {
   292   if (address.IsGroup ())
   464   if (address.IsGroup ())
   293     {
   465     {
   344   if (IsLowLatency () || address.IsGroup ())
   516   if (IsLowLatency () || address.IsGroup ())
   345     {
   517     {
   346       return;
   518       return;
   347     }
   519     }
   348   WifiRemoteStation *station = Lookup (address, header);
   520   WifiRemoteStation *station = Lookup (address, header);
   349   WifiMode rts = DoGetRtsMode (station);
   521   WifiTxVector rts = DoGetRtsTxVector (station);
   350   WifiMode data = DoGetDataMode (station, fullPacketSize);
   522   WifiTxVector data = DoGetDataTxVector (station, fullPacketSize); 
   351   TxModeTag tag;
   523   WifiTxVector ctstoself = DoGetCtsToSelfTxVector (); 
       
   524   HighLatencyDataTxVectorTag datatag;
       
   525   HighLatencyRtsTxVectorTag rtstag;
       
   526   HighLatencyCtsToSelfTxVectorTag ctstoselftag;
   352   // first, make sure that the tag is not here anymore.
   527   // first, make sure that the tag is not here anymore.
   353   ConstCast<Packet> (packet)->RemovePacketTag (tag);
   528   ConstCast<Packet> (packet)->RemovePacketTag (datatag);
   354   tag = TxModeTag (rts, data);
   529   ConstCast<Packet> (packet)->RemovePacketTag (rtstag);
       
   530   ConstCast<Packet> (packet)->RemovePacketTag (ctstoselftag);
       
   531   datatag = HighLatencyDataTxVectorTag (data);
       
   532   rtstag = HighLatencyRtsTxVectorTag (rts);
       
   533   ctstoselftag = HighLatencyCtsToSelfTxVectorTag (ctstoself);
   355   // and then, add it back
   534   // and then, add it back
   356   packet->AddPacketTag (tag);
   535   packet->AddPacketTag (datatag);
   357 }
   536   packet->AddPacketTag (rtstag);
   358 WifiMode
   537   packet->AddPacketTag (ctstoselftag);
   359 WifiRemoteStationManager::GetDataMode (Mac48Address address, const WifiMacHeader *header,
   538 }
       
   539 WifiTxVector
       
   540 WifiRemoteStationManager::GetDataTxVector (Mac48Address address, const WifiMacHeader *header,
   360                                        Ptr<const Packet> packet, uint32_t fullPacketSize)
   541                                        Ptr<const Packet> packet, uint32_t fullPacketSize)
   361 {
   542 {
   362   if (address.IsGroup ())
   543   if (address.IsGroup ())
   363     {
   544     {
   364       return GetNonUnicastMode ();
   545       WifiTxVector v;
       
   546       v.SetMode (GetNonUnicastMode ());
       
   547       v.SetTxPowerLevel (m_defaultTxPowerLevel);
       
   548       v.SetShortGuardInterval (false);
       
   549       v.SetNss (1);
       
   550       v.SetNess (0);
       
   551       v.SetStbc (false);
       
   552       return v;
   365     }
   553     }
   366   if (!IsLowLatency ())
   554   if (!IsLowLatency ())
   367     {
   555     {
   368       TxModeTag tag;
   556       HighLatencyDataTxVectorTag datatag;
   369       bool found;
   557       bool found;
   370       found = ConstCast<Packet> (packet)->PeekPacketTag (tag);
   558       found = ConstCast<Packet> (packet)->PeekPacketTag (datatag);
   371       NS_ASSERT (found);
   559       NS_ASSERT (found);
   372       return tag.GetDataMode ();
   560       // cast found to void, to suppress 'found' set but not used
   373     }
   561       // compiler warning
   374   return DoGetDataMode (Lookup (address, header), fullPacketSize);
   562       (void) found;
   375 }
   563       return datatag.GetDataTxVector ();
   376 WifiMode
   564     }
   377 WifiRemoteStationManager::GetRtsMode (Mac48Address address, const WifiMacHeader *header,
   565   return DoGetDataTxVector (Lookup (address, header), fullPacketSize);
       
   566 }
       
   567 WifiTxVector
       
   568 WifiRemoteStationManager::GetCtsToSelfTxVector(const WifiMacHeader *header,
   378                                       Ptr<const Packet> packet)
   569                                       Ptr<const Packet> packet)
   379 {
   570 {
   380   NS_ASSERT (!address.IsGroup ());
   571   
   381   if (!IsLowLatency ())
   572   if (!IsLowLatency ())
   382     {
   573     {
   383       TxModeTag tag;
   574       HighLatencyCtsToSelfTxVectorTag ctstoselftag;
   384       bool found;
   575       bool found;
   385       found = ConstCast<Packet> (packet)->PeekPacketTag (tag);
   576       found = ConstCast<Packet> (packet)->PeekPacketTag (ctstoselftag);
   386       NS_ASSERT (found);
   577       NS_ASSERT (found);
   387       return tag.GetRtsMode ();
   578       // cast found to void, to suppress 'found' set but not used
   388     }
   579       // compiler warning
   389   return DoGetRtsMode (Lookup (address, header));
   580       (void) found;
       
   581       return ctstoselftag.GetCtsToSelfTxVector ();
       
   582     }
       
   583   return DoGetCtsToSelfTxVector ();
       
   584 }
       
   585 
       
   586 WifiTxVector
       
   587 WifiRemoteStationManager::DoGetCtsToSelfTxVector (void)
       
   588 {
       
   589   return WifiTxVector (GetDefaultMode(), GetDefaultTxPowerLevel (),0,m_wifiPhy->GetGuardInterval(),GetNumberOfTransmitAntennas(), GetNumberOfTransmitAntennas(), false);
       
   590 }
       
   591 
       
   592 WifiTxVector
       
   593 WifiRemoteStationManager::GetRtsTxVector (Mac48Address address, const WifiMacHeader *header,
       
   594                                       Ptr<const Packet> packet)
       
   595 {
       
   596   NS_ASSERT (!address.IsGroup ());
       
   597   if (!IsLowLatency ())
       
   598     {
       
   599       HighLatencyRtsTxVectorTag rtstag;
       
   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));
   390 }
   609 }
   391 void
   610 void
   392 WifiRemoteStationManager::ReportRtsFailed (Mac48Address address, const WifiMacHeader *header)
   611 WifiRemoteStationManager::ReportRtsFailed (Mac48Address address, const WifiMacHeader *header)
   393 {
   612 {
   394   NS_ASSERT (!address.IsGroup ());
   613   NS_ASSERT (!address.IsGroup ());
   465     {
   684     {
   466       return false;
   685       return false;
   467     }
   686     }
   468   bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetRtsCtsThreshold ();
   687   bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetRtsCtsThreshold ();
   469   return DoNeedRts (Lookup (address, header), packet, normally);
   688   return DoNeedRts (Lookup (address, header), packet, normally);
       
   689 }
       
   690 bool
       
   691 WifiRemoteStationManager::NeedCtsToSelf (WifiTxVector txVector)
       
   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;
   470 }
   717 }
   471 bool
   718 bool
   472 WifiRemoteStationManager::NeedRtsRetransmission (Mac48Address address, const WifiMacHeader *header,
   719 WifiRemoteStationManager::NeedRtsRetransmission (Mac48Address address, const WifiMacHeader *header,
   473                                                  Ptr<const Packet> packet)
   720                                                  Ptr<const Packet> packet)
   474 {
   721 {
   620           // need to continue and consider all the basic rates before
   867           // need to continue and consider all the basic rates before
   621           // we can be sure we've got the right one.
   868           // we can be sure we've got the right one.
   622           found = true;
   869           found = true;
   623         }
   870         }
   624     }
   871     }
   625 
   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 }
   626   // If we found a suitable rate in the BSSBasicRateSet, then we are
   895   // If we found a suitable rate in the BSSBasicRateSet, then we are
   627   // done and can return that mode.
   896   // done and can return that mode.
   628   if (found)
   897   if (found)
   629     {
   898     {
   630       return mode;
   899       return mode;
   671           // mandatory rates before we can be sure we've got the right
   940           // mandatory rates before we can be sure we've got the right
   672           // one.
   941           // one.
   673           found = true;
   942           found = true;
   674         }
   943         }
   675     }
   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       }
   676 
   966 
   677   /**
   967   /**
   678    * If we still haven't found a suitable rate for the response then
   968    * If we still haven't found a suitable rate for the response then
   679    * someone has messed up the simulation config. This probably means
   969    * someone has messed up the simulation config. This probably means
   680    * that the WifiPhyStandard is not set correctly, or that a rate that
   970    * that the WifiPhyStandard is not set correctly, or that a rate that
   691     }
   981     }
   692 
   982 
   693   return mode;
   983   return mode;
   694 }
   984 }
   695 
   985 
   696 WifiMode
   986 WifiTxVector
   697 WifiRemoteStationManager::GetCtsMode (Mac48Address address, WifiMode rtsMode)
   987 WifiRemoteStationManager::GetCtsTxVector (Mac48Address address, WifiMode rtsMode)
   698 {
   988 {
   699   NS_ASSERT (!address.IsGroup ());
   989   NS_ASSERT (!address.IsGroup ());
   700   return GetControlAnswerMode (address, rtsMode);
   990   WifiTxVector v;
   701 }
   991   v.SetMode (GetControlAnswerMode (address, rtsMode));
   702 WifiMode
   992   v.SetTxPowerLevel (DoGetCtsTxPowerLevel (address, v.GetMode()));
   703 WifiRemoteStationManager::GetAckMode (Mac48Address address, WifiMode dataMode)
   993   v.SetShortGuardInterval (DoGetCtsTxGuardInterval(address, v.GetMode()));
   704 {
   994   v.SetNss (DoGetCtsTxNss(address, v.GetMode()));
   705   NS_ASSERT (!address.IsGroup ());
   995   v.SetNess (DoGetCtsTxNess(address, v.GetMode()));
   706   return GetControlAnswerMode (address, dataMode);
   996   v.SetStbc (DoGetCtsTxStbc(address, v.GetMode()));
   707 }
   997   return v;
       
   998 }
       
   999 WifiTxVector
       
  1000 WifiRemoteStationManager::GetAckTxVector (Mac48Address address, WifiMode dataMode)
       
  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 }
       
  1012 WifiTxVector
       
  1013 WifiRemoteStationManager::GetBlockAckTxVector (Mac48Address address, WifiMode blockAckReqMode)
       
  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 
       
  1027 WifiRemoteStationManager::DoGetCtsTxPowerLevel (Mac48Address address, WifiMode ctsMode)
       
  1028 {
       
  1029   return m_defaultTxPowerLevel;
       
  1030 }
       
  1031 
       
  1032 bool 
       
  1033 WifiRemoteStationManager::DoGetCtsTxGuardInterval(Mac48Address address, WifiMode ctsMode)
       
  1034 {
       
  1035   return m_wifiPhy->GetGuardInterval();
       
  1036 }
       
  1037 
       
  1038 uint8_t
       
  1039 WifiRemoteStationManager::DoGetCtsTxNss(Mac48Address address, WifiMode ctsMode)
       
  1040 {
       
  1041   return 1;
       
  1042 }
       
  1043 uint8_t
       
  1044 WifiRemoteStationManager::DoGetCtsTxNess(Mac48Address address, WifiMode ctsMode)
       
  1045 {
       
  1046   return 0;
       
  1047 }
       
  1048 bool 
       
  1049 WifiRemoteStationManager::DoGetCtsTxStbc(Mac48Address address, WifiMode ctsMode)
       
  1050 {
       
  1051   return m_wifiPhy->GetStbc();
       
  1052 }
       
  1053 
       
  1054 uint8_t 
       
  1055 WifiRemoteStationManager::DoGetAckTxPowerLevel (Mac48Address address, WifiMode ackMode)
       
  1056 {
       
  1057   return m_defaultTxPowerLevel;
       
  1058 }
       
  1059 
       
  1060 bool 
       
  1061 WifiRemoteStationManager::DoGetAckTxGuardInterval(Mac48Address address, WifiMode ackMode)
       
  1062 {
       
  1063   return m_wifiPhy->GetGuardInterval();
       
  1064 }
       
  1065 
       
  1066 uint8_t
       
  1067 WifiRemoteStationManager::DoGetAckTxNss(Mac48Address address, WifiMode ackMode)
       
  1068 {
       
  1069   return 1;
       
  1070 }
       
  1071 uint8_t
       
  1072 WifiRemoteStationManager::DoGetAckTxNess(Mac48Address address, WifiMode ackMode)
       
  1073 {
       
  1074   return 0;
       
  1075 }
       
  1076 bool 
       
  1077 WifiRemoteStationManager::DoGetAckTxStbc(Mac48Address address, WifiMode ackMode)
       
  1078 {
       
  1079   return m_wifiPhy->GetStbc();
       
  1080 }
       
  1081 
       
  1082 uint8_t 
       
  1083 WifiRemoteStationManager::DoGetBlockAckTxPowerLevel (Mac48Address address, WifiMode blockAckMode)
       
  1084 {
       
  1085   return m_defaultTxPowerLevel;
       
  1086 }
       
  1087 
       
  1088 bool 
       
  1089 WifiRemoteStationManager::DoGetBlockAckTxGuardInterval(Mac48Address address, WifiMode blockAckMode)
       
  1090 {
       
  1091   return m_wifiPhy->GetGuardInterval();
       
  1092 }
       
  1093 
       
  1094 uint8_t
       
  1095 WifiRemoteStationManager::DoGetBlockAckTxNss(Mac48Address address, WifiMode blockAckMode)
       
  1096 {
       
  1097   return 1;
       
  1098 }
       
  1099 uint8_t
       
  1100 WifiRemoteStationManager::DoGetBlockAckTxNess(Mac48Address address, WifiMode blockAckMode)
       
  1101 {
       
  1102   return 0;
       
  1103 }
       
  1104 bool 
       
  1105 WifiRemoteStationManager::DoGetBlockAckTxStbc(Mac48Address address, WifiMode blockAckMode)
       
  1106 {
       
  1107   return m_wifiPhy->GetStbc();
       
  1108 }
       
  1109 
       
  1110 
       
  1111 uint8_t
       
  1112 WifiRemoteStationManager::GetDefaultTxPowerLevel (void) const
       
  1113 {
       
  1114   return m_defaultTxPowerLevel;
       
  1115 }
       
  1116 
   708 
  1117 
   709 WifiRemoteStationInfo
  1118 WifiRemoteStationInfo
   710 WifiRemoteStationManager::GetInfo (Mac48Address address)
  1119 WifiRemoteStationManager::GetInfo (Mac48Address address)
   711 {
  1120 {
   712   WifiRemoteStationState *state = LookupState (address);
  1121   WifiRemoteStationState *state = LookupState (address);
   725     }
  1134     }
   726   WifiRemoteStationState *state = new WifiRemoteStationState ();
  1135   WifiRemoteStationState *state = new WifiRemoteStationState ();
   727   state->m_state = WifiRemoteStationState::BRAND_NEW;
  1136   state->m_state = WifiRemoteStationState::BRAND_NEW;
   728   state->m_address = address;
  1137   state->m_address = address;
   729   state->m_operationalRateSet.push_back (GetDefaultMode ());
  1138   state->m_operationalRateSet.push_back (GetDefaultMode ());
       
  1139   state->m_operationalMcsSet.push_back(GetDefaultMcs());
       
  1140   state->m_shortGuardInterval=m_wifiPhy->GetGuardInterval();
       
  1141   state->m_greenfield=m_wifiPhy->GetGreenfield();
       
  1142   state->m_rx=1;
       
  1143   state->m_tx=1;
       
  1144   state->m_stbc=false;
   730   const_cast<WifiRemoteStationManager *> (this)->m_states.push_back (state);
  1145   const_cast<WifiRemoteStationManager *> (this)->m_states.push_back (state);
   731   return state;
  1146   return state;
   732 }
  1147 }
   733 WifiRemoteStation *
  1148 WifiRemoteStation *
   734 WifiRemoteStationManager::Lookup (Mac48Address address, const WifiMacHeader *header) const
  1149 WifiRemoteStationManager::Lookup (Mac48Address address, const WifiMacHeader *header) const
   765   // XXX
  1180   // XXX
   766   const_cast<WifiRemoteStationManager *> (this)->m_stations.push_back (station);
  1181   const_cast<WifiRemoteStationManager *> (this)->m_stations.push_back (station);
   767   return station;
  1182   return station;
   768 
  1183 
   769 }
  1184 }
   770 
  1185 //Used by all stations to record HT capabilities of remote stations
       
  1186 void
       
  1187 WifiRemoteStationManager::AddStationHtCapabilities (Mac48Address from, HtCapabilities htcapabilities)
       
  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 
       
  1197 WifiRemoteStationManager::GetGreenfieldSupported (Mac48Address address) const
       
  1198 {
       
  1199  return LookupState(address)->m_greenfield;
       
  1200 }
   771 WifiMode
  1201 WifiMode
   772 WifiRemoteStationManager::GetDefaultMode (void) const
  1202 WifiRemoteStationManager::GetDefaultMode (void) const
   773 {
  1203 {
   774   return m_defaultTxMode;
  1204   return m_defaultTxMode;
       
  1205 }
       
  1206 uint8_t
       
  1207 WifiRemoteStationManager::GetDefaultMcs (void) const
       
  1208 {
       
  1209   return m_defaultTxMcs;
   775 }
  1210 }
   776 void
  1211 void
   777 WifiRemoteStationManager::Reset (void)
  1212 WifiRemoteStationManager::Reset (void)
   778 {
  1213 {
   779   for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
  1214   for (Stations::const_iterator i = m_stations.begin (); i != m_stations.end (); i++)
   781       delete (*i);
  1216       delete (*i);
   782     }
  1217     }
   783   m_stations.clear ();
  1218   m_stations.clear ();
   784   m_bssBasicRateSet.clear ();
  1219   m_bssBasicRateSet.clear ();
   785   m_bssBasicRateSet.push_back (m_defaultTxMode);
  1220   m_bssBasicRateSet.push_back (m_defaultTxMode);
       
  1221   m_bssBasicMcsSet.clear();
       
  1222   m_bssBasicMcsSet.push_back (m_defaultTxMcs);
   786   NS_ASSERT (m_defaultTxMode.IsMandatory ());
  1223   NS_ASSERT (m_defaultTxMode.IsMandatory ());
   787 }
  1224 }
   788 void
  1225 void
   789 WifiRemoteStationManager::AddBasicMode (WifiMode mode)
  1226 WifiRemoteStationManager::AddBasicMode (WifiMode mode)
   790 {
  1227 {
   806 WifiRemoteStationManager::GetBasicMode (uint32_t i) const
  1243 WifiRemoteStationManager::GetBasicMode (uint32_t i) const
   807 {
  1244 {
   808   NS_ASSERT (i < m_bssBasicRateSet.size ());
  1245   NS_ASSERT (i < m_bssBasicRateSet.size ());
   809   return m_bssBasicRateSet[i];
  1246   return m_bssBasicRateSet[i];
   810 }
  1247 }
       
  1248 
       
  1249 void 
       
  1250 WifiRemoteStationManager::AddBasicMcs (uint8_t mcs)
       
  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
       
  1263 WifiRemoteStationManager::GetNBasicMcs (void) const
       
  1264 {
       
  1265   return m_bssBasicMcsSet.size ();
       
  1266 }
       
  1267 uint8_t 
       
  1268 WifiRemoteStationManager::GetBasicMcs (uint32_t i) const
       
  1269 {
       
  1270    NS_ASSERT (i < m_bssBasicMcsSet.size ());
       
  1271   return m_bssBasicMcsSet[i];
       
  1272 }
       
  1273 
   811 WifiMode
  1274 WifiMode
   812 WifiRemoteStationManager::GetNonUnicastMode (void) const
  1275 WifiRemoteStationManager::GetNonUnicastMode (void) const
   813 {
  1276 {
   814   if (m_nonUnicastMode == WifiMode ())
  1277   if (m_nonUnicastMode == WifiMode ())
   815     {
  1278     {
   850 WifiRemoteStationManager::GetSupported (const WifiRemoteStation *station, uint32_t i) const
  1313 WifiRemoteStationManager::GetSupported (const WifiRemoteStation *station, uint32_t i) const
   851 {
  1314 {
   852   NS_ASSERT (i < GetNSupported (station));
  1315   NS_ASSERT (i < GetNSupported (station));
   853   return station->m_state->m_operationalRateSet[i];
  1316   return station->m_state->m_operationalRateSet[i];
   854 }
  1317 }
       
  1318 uint8_t
       
  1319 WifiRemoteStationManager::GetMcsSupported (const WifiRemoteStation *station, uint32_t i) const
       
  1320 {
       
  1321   NS_ASSERT (i < GetNMcsSupported (station));
       
  1322   return station->m_state->m_operationalMcsSet[i];
       
  1323 }
       
  1324 bool 
       
  1325 WifiRemoteStationManager::GetShortGuardInterval (const WifiRemoteStation *station) const
       
  1326 {
       
  1327   return station->m_state->m_shortGuardInterval;
       
  1328 }
       
  1329 bool 
       
  1330 WifiRemoteStationManager::GetGreenfield (const WifiRemoteStation *station) const
       
  1331 {
       
  1332   return station->m_state->m_greenfield;
       
  1333 }
       
  1334 bool 
       
  1335 WifiRemoteStationManager::GetStbc (const WifiRemoteStation *station) const
       
  1336 {
       
  1337   return station->m_state->m_stbc;
       
  1338 }
       
  1339 uint32_t 
       
  1340 WifiRemoteStationManager::GetNumberOfReceiveAntennas (const WifiRemoteStation *station) const
       
  1341 {
       
  1342   return station->m_state->m_rx;
       
  1343 }
       
  1344 uint32_t 
       
  1345 WifiRemoteStationManager::GetNumberOfTransmitAntennas (const WifiRemoteStation *station) const
       
  1346 {
       
  1347   return station->m_state->m_tx;
       
  1348 }
       
  1349 uint32_t 
       
  1350 WifiRemoteStationManager::GetShortRetryCount (const WifiRemoteStation *station) const
       
  1351 {
       
  1352   return station->m_ssrc;
       
  1353 }
       
  1354 uint32_t 
       
  1355 WifiRemoteStationManager::GetLongRetryCount (const WifiRemoteStation *station) const
       
  1356 {
       
  1357   return station->m_slrc;
       
  1358 }
   855 uint32_t
  1359 uint32_t
   856 WifiRemoteStationManager::GetNSupported (const WifiRemoteStation *station) const
  1360 WifiRemoteStationManager::GetNSupported (const WifiRemoteStation *station) const
   857 {
  1361 {
   858   return station->m_state->m_operationalRateSet.size ();
  1362   return station->m_state->m_operationalRateSet.size ();
   859 }
  1363 }
   860 
  1364 uint32_t
       
  1365 WifiRemoteStationManager::GetNMcsSupported (const WifiRemoteStation *station) const
       
  1366 {
       
  1367   return station->m_state->m_operationalMcsSet.size ();
       
  1368 }
       
  1369 void
       
  1370 WifiRemoteStationManager::SetDefaultTxPowerLevel (uint8_t txPower)
       
  1371 {
       
  1372   m_defaultTxPowerLevel = txPower;
       
  1373 }
       
  1374 
       
  1375 //support 11n
       
  1376 uint32_t
       
  1377 WifiRemoteStationManager::GetNumberOfTransmitAntennas (void)
       
  1378 {
       
  1379   return m_wifiPhy->GetNumberOfTransmitAntennas();
       
  1380 }
   861 //WifiRemoteStationInfo constructor
  1381 //WifiRemoteStationInfo constructor
   862 WifiRemoteStationInfo::WifiRemoteStationInfo ()
  1382 WifiRemoteStationInfo::WifiRemoteStationInfo ()
   863   : m_memoryTime (Seconds (1.0)),
  1383   : m_memoryTime (Seconds (1.0)),
   864     m_lastUpdate (Seconds (0.0)),
  1384     m_lastUpdate (Seconds (0.0)),
   865     m_failAvg (0.0)
  1385     m_failAvg (0.0)