# HG changeset patch # User Lalith Suresh # Date 1310882525 -19800 # Node ID 0ac15aa6350847f865774ccd486ec9550acd3ec3 # Parent a9fae1ab88e02e06a63a314666259e50fbc7b0e4 Monitor mode Wifi header manipulation fixes and Click based example diff -r a9fae1ab88e0 -r 0ac15aa63508 examples/wireless/wifi-monitor-mac-high.cc --- a/examples/wireless/wifi-monitor-mac-high.cc Sat Jul 16 13:57:50 2011 -0400 +++ b/examples/wireless/wifi-monitor-mac-high.cc Sun Jul 17 11:32:05 2011 +0530 @@ -79,6 +79,7 @@ #include "ns3/olsr-helper.h" #include "ns3/ipv4-static-routing-helper.h" #include "ns3/ipv4-list-routing-helper.h" +#include "ns3/click-internet-stack-helper.h" #include #include @@ -192,7 +193,6 @@ wifinetdev->SetMonitorMode (); // Sets the NetDevice in Monitor mode } - c.Add (monitorNode); devices.Add (monitorDevices); MobilityHelper mobility; @@ -205,6 +205,7 @@ "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); + mobility.Install (monitorNode); // Enable OLSR OlsrHelper olsr; @@ -218,6 +219,10 @@ internet.SetRoutingHelper (list); // has effect on the next Install () internet.Install (c); + ClickInternetStackHelper clickInternet; + clickInternet.SetClickFile ("nsclick-wifi-single-interface.click"); + clickInternet.Install (monitorNode); + Ipv4AddressHelper ipv4; NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("10.1.1.0", "255.255.255.0"); diff -r a9fae1ab88e0 -r 0ac15aa63508 examples/wireless/wscript --- a/examples/wireless/wscript Sat Jul 16 13:57:50 2011 -0400 +++ b/examples/wireless/wscript Sun Jul 17 11:32:05 2011 +0530 @@ -34,9 +34,6 @@ obj = bld.create_ns3_program('wifi-simple-adhoc-grid', ['internet', 'mobility', 'wifi', 'olsr', 'config-store', 'tools', 'point-to-point', 'visualizer']) obj.source = 'wifi-simple-adhoc-grid.cc' - obj = bld.create_ns3_program('wifi-monitor-mac', ['internet', 'mobility', 'wifi', 'olsr', 'config-store', 'tools', 'point-to-point']) - obj.source = 'wifi-monitor-mac.cc' - obj = bld.create_ns3_program('wifi-simple-infra', ['internet', 'mobility', 'wifi','config-store', 'visualizer']) obj.source = 'wifi-simple-infra.cc' diff -r a9fae1ab88e0 -r 0ac15aa63508 src/click/examples/nsclick-monitor.click --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/click/examples/nsclick-monitor.click Sun Jul 17 11:32:05 2011 +0530 @@ -0,0 +1,116 @@ +// nsclick-wifi-single-interface.click +// +// Copyright (c) 2011, Deutsche Telekom Laboratories +// +// 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: Ruben Merz +// +// This is a single host Click configuration for wifi. +// The node broadcasts ARP requests if it wants to find a destination +// address, and it responds to ARP requests made for it. + +elementclass WiFiSimHost { + $ipaddr, $hwaddr | + + cl::Classifier(12/0806 20/0001,12/0806 20/0002, -); + forhost::IPClassifier(dst host $ipaddr,-); + arpquerier::ARPQuerier(eth0); + arpresponder::ARPResponder(eth0); + + ethout::Queue + -> ToDump(out_eth0.pcap,PER_NODE 1) + -> ToSimDevice(eth0); + + // All packets received on eth0 are silently + // dropped if they are destined for another location + FromSimDevice(eth0, SNAPLEN 4096) + -> RadiotapDecap () + -> PrintWifi (MonitorNodeClick) + -> ToDump(in_eth0.pcap,PER_NODE 1,ENCAP 802_11) + -> WifiDecap () + -> cl; + + // ARP queries from other nodes go to the ARP responder element + cl[0] -> arpresponder; + + // ARP responses go to our ARP query element + cl[1] -> [1]arpquerier; + + // All other packets get checked whether they are meant for us + cl[2] + -> Strip (14) + -> CheckIPHeader2 + -> MarkIPHeader + -> GetIPAddress(16) // Sets destination IP address annotation from packet data + -> forhost; + + // Packets for us are pushed outside + forhost[0] + ->[0]output; + + // Packets for other folks or broadcast packets get sent to output 1 + forhost[1] + -> ToDump(discard.pcap,2000,PER_NODE 1,ENCAP IP) + -> [1]output; + + // Incoming packets get pushed into the ARP query module + input[0] + -> arpquerier; + + // Both the ARP query and response modules send data out to + // the simulated network device, eth0. + arpquerier + -> ToDump(out_arpquery.pcap,PER_NODE 1) + -> ethout; + + arpresponder + -> ToDump(out_arprespond.pcap,PER_NODE 1) + -> ethout; + +} + +elementclass TapSimHost { + $dev | + + // Packets go to "tap0" which sends them to the kernel + input[0] + -> ToDump(tokernel.pcap,2000,IP,PER_NODE 1) + -> ToSimDevice($dev,IP); + + // Packets sent out by the "kernel" get pushed outside + FromSimDevice($dev, SNAPLEN 4096) + -> CheckIPHeader2 + -> ToDump(fromkernel.pcap,2000,IP,PER_NODE 1) + -> GetIPAddress(16) + -> [0]output; +} + +// Instantiate elements +wifi::WiFiSimHost(eth0:ip,eth0:eth); +kernel::TapSimHost(tap0); + +// Users can do some processing between the two elements +wifi[0] -> kernel; +kernel -> wifi; +// Packets not for us are discarded +wifi[1] -> Discard; + +// It is mandatory to use an IPRouteTable element with ns-3-click +// (but we do not use it in this example) +rt :: LinearIPLookup (172.16.1.0/24 0.0.0.0 1); +// We are actually not using the routing table +Idle () -> rt; +rt[0] -> Discard; +rt[1] -> Discard; diff -r a9fae1ab88e0 -r 0ac15aa63508 src/click/examples/nsclick-wifi-single-interface.click --- a/src/click/examples/nsclick-wifi-single-interface.click Sat Jul 16 13:57:50 2011 -0400 +++ b/src/click/examples/nsclick-wifi-single-interface.click Sun Jul 17 11:32:05 2011 +0530 @@ -35,7 +35,7 @@ // All packets received on eth0 are silently // dropped if they are destined for another location - FromSimDevice(eth0,4096) + FromSimDevice(eth0, SNAPLEN 4096) -> ToDump(in_eth0.pcap,PER_NODE 1,ENCAP ETHER) -> cl; @@ -87,7 +87,7 @@ -> ToSimDevice($dev,IP); // Packets sent out by the "kernel" get pushed outside - FromSimDevice($dev,4096) + FromSimDevice($dev, SNAPLEN 4096) -> CheckIPHeader2 -> ToDump(fromkernel.pcap,2000,IP,PER_NODE 1) -> GetIPAddress(16) diff -r a9fae1ab88e0 -r 0ac15aa63508 src/click/examples/wscript --- a/src/click/examples/wscript Sat Jul 16 13:57:50 2011 -0400 +++ b/src/click/examples/wscript Sun Jul 17 11:32:05 2011 +0530 @@ -20,3 +20,7 @@ obj = bld.create_ns3_program('nsclick-routing', ['click', 'csma', 'internet', 'applications']) obj.source = 'nsclick-routing.cc' + + obj = bld.create_ns3_program('wifi-monitor-mac', + ['click', 'wifi', 'internet', 'applications', 'olsr']) + obj.source = 'wifi-monitor-mac.cc' diff -r a9fae1ab88e0 -r 0ac15aa63508 src/click/model/ipv4-l3-click-protocol.cc --- a/src/click/model/ipv4-l3-click-protocol.cc Sat Jul 16 13:57:50 2011 -0400 +++ b/src/click/model/ipv4-l3-click-protocol.cc Sun Jul 17 11:32:05 2011 +0530 @@ -30,6 +30,7 @@ #include "ns3/net-device.h" #include "ns3/uinteger.h" #include "ns3/object-vector.h" +#include "ns3/wifi-net-device.h" #include "ns3/ipv4-raw-socket-impl.h" #include "ns3/arp-l3-protocol.h" @@ -718,13 +719,20 @@ NS_LOG_FUNCTION (this << device << p << from << to); Ptr packet = p->Copy (); - // Add an ethernet frame. This allows - // Click to work with csma and wifi - EthernetHeader hdr; - hdr.SetSource (Mac48Address::ConvertFrom (from)); - hdr.SetDestination (Mac48Address::ConvertFrom (to)); - hdr.SetLengthType (protocol); - packet->AddHeader (hdr); + // If we're running a Wifi Device in Monitor mode, + // then we need to use Click's Wifi MAC. Else + // we attach a 'fake' ethernet header. + if (!(DynamicCast (device) && + DynamicCast (device)->GetMonitorMode ())) + { + //Add an ethernet frame. This allows + // Click to work with csma and wifi + EthernetHeader hdr; + hdr.SetSource (Mac48Address::ConvertFrom (from)); + hdr.SetDestination (Mac48Address::ConvertFrom (to)); + hdr.SetLengthType (protocol); + packet->AddHeader (hdr); + } Ptr click = DynamicCast (GetRoutingProtocol ()); click->Receive (packet->Copy (), Mac48Address::ConvertFrom (device->GetAddress ()), Mac48Address::ConvertFrom (to)); diff -r a9fae1ab88e0 -r 0ac15aa63508 src/wifi/model/mac-low.cc --- a/src/wifi/model/mac-low.cc Sat Jul 16 13:57:50 2011 -0400 +++ b/src/wifi/model/mac-low.cc Sun Jul 17 11:32:05 2011 +0530 @@ -677,7 +677,15 @@ * packet queue. */ WifiMacHeader hdr; - packet->RemoveHeader (hdr); + + if (!m_monitorMode) + { + packet->RemoveHeader (hdr); + } + else + { + packet->Copy ()->RemoveHeader (hdr); + } m_currentRadiotapHdr = &radiotaphdr; bool isPrevNavZero = IsNavZero (); diff -r a9fae1ab88e0 -r 0ac15aa63508 src/wifi/model/monitor-wifi-mac.h --- a/src/wifi/model/monitor-wifi-mac.h Sat Jul 16 13:57:50 2011 -0400 +++ b/src/wifi/model/monitor-wifi-mac.h Sun Jul 17 11:32:05 2011 +0530 @@ -22,7 +22,6 @@ #define MONITOR_WIFI_MAC_H #include "ns3/wifi-mac.h" -#include "ns3/radiotap-header.h" #include "dca-txop.h" #include "edca-txop-n.h" diff -r a9fae1ab88e0 -r 0ac15aa63508 src/wifi/model/wifi-net-device.cc --- a/src/wifi/model/wifi-net-device.cc Sat Jul 16 13:57:50 2011 -0400 +++ b/src/wifi/model/wifi-net-device.cc Sun Jul 17 11:32:05 2011 +0530 @@ -29,6 +29,8 @@ #include "ns3/node.h" #include "ns3/trace-source-accessor.h" #include "ns3/log.h" +#include "ns3/radiotap-header.h" +#include "ns3/wifi-mac-header.h" NS_LOG_COMPONENT_DEFINE ("WifiNetDevice"); @@ -294,7 +296,13 @@ } else { - packet->Copy ()->RemoveHeader (llc); + Ptr pCopy = packet->Copy (); + RadiotapHeader rtHeader; + WifiMacHeader wmHeader; + pCopy->RemoveHeader (rtHeader); + pCopy->RemoveHeader (wmHeader); + pCopy->RemoveHeader (llc); + } enum NetDevice::PacketType type; if (to.IsBroadcast ()) @@ -371,6 +379,12 @@ } bool +WifiNetDevice::GetMonitorMode (void) const +{ + return m_monitor; +} + +bool WifiNetDevice::SupportsSendFrom (void) const { return m_mac->SupportsSendFrom (); diff -r a9fae1ab88e0 -r 0ac15aa63508 src/wifi/model/wifi-net-device.h --- a/src/wifi/model/wifi-net-device.h Sat Jul 16 13:57:50 2011 -0400 +++ b/src/wifi/model/wifi-net-device.h Sun Jul 17 11:32:05 2011 +0530 @@ -25,6 +25,7 @@ #include "ns3/packet.h" #include "ns3/traced-callback.h" #include "ns3/mac48-address.h" +#include "ns3/radiotap-header.h" #include namespace ns3 { @@ -86,6 +87,12 @@ */ void SetMonitorMode (void); + /** + * Sets device in Monitor Mode. Must be done only if WifiNetDevice + * has a MonitorMacHigh underneath + */ + bool GetMonitorMode (void) const; + // inherited from NetDevice base class. virtual void SetIfIndex (const uint32_t index); virtual uint32_t GetIfIndex (void) const;