Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
authorKirill Andreev <andreev@iitp.ru>
Thu, 18 Jun 2009 18:07:22 +0400
changeset 5086 fccfd0073ea3
parent 5085 5cfc1e9372af
child 5087 444caf312d1e
Fixed names: now protocols are called *-protocol.[h,cc], plugin is called *-protocol-mac.[cc,h]
examples/mesh.cc
src/devices/mesh/dot11s/hwmp-mac-plugin.cc
src/devices/mesh/dot11s/hwmp-mac-plugin.h
src/devices/mesh/dot11s/hwmp-protocol-mac.cc
src/devices/mesh/dot11s/hwmp-protocol-mac.h
src/devices/mesh/dot11s/hwmp-protocol.cc
src/devices/mesh/dot11s/hwmp-protocol.h
src/devices/mesh/dot11s/peer-link.cc
src/devices/mesh/dot11s/peer-link.h
src/devices/mesh/dot11s/peer-management-plugin.cc
src/devices/mesh/dot11s/peer-management-plugin.h
src/devices/mesh/dot11s/peer-management-protocol-mac.cc
src/devices/mesh/dot11s/peer-management-protocol-mac.h
src/devices/mesh/dot11s/peer-management-protocol.cc
src/devices/mesh/dot11s/peer-management-protocol.h
src/devices/mesh/dot11s/wscript
src/devices/mesh/flame/flame-protocol-mac.cc
src/devices/mesh/flame/flame-protocol-mac.h
src/devices/mesh/flame/flame-protocol.cc
src/devices/mesh/flame/flame-protocol.h
src/helper/dot11s-helper.cc
src/helper/dot11s-helper.h
src/helper/mesh-helper.cc
src/helper/mesh-helper.h
src/helper/wscript
--- a/examples/mesh.cc	Thu Jun 18 16:51:28 2009 +0400
+++ b/examples/mesh.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -65,8 +65,8 @@
     NetDeviceContainer meshDevices;
     //Addresses of interfaces:
     Ipv4InterfaceContainer interfaces;
-    // MeshWifiHelper. Report is not static methods
-    MeshWifiHelper mesh;
+    // MeshHelper. Report is not static methods
+    MeshHelper mesh;
   private:
     /// Create nodes and setup their mobility
     void CreateNodes ();
