#!/usr/bin/env bash # # Usage # ----- # $1 means 1st commandline argument, $2 second etc.: # $1=output interface (defaults to eth0) # $2=input interface (defaults to eth0) # $3=payload length of eth. frame in bytes (42...1500, defaults to 256) # $4=number of packets # # Output format # ------------- # Colum number # 1 Timestamp # 2 Packetloss at 10MHz [%] # 3 Packetloss at 5MHz [%] # 4 Number of packets in a batch # 5 Number of bits in packets susceptible to bit flip # # Requirements #------------- # # * Root access to the machine # * The interface must be in the up state (and not the down state). # * The interface must support full duplex and must be set in full duplex # mode # * Ability to install software # * No fiddling with IP address and/or ARP entries necessary. # * GNU/Linux operating system # * A single free network card dedicated for the test # * There must not be any traffic on the network card at all, including # ARP requests. Any traffic will cause deviation in reading. # # Step by step procedure #------------------------ # # * Ensure you have installed GNU grep version at least 2.5. # * Ensure the network card dedicated for the testing is in full duplex # 10Mbps-only mode (see RonjaFullDuplexHints) # * Connect a hardware that will send the data back to the same or # different network card # * Run the pktloss script. It will print out packetloss immediately, # accurately and automatically. 5 columns of numbers will be infinitely # printed. They mean: # 1. time stamp # 2. 10MHz packet loss # 3. 5MHz packet loss # 4. number of packets in batch # 5. number of bits in ethernet frame effectively susceptible to bit flip # Each row means one batch run. # Configuration: edit the iface and cont below to set up the script # iiface=eth0 oiface=eth0 count=1024 # Minimum payload is 42 and max. 1500 payload=256 #payload=42 # End of user-configurable data if [ `whoami` != 'root' ] then echo "Error: you must be root to run pktloss." >&2 echo "Run su and enter your root password and then rerun the pktloss script again." >&2 exit 3 fi if [ $# -ge 1 ] then oiface="$1" fi if [ $# -ge 2 ] then iiface="$2" fi if [ $# -ge 3 ] then payload="$3" fi if [ $# -ge 4 ] then count="$4" fi if [ "$payload" -gt 1500 ] then echo "Payload length too much: maximum 1500." >& 2 exit 1; fi if [ "$payload" -lt 42 ] then echo "Payload length too short: minimum 42." >& 2 exit 1; fi nbits=`echo "($payload+4+6+6+2+4)*8" | bc` # Only half preamble is assumed # sensitive to bit flip ifconfig $iiface up ifconfig $oiface up rx0=`netstat -in -f link -I $iiface | tail -1 | awk '{print $5}'` tx0=`netstat -in -f link -I $oiface | tail -1 | awk '{print $7}'` while true do ./bertest $count "$oiface" $payload 0 sleep 0.05 date=`date +'%s.0'` tx1=`netstat -in -f link -I $oiface | tail -1 | awk '{print $7}'` txa=`expr "$tx1" '-' "$tx0"` if [ $? -gt 1 ] then echo "0 Expr error" >&2 exit 1 fi if [ "$txa" -lt "$count" ] then # The buffer is probably big or sending slow on this kernel/card sleep 0.5 tx1=`netstat -in -f link -I $oiface | tail -1 | awk '{print $7}'` txa=`expr "$tx1" '-' "$tx0"` if [ $? -gt 1 ] then echo "1 Expr error" >&2 exit 1 fi fi rx1=`netstat -in -f link -I $iiface | tail -1 | awk '{print $5}'` ./bertest $count "$oiface" $payload 1 sleep 0.05 tx2=`netstat -in -f link -I $oiface | tail -1 | awk '{print $7}'` txb=`expr "$tx2" '-' "$tx1"` if [ $? -gt 1 ] then echo "2 Expr error" >&2 exit 1 fi if [ "$txb" -lt "$count" ] then # The buffer is probably big or sending slow on this kernel/card sleep 0.5 tx2=`netstat -in -f link -I $oiface | tail -1 | awk '{print $7}'` txb=`expr "$tx2" '-' "$tx1"` if [ $? -gt 1 ] then echo "3 Expr error" >&2 exit 1 fi fi rx2=`netstat -in -f link -I $iiface | tail -1 | awk '{print $5}'` txb=`expr "$tx2" '-' "$tx1"` if [ "$txa" -gt "$count" -o "$txb" -gt "$count" ] then echo "Warning: other traffic is possibly mixing into the measurement. The \ result is shifted. \ tx is $txa and $txb instead of $count and $count." >& 2 fi if [ "$txa" -lt "$count" -o "$txb" -lt "$count" ] then echo -e "Error: the interface is unable to transmit. \ tx is $txa and $txb instead of $count and $count. This must be fixed as it means\ totally invalid measurement.\nPossible causes:\n\ - nothink is connected to the card (the card doesn't see link integrity) - network card not in full duplex\n\ - network card is receiving noise (weak signal on RX or bad RX)\n\ - network card is down (put up using ifconfig)." >& 2 exit 2 fi lossa=`echo "scale=3; 100-($rx1-$rx0)*100/$count"| bc -l` lossb=`echo "scale=3; 100-($rx2-$rx1)*100/$count"| bc -l` echo -e "$date\t$lossa\t$lossb\t$count\t$nbits" rx0=$rx2 tx0=$tx2 done