src/devices/mesh/mesh-wifi-interface-mac.cc
changeset 5125 b90c6c0af6a3
parent 5123 bdd3ae2a9816
child 5126 8e06088a785d
equal deleted inserted replaced
5124:e206046b2e44 5125:b90c6c0af6a3
   188 MeshWifiInterfaceMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
   188 MeshWifiInterfaceMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
   189 {
   189 {
   190   NS_LOG_FUNCTION (this << stationManager);
   190   NS_LOG_FUNCTION (this << stationManager);
   191   m_stationManager = stationManager;
   191   m_stationManager = stationManager;
   192   for (Queues::const_iterator i = m_queues.begin (); i != m_queues.end (); i ++)
   192   for (Queues::const_iterator i = m_queues.begin (); i != m_queues.end (); i ++)
       
   193   {
   193     i->second->SetWifiRemoteStationManager (stationManager);
   194     i->second->SetWifiRemoteStationManager (stationManager);
       
   195   }
   194   m_beaconDca->SetWifiRemoteStationManager (stationManager);
   196   m_beaconDca->SetWifiRemoteStationManager (stationManager);
   195   m_low->SetWifiRemoteStationManager (stationManager);
   197   m_low->SetWifiRemoteStationManager (stationManager);
   196 }
   198 }
   197 
   199 
   198 void
   200 void
   308   NS_LOG_FUNCTION (this);
   310   NS_LOG_FUNCTION (this);
   309   NS_ASSERT (m_phy != 0); // need PHY to set/get channel
   311   NS_ASSERT (m_phy != 0); // need PHY to set/get channel
   310 
   312 
   311   Ptr<YansWifiPhy> phy = m_phy->GetObject<YansWifiPhy> ();
   313   Ptr<YansWifiPhy> phy = m_phy->GetObject<YansWifiPhy> ();
   312   if (phy != 0)
   314   if (phy != 0)
   313     return phy->GetChannelNumber ();
   315     {
       
   316       return phy->GetChannelNumber ();
       
   317     }
   314   else
   318   else
   315     return 0;
   319     {
       
   320       return 0;
       
   321     }
   316 }
   322 }
   317 
   323 
   318 void MeshWifiInterfaceMac::SwitchFrequencyChannel (uint16_t new_id)
   324 void MeshWifiInterfaceMac::SwitchFrequencyChannel (uint16_t new_id)
   319 {
   325 {
   320   NS_LOG_FUNCTION (this);
   326   NS_LOG_FUNCTION (this);
   369 
   375 
   370   // Filter packet through all installed plugins
   376   // Filter packet through all installed plugins
   371   for (PluginList::const_iterator i = m_plugins.end()-1; i != m_plugins.begin()-1; i--)
   377   for (PluginList::const_iterator i = m_plugins.end()-1; i != m_plugins.begin()-1; i--)
   372     {
   378     {
   373       bool drop = ! ((*i)->UpdateOutcomingFrame(packet, hdr, from, to));
   379       bool drop = ! ((*i)->UpdateOutcomingFrame(packet, hdr, from, to));
   374       if (drop) return; // plugin drops frame
   380       if (drop)
       
   381         {
       
   382           return; // plugin drops frame
       
   383         }
   375     }
   384     }
   376 
   385 
   377   // Assert that address1 is set. Assert will fail e.g. if there is no installed routing plugin.
   386   // Assert that address1 is set. Assert will fail e.g. if there is no installed routing plugin.
   378   NS_ASSERT (hdr.GetAddr1() != Mac48Address() );
   387   NS_ASSERT (hdr.GetAddr1() != Mac48Address() );
   379 
   388 
   392     }
   401     }
   393   //Classify: application sets a tag, which is removed here
   402   //Classify: application sets a tag, which is removed here
   394   // Get Qos tag:
   403   // Get Qos tag:
   395   AccessClass ac = AC_BE;
   404   AccessClass ac = AC_BE;
   396   QosTag tag;
   405   QosTag tag;
   397   if(packet->RemovePacketTag (tag))
   406   if (packet->RemovePacketTag (tag))
   398     ac = QosUtilsMapTidToAc (tag.Get ());
   407     {
       
   408       ac = QosUtilsMapTidToAc (tag.Get ());
       
   409     }
   399   m_stats.sentFrames ++;
   410   m_stats.sentFrames ++;
   400   m_stats.sentBytes += packet->GetSize ();
   411   m_stats.sentBytes += packet->GetSize ();
   401   NS_ASSERT(m_queues.find(ac) != m_queues.end ());
   412   NS_ASSERT(m_queues.find(ac) != m_queues.end ());
   402   m_queues[ac]->Queue (packet, hdr);
   413   m_queues[ac]->Queue (packet, hdr);
   403 }
   414 }
   408   //Filter management frames:
   419   //Filter management frames:
   409   WifiMacHeader header = hdr;
   420   WifiMacHeader header = hdr;
   410   for (PluginList::const_iterator i = m_plugins.end()-1; i != m_plugins.begin()-1; i--)
   421   for (PluginList::const_iterator i = m_plugins.end()-1; i != m_plugins.begin()-1; i--)
   411     {
   422     {
   412       bool drop = ! ((*i)->UpdateOutcomingFrame(packet, header, Mac48Address (), Mac48Address ()));
   423       bool drop = ! ((*i)->UpdateOutcomingFrame(packet, header, Mac48Address (), Mac48Address ()));
   413       if (drop) return; // plugin drops frame
   424       if (drop)
       
   425         {
       
   426           return; // plugin drops frame
       
   427         }
   414     }
   428     }
   415   m_stats.sentFrames ++;
   429   m_stats.sentFrames ++;
   416   m_stats.sentBytes += packet->GetSize ();
   430   m_stats.sentBytes += packet->GetSize ();
   417   Queues::iterator i = m_queues.find (AC_VO);
   431   Queues::iterator i = m_queues.find (AC_VO);
   418   if (i == m_queues.end ())
   432   if (i == m_queues.end ())
   446 {
   460 {
   447   for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++)
   461   for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++)
   448   {
   462   {
   449     WifiMode mode = m_stationManager->GetBasicMode (i);
   463     WifiMode mode = m_stationManager->GetBasicMode (i);
   450     if (!rates.IsSupportedRate (mode.GetDataRate ()))
   464     if (!rates.IsSupportedRate (mode.GetDataRate ()))
   451       return false;
   465       {
       
   466         return false;
       
   467       }
   452   }
   468   }
   453   return true;
   469   return true;
   454 }
   470 }
   455 
   471 
   456 //-----------------------------------------------------------------------------
   472 //-----------------------------------------------------------------------------
   488 
   504 
   489       m_beaconSendEvent = Simulator::Schedule (randomStart, &MeshWifiInterfaceMac::SendBeacon, this);
   505       m_beaconSendEvent = Simulator::Schedule (randomStart, &MeshWifiInterfaceMac::SendBeacon, this);
   490       m_tbtt = Simulator::Now() + randomStart;
   506       m_tbtt = Simulator::Now() + randomStart;
   491     }
   507     }
   492   else
   508   else
   493     // stop sending beacons
   509     {
   494     m_beaconSendEvent.Cancel ();
   510       // stop sending beacons
       
   511       m_beaconSendEvent.Cancel ();
       
   512     }
   495 }
   513 }
   496 
   514 
   497 bool
   515 bool
   498 MeshWifiInterfaceMac::GetBeaconGeneration () const
   516 MeshWifiInterfaceMac::GetBeaconGeneration () const
   499 {
   517 {
   536   // Form & send beacon
   554   // Form & send beacon
   537   MeshWifiBeacon beacon (GetSsid (), GetSupportedRates (), m_beaconInterval.GetMicroSeconds ());
   555   MeshWifiBeacon beacon (GetSsid (), GetSupportedRates (), m_beaconInterval.GetMicroSeconds ());
   538 
   556 
   539   // Ask all plugins to add their specific information elements to beacon
   557   // Ask all plugins to add their specific information elements to beacon
   540   for (PluginList::const_iterator i = m_plugins.begin(); i != m_plugins.end(); ++i)
   558   for (PluginList::const_iterator i = m_plugins.begin(); i != m_plugins.end(); ++i)
   541     (*i)->UpdateBeacon (beacon);
   559     {
   542 
   560       (*i)->UpdateBeacon (beacon);
       
   561     }
   543   m_beaconDca->Queue (beacon.CreatePacket(), beacon.CreateHeader(GetAddress (), GetMeshPointAddress ()));
   562   m_beaconDca->Queue (beacon.CreatePacket(), beacon.CreateHeader(GetAddress (), GetMeshPointAddress ()));
   544 
   563 
   545   ScheduleNextBeacon ();
   564   ScheduleNextBeacon ();
   546 }
   565 }
   547 
   566 
   548 void
   567 void
   549 MeshWifiInterfaceMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
   568 MeshWifiInterfaceMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
   550 {
   569 {
   551   // Process beacon
   570   // Process beacon
   552   if((hdr->GetAddr1() != GetAddress()) && (hdr->GetAddr1() != Mac48Address::GetBroadcast()))
   571   if ((hdr->GetAddr1() != GetAddress()) && (hdr->GetAddr1() != Mac48Address::GetBroadcast()))
   553     return;
   572     {
       
   573       return;
       
   574     }
   554   if (hdr->IsBeacon ())
   575   if (hdr->IsBeacon ())
   555     {
   576     {
   556       m_stats.recvBeacons ++;
   577       m_stats.recvBeacons ++;
   557       MgtBeaconHeader beacon_hdr;
   578       MgtBeaconHeader beacon_hdr;
   558       Mac48Address from = hdr->GetAddr2 ();
   579       Mac48Address from = hdr->GetAddr2 ();
   575             WifiMode mode = m_phy->GetMode (i);
   596             WifiMode mode = m_phy->GetMode (i);
   576             if (rates.IsSupportedRate (mode.GetDataRate ()))
   597             if (rates.IsSupportedRate (mode.GetDataRate ()))
   577               {
   598               {
   578                 peerSta->AddSupportedMode (mode);
   599                 peerSta->AddSupportedMode (mode);
   579                 if (rates.IsBasicRate (mode.GetDataRate ()))
   600                 if (rates.IsBasicRate (mode.GetDataRate ()))
   580                   m_stationManager->AddBasicMode (mode);
   601                   {
       
   602                     m_stationManager->AddBasicMode (mode);
       
   603                   }
   581               }
   604               }
   582           }
   605           }
   583         }
   606         }
   584     }
   607     }
   585   else
   608   else
   589   }
   612   }
   590   // Filter frame through all installed plugins
   613   // Filter frame through all installed plugins
   591   for (PluginList::iterator i = m_plugins.begin (); i != m_plugins.end(); ++i)
   614   for (PluginList::iterator i = m_plugins.begin (); i != m_plugins.end(); ++i)
   592     {
   615     {
   593       bool drop = ! ((*i)->Receive(packet, *hdr));
   616       bool drop = ! ((*i)->Receive(packet, *hdr));
   594       if (drop) return; // plugin drops frame
   617       if (drop)
       
   618         {
       
   619           return; // plugin drops frame
       
   620         }
   595     }
   621     }
   596 
   622 
   597   // Check if QoS tag exists and add it:
   623   // Check if QoS tag exists and add it:
   598   if (hdr->IsQosData ())
   624   if (hdr->IsQosData ())
   599     packet->AddPacketTag (QosTag (hdr->GetQosTid ()));
   625     {
       
   626       packet->AddPacketTag (QosTag (hdr->GetQosTid ()));
       
   627     }
   600   // Forward data up
   628   // Forward data up
   601   if (hdr->IsData ())
   629   if (hdr->IsData ())
       
   630     {
   602       ForwardUp (packet, hdr->GetAddr4(), hdr->GetAddr3());
   631       ForwardUp (packet, hdr->GetAddr4(), hdr->GetAddr3());
       
   632     }
   603 }
   633 }
   604 
   634 
   605 uint32_t
   635 uint32_t
   606 MeshWifiInterfaceMac::GetLinkMetric (Mac48Address peerAddress)
   636 MeshWifiInterfaceMac::GetLinkMetric (Mac48Address peerAddress)
   607 {
   637 {
   608   uint32_t metric = 1;
   638   uint32_t metric = 1;
   609   if(!m_linkMetricCallback.IsNull ())
   639   if (!m_linkMetricCallback.IsNull ())
   610     metric = m_linkMetricCallback(peerAddress, this);
   640     {
       
   641       metric = m_linkMetricCallback(peerAddress, this);
       
   642     }
   611   return metric;
   643   return metric;
   612 }
   644 }
   613 
   645 
   614 void
   646 void
   615 MeshWifiInterfaceMac::SetLinkMetricCallback (Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > cb)
   647 MeshWifiInterfaceMac::SetLinkMetricCallback (Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > cb)
   663 }
   695 }
   664 void
   696 void
   665 MeshWifiInterfaceMac::SetQueue (Ptr<DcaTxop> queue, AccessClass ac)
   697 MeshWifiInterfaceMac::SetQueue (Ptr<DcaTxop> queue, AccessClass ac)
   666 {
   698 {
   667   Queues::iterator i = m_queues.find(ac);
   699   Queues::iterator i = m_queues.find(ac);
   668   if(i != m_queues.end ())
   700   if (i != m_queues.end ())
   669   {
   701   {
   670     NS_LOG_WARN("Queue is already set!");
   702     NS_LOG_WARN("Queue is already set!");
   671     return;
   703     return;
   672   }
   704   }
   673   m_queues.insert (std::make_pair(ac, queue));
   705   m_queues.insert (std::make_pair(ac, queue));
   675   m_queues[ac]->SetManager (m_dcfManager);
   707   m_queues[ac]->SetManager (m_dcfManager);
   676 }
   708 }
   677 Ptr<DcaTxop>
   709 Ptr<DcaTxop>
   678 MeshWifiInterfaceMac::GetQueue (AccessClass ac)
   710 MeshWifiInterfaceMac::GetQueue (AccessClass ac)
   679 {
   711 {
   680   Queues::iterator i = m_queues.find(ac);
   712   Queues::iterator i = m_queues.find (ac);
   681   if(i != m_queues.end ())
   713   if(i != m_queues.end ())
   682   {
   714   {
   683     NS_LOG_WARN("Queue is not found! Check access class!");
   715     NS_LOG_WARN("Queue is not found! Check access class!");
   684     return 0;
   716     return 0;
   685   }
   717   }