--- a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Thu Jun 18 16:51:28 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,360 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008,2009 IITP RAS
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Kirill Andreev <andreev@iitp.ru>
- */
-
-#include "ns3/mesh-wifi-interface-mac.h"
-#include "ns3/packet.h"
-#include "ns3/simulator.h"
-#include "ns3/nstime.h"
-#include "ns3/log.h"
-#include "hwmp-mac-plugin.h"
-#include "dot11s-mac-header.h"
-#include "hwmp-protocol.h"
-#include "hwmp-tag.h"
-#include "ie-dot11s-preq.h"
-#include "ie-dot11s-prep.h"
-
-namespace ns3 {
-namespace dot11s {
-
-NS_LOG_COMPONENT_DEFINE ("HwmpMacPlugin");
-HwmpMacPlugin::HwmpMacPlugin (uint32_t ifIndex, Ptr<HwmpProtocol> protocol):
-  m_ifIndex (ifIndex),
-  m_protocol (protocol)
-{
-}
-HwmpMacPlugin::~HwmpMacPlugin ()
-{
-}
-void
-HwmpMacPlugin::SetParent (Ptr<MeshWifiInterfaceMac> parent)
-{
-  m_parent = parent;
-}
-
-bool
-HwmpMacPlugin::ReceiveData (Ptr<Packet> packet, const WifiMacHeader & header)
-{
-  NS_ASSERT (header.IsData());
-
-  MeshHeader meshHdr;
-  HwmpTag tag;
-  if(packet->PeekPacketTag (tag))
-  {
-    NS_FATAL_ERROR ("HWMP tag is not supposed to be received by network");
-  }
-  
-  packet->RemoveHeader(meshHdr);
-  m_stats.rxData ++;
-  m_stats.rxDataBytes += packet->GetSize ();
-  
-  //TODO: address extension
-  Mac48Address destination;
-  Mac48Address source;
-  switch (meshHdr.GetAddressExt ())
-  {
-    case 0:
-      source = header.GetAddr4 ();
-      destination = header.GetAddr3 ();
-      break;
-    default:
-      NS_FATAL_ERROR ("6-address scheme is not yet supported and 4-address extension is not supposed to be used for data frames.");
-  };
-  tag.SetSeqno (meshHdr.GetMeshSeqno ());
-  tag.SetTtl (meshHdr.GetMeshTtl ());
-  packet->AddPacketTag(tag);
- 
-  if (destination == Mac48Address::GetBroadcast ())
-    if(m_protocol->DropDataFrame (meshHdr.GetMeshSeqno (), source))
-      return false;
-  
-  return true;
-}
-
-bool
-HwmpMacPlugin::ReceiveAction (Ptr<Packet> packet, const WifiMacHeader & header)
-{
-  m_stats.rxMgt ++;
-  m_stats.rxMgtBytes += packet->GetSize ();
-  WifiMeshActionHeader actionHdr;
-  packet->RemoveHeader (actionHdr);
-  WifiMeshActionHeader::ActionValue actionValue = actionHdr.GetAction ();
-  if(actionHdr.GetCategory () != WifiMeshActionHeader::MESH_PATH_SELECTION)
-    return true;
-  switch (actionValue.pathSelection)
-  {
-    case WifiMeshActionHeader::PATH_REQUEST:
-      {
-        IePreq preq;
-        m_stats.rxPreq ++;
-        packet->RemoveHeader (preq);
-        if(preq.GetOriginatorAddress () == m_protocol->GetAddress ())
-          return false;
-        if (preq.GetTtl () == 0)
-          return false;
-        preq.DecrementTtl ();
-        m_protocol->ReceivePreq (preq, header.GetAddr2 (), m_ifIndex, header.GetAddr3 (), m_parent->GetLinkMetric(header.GetAddr2 ()));
-        return false;
-      }
-    case WifiMeshActionHeader::PATH_REPLY:
-      {
-        IePrep prep;
-        m_stats.rxPrep ++;
-        packet->RemoveHeader (prep);
-        if(prep.GetTtl () == 0)
-          return false;
-        prep.DecrementTtl ();
-        m_protocol->ReceivePrep (prep, header.GetAddr2 (), m_ifIndex, header.GetAddr3 (), m_parent->GetLinkMetric(header.GetAddr2 ()));
-        return false;
-      }
-    case WifiMeshActionHeader::PATH_ERROR:
-      {
-        IePerr perr;
-        m_stats.rxPerr ++;
-        packet->RemoveHeader (perr);
-        m_protocol->ReceivePerr (perr, header.GetAddr2 (), m_ifIndex, header.GetAddr3 ());
-        return false;
-      }
-    case WifiMeshActionHeader::ROOT_ANNOUNCEMENT:
-      return false;
-  }
-  return true;
-}
-
-bool
-HwmpMacPlugin::Receive (Ptr<Packet> packet, const WifiMacHeader & header)
-{
-  if (header.IsData ())
-    return ReceiveData (packet, header);
-  else if (header.IsAction ())
-    return ReceiveAction (packet, header);
-  else
-    return true; // don't care
-}
-bool
-HwmpMacPlugin::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to)
-{
-  if(!header.IsData ())
-    return true;
-  HwmpTag tag;
-  bool tagExists = packet->RemovePacketTag(tag);
-  if (!tagExists)
-  {
-    NS_FATAL_ERROR ("HWMP tag must exist at this point");
-  }
-  m_stats.txData ++;
-  m_stats.txDataBytes += packet->GetSize ();
-  MeshHeader meshHdr;
-  meshHdr.SetMeshSeqno(tag.GetSeqno());
-  meshHdr.SetMeshTtl(tag.GetTtl());
-  packet->AddHeader(meshHdr);
-  header.SetAddr1(tag.GetAddress());
-  return true;
-}
-void
-HwmpMacPlugin::SendPreq(IePreq preq)
-{
-  m_preqQueue.push_back (preq);
-  SendOnePreq ();
-}
-void
-HwmpMacPlugin::RequestDestination (Mac48Address dst, uint32_t originator_seqno, uint32_t dst_seqno)
-{
-  for(std::vector<IePreq>::iterator i = m_preqQueue.begin (); i != m_preqQueue.end (); i ++)
-    if(i->MayAddAddress(m_protocol->GetAddress ()))
-    {
-      i->AddDestinationAddressElement (m_protocol->GetDoFlag(), m_protocol->GetRfFlag(), dst, dst_seqno);
-      return;
-    }
-  IePreq preq;
-  //fill PREQ:
-  preq.SetHopcount (0);
-  preq.SetTTL (m_protocol->GetMaxTtl ());
-  preq.SetPreqID (m_protocol->GetNextPreqId ());
-  preq.SetOriginatorAddress (m_protocol->GetAddress ());
-  preq.SetOriginatorSeqNumber (originator_seqno);
-  preq.SetLifetime (m_protocol->GetActivePathLifetime ());
-  preq.AddDestinationAddressElement (m_protocol->GetDoFlag (), m_protocol->GetRfFlag (), dst, dst_seqno);
-  m_preqQueue.push_back (preq);
-  //set iterator position to my preq:
-  SendOnePreq ();
-}
-void
-HwmpMacPlugin::SendOnePreq ()
-{
-  if(m_preqTimer.IsRunning ())
-    return;
-  if (m_preqQueue.size () == 0)
-    return;
-  //reschedule sending PREQ
-  NS_ASSERT (!m_preqTimer.IsRunning());
-  m_preqTimer = Simulator::Schedule (m_protocol->GetPreqMinInterval (), &HwmpMacPlugin::SendOnePreq, this);
-  Ptr<Packet> packet  = Create<Packet> ();
-  packet->AddHeader(m_preqQueue[0]);
-  //Action header:
-  WifiMeshActionHeader actionHdr;
-  WifiMeshActionHeader::ActionValue action;
-  action.pathSelection = WifiMeshActionHeader::PATH_REQUEST;
-  actionHdr.SetAction (WifiMeshActionHeader::MESH_PATH_SELECTION, action);
-  packet->AddHeader (actionHdr);
-  //create 802.11 header:
-  WifiMacHeader hdr;
-  hdr.SetAction ();
-  hdr.SetDsNotFrom ();
-  hdr.SetDsNotTo ();
-  hdr.SetAddr2 (m_parent->GetAddress ());
-  hdr.SetAddr3 (m_protocol->GetAddress ());
-  //Send Management frame
-  std::vector <Mac48Address> receivers = m_protocol->GetPreqReceivers (m_ifIndex);
-  for(std::vector<Mac48Address>::const_iterator i = receivers.begin (); i != receivers.end (); i ++)
-  {
-    hdr.SetAddr1 (*i);
-    m_stats.txPreq ++;
-    m_stats.txMgt ++;
-    m_stats.txMgtBytes += packet->GetSize ();
-    m_parent->SendManagementFrame(packet, hdr);
-  }
-  //erase queue
-  m_preqQueue.erase (m_preqQueue.begin());
-}
-void
-HwmpMacPlugin::SendOnePerr()
-{
-  if(m_perrTimer.IsRunning ())
-    return;
-  if(m_myPerr.receivers.size () >= m_protocol->GetUnicastPerrThreshold ())
-  {
-    m_myPerr.receivers.clear ();
-    m_myPerr.receivers.push_back (Mac48Address::GetBroadcast ());
-  }
-  m_perrTimer = Simulator::Schedule (m_protocol->GetPerrMinInterval (), &HwmpMacPlugin::SendOnePerr, this);
-//Create packet
-  Ptr<Packet> packet  = Create<Packet> ();
-  packet->AddHeader(m_myPerr.perr);
-  //Action header:
-  WifiMeshActionHeader actionHdr;
-  WifiMeshActionHeader::ActionValue action;
-  action.pathSelection = WifiMeshActionHeader::PATH_ERROR;
-  actionHdr.SetAction (WifiMeshActionHeader::MESH_PATH_SELECTION, action);
-  packet->AddHeader (actionHdr);
-  //create 802.11 header:
-  WifiMacHeader hdr;
-  hdr.SetAction ();
-  hdr.SetDsNotFrom ();
-  hdr.SetDsNotTo ();
-  hdr.SetAddr2 (m_parent->GetAddress ());
-  hdr.SetAddr3 (m_protocol->GetAddress ());
-  //Send Management frame
-  for(std::vector<Mac48Address>::const_iterator i = m_myPerr.receivers.begin (); i != m_myPerr.receivers.end (); i ++)
-  {
-    hdr.SetAddr1 (*i);
-    m_stats.txPerr ++;
-    m_stats.txMgt ++;
-    m_stats.txMgtBytes += packet->GetSize ();
-    m_parent->SendManagementFrame(packet, hdr);
-  }
-  m_myPerr.perr.ResetPerr ();
-  m_myPerr.receivers.clear ();
-}
-void
-HwmpMacPlugin::SendPrep (IePrep prep, Mac48Address receiver)
-{
-  //Create packet
-  Ptr<Packet> packet  = Create<Packet> ();
-  packet->AddHeader(prep);
-  //Action header:
-  WifiMeshActionHeader actionHdr;
-  WifiMeshActionHeader::ActionValue action;
-  action.pathSelection = WifiMeshActionHeader::PATH_REPLY;
-  actionHdr.SetAction (WifiMeshActionHeader::MESH_PATH_SELECTION, action);
-  packet->AddHeader (actionHdr);
-  //create 802.11 header:
-  WifiMacHeader hdr;
-  hdr.SetAction ();
-  hdr.SetDsNotFrom ();
-  hdr.SetDsNotTo ();
-  hdr.SetAddr1 (receiver);
-  hdr.SetAddr2 (m_parent->GetAddress ());
-  hdr.SetAddr3 (m_protocol->GetAddress ());
-  //Send Management frame
-  m_stats.txPrep ++;
-  m_stats.txMgt ++;
-  m_stats.txMgtBytes += packet->GetSize ();
-  m_parent->SendManagementFrame(packet, hdr);
-}
-void
-HwmpMacPlugin::SendPerr(IePerr perr, std::vector<Mac48Address> receivers)
-{
-  m_myPerr.perr.Merge(perr);
-  for(unsigned int i = 0; i < receivers.size (); i ++)
-  {
-    bool should_add = true;
-    for (unsigned int j = 0; j < m_myPerr.receivers.size (); j ++)
-      if(receivers[j] == m_myPerr.receivers[i])
-        should_add = false;
-    if(should_add)
-      m_myPerr.receivers.push_back(receivers[i]);
-  }
-  SendOnePerr ();
-}
-uint32_t
-HwmpMacPlugin::GetLinkMetric(Mac48Address peerAddress) const
-{
-  return m_parent->GetLinkMetric(peerAddress);
-}
-uint16_t
-HwmpMacPlugin::GetChannelId () const
-{
-  return m_parent->GetFrequencyChannel ();
-}
-void
-HwmpMacPlugin::Statistics::Print (std::ostream & os) const
-{
-  os << "<Statistics "
-    "txPreq= \"" << txPreq << "\"\n"
-    "txPrep=\"" << txPrep << "\"\n"
-    "txPerr=\"" << txPerr << "\"\n"
-    "rxPreq=\"" << rxPreq << "\"\n"
-    "rxPrep=\"" << rxPrep << "\"\n"
-    "rxPerr=\"" << rxPerr << "\"\n"
-    "txMgt=\"" << txMgt << "\"\n"
-    "txMgtBytes=\"" << (double)txMgtBytes  / 1024.0 << "K\"\n"
-    "rxMgt=\"" << rxMgt << "\"\n"
-    "rxMgtBytes=\"" << (double)rxMgtBytes / 1204.0 << "K\"\n"
-    "txData=\"" << txData << "\"\n"
-    "txDataBytes=\"" << (double)txDataBytes / 1024.0 << "K\"\n"
-    "rxData=\"" << rxData << "\"\n"
-    "rxDataBytes=\"" << (double)rxDataBytes / 1024.0 << "K\"/>\n";
-}
-void
-HwmpMacPlugin::Report (std::ostream & os) const
-{
-  os << "<HwmpMacPlugin\n"
-    "address =\""<< m_parent->GetAddress () <<"\">\n";
-  m_stats.Print(os);
-  os << "</HwmpMacPlugin>\n";
-}
-void
-HwmpMacPlugin::ResetStats ()
-{
-  m_stats = Statistics::Statistics ();
-}
-
-} //namespace dot11s
-}//namespace ns3
--- a/src/devices/mesh/dot11s/hwmp-mac-plugin.h	Thu Jun 18 16:51:28 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008,2009 IITP RAS
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Kirill Andreev <andreev@iitp.ru>
- */
-
-
-#ifndef HWMP_STATE_H
-#define HWMP_STATE_H
-
-#include "ns3/mesh-wifi-interface-mac-plugin.h"
-#include "ie-dot11s-perr.h"
-
-namespace ns3 {
-
-class MeshWifiInterfaceMac;
-
-namespace dot11s {
-
-class HwmpProtocol;
-class IePreq;
-class IePrep;
-class IePerr;
-
-/**
- * \ingroup dot11s
- * 
- * \brief Interface MAC plugin for HWMP -- 802.11s routing protocol
- */
-class HwmpMacPlugin : public MeshWifiInterfaceMacPlugin
-{
-public:
-  HwmpMacPlugin (uint32_t, Ptr<HwmpProtocol>);
-  ~HwmpMacPlugin ();
-  ///\name Inherited from MAC plugin
-  //\{
-  void SetParent (Ptr<MeshWifiInterfaceMac> parent);
-  bool Receive (Ptr<Packet> packet, const WifiMacHeader & header);
-  bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
-  /// Update beacon is empty, because HWMP does not know anything about beacons
-  void UpdateBeacon (MeshWifiBeacon & beacon) const {};
-  //\}
-  
-private:
-  friend class HwmpProtocol;
-  
-  ///\name Intercation with HWMP:
-  //\{
-  void SendPreq(IePreq preq);
-  void SendPrep(IePrep prep, Mac48Address receiver);
-  void SendPerr(IePerr perr, std::vector<Mac48Address> receivers);
-  /** \brief Request a destination. If can not send preq immediately -
-   * add a destination to exisying PREQ generated by me and stored in
-   * PREQ queue
-   * \param originator_seqno is a sequence number that shall be preq originator sequenece number
-   * \param dst_seqno is a sequence number taken from routing table
-   */
-  void RequestDestination (Mac48Address dest, uint32_t originator_seqno, uint32_t dst_seqno);
-  //\}
-  
-  /// Sends one PREQ when PreqMinInterval after last PREQ expires (if any PREQ exists in rhe queue)
-  void SendOnePreq ();
-  void SendOnePerr ();
-  /// \return metric to HWMP protocol, needed only by metrics to add
-  //peer as routing entry
-  uint32_t GetLinkMetric (Mac48Address peerAddress) const;
-  uint16_t GetChannelId () const;
-  /// Report statistics
-  void Report (std::ostream &) const;
-  void ResetStats ();
-private:
-  Ptr<MeshWifiInterfaceMac> m_parent;
-  uint32_t m_ifIndex;
-  Ptr<HwmpProtocol> m_protocol;
-  
-  ///\name PREQ queue and PREQ timer:
-  //\{
-  EventId  m_preqTimer;
-  std::vector<IePreq>  m_preqQueue;
-  //\}
-  ///\name PERR timer and stored path error
-  //\{
-  EventId m_perrTimer;
-  struct MyPerr {
-    IePerr perr;
-    std::vector<Mac48Address> receivers;
-  };
-  MyPerr m_myPerr;
-  ///\name Statistics:
-  //\{
-  struct Statistics
-  {
-    uint16_t txPreq;
-    uint16_t rxPreq;
-    uint16_t txPrep;
-    uint16_t rxPrep;
-    uint16_t txPerr;
-    uint16_t rxPerr;
-    uint16_t txMgt;
-    uint32_t txMgtBytes;
-    uint16_t rxMgt;
-    uint32_t rxMgtBytes;
-    uint16_t txData;
-    uint32_t txDataBytes;
-    uint16_t rxData;
-    uint32_t rxDataBytes;
-    void Print (std::ostream & os) const;
-    Statistics () : 
-      txPreq (0), 
-      rxPreq (0),
-      txPrep (0),
-      rxPrep (0),
-      txPerr (0),
-      rxPerr (0),
-      txMgt (0),
-      txMgtBytes (0),
-      rxMgt (0),
-      rxMgtBytes (0),
-      txData (0),
-      txDataBytes (0),
-      rxData (0),
-      rxDataBytes (0)
-      {}
-  };
-  Statistics m_stats;
-  //\}
-private:
-  /// Receive data frame
-  bool ReceiveData (Ptr<Packet> packet, const WifiMacHeader & header);
-  /// Receive action management frame
-  bool ReceiveAction (Ptr<Packet> packet, const WifiMacHeader & header);
-};
-} //namespace dot11s
-} //namespace ns3
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/dot11s/hwmp-protocol-mac.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -0,0 +1,360 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ */
+
+#include "ns3/mesh-wifi-interface-mac.h"
+#include "ns3/packet.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/log.h"
+#include "dot11s-mac-header.h"
+#include "hwmp-protocol.h"
+#include "hwmp-protocol-mac.h"
+#include "hwmp-tag.h"
+#include "ie-dot11s-preq.h"
+#include "ie-dot11s-prep.h"
+
+namespace ns3 {
+namespace dot11s {
+
+NS_LOG_COMPONENT_DEFINE ("HwmpProtocolMac");
+HwmpProtocolMac::HwmpProtocolMac (uint32_t ifIndex, Ptr<HwmpProtocol> protocol):
+  m_ifIndex (ifIndex),
+  m_protocol (protocol)
+{
+}
+HwmpProtocolMac::~HwmpProtocolMac ()
+{
+}
+void
+HwmpProtocolMac::SetParent (Ptr<MeshWifiInterfaceMac> parent)
+{
+  m_parent = parent;
+}
+
+bool
+HwmpProtocolMac::ReceiveData (Ptr<Packet> packet, const WifiMacHeader & header)
+{
+  NS_ASSERT (header.IsData());
+
+  MeshHeader meshHdr;
+  HwmpTag tag;
+  if(packet->PeekPacketTag (tag))
+  {
+    NS_FATAL_ERROR ("HWMP tag is not supposed to be received by network");
+  }
+  
+  packet->RemoveHeader(meshHdr);
+  m_stats.rxData ++;
+  m_stats.rxDataBytes += packet->GetSize ();
+  
+  //TODO: address extension
+  Mac48Address destination;
+  Mac48Address source;
+  switch (meshHdr.GetAddressExt ())
+  {
+    case 0:
+      source = header.GetAddr4 ();
+      destination = header.GetAddr3 ();
+      break;
+    default:
+      NS_FATAL_ERROR ("6-address scheme is not yet supported and 4-address extension is not supposed to be used for data frames.");
+  };
+  tag.SetSeqno (meshHdr.GetMeshSeqno ());
+  tag.SetTtl (meshHdr.GetMeshTtl ());
+  packet->AddPacketTag(tag);
+ 
+  if (destination == Mac48Address::GetBroadcast ())
+    if(m_protocol->DropDataFrame (meshHdr.GetMeshSeqno (), source))
+      return false;
+  
+  return true;
+}
+
+bool
+HwmpProtocolMac::ReceiveAction (Ptr<Packet> packet, const WifiMacHeader & header)
+{
+  m_stats.rxMgt ++;
+  m_stats.rxMgtBytes += packet->GetSize ();
+  WifiMeshActionHeader actionHdr;
+  packet->RemoveHeader (actionHdr);
+  WifiMeshActionHeader::ActionValue actionValue = actionHdr.GetAction ();
+  if(actionHdr.GetCategory () != WifiMeshActionHeader::MESH_PATH_SELECTION)
+    return true;
+  switch (actionValue.pathSelection)
+  {
+    case WifiMeshActionHeader::PATH_REQUEST:
+      {
+        IePreq preq;
+        m_stats.rxPreq ++;
+        packet->RemoveHeader (preq);
+        if(preq.GetOriginatorAddress () == m_protocol->GetAddress ())
+          return false;
+        if (preq.GetTtl () == 0)
+          return false;
+        preq.DecrementTtl ();
+        m_protocol->ReceivePreq (preq, header.GetAddr2 (), m_ifIndex, header.GetAddr3 (), m_parent->GetLinkMetric(header.GetAddr2 ()));
+        return false;
+      }
+    case WifiMeshActionHeader::PATH_REPLY:
+      {
+        IePrep prep;
+        m_stats.rxPrep ++;
+        packet->RemoveHeader (prep);
+        if(prep.GetTtl () == 0)
+          return false;
+        prep.DecrementTtl ();
+        m_protocol->ReceivePrep (prep, header.GetAddr2 (), m_ifIndex, header.GetAddr3 (), m_parent->GetLinkMetric(header.GetAddr2 ()));
+        return false;
+      }
+    case WifiMeshActionHeader::PATH_ERROR:
+      {
+        IePerr perr;
+        m_stats.rxPerr ++;
+        packet->RemoveHeader (perr);
+        m_protocol->ReceivePerr (perr, header.GetAddr2 (), m_ifIndex, header.GetAddr3 ());
+        return false;
+      }
+    case WifiMeshActionHeader::ROOT_ANNOUNCEMENT:
+      return false;
+  }
+  return true;
+}
+
+bool
+HwmpProtocolMac::Receive (Ptr<Packet> packet, const WifiMacHeader & header)
+{
+  if (header.IsData ())
+    return ReceiveData (packet, header);
+  else if (header.IsAction ())
+    return ReceiveAction (packet, header);
+  else
+    return true; // don't care
+}
+bool
+HwmpProtocolMac::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to)
+{
+  if(!header.IsData ())
+    return true;
+  HwmpTag tag;
+  bool tagExists = packet->RemovePacketTag(tag);
+  if (!tagExists)
+  {
+    NS_FATAL_ERROR ("HWMP tag must exist at this point");
+  }
+  m_stats.txData ++;
+  m_stats.txDataBytes += packet->GetSize ();
+  MeshHeader meshHdr;
+  meshHdr.SetMeshSeqno(tag.GetSeqno());
+  meshHdr.SetMeshTtl(tag.GetTtl());
+  packet->AddHeader(meshHdr);
+  header.SetAddr1(tag.GetAddress());
+  return true;
+}
+void
+HwmpProtocolMac::SendPreq(IePreq preq)
+{
+  m_preqQueue.push_back (preq);
+  SendOnePreq ();
+}
+void
+HwmpProtocolMac::RequestDestination (Mac48Address dst, uint32_t originator_seqno, uint32_t dst_seqno)
+{
+  for(std::vector<IePreq>::iterator i = m_preqQueue.begin (); i != m_preqQueue.end (); i ++)
+    if(i->MayAddAddress(m_protocol->GetAddress ()))
+    {
+      i->AddDestinationAddressElement (m_protocol->GetDoFlag(), m_protocol->GetRfFlag(), dst, dst_seqno);
+      return;
+    }
+  IePreq preq;
+  //fill PREQ:
+  preq.SetHopcount (0);
+  preq.SetTTL (m_protocol->GetMaxTtl ());
+  preq.SetPreqID (m_protocol->GetNextPreqId ());
+  preq.SetOriginatorAddress (m_protocol->GetAddress ());
+  preq.SetOriginatorSeqNumber (originator_seqno);
+  preq.SetLifetime (m_protocol->GetActivePathLifetime ());
+  preq.AddDestinationAddressElement (m_protocol->GetDoFlag (), m_protocol->GetRfFlag (), dst, dst_seqno);
+  m_preqQueue.push_back (preq);
+  //set iterator position to my preq:
+  SendOnePreq ();
+}
+void
+HwmpProtocolMac::SendOnePreq ()
+{
+  if(m_preqTimer.IsRunning ())
+    return;
+  if (m_preqQueue.size () == 0)
+    return;
+  //reschedule sending PREQ
+  NS_ASSERT (!m_preqTimer.IsRunning());
+  m_preqTimer = Simulator::Schedule (m_protocol->GetPreqMinInterval (), &HwmpProtocolMac::SendOnePreq, this);
+  Ptr<Packet> packet  = Create<Packet> ();
+  packet->AddHeader(m_preqQueue[0]);
+  //Action header:
+  WifiMeshActionHeader actionHdr;
+  WifiMeshActionHeader::ActionValue action;
+  action.pathSelection = WifiMeshActionHeader::PATH_REQUEST;
+  actionHdr.SetAction (WifiMeshActionHeader::MESH_PATH_SELECTION, action);
+  packet->AddHeader (actionHdr);
+  //create 802.11 header:
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+  hdr.SetAddr2 (m_parent->GetAddress ());
+  hdr.SetAddr3 (m_protocol->GetAddress ());
+  //Send Management frame
+  std::vector <Mac48Address> receivers = m_protocol->GetPreqReceivers (m_ifIndex);
+  for(std::vector<Mac48Address>::const_iterator i = receivers.begin (); i != receivers.end (); i ++)
+  {
+    hdr.SetAddr1 (*i);
+    m_stats.txPreq ++;
+    m_stats.txMgt ++;
+    m_stats.txMgtBytes += packet->GetSize ();
+    m_parent->SendManagementFrame(packet, hdr);
+  }
+  //erase queue
+  m_preqQueue.erase (m_preqQueue.begin());
+}
+void
+HwmpProtocolMac::SendOnePerr()
+{
+  if(m_perrTimer.IsRunning ())
+    return;
+  if(m_myPerr.receivers.size () >= m_protocol->GetUnicastPerrThreshold ())
+  {
+    m_myPerr.receivers.clear ();
+    m_myPerr.receivers.push_back (Mac48Address::GetBroadcast ());
+  }
+  m_perrTimer = Simulator::Schedule (m_protocol->GetPerrMinInterval (), &HwmpProtocolMac::SendOnePerr, this);
+//Create packet
+  Ptr<Packet> packet  = Create<Packet> ();
+  packet->AddHeader(m_myPerr.perr);
+  //Action header:
+  WifiMeshActionHeader actionHdr;
+  WifiMeshActionHeader::ActionValue action;
+  action.pathSelection = WifiMeshActionHeader::PATH_ERROR;
+  actionHdr.SetAction (WifiMeshActionHeader::MESH_PATH_SELECTION, action);
+  packet->AddHeader (actionHdr);
+  //create 802.11 header:
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+  hdr.SetAddr2 (m_parent->GetAddress ());
+  hdr.SetAddr3 (m_protocol->GetAddress ());
+  //Send Management frame
+  for(std::vector<Mac48Address>::const_iterator i = m_myPerr.receivers.begin (); i != m_myPerr.receivers.end (); i ++)
+  {
+    hdr.SetAddr1 (*i);
+    m_stats.txPerr ++;
+    m_stats.txMgt ++;
+    m_stats.txMgtBytes += packet->GetSize ();
+    m_parent->SendManagementFrame(packet, hdr);
+  }
+  m_myPerr.perr.ResetPerr ();
+  m_myPerr.receivers.clear ();
+}
+void
+HwmpProtocolMac::SendPrep (IePrep prep, Mac48Address receiver)
+{
+  //Create packet
+  Ptr<Packet> packet  = Create<Packet> ();
+  packet->AddHeader(prep);
+  //Action header:
+  WifiMeshActionHeader actionHdr;
+  WifiMeshActionHeader::ActionValue action;
+  action.pathSelection = WifiMeshActionHeader::PATH_REPLY;
+  actionHdr.SetAction (WifiMeshActionHeader::MESH_PATH_SELECTION, action);
+  packet->AddHeader (actionHdr);
+  //create 802.11 header:
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+  hdr.SetAddr1 (receiver);
+  hdr.SetAddr2 (m_parent->GetAddress ());
+  hdr.SetAddr3 (m_protocol->GetAddress ());
+  //Send Management frame
+  m_stats.txPrep ++;
+  m_stats.txMgt ++;
+  m_stats.txMgtBytes += packet->GetSize ();
+  m_parent->SendManagementFrame(packet, hdr);
+}
+void
+HwmpProtocolMac::SendPerr(IePerr perr, std::vector<Mac48Address> receivers)
+{
+  m_myPerr.perr.Merge(perr);
+  for(unsigned int i = 0; i < receivers.size (); i ++)
+  {
+    bool should_add = true;
+    for (unsigned int j = 0; j < m_myPerr.receivers.size (); j ++)
+      if(receivers[j] == m_myPerr.receivers[i])
+        should_add = false;
+    if(should_add)
+      m_myPerr.receivers.push_back(receivers[i]);
+  }
+  SendOnePerr ();
+}
+uint32_t
+HwmpProtocolMac::GetLinkMetric(Mac48Address peerAddress) const
+{
+  return m_parent->GetLinkMetric(peerAddress);
+}
+uint16_t
+HwmpProtocolMac::GetChannelId () const
+{
+  return m_parent->GetFrequencyChannel ();
+}
+void
+HwmpProtocolMac::Statistics::Print (std::ostream & os) const
+{
+  os << "<Statistics "
+    "txPreq= \"" << txPreq << "\"\n"
+    "txPrep=\"" << txPrep << "\"\n"
+    "txPerr=\"" << txPerr << "\"\n"
+    "rxPreq=\"" << rxPreq << "\"\n"
+    "rxPrep=\"" << rxPrep << "\"\n"
+    "rxPerr=\"" << rxPerr << "\"\n"
+    "txMgt=\"" << txMgt << "\"\n"
+    "txMgtBytes=\"" << (double)txMgtBytes  / 1024.0 << "K\"\n"
+    "rxMgt=\"" << rxMgt << "\"\n"
+    "rxMgtBytes=\"" << (double)rxMgtBytes / 1204.0 << "K\"\n"
+    "txData=\"" << txData << "\"\n"
+    "txDataBytes=\"" << (double)txDataBytes / 1024.0 << "K\"\n"
+    "rxData=\"" << rxData << "\"\n"
+    "rxDataBytes=\"" << (double)rxDataBytes / 1024.0 << "K\"/>\n";
+}
+void
+HwmpProtocolMac::Report (std::ostream & os) const
+{
+  os << "<HwmpProtocolMac\n"
+    "address =\""<< m_parent->GetAddress () <<"\">\n";
+  m_stats.Print(os);
+  os << "</HwmpProtocolMac>\n";
+}
+void
+HwmpProtocolMac::ResetStats ()
+{
+  m_stats = Statistics::Statistics ();
+}
+
+} //namespace dot11s
+}//namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/dot11s/hwmp-protocol-mac.h	Thu Jun 18 18:07:22 2009 +0400
@@ -0,0 +1,149 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ */
+
+
+#ifndef HWMP_STATE_H
+#define HWMP_STATE_H
+
+#include "ns3/mesh-wifi-interface-mac-plugin.h"
+#include "ie-dot11s-perr.h"
+
+namespace ns3 {
+
+class MeshWifiInterfaceMac;
+
+namespace dot11s {
+
+class HwmpProtocol;
+class IePreq;
+class IePrep;
+class IePerr;
+
+/**
+ * \ingroup dot11s
+ * 
+ * \brief Interface MAC plugin for HWMP -- 802.11s routing protocol
+ */
+class HwmpProtocolMac : public MeshWifiInterfaceMacPlugin
+{
+public:
+  HwmpProtocolMac (uint32_t, Ptr<HwmpProtocol>);
+  ~HwmpProtocolMac ();
+  ///\name Inherited from MAC plugin
+  //\{
+  void SetParent (Ptr<MeshWifiInterfaceMac> parent);
+  bool Receive (Ptr<Packet> packet, const WifiMacHeader & header);
+  bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
+  /// Update beacon is empty, because HWMP does not know anything about beacons
+  void UpdateBeacon (MeshWifiBeacon & beacon) const {};
+  //\}
+  
+private:
+  friend class HwmpProtocol;
+  
+  ///\name Intercation with HWMP:
+  //\{
+  void SendPreq(IePreq preq);
+  void SendPrep(IePrep prep, Mac48Address receiver);
+  void SendPerr(IePerr perr, std::vector<Mac48Address> receivers);
+  /** \brief Request a destination. If can not send preq immediately -
+   * add a destination to exisying PREQ generated by me and stored in
+   * PREQ queue
+   * \param originator_seqno is a sequence number that shall be preq originator sequenece number
+   * \param dst_seqno is a sequence number taken from routing table
+   */
+  void RequestDestination (Mac48Address dest, uint32_t originator_seqno, uint32_t dst_seqno);
+  //\}
+  
+  /// Sends one PREQ when PreqMinInterval after last PREQ expires (if any PREQ exists in rhe queue)
+  void SendOnePreq ();
+  void SendOnePerr ();
+  /// \return metric to HWMP protocol, needed only by metrics to add
+  //peer as routing entry
+  uint32_t GetLinkMetric (Mac48Address peerAddress) const;
+  uint16_t GetChannelId () const;
+  /// Report statistics
+  void Report (std::ostream &) const;
+  void ResetStats ();
+private:
+  Ptr<MeshWifiInterfaceMac> m_parent;
+  uint32_t m_ifIndex;
+  Ptr<HwmpProtocol> m_protocol;
+  
+  ///\name PREQ queue and PREQ timer:
+  //\{
+  EventId  m_preqTimer;
+  std::vector<IePreq>  m_preqQueue;
+  //\}
+  ///\name PERR timer and stored path error
+  //\{
+  EventId m_perrTimer;
+  struct MyPerr {
+    IePerr perr;
+    std::vector<Mac48Address> receivers;
+  };
+  MyPerr m_myPerr;
+  ///\name Statistics:
+  //\{
+  struct Statistics
+  {
+    uint16_t txPreq;
+    uint16_t rxPreq;
+    uint16_t txPrep;
+    uint16_t rxPrep;
+    uint16_t txPerr;
+    uint16_t rxPerr;
+    uint16_t txMgt;
+    uint32_t txMgtBytes;
+    uint16_t rxMgt;
+    uint32_t rxMgtBytes;
+    uint16_t txData;
+    uint32_t txDataBytes;
+    uint16_t rxData;
+    uint32_t rxDataBytes;
+    void Print (std::ostream & os) const;
+    Statistics () : 
+      txPreq (0), 
+      rxPreq (0),
+      txPrep (0),
+      rxPrep (0),
+      txPerr (0),
+      rxPerr (0),
+      txMgt (0),
+      txMgtBytes (0),
+      rxMgt (0),
+      rxMgtBytes (0),
+      txData (0),
+      txDataBytes (0),
+      rxData (0),
+      rxDataBytes (0)
+      {}
+  };
+  Statistics m_stats;
+  //\}
+private:
+  /// Receive data frame
+  bool ReceiveData (Ptr<Packet> packet, const WifiMacHeader & header);
+  /// Receive action management frame
+  bool ReceiveAction (Ptr<Packet> packet, const WifiMacHeader & header);
+};
+} //namespace dot11s
+} //namespace ns3
+#endif
--- a/src/devices/mesh/dot11s/hwmp-protocol.cc	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -20,7 +20,7 @@
 
 
 #include "hwmp-protocol.h"
