BCA works again
authorKirill Andreev <andreev@iitp.ru>
Wed, 25 Mar 2009 16:12:01 +0300
changeset 4879 597d1e0a4bb5
parent 4878 60c3aba0dcd1
child 4880 26828c0949f1
BCA works again
src/devices/mesh/dot11s/peer-manager-plugin.cc
src/devices/mesh/dot11s/peer-manager-plugin.h
src/devices/mesh/dot11s/peer-manager-protocol.cc
src/devices/mesh/dot11s/peer-manager-protocol.h
--- a/src/devices/mesh/dot11s/peer-manager-plugin.cc	Wed Mar 25 14:32:56 2009 +0300
+++ b/src/devices/mesh/dot11s/peer-manager-plugin.cc	Wed Mar 25 16:12:01 2009 +0300
@@ -142,7 +142,7 @@
 bool
 PeerManagerMacPlugin::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to) const
 {
-  return false;
+  return true;
 }
 
 void
@@ -216,7 +216,20 @@
     return m_parent->GetAddress ();
   else return Mac48Address::Mac48Address();
 }
-  
+std::pair<Time, Time> 
+PeerManagerMacPlugin::GetBeaconInfo() const
+{
+  std::pair<Time,Time> retval;
+  retval.first = m_parent->GetTbtt ();
+  retval.second = m_parent->GetBeaconInterval ();
+  return retval;
+}
+void
+PeerManagerMacPlugin::SetBeaconShift(Time shift)
+{
+  m_parent->ShiftTbtt (shift);
+}
+
 } // namespace dot11s
 } //namespace ns3
 
--- a/src/devices/mesh/dot11s/peer-manager-plugin.h	Wed Mar 25 14:32:56 2009 +0300
+++ b/src/devices/mesh/dot11s/peer-manager-plugin.h	Wed Mar 25 16:12:01 2009 +0300
@@ -53,7 +53,16 @@
   ///\}
 private:
   friend class PeerManagerProtocol;
-  friend class PeerLink;
+  friend class PeerLink; 
+  ///\name BCA functionallity:
+  ///\{
+  ///\brief Fills TBTT and beacon interval. Needed by BCA
+  ///functionallity
+  ///\param first in retval is TBTT
+  ///\param second in retval is beacon interval
+  std::pair<Time, Time> GetBeaconInfo() const;
+  void SetBeaconShift(Time shift);
+  ///\}
   void SetPeerManagerProtcol(Ptr<PeerManagerProtocol> protocol);
   void SendPeerLinkManagementFrame(
       Mac48Address peerAddress,
--- a/src/devices/mesh/dot11s/peer-manager-protocol.cc	Wed Mar 25 14:32:56 2009 +0300
+++ b/src/devices/mesh/dot11s/peer-manager-protocol.cc	Wed Mar 25 16:12:01 2009 +0300
@@ -119,18 +119,29 @@
   BeaconInfoMap::iterator i = m_neighbourBeacons.find(interface);
   if(i == m_neighbourBeacons.end())
     return retval;
-  for(BeaconsOnInterface::iterator j = i->second.begin(); j != i->second.end(); j++)
+  bool cleaned = false;
+  while(!cleaned)
   {
-    //check beacon loss and make a timing element
-    if(
-        (j->second.referenceTbtt.GetMicroSeconds() +
-        (j->second.beaconInterval.GetMicroSeconds()* m_maxBeaconLoss))
+    for(BeaconsOnInterface::iterator j = i->second.begin(); j != i->second.end(); j++)
+    {
+      //check beacon loss and make a timing element
+      //if last beacon was 3 beacons ago - we do not put it to the
+      //timing element
+      if(
+          (j->second.referenceTbtt.GetMicroSeconds() +
+           (j->second.beaconInterval.GetMicroSeconds()* 3))
           <
-        Simulator::Now().GetMicroSeconds()
-        )
-      continue;
+          Simulator::Now().GetMicroSeconds()
+          )
+      {
+        i->second.erase(j);
+        break;
+      }
+    }
+    cleaned = true;
+  }
+  for(BeaconsOnInterface::iterator j = i->second.begin(); j != i->second.end(); j++)
     retval->AddNeighboursTimingElementUnit(j->second.aid, j->second.referenceTbtt, j->second.beaconInterval);
-  }
   return retval;
 }
 void
