1*7273ec43Smmehari 2*7273ec43Smmehari## 802.11 packet injection 3*7273ec43Smmehari 4*7273ec43SmmehariThe Linux wireless networking stack (i.e. driver, mac80211, cfg80211, net_dev, user app) is a robust implementation supporting a plethora of wireless devices. As robust as it is, it also has a drawback when it comes to single-layer testing. 5*7273ec43Smmehari 6*7273ec43SmmehariPing and Iperf are well established performance measurement tools. However, using such tools to measure 802.11 PHY performance can be misleading, simply because they touch multiple layers in the network stack. 7*7273ec43Smmehari 8*7273ec43SmmehariLuckily, the mac80211 Linux subsystem provides packet injection functionality and it allows us to have finer control over physical layer testing. 9*7273ec43Smmehari 10*7273ec43SmmehariTo this end, we have adapted a [packetspammer](https://github.com/gnychis/packetspammer) application originally written by Andy Green <[email protected]> and maintained by George Nychis <[email protected]>. 11*7273ec43Smmehari 12*7273ec43Smmehari### inject_80211 13*7273ec43SmmehariUserspace program to inject 802.11 packets through mac80211 supported (softmac) wireless devices. 14*7273ec43Smmehari 15*7273ec43Smmehari### Options 16*7273ec43Smmehari ``` 17*7273ec43Smmehari-m/--hw_mode <hardware operation mode> (a,g,n) 18*7273ec43Smmehari-r/--rate_index <rate/MCS index> (0,1,2,3,4,5,6,7) 19*7273ec43Smmehari-i/--sgi_flag (0,1) 20*7273ec43Smmehari-n/--num_packets <number of packets> 21*7273ec43Smmehari-s/--payload_size <payload size in bytes> 22*7273ec43Smmehari-d/--delay <delay between packets in usec> 23*7273ec43Smmehari-h this menu 24*7273ec43Smmehari ``` 25*7273ec43Smmehari 26*7273ec43Smmehari### Example: 27*7273ec43Smmehari``` 28*7273ec43Smmehariiw dev wlan0 interface add mon0 type monitor && ifconfig mon0 up 29*7273ec43Smmehariinject_80211 -m n -r 0 -n 64 -s 100 mon0 # Inject 10 802.11n packets at 6.5Mbps bitrate and 64bytes size 30*7273ec43Smmehari``` 31*7273ec43Smmehari 32*7273ec43Smmehari### Link performance test 33*7273ec43Smmehari 34*7273ec43SmmehariTo make a profound experimental analysis on the physical layer performance, we can rely on automation scripts. 35*7273ec43Smmehari 36*7273ec43SmmehariThe following script will inject 100 802.11n packets at different bitrates and payload sizes. 37*7273ec43Smmehari 38*7273ec43Smmehari``` 39*7273ec43Smmehari#!/bin/bash 40*7273ec43Smmehari 41*7273ec43SmmehariHW_MODE='n' 42*7273ec43SmmehariCOUNT=100 43*7273ec43SmmehariDELAY=1000 44*7273ec43SmmehariRATE=( 0 1 2 3 4 5 6 7 ) 45*7273ec43SmmehariSIZE=( $(seq -s' ' 50 100 1450) ) # paload size in bytes 46*7273ec43SmmehariIF="mon0" 47*7273ec43Smmehari 48*7273ec43Smmeharifor (( i = 0 ; i < ${#PAYLOAD[@]} ; i++ )) do 49*7273ec43Smmehari for (( j = 0 ; j < ${#RATE[@]} ; j++ )) do 50*7273ec43Smmehari inject_80211 -m $HW_MODE -n $COUNT -d $DELAY -r ${RATE[$j]} -s ${SIZE[$i]} $IF 51*7273ec43Smmehari sleep 1 52*7273ec43Smmehari done 53*7273ec43Smmeharidone 54*7273ec43Smmehari 55*7273ec43Smmehari``` 56*7273ec43Smmehari 57*7273ec43SmmehariOn the receiver side, we can use tcpdump to collect the pcap traces. 58*7273ec43Smmehari 59*7273ec43Smmehari``` 60*7273ec43Smmehariiw dev wlan0 interface add mon0 type monitor && ifconfig mon0 up 61*7273ec43Smmeharitcpdump -i mon0 -w trace.pcap 'wlan addr1 ff:ff:ff:ff:ff:ff and wlan addr2 66:55:44:33:22:11' 62*7273ec43Smmehari``` 63*7273ec43Smmehari 64*7273ec43SmmehariWlan addresses *ff:ff:ff:ff:ff:ff* and *66:55:44:33:22:11* are specific to our injector application. 65*7273ec43Smmehari 66*7273ec43SmmehariNext, we analyze the collected pcap traces using the analysis tool provided. 67*7273ec43Smmehari 68*7273ec43Smmehari``` 69*7273ec43Smmeharianalyze_80211 trace.pcap 70*7273ec43Smmehari``` 71*7273ec43Smmehari 72*7273ec43SmmehariAn excerpt from a sample analysis looks the following 73*7273ec43Smmehari 74*7273ec43Smmehari``` 75*7273ec43SmmehariHW MODE RATE(Mbps) SGI SIZE(bytes) COUNT Duration(sec) 76*7273ec43Smmehari======= ========== === =========== ===== ============= 77*7273ec43Smmehari802.11n 6.5 OFF 54 100 0.11159 78*7273ec43Smmehari802.11n 13.0 OFF 54 100 0.11264 79*7273ec43Smmehari802.11n 19.5 OFF 54 100 0.11156 80*7273ec43Smmehari802.11n 26.0 OFF 54 100 0.11268 81*7273ec43Smmehari802.11n 39.0 OFF 54 100 0.11333 82*7273ec43Smmehari802.11n 52.0 OFF 54 100 0.11149 83*7273ec43Smmehari802.11n 58.5 OFF 54 100 0.11469 84*7273ec43Smmehari802.11n 65.0 OFF 54 100 0.11408 85*7273ec43Smmehari``` 86*7273ec43Smmehari 87