-#include "hwmp-mac-plugin.h"
+#include "hwmp-protocol-mac.h"
 #include "hwmp-tag.h"
 #include "hwmp-rtable.h"
 #include "ns3/log.h"
@@ -622,7 +622,7 @@
       if (mac == 0)
         return false;
       // Installing plugins:
-      Ptr<HwmpMacPlugin> hwmpMac = Create<HwmpMacPlugin> (wifiNetDev->GetIfIndex (), this);
+      Ptr<HwmpProtocolMac> hwmpMac = Create<HwmpProtocolMac> (wifiNetDev->GetIfIndex (), this);
       m_interfaces[wifiNetDev->GetIfIndex ()] = hwmpMac;
       mac->InstallPlugin (hwmpMac);
       //Installing airtime link metric:
--- a/src/devices/mesh/dot11s/hwmp-protocol.h	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.h	Thu Jun 18 18:07:22 2009 +0400
@@ -34,7 +34,7 @@
 class Packet;
 class Mac48Address;
 namespace dot11s {
-class HwmpMacPlugin;
+class HwmpProtocolMac;
 class HwmpRtable;
 class IePreq;
 class IePrep;
@@ -80,7 +80,7 @@
   void Report (std::ostream &) const;
   void ResetStats ();
 private:
-  friend class HwmpMacPlugin;
+  friend class HwmpProtocolMac;
   
   /// Like RequestRoute, but for unicast packets
   bool ForwardUnicast (uint32_t  sourceIface, const Mac48Address source, const Mac48Address destination,
@@ -181,7 +181,7 @@
   ///\return address of MeshPointDevice
   Mac48Address GetAddress (); 
 private:
-  typedef std::map<uint32_t, Ptr<HwmpMacPlugin> > HwmpPluginMap;
+  typedef std::map<uint32_t, Ptr<HwmpProtocolMac> > HwmpPluginMap;
   HwmpPluginMap m_interfaces;
   Mac48Address m_address;
   uint32_t m_dataSeqno;
--- a/src/devices/mesh/dot11s/peer-link.cc	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/peer-link.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -267,7 +267,7 @@
   return (m_state == IDLE);
 }
 void
-PeerLink::SetMacPlugin(Ptr<PeerManagerMacPlugin> plugin)
+PeerLink::SetMacPlugin(Ptr<PeerManagementProtocolMac> plugin)
 {
   m_macPlugin = plugin;
 }
--- a/src/devices/mesh/dot11s/peer-link.h	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/peer-link.h	Thu Jun 18 18:07:22 2009 +0400
@@ -29,7 +29,7 @@
 #include "ie-dot11s-beacon-timing.h"
 #include "ie-dot11s-peer-management.h"
 #include "ie-dot11s-configuration.h"
-#include "peer-management-plugin.h"
+#include "peer-management-protocol-mac.h"
 namespace ns3 {
 namespace dot11s {
 /**
@@ -143,7 +143,7 @@
    * Set pointer to MAC-plugin, which is responsible for sending peer
    * link management frames
    */
-  void SetMacPlugin(Ptr<PeerManagerMacPlugin> plugin);
+  void SetMacPlugin(Ptr<PeerManagementProtocolMac> plugin);
   /// Peer link states, see 802.11s draft 11B.3.3.1
 private:
   /// Peer link events, see 802.11s draft 11B.3.3.2
@@ -201,7 +201,7 @@
   ///The number of interface I am associated with
   uint32_t m_interface;
   /// pointer to mac plugin, which is responsible for peer management
-  Ptr<PeerManagerMacPlugin> m_macPlugin;
+  Ptr<PeerManagementProtocolMac> m_macPlugin;
   /// Peer address
   Mac48Address m_peerAddress;
   /// Mesh point address, equal to peer address in case of single
--- a/src/devices/mesh/dot11s/peer-management-plugin.cc	Thu Jun 18 16:51:28 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,317 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/* 
- * Copyright (c) 2009 IITP RAS
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
- * Author: Kirill Andreev <andreev@iitp.ru>
- */
-
-#include "ie-dot11s-configuration.h"
-#include "ie-dot11s-peer-management.h"
-#include "dot11s-mac-header.h"
-#include "peer-management-plugin.h"
-#include "peer-management-protocol.h"
-#include "peer-link-frame.h"
-#include "ns3/mesh-wifi-interface-mac.h"
-#include "ns3/simulator.h"
-#include "ns3/wifi-mac-header.h"
-namespace ns3 {
-namespace dot11s {
-PeerManagerMacPlugin::PeerManagerMacPlugin (uint32_t interface, Ptr<PeerManagementProtocol> protocol)
-{
-  m_ifIndex = interface;
-  m_protocol = protocol;
-}
-
-PeerManagerMacPlugin::~PeerManagerMacPlugin ()
-{
-}
-
-void
-PeerManagerMacPlugin::SetParent (Ptr<MeshWifiInterfaceMac> parent)
-{
-  m_parent = 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())
-  {
-    IeBeaconTiming beaconTiming;
-    IeMeshId meshId;
-    Ptr<Packet> myBeacon = packet->Copy();
-    MgtBeaconHeader beacon_hdr;
-    myBeacon->RemoveHeader(beacon_hdr);
-    meshId.FindFirst(myBeacon);
-    bool meshBeacon = false;
-    if (
-        (beaconTiming.FindFirst(myBeacon)) &&
-        (m_protocol->GetMeshId ()->IsEqual(meshId))
-        )
-      meshBeacon = true;
-    m_protocol->UpdatePeerBeaconTiming(
-        m_ifIndex,
-        meshBeacon,
-        beaconTiming,
-        header.GetAddr2(),
-        Simulator::Now(),
-        MicroSeconds(beacon_hdr.GetBeaconIntervalUs())
-        );
-    // Beacon shall not be dropeed. May be needed to another plugins
-    return true;
-  }
-  if(header.IsAction())
-  {
-    WifiMeshActionHeader actionHdr;
-    packet->RemoveHeader (actionHdr);
-    WifiMeshActionHeader::ActionValue actionValue = actionHdr.GetAction ();
-    // If can not handle - just return;
-    if(actionHdr.GetCategory () != WifiMeshActionHeader::MESH_PEERING_MGT)
-      return m_protocol->IsActiveLink(m_ifIndex,header.GetAddr2());
-    m_stats.rxMgt ++;
-    m_stats.rxMgtBytes += packet->GetSize ();
-    Mac48Address peerAddress = header.GetAddr2 ();
-    Mac48Address peerMpAddress = header.GetAddr3 ();
-    PeerLinkFrameStart::PlinkFrameStartFields fields;
-    {
-      PeerLinkFrameStart peerFrame;
-      peerFrame.SetPlinkFrameSubtype((uint8_t)actionValue.peerLink);
-      packet->RemoveHeader (peerFrame);
-      fields = peerFrame.GetFields();
-      NS_ASSERT(fields.subtype == actionValue.peerLink);
-    }
-    if (
-        (actionValue.peerLink != WifiMeshActionHeader::PEER_LINK_CLOSE) &&
-        !(m_parent->CheckSupportedRates(fields.rates))
-        )
-      {
-        m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress);
-        // Broken peer link frame - drop it
-        m_stats.brokenMgt ++;
-        return false;
-      }
-    if (
-        (actionValue.peerLink != WifiMeshActionHeader::PEER_LINK_CONFIRM) &&
-        !fields.meshId.IsEqual(*(m_protocol->GetMeshId()))
-        )
-      {
-        m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress);
-        // Broken peer link frame - drop it
-        m_stats.brokenMgt ++;
-        return false;
-      }
-    IePeerManagement peerElement;
-    packet->RemoveHeader(peerElement);
-    //Check taht frame subtype corresponds peer link subtype
-    if(peerElement.SubtypeIsOpen ())
-    {
-      m_stats.rxOpen ++;
-      NS_ASSERT(actionValue.peerLink == WifiMeshActionHeader::PEER_LINK_OPEN);
-    }
-    if(peerElement.SubtypeIsConfirm ())
-    {
-      m_stats.rxConfirm ++;
-      NS_ASSERT(actionValue.peerLink == WifiMeshActionHeader::PEER_LINK_CONFIRM);
-    }
-    if(peerElement.SubtypeIsClose ())
-    {
-      m_stats.rxClose ++;
-      NS_ASSERT(actionValue.peerLink == WifiMeshActionHeader::PEER_LINK_CLOSE);
-    }
-    //Deliver Peer link management frame to protocol:
-    m_protocol->ReceivePeerLinkFrame(m_ifIndex, peerAddress, peerMpAddress, fields.aid, peerElement, fields.config);
-    // if we can handle a frame - drop it
-    return false;
-  }
-  return m_protocol->IsActiveLink(m_ifIndex,header.GetAddr2());
-}
-bool
-PeerManagerMacPlugin::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to)
-{
-  if(header.IsAction ())
-  {
-    WifiMeshActionHeader actionHdr;
-    packet->PeekHeader (actionHdr);
-    WifiMeshActionHeader::ActionValue actionValue = actionHdr.GetAction ();
-    if(actionHdr.GetCategory () == WifiMeshActionHeader::MESH_PEERING_MGT)
-      return true;
-  }
-  if(header.GetAddr1 ().IsGroup ())
-    return true;
-  else
-  {
-    if(m_protocol->IsActiveLink(m_ifIndex,header.GetAddr1()))
-      return true;
-    else
-    {
-      m_stats.dropped ++;
-      return false;
-    }
-  }
-}
-void
-PeerManagerMacPlugin::UpdateBeacon (MeshWifiBeacon & beacon) const
-{
-  Ptr<IeBeaconTiming>  beaconTiming = m_protocol->GetBeaconTimingElement(m_ifIndex);
-  beacon.AddInformationElement(beaconTiming);
-  beacon.AddInformationElement(m_protocol->GetMeshId ());
-}
-
-void
-PeerManagerMacPlugin::SendPeerLinkManagementFrame(
-      Mac48Address peerAddress,
-      Mac48Address peerMpAddress,
-      uint16_t aid,
-      IePeerManagement peerElement,
-      IeConfiguration meshConfig
-      )
-{
-  //Create a packet:
-  meshConfig.SetNeighborCount (m_protocol->GetNumberOfLinks ());
-  Ptr<Packet> packet = Create<Packet> ();
-  packet->AddHeader (peerElement);
-  PeerLinkFrameStart::PlinkFrameStartFields fields;
-  fields.rates = m_parent->GetSupportedRates ();
-  fields.capability = 0;
-  fields.meshId = *(m_protocol->GetMeshId ());
-  fields.config = meshConfig;
-  PeerLinkFrameStart plinkFrame;
-  //Create an 802.11 frame header:
-  //Send management frame to MAC:
-  WifiMeshActionHeader actionHdr;
-  if (peerElement.SubtypeIsOpen ())
-    {
-      m_stats.txOpen ++;
-      WifiMeshActionHeader::ActionValue action;
-      action.peerLink = WifiMeshActionHeader::PEER_LINK_OPEN;
-      fields.subtype = WifiMeshActionHeader::PEER_LINK_OPEN;
-      actionHdr.SetAction (WifiMeshActionHeader::MESH_PEERING_MGT, action);
-    }
-  if (peerElement.SubtypeIsConfirm ())
-    {
-      m_stats.txConfirm ++;
-      WifiMeshActionHeader::ActionValue action;
-      action.peerLink = WifiMeshActionHeader::PEER_LINK_CONFIRM;
-      fields.aid = aid;
-      fields.subtype = WifiMeshActionHeader::PEER_LINK_CONFIRM;
-      actionHdr.SetAction (WifiMeshActionHeader::MESH_PEERING_MGT, action);
-    }
-  if (peerElement.SubtypeIsClose ())
-    {
-      m_stats.txClose ++;
-      WifiMeshActionHeader::ActionValue action;
-      action.peerLink = WifiMeshActionHeader::PEER_LINK_CLOSE;
-      fields.subtype = WifiMeshActionHeader::PEER_LINK_CLOSE;
-      fields.reasonCode = peerElement.GetReasonCode ();
-      actionHdr.SetAction (WifiMeshActionHeader::MESH_PEERING_MGT, action);
-    }
-  plinkFrame.SetPlinkFrameStart(fields);
-  packet->AddHeader (plinkFrame);
-  packet->AddHeader (actionHdr);
-  m_stats.txMgt ++;
-  m_stats.txMgtBytes += packet->GetSize ();
-  // Wifi Mac header:
-  WifiMacHeader hdr;
-  hdr.SetAction ();
-  hdr.SetAddr1 (peerAddress);
-  hdr.SetAddr2 (m_parent->GetAddress ());
-  //Addr is not used here, we use it as our MP address
-  hdr.SetAddr3 (m_protocol->GetAddress ());
-  hdr.SetDsNotFrom ();
-  hdr.SetDsNotTo ();
-  m_parent->SendManagementFrame(packet, hdr);
-}
-
-Mac48Address
-PeerManagerMacPlugin::GetAddress () const
-{
-  if(m_parent !=  0)
-    return m_parent->GetAddress ();
-  else return Mac48Address::Mac48Address();
-}
-std::pair<Time, Time> 
-PeerManagerMacPlugin::GetBeaconInfo() const
-{
-  std::pair<Time,Time> retval;
-  retval.first = m_parent->GetTbtt ();
-  retval.second = m_parent->GetBeaconInterval ();
-  return retval;
-}
-void
-PeerManagerMacPlugin::SetBeaconShift(Time shift)
-{
-  if(shift != Seconds (0))
-    m_stats.beaconShift ++;
-  m_parent->ShiftTbtt (shift);
-}
-PeerManagerMacPlugin::Statistics::Statistics () :
-  txOpen (0),
-  txConfirm (0),
-  txClose (0),
-  rxOpen (0),
-  rxConfirm (0),
-  rxClose (0),
-  dropped (0),
-  brokenMgt (0),
-  txMgt (0),
-  txMgtBytes (0),
-  rxMgt (0),
-  rxMgtBytes (0),
-  beaconShift (0)
-{
-}
-void
-PeerManagerMacPlugin::Statistics::Print (std::ostream & os) const
-{
-  os << "<Statistics "
-    "txOpen=\"" << txOpen << "\"\n"
-    "txConfirm=\"" << txConfirm << "\"\n"
-    "txClose=\"" << txClose << "\"\n"
-    "rxOpen=\"" << rxOpen << "\"\n"
-    "rxConfirm=\"" << rxConfirm << "\"\n"
-    "rxClose=\"" << rxClose << "\"\n"
-    "dropped=\"" << dropped << "\"\n"
-    "brokenMgt=\"" << brokenMgt << "\"\n"
-    "txMgt=\"" << txMgt << "\"\n"
-    "txMgtBytes=\"" << (double)txMgtBytes /1024.0 << "\"\n"
-    "rxMgt=\"" << rxMgt << "\"\n"
-    "rxMgtBytes=\"" << (double)rxMgtBytes / 1024.0 << "K\"\n"
-    "beaconShift=\"" << beaconShift << "\"/>\n";
-}
-void
-PeerManagerMacPlugin::Report (std::ostream & os) const
-{
-  os << "<PeerManagerPlugin "
-    "address=\"" << m_parent->GetAddress () << "\">\n";
-  m_stats.Print (os);
-  os << "</PeerManagerPlugin>\n";
-}
-void
-PeerManagerMacPlugin::ResetStats ()
-{
-  m_stats = Statistics::Statistics ();
-}
-uint32_t
-PeerManagerMacPlugin::GetLinkMetric (Mac48Address peerAddress)
-{
-  return m_parent->GetLinkMetric (peerAddress);
-}
-} // namespace dot11s
-} //namespace ns3
-
--- a/src/devices/mesh/dot11s/peer-management-plugin.h	Thu Jun 18 16:51:28 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/* 
- * Copyright (c) 2009 IITP RAS
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
- * Author: Kirill Andreev <andreev@iitp.ru>
- */
-
-#ifndef PEER_MANAGER_MAC_PLUGIN_H_
-#define PEER_MANAGER_MAC_PLUGIN_H_
-
-#include "ns3/mesh-wifi-interface-mac-plugin.h"
-
-namespace ns3 {
-class MeshWifiInterfaceMac;
-namespace dot11s {
-class PeerManagementProtocol;
-class IeConfiguration;
-class IePeerManagement;
-class PeerManagementProtocol;
-/**
- * \ingroup dot11s
- * 
- * \brief This is plugin to Mesh WiFi MAC, which implements
- * interface to dot11s peer management protocol: it takes proper
- * frames from MAC-layer, extracts peer link management information
- * element and mesh configuration element and passes it to main part
- * of protocol
- */
-class PeerManagerMacPlugin : public MeshWifiInterfaceMacPlugin
-{
-public:
-  PeerManagerMacPlugin (uint32_t interface, Ptr<PeerManagementProtocol> protocol);
-  ~PeerManagerMacPlugin ();
-  ///\name Inherited from plugin abstract class
-  ///\{
-  void SetParent (Ptr<MeshWifiInterfaceMac> parent);
-  bool Receive (Ptr<Packet> packet, const WifiMacHeader & header);
-  bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
-  void UpdateBeacon (MeshWifiBeacon & beacon) const;
-  ///\}
-  ///\name Statistics:
-  ///\{
-  void Report (std::ostream &) const;
-  void ResetStats ();
-  uint32_t GetLinkMetric (Mac48Address peerAddress);
-  ///\}
-private:
-  friend class PeerManagementProtocol;
-  friend class PeerLink; 
-  ///\name BCA functionallity:
-  ///\{
-  ///\brief Fills TBTT and beacon interval. Needed by BCA
-  ///functionallity
-  ///\param first in retval is TBTT
-  ///\param second in retval is beacon interval
-  std::pair<Time, Time> GetBeaconInfo() const;
-  void SetBeaconShift(Time shift);
-  ///\}
-  void SetPeerManagerProtcol(Ptr<PeerManagementProtocol> protocol);
-  void SendPeerLinkManagementFrame(
-      Mac48Address peerAddress,
-      Mac48Address peerMpAddress,
-      uint16_t aid,
-      IePeerManagement peerElement,
-      IeConfiguration meshConfig
-      );
-  ///\brief DUBUG only - to print established links
-  Mac48Address GetAddress () const;
-private:
-  ///\name Information about MAC and protocol:
-  ///\{
-  Ptr<MeshWifiInterfaceMac> m_parent;
-  uint32_t m_ifIndex;
-  Ptr<PeerManagementProtocol> m_protocol;
-   ///\}
-   ///\name Create peer link management frames:
-   ///\{
-  Ptr<Packet> CreatePeerLinkOpenFrame();
-  Ptr<Packet> CreatePeerLinkConfirmFrame();
-  Ptr<Packet> CreatePeerLinkCloseFrame();
-  ///This structure keeps all fields in peer link management frame,
-  ///which are not subclasses of WifiInformationElement
-  struct PlinkFrameStart {
-    uint8_t subtype;
-    uint16_t aid;
-    SupportedRates rates;
-    uint16_t qos;
-  };
-  /// \name Parses the start of the frame, where there are no
-  /// WifiInformationElements exist
-  PlinkFrameStart ParsePlinkFrame(Ptr<const Packet> packet);
-  ///\}
-  //Keeps statistics
-  struct Statistics {
-    uint16_t txOpen;
-    uint16_t txConfirm;
-    uint16_t txClose;
-    uint16_t rxOpen;
-    uint16_t rxConfirm;
-    uint16_t rxClose;
-    uint16_t dropped;
-    uint16_t brokenMgt;
-    uint16_t txMgt;
-    uint32_t txMgtBytes;
-    uint16_t rxMgt;
-    uint32_t rxMgtBytes;
-    uint16_t beaconShift;
-    
-    Statistics ();
-    void Print (std::ostream & os) const;
-  };
-  struct Statistics m_stats;
-};
-  
-} // namespace dot11s
-} //namespace ns3
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/dot11s/peer-management-protocol-mac.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -0,0 +1,317 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/* 
+ * Copyright (c) 2009 IITP RAS
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ */
+
+#include "ie-dot11s-configuration.h"
+#include "ie-dot11s-peer-management.h"
+#include "dot11s-mac-header.h"
+#include "peer-management-protocol-mac.h"
+#include "peer-management-protocol.h"
+#include "peer-link-frame.h"
+#include "ns3/mesh-wifi-interface-mac.h"
+#include "ns3/simulator.h"
+#include "ns3/wifi-mac-header.h"
+namespace ns3 {
+namespace dot11s {
+PeerManagementProtocolMac::PeerManagementProtocolMac (uint32_t interface, Ptr<PeerManagementProtocol> protocol)
+{
+  m_ifIndex = interface;
+  m_protocol = protocol;
+}
+
+PeerManagementProtocolMac::~PeerManagementProtocolMac ()
+{
+}
+
+void
+PeerManagementProtocolMac::SetParent (Ptr<MeshWifiInterfaceMac> parent)
+{
+  m_parent = parent;
+}
+
+bool
+PeerManagementProtocolMac::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())
+  {
+    IeBeaconTiming beaconTiming;
+    IeMeshId meshId;
+    Ptr<Packet> myBeacon = packet->Copy();
+    MgtBeaconHeader beacon_hdr;
+    myBeacon->RemoveHeader(beacon_hdr);
+    meshId.FindFirst(myBeacon);
+    bool meshBeacon = false;
+    if (
+        (beaconTiming.FindFirst(myBeacon)) &&
+        (m_protocol->GetMeshId ()->IsEqual(meshId))
+        )
+      meshBeacon = true;
+    m_protocol->UpdatePeerBeaconTiming(
+        m_ifIndex,
+        meshBeacon,
+        beaconTiming,
+        header.GetAddr2(),
+        Simulator::Now(),
+        MicroSeconds(beacon_hdr.GetBeaconIntervalUs())
+        );
+    // Beacon shall not be dropeed. May be needed to another plugins
+    return true;
+  }
+  if(header.IsAction())
+  {
+    WifiMeshActionHeader actionHdr;
+    packet->RemoveHeader (actionHdr);
+    WifiMeshActionHeader::ActionValue actionValue = actionHdr.GetAction ();
+    // If can not handle - just return;
+    if(actionHdr.GetCategory () != WifiMeshActionHeader::MESH_PEERING_MGT)
+      return m_protocol->IsActiveLink(m_ifIndex,header.GetAddr2());
+    m_stats.rxMgt ++;
+    m_stats.rxMgtBytes += packet->GetSize ();
+    Mac48Address peerAddress = header.GetAddr2 ();
+    Mac48Address peerMpAddress = header.GetAddr3 ();
+    PeerLinkFrameStart::PlinkFrameStartFields fields;
+    {
+      PeerLinkFrameStart peerFrame;
+      peerFrame.SetPlinkFrameSubtype((uint8_t)actionValue.peerLink);
+      packet->RemoveHeader (peerFrame);
+      fields = peerFrame.GetFields();
+      NS_ASSERT(fields.subtype == actionValue.peerLink);
+    }
+    if (
+        (actionValue.peerLink != WifiMeshActionHeader::PEER_LINK_CLOSE) &&
+        !(m_parent->CheckSupportedRates(fields.rates))
+        )
+      {
+        m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress);
+        // Broken peer link frame - drop it
+        m_stats.brokenMgt ++;
+        return false;
+      }
+    if (
+        (actionValue.peerLink != WifiMeshActionHeader::PEER_LINK_CONFIRM) &&
+        !fields.meshId.IsEqual(*(m_protocol->GetMeshId()))
+        )
+      {
+        m_protocol->ConfigurationMismatch (m_ifIndex, peerAddress);
+        // Broken peer link frame - drop it
+        m_stats.brokenMgt ++;
+        return false;
+      }
+    IePeerManagement peerElement;
+    packet->RemoveHeader(peerElement);
+    //Check taht frame subtype corresponds peer link subtype
+    if(peerElement.SubtypeIsOpen ())
+    {
+      m_stats.rxOpen ++;
+      NS_ASSERT(actionValue.peerLink == WifiMeshActionHeader::PEER_LINK_OPEN);
+    }
+    if(peerElement.SubtypeIsConfirm ())
+    {
+      m_stats.rxConfirm ++;
+      NS_ASSERT(actionValue.peerLink == WifiMeshActionHeader::PEER_LINK_CONFIRM);
+    }
+    if(peerElement.SubtypeIsClose ())
+    {
+      m_stats.rxClose ++;
+      NS_ASSERT(actionValue.peerLink == WifiMeshActionHeader::PEER_LINK_CLOSE);
+    }
+    //Deliver Peer link management frame to protocol:
+    m_protocol->ReceivePeerLinkFrame(m_ifIndex, peerAddress, peerMpAddress, fields.aid, peerElement, fields.config);
+    // if we can handle a frame - drop it
+    return false;
+  }
+  return m_protocol->IsActiveLink(m_ifIndex,header.GetAddr2());
+}
+bool
+PeerManagementProtocolMac::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to)
+{
+  if(header.IsAction ())
+  {
+    WifiMeshActionHeader actionHdr;
+    packet->PeekHeader (actionHdr);
+    WifiMeshActionHeader::ActionValue actionValue = actionHdr.GetAction ();
+    if(actionHdr.GetCategory () == WifiMeshActionHeader::MESH_PEERING_MGT)
+      return true;
+  }
+  if(header.GetAddr1 ().IsGroup ())
+    return true;
+  else
+  {
+    if(m_protocol->IsActiveLink(m_ifIndex,header.GetAddr1()))
+      return true;
+    else
+    {
+      m_stats.dropped ++;
+      return false;
+    }
+  }
+}
+void
+PeerManagementProtocolMac::UpdateBeacon (MeshWifiBeacon & beacon) const
+{
+  Ptr<IeBeaconTiming>  beaconTiming = m_protocol->GetBeaconTimingElement(m_ifIndex);
+  beacon.AddInformationElement(beaconTiming);
+  beacon.AddInformationElement(m_protocol->GetMeshId ());
+}
+
+void
+PeerManagementProtocolMac::SendPeerLinkManagementFrame(
+      Mac48Address peerAddress,
+      Mac48Address peerMpAddress,
+      uint16_t aid,
+      IePeerManagement peerElement,
+      IeConfiguration meshConfig
+      )
+{
+  //Create a packet:
+  meshConfig.SetNeighborCount (m_protocol->GetNumberOfLinks ());
+  Ptr<Packet> packet = Create<Packet> ();
+  packet->AddHeader (peerElement);
+  PeerLinkFrameStart::PlinkFrameStartFields fields;
+  fields.rates = m_parent->GetSupportedRates ();
+  fields.capability = 0;
+  fields.meshId = *(m_protocol->GetMeshId ());
+  fields.config = meshConfig;
+  PeerLinkFrameStart plinkFrame;
+  //Create an 802.11 frame header:
+  //Send management frame to MAC:
+  WifiMeshActionHeader actionHdr;
+  if (peerElement.SubtypeIsOpen ())
+    {
+      m_stats.txOpen ++;
+      WifiMeshActionHeader::ActionValue action;
+      action.peerLink = WifiMeshActionHeader::PEER_LINK_OPEN;
+      fields.subtype = WifiMeshActionHeader::PEER_LINK_OPEN;
+      actionHdr.SetAction (WifiMeshActionHeader::MESH_PEERING_MGT, action);
+    }
+  if (peerElement.SubtypeIsConfirm ())
+    {
+      m_stats.txConfirm ++;
+      WifiMeshActionHeader::ActionValue action;
+      action.peerLink = WifiMeshActionHeader::PEER_LINK_CONFIRM;
+      fields.aid = aid;
+      fields.subtype = WifiMeshActionHeader::PEER_LINK_CONFIRM;
+      actionHdr.SetAction (WifiMeshActionHeader::MESH_PEERING_MGT, action);
+    }
+  if (peerElement.SubtypeIsClose ())
+    {
+      m_stats.txClose ++;
+      WifiMeshActionHeader::ActionValue action;
+      action.peerLink = WifiMeshActionHeader::PEER_LINK_CLOSE;
+      fields.subtype = WifiMeshActionHeader::PEER_LINK_CLOSE;
+      fields.reasonCode = peerElement.GetReasonCode ();
+      actionHdr.SetAction (WifiMeshActionHeader::MESH_PEERING_MGT, action);
+    }
+  plinkFrame.SetPlinkFrameStart(fields);
+  packet->AddHeader (plinkFrame);
+  packet->AddHeader (actionHdr);
+  m_stats.txMgt ++;
+  m_stats.txMgtBytes += packet->GetSize ();
+  // Wifi Mac header:
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetAddr1 (peerAddress);
+  hdr.SetAddr2 (m_parent->GetAddress ());
+  //Addr is not used here, we use it as our MP address
+  hdr.SetAddr3 (m_protocol->GetAddress ());
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+  m_parent->SendManagementFrame(packet, hdr);
+}
+
+Mac48Address
+PeerManagementProtocolMac::GetAddress () const
+{
+  if(m_parent !=  0)
+    return m_parent->GetAddress ();
+  else return Mac48Address::Mac48Address();
+}
+std::pair<Time, Time> 
+PeerManagementProtocolMac::GetBeaconInfo() const
+{
+  std::pair<Time,Time> retval;
+  retval.first = m_parent->GetTbtt ();
+  retval.second = m_parent->GetBeaconInterval ();
+  return retval;
+}
+void
+PeerManagementProtocolMac::SetBeaconShift(Time shift)
+{
+  if(shift != Seconds (0))
+    m_stats.beaconShift ++;
+  m_parent->ShiftTbtt (shift);
+}
+PeerManagementProtocolMac::Statistics::Statistics () :
+  txOpen (0),
+  txConfirm (0),
+  txClose (0),
+  rxOpen (0),
+  rxConfirm (0),
+  rxClose (0),
+  dropped (0),
+  brokenMgt (0),
+  txMgt (0),
+  txMgtBytes (0),
+  rxMgt (0),
+  rxMgtBytes (0),
+  beaconShift (0)
+{
+}
+void
+PeerManagementProtocolMac::Statistics::Print (std::ostream & os) const
+{
+  os << "<Statistics "
+    "txOpen=\"" << txOpen << "\"\n"
+    "txConfirm=\"" << txConfirm << "\"\n"
+    "txClose=\"" << txClose << "\"\n"
+    "rxOpen=\"" << rxOpen << "\"\n"
+    "rxConfirm=\"" << rxConfirm << "\"\n"
+    "rxClose=\"" << rxClose << "\"\n"
+    "dropped=\"" << dropped << "\"\n"
+    "brokenMgt=\"" << brokenMgt << "\"\n"
+    "txMgt=\"" << txMgt << "\"\n"
+    "txMgtBytes=\"" << (double)txMgtBytes /1024.0 << "\"\n"
+    "rxMgt=\"" << rxMgt << "\"\n"
+    "rxMgtBytes=\"" << (double)rxMgtBytes / 1024.0 << "K\"\n"
+    "beaconShift=\"" << beaconShift << "\"/>\n";
+}
+void
+PeerManagementProtocolMac::Report (std::ostream & os) const
+{
+  os << "<PeerManagerPlugin "
+    "address=\"" << m_parent->GetAddress () << "\">\n";
+  m_stats.Print (os);
+  os << "</PeerManagerPlugin>\n";
+}
+void
+PeerManagementProtocolMac::ResetStats ()
+{
+  m_stats = Statistics::Statistics ();
+}
+uint32_t
+PeerManagementProtocolMac::GetLinkMetric (Mac48Address peerAddress)
+{
+  return m_parent->GetLinkMetric (peerAddress);
+}
+} // namespace dot11s
+} //namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/dot11s/peer-management-protocol-mac.h	Thu Jun 18 18:07:22 2009 +0400
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/* 
+ * Copyright (c) 2009 IITP RAS
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ */
+
+#ifndef PEER_MANAGER_MAC_PLUGIN_H_
+#define PEER_MANAGER_MAC_PLUGIN_H_
+
+#include "ns3/mesh-wifi-interface-mac-plugin.h"
+
+namespace ns3 {
+class MeshWifiInterfaceMac;
+namespace dot11s {
+class PeerManagementProtocol;
+class IeConfiguration;
+class IePeerManagement;
+class PeerManagementProtocol;
+/**
+ * \ingroup dot11s
+ * 
+ * \brief This is plugin to Mesh WiFi MAC, which implements
+ * interface to dot11s peer management protocol: it takes proper
+ * frames from MAC-layer, extracts peer link management information
+ * element and mesh configuration element and passes it to main part
+ * of protocol
+ */
+class PeerManagementProtocolMac : public MeshWifiInterfaceMacPlugin
+{
+public:
+  PeerManagementProtocolMac (uint32_t interface, Ptr<PeerManagementProtocol> protocol);
+  ~PeerManagementProtocolMac ();
+  ///\name Inherited from plugin abstract class
+  ///\{
+  void SetParent (Ptr<MeshWifiInterfaceMac> parent);
+  bool Receive (Ptr<Packet> packet, const WifiMacHeader & header);
+  bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
+  void UpdateBeacon (MeshWifiBeacon & beacon) const;
+  ///\}
+  ///\name Statistics:
+  ///\{
+  void Report (std::ostream &) const;
+  void ResetStats ();
+  uint32_t GetLinkMetric (Mac48Address peerAddress);
+  ///\}
+private:
+  friend class PeerManagementProtocol;
+  friend class PeerLink; 
+  ///\name BCA functionallity:
+  ///\{
+  ///\brief Fills TBTT and beacon interval. Needed by BCA
+  ///functionallity
+  ///\param first in retval is TBTT
+  ///\param second in retval is beacon interval
+  std::pair<Time, Time> GetBeaconInfo() const;
+  void SetBeaconShift(Time shift);
+  ///\}
+  void SetPeerManagerProtcol(Ptr<PeerManagementProtocol> protocol);
+  void SendPeerLinkManagementFrame(
+      Mac48Address peerAddress,
+      Mac48Address peerMpAddress,
+      uint16_t aid,
+      IePeerManagement peerElement,
+      IeConfiguration meshConfig
+      );
+  ///\brief DUBUG only - to print established links
+  Mac48Address GetAddress () const;
+private:
+  ///\name Information about MAC and protocol:
+  ///\{
+  Ptr<MeshWifiInterfaceMac> m_parent;
+  uint32_t m_ifIndex;
+  Ptr<PeerManagementProtocol> m_protocol;
+   ///\}
+   ///\name Create peer link management frames:
+   ///\{
+  Ptr<Packet> CreatePeerLinkOpenFrame();
+  Ptr<Packet> CreatePeerLinkConfirmFrame();
+  Ptr<Packet> CreatePeerLinkCloseFrame();
+  ///This structure keeps all fields in peer link management frame,
+  ///which are not subclasses of WifiInformationElement
+  struct PlinkFrameStart {
+    uint8_t subtype;
+    uint16_t aid;
+    SupportedRates rates;
+    uint16_t qos;
+  };
+  /// \name Parses the start of the frame, where there are no
+  /// WifiInformationElements exist
+  PlinkFrameStart ParsePlinkFrame(Ptr<const Packet> packet);
+  ///\}
+  //Keeps statistics
+  struct Statistics {
+    uint16_t txOpen;
+    uint16_t txConfirm;
+    uint16_t txClose;
+    uint16_t rxOpen;
+    uint16_t rxConfirm;
+    uint16_t rxClose;
+    uint16_t dropped;
+    uint16_t brokenMgt;
+    uint16_t txMgt;
+    uint32_t txMgtBytes;
+    uint16_t rxMgt;
+    uint32_t rxMgtBytes;
+    uint16_t beaconShift;
+    
+    Statistics ();
+    void Print (std::ostream & os) const;
+  };
+  struct Statistics m_stats;
+};
+  
+} // namespace dot11s
+} //namespace ns3
+#endif
+
--- a/src/devices/mesh/dot11s/peer-management-protocol.cc	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/peer-management-protocol.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -34,8 +34,6 @@
 #include "ns3/mesh-wifi-interface-mac-plugin.h"
 #include "ns3/wifi-net-device.h"
 #include "peer-link.h"