@@ -173,20 +184,24 @@
   FillBeaconInfo(interface, peerAddress, receivingTime, beaconInterval);
    if(!meshBeacon)
      return;
-  //PM STATE Machine
-  Ptr<PeerLink> peerLink = FindPeerLink(interface, peerAddress);
-  if(peerLink !=0)  
-  {
-    peerLink->SetBeaconTimingElement (timingElement);
-    peerLink->SetBeaconInformation (receivingTime, beaconInterval);
-  }
-  else
-  {
-    peerLink = InitiateLink (interface, peerAddress, receivingTime, beaconInterval);
-    peerLink->SetBeaconTimingElement (timingElement);
-    if (ShouldSendOpen (interface, peerAddress))
-      peerLink->MLMEActivePeerLinkOpen ();
-  }
+   //BCA:
+   PeerManagerPluginMap::iterator plugin = m_plugins.find (interface);
+   NS_ASSERT(plugin != m_plugins.end ());
+   plugin->second->SetBeaconShift(GetNextBeaconShift(interface));
+   //PM STATE Machine
+   Ptr<PeerLink> peerLink = FindPeerLink(interface, peerAddress);
+   if(peerLink !=0)  
+   {
+     peerLink->SetBeaconTimingElement (timingElement);
+     peerLink->SetBeaconInformation (receivingTime, beaconInterval);
+   }
+   else
+   {
+     peerLink = InitiateLink (interface, peerAddress, receivingTime, beaconInterval);
+     peerLink->SetBeaconTimingElement (timingElement);
+     if (ShouldSendOpen (interface, peerAddress))
+       peerLink->MLMEActivePeerLinkOpen ();
+   }
 }
 
 void
@@ -329,71 +344,61 @@
     }
   return true;
 }
-#if 0
 Time
