src/wifi/model/wifi-remote-station-manager.cc
changeset 9165 7b219a73b844
parent 9063 32755d0516f4
child 9870 6543f3876ff5
equal deleted inserted replaced
9164:347452534b2e 9165:7b219a73b844
   163     .AddAttribute ("FragmentationThreshold", "If the size of the data packet + LLC header + MAC header + FCS trailer is bigger"
   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 "
   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. "
   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.",
   166                    "This value will not have any effect on some rate control algorithms.",
   167                    UintegerValue (2346),
   167                    UintegerValue (2346),
   168                    MakeUintegerAccessor (&WifiRemoteStationManager::m_fragmentationThreshold),
   168                    MakeUintegerAccessor (&WifiRemoteStationManager::DoSetFragmentationThreshold,
       
   169                                          &WifiRemoteStationManager::DoGetFragmentationThreshold),
   169                    MakeUintegerChecker<uint32_t> ())
   170                    MakeUintegerChecker<uint32_t> ())
   170     .AddAttribute ("NonUnicastMode", "Wifi mode used for non-unicast transmissions.",
   171     .AddAttribute ("NonUnicastMode", "Wifi mode used for non-unicast transmissions.",
   171                    WifiModeValue (),
   172                    WifiModeValue (),
   172                    MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
   173                    MakeWifiModeAccessor (&WifiRemoteStationManager::m_nonUnicastMode),
   173                    MakeWifiModeChecker ())
   174                    MakeWifiModeChecker ())
   237   return m_rtsCtsThreshold;
   238   return m_rtsCtsThreshold;
   238 }
   239 }
   239 uint32_t
   240 uint32_t
   240 WifiRemoteStationManager::GetFragmentationThreshold (void) const
   241 WifiRemoteStationManager::GetFragmentationThreshold (void) const
   241 {
   242 {
   242   return m_fragmentationThreshold;
   243   return DoGetFragmentationThreshold ();
   243 }
   244 }
   244 void
   245 void
   245 WifiRemoteStationManager::SetMaxSsrc (uint32_t maxSsrc)
   246 WifiRemoteStationManager::SetMaxSsrc (uint32_t maxSsrc)
   246 {
   247 {
   247   m_maxSsrc = maxSsrc;
   248   m_maxSsrc = maxSsrc;
   257   m_rtsCtsThreshold = threshold;
   258   m_rtsCtsThreshold = threshold;
   258 }
   259 }
   259 void
   260 void
   260 WifiRemoteStationManager::SetFragmentationThreshold (uint32_t threshold)
   261 WifiRemoteStationManager::SetFragmentationThreshold (uint32_t threshold)
   261 {
   262 {
   262   m_fragmentationThreshold = threshold;
   263   DoSetFragmentationThreshold (threshold);
   263 }
   264 }
   264 
   265 
   265 void
   266 void
   266 WifiRemoteStationManager::Reset (Mac48Address address)
   267 WifiRemoteStationManager::Reset (Mac48Address address)
   267 {
   268 {
   495     }
   496     }
   496   WifiRemoteStation *station = Lookup (address, header);
   497   WifiRemoteStation *station = Lookup (address, header);
   497   bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetFragmentationThreshold ();
   498   bool normally = (packet->GetSize () + header->GetSize () + WIFI_MAC_FCS_LENGTH) > GetFragmentationThreshold ();
   498   return DoNeedFragmentation (station, packet, normally);
   499   return DoNeedFragmentation (station, packet, normally);
   499 }
   500 }
   500 uint32_t
   501 
   501 WifiRemoteStationManager::GetNFragments (Ptr<const Packet> packet)
   502 void
   502 {
   503 WifiRemoteStationManager::DoSetFragmentationThreshold (uint32_t threshold)
   503   uint32_t nFragments = packet->GetSize () / GetFragmentationThreshold () + 1;
   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     }
   504   return nFragments;
   548   return nFragments;
   505 }
   549 }
   506 
   550 
   507 uint32_t
   551 uint32_t
   508 WifiRemoteStationManager::GetFragmentSize (Mac48Address address, const WifiMacHeader *header,
   552 WifiRemoteStationManager::GetFragmentSize (Mac48Address address, const WifiMacHeader *header,
   509                                            Ptr<const Packet> packet, uint32_t fragmentNumber)
   553                                            Ptr<const Packet> packet, uint32_t fragmentNumber)
   510 {
   554 {
   511   NS_ASSERT (!address.IsGroup ());
   555   NS_ASSERT (!address.IsGroup ());
   512   uint32_t nFragment = GetNFragments (packet);
   556   uint32_t nFragment = GetNFragments (header, packet);
   513   if (fragmentNumber >= nFragment)
   557   if (fragmentNumber >= nFragment)
   514     {
   558     {
   515       return 0;
   559       return 0;
   516     }
   560     }
       
   561   //Last fragment
   517   if (fragmentNumber == nFragment - 1)
   562   if (fragmentNumber == nFragment - 1)
   518     {
   563     {
   519       uint32_t lastFragmentSize = packet->GetSize () % GetFragmentationThreshold ();
   564       uint32_t lastFragmentSize = packet->GetSize () - (fragmentNumber * (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH));
   520       return lastFragmentSize;
   565       return lastFragmentSize;
   521     }
   566     }
       
   567   //All fragments but the last, the number of bytes is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
   522   else
   568   else
   523     {
   569     {
   524       return GetFragmentationThreshold ();
   570       return GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH;
   525     }
   571     }
   526 }
   572 }
   527 uint32_t
   573 uint32_t
   528 WifiRemoteStationManager::GetFragmentOffset (Mac48Address address, const WifiMacHeader *header,
   574 WifiRemoteStationManager::GetFragmentOffset (Mac48Address address, const WifiMacHeader *header,
   529                                              Ptr<const Packet> packet, uint32_t fragmentNumber)
   575                                              Ptr<const Packet> packet, uint32_t fragmentNumber)
   530 {
   576 {
   531   NS_ASSERT (!address.IsGroup ());
   577   NS_ASSERT (!address.IsGroup ());
   532   NS_ASSERT (fragmentNumber < GetNFragments (packet));
   578   NS_ASSERT (fragmentNumber < GetNFragments (header, packet));
   533   uint32_t fragmentOffset = fragmentNumber * GetFragmentationThreshold ();
   579   uint32_t fragmentOffset = fragmentNumber * (GetFragmentationThreshold () - header->GetSize () - WIFI_MAC_FCS_LENGTH);
   534   return fragmentOffset;
   580   return fragmentOffset;
   535 }
   581 }
   536 bool
   582 bool
   537 WifiRemoteStationManager::IsLastFragment (Mac48Address address, const WifiMacHeader *header,
   583 WifiRemoteStationManager::IsLastFragment (Mac48Address address, const WifiMacHeader *header,
   538                                           Ptr<const Packet> packet, uint32_t fragmentNumber)
   584                                           Ptr<const Packet> packet, uint32_t fragmentNumber)
   539 {
   585 {
   540   NS_ASSERT (!address.IsGroup ());
   586   NS_ASSERT (!address.IsGroup ());
   541   bool isLast = fragmentNumber == (GetNFragments (packet) - 1);
   587   bool isLast = fragmentNumber == (GetNFragments (header, packet) - 1);
   542   return isLast;
   588   return isLast;
   543 }
   589 }
   544 WifiMode
   590 WifiMode
   545 WifiRemoteStationManager::GetControlAnswerMode (Mac48Address address, WifiMode reqMode)
   591 WifiRemoteStationManager::GetControlAnswerMode (Mac48Address address, WifiMode reqMode)
   546 {
   592 {