First management frame goes through new archotecture

This commit is contained in:
Kirill Andreev
2009-03-22 17:05:45 +03:00
parent 58bd437f81
commit 149a32afe2
8 changed files with 291 additions and 256 deletions

View File

@@ -34,13 +34,12 @@ namespace ns3 {
class IeDot11sPeerManagement : public WifiInformationElement
{
public:
enum Subtype {
PEER_OPEN = 0,
PEER_CLOSE = 1,
PEER_CONFIRM = 2,
};
IeDot11sPeerManagement ();
IeDot11sPeerManagement ();
enum Subtype {
PEER_OPEN = 0,
PEER_CLOSE = 1,
PEER_CONFIRM = 2,
};
void SetPeerOpen (uint16_t localLinkId);
void SetPeerClose (uint16_t localLinkID, uint16_t peerLinkId, dot11sReasonCode reasonCode);
void SetPeerConfirm (uint16_t localLinkID, uint16_t peerLinkId);
@@ -51,6 +50,7 @@ public:
bool SubtypeIsOpen () const;
bool SubtypeIsClose () const;
bool SubtypeIsConfirm () const ;
uint8_t GetSubtype() const { return m_subtype;};
private:
WifiElementId ElementId () const{
return IE11S_PEER_LINK_MANAGEMENT;
@@ -59,6 +59,7 @@ private:
void SerializeInformation (Buffer::Iterator i) const;
uint8_t DeserializeInformation (Buffer::Iterator i, uint8_t length);
void PrintInformation (std::ostream& os) const;
private:
uint8_t m_length;
uint8_t m_subtype;
uint16_t m_localLinkId;

View File

@@ -25,7 +25,7 @@ NS_OBJECT_ENSURE_REGISTERED (PeerLinkFrameStart);
PeerLinkFrameStart::PeerLinkFrameStart ()
{
m_fields.subtype = PEER_LINK_OPEN;
m_fields.subtype = IeDot11sPeerManagement::PEER_OPEN;
m_fields.aid = 0;
m_fields.rates = SupportedRates();
m_fields.meshId = Ssid();
@@ -37,7 +37,7 @@ PeerLinkFrameStart::SetPlinkFrameStart(PeerLinkFrameStart::PlinkFrameStartFields
}
PeerLinkFrameStart::PlinkFrameStartFields
PeerLinkFrameStart::GetPlinkFrameStart ()
PeerLinkFrameStart::GetFields ()
{
return m_fields;
}
@@ -79,9 +79,9 @@ uint32_t
PeerLinkFrameStart::GetSerializedSize () const
{
uint32_t size = 1; //Subtype
if (PEER_LINK_CONFIRM == m_fields.subtype)
if (IeDot11sPeerManagement::PEER_CONFIRM == m_fields.subtype)
size += 2; //AID of remote peer
if (PEER_LINK_CLOSE != m_fields.subtype)
if (IeDot11sPeerManagement::PEER_CLOSE != m_fields.subtype)
{
size += m_fields.rates.GetSerializedSize ();
size += 2;
@@ -95,9 +95,9 @@ PeerLinkFrameStart::Serialize (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
i.WriteU8 (m_fields.subtype); //Like a Category in Standart
if (PEER_LINK_CONFIRM == m_fields.subtype)
if (IeDot11sPeerManagement::PEER_CONFIRM == m_fields.subtype)
i.WriteHtonU16 (m_fields.aid);
if (PEER_LINK_CLOSE != m_fields.subtype)
if (IeDot11sPeerManagement::PEER_CLOSE != m_fields.subtype)
{
i = m_fields.rates.Serialize (i);
i.Next(2); //QoS
@@ -109,10 +109,10 @@ uint32_t
PeerLinkFrameStart::Deserialize (Buffer::Iterator start)
{
Buffer::Iterator i = start;
m_fields.subtype = (PeerLinkSubtype)i.ReadU8 ();
if (PEER_LINK_CONFIRM == m_fields.subtype)
m_fields.subtype = (IeDot11sPeerManagement::Subtype)i.ReadU8 ();
if (IeDot11sPeerManagement::PEER_CONFIRM == m_fields.subtype)
m_fields.aid = i.ReadNtohU16 ();
if (PEER_LINK_CLOSE != m_fields.subtype)
if (IeDot11sPeerManagement::PEER_CLOSE != m_fields.subtype)
{
i = m_fields.rates.Deserialize (i);
i.Next(2); //QoS

View File

@@ -23,27 +23,22 @@
#include "ns3/header.h"
#include "ns3/supported-rates.h"
#include "ns3/ssid.h"
#include "ns3/ie-dot11s-peer-management.h"
namespace ns3 {
class MeshWifiInterfaceMac;
class PeerLinkFrameStart : public Header
{
public:
enum PeerLinkSubtype
{
PEER_LINK_OPEN = 0,
PEER_LINK_CONFIRM,
PEER_LINK_CLOSE
};
PeerLinkFrameStart ();
struct PlinkFrameStartFields
{
PeerLinkSubtype subtype;
uint8_t subtype;
uint16_t aid;
SupportedRates rates;
Ssid meshId;
};
void SetPlinkFrameStart(PlinkFrameStartFields);
PlinkFrameStartFields GetPlinkFrameStart ();
PlinkFrameStartFields GetFields ();
bool CheckPlinkFrameStart(Ptr<MeshWifiInterfaceMac> mac);
/** Inherited from header:
* \{

View File

@@ -81,12 +81,6 @@ PeerLink::SetPeerAddress (Mac48Address macaddr)
m_peerAddress = macaddr;
}
void
PeerLink::SetLocalAddress (Mac48Address macaddr)
{
m_localAddress = macaddr;
}
void
PeerLink::SetLocalLinkId (uint16_t id)
{
@@ -134,12 +128,6 @@ PeerLink::GetPeerAddress () const
return m_peerAddress;
}
Mac48Address
PeerLink::GetLocalAddress () const
{
return m_localAddress;
}
uint16_t
PeerLink::GetLocalAid () const
{
@@ -182,6 +170,7 @@ void PeerLink::MLMEPassivePeerLinkOpen ()
void PeerLink::MLMEActivePeerLinkOpen ()
{
NS_LOG_UNCOND("Sending OPEN");
StateMachine (ACTOPN);
}
@@ -256,6 +245,11 @@ PeerLink::LinkIsIdle () const
{
return (m_state == IDLE);
}
void
PeerLink::SetMacPlugin(Ptr<Dot11sPeerManagerMacPlugin> plugin)
{
m_macPlugin = plugin;
}
//-----------------------------------------------------------------------------
// Private
//-----------------------------------------------------------------------------
@@ -358,10 +352,9 @@ PeerLink::StateMachine (PeerEvent event,dot11sReasonCode reasoncode)
break;
case OPN_ACPT:
m_state = ESTAB;
NS_LOG_DEBUG ("I am "<<m_localAddress<<", established link with "<<m_peerAddress<<", at "<<Simulator::Now());
ClearConfirmTimer ();
SendPeerLinkConfirm ();
m_linkStatusCallback (m_localAddress, m_peerAddress, true);
m_linkStatusCallback (m_interface, m_peerAddress, true);
// TODO Callback MLME-SignalPeerLinkStatus
break;
case CLS_ACPT:
@@ -401,10 +394,9 @@ PeerLink::StateMachine (PeerEvent event,dot11sReasonCode reasoncode)
SetRetryTimer ();
break;
case CNF_ACPT:
NS_LOG_DEBUG ("I am "<<m_localAddress<<", established link with "<<m_peerAddress<<", at "<<Simulator::Now());
m_state = ESTAB;
ClearRetryTimer ();
m_linkStatusCallback (m_localAddress, m_peerAddress, true);
m_linkStatusCallback (m_interface, m_peerAddress, true);
// TODO Callback MLME-SignalPeerLinkStatus
break;
case CLS_ACPT:
@@ -443,27 +435,24 @@ PeerLink::StateMachine (PeerEvent event,dot11sReasonCode reasoncode)
SendPeerLinkConfirm ();
break;
case CLS_ACPT:
NS_LOG_DEBUG ("I am "<<m_localAddress<<", CLOSED link with "<<m_peerAddress<<", at "<<Simulator::Now()<<" Close received");
m_state = HOLDING;
SendPeerLinkClose (REASON11S_MESH_CLOSE_RCVD);
SetHoldingTimer ();
m_linkStatusCallback (m_localAddress, m_peerAddress, false);
m_linkStatusCallback (m_interface, m_peerAddress, false);
break;
case OPN_RJCT:
case CNF_RJCT:
NS_LOG_DEBUG ("I am "<<m_localAddress<<", CLOSED link with "<<m_peerAddress<<", at "<<Simulator::Now()<<" Rejected open or confirm");
m_state = HOLDING;
ClearRetryTimer ();
SendPeerLinkClose (reasoncode);
SetHoldingTimer ();
m_linkStatusCallback (m_localAddress, m_peerAddress, false);
m_linkStatusCallback (m_interface, m_peerAddress, false);
break;
case CNCL:
NS_LOG_DEBUG ("I am "<<m_localAddress<<", CLOSED link with "<<m_peerAddress<<", at "<<Simulator::Now()<<" Link cancelled");
m_state = HOLDING;
SendPeerLinkClose (REASON11S_PEER_LINK_CANCELLED);
SetHoldingTimer ();
m_linkStatusCallback (m_localAddress, m_peerAddress, false);
m_linkStatusCallback (m_interface, m_peerAddress, false);
break;
default:
{}
@@ -522,8 +511,9 @@ void PeerLink::SendPeerLinkOpen ()
{
IeDot11sPeerManagement peerElement;
peerElement.SetPeerOpen (m_localLinkId);
//NS_ASSERT (m_mac != NULL);
//m_mac->SendPeerLinkOpen (peerElement, m_peerAddress);
NS_LOG_UNCOND("sending peer link open");
NS_ASSERT (m_macPlugin != NULL);
m_macPlugin->SendPeerLinkManagementFrame (m_peerAddress, m_assocId, peerElement, m_configuration);
}
void PeerLink::SendPeerLinkConfirm ()

View File

@@ -30,6 +30,7 @@
#include "ie-dot11s-beacon-timing.h"
#include "ie-dot11s-peer-management.h"
#include "ie-dot11s-configuration.h"
#include "peer-manager-plugin.h"
namespace ns3 {
/**
@@ -58,7 +59,6 @@ public:
* \{
*/
void SetPeerAddress (Mac48Address macaddr);
void SetLocalAddress (Mac48Address macaddr);
void SetLocalLinkId (uint16_t id);
void SetPeerLinkId (uint16_t id);
void SetLocalAid (uint16_t aid);
@@ -66,7 +66,6 @@ public:
void SetBeaconTimingElement (IeDot11sBeaconTiming beaconTiming);
void SetPeerLinkDescriptorElement (IeDot11sPeerManagement peerLinkElement);
Mac48Address GetPeerAddress () const;
Mac48Address GetLocalAddress () const;
uint16_t GetLocalAid () const;
Time GetLastBeacon () const;
Time GetBeaconInterval () const;
@@ -88,7 +87,7 @@ public:
/// MLME-PeeringRequestReject
void MLMEPeeringRequestReject ();
/// Callback type for MLME-SignalPeerLinkStatus event
typedef Callback<void, Mac48Address, Mac48Address, bool> SignalStatusCallback;
typedef Callback<void, uint32_t, Mac48Address, bool> SignalStatusCallback;
/// Set callback
void MLMESetSignalStatusCallback (SignalStatusCallback);
//\}
@@ -129,7 +128,11 @@ public:
bool LinkIsEstab () const;
/// True if link is idle. Link can be deleted in this state
bool LinkIsIdle () const;
/**
* Set pointer to MAC-plugin, which is responsible for sending peer
* link management frames
*/
void SetMacPlugin(Ptr<Dot11sPeerManagerMacPlugin> plugin);
private:
/// Peer link states, see 802.11s draft 11B.3.3.1
enum PeerState {
@@ -194,10 +197,12 @@ private:
//\}
private:
///The number of interface I am associated with
uint32_t m_interface;
/// pointer to mac plugin, which is responsible for peer management
Ptr<Dot11sPeerManagerMacPlugin> m_macPlugin;
/// Peer address
Mac48Address m_peerAddress;
/// My own address
Mac48Address m_localAddress;
/// My ID of this link
uint16_t m_localLinkId;
/// Peer ID of this link

View File

@@ -24,6 +24,9 @@
#include "peer-manager-plugin.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"
NS_LOG_COMPONENT_DEFINE("PeerManager");
@@ -69,93 +72,57 @@ Dot11sPeerManagerMacPlugin::Receive (Ptr<Packet> packet, const WifiMacHeader & h
Simulator::Now(),
MicroSeconds(beacon_hdr.GetBeaconIntervalUs())
);
#if 0
packet->RemoveHeader (beacon);
m_peerManager->SetReceivedBeaconTimers (
GetAddress (),
from,
Simulator::Now (),
MicroSeconds (beacon.GetBeaconIntervalUs()),
beacon.GetIeDot11sBeaconTiming ()
);
#endif
}
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(multihopHdr.GetCategory () != WifiMeshMultihopActionHeader::MESH_PEER_LINK_MGT)
return false;
#if 0
{
case WifiMeshMultihopActionHeader::MESH_PEER_LINK_MGT:
{
Mac48Address peerAddress;
MeshMgtPeerLinkManFrame peer_frame;
if (hdr->GetAddr1 () != GetAddress ())
return;
peerAddress = hdr->GetAddr2 ();
packet->RemoveHeader (peer_frame);
if (actionValue.peerLink != WifiMeshMultihopActionHeader::PEER_LINK_CLOSE)
{
//check Supported Rates
SupportedRates rates = peer_frame.GetSupportedRates ();
for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++)
{
WifiMode mode = m_stationManager->GetBasicMode (i);
if (!rates.IsSupportedRate (mode.GetDataRate ()))
{
m_peerManager->ConfigurationMismatch (GetAddress(), peerAddress);
return;
}
}
//Check SSID
if (!peer_frame.GetMeshId ().IsEqual(GetSsid()))
{
m_peerManager->ConfigurationMismatch (GetAddress(), peerAddress);
return;
}
}
switch (actionValue.peerLink)
{
case WifiMeshMultihopActionHeader::PEER_LINK_CONFIRM:
m_peerManager->SetConfirmReceived (
GetAddress (),
peerAddress,
peer_frame.GetAid (),
peer_frame.GetIeDot11sPeerManagement (),
m_meshConfig
);
return;
case WifiMeshMultihopActionHeader::PEER_LINK_OPEN:
m_peerManager->SetOpenReceived (
GetAddress (),
peerAddress,
peer_frame.GetIeDot11sPeerManagement (),
m_meshConfig
);
return;
case WifiMeshMultihopActionHeader::PEER_LINK_CLOSE:
m_peerManager->SetCloseReceived (
GetAddress (),
peerAddress,
peer_frame.GetIeDot11sPeerManagement ()
);
return;
default:
return;
}
break;
#endif
}
Mac48Address peerAddress = header.GetAddr2 ();
PeerLinkFrameStart::PlinkFrameStartFields fields;
{
PeerLinkFrameStart peerFrame;
packet->RemoveHeader (peerFrame);
fields = peerFrame.GetFields();
}
if (actionValue.peerLink != WifiMeshMultihopActionHeader::PEER_LINK_CLOSE)
{
if(!(m_parent->CheckSupportedRates(fields.rates)))
{
NS_ASSERT(false);
//m_peerManager->ConfigurationMismatch (GetAddress(), peerAddress);
return true;
}
if (!fields.meshId.IsEqual(m_parent->GetSsid()))
{
NS_ASSERT(false);
//m_peerManager->ConfigurationMismatch (GetAddress(), peerAddress);
return true;
}
}
switch (actionValue.peerLink)
{
case WifiMeshMultihopActionHeader::PEER_LINK_CONFIRM:
return true;
case WifiMeshMultihopActionHeader::PEER_LINK_OPEN:
NS_LOG_UNCOND("OPEN RECEIVED");
NS_ASSERT(false);
return true;
case WifiMeshMultihopActionHeader::PEER_LINK_CLOSE:
return true;
default:
return false;
}
}
return false;
}
@@ -179,4 +146,62 @@ Dot11sPeerManagerMacPlugin::UpdateBeacon (MeshWifiBeacon & beacon) const
MicroSeconds(beacon.BeaconHeader().GetBeaconIntervalUs()));
beacon.AddInformationElement(beaconTiming);
}
void
Dot11sPeerManagerMacPlugin::SendPeerLinkManagementFrame(
Mac48Address peerAddress,
uint16_t aid,
IeDot11sPeerManagement peerElement,
IeDot11sConfiguration meshConfig
)
{
NS_LOG_UNCOND("sending open");
//Create a packet:
Ptr<Packet> packet = Create<Packet> ();
packet->AddHeader(peerElement);
packet->AddHeader(meshConfig);
PeerLinkFrameStart::PlinkFrameStartFields fields;
fields.subtype = peerElement.GetSubtype();
fields.aid = aid;
fields.rates = m_parent->GetSupportedRates ();
fields.meshId = m_parent->GetSsid ();
PeerLinkFrameStart plinkFrame;
plinkFrame.SetPlinkFrameStart(fields);
packet->AddHeader(plinkFrame);
//Create an 802.11 frame header:
//Send management frame to MAC:
WifiMeshMultihopActionHeader multihopHdr;
if (peerElement.SubtypeIsOpen ())
{
WifiMeshMultihopActionHeader::ACTION_VALUE action;
action.peerLink = WifiMeshMultihopActionHeader::PEER_LINK_OPEN;
multihopHdr.SetAction (WifiMeshMultihopActionHeader::MESH_PEER_LINK_MGT, action);
}
if (peerElement.SubtypeIsConfirm ())
{
WifiMeshMultihopActionHeader::ACTION_VALUE action;
action.peerLink = WifiMeshMultihopActionHeader::PEER_LINK_CONFIRM;
multihopHdr.SetAction (WifiMeshMultihopActionHeader::MESH_PEER_LINK_MGT, action);
}
if (peerElement.SubtypeIsClose ())
{
WifiMeshMultihopActionHeader::ACTION_VALUE action;
action.peerLink = WifiMeshMultihopActionHeader::PEER_LINK_CLOSE;
multihopHdr.SetAction (WifiMeshMultihopActionHeader::MESH_PEER_LINK_MGT, action);
}
packet->AddHeader (multihopHdr);
//mesh header:
WifiMeshHeader meshHdr;
meshHdr.SetMeshTtl (1);
meshHdr.SetMeshSeqno (0);
packet->AddHeader (meshHdr);
//Wifi Mac header:
WifiMacHeader hdr;
hdr.SetMultihopAction ();
hdr.SetAddr1 (peerAddress);
hdr.SetAddr2 (m_parent->GetAddress ());
hdr.SetAddr3 (m_parent->GetAddress ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
m_parent->SendManagementFrame(packet, hdr);
}
}//namespace ns3

View File

@@ -28,6 +28,7 @@
#include "ns3/log.h"
#include "ns3/random-variable.h"
#include "ns3/mesh-wifi-interface-mac.h"
#include "ns3/peer-link.h"
NS_LOG_COMPONENT_DEFINE ("Dot11sPeerManagerProtocol");
namespace ns3 {
@@ -41,7 +42,7 @@ Dot11sPeerManagerProtocol::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Dot11sPeerManagerProtocol")
.SetParent<Object> ()
.AddConstructor<Dot11sPeerManagerProtocol> ();
.AddConstructor<Dot11sPeerManagerProtocol> ()
#if 0
//peerLinkCleanupTimeout. This constant is not specified in Draft 2.0
.AddAttribute ("PeerLinkCleanupPeriod",
@@ -56,6 +57,7 @@ Dot11sPeerManagerProtocol::GetTypeId (void)
MakeUintegerAccessor (&Dot11sPeerManagerProtocol::m_maxBeaconLoss),
MakeUintegerChecker<uint8_t> ()
)
#endif
//maximum number of peer links.
.AddAttribute ("MaxNumberOfPeerLinks",
"Maximum number of peer links ",
@@ -63,7 +65,6 @@ Dot11sPeerManagerProtocol::GetTypeId (void)
MakeUintegerAccessor (&Dot11sPeerManagerProtocol::m_maxNumberOfPeerLinks),
MakeUintegerChecker<uint8_t> ()
);
#endif
return tid;
}
@@ -82,12 +83,12 @@ Dot11sPeerManagerProtocol::~Dot11sPeerManagerProtocol ()
m_cleanupEvent.Cancel ();
//TODO: delete a list of descriptors
for (
PeerDescriptorsMap::iterator j = m_peerDescriptors.begin ();
j != m_peerDescriptors.end ();
PeerDescriptorsMap::iterator j = m_peerLinks.begin ();
j != m_peerLinks.end ();
j++)
{
int to_delete = 0;
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = j->second.begin (); i != j->second.end(); i++)
for (std::vector<Ptr<PeerLink> >::iterator i = j->second.begin (); i != j->second.end(); i++)
{
to_delete ++;
(*i)->ClearTimingElement ();
@@ -97,7 +98,7 @@ Dot11sPeerManagerProtocol::~Dot11sPeerManagerProtocol ()
j->second.pop_back ();
j->second.clear ();
}
m_peerDescriptors.clear ();
m_peerLinks.clear ();
#endif
}
//-----------------------------------------------------
@@ -115,6 +116,8 @@ Dot11sPeerManagerProtocol::AttachPorts(std::vector<Ptr<WifiNetDevice> > interfac
Ptr<Dot11sPeerManagerMacPlugin> peerPlugin = Create<Dot11sPeerManagerMacPlugin> ((*i)->GetIfIndex(), this);
mac->InstallPlugin(peerPlugin);
m_plugins[(*i)->GetIfIndex()] = peerPlugin;
PeerLinksOnInterface newmap;
m_peerLinks[(*i)->GetIfIndex()] = newmap;
}
return true;
}
@@ -127,7 +130,7 @@ Dot11sPeerManagerProtocol::SendBeacon(uint32_t interface, Time currentTbtt, Time
BeaconInfoMap::iterator i = m_neighbourBeacons.find(interface);
if(i == m_neighbourBeacons.end())
return retval;
for(BeaconInterfaceInfoMap::iterator j = i->second.begin(); j != i->second.end(); j++)
for(BeaconsOnInterface::iterator j = i->second.begin(); j != i->second.end(); j++)
{
//check beacon loss and make a timing element
if(
@@ -154,34 +157,56 @@ Dot11sPeerManagerProtocol::ReceiveBeacon(
NS_LOG_UNCOND("Beacon received from "<<peerAddress);
NS_LOG_UNCOND(timingElement);
//find beacon entry and write there a new one
BeaconInfoMap::iterator i = m_neighbourBeacons.find(interface);
if(i == m_neighbourBeacons.end())
{
NS_LOG_UNCOND("First beacon from this interface");
BeaconInterfaceInfoMap newMap;
m_neighbourBeacons[interface] = newMap;
BeaconInfoMap::iterator i = m_neighbourBeacons.find(interface);
if(i == m_neighbourBeacons.end())
{
NS_LOG_UNCOND("First beacon from this interface");
BeaconsOnInterface newMap;
m_neighbourBeacons[interface] = newMap;
}
i = m_neighbourBeacons.find(interface);
BeaconsOnInterface::iterator j = i->second.find(peerAddress);
if(j == i->second.end())
{
NS_LOG_UNCOND("first beacon from this station");
BeaconInfo newInfo;
newInfo.referenceTbtt = receivingTime;
newInfo.beaconInterval = beaconInterval;
newInfo.aid = m_lastAssocId++;
if(m_lastAssocId == 0xff)
m_lastAssocId = 0;
i->second[peerAddress] = newInfo;
}
else
{
NS_LOG_UNCOND("last beacon was at"<<j->second.referenceTbtt);
j->second.referenceTbtt = receivingTime;
NS_LOG_UNCOND("now beacon is at"<<j->second.referenceTbtt);
j->second.beaconInterval = beaconInterval;
}
if(!meshBeacon)
return;
}
i = m_neighbourBeacons.find(interface);
BeaconInterfaceInfoMap::iterator j = i->second.find(peerAddress);
if(j == i->second.end())
//PM STATE Machine
{
NS_LOG_UNCOND("first beacon from this station");
BeaconInfo newInfo;
newInfo.referenceTbtt = receivingTime;
newInfo.beaconInterval = beaconInterval;
newInfo.aid = m_lastAssocId++;
i->second[peerAddress] = newInfo;
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 ();
}
else
{
NS_LOG_UNCOND("last beacon was at"<<j->second.referenceTbtt);
j->second.referenceTbtt = receivingTime;
NS_LOG_UNCOND("now beacon is at"<<j->second.referenceTbtt);
j->second.beaconInterval = beaconInterval;
}
if(!meshBeacon)
return;
//TODO: PM STATE Machine
}
void
@@ -220,9 +245,9 @@ Dot11sPeerManagerProtocol::SetReceivedBeaconTimers (
IeDot11sBeaconTiming beaconTiming
)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
{
if ((*i)->GetPeerAddress () == peerAddress)
{
@@ -231,9 +256,9 @@ Dot11sPeerManagerProtocol::SetReceivedBeaconTimers (
return;
}
}
Ptr<WifiPeerLinkDescriptor> new_descriptor =
Ptr<PeerLink> new_link =
AddDescriptor (interfaceAddress, peerAddress, Simulator::Now(), beaconInterval);
new_descriptor->SetBeaconTimingElement (beaconTiming);
new_link->SetBeaconTimingElement (beaconTiming);
}
bool
@@ -249,27 +274,14 @@ Dot11sPeerManagerProtocol::AttachPorts (std::vector<Ptr<WifiNetDevice> > interfa
//Add a mac pointer:
m_macPointers[meshWifiMac->GetAddress ()] = meshWifiMac;
//Add descriptor array:
std::vector<Ptr<WifiPeerLinkDescriptor> > descriptors;
m_peerDescriptors[meshWifiMac->GetAddress ()] = descriptors;
std::vector<Ptr<PeerLink> > descriptors;
m_peerLinks[meshWifiMac->GetAddress ()] = descriptors;
//Add beacon timers:
struct BeaconInfo myBeacon;
m_myBeaconInfo[meshWifiMac->GetAddress ()] = myBeacon;
}
return true;
}
void
Dot11sPeerManagerProtocol::AskIfOpenNeeded (Mac48Address interfaceAddress, Mac48Address peerAddress)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == peerAddress)
{
if (ShouldSendOpen (interfaceAddress, peerAddress))
(*i)->MLMEActivePeerLinkOpen ();
break;
}
}
void
Dot11sPeerManagerProtocol::SetOpenReceived (
@@ -282,9 +294,9 @@ Dot11sPeerManagerProtocol::SetOpenReceived (
dot11sReasonCode reasonCode;
if (!ShouldAcceptOpen (interfaceAddress, peerAddress,reasonCode))
return;
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == peerAddress)
{
(*i)->PeerLinkOpenAccept (peerMan.GetLocalLinkId(), conf);
@@ -292,13 +304,13 @@ Dot11sPeerManagerProtocol::SetOpenReceived (
}
BeaconInfoMap::iterator myBeacon = m_myBeaconInfo.find (interfaceAddress);
NS_ASSERT (myBeacon != m_myBeaconInfo.end());
Ptr<WifiPeerLinkDescriptor>new_descriptor = AddDescriptor (
Ptr<PeerLink>new_link = AddDescriptor (
interfaceAddress,
peerAddress,
Simulator::Now (),
myBeacon->second.beaconInterval
);
new_descriptor->PeerLinkOpenAccept (peerMan.GetLocalLinkId(), conf);
new_link->PeerLinkOpenAccept (peerMan.GetLocalLinkId(), conf);
}
void
Dot11sPeerManagerProtocol::SetConfirmReceived (
@@ -309,9 +321,9 @@ Dot11sPeerManagerProtocol::SetConfirmReceived (
IeDot11sConfiguration meshConfig
)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == peerAddress)
(*i)->PeerLinkConfirmAccept (peerMan.GetLocalLinkId(), peerMan.GetPeerLinkId(), peerAid, meshConfig);
}
@@ -323,9 +335,9 @@ Dot11sPeerManagerProtocol::SetCloseReceived (
IeDot11sPeerManagement peerMan
)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == peerAddress)
{
(*i)->PeerLinkClose (peerMan.GetLocalLinkId(), peerMan.GetPeerLinkId(), peerMan.GetReasonCode());
@@ -339,9 +351,9 @@ Dot11sPeerManagerProtocol::ConfigurationMismatch (
Mac48Address peerAddress
)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == peerAddress)
{
(*i)->MLMECancelPeerLink (REASON11S_MESH_CONFIGURATION_POLICY_VIOLATION);
@@ -353,10 +365,10 @@ Dot11sPeerManagerProtocol::ConfigurationMismatch (
IeDot11sBeaconTiming
Dot11sPeerManagerProtocol::GetIeDot11sBeaconTimingForMyBeacon (Mac48Address interfaceAddress)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
IeDot11sBeaconTiming return_val;
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
{
//Just go through all neighbor entries and add it to timing element:
return_val.AddNeighboursTimingElementUnit (
@@ -373,52 +385,50 @@ Dot11sPeerManagerProtocol::GetIeDot11sBeaconTimingForAddress (
Mac48Address interfaceAddress,
Mac48Address addr)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
IeDot11sBeaconTiming return_val;
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == addr)
return_val = (*i)->GetBeaconTimingElement ();
return return_val;
}
Ptr<WifiPeerLinkDescriptor>
Dot11sPeerManagerProtocol::AddDescriptor (
Mac48Address interfaceAddress,
#endif
Ptr<PeerLink>
Dot11sPeerManagerProtocol::InitiateLink (
uint32_t interface,
Mac48Address peerAddress,
Time lastBeacon,
Time beaconInterval)
{
Ptr<WifiPeerLinkDescriptor> new_descriptor = Create<WifiPeerLinkDescriptor> ();
if (m_assocId == 0xff)
m_assocId = 0;
if (m_localLinkId == 0xff)
m_localLinkId = 0;
new_descriptor->SetLocalAid (m_assocId++);
new_descriptor->SetLocalLinkId (m_localLinkId++);
new_descriptor->SetPeerAddress (peerAddress);
new_descriptor->SetBeaconInformation (lastBeacon, beaconInterval);
//DEBUG ONLY:
new_descriptor->SetLocalAddress (interfaceAddress);
//check if interface address is wrong
MeshMacMap::iterator pos = m_macPointers.find (interfaceAddress);
NS_ASSERT (pos != m_macPointers.end());
//check if descriptors array exist
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
new_descriptor->SetMac (pos->second);
new_descriptor->SetMaxBeaconLoss (m_maxBeaconLoss);
new_descriptor->SetLinkStatusCallback (MakeCallback(&Dot11sPeerManagerProtocol::PeerLinkStatus, this));
NS_ASSERT (interface != m_peerDescriptors.end());
m_peerDescriptors[interfaceAddress].push_back (new_descriptor);
return new_descriptor;
}
Ptr<PeerLink> new_link = CreateObject<PeerLink> ();
if (m_lastLocalLinkId == 0xff)
m_lastLocalLinkId = 0;
//the entry about beacon must exist in beacon map
BeaconInfoMap::iterator beaconsOnInterface = m_neighbourBeacons.find (interface);
NS_ASSERT(beaconsOnInterface != m_neighbourBeacons.end());
BeaconsOnInterface::iterator beacon = beaconsOnInterface->second.find (peerAddress);
NS_ASSERT(beacon != beaconsOnInterface->second.end ());
PeerManagerPluginMap::iterator plugin = m_plugins.find (interface);
NS_ASSERT(plugin != m_plugins.end ());
NS_LOG_UNCOND("Adding a new descriptor");
new_link->SetLocalAid (beacon->second.aid);
new_link->SetLocalLinkId (m_lastLocalLinkId++);
new_link->SetPeerAddress (peerAddress);
new_link->SetBeaconInformation (lastBeacon, beaconInterval);
new_link->SetMacPlugin (plugin->second);
//new_link->SetLinkStatusCallback (MakeCallback(&Dot11sPeerManagerProtocol::PeerLinkStatus, this));
m_peerLinks[interface].push_back (new_link);
return new_link;
}
#if 0
void
Dot11sPeerManagerProtocol::PeerCleanup ()
{
for (
PeerDescriptorsMap::iterator j = m_peerDescriptors.begin ();
j != m_peerDescriptors.end ();
PeerDescriptorsMap::iterator j = m_peerLinks.begin ();
j != m_peerLinks.end ();
j++)
{
std::vector<unsigned int> to_erase;
@@ -441,10 +451,10 @@ Dot11sPeerManagerProtocol::PeerCleanup ()
std::vector<Mac48Address>
Dot11sPeerManagerProtocol::GetNeighbourAddressList (Mac48Address interfaceAddress, Mac48Address peerAddress)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
std::vector<Mac48Address> return_value;
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
return_value.push_back ((*i)->GetPeerAddress());
return return_value;
}
@@ -452,22 +462,22 @@ Dot11sPeerManagerProtocol::GetNeighbourAddressList (Mac48Address interfaceAddres
bool
Dot11sPeerManagerProtocol::IsActiveLink (Mac48Address interfaceAddress, Mac48Address peerAddress)
{
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
for (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
PeerDescriptorsMap::iterator interface = m_peerLinks.find (interfaceAddress);
NS_ASSERT (interface != m_peerLinks.end());
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
if ((*i)->GetPeerAddress () == peerAddress)
return ((*i)->LinkIsEstab ());
return false;
}
#endif
bool
Dot11sPeerManagerProtocol::ShouldSendOpen (Mac48Address interfaceAddress, Mac48Address peerAddress)
Dot11sPeerManagerProtocol::ShouldSendOpen (uint32_t interface, Mac48Address peerAddress)
{
if (m_numberOfActivePeers > m_maxNumberOfPeerLinks)
return false;
return true;
}
#if 0
bool
Dot11sPeerManagerProtocol::ShouldAcceptOpen (Mac48Address interfaceAddress, Mac48Address peerAddress,dot11sReasonCode & reasonCode)
{
@@ -493,11 +503,11 @@ Dot11sPeerManagerProtocol::GetNextBeaconShift (
uint32_t myNextTBTTInTimeUnits = 0;
uint32_t futureBeaconInTimeUnits = 0;
//Going through all my timing elements and detecting future beacon collisions
PeerDescriptorsMap::iterator interface = m_peerDescriptors.find (interfaceAddress);
NS_ASSERT (interface != m_peerDescriptors.end());
PeerDescriptorsMap::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 (std::vector<Ptr<WifiPeerLinkDescriptor> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
for (std::vector<Ptr<PeerLink> >::iterator i = interface->second.begin (); i != interface->second.end(); i++)
{
IeDot11sBeaconTiming::NeighboursTimingUnitsList neighbours;
neighbours = (*i)->GetBeaconTimingElement ().GetNeighboursTimingElementsList();
@@ -562,7 +572,7 @@ Dot11sPeerManagerProtocol::GetNextBeaconShift (
}
void
Dot11sPeerManagerProtocol::PeerLinkStatus (Mac48Address interfaceAddress, Mac48Address peerAddress, bool status)
Dot11sPeerManagerProtocol::PeerLinkStatus (uint32_t interface, Mac48Address peerAddress, bool status)
{
MeshMacMap::iterator pos = m_macPointers.find (interfaceAddress);
NS_ASSERT (pos != m_macPointers.end());

View File

@@ -29,10 +29,11 @@
#include "ns3/ie-dot11s-beacon-timing.h"
#include "ns3/ie-dot11s-configuration.h"
#include "ns3/event-id.h"
//#include "ns3/peer-link.h"
#include "peer-manager-plugin.h"
#include <list>
#include <map>
namespace ns3 {
class Dot11sPeerManagerMacPlugin;
class PeerLink;
@@ -108,6 +109,12 @@ public:
/**
* \}
*/
private:
Ptr<PeerLink> InitiateLink (uint32_t interface, Mac48Address peerAddress, Time lastBeacon, Time beaconInterval);
/**
* External peer-chooser
*/
bool ShouldSendOpen(uint32_t interface, Mac48Address peerAddress);
private:
/**
* All private structures:
@@ -122,9 +129,10 @@ private:
Time referenceTbtt; //When one of my station's beacons was put into a beacon queue;
Time beaconInterval; //Beacon interval of my station;
};
typedef std::map<uint32_t, std::vector<Ptr<PeerLink> > > PeerDescriptorsMap;
typedef std::map<Mac48Address, BeaconInfo> BeaconInterfaceInfoMap;
typedef std::map<uint32_t, BeaconInterfaceInfoMap> BeaconInfoMap;
typedef std::vector<Ptr<PeerLink> > PeerLinksOnInterface;
typedef std::map<uint32_t, PeerLinksOnInterface> PeerLinksMap;
typedef std::map<Mac48Address, BeaconInfo> BeaconsOnInterface;
typedef std::map<uint32_t, BeaconsOnInterface> BeaconInfoMap;
typedef std::map<uint32_t, Ptr<Dot11sPeerManagerMacPlugin> > PeerManagerPluginMap;
PeerManagerPluginMap m_plugins;
@@ -140,9 +148,18 @@ private:
*/
uint16_t m_lastAssocId;
uint16_t m_lastLocalLinkId;
uint8_t m_numberOfActivePeers; //number of established peer links
uint8_t m_maxNumberOfPeerLinks;
/**
* Peer Links
* \{
*/
PeerLinksMap m_peerLinks;
/**
* \}
*/
#if 0
//Maximum peers that may be opened:
uint8_t m_maxNumberOfPeerLinks;
/**
* Peer manager identify interface by address
* of MAC. So, for every interface we store
@@ -154,7 +171,6 @@ private:
* mac
*/
MeshMacMap m_macPointers;
uint8_t m_numberOfActivePeers; //number of established peer links
uint16_t m_assocId; //last stored assoc ID
uint16_t m_localLinkId; //last stored local link ID
//This Variables used in beacon miss auto-cleanup:
@@ -165,15 +181,8 @@ private:
//and check if the too many beacons were lost:
Time m_peerLinkCleanupPeriod;
EventId m_cleanupEvent;
Ptr<WifiPeerLinkDescriptor> AddDescriptor (
Mac48Address interfaceAddress,
Mac48Address peerAddress,
Time lastBeacon,
Time beaconInterval
);
void PeerCleanup ();
//Mechanism of choosing PEERs:
bool ShouldSendOpen (Mac48Address interfaceAddress, Mac48Address peerAddress);
bool ShouldAcceptOpen (
Mac48Address interfaceAddress,
Mac48Address peerAddress,