Added a method to find peer link, code cleanup
This commit is contained in:
@@ -84,6 +84,7 @@ main (int argc, char *argv[])
|
||||
"LayoutType", StringValue ("RowFirst"));
|
||||
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
|
||||
mobility.Install (nodes);
|
||||
NS_LOG_UNCOND("start");
|
||||
#if 0
|
||||
// Setting Internet Stack:
|
||||
InternetStackHelper stack;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-beacon-timing.h"
|
||||
#include "ie-dot11s-beacon-timing.h"
|
||||
#include "ns3/log.h"
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-configuration.h"
|
||||
#include "ie-dot11s-configuration.h"
|
||||
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-peer-management.h"
|
||||
#include "ie-dot11s-peer-management.h"
|
||||
#include "ns3/assert.h"
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-perr.h"
|
||||
#include "ie-dot11s-perr.h"
|
||||
#include "ns3/address-utils.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-prep.h"
|
||||
#include "ie-dot11s-prep.h"
|
||||
#include "ns3/address-utils.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/assert.h"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-preq.h"
|
||||
#include "ie-dot11s-preq.h"
|
||||
#include "ns3/address-utils.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/assert.h"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "ns3/ie-dot11s-rann.h"
|
||||
#include "ie-dot11s-rann.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/address-utils.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Authors: Kirill Andreev <andreev@iitp.ru>
|
||||
*/
|
||||
|
||||
#include "ns3/peer-link-frame.h"
|
||||
#include "peer-link-frame.h"
|
||||
#include "ns3/mesh-wifi-interface-mac.h"
|
||||
namespace ns3 {
|
||||
namespace dot11s {
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#include "ie-dot11s-configuration.h"
|
||||
#include "ie-dot11s-peer-management.h"
|
||||
#include "peer-manager-plugin.h"
|
||||
#include "peer-link-frame.h"
|
||||
#include "ns3/mesh-wifi-mac-header.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/peer-link-frame.h"
|
||||
#include "ns3/wifi-mac-header.h"
|
||||
#include "ns3/mesh-wifi-mac-header.h"
|
||||
#include "ns3/log.h"
|
||||
@@ -51,6 +51,8 @@ PeerManagerMacPlugin::SetParent (Ptr<MeshWifiInterfaceMac> parent)
|
||||
bool
|
||||
PeerManagerMacPlugin::Receive (Ptr<Packet> const_packet, const WifiMacHeader & header)
|
||||
{
|
||||
/// First of all we copy a packet, because we need to remove some
|
||||
//headers
|
||||
Ptr<Packet> packet = const_packet->Copy();
|
||||
if(header.IsBeacon())
|
||||
{
|
||||
@@ -60,10 +62,7 @@ PeerManagerMacPlugin::Receive (Ptr<Packet> const_packet, const WifiMacHeader & h
|
||||
myBeacon->RemoveHeader(beacon_hdr);
|
||||
bool meshBeacon = false;
|
||||
if(beaconTiming.FindFirst(myBeacon))
|
||||
{
|
||||
NS_LOG_DEBUG("Beacon timing:"<<beaconTiming);
|
||||
meshBeacon = true;
|
||||
}
|
||||
m_protocol->UpdatePeerBeaconTiming(
|
||||
m_ifIndex,
|
||||
meshBeacon,
|
||||
@@ -72,20 +71,20 @@ PeerManagerMacPlugin::Receive (Ptr<Packet> const_packet, const WifiMacHeader & h
|
||||
Simulator::Now(),
|
||||
MicroSeconds(beacon_hdr.GetBeaconIntervalUs())
|
||||
);
|
||||
/// Beacon shall not be dropeed. May be needed to another plugins
|
||||
return true;
|
||||
}
|
||||
if(header.IsMultihopAction())
|
||||
{
|
||||
if (header.GetAddr1 () != m_parent->GetAddress ())
|
||||
return true;
|
||||
|
||||
WifiMeshHeader meshHdr;
|
||||
packet->RemoveHeader (meshHdr);
|
||||
WifiMeshMultihopActionHeader multihopHdr;
|
||||
//parse multihop action header:
|
||||
packet->RemoveHeader (multihopHdr);
|
||||
WifiMeshMultihopActionHeader::ACTION_VALUE actionValue = multihopHdr.GetAction ();
|
||||
/// If can not handle - just return;
|
||||
if(multihopHdr.GetCategory () != WifiMeshMultihopActionHeader::MESH_PEER_LINK_MGT)
|
||||
return false;
|
||||
return true;
|
||||
Mac48Address peerAddress = header.GetAddr2 ();
|
||||
PeerLinkFrameStart::PlinkFrameStartFields fields;
|
||||
{
|
||||
@@ -98,21 +97,25 @@ PeerManagerMacPlugin::Receive (Ptr<Packet> const_packet, const WifiMacHeader & h
|
||||
if(!(m_parent->CheckSupportedRates(fields.rates)))
|
||||
{
|
||||
m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress);
|
||||
return true;
|
||||
/// Broken peer link frame - drop it
|
||||
return false;
|
||||
}
|
||||
if (!fields.meshId.IsEqual(m_parent->GetSsid()))
|
||||
{
|
||||
m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress);
|
||||
/// Broken peer link frame - drop it
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//link management element:
|
||||
/// MeshConfiguration Element - exists in all peer link management
|
||||
/// frames except CLOSE
|
||||
IeConfiguration meshConfig;
|
||||
if(fields.subtype != IePeerManagement::PEER_CLOSE)
|
||||
packet->RemoveHeader(meshConfig);
|
||||
IePeerManagement peerElement;
|
||||
packet->RemoveHeader(peerElement);
|
||||
|
||||
/// Check the correspondance betwee action valuse and peer link
|
||||
/// management element subtypes:
|
||||
switch (actionValue.peerLink)
|
||||
{
|
||||
case WifiMeshMultihopActionHeader::PEER_LINK_CONFIRM:
|
||||
@@ -125,12 +128,15 @@ PeerManagerMacPlugin::Receive (Ptr<Packet> const_packet, const WifiMacHeader & h
|
||||
NS_ASSERT(fields.subtype == IePeerManagement::PEER_CLOSE);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
/// Protocol can not define which frame is it - pass further
|
||||
return true;
|
||||
}
|
||||
//Deliver Peer link management frame to protocol:
|
||||
m_protocol->ReceivePeerLinkFrame(m_ifIndex, peerAddress, fields.aid, peerElement, meshConfig);
|
||||
/// if we can handle a frame - drop it
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/mesh-wifi-interface-mac.h"
|
||||
#include "ns3/mesh-wifi-interface-mac-plugin.h"
|
||||
#include "ns3/peer-link.h"
|
||||
#include "peer-link.h"
|
||||
#include "peer-manager-plugin.h"
|
||||
|
||||
|
||||
@@ -74,25 +74,25 @@ PeerManagerProtocol::PeerManagerProtocol ():
|
||||
}
|
||||
PeerManagerProtocol::~PeerManagerProtocol ()
|
||||
{
|
||||
//cancel cleanup event and go through the map of peer links,
|
||||
//deleting each
|
||||
m_cleanupEvent.Cancel ();
|
||||
//TODO: delete a list of descriptors
|
||||
for (
|
||||
PeerLinksMap::iterator j = m_peerLinks.begin ();
|
||||
j != m_peerLinks.end ();
|
||||
j++)
|
||||
for (PeerLinksMap::iterator j = m_peerLinks.begin (); j != m_peerLinks.end (); j++)
|
||||
{
|
||||
int to_delete = 0;
|
||||
for (PeerLinksOnInterface::iterator i = j->second.begin (); i != j->second.end(); i++)
|
||||
{
|
||||
to_delete ++;
|
||||
(*i)->ClearTimingElement ();
|
||||
(*i) = 0;
|
||||
}
|
||||
for (int i = 0; i < to_delete; i ++)
|
||||
j->second.pop_back ();
|
||||
j->second.clear ();
|
||||
}
|
||||
m_peerLinks.clear ();
|
||||
//cleaning beacon structures:
|
||||
for(BeaconInfoMap::iterator i = m_neighbourBeacons.begin(); i != m_neighbourBeacons.end(); i ++)
|
||||
{
|
||||
i->second.clear();
|
||||
}
|
||||
m_neighbourBeacons.clear();
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -174,23 +174,18 @@ PeerManagerProtocol::UpdatePeerBeaconTiming(
|
||||
if(!meshBeacon)
|
||||
return;
|
||||
//PM STATE Machine
|
||||
Ptr<PeerLink> peerLink = FindPeerLink(interface, peerAddress);
|
||||
if(peerLink !=0)
|
||||
{
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++){
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
{
|
||||
(*i)->SetBeaconTimingElement (timingElement);
|
||||
(*i)->SetBeaconInformation (receivingTime, beaconInterval);
|
||||
return;
|
||||
}
|
||||
}
|
||||
PeerManagerPluginMap::iterator plugin = m_plugins.find (interface);
|
||||
NS_ASSERT(plugin != m_plugins.end());
|
||||
Ptr<PeerLink> new_link = InitiateLink (interface, peerAddress, receivingTime, beaconInterval);
|
||||
new_link->SetBeaconTimingElement (timingElement);
|
||||
if (ShouldSendOpen (interface, peerAddress))
|
||||
new_link->MLMEActivePeerLinkOpen ();
|
||||
peerLink->SetBeaconTimingElement (timingElement);
|
||||
peerLink->SetBeaconInformation (receivingTime, beaconInterval);
|
||||
}
|
||||
else
|
||||
{
|
||||
peerLink = InitiateLink (interface, peerAddress, receivingTime, beaconInterval);
|
||||
peerLink->SetBeaconTimingElement (timingElement);
|
||||
if (ShouldSendOpen (interface, peerAddress))
|
||||
peerLink->MLMEActivePeerLinkOpen ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,81 +198,39 @@ PeerManagerProtocol::ReceivePeerLinkFrame (
|
||||
IeConfiguration meshConfig
|
||||
)
|
||||
{
|
||||
Ptr<PeerLink> peerLink = FindPeerLink(interface, peerAddress);
|
||||
if (peerManagementElement.SubtypeIsOpen ())
|
||||
{
|
||||
dot11sReasonCode reasonCode;
|
||||
bool reject = ! (ShouldAcceptOpen (interface, peerAddress,reasonCode));
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++)
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
{
|
||||
if(!reject)
|
||||
{
|
||||
//Drop from INIT state:
|
||||
//(*i)->MLMEPassivePeerLinkOpen ();
|
||||
(*i)->OpenAccept (peerManagementElement.GetLocalLinkId(), meshConfig);
|
||||
}
|
||||
else
|
||||
(*i)->OpenReject (peerManagementElement.GetLocalLinkId(), meshConfig, reasonCode);
|
||||
return;
|
||||
}
|
||||
Ptr<PeerLink> new_link = InitiateLink (
|
||||
interface,
|
||||
peerAddress,
|
||||
Simulator::Now (),
|
||||
Seconds(1.0)
|
||||
);
|
||||
if (peerLink == 0)
|
||||
peerLink = InitiateLink (interface, peerAddress, Simulator::Now (), Seconds(1.0));
|
||||
if(!reject)
|
||||
{
|
||||
//Drop from INIT state:
|
||||
new_link->MLMEPassivePeerLinkOpen ();
|
||||
new_link->OpenAccept (peerManagementElement.GetLocalLinkId(), meshConfig);
|
||||
peerLink->MLMEPassivePeerLinkOpen ();
|
||||
peerLink->OpenAccept (peerManagementElement.GetLocalLinkId(), meshConfig);
|
||||
}
|
||||
else
|
||||
new_link->OpenReject (peerManagementElement.GetLocalLinkId(), meshConfig, reasonCode);
|
||||
return;
|
||||
peerLink->OpenReject (peerManagementElement.GetLocalLinkId(), meshConfig, reasonCode);
|
||||
}
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++)
|
||||
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
{
|
||||
if(peerManagementElement.SubtypeIsConfirm ())
|
||||
{
|
||||
(*i)->ConfirmAccept (peerManagementElement.GetLocalLinkId(), peerManagementElement.GetPeerLinkId(), aid, meshConfig);
|
||||
return;
|
||||
}
|
||||
if(peerManagementElement.SubtypeIsClose ())
|
||||
{
|
||||
(*i)->Close (
|
||||
peerManagementElement.GetLocalLinkId(),
|
||||
peerManagementElement.GetPeerLinkId(),
|
||||
peerManagementElement.GetReasonCode());
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
NS_ASSERT (false);
|
||||
if (peerLink == 0)
|
||||
return;
|
||||
if (peerManagementElement.SubtypeIsConfirm ())
|
||||
peerLink->ConfirmAccept (peerManagementElement.GetLocalLinkId(), peerManagementElement.GetPeerLinkId(), aid, meshConfig);
|
||||
if (peerManagementElement.SubtypeIsClose ())
|
||||
peerLink->Close (
|
||||
peerManagementElement.GetLocalLinkId(),
|
||||
peerManagementElement.GetPeerLinkId(),
|
||||
peerManagementElement.GetReasonCode()
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
PeerManagerProtocol::ConfigurationMismatch (
|
||||
uint32_t interface,
|
||||
Mac48Address peerAddress
|
||||
)
|
||||
PeerManagerProtocol::ConfigurationMismatch (uint32_t interface, Mac48Address peerAddress)
|
||||
{
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++)
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
{
|
||||
(*i)->MLMECancelPeerLink (REASON11S_MESH_CONFIGURATION_POLICY_VIOLATION);
|
||||
return;
|
||||
}
|
||||
Ptr<PeerLink> peerLink = FindPeerLink(interface, peerAddress);
|
||||
if(peerLink != 0)
|
||||
peerLink->MLMECancelPeerLink (REASON11S_MESH_CONFIGURATION_POLICY_VIOLATION);
|
||||
}
|
||||
|
||||
Ptr<PeerLink>
|
||||
@@ -297,19 +250,13 @@ PeerManagerProtocol::InitiateLink (
|
||||
BeaconsOnInterface::iterator beacon = beaconsOnInterface->second.find (peerAddress);
|
||||
if(beacon == beaconsOnInterface->second.end ())
|
||||
FillBeaconInfo(interface, peerAddress, lastBeacon, beaconInterval);
|
||||
//find a peer link
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++)
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
{
|
||||
NS_ASSERT(false);
|
||||
return (*i);
|
||||
}
|
||||
|
||||
//find a peer link - it must not exist
|
||||
NS_ASSERT(FindPeerLink(interface, peerAddress) == 0);
|
||||
/// Plugin must exust
|
||||
PeerManagerPluginMap::iterator plugin = m_plugins.find (interface);
|
||||
NS_ASSERT(plugin != m_plugins.end ());
|
||||
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
new_link->SetLocalAid (beacon->second.aid);
|
||||
new_link->SetInterface (interface);
|
||||
new_link->SetLocalLinkId (m_lastLocalLinkId++);
|
||||
@@ -320,6 +267,16 @@ PeerManagerProtocol::InitiateLink (
|
||||
iface->second.push_back (new_link);
|
||||
return new_link;
|
||||
}
|
||||
Ptr<PeerLink>
|
||||
PeerManagerProtocol::FindPeerLink(uint32_t interface, Mac48Address peerAddress)
|
||||
{
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++)
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
return (*i);
|
||||
return 0;
|
||||
}
|
||||
void
|
||||
PeerManagerProtocol::PeerCleanup ()
|
||||
{
|
||||
@@ -343,16 +300,16 @@ PeerManagerProtocol::PeerCleanup ()
|
||||
j->second.erase (j->second.begin() + to_erase[i]);
|
||||
to_erase.clear ();
|
||||
}
|
||||
// cleanup neighbour beacons:
|
||||
//NS_ASSERT(false);
|
||||
m_cleanupEvent = Simulator::Schedule (m_peerLinkCleanupPeriod, &PeerManagerProtocol::PeerCleanup, this);
|
||||
}
|
||||
bool
|
||||
PeerManagerProtocol::IsActiveLink (uint32_t interface, Mac48Address peerAddress)
|
||||
{
|
||||
PeerLinksMap::iterator iface = m_peerLinks.find (interface);
|
||||
NS_ASSERT (iface != m_peerLinks.end());
|
||||
for (PeerLinksOnInterface::iterator i = iface->second.begin (); i != iface->second.end(); i++)
|
||||
if ((*i)->GetPeerAddress () == peerAddress)
|
||||
return ((*i)->LinkIsEstab ());
|
||||
Ptr<PeerLink> peerLink = FindPeerLink(interface, peerAddress);
|
||||
if(peerLink != 0)
|
||||
return (peerLink->LinkIsEstab ());
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
@@ -460,7 +417,6 @@ void
|
||||
PeerManagerProtocol::PeerLinkStatus (uint32_t interface, Mac48Address peerAddress, bool status)
|
||||
{
|
||||
PeerManagerPluginMap::iterator plugin = m_plugins.find (interface);
|
||||
NS_LOG_UNCOND(interface);
|
||||
NS_ASSERT(plugin != m_plugins.end());
|
||||
NS_LOG_UNCOND("LINK between me:"<<plugin->second->GetAddress() <<" and peer:"<<peerAddress<<", at interface "<<interface);
|
||||
if(status)
|
||||
|
||||
@@ -111,9 +111,9 @@ public:
|
||||
* Checks if there is established link
|
||||
*/
|
||||
bool IsActiveLink (uint32_t interface, Mac48Address peerAddress);
|
||||
/**
|
||||
* \}
|
||||
*/
|
||||
///\}
|
||||
///\brief Needed by external module to do MLME
|
||||
Ptr<PeerLink> FindPeerLink(uint32_t interface, Mac48Address peerAddress);
|
||||
private:
|
||||
///\name Private structures
|
||||
///\{
|
||||
|
||||
@@ -488,6 +488,8 @@ void
|
||||
MeshWifiInterfaceMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
|
||||
{
|
||||
// Process beacon
|
||||
if((hdr->GetAddr1() != GetAddress()) && (hdr->GetAddr1() != Mac48Address::GetBroadcast()))
|
||||
return;
|
||||
if (hdr->IsBeacon ())
|
||||
{
|
||||
MgtBeaconHeader beacon_hdr;
|
||||
|
||||
@@ -26,13 +26,10 @@
|
||||
#include <map>
|
||||
#include "ns3/mac48-address.h"
|
||||
#include "ns3/mgt-headers.h"
|
||||
//#include "ns3/mesh-mgt-headers.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/ie-dot11s-beacon-timing.h"
|
||||
#include "ns3/wifi-remote-station-manager.h"
|
||||
//#include "ns3/mesh-wifi-peer-manager.h"
|
||||
#include "ns3/wifi-mac.h"
|
||||
#include "ns3/mesh-wifi-interface-mac-plugin.h"
|
||||
#include "ns3/event-id.h"
|
||||
|
||||
@@ -56,7 +56,7 @@ def build(bld):
|
||||
'wifi-mode.h',
|
||||
'ssid.h',
|
||||
'wifi-preamble.h',
|
||||
'wifi-phy-standard.h',
|
||||
'wifi-phy-standard.h',
|
||||
'yans-wifi-phy.h',
|
||||
'yans-wifi-channel.h',
|
||||
'wifi-phy.h',
|
||||
|
||||
Reference in New Issue
Block a user