Restructured L2RoutingProtocol: added cleanup function, which deletes all tags
authorKirill Andreev <andreev@iitp.ru>
Thu, 18 Jun 2009 13:50:43 +0400
changeset 5083 5b154b30a8a1
parent 5082 528da3d1e5a4
child 5084 ddf23699f0b7
Restructured L2RoutingProtocol: added cleanup function, which deletes all tags and headers
src/devices/mesh/dot11s/hwmp-mac-plugin.cc
src/devices/mesh/dot11s/hwmp-protocol.cc
src/devices/mesh/dot11s/hwmp-protocol.h
src/devices/mesh/flame/flame-protocol.cc
src/devices/mesh/flame/flame-protocol.h
src/devices/mesh/mesh-l2-routing-protocol.h
src/devices/mesh/mesh-point-device.cc
src/devices/mesh/mesh-point-device.h
--- a/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-mac-plugin.cc	Thu Jun 18 13:50:43 2009 +0400
@@ -78,9 +78,8 @@
   };
   tag.SetSeqno (meshHdr.GetMeshSeqno ());
   tag.SetTtl (meshHdr.GetMeshTtl ());
-  if(m_protocol->GetAddress() != destination)
-    packet->AddPacketTag(tag);
-  
+  packet->AddPacketTag(tag);
+ 
   if (destination == Mac48Address::GetBroadcast ())
     if(m_protocol->DropDataFrame (meshHdr.GetMeshSeqno (), source))
       return false;
--- a/src/devices/mesh/dot11s/hwmp-protocol.cc	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.cc	Thu Jun 18 13:50:43 2009 +0400
@@ -257,6 +257,17 @@
   return true;
 }
 bool
