L2RoutingProtocol refactored to MeshL2RoutingProtocol
authorPavel Boyko <boyko@iitp.ru>
Tue, 17 Mar 2009 10:56:45 +0300
changeset 4817 1257e4b82e17
parent 4816 2efabacfb585
child 4818 4ecb2ab650f3
L2RoutingProtocol refactored to MeshL2RoutingProtocol
src/devices/mesh/hwmp.cc
src/devices/mesh/hwmp.h
src/devices/mesh/l2-routing-protocol.cc
src/devices/mesh/l2-routing-protocol.h
src/devices/mesh/mesh-l2-routing-protocol.cc
src/devices/mesh/mesh-l2-routing-protocol.h
src/devices/mesh/mesh-point-device.cc
src/devices/mesh/mesh-point-device.h
src/devices/mesh/mesh-wifi-helper.cc
src/devices/mesh/mesh-wifi-helper.h
src/devices/mesh/wscript
--- a/src/devices/mesh/hwmp.cc	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/hwmp.cc	Tue Mar 17 10:56:45 2009 +0300
@@ -17,14 +17,17 @@
  *
  * Authors: Kirill Andreev <andreev@iitp.ru>
  *          Aleksey Kovalenko <kovalenko@iitp.ru>
+ *          Pavel Boyko <boyko@iitp.ru>
  */
 
 
 #include "ns3/hwmp.h"
 #include "ns3/log.h"
 #include "ns3/simulator.h"
+#include "ns3/mesh-point-device.h"
 
 NS_LOG_COMPONENT_DEFINE ("Hwmp");
+
 namespace ns3 {
 
 NS_OBJECT_ENSURE_REGISTERED (Hwmp);
@@ -104,12 +107,11 @@
 
 uint32_t
 HwmpTag::GetSerializedSize() const
-  {
-
-    return  6 //address
-           +1 //ttl
-           +4; //metric
-  }
+{
+  return  6 //address
+         +1 //ttl
+         +4; //metric
+}
 
 void
 HwmpTag::Serialize(TagBuffer i) const
@@ -152,7 +154,7 @@
 Hwmp::GetTypeId ()
 {
   static TypeId tid = TypeId ("ns3::Hwmp")
-                      .SetParent<L2RoutingProtocol> ()
+                      .SetParent<MeshL2RoutingProtocol> ()
                       .AddConstructor<Hwmp>();
   return tid;
 }
@@ -208,12 +210,13 @@
   const Mac48Address destination,
   Ptr<Packet> packet,
   uint16_t protocolType, //ethrnet 'Protocol' field
-  L2RoutingProtocol::RouteReplyCallback routeReply
+  MeshL2RoutingProtocol::RouteReplyCallback routeReply
 )
 {
   HwmpRtable::LookupResult result;
   HwmpTag tag;
-  if (sourceIface == m_interface)
+  if (sourceIface == GetMeshPoint()->GetIfIndex())
+    // packet from level 3
     {
       if (destination == Mac48Address::GetBroadcast())
         {
@@ -225,6 +228,7 @@
       tag.SetTtl(m_maxTtl);
     }
   else
+    // packet from own interface
     {
       NS_ASSERT(packet->FindFirstMatchingTag(tag));
       //check seqno!
@@ -265,7 +269,7 @@
     {
       //no actual route exists, queue packet and start route
       //discover procedure
-      if (sourceIface != m_interface)
+      if (sourceIface != GetMeshPoint()->GetIfIndex())
         {
           //Start path error procedure:
           NS_LOG_DEBUG("Must Send PERR");
@@ -276,7 +280,7 @@
           destinations.push_back(dst);
           StartPathErrorProcedure(destinations, result.ifIndex);
         }
-      L2RoutingProtocol::QueuedPacket pkt;
+      MeshL2RoutingProtocol::QueuedPacket pkt;
       packet->RemoveAllTags();
       packet->AddTag(tag);
       pkt.pkt = packet;
@@ -374,12 +378,6 @@
 }
 
 void
-Hwmp::SetIfIndex(uint32_t interface)
-{
-  m_interface = interface;
-}
-
-void
 Hwmp::DisablePort(uint32_t port)
 {
   int position = 0;
@@ -596,7 +594,7 @@
 }
 
 bool
-Hwmp::QueuePacket(L2RoutingProtocol::QueuedPacket packet)
+Hwmp::QueuePacket(MeshL2RoutingProtocol::QueuedPacket packet)
 {
   if ((int)m_rqueue[packet.dst].size() > m_maxQueueSize)
     return false;
@@ -604,10 +602,10 @@
   return true;
 }
 
-L2RoutingProtocol::QueuedPacket
+MeshL2RoutingProtocol::QueuedPacket
 Hwmp::DequeuePacket(Mac48Address dst)
 {
-  L2RoutingProtocol::QueuedPacket retval;
+  MeshL2RoutingProtocol::QueuedPacket retval;
   retval.pkt = NULL;
   //Ptr<Packet> in this structure is NULL when queue is empty
   std::map<Mac48Address, std::queue<QueuedPacket>, mac48addrComparator>:: iterator i = m_rqueue.find(dst);
@@ -629,7 +627,7 @@
 Hwmp::SendAllPossiblePackets(Mac48Address dst)
 {
   HwmpRtable::LookupResult result = m_rtable->LookupReactive(dst);
-  L2RoutingProtocol::QueuedPacket packet;
+  MeshL2RoutingProtocol::QueuedPacket packet;
   while (1)
 
     {
@@ -674,7 +672,7 @@
   numOfRetry++;
   if (numOfRetry > dot11sParameters::dot11MeshHWMPmaxPREQretries)
     {
-      L2RoutingProtocol::QueuedPacket packet;
+      MeshL2RoutingProtocol::QueuedPacket packet;
       //purge queue and delete entry from retryDatabase
       while (1)
         {
--- a/src/devices/mesh/hwmp.h	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/hwmp.h	Tue Mar 17 10:56:45 2009 +0300
@@ -17,6 +17,7 @@
  *
  * Authors: Kirill Andreev <andreev@iitp.ru>
  *          Aleksey Kovalenko <kovalenko@iitp.ru>
+ *          Pavel Boyko <boyko@iitp.ru>
  */
 
 
@@ -28,7 +29,7 @@
 #include "ns3/object.h"
 #include "ns3/mac48-address.h"
 #include "ns3/mac48-address-comparator.h"
-#include "ns3/l2-routing-protocol.h"
+#include "ns3/mesh-l2-routing-protocol.h"
 #include "ns3/packet.h"
 #include "ns3/ptr.h"
 #include "ns3/hwmp-state.h"
@@ -81,7 +82,7 @@
 /**
  * \ingroup mesh
  */
-class Hwmp : public L2RoutingProtocol
+class Hwmp : public MeshL2RoutingProtocol
 {
 public:
   static TypeId GetTypeId();
@@ -112,10 +113,9 @@
     const Mac48Address destination,
     Ptr<Packet>  packet,
     uint16_t  protocolType,
-    L2RoutingProtocol::RouteReplyCallback  routeReply
+    MeshL2RoutingProtocol::RouteReplyCallback  routeReply
   );
   bool AttachPorts(std::vector<Ptr<NetDevice> >);
-  void SetIfIndex(uint32_t interface);
   /**
    * \brief Disables port by index.
    * \details Needed for external modules like
@@ -172,8 +172,8 @@
   //protocol:
   void  SetMaxQueueSize(int maxPacketsPerDestination);
   int  m_maxQueueSize;
-  bool  QueuePacket(L2RoutingProtocol::QueuedPacket packet);
-  L2RoutingProtocol::QueuedPacket  DequeuePacket(Mac48Address dst);
+  bool  QueuePacket(MeshL2RoutingProtocol::QueuedPacket packet);
+  MeshL2RoutingProtocol::QueuedPacket  DequeuePacket(Mac48Address dst);
   void  SendAllPossiblePackets(Mac48Address dst);
   std::map<Mac48Address, std::queue<QueuedPacket> >  m_rqueue;
   //devices and HWMP states:
@@ -246,11 +246,6 @@
   HwmpRtable::LookupResult  RequestRootPathForPort(uint32_t port);
 
   /**
-   * \brief interface which is the HWMP attached to
-   * (Virtual netdevice)
-   */
-  uint32_t m_interface;
-  /**
    * \attention mesh seqno is processed at HWMP
    */
   uint32_t m_seqno;
--- a/src/devices/mesh/l2-routing-protocol.cc	Mon Mar 16 20:00:55 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +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/object.h"
-#include "ns3/log.h"
-#include "ns3/l2-routing-protocol.h"
-
-NS_LOG_COMPONENT_DEFINE ("L2RoutingProtocol");
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (L2RoutingProtocol);
-
-TypeId
-L2RoutingProtocol::GetTypeId (void)
-{
-  static TypeId tid = TypeId ("ns3::L2RoutingProtocol")
-                      .SetParent<Object> ();
-  return tid;
-}
-
-L2RoutingProtocol::~L2RoutingProtocol ()
-{}
-
-} // namespace ns3
--- a/src/devices/mesh/l2-routing-protocol.h	Mon Mar 16 20:00:55 2009 +0300
+++ /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 L2_ROUTING_PROTOCOL_H
-#define L2_ROUTING_PROTOCOL_H
-
-#include <list>
-#include <vector>
-#include <ostream>
-#include "ns3/nstime.h"
-#include "ns3/mac48-address.h"
-#include "ns3/net-device.h"
-#include "ns3/ptr.h"
-
-namespace ns3 {
-
-class Packet;
-class MeshPointDevice;
-
-/**
- * \ingroup mesh
- *
- * \brief Interface for L2 mesh routing protocol and mesh point communication. 
- *
- * Every mesh routing protocol must implement this interface. Each mesh point (MeshPointDevice) is supposed
- * to know single L2RoutingProtocol to work with, see MeshPointDevice::SetRoutingProtocol().  
- * 
- * This interface is similar to ipv4 routiong protocol base class.
- */
-class L2RoutingProtocol : public Object
-{
-public:
-  /// Support NS3 object model
-  static TypeId GetTypeId();
-  /// virtual D-tor
-  virtual ~L2RoutingProtocol();
-  
-  /**
-   * Callback to be invoked when route discovery  procedure is completed.
-   * 
-   * \param flag        indicating whether a route was actually found and all needed information is 
-   *                    added to the packet succesfully
-   *                    
-   * \param packet      for which the route was resolved. All routing information for MAC layer
-   *                    must be stored in proper tags (like in case of HWMP, when WifiMacHeader 
-   *                    needs address of next hop), or must be added as a packet header (if MAC
-   *                    does not need any additional information). So, the packet is returned back 
-   *                    to MeshPointDevice looks like a pure packet with ethernet header 
-   *                    (i.e data + src +dst + protocol). The only special information addressed
-   *                    to MeshPointDevice is an outcoming interface ID.
-   *                    
-   * \param src         source address of the packet
-   * 
-   * \param dst         destiation address of the packet
-   * 
-   * \param protocol    ethernet 'Protocol' field, needed to form a proper MAC-layer header
-   * 
-   * \param uint32_t    outcoming interface to use or 0xffffffff if packet should be sent by ALL interfaces
-   */
-  typedef Callback<void,                /* return type */
-                   bool,                /* flag */
-                   Ptr<Packet>,         /* packet */
-                   Mac48Address,        /* src */
-                   Mac48Address,        /* dst */
-                   uint16_t,            /* protocol */
-                   uint32_t             /* out interface ID */ 
-          > RouteReplyCallback;
-  /**
-   * Request routing information, all packets must go through this request.
-   * 
-   * Note that route discobery works async. -- RequestRoute returns immediately, while
-   * reply callback will be called when routing information will be avaliable.
-   *  
-   * \return true if valid route is already known
-   * 
-   * \param sourceIface         the incoming interface of the packet
-   * 
-   * \param source              source address
-   * 
-   * \param destination         destination address
-   * 
-   * \param packet              the packet to be resolved (needed the whole packet, because routing information 
-   *                            is added as tags or headers). The packet will be retutned to reply callback. 
-   *                            
-   * \param protocolType        protocol ID, needed to form a proper MAC-layer header
-   * 
-   * \param routeReply          callback to be invoked after route discovery procedure, supposed to really send packet using routing information.
-   */
-  virtual bool RequestRoute(uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, 
-                            Ptr<Packet> packet, uint16_t  protocolType, RouteReplyCallback routeReply ) = 0;
-  /**
-   * Set host mesh point, analog of SetNode(...) methods for upper layer protocols
-   */
-  virtual void SetMeshPoint(MeshPointDevice * mp) = 0;
-  
-protected:
-  struct QueuedPacket {
-    Ptr<Packet> pkt;
-    Mac48Address dst;
-    Mac48Address src;
-    uint16_t protocol;
-    uint32_t inPort;
-    RouteReplyCallback reply;
-  };
-  /**
-   * \brief Set Max queue size per destinztion
-   * \details Routing Queue is implemented inside the
-   * routing protocol and keeps one queue per
-   * destination (to make it easier to find resolved and
-   * timed out packets).
-   * \param maxPacketsPerDestination Packets per
-   * destination that can be stored inside protocol.
-   */
-  virtual void SetMaxQueueSize(int maxPacketsPerDestination) = 0;
-  /**
-   * \brief Queue packet with 'Ethernet header'
-   * \returns false if the queue is full.
-   */
-  virtual bool QueuePacket(struct QueuedPacket packet) = 0;
-  /**
-   * \brief Deques packet with 'Ethernet header'
-   * \returns Ptr<packet> (NULL if queue is empty), src,
-   * dst, protocol ID, incoming port ID, and reply
-   * callback
-   * \param destination The destination address, which
-   * identifyes queue.
-   */
-  virtual struct QueuedPacket DequeuePacket(Mac48Address destination) = 0;
-};
-}//namespace ns3
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/mesh-l2-routing-protocol.cc	Tue Mar 17 10:56:45 2009 +0300
@@ -0,0 +1,55 @@
+/* -*-  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
+ *
+ * Authors: Kirill Andreev <andreev@iitp.ru>
+ *          Pavel Boyko <boyko@iitp.ru>
+ */
+
+#include "ns3/log.h"
+#include "ns3/mesh-l2-routing-protocol.h"
+#include "ns3/mesh-point-device.h"
+
+NS_LOG_COMPONENT_DEFINE ("MeshL2RoutingProtocol");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (MeshL2RoutingProtocol);
+
+TypeId
+MeshL2RoutingProtocol::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::MeshL2RoutingProtocol")
+                      .SetParent<Object> ();
+  return tid;
+}
+
+MeshL2RoutingProtocol::~MeshL2RoutingProtocol()
+{
+}
+
+void
+MeshL2RoutingProtocol::SetMeshPoint(Ptr<MeshPointDevice> mp)
+{
+  m_mp = mp;
+}
+
+Ptr<MeshPointDevice> MeshL2RoutingProtocol::GetMeshPoint() const
+{
+  return m_mp;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/mesh-l2-routing-protocol.h	Tue Mar 17 10:56:45 2009 +0300
@@ -0,0 +1,153 @@
+/* -*-  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
+ *
+ * Authors: Kirill Andreev <andreev@iitp.ru>
+ *          Pavel Boyko <boyko@iitp.ru>
+ */
+
+#ifndef MESH_L2_ROUTING_PROTOCOL_H
+#define MESH_L2_ROUTING_PROTOCOL_H
+
+#include "ns3/object.h"
+#include "ns3/mac48-address.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Packet;
+class MeshPointDevice;
+
+/**
+ * \ingroup mesh
+ *
+ * \brief Interface for L2 mesh routing protocol and mesh point communication. 
+ *
+ * Every mesh routing protocol must implement this interface. Each mesh point (MeshPointDevice) is supposed
+ * to know single L2RoutingProtocol to work with, see MeshPointDevice::SetRoutingProtocol().  
+ * 
+ * This interface is similar to ipv4 routiong protocol base class.
+ */
+class MeshL2RoutingProtocol : public Object
+{
+public:
+  /// Never forget to support NS3 object model
+  static TypeId GetTypeId();
+  /// virtual D-tor for subclasses
+  virtual ~MeshL2RoutingProtocol();
+  /**
+   * Callback to be invoked when route discovery  procedure is completed.
+   * 
+   * \param flag        indicating whether a route was actually found and all needed information is 
+   *                    added to the packet succesfully
+   *                    
+   * \param packet      for which the route was resolved. All routing information for MAC layer
+   *                    must be stored in proper tags (like in case of HWMP, when WifiMacHeader 
+   *                    needs address of next hop), or must be added as a packet header (if MAC
+   *                    does not need any additional information). So, the packet is returned back 
+   *                    to MeshPointDevice looks like a pure packet with ethernet header 
+   *                    (i.e data + src +dst + protocol). The only special information addressed
+   *                    to MeshPointDevice is an outcoming interface ID.
+   *                    
+   * \param src         source address of the packet
+   * 
+   * \param dst         destiation address of the packet
+   * 
+   * \param protocol    ethernet 'Protocol' field, needed to form a proper MAC-layer header
+   * 
+   * \param uint32_t    outcoming interface to use or 0xffffffff if packet should be sent by ALL interfaces
+   */
+  typedef Callback<void,                /* return type */
+                   bool,                /* flag */
+                   Ptr<Packet>,         /* packet */
+                   Mac48Address,        /* src */
+                   Mac48Address,        /* dst */
+                   uint16_t,            /* protocol */
+                   uint32_t             /* out interface ID */ 
+          > RouteReplyCallback;
+  /**
+   * Request routing information, all packets must go through this request.
+   * 
+   * Note that route discobery works async. -- RequestRoute returns immediately, while
+   * reply callback will be called when routing information will be avaliable.
+   *  
+   * \return true if valid route is already known
+   * 
+   * \param sourceIface         the incoming interface of the packet
+   * 
+   * \param source              source address
+   * 
+   * \param destination         destination address
+   * 
+   * \param packet              the packet to be resolved (needed the whole packet, because routing information 
+   *                            is added as tags or headers). The packet will be retutned to reply callback. 
+   *                            
+   * \param protocolType        protocol ID, needed to form a proper MAC-layer header
+   * 
+   * \param routeReply          callback to be invoked after route discovery procedure, supposed to really send packet using routing information.
+   */
+  virtual bool RequestRoute(uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, 
+                            Ptr<Packet> packet, uint16_t  protocolType, RouteReplyCallback routeReply ) = 0;
+  
+  /// Set host mesh point, analog of SetNode(...) methods for upper layer protocols.
+  void SetMeshPoint(Ptr<MeshPointDevice> mp);
+  /// Each mesh protocol must be installed on the mesh point to work.
+  Ptr<MeshPointDevice> GetMeshPoint() const; 
+  
+protected:
+  
+  ///\name Route request queue API, supposed to be implemented in subclasses
+  //\{
+  
+  /// Packet waiting its routing inforamation, supposed to be used by all implementations to correctly implement timeouts.
+  struct QueuedPacket {
+    Ptr<Packet> pkt;            ///< the packet
+    Mac48Address src;           ///< src address
+    Mac48Address dst;           ///< dst address
+    uint16_t protocol;          ///< protocol number
+    uint32_t inPort;            ///< incoming device interface ID (= mesh point IfID for packets from level 3 and mesh interface ID for packets to forward) 
+    RouteReplyCallback reply;   ///< how to reply
+  };
+  /**
+   * \brief Set maximum route request queue size per destination
+   * 
+   * Routing Queue is implemented inside the routing protocol and keeps one queue per
+   * destination (to make it easier to find resolved and timed out packets).
+   * 
+   * \param maxPacketsPerDestination    Packets per destination that can be stored inside protocol.
+   */
+  virtual void SetMaxQueueSize(int maxPacketsPerDestination) = 0;
+  /**
+   * \brief Queue route request packet with 'Ethernet header' \return false if the queue is full.
+   */
+  virtual bool QueuePacket(struct QueuedPacket packet) = 0;
+  /**
+   * \brief Deque packet with 'Ethernet header'
+   * 
+   * \param destination The destination address, which identifyes queue.
+   * 
+   * \return Ptr<packet> (0 if queue is empty), src, dst, protocol ID, incoming port ID, and reply callback
+   */
+  virtual struct QueuedPacket DequeuePacket(Mac48Address destination) = 0;
+  
+  //\}
+  
+protected:
+  /// Host mesh point
+  Ptr<MeshPointDevice> m_mp;
+};
+}//namespace ns3
+#endif
--- a/src/devices/mesh/mesh-point-device.cc	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/mesh-point-device.cc	Tue Mar 17 10:56:45 2009 +0300
@@ -16,6 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Author: Kirill Andreev <andreev@iitp.ru>
+ *         Pavel Boyko <boyko@iitp.ru>
  */
 
 
@@ -25,7 +26,7 @@
 #include "ns3/log.h"
 #include "ns3/boolean.h"
 #include "ns3/simulator.h"
-#include "ns3/l2-routing-net-device.h"
+#include "ns3/mesh-point-device.h"
 
 NS_LOG_COMPONENT_DEFINE ("MeshPointDevice");
 
@@ -323,16 +324,17 @@
 // Protocols
 //-----------------------------------------------------------------------------
 
-bool
-MeshPointDevice::SetRoutingProtocol(Ptr<L2RoutingProtocol> protocol)
+void
+MeshPointDevice::SetRoutingProtocol(Ptr<MeshL2RoutingProtocol> protocol)
 {
   NS_LOG_FUNCTION_NOARGS ();
   
-  m_requestRoute = MakeCallback(&L2RoutingProtocol::RequestRoute, protocol);
+  NS_ASSERT_MSG(PeekPointer(protocol->GetMeshPoint()) == this, "Routing protocol must be installed on mesh point to be usefull.");
+  
+  m_requestRoute = MakeCallback(&MeshL2RoutingProtocol::RequestRoute, protocol);
   m_myResponse = MakeCallback(&MeshPointDevice::DoSend, this);
-  protocol->SetIfIndex(m_ifIndex);
-  // TODO don't install protocol on ifaces here, this must be done separately. Just set callbacks.
-  return protocol->AttachPorts(m_ifaces);       
+  
+  return;
 }
 
 void
--- a/src/devices/mesh/mesh-point-device.h	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/mesh-point-device.h	Tue Mar 17 10:56:45 2009 +0300
@@ -15,7 +15,8 @@
  * 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>
+ * Authors: Kirill Andreev <andreev@iitp.ru>
+ *          Pavel Boyko <boyko@iitp.ru>
  */
 
 
@@ -27,7 +28,7 @@
 #include "ns3/nstime.h"
 #include "ns3/bridge-net-device.h"
 #include "ns3/bridge-channel.h"
-#include "ns3/l2-routing-protocol.h"
+#include "ns3/mesh-l2-routing-protocol.h"
 
 namespace ns3 {
   
@@ -61,7 +62,7 @@
   ///\name Interfaces 
   //\{
   /**
-   * Attach new interface to the station. Interface must support 48-bit MAC address and SendFrom method.
+   * \brief Attach new interface to the station. Interface must support 48-bit MAC address and SendFrom method.
    * 
    * \attention Only MeshPointDevice can have IP address, but not individual interfaces. 
    */
@@ -80,9 +81,9 @@
   ///\name Protocols
   //\{
   /**
-   * Register routing protocol to be used \return true on success
+   * \brief Register routing protocol to be used. Protocol must be alredy installed on this mesh point.
    */
-  virtual bool SetRoutingProtocol(Ptr<L2RoutingProtocol> protocol);
+  void SetRoutingProtocol(Ptr<MeshL2RoutingProtocol> protocol);
   //\}
   
   ///\name NetDevice interface for upper layers
@@ -132,7 +133,7 @@
    * \param protocol    Protocol ID
    * \param outIface    Interface to use (ID) for send (decided by routing protocol). All interfaces will be used if outIface = 0xffffffff
    */
-  virtual void DoSend(bool success, Ptr<Packet> packet, Mac48Address src, Mac48Address dst, uint16_t protocol, uint32_t iface);
+  void DoSend(bool success, Ptr<Packet> packet, Mac48Address src, Mac48Address dst, uint16_t protocol, uint32_t iface);
   
 private:
   /// Receive action
@@ -161,10 +162,10 @@
            Mac48Address,
            Ptr<Packet>,
            uint16_t,
-           L2RoutingProtocol::RouteReplyCallback>  m_requestRoute;
+           MeshL2RoutingProtocol::RouteReplyCallback>  m_requestRoute;
   
   /// Routing response callback, this is supplied to mesh routing protocol
-  L2RoutingProtocol::RouteReplyCallback  m_myResponse;
+  MeshL2RoutingProtocol::RouteReplyCallback  m_myResponse;
 };
 } //namespace ns3
 #endif
--- a/src/devices/mesh/mesh-wifi-helper.cc	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/mesh-wifi-helper.cc	Tue Mar 17 10:56:45 2009 +0300
@@ -16,6 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * Author: Kirill Andreev <andreev@iitp.ru>
+ *         Pavel Boyko <boyko@iitp.ru>
  */
 
 
@@ -177,9 +178,9 @@
     for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
       {
         Ptr<Node> node = *i;
-        Ptr<MeshPointDevice> virtualDevice = m_deviceFactory.Create<MeshPointDevice> ();
+        Ptr<MeshPointDevice> mp = m_deviceFactory.Create<MeshPointDevice> ();
         Ptr<WifiPeerManager> pPeer = m_peerManager.Create<WifiPeerManager > ();
-        devices.Add (virtualDevice);
+        devices.Add (mp);
         std::vector<Ptr<WifiNetDevice> > nodeDevices;
         for (uint8_t k=0; k<numOfPorts; k++)
           {
@@ -195,13 +196,17 @@
             node->AddDevice(device);
             nodeDevices.push_back(device);
           }
-        node -> AddDevice(virtualDevice);
+        node -> AddDevice(mp);
         for (std::vector<Ptr<WifiNetDevice> > ::iterator iter=nodeDevices.begin();iter!=nodeDevices.end(); ++iter)
-          virtualDevice->AddInterface(*iter);
+          mp->AddInterface(*iter);
         // nodeDevice.pop_back()
         pPeer->AttachPorts(nodeDevices);
-        Ptr<L2RoutingProtocol> routingProtocol = m_routingProtocol.Create <L2RoutingProtocol>();
-        virtualDevice->SetRoutingProtocol(routingProtocol);
+        
+        // Install routing protocol
+        Ptr<MeshL2RoutingProtocol> routing = m_routingProtocol.Create <MeshL2RoutingProtocol>();
+        routing->SetMeshPoint(mp);
+        mp->SetRoutingProtocol(routing);
+        
         //hwmp->SetRoot(device->GetIfIndex(), Seconds(5));
         nodeDevices.clear();
       }
--- a/src/devices/mesh/mesh-wifi-helper.h	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/mesh-wifi-helper.h	Tue Mar 17 10:56:45 2009 +0300
@@ -23,7 +23,7 @@
 #define _MESHWIFIHELPER_H
 
 #include "ns3/wifi-net-device.h"
-#include "ns3/l2-routing-net-device.h"
+#include "ns3/mesh-point-device.h"
 #include "ns3/mesh-wifi-mac.h"
 #include "ns3/wifi-channel.h"
 #include "ns3/mesh-wifi-peer-manager.h"
--- a/src/devices/mesh/wscript	Mon Mar 16 20:00:55 2009 +0300
+++ b/src/devices/mesh/wscript	Tue Mar 17 10:56:45 2009 +0300
@@ -3,14 +3,16 @@
 def build(bld):
     obj = bld.create_ns3_module('mesh', ['wifi'])
     obj.source = [
+        # Refactored
+        'mesh-point-device.cc',
+        'mesh-l2-routing-protocol.cc',
+        # Not refactored
         'mesh-wifi-helper.cc',
         'mesh-wifi-mac-header.cc',
         'mesh-wifi-peer-manager.cc',
         'tx-statistics.cc',
-        'l2-routing-protocol.cc',
         'mesh-wifi-beacon-timing-element.cc',
         'hwmp-rtable.cc',
-        'l2-routing-net-device.cc',
         'dot11s-parameters.cc',
         'mesh-wifi-perr-information-element.cc',
         'hwmp.cc',
@@ -26,10 +28,12 @@
     headers = bld.new_task_gen('ns3header')
     headers.module = 'mesh'
     headers.source = [
-        'l2-routing-protocol.h',
+        # Refactored
+        'mesh-point-device.h',
+        'mesh-l2-routing-protocol.h',
+        # Dirty
         'dot11s-codes.h',
         'mesh-wifi-rann-information-element.h',
-        'l2-routing-net-device.h',
         'hwmp-state.h',
         'mesh-wifi-beacon-timing-element.h',
         'dot11s-parameters.h',