Presentation is loading. Please wait.

Presentation is loading. Please wait.

References Awk – A Tutorial and Introduction NS by Example nile.wpi.edu/NS/

Similar presentations


Presentation on theme: "References Awk – A Tutorial and Introduction NS by Example nile.wpi.edu/NS/"— Presentation transcript:

1

2 References Awk – A Tutorial and Introduction NS by Example nile.wpi.edu/NS/

3 Trace Analysis Tools

4 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)

5 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

6 Awk – Basic Structure Example on an NS trace file Output
cbr cbr r cbr BEGIN {print “Time\tSequence Number”} {print $2”\t”$11} END {print “DONE”} Output Time Sequence Number DONE M. Dahshan - TCOM5272

7 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. # highest_packet_id = 0; } M. Dahshan - TCOM5272

8 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

9 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

10 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

11 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

12 Calculating Dropped Packets
BEGIN{dropped=0} { action = $1; if(action=="d") dropped++; } END{print dropped} M. Dahshan - TCOM5272

13 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

14 Calculating Jitter Jitter = difference between packet delays
First, calculate packet delay M. Dahshan - TCOM5272

15 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

16 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

17 Print only CBR Traffic grep cbr out.tr
r cbr cbr cbr cbr cbr r cbr M. Dahshan - TCOM5272

18 Print CBR Traffic From 2 to 3
grep "2 3 cbr" out.tr cbr cbr cbr cbr cbr cbr cbr cbr r cbr cbr M. Dahshan - TCOM5272

19 Print Only Received Packets
grep ^r out.tr r cbr r cbr r cbr r cbr r cbr r cbr r cbr r cbr r cbr r cbr M. Dahshan - TCOM5272

20 Print CBR Received at Node 3
grep ^r out.tr | grep "2 3 cbr" r cbr r cbr r cbr r cbr r cbr r cbr r cbr r cbr r cbr r cbr M. Dahshan - TCOM5272

21 Calculate Dropped Packets!
grep ^d out.tr | wc –l 18 M. Dahshan - TCOM5272

22 Activities M. Dahshan - TCOM5272

23 Trace Analysis Example
Download the file Trace Analysis Example M. Dahshan - TCOM5272

24 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

25 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

26 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

27 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

28 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

29 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


Download ppt "References Awk – A Tutorial and Introduction NS by Example nile.wpi.edu/NS/"

Similar presentations


Ads by Google