View | Details | Raw Unified | Return to bug 1021
Collapse All | Expand All

(-)a/src/devices/mesh/dot11s/peer-management-protocol.cc (-27 / +55 lines)
 Lines 164-170    Link Here 
164
{
164
{
165
  //PM STATE Machine
165
  //PM STATE Machine
166
  //Check that a given beacon is not from our interface
166
  //Check that a given beacon is not from our interface
167
  Simulator::Schedule (beaconInterval - TuToTime (m_maxBeaconShift + 1), &PeerManagementProtocol::DoShiftBeacon, this, interface);
168
  for (PeerManagementProtocolMacMap::const_iterator i = m_plugins.begin (); i != m_plugins.end (); i++)
167
  for (PeerManagementProtocolMacMap::const_iterator i = m_plugins.begin (); i != m_plugins.end (); i++)
169
    {
168
    {
170
      if (i->second->GetAddress () == peerAddress)
169
      if (i->second->GetAddress () == peerAddress)
 Lines 180-185    Link Here 
180
          peerLink = InitiateLink (interface, peerAddress, Mac48Address::GetBroadcast ());
179
          peerLink = InitiateLink (interface, peerAddress, Mac48Address::GetBroadcast ());
181
          peerLink->MLMEActivePeerLinkOpen ();
180
          peerLink->MLMEActivePeerLinkOpen ();
182
        }
181
        }
182
      else
183
        {
184
          //PMP has cancelled new link and should not open it.
185
    	    return;
186
        }
183
    }
187
    }
184
  peerLink->SetBeaconInformation (Simulator::Now (), beaconInterval);
188
  peerLink->SetBeaconInformation (Simulator::Now (), beaconInterval);
185
  if (GetBeaconCollisionAvoidance ())
189
  if (GetBeaconCollisionAvoidance ())
 Lines 391-445    Link Here 
391
    {
395
    {
392
      return;
396
      return;
393
    }
397
    }
398
  //my last beacon in 256 us units
399
  uint16_t lastBeaconInTimeElement = (uint16_t) ((lastBeacon->second.GetMicroSeconds () >> 8) & 0xffff);
394
  if (TuToTime (m_maxBeaconShift) > m_beaconInterval[interface])
400
  if (TuToTime (m_maxBeaconShift) > m_beaconInterval[interface])
395
    {
401
    {
396
      NS_FATAL_ERROR ("Wrong beacon shift parameters");
402
      NS_FATAL_ERROR ("Wrong beacon shift parameters");
397
      return;
403
      return;
398
    }
404
    }
405
  //check whether we need to shift our beacon
406
  bool shiftIsNeeded = false;
407
408
  if (iface->second.size () == 0)
409
    {
410
      //I have no peers - may be our beacons are in collision
411
      shiftIsNeeded = true;
412
    }
413
  //check whether all my peers receive my beacon and I'am not in collision with other beacons
399
  for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
414
  for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end (); i++)
400
    {
415
    {
416
      bool isMyBeaconRec = false;
417
      bool isCollision = false;
401
      IeBeaconTiming::NeighboursTimingUnitsList neighbours;
418
      IeBeaconTiming::NeighboursTimingUnitsList neighbours;
402
      neighbours = (*i)->GetBeaconTimingElement ().GetNeighboursTimingElementsList ();
419
      neighbours = (*i)->GetBeaconTimingElement ().GetNeighboursTimingElementsList ();
403
      //Going through all my timing elements and detecting future beacon collisions
420
      for (IeBeaconTiming::NeighboursTimingUnitsList::const_iterator j = neighbours.begin (); j != neighbours.end (); j++)
404
      for (IeBeaconTiming::NeighboursTimingUnitsList::const_iterator j = neighbours.begin (); j
405
          != neighbours.end (); j++)
406
        {
421
        {
407
          if ((*i)->GetPeerAid () == (*j)->GetAid ())
422
          if ((*i)->GetPeerAid () == (*j)->GetAid ())
408
            {
423
            {
409
              // I am present at neighbour's list of neighbors
424
              // I am presented at neighbour's list of neighbors
425
              isMyBeaconRec = true;
410
              continue;
426
              continue;
411
            }
427
            }
412
          //Beacon interval is stored in TU's
428
          if (
413
          if (((*j)->GetBeaconInterval ()) != TimeToTu (beaconInterval->second))
429
              ((int16_t) ((*j)->GetLastBeacon () - lastBeaconInTimeElement) >= 0)
430
              && 
431
              (((*j)->GetLastBeacon () - lastBeaconInTimeElement) % (4 * TimeToTu (beaconInterval->second))== 0)
432
              )
414
            {
433
            {
415
              continue;
434
               isCollision=true;
416
            }
435
            }
417
          //Timing element keeps beacon receiving times in 256us units, TU=1024us
418
          if ((int) ((int)(*j)->GetLastBeacon () / 4 - (int)TimeToTu (lastBeacon->second)) % TimeToTu (
419
              beaconInterval->second)
420
              != 0)
421
            {
422
              continue;
423
            }
424
              int shift = 0;
425
              do
426
                {
427
                  shift = (int) beaconShift.GetValue ();
428
                }
429
              while (shift == 0);
430
              PeerManagementProtocolMacMap::iterator plugin = m_plugins.find (interface);
431
              NS_ASSERT (plugin != m_plugins.end ());
432
              plugin->second->SetBeaconShift (TuToTime (shift));
433
              return;
434
        }
436
        }
437
      // If I am not present in neighbor's beacon timing element, this may be caused vy collisions with
438
      // other beacons, and no peering link was established.
439
      if ((!isMyBeaconRec)||(isCollision))
440
        {
441
          shiftIsNeeded=true;
442
          break;
443
        }
444
     }
445
  // Now, shift beacon. The value is chosen randomly:
446
  if (!shiftIsNeeded)
447
    {
448
      return;
435
    }
449
    }
