Ipv4ClickRouting clean up
authorLalith Suresh <suresh.lalith@gmail.com>
Thu, 24 Jun 2010 12:13:33 +0530
changeset 6312 06bfcc8d0f56
parent 6311 ac1114adddc5
child 6313 3018f1f7ae34
Ipv4ClickRouting clean up
src/routing/click/ipv4-click-routing.cc
--- a/src/routing/click/ipv4-click-routing.cc	Thu Jun 24 12:10:21 2010 +0530
+++ b/src/routing/click/ipv4-click-routing.cc	Thu Jun 24 12:13:33 2010 +0530
@@ -29,6 +29,7 @@
 #include "ns3/ipv4-interface.h"
 #include "ns3/ipv4-l3-click-protocol.h"
 #include "ns3/llc-snap-header.h"
+#include "ns3/csma-net-device.h"
 
 #include "ipv4-click-routing.h"
 #include <string>
@@ -272,24 +273,32 @@
 
       // NetDevice::Send () attaches ethernet headers,
       // so this one's not required.
-      EthernetHeader header;
-      p->RemoveHeader (header);
+
+      Ptr<NetDevice> netdev = m_ipv4->GetNetDevice (ifid);
 
-      uint16_t protocol;
+      if (DynamicCast<CsmaNetDevice> (netdev))
+        {
+          EthernetHeader header;
+          p->PeekHeader (header);
+
+          uint16_t protocol;
 
-      if (header.GetLengthType () <= 1500)
-        {
-          LlcSnapHeader llc;
-          p->RemoveHeader (llc);
-          protocol = llc.GetType ();
+          if (header.GetLengthType () <= 1500)
+            {
+              LlcSnapHeader llc;
+              p->PeekHeader (llc);
+              protocol = llc.GetType ();
+            }
+          else
+            {
+              protocol = header.GetLengthType ();
+            }
+          netdev->Send (p, header.GetDestination (), protocol);
         }
       else
         {
-          protocol = header.GetLengthType ();
+          NS_LOG_ERROR ("Ipv4ClickRouting: Non CSMA devices not supported yet");
         }
-
-      Ptr<NetDevice> netdev = m_ipv4->GetNetDevice (ifid);
-      netdev->Send (p, header.GetDestination (), protocol);
     }
 }