+HwmpProtocol::RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source,
+      const Mac48Address destination, Ptr<Packet>  packet, uint16_t&  protocolType)
+{
+  HwmpTag tag;
+  if(!packet->RemovePacketTag (tag))
+  {
+    NS_FATAL_ERROR ("HWMP tag must exist when packet received from the network");
+  }
+  return true;
+}
+bool
 HwmpProtocol::ForwardUnicast(uint32_t  sourceIface, const Mac48Address source, const Mac48Address destination,
     Ptr<Packet>  packet, uint16_t  protocolType, RouteReplyCallback  routeReply, uint32_t ttl)
 {
--- a/src/devices/mesh/dot11s/hwmp-protocol.h	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-protocol.h	Thu Jun 18 13:50:43 2009 +0400
@@ -54,6 +54,9 @@
   /// Route request, inherited from MeshL2RoutingProtocol
   bool RequestRoute (uint32_t  sourceIface, const Mac48Address source, const Mac48Address destination,
       Ptr<const Packet>  packet, uint16_t  protocolType, RouteReplyCallback  routeReply);
+  /// Cleanup packet from all tags
+  bool RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source,
+      const Mac48Address destination, Ptr<Packet>  packet, uint16_t&  protocolType);
   /** 
    * \brief Install HWMP on given mesh point. 
    * 
--- a/src/devices/mesh/flame/flame-protocol.cc	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/flame/flame-protocol.cc	Thu Jun 18 13:50:43 2009 +0400
@@ -21,6 +21,7 @@
 #include "flame-protocol.h"
 #include "flame-rtable.h"
 #include "flame-header.h"
+#include "ns3/llc-snap-header.h"
 #include "ns3/log.h"
 #include "ns3/simulator.h"
 #include "ns3/packet.h"
@@ -116,7 +117,6 @@
       Ptr<const Packet> const_packet, uint16_t  protocolType, RouteReplyCallback  routeReply)
 {
   Ptr<Packet> packet = const_packet->Copy ();
-  NS_LOG_UNCOND("Forwarding packet from "<<source <<", to "<<destination<<"protocol = "<<protocolType);
   if (source == m_address)
   {
     //Packet from upper layer!
@@ -135,12 +135,47 @@
       routeReply (true, packet, source, destination, FLAME_PORT, FlameRtable::INTERFACE_ANY);
     }
     else
-      NS_FATAL_ERROR ("not done yet!");
+      NS_FATAL_ERROR ("unicast not done yet!");
   }
   else
   {
-    NS_FATAL_ERROR ("not done yet!");
+    FlameHeader flameHdr;
+    packet->RemoveHeader (flameHdr); 
+    //if(DropDataFrame(flameHdr.GetSeqno (), source))
+    //  return false;
+    if(destination == Mac48Address::GetBroadcast ())
+    {
+      //Broadcast always is forwarded as broadcast!
+      //Broadcast was filtered in RemoveRoutingStuff, because mesh
+      //point device first calss it
+      FlameTag tag (Mac48Address::GetBroadcast ());
+      flameHdr.AddCost (1);
+      packet->AddHeader (flameHdr);
+      packet->AddPacketTag (tag);
+      routeReply (true, packet, source, destination, FLAME_PORT, FlameRtable::INTERFACE_ANY);
+      return true;
+    }
+    else
+    {
+      if(DropDataFrame(flameHdr.GetSeqno (), source))
+        return false;
+      NS_FATAL_ERROR ("not done yet!");
+    }
+    return true;
   }
+  return false;
+}
+bool
+FlameProtocol::RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source,
+      const Mac48Address destination, Ptr<Packet>  packet, uint16_t&  protocolType)
+{
+  //Filter seqno:
+  FlameHeader flameHdr;
+  packet->RemoveHeader (flameHdr);
+  NS_ASSERT(protocolType == FLAME_PORT);
+  protocolType = flameHdr.GetProtocol ();
+  if(DropDataFrame(flameHdr.GetSeqno (), source))
+    return false;
   return true;
 }
 bool
@@ -173,5 +208,22 @@
 {
   return m_address;
 }
+bool
+FlameProtocol::DropDataFrame(uint16_t seqno, Mac48Address source)
+{
+  if(source == GetAddress ())
+    return true;
+  std::map<Mac48Address, uint16_t,std::less<Mac48Address> >::const_iterator i = m_lastSeqno.find (source);
+  if (i == m_lastSeqno.end ())
+    m_lastSeqno[source] = seqno;
+  else
+  {
+    if (i->second >= seqno)
+      return true;
+    m_lastSeqno[source] = seqno;
+  }
+  return false;
+}
+
 } //namespace flame
 } //namespace ns3
--- a/src/devices/mesh/flame/flame-protocol.h	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/flame/flame-protocol.h	Thu Jun 18 13:50:43 2009 +0400
@@ -69,6 +69,9 @@
   /// Route request, inherited from MeshL2RoutingProtocol
   bool RequestRoute (uint32_t  sourceIface, const Mac48Address source, const Mac48Address destination,
       Ptr<const Packet>  packet, uint16_t  protocolType, RouteReplyCallback  routeReply);
+  /// Cleanup flame headers!
+  bool RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source,
+      const Mac48Address destination, Ptr<Packet>  packet, uint16_t&  protocolType);
   /** 
    * \brief Install FLAME on given mesh point. 
    * 
@@ -83,6 +86,13 @@
   void Report (std::ostream &) const;
   void ResetStats ();
 private:
+  /**
+   * \name Seqno filter:
+   * \{
+   */
+  bool DropDataFrame (uint16_t seqno, Mac48Address source);
+  std::map<Mac48Address, uint16_t> m_lastSeqno;
+  ///\}
   static const uint16_t FLAME_PORT = 0x4040;
   /**
    * \name Information about MeshPointDeviceaddress , plugins
--- a/src/devices/mesh/mesh-l2-routing-protocol.h	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/mesh-l2-routing-protocol.h	Thu Jun 18 13:50:43 2009 +0400
@@ -96,6 +96,22 @@
    */
   virtual bool RequestRoute (uint32_t sourceIface, const Mac48Address source, const Mac48Address destination, 
       Ptr<const Packet> packet, uint16_t  protocolType, RouteReplyCallback routeReply ) = 0;