450
  int shift = 0;
451
  do
452
    {
453
      shift = (int) beaconShift.GetValue ();
454
    }
455
  while (shift == 0);
456
  // Apply beacon shift parameters:
457
  PeerManagementProtocolMacMap::iterator plugin = m_plugins.find (interface);
458
  NS_ASSERT (plugin != m_plugins.end ());
459
  plugin->second->SetBeaconShift (TuToTime (shift));
460
  return;
436
}
461
}
462
437
Time
463
Time
438
PeerManagementProtocol::TuToTime (uint32_t x)
464
PeerManagementProtocol::TuToTime (int x)
439
{
465
{
440
  return MicroSeconds (x * 1024);
466
  return MicroSeconds (x * 1024);
441
}
467
}
442
uint32_t
468
469
int
443
PeerManagementProtocol::TimeToTu (Time x)
470
PeerManagementProtocol::TimeToTu (Time x)
444
{
471
{
445
  return (uint32_t) (x.GetMicroSeconds () / 1024);
472
  return (uint32_t) (x.GetMicroSeconds () / 1024);
 Lines 519-524    Link Here 
519
PeerManagementProtocol::NotifyBeaconSent (uint32_t interface, Time beaconInterval)
546
PeerManagementProtocol::NotifyBeaconSent (uint32_t interface, Time beaconInterval)
520
{
547
{
521
  m_lastBeacon[interface] = Simulator::Now ();
548
  m_lastBeacon[interface] = Simulator::Now ();
549
  Simulator::Schedule(beaconInterval - TuToTime(m_maxBeaconShift + 1), &PeerManagementProtocol::DoShiftBeacon,this, interface);
522
  m_beaconInterval[interface] = beaconInterval;
550
  m_beaconInterval[interface] = beaconInterval;
523
}
551
}
524
PeerManagementProtocol::Statistics::Statistics (uint16_t t) :
552
PeerManagementProtocol::Statistics::Statistics (uint16_t t) :
(-)a/src/devices/mesh/dot11s/peer-management-protocol.h (-2 / +2 lines)
 Lines 198-205    Link Here 
198
   * \name Time<-->TU converters:
198
   * \name Time<-->TU converters:
199
   * \{
199
   * \{
200
   */
200
   */
201
  Time TuToTime (uint32_t x);
201
  Time TuToTime (int x);
202
  uint32_t TimeToTu (Time x);
202
  int TimeToTu (Time x);
203
  ///\}
203
  ///\}
204
  
204
  
205
  /// Aux. method to register open links
205
  /// Aux. method to register open links
(-)a/src/devices/mesh/mesh-wifi-interface-mac.cc (-1 lines)
 Lines 563-569    Link Here 
563
  NS_LOG_DEBUG (GetAddress () << " is sending beacon");
563
  NS_LOG_DEBUG (GetAddress () << " is sending beacon");
564
564
565
  NS_ASSERT (!m_beaconSendEvent.IsRunning ());
565
  NS_ASSERT (!m_beaconSendEvent.IsRunning ());
566
  NS_ASSERT (Simulator::Now ().GetMicroSeconds () == GetTbtt ().GetMicroSeconds ()); // assert that beacon is just on time
567
566
568
  // Form & send beacon
567
  // Form & send beacon
569
  MeshWifiBeacon beacon (GetSsid (), GetSupportedRates (), m_beaconInterval.GetMicroSeconds ());
568
  MeshWifiBeacon beacon (GetSsid (), GetSupportedRates (), m_beaconInterval.GetMicroSeconds ());

Return to bug 1021