From 359cc256d70278b375d2bb8a9d987e7be835e172 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Wed, 25 Mar 2009 16:12:01 +0300 Subject: [PATCH] BCA works again --- .../mesh/dot11s/peer-manager-plugin.cc | 17 ++- src/devices/mesh/dot11s/peer-manager-plugin.h | 11 +- .../mesh/dot11s/peer-manager-protocol.cc | 113 +++++++++--------- .../mesh/dot11s/peer-manager-protocol.h | 3 +- 4 files changed, 85 insertions(+), 59 deletions(-) diff --git a/src/devices/mesh/dot11s/peer-manager-plugin.cc b/src/devices/mesh/dot11s/peer-manager-plugin.cc index 9790248cc..ebabcdf06 100644 --- a/src/devices/mesh/dot11s/peer-manager-plugin.cc +++ b/src/devices/mesh/dot11s/peer-manager-plugin.cc @@ -142,7 +142,7 @@ PeerManagerMacPlugin::Receive (Ptr const_packet, const WifiMacHeader & h bool PeerManagerMacPlugin::UpdateOutcomingFrame (Ptr packet, WifiMacHeader & header, Mac48Address from, Mac48Address to) const { - return false; + return true; } void @@ -216,7 +216,20 @@ PeerManagerMacPlugin::GetAddress () const return m_parent->GetAddress (); else return Mac48Address::Mac48Address(); } - +std::pair +PeerManagerMacPlugin::GetBeaconInfo() const +{ + std::pair 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 diff --git a/src/devices/mesh/dot11s/peer-manager-plugin.h b/src/devices/mesh/dot11s/peer-manager-plugin.h index 91ac68841..81e10066f 100644 --- a/src/devices/mesh/dot11s/peer-manager-plugin.h +++ b/src/devices/mesh/dot11s/peer-manager-plugin.h @@ -53,7 +53,16 @@ public: ///\} 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 GetBeaconInfo() const; + void SetBeaconShift(Time shift); + ///\} void SetPeerManagerProtcol(Ptr protocol); void SendPeerLinkManagementFrame( Mac48Address peerAddress, diff --git a/src/devices/mesh/dot11s/peer-manager-protocol.cc b/src/devices/mesh/dot11s/peer-manager-protocol.cc index 86b39c81c..f37d54d2e 100644 --- a/src/devices/mesh/dot11s/peer-manager-protocol.cc +++ b/src/devices/mesh/dot11s/peer-manager-protocol.cc @@ -119,18 +119,29 @@ PeerManagerProtocol::GetBeaconTimingElement(uint32_t interface) 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; - retval->AddNeighboursTimingElementUnit(j->second.aid, j->second.referenceTbtt, j->second.beaconInterval); + 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 @@ PeerManagerProtocol::UpdatePeerBeaconTiming( FillBeaconInfo(interface, peerAddress, receivingTime, beaconInterval); if(!meshBeacon) return; - //PM STATE Machine - Ptr 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 = 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 @@ PeerManagerProtocol::ShouldAcceptOpen (uint32_t interface, Mac48Address peerAddr } 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 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 @@ PeerManagerProtocol::GetNextBeaconShift ( //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) { diff --git a/src/devices/mesh/dot11s/peer-manager-protocol.h b/src/devices/mesh/dot11s/peer-manager-protocol.h index d9576ad04..1c28e2484 100644 --- a/src/devices/mesh/dot11s/peer-manager-protocol.h +++ b/src/devices/mesh/dot11s/peer-manager-protocol.h @@ -161,6 +161,8 @@ private: * Removes all links which are idle */ void PeerCleanup (); + ///\brief BCA + Time GetNextBeaconShift (uint32_t interface); private: PeerManagerPluginMap m_plugins; /** @@ -168,7 +170,6 @@ private: * \{ */ BeaconInfoMap m_neighbourBeacons; - static const uint8_t m_maxBeaconLoss = 3; ///\} uint16_t m_lastAssocId; uint16_t m_lastLocalLinkId;