From e6ac62ac027310f1edf43122f8231dfd2c8b8bc4 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Tue, 16 Jun 2009 18:20:34 +0400 Subject: [PATCH] Fixed MBCA --- src/devices/mesh/dot11s/peer-link.cc | 9 +- .../mesh/dot11s/peer-management-protocol.cc | 93 +++++++------------ .../mesh/dot11s/peer-management-protocol.h | 7 ++ 3 files changed, 42 insertions(+), 67 deletions(-) diff --git a/src/devices/mesh/dot11s/peer-link.cc b/src/devices/mesh/dot11s/peer-link.cc index d77dcaf51..e6784e588 100644 --- a/src/devices/mesh/dot11s/peer-link.cc +++ b/src/devices/mesh/dot11s/peer-link.cc @@ -285,7 +285,7 @@ PeerLink::StateMachine (PeerEvent event,PmpReasonCode reasoncode) case CNCL: case CLS_ACPT: m_state = IDLE; - // TODO Callback MLME-SignalPeerLinkStatus + m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, false); break; case REQ_RJCT: SendPeerLinkClose (reasoncode); @@ -366,7 +366,6 @@ PeerLink::StateMachine (PeerEvent event,PmpReasonCode reasoncode) SendPeerLinkConfirm (); NS_ASSERT(m_peerMeshPointAddress != Mac48Address::GetBroadcast ()); m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, true); - // TODO Callback MLME-SignalPeerLinkStatus break; case CLS_ACPT: m_state = HOLDING; @@ -411,7 +410,6 @@ PeerLink::StateMachine (PeerEvent event,PmpReasonCode reasoncode) ClearRetryTimer (); NS_ASSERT(m_peerMeshPointAddress != Mac48Address::GetBroadcast ()); m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, true); - // TODO Callback MLME-SignalPeerLinkStatus break; case CLS_ACPT: m_state = HOLDING; @@ -454,7 +452,6 @@ PeerLink::StateMachine (PeerEvent event,PmpReasonCode reasoncode) m_state = HOLDING; SendPeerLinkClose (REASON11S_MESH_CLOSE_RCVD); SetHoldingTimer (); - m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, false); break; case OPN_RJCT: case CNF_RJCT: @@ -462,13 +459,11 @@ PeerLink::StateMachine (PeerEvent event,PmpReasonCode reasoncode) ClearRetryTimer (); SendPeerLinkClose (reasoncode); SetHoldingTimer (); - m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, false); break; case CNCL: m_state = HOLDING; SendPeerLinkClose (REASON11S_PEERING_CANCELLED); SetHoldingTimer (); - m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, false); break; default: //11B.5.3.8 of 802.11s Draft D3.0 @@ -483,7 +478,7 @@ PeerLink::StateMachine (PeerEvent event,PmpReasonCode reasoncode) ClearHoldingTimer (); case TOH: m_state = IDLE; - // TODO Callback MLME-SignalPeerLinkStatus + m_linkStatusCallback (m_interface, m_peerAddress, m_peerMeshPointAddress, false); break; case OPN_ACPT: case CNF_ACPT: diff --git a/src/devices/mesh/dot11s/peer-management-protocol.cc b/src/devices/mesh/dot11s/peer-management-protocol.cc index 6ad732cf4..e3c20a659 100644 --- a/src/devices/mesh/dot11s/peer-management-protocol.cc +++ b/src/devices/mesh/dot11s/peer-management-protocol.cc @@ -203,12 +203,12 @@ PeerManagementProtocol::UpdatePeerBeaconTiming( peerLink->SetBeaconInformation (receivingTime, beaconInterval); } else - { - peerLink = InitiateLink (interface, peerAddress, Mac48Address::GetBroadcast (), receivingTime, beaconInterval); - peerLink->SetBeaconTimingElement (timingElement); if (ShouldSendOpen (interface, peerAddress)) + { + peerLink = InitiateLink (interface, peerAddress, Mac48Address::GetBroadcast (), receivingTime, beaconInterval); + peerLink->SetBeaconTimingElement (timingElement); peerLink->MLMEActivePeerLinkOpen (); - } + } } void @@ -281,7 +281,7 @@ PeerManagementProtocol::InitiateLink ( //find a peer link - it must not exist if(FindPeerLink(interface, peerAddress) != 0) { - NS_FATAL_ERROR ("Peer link must not to exist."); + NS_FATAL_ERROR ("Peer link must not exist."); } // Plugin must exist PeerManagerPluginMap::iterator plugin = m_plugins.find (interface); @@ -368,76 +368,47 @@ PeerManagementProtocol::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 = Simulator::Now().GetMicroSeconds(); - uint32_t futureBeaconInTimeUnits = 0; - //Going through all my timing elements and detecting future beacon collisions 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()); + 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; + if((*i)->LinkIsIdle ()) + continue; neighbours = (*i)->GetBeaconTimingElement ().GetNeighboursTimingElementsList(); - //first let's form the list of all kown Tbtts + //Going through all my timing elements and detecting future beacon collisions 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 = myBeacon.first.GetMicroSeconds ()/1024; - //My beacon interval in Time Units - uint32_t myBeaconIntervalInTimeUnits; - 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) - futureBeaconInTimeUnits = lastBeaconInTimeUnits + beaconIntervalTimeUnits; //We apply MBAC only if beacon Intervals are equal - if (beaconIntervalTimeUnits == myBeaconIntervalInTimeUnits) + if ((*j)->GetBeaconInterval () == TimeToTu (myBeacon.second)) { - //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) - 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) - break; + //Apply MBCA if future beacons may coinside + if ((TimeToTu (myBeacon.first) - ((*j)->GetLastBeacon ()/4)) % ((*j)->GetBeaconInterval ()) == 0) + { + UniformVariable randomSign (-1, 1); + UniformVariable randomShift (1, 15); + //So, the shift is a random integer variable uniformly distributed in [-15;-1] U [1;15] + int beaconShift = randomShift.GetInteger (1,15) * ((randomSign.GetValue () >= 0) ? 1 : -1); + NS_LOG_DEBUG ("Apply MBCA: Shift value = " << beaconShift << " beacon TUs"); + //Do not shift to the past! + return (TuToTime (beaconShift) + Simulator::Now() < myBeacon.first) ? TuToTime (beaconShift) : TuToTime (0); + } } - } - if (myNextTbttInTimeUnits == futureBeaconInTimeUnits) - break; } - //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); - int coefficientSign = -1; - if (randomSign.GetValue () >= 0) - coefficientSign = 1; - UniformVariable randomShift (1, 15); - //So, the shift is a random integer variable uniformly distributed in [-15;-1] U [1;15] - int beaconShift = randomShift.GetInteger (1,15) * coefficientSign; - NS_LOG_DEBUG ("Shift value = " << beaconShift << " beacon TUs"); - //We need the result not in Time Units, but in microseconds - //Do not shift to the past - if(MicroSeconds(beaconShift * 1024) + Simulator::Now() < myBeacon.first) - return MicroSeconds (beaconShift * 1024); - else - return MicroSeconds (0); - } - //No collision detected, hence no shift is needed - else return MicroSeconds (0); } +Time +PeerManagementProtocol::TuToTime (uint32_t x) +{ + return MicroSeconds (x * 1024); +} +uint32_t +PeerManagementProtocol::TimeToTu (Time x) +{ + return (uint32_t) (x.GetMicroSeconds ()/1024); +} void PeerManagementProtocol::PeerLinkStatus (uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddress, bool status) { @@ -459,6 +430,8 @@ PeerManagementProtocol::PeerLinkStatus (uint32_t interface, Mac48Address peerAdd { m_stats.linksClosed ++; m_numberOfActivePeers --; + Ptr link = FindPeerLink (interface, peerAddress); + NS_ASSERT (link == 0); } if(!m_peerStatusCallback.IsNull ()) m_peerStatusCallback (peerMeshPointAddress, peerAddress, interface, status); diff --git a/src/devices/mesh/dot11s/peer-management-protocol.h b/src/devices/mesh/dot11s/peer-management-protocol.h index c250b20da..e8d44f2e3 100644 --- a/src/devices/mesh/dot11s/peer-management-protocol.h +++ b/src/devices/mesh/dot11s/peer-management-protocol.h @@ -192,6 +192,13 @@ private: void PeerLinkStatus (uint32_t interface, Mac48Address peerAddress, Mac48Address peerMeshPointAddres, bool status); ///\brief BCA Time GetNextBeaconShift (uint32_t interface); + /** + * \name Time<-->TU converters: + * \{ + */ + Time TuToTime (uint32_t x); + uint32_t TimeToTu (Time x); + ///\} private: PeerManagerPluginMap m_plugins; Mac48Address m_address;