-PeerManagerProtocol::GetNextBeaconShift (
-  Mac48Address interfaceAddress,
-  Time myNextTBTT
-)
+PeerManagerProtocol::GetNextBeaconShift (uint32_t interface)
 {
   //REMINDER:: in timing element  1) last beacon reception time is measured in units of 256 microseconds
   //                              2) beacon interval is mesured in units of 1024 microseconds
   //                              3) hereafter TU = 1024 microseconds
   //Im my MAC everything is stored in MicroSeconds
 
-  uint32_t myNextTBTTInTimeUnits = 0;
+  uint32_t myNextTbttInTimeUnits = 0;
   uint32_t futureBeaconInTimeUnits = 0;
   //Going through all my timing elements and detecting future beacon collisions
-  PeerLinksMap::iterator interface = m_peerLinks.find (interfaceAddress);
-  NS_ASSERT (interface != m_peerLinks.end());
-  BeaconInfoMap::iterator myBeacon = m_myBeaconInfo.find (interfaceAddress);
-  NS_ASSERT (myBeacon != m_myBeaconInfo.end());
-  for (PeerLinksOnInterface::iterator i = interface->second.begin (); i != interface->second.end(); i++)
+  PeerLinksMap::iterator iface = m_peerLinks.find (interface);
+  NS_ASSERT (iface != m_peerLinks.end());
+  PeerManagerPluginMap::iterator plugin = m_plugins.find (interface);
+  NS_ASSERT(plugin != m_plugins.end());
+  std::pair<Time, Time> myBeacon = plugin->second->GetBeaconInfo ();
+  for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
     {
       IeBeaconTiming::NeighboursTimingUnitsList neighbours;
       neighbours = (*i)->GetBeaconTimingElement ().GetNeighboursTimingElementsList();
-      //first let's form the list of all kown TBTTs
+      //first let's form the list of all kown Tbtts
       for (IeBeaconTiming::NeighboursTimingUnitsList::const_iterator j = neighbours.begin (); j != neighbours.end(); j++)
         {
           uint16_t beaconIntervalTimeUnits;
           beaconIntervalTimeUnits = (*j)->GetBeaconInterval ();
-
           //The last beacon time in timing elememt in Time Units
           uint32_t lastBeaconInTimeUnits;
           lastBeaconInTimeUnits = (*j)->GetLastBeacon ()/4;
-
           //The time of my next beacon sending in Time Units
-          myNextTBTTInTimeUnits = myNextTBTT.GetMicroSeconds ()/1024;
-
+          myNextTbttInTimeUnits = myBeacon.first.GetMicroSeconds ()/1024;
           //My beacon interval in Time Units
           uint32_t myBeaconIntervalInTimeUnits;
-          myBeaconIntervalInTimeUnits = myBeacon->second.beaconInterval.GetMicroSeconds ()/1024;
-
+          myBeaconIntervalInTimeUnits = myBeacon.second.GetMicroSeconds ()/1024;
           //The time the beacon of other station will be sent
-          //we need the time just after my next TBTT (or equal to my TBTT)
+          //we need the time just after my next Tbtt (or equal to my Tbtt)
           futureBeaconInTimeUnits = lastBeaconInTimeUnits + beaconIntervalTimeUnits;
-
           //We apply MBAC only if beacon Intervals are equal
           if (beaconIntervalTimeUnits == myBeaconIntervalInTimeUnits)
             {
               //We know when the neighbor STA transmitted it's beacon
               //Now we need to know when it's going to send it's beacon in the future
               //So let's use the valuse of it's beacon interval
-              while (myNextTBTTInTimeUnits >= futureBeaconInTimeUnits)
+              while (myNextTbttInTimeUnits >= futureBeaconInTimeUnits)
                 futureBeaconInTimeUnits = futureBeaconInTimeUnits + beaconIntervalTimeUnits;
-              //If we found that my TBTT coincide with another STA's TBTT
-              //break all cylce and return time shift for my next TBTT
-              if (myNextTBTTInTimeUnits == futureBeaconInTimeUnits)
+              //If we found that my Tbtt coincide with another STA's Tbtt
+              //break all cylce and return time shift for my next Tbtt
+              if (myNextTbttInTimeUnits == futureBeaconInTimeUnits)
                 break;
             }
-
         }
-      if (myNextTBTTInTimeUnits == futureBeaconInTimeUnits)
+      if (myNextTbttInTimeUnits == futureBeaconInTimeUnits)
         break;
     }
-
-  //TBTTs coincide, so let's calculate the shift
-  if (myNextTBTTInTimeUnits == futureBeaconInTimeUnits)
+  //Tbtts coincide, so let's calculate the shift
+  if (myNextTbttInTimeUnits == futureBeaconInTimeUnits)
     {
       NS_LOG_DEBUG ("MBCA: Future beacon collision is detected, applying avoidance mechanism");
       UniformVariable randomSign (-1, 1);
@@ -407,12 +412,10 @@
       //We need the result not in Time Units, but in microseconds
       return MicroSeconds (beaconShift * 1024);
     }
-  //No collision detecterf, hence no shift is needed
+  //No collision detected, hence no shift is needed
   else
     return MicroSeconds (0);
 }
-
-#endif
 void
 PeerManagerProtocol::PeerLinkStatus (uint32_t interface, Mac48Address peerAddress, bool status)
 {
--- a/src/devices/mesh/dot11s/peer-manager-protocol.h	Wed Mar 25 14:32:56 2009 +0300
+++ b/src/devices/mesh/dot11s/peer-manager-protocol.h	Wed Mar 25 16:12:01 2009 +0300
@@ -161,6 +161,8 @@
    * Removes all links which are idle
    */
   void  PeerCleanup ();
+  ///\brief BCA
+  Time GetNextBeaconShift (uint32_t interface);
 private:
   PeerManagerPluginMap m_plugins;
   /**
@@ -168,7 +170,6 @@
    * \{
    */
   BeaconInfoMap m_neighbourBeacons;
-  static const uint8_t m_maxBeaconLoss = 3;
   ///\}
   uint16_t m_lastAssocId;
   uint16_t m_lastLocalLinkId;