References Awk – A Tutorial and Introduction www.grymoire.com/Unix/Awk.html NS by Example nile.wpi.edu/NS/
Trace Analysis Tools
Awk utility Awk is an excellent filtering and reporting utility A pseudo-C interpreter Same C arithmetic Supports associative arrays (array index can be a variable of any type)
Awk – Basic Structure pattern { action } pattern specifies when action is performed Awk is line oriented Default pattern matches every line Two other important patterns BEGIN END M. Dahshan - TCOM5272
Awk – Basic Structure Example on an NS trace file Output + 0.5075 0 1 cbr 210 ------- 0 0.0 1.0 2 2 - 0.5075 0 1 cbr 210 ------- 0 0.0 1.0 2 2 r 0.51112 0 1 cbr 210 ------- 0 0.0 1.0 0 0 BEGIN {print “Time\tSequence Number”} {print $2”\t”$11} END {print “DONE”} Output Time Sequence Number 0.5075 2 0.5075 2 0.51112 0 DONE M. Dahshan - TCOM5272
Calculating Packet Delay BEGIN { # simple awk script to generate end-to-end # packet lifetime statistics # in a form suitable for plotting with xgraph # Lloyd Wood, July 1999. # http://www.ee.surrey.ac.uk/Personal/L.Wood/ns/ highest_packet_id = 0; } M. Dahshan - TCOM5272
Calculating Packet Delay { action = $1; time = $2; node_1 = $3; node_2 = $4; src = $5; flow_id = $8; node_1_address = $9; node_2_address = $10; seq_no = $11; packet_id = $12; M. Dahshan - TCOM5272
Calculating Packet Delay if ( packet_id > highest_packet_id ) highest_packet_id = packet_id; # getting start time is not a problem, provided you're not starting # traffic at 0.0. # could test for sending node_1_address or flow_id here. if ( start_time[packet_id] == 0 ) start_time[packet_id] = time; # only useful for small unicast where packet_id doesn't wrap. # checking receive means avoiding recording drops if ( action != "d" ) { if ( action == "r" ) { # could test for receiving node_2_address or flow_id here. end_time[packet_id] = time; } } else { end_time[packet_id] = -1; M. Dahshan - TCOM5272
Calculating Packet Delay END { for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) { start = start_time[packet_id]; end = end_time[packet_id]; packet_duration = end - start; if ( start < end ) printf("%d %f\n", packet_id , packet_duration); } M. Dahshan - TCOM5272
Calculate Average Delay First, calculate packet delay { #increment number of lines num_lines++; #sum the delay values #column 2 is the packet delay sum_delay=sum_delay+$2; } END {print sum_delay/num_lines} M. Dahshan - TCOM5272
Calculating Dropped Packets BEGIN{dropped=0} { action = $1; if(action=="d") dropped++; } END{print dropped} M. Dahshan - TCOM5272
Calculating Throughput Throughput = total number of bytes received BEGIN{dest=3} { action = $1; node2 = $4; packet_size = $6; if(action=="r" && node2=dest) throughput + = packet_size; } END{throughput} M. Dahshan - TCOM5272
Calculating Jitter Jitter = difference between packet delays First, calculate packet delay M. Dahshan - TCOM5272
Calculating Jitter BEGIN {old_delay=0.0;} { delay = $2; if(old_delay>0) jitter=delay-old_delay; else jitter=0.0; #if(jitter<0) jitter = -jitter; old_delay = delay; print $1 " " jitter; } M. Dahshan - TCOM5272
cat, grep, wc We can simplify processing by doing some pre-filtering using grep We can also do some quick calculations by combining multiple small commands Take the output of a command as an input to the next command (pipes) M. Dahshan - TCOM5272
Print only CBR Traffic grep cbr out.tr r 0.114 1 2 cbr 1000 ------- 2 1.0 3.1 0 0 + 0.114 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 - 0.114 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 + 0.116 1 2 cbr 1000 ------- 2 1.0 3.1 2 2 - 0.116 1 2 cbr 1000 ------- 2 1.0 3.1 2 2 r 0.122 1 2 cbr 1000 ------- 2 1.0 3.1 1 1 M. Dahshan - TCOM5272
Print CBR Traffic From 2 to 3 grep "2 3 cbr" out.tr + 0.114 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 - 0.114 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 + 0.122 2 3 cbr 1000 ------- 2 1.0 3.1 1 1 - 0.122 2 3 cbr 1000 ------- 2 1.0 3.1 1 1 + 0.13 2 3 cbr 1000 ------- 2 1.0 3.1 2 2 - 0.13 2 3 cbr 1000 ------- 2 1.0 3.1 2 2 + 0.138 2 3 cbr 1000 ------- 2 1.0 3.1 3 3 - 0.138 2 3 cbr 1000 ------- 2 1.0 3.1 3 3 r 0.138706 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 + 0.146 2 3 cbr 1000 ------- 2 1.0 3.1 4 4 M. Dahshan - TCOM5272
Print Only Received Packets grep ^r out.tr r 0.114 1 2 cbr 1000 ------- 2 1.0 3.1 0 0 r 0.122 1 2 cbr 1000 ------- 2 1.0 3.1 1 1 r 0.13 1 2 cbr 1000 ------- 2 1.0 3.1 2 2 r 0.138 1 2 cbr 1000 ------- 2 1.0 3.1 3 3 r 0.138706 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 r 0.146 1 2 cbr 1000 ------- 2 1.0 3.1 4 4 r 0.146706 2 3 cbr 1000 ------- 2 1.0 3.1 1 1 r 0.154 1 2 cbr 1000 ------- 2 1.0 3.1 5 5 r 0.154706 2 3 cbr 1000 ------- 2 1.0 3.1 2 2 r 0.162 1 2 cbr 1000 ------- 2 1.0 3.1 6 6 M. Dahshan - TCOM5272
Print CBR Received at Node 3 grep ^r out.tr | grep "2 3 cbr" r 0.138706 2 3 cbr 1000 ------- 2 1.0 3.1 0 0 r 0.146706 2 3 cbr 1000 ------- 2 1.0 3.1 1 1 r 0.154706 2 3 cbr 1000 ------- 2 1.0 3.1 2 2 r 0.162706 2 3 cbr 1000 ------- 2 1.0 3.1 3 3 r 0.170706 2 3 cbr 1000 ------- 2 1.0 3.1 4 4 r 0.178706 2 3 cbr 1000 ------- 2 1.0 3.1 5 5 r 0.186706 2 3 cbr 1000 ------- 2 1.0 3.1 6 6 r 0.194706 2 3 cbr 1000 ------- 2 1.0 3.1 7 7 r 0.202706 2 3 cbr 1000 ------- 2 1.0 3.1 8 8 r 0.210706 2 3 cbr 1000 ------- 2 1.0 3.1 9 9 M. Dahshan - TCOM5272
Calculate Dropped Packets! grep ^d out.tr | wc –l 18 M. Dahshan - TCOM5272
Activities M. Dahshan - TCOM5272
Trace Analysis Example Download the file Trace Analysis Example http://nile.wpi.edu/NS/Example/ns-simple-trace.tcl M. Dahshan - TCOM5272
Activity 1: Calculate Packet Delay Use the provided packet delay script to calculate the delay for CBR traffic only! Save the output to a file cbr_delay.txt Commands: ns ns-simple-trace.tcl grep cbr out.tr | awk -f pkt_delay.awk > cbr_delay.txt M. Dahshan - TCOM5272
Activity 2: Calculate Jitter Use the provided packet jitter script to calculate the delay for CBR traffic Save the output to a file cbr_jitter.txt Commands: awk -f jitter.awk cbr_delay.txt > cbr_jitter.txt M. Dahshan - TCOM5272
Activity 3: Plot Delay and Jitter Use xgraph or gnuplot to plot the delay and jitter for CBR traffic on the same graph For xgraph xgraph cbr_delay.txt cbr_jitter.txt M. Dahshan - TCOM5272
Activity 3: Plot Delay and Jitter Using gnuplot gnuplot gnuplot>set key left top Right noreverse enhanced box gnuplot>set xlabel "Packet ID" gnuplot>set ylabel "Delay and Jitter (sec)" gnuplot>plot “cbr_delay.txt" using 1:2 title “Packet Delay" with lines 1, “cbr_jitter.txt" using 1:2 title “Jitter" with lines 2 M. Dahshan - TCOM5272
Activity 4: Stochastic Fair Queue Edit the ns-sample-trace.tcl script Change the queue type from DropTail to SFQ Save as ns-sample-trace-sfq.tcl Recalculate delay, jitter and plot the results (cbr_delay_sfq.txt, cbr_jitter_sfq.txt) Discuss your findings M. Dahshan - TCOM5272
Activity 4: Random Early Detection Edit the ns-sample-trace.tcl script Change the queue type from DropTail to RED Save as: ns-sample-trace-red.tcl Recalculate delay, jitter and plot the results (cbr_delay_red.txt, cbr_jitter_red.txt) Discuss your findings M. Dahshan - TCOM5272