-#include "peer-management-plugin.h"
-
 
 NS_LOG_COMPONENT_DEFINE ("PeerManagementProtocol");
 namespace ns3 {
@@ -102,7 +100,7 @@
       Ptr<MeshWifiInterfaceMac>  mac = wifiNetDev->GetMac ()->GetObject<MeshWifiInterfaceMac> ();
       if (mac == 0)
         return false;
-      Ptr<PeerManagerMacPlugin> peerPlugin = Create<PeerManagerMacPlugin> ((*i)->GetIfIndex(), this);
+      Ptr<PeerManagementProtocolMac> peerPlugin = Create<PeerManagementProtocolMac> ((*i)->GetIfIndex(), this);
       mac->InstallPlugin(peerPlugin);
       m_plugins[(*i)->GetIfIndex()] = peerPlugin;
       PeerLinksOnInterface newmap;
--- a/src/devices/mesh/dot11s/peer-management-protocol.h	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/peer-management-protocol.h	Thu Jun 18 18:07:22 2009 +0400
@@ -36,7 +36,7 @@
 namespace ns3 {
 class MeshPointDevice;
 namespace dot11s {
-class PeerManagerMacPlugin;
+class PeerManagementProtocolMac;
 class PeerLink;
 class IePeerManagement;
 class IeConfiguration;
@@ -166,7 +166,7 @@
   ///\brief This map keeps beacon information on all intefaces
   typedef std::map<uint32_t, BeaconsOnInterface> BeaconInfoMap;
   ///\brief this vector keeps pointers to MAC-plugins
-  typedef std::map<uint32_t, Ptr<PeerManagerMacPlugin> > PeerManagerPluginMap;
+  typedef std::map<uint32_t, Ptr<PeerManagementProtocolMac> > PeerManagerPluginMap;
   ///\}
 private:
   /**
--- a/src/devices/mesh/dot11s/wscript	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/dot11s/wscript	Thu Jun 18 18:07:22 2009 +0400
@@ -16,11 +16,11 @@
         'dot11s-mac-header.cc',
         'peer-link-frame.cc',
         'peer-link.cc',
-        'peer-management-plugin.cc',
+        'peer-management-protocol-mac.cc',
         'peer-management-protocol.cc',
         'hwmp-tag.cc',
         'hwmp-rtable.cc',
-        'hwmp-mac-plugin.cc',
+        'hwmp-protocol-mac.cc',
         'hwmp-protocol.cc',
         'airtime-metric.cc',
         'dot11s-installer.cc',
--- a/src/devices/mesh/flame/flame-protocol-mac.cc	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/flame/flame-protocol-mac.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -24,23 +24,23 @@
 #include "ns3/log.h"
 namespace ns3 {
 namespace flame {
-NS_LOG_COMPONENT_DEFINE ("FlameMacPlugin");
-FlameMacPlugin::FlameMacPlugin (uint32_t ifIndex, Ptr<FlameProtocol> protocol):
+NS_LOG_COMPONENT_DEFINE ("FlameProtocolMac");
+FlameProtocolMac::FlameProtocolMac (uint32_t ifIndex, Ptr<FlameProtocol> protocol):
   m_protocol (protocol),
   m_ifIndex (ifIndex)
 {
 }
-FlameMacPlugin::~FlameMacPlugin ()
+FlameProtocolMac::~FlameProtocolMac ()
 {
 }
 void
-FlameMacPlugin::SetParent (Ptr<MeshWifiInterfaceMac> parent)
+FlameProtocolMac::SetParent (Ptr<MeshWifiInterfaceMac> parent)
 {
   m_parent = parent;
 }
 
 bool
-FlameMacPlugin::Receive (Ptr<Packet> packet, const WifiMacHeader & header)
+FlameProtocolMac::Receive (Ptr<Packet> packet, const WifiMacHeader & header)
 {
   if (!header.IsData ())
     return true;
@@ -54,7 +54,7 @@
   return true;
 }
 bool
-FlameMacPlugin::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to)
+FlameProtocolMac::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to)
 {
   if(!header.IsData ())
     return true;
@@ -67,22 +67,22 @@
   return true;
 }
 uint8_t
-FlameMacPlugin::GetCost(Mac48Address peerAddress) const
+FlameProtocolMac::GetCost(Mac48Address peerAddress) const
 {
   uint32_t metric = m_parent->GetLinkMetric(peerAddress);
   return (metric > 255 ? 255 : (uint8_t)(metric & 0xff));
 }
 uint16_t
-FlameMacPlugin::GetChannelId () const
+FlameProtocolMac::GetChannelId () const
 {
   return m_parent->GetFrequencyChannel ();
 }
 void
-FlameMacPlugin::Report (std::ostream & os) const
+FlameProtocolMac::Report (std::ostream & os) const
 {
 }
 void
-FlameMacPlugin::ResetStats ()
+FlameProtocolMac::ResetStats ()
 {
 }
 
--- a/src/devices/mesh/flame/flame-protocol-mac.h	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/flame/flame-protocol-mac.h	Thu Jun 18 18:07:22 2009 +0400
@@ -31,11 +31,11 @@
  * 
  * \brief Interface MAC plugin FLAME routing protocol
  */
-class FlameMacPlugin : public MeshWifiInterfaceMacPlugin
+class FlameProtocolMac : public MeshWifiInterfaceMacPlugin
 {
 public:
-  FlameMacPlugin (uint32_t, Ptr<FlameProtocol>);
-  ~FlameMacPlugin ();
+  FlameProtocolMac (uint32_t, Ptr<FlameProtocol>);
+  ~FlameProtocolMac ();
   ///\name Inherited from MAC plugin
   //\{
   void SetParent (Ptr<MeshWifiInterfaceMac> parent);
--- a/src/devices/mesh/flame/flame-protocol.cc	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/flame/flame-protocol.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -219,7 +219,7 @@
       if (mac == 0)
         return false;
       // Installing plugins:
-      Ptr<FlameMacPlugin> flameMac = Create<FlameMacPlugin> (wifiNetDev->GetIfIndex (), this);
+      Ptr<FlameProtocolMac> flameMac = Create<FlameProtocolMac> (wifiNetDev->GetIfIndex (), this);
       m_interfaces[wifiNetDev->GetIfIndex ()] = flameMac;
       mac->InstallPlugin (flameMac);
     }
--- a/src/devices/mesh/flame/flame-protocol.h	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/devices/mesh/flame/flame-protocol.h	Thu Jun 18 18:07:22 2009 +0400
@@ -99,7 +99,7 @@
    * \name Information about MeshPointDeviceaddress , plugins
    * \{
    */
-  typedef std::map<uint32_t, Ptr<FlameMacPlugin> > FlamePluginMap;
+  typedef std::map<uint32_t, Ptr<FlameProtocolMac> > FlamePluginMap;
   FlamePluginMap m_interfaces;
   Mac48Address m_address;
   ///\}
--- a/src/helper/dot11s-helper.cc	Thu Jun 18 16:51:28 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008,2009 IITP RAS
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Kirill Andreev <andreev@iitp.ru>
- *         Pavel Boyko <boyko@iitp.ru>
- */
-#include "dot11s-helper.h"
-#include "ns3/simulator.h"
-#include "ns3/mesh-point-device.h"
-#include "ns3/wifi-net-device.h"
-#include "ns3/log.h"
-NS_LOG_COMPONENT_DEFINE ("MeshWifiHelper");
-namespace ns3 {
-MeshWifiHelper::MeshWifiHelper () : 
-    m_spreadInterfaceChannels (false),
-    m_stack (0)
-{
-}
-void 
-MeshWifiHelper::SetSpreadInterfaceChannels (bool s)
-{
-  m_spreadInterfaceChannels = s;
-}
-void 
-MeshWifiHelper::SetStackInstaller (std::string type)
-{
-  NS_LOG_FUNCTION (this << type);
-  m_stackFactory = ObjectFactory ();
-  m_stackFactory.SetTypeId (type);
-  m_stack = m_stackFactory.Create<MeshStack> ();
-  if (m_stack == 0)
-    NS_FATAL_ERROR ("Stack has not been created: "<<type);
-}
-
-NetDeviceContainer
-MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces) const
-{
-  NetDeviceContainer devices;
-  NS_ASSERT (m_stack != 0);
-  uint16_t node_counter = 0;
-  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
-  {
-    Ptr<Node> node = *i;
-    
-    // Create a mesh point device
-    Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
-    node->AddDevice (mp);
-    
-    // Create wifi interfaces (single interface by default)
-    for (uint32_t i = 0; i < nInterfaces; ++i)
-      {
-        uint32_t channel = i * 5;
-        Ptr<WifiNetDevice> iface = interfaceHelper.CreateInterface (phyHelper,node, (m_spreadInterfaceChannels ? channel : 0));
-        mp->AddInterface (iface);
-      }
-    if(!m_stack->InstallStack (mp))
-    {
-      NS_FATAL_ERROR ("Stack is not installed!");
-    }
-    devices.Add (mp);
-    node_counter ++;
-  }
-  return devices;
-}
-
-NetDeviceContainer
-MeshWifiHelper::Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces) const
-{
-  return Install (phy, interfaceHelper, NodeContainer (node), nInterfaces);
-}
-void
-MeshWifiHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
-{
-  NS_ASSERT (m_stack != 0);
-  Ptr <MeshPointDevice> mp = device->GetObject<MeshPointDevice> ();
-  NS_ASSERT (mp != 0);
-  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
-  os << "<MeshPointDevice ReportTime=\"" << Simulator::Now().GetSeconds() << "s\" MpAddress=\"" << mp->GetAddress () << "\">\n";
-  m_stack->Report (mp, os);
-  os << "</MeshPointDevice>\n";
-}
-void
-MeshWifiHelper::ResetStats (const ns3::Ptr<ns3::NetDevice>& device)
-{
-  NS_ASSERT (m_stack != 0);
-  Ptr <MeshPointDevice> mp = device->GetObject<MeshPointDevice> ();
-  NS_ASSERT (mp != 0);
-  m_stack->ResetStats (mp);
-}
-} //namespace ns3
-
--- a/src/helper/dot11s-helper.h	Thu Jun 18 16:51:28 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008,2009 IITP RAS
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Kirill Andreev <andreev@iitp.ru>
- *         Pavel Boyko <boyko@iitp.ru>
- */
-
-
-#ifndef _MESHWIFIHELPER_H
-#define _MESHWIFIHELPER_H
-
-#include "ns3/wifi-helper.h"
-#include "ns3/mesh-stack-installer.h"
-#include "ns3/nstime.h"
-#include "ns3/mesh-interface-helper.h"
-
-namespace ns3 {
-
-class WifiChannel;
-
-/** 
- * \ingroup dot11s
- * 
- * \brief Helper to create IEEE 802.11s mesh networks
- */
-class MeshWifiHelper
-{
-public:
-  MeshWifiHelper (); 
-  /** 
-   *  \brief Spread/not spread frequency channels of MP interfaces. 
-   * 
-   *  If set to true different non-overlaping 20MHz frequency 
-   *  channels will be assigned to different mesh point interfaces.
-   */ 
-  void SetSpreadInterfaceChannels (bool); 
-  
-  /** 
-   * \brief Install 802.11s mesh device & protocols on given node list
-   * 
-   * \param phy                 Wifi PHY helper
-   * \param nodes               List of nodes to install
-   * \param roots               List of root mesh points
-   * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
-   * 
-   * \return list of created mesh point devices, see MeshPointDevice
-   */
-  NetDeviceContainer Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces = 1) const;
-  /** 
-   * \brief Install 802.11s mesh device & protocols on given node
-   * 
-   * \param phy                 Wifi PHY helper
-   * \param node                Node to install
-   * \param roots               List of root mesh points
-   * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
-   * 
-   * \return list of created mesh point devices, see MeshPointDevice
-   */ 
-  NetDeviceContainer Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces = 1) const;
-  /**
-   * \param type the type of ns3::MeshStack.
-   *
-   * All the attributes specified in this method should exist
-   * in the requested station manager.
-   */
-  void SetStackInstaller (std::string type);
-  void Report (const ns3::Ptr<ns3::NetDevice>&, std::ostream&);
-  void ResetStats (const ns3::Ptr<ns3::NetDevice>&);
-private:
-  bool m_spreadInterfaceChannels;
-  Ptr<MeshStack> m_stack;
-  ObjectFactory m_stackFactory;
-};
-} //namespace ns3
-
-#endif /* _MESHWIFIHELPER_H */
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/mesh-helper.cc	Thu Jun 18 18:07:22 2009 +0400
@@ -0,0 +1,105 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ *         Pavel Boyko <boyko@iitp.ru>
+ */
+#include "mesh-helper.h"
+#include "ns3/simulator.h"
+#include "ns3/mesh-point-device.h"
+#include "ns3/wifi-net-device.h"
+#include "ns3/log.h"
+NS_LOG_COMPONENT_DEFINE ("MeshHelper");
+namespace ns3 {
+MeshHelper::MeshHelper () : 
+    m_spreadInterfaceChannels (false),
+    m_stack (0)
+{
+}
+void 
+MeshHelper::SetSpreadInterfaceChannels (bool s)
+{
+  m_spreadInterfaceChannels = s;
+}
+void 
+MeshHelper::SetStackInstaller (std::string type)
+{
+  NS_LOG_FUNCTION (this << type);
+  m_stackFactory = ObjectFactory ();
+  m_stackFactory.SetTypeId (type);
+  m_stack = m_stackFactory.Create<MeshStack> ();
+  if (m_stack == 0)
+    NS_FATAL_ERROR ("Stack has not been created: "<<type);
+}
+
+NetDeviceContainer
+MeshHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces) const
+{
+  NetDeviceContainer devices;
+  NS_ASSERT (m_stack != 0);
+  uint16_t node_counter = 0;
+  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+  {
+    Ptr<Node> node = *i;
+    
+    // Create a mesh point device
+    Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
+    node->AddDevice (mp);
+    
+    // Create wifi interfaces (single interface by default)
+    for (uint32_t i = 0; i < nInterfaces; ++i)
+      {
+        uint32_t channel = i * 5;
+        Ptr<WifiNetDevice> iface = interfaceHelper.CreateInterface (phyHelper,node, (m_spreadInterfaceChannels ? channel : 0));
+        mp->AddInterface (iface);
+      }
+    if(!m_stack->InstallStack (mp))
+    {
+      NS_FATAL_ERROR ("Stack is not installed!");
+    }
+    devices.Add (mp);
+    node_counter ++;
+  }
+  return devices;
+}
+
+NetDeviceContainer
+MeshHelper::Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces) const
+{
+  return Install (phy, interfaceHelper, NodeContainer (node), nInterfaces);
+}
+void
+MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
+{
+  NS_ASSERT (m_stack != 0);
+  Ptr <MeshPointDevice> mp = device->GetObject<MeshPointDevice> ();
+  NS_ASSERT (mp != 0);
+  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
+  os << "<MeshPointDevice ReportTime=\"" << Simulator::Now().GetSeconds() << "s\" MpAddress=\"" << mp->GetAddress () << "\">\n";
+  m_stack->Report (mp, os);
+  os << "</MeshPointDevice>\n";
+}
+void
+MeshHelper::ResetStats (const ns3::Ptr<ns3::NetDevice>& device)
+{
+  NS_ASSERT (m_stack != 0);
+  Ptr <MeshPointDevice> mp = device->GetObject<MeshPointDevice> ();
+  NS_ASSERT (mp != 0);
+  m_stack->ResetStats (mp);
+}
+} //namespace ns3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/mesh-helper.h	Thu Jun 18 18:07:22 2009 +0400
@@ -0,0 +1,91 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ *         Pavel Boyko <boyko@iitp.ru>
+ */
+
+
+#ifndef _MESHWIFIHELPER_H
+#define _MESHWIFIHELPER_H
+
+#include "ns3/wifi-helper.h"
+#include "ns3/mesh-stack-installer.h"
+#include "ns3/nstime.h"
+#include "ns3/mesh-interface-helper.h"
+
+namespace ns3 {
+
+class WifiChannel;
+
+/** 
+ * \ingroup dot11s
+ * 
+ * \brief Helper to create IEEE 802.11s mesh networks
+ */
+class MeshHelper
+{
+public:
+  MeshHelper (); 
+  /** 
+   *  \brief Spread/not spread frequency channels of MP interfaces. 
+   * 
+   *  If set to true different non-overlaping 20MHz frequency 
+   *  channels will be assigned to different mesh point interfaces.
+   */ 
+  void SetSpreadInterfaceChannels (bool); 
+  
+  /** 
+   * \brief Install 802.11s mesh device & protocols on given node list
+   * 
+   * \param phy                 Wifi PHY helper
+   * \param nodes               List of nodes to install
+   * \param roots               List of root mesh points
+   * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
+   * 
+   * \return list of created mesh point devices, see MeshPointDevice
+   */
+  NetDeviceContainer Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces = 1) const;
+  /** 
+   * \brief Install 802.11s mesh device & protocols on given node
+   * 
+   * \param phy                 Wifi PHY helper
+   * \param node                Node to install
+   * \param roots               List of root mesh points
+   * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
+   * 
+   * \return list of created mesh point devices, see MeshPointDevice
+   */ 
+  NetDeviceContainer Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces = 1) const;
+  /**
+   * \param type the type of ns3::MeshStack.
+   *
+   * All the attributes specified in this method should exist
+   * in the requested station manager.
+   */
+  void SetStackInstaller (std::string type);
+  void Report (const ns3::Ptr<ns3::NetDevice>&, std::ostream&);
+  void ResetStats (const ns3::Ptr<ns3::NetDevice>&);
+private:
+  bool m_spreadInterfaceChannels;
+  Ptr<MeshStack> m_stack;
+  ObjectFactory m_stackFactory;
+};
+} //namespace ns3
+
+#endif /* _MESHWIFIHELPER_H */
+
--- a/src/helper/wscript	Thu Jun 18 16:51:28 2009 +0400
+++ b/src/helper/wscript	Thu Jun 18 18:07:22 2009 +0400
@@ -26,7 +26,7 @@
         'nqos-wifi-mac-helper.cc',
         'qos-wifi-mac-helper.cc',
         'mesh-interface-helper.cc',
-        'dot11s-helper.cc',
+        'mesh-helper.cc',
         ]
 
     headers = bld.new_task_gen('ns3header')
@@ -55,7 +55,7 @@
         'nqos-wifi-mac-helper.h',
         'qos-wifi-mac-helper.h',
         'mesh-interface-helper.h',
-        'dot11s-helper.h',
+        'mesh-helper.h',
         ]
 
     env = bld.env_of_name('default')