+  /**
+   * \brief When packet is ready to go to upper layer, protocol must
+   * remove all its information: tags, header, etc. So,
+   * MeshPointDevice must call this method when passing a packet to
+   * upper layer.
+   * \returns true if packet shall not be dropeed, false otherwise.
+   * \param sourceIface the incoming interface of the packet
+   * \param source        source address
+   * \param destination   destination address
+   * \param packet        the packet to be handled
+   * \param protocolType  protocol ID, needed to form a proper MAC-layer header
+   * \attention protocol type is passed by reference, because may be
+   * changed
+   */
+  virtual bool RemoveRoutingStuff (uint32_t fromIface, const Mac48Address source,
+      const Mac48Address destination, Ptr<Packet>  packet, uint16_t &  protocolType) = 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.
--- a/src/devices/mesh/mesh-point-device.cc	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/mesh-point-device.cc	Thu Jun 18 13:50:43 2009 +0400
@@ -84,17 +84,29 @@
   NS_LOG_DEBUG ("UID is " << packet->GetUid ());
   const Mac48Address src48 = Mac48Address::ConvertFrom (src);
   const Mac48Address dst48 = Mac48Address::ConvertFrom (dst);
+  uint16_t& realProtocol = protocol;
   NS_LOG_DEBUG ("SRC="<<src48<<", DST = "<<dst48<<", I am: "<<m_address);
   if (!m_promiscRxCallback.IsNull ())
     m_promiscRxCallback (this, packet, protocol, src, dst, packetType);
   if(dst48.IsGroup ())
   {
-    Forward (incomingPort, packet, protocol, src48, dst48);
-    m_rxCallback (this, packet->Copy (), protocol, src);
+    Ptr<Packet> packet_copy = packet->Copy ();
+    if(m_removeRoutingStuff (incomingPort->GetIfIndex(), src48, dst48, packet_copy, realProtocol))
+    {
+      m_rxCallback (this, packet_copy, realProtocol, src);
+      Forward (incomingPort, packet, protocol, src48, dst48);
+    }
     return;
   }
   if(dst48 == m_address)
-    m_rxCallback (this, packet, protocol, src);
+  {  
+    Ptr<Packet> packet_copy = packet->Copy ();
+    if(m_removeRoutingStuff (incomingPort->GetIfIndex (), src48, dst48, packet_copy, realProtocol))
+    {
+      m_rxCallback (this, packet_copy, realProtocol, src);
+    }
+    return;
+  }
   else
     Forward (incomingPort, packet->Copy (), protocol, src48, dst48);
 }
@@ -225,7 +237,6 @@
 MeshPointDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
 {
   const Mac48Address dst48 = Mac48Address::ConvertFrom (dest);
-  NS_LOG_DEBUG("SEND:, DST = "<<dst48<<", I am: "<<m_address);
   return m_requestRoute (m_ifIndex, m_address, dst48, packet, protocolNumber, m_myResponse);
 }
 
@@ -361,6 +372,7 @@
   
   m_routingProtocol = protocol;
   m_requestRoute = MakeCallback (&MeshL2RoutingProtocol::RequestRoute, protocol);
+  m_removeRoutingStuff = MakeCallback (&MeshL2RoutingProtocol::RemoveRoutingStuff, protocol);
   m_myResponse = MakeCallback (&MeshPointDevice::DoSend, this);
 }
 
--- a/src/devices/mesh/mesh-point-device.h	Wed Jun 17 20:37:32 2009 +0400
+++ b/src/devices/mesh/mesh-point-device.h	Thu Jun 18 13:50:43 2009 +0400
@@ -165,7 +165,7 @@
            Ptr<const Packet>,
            uint16_t,
            MeshL2RoutingProtocol::RouteReplyCallback>  m_requestRoute;
-  
+  Callback<bool, uint32_t, Mac48Address, Mac48Address, Ptr<Packet>, uint16_t&> m_removeRoutingStuff;
   /// Routing response callback, this is supplied to mesh routing protocol
   MeshL2RoutingProtocol::RouteReplyCallback  m_myResponse;
   /// Current routing protocol, used mainly by GetRoutingProtocol