Click now handles all packets pertaining to Mac High models default tip
authorLalith Suresh <suresh.lalith@gmail.com>
Sun, 18 Jul 2010 13:29:13 +0530
changeset 6339 366418369bda
parent 6338 5b999177bf08
Click now handles all packets pertaining to Mac High models
nsclick-raw-wlan.click
src/devices/csma/csma-net-device.cc
src/devices/csma/csma-net-device.h
src/devices/wifi/mac-low.cc
src/internet-stack/ipv4-l3-click-protocol.cc
--- a/nsclick-raw-wlan.click	Thu Jul 08 09:23:40 2010 +0530
+++ b/nsclick-raw-wlan.click	Sun Jul 18 13:29:13 2010 +0530
@@ -37,19 +37,30 @@
   myarpresponder :: ARPResponder($myaddr $myaddr_ethernet);
   rt :: LinearIPLookup (172.16.1.0/24 0.0.0.0 1);
 
+  rinfo::AvailableRates(DEFAULT 2 4 11 22)
+  rateselection::MadwifiRate(RT rinfo,ACTIVE true,OFFSET 4);
+  wlinfo :: WirelessInfo(SSID raw, BSSID 01:01:01:01:01:01,CHANNEL 2, IFID 0);
   ethout :: Queue 	
+	-> WifiEncap(0x0, WIRELESS_INFO wlinfo)	
+	-> rateselection
 	-> PrintWifi(eth0_out)
 	-> ToDump(out_eth0,PER_NODE 1,ENCAP 802_11)
+//	-> ExtraEncap()
 	-> ToSimDevice(eth0);
 
   FromSimDevice(eth0,4096)
 	-> ExtraDecap()
+	-> filtertx::FilterTX()
 	-> ToDump(in_eth0,PER_NODE 1,ENCAP 802_11)
 	-> WifiDecap()
 	-> Print(eth0,64)	
 	-> HostEtherFilter($myaddr_ethernet)
 	-> class;
 
+  // transmission is fed back to the rate selection module	
+  filtertx[1]
+	-> [1]rateselection;
+
   // ARP queries from other nodes go to the ARP responder module
   class[0] -> myarpresponder;
 
--- a/src/devices/csma/csma-net-device.cc	Thu Jul 08 09:23:40 2010 +0530
+++ b/src/devices/csma/csma-net-device.cc	Sun Jul 18 13:29:13 2010 +0530
@@ -905,10 +905,42 @@
 CsmaNetDevice::Send (Ptr<Packet> packet,const Address& dest, uint16_t protocolNumber)
 {
   NS_LOG_FUNCTION (packet << dest << protocolNumber);
+
   return SendFrom (packet, m_address, dest, protocolNumber);
 }
 
   bool
+CsmaNetDevice::ClickSend (Ptr<Packet> packet)
+{
+  EthernetTrailer trailer;
+
+  if (Node::ChecksumEnabled ())
+    {
+      trailer.EnableFcs (true);
+    }
+  trailer.CalcFcs (packet);
+
+  packet->AddTrailer (trailer);
+
+  if (m_queue->Enqueue(packet) == false)
+    {
+      return false;
+    }
+
+  if (m_txMachineState == READY)
+    {
+      if (m_queue->IsEmpty () == false)
+        {
+          m_currentPkt = m_queue->Dequeue ();
+          NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?");
+          TransmitStart ();
+        }
+    }
+
+  return true;
+}
+
+  bool
 CsmaNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
 {
   NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
--- a/src/devices/csma/csma-net-device.h	Thu Jul 08 09:23:40 2010 +0530
+++ b/src/devices/csma/csma-net-device.h	Sun Jul 18 13:29:13 2010 +0530
@@ -261,6 +261,8 @@
   virtual bool Send (Ptr<Packet> packet, const Address& dest, 
     uint16_t protocolNumber);
 
+  bool ClickSend (Ptr<Packet> packet);
+
   /**
    * Start sending a packet down the channel, with MAC spoofing
    * \param packet packet to send
--- a/src/devices/wifi/mac-low.cc	Thu Jul 08 09:23:40 2010 +0530
+++ b/src/devices/wifi/mac-low.cc	Sun Jul 18 13:29:13 2010 +0530
@@ -881,7 +881,7 @@
   // If we're running a Click node, and we've just received a data packet
   // then send the packet directly to Ipv4L3ClickProtocol. Else, take the
   // normal path of a packet.
-  if (device->GetNode ()->GetObject<Ipv4L3ClickProtocol> () && !hdr.IsMgt ())
+  if (device->GetNode ()->GetObject<Ipv4L3ClickProtocol> ())
     {
       Ptr<Ipv4L3ClickProtocol> clickL3 = device->GetNode ()->GetObject<Ipv4L3ClickProtocol> ();
       // We don't need the protocol and PacketType fields here, so pass on a 0
--- a/src/internet-stack/ipv4-l3-click-protocol.cc	Thu Jul 08 09:23:40 2010 +0530
+++ b/src/internet-stack/ipv4-l3-click-protocol.cc	Sun Jul 18 13:29:13 2010 +0530
@@ -25,6 +25,12 @@
 #include "ns3/ethernet-header.h"
 #include "ns3/llc-snap-header.h"
 #include "ns3/net-device.h"
+#include "ns3/csma-net-device.h"
+#include "ns3/wifi-net-device.h"
+#include "ns3/wifi-mac.h"
+#include "ns3/wifi-mac-header.h"
+#include "ns3/uinteger.h"
+#include "ns3/object-vector.h"
 
 #include "ipv4-raw-socket-impl.h"
 #include "arp-l3-protocol.h"
@@ -47,7 +53,14 @@
   static TypeId tid = TypeId ("ns3::Ipv4L3ClickProtocol")
     .SetParent<Ipv4> ()
     .AddConstructor<Ipv4L3ClickProtocol> ()
-
+    .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.",
+                   UintegerValue (64),
+                   MakeUintegerAccessor (&Ipv4L3ClickProtocol::m_defaultTtl),
+                   MakeUintegerChecker<uint8_t> ())
+    .AddAttribute ("InterfaceList", "The set of Ipv4 interfaces associated to this Ipv4 stack.",
+                   ObjectVectorValue (),
+                   MakeObjectVectorAccessor (&Ipv4L3ClickProtocol::m_interfaces),
+                   MakeObjectVectorChecker<Ipv4Interface> ()) 
     ;
   return tid;
 }
@@ -652,26 +665,17 @@
   // but we need the destination address and
   // protocol values from the header.
 
-  EthernetHeader header;
-  p->RemoveHeader (header);
-
-  uint16_t protocol;
-
-  if (header.GetLengthType () <= 1500)
-   {
-     LlcSnapHeader llc;
-     p->RemoveHeader (llc);
-     protocol = llc.GetType ();
-   }
-  else
-   {
-     protocol = header.GetLengthType ();
-   }
-
-  // Use the destination address and protocol obtained
-  // from above to send the packet.
   Ptr<NetDevice> netdev = GetNetDevice (ifid);
-  netdev->Send (p, header.GetDestination (), protocol); 
+  if (DynamicCast<CsmaNetDevice> (netdev))
+    {
+      DynamicCast<CsmaNetDevice> (netdev)->ClickSend (p);
+    }
+  else if (DynamicCast<WifiNetDevice> (netdev))
+    {
+      WifiMacHeader hdr;
+      p->RemoveHeader (hdr);
+      DynamicCast<WifiNetDevice> (netdev)->GetMac ()->Enqueue (p, hdr.GetAddr1 ());
+    }
 }
 
 void