Introduction to NS-2
Min Chen School of Computer Science and Engineering Seoul National University
Part 3. Result Analysis
1
Part 3. Result Analysis Min Chen School of Computer Science and - - PowerPoint PPT Presentation
Introduction to NS-2 Part 3. Result Analysis Min Chen School of Computer Science and Engineering Seoul National University 1 Outline A Simulation and its results The Format of Trace File The AWK language Result Analysis
Min Chen School of Computer Science and Engineering Seoul National University
1
A Simulation and its results The Format of Trace File The AWK language Result Analysis
End-to-End Delay Jitter Packet Loss
Figure Output
GNUplot
2
s2 s1 r d
tcp udp ftp cbr
3
sink null
0.1 s ~ 4.5 s 1 s ~ 4.0 s
set s1 [$ns node] set s2 [$ns node] set r [$ns node] set d [$ns node] $ns duplex-link $s1 $r 2Mb 10ms DropTail $ns duplex-link $s2 $r 2Mb 10ms DropTail $ns duplex-link $r $d 1.7Mb 20ms DropTail $ns queue-limit $r $d 10 $ns duplex-link-op $s1 $r orient right-down $ns duplex-link-op $s2 $r orient right-up $ns duplex-link-op $r $d orient right $ns duplex-link-op $r $d queuePos 0.5
4
set tcp [new Agent/TCP] $ns attach-agent $s1 $tcp set sink [new Agent/TCPSink] $ns attach-agent $d $sink $ns connect $tcp $sink $tcp set fid_ 1 set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP
5
set udp [new Agent/UDP] $ns attach-agent $s2 $udp set null [new Agent/Null] $ns attach-agent $d $null $ns connect $udp $null $udp set fid_ 2 set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false
6
$ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 4.0 "$ftp stop" $ns at 4.5 "$cbr stop" $ns at 4.5 "$ns detach-agent $s1 $tcp; $ns detach-agent $d $sink" $ns at 5.0 "finish"
7
8
+ 0.1 1 2 cbr 1000 ------- 2 1.0 3.1 0 0
+ 0.108 1 2 cbr 1000 ------- 2 1.0 3.1 1 1
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.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 + 0.122 2 3 cbr 1000 ------- 2 1.0 3.1 1 1
+ 0.124 1 2 cbr 1000 ------- 2 1.0 3.1 3 3
r 0.13 1 2 cbr 1000 ------- 2 1.0 3.1 2 2 + 0.13 2 3 cbr 1000 ------- 2 1.0 3.1 2 2
+ 0.132 1 2 cbr 1000 ------- 2 1.0 3.1 4 4 ...
9
Event Event Time Time From node From node To node To node Packet Type Packet Type Packet Size Packet Size Flags Flags Flow ID Flow ID Source address Source address Destination address Destination address Sequence number Sequence number Packet ID Packet ID r: receive r: receive +: enqueue +: enqueue
d: drop d: drop src_node.port src_node.port dest_node.port dest_node.port
10
Designed for text analysis Similar to C but more simple Read the records line by line
$0: the whole string in the corresponding line $1: the first data in the corresponding line $2: the second data in the corresponding line ...
$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12
11
Three parts in the AWK code
BEGIN Process END
Process Procedure
12
AWK Code: awk.awk file
BEGIN{ sum=0; } { if($1=="+") { sum++; } } END{ printf("The number of enqueue is: %d\n",sum); }
13
Use the awk.awk to anlyze the out.tr trace file
Output the results into sum.txt
14
Calculate the duration of a packet In this example, we calculate the end-to-end
s2 r d Start Time End Time
End to End Delay = End Time – Start Time
15
BEGIN { highest_packet_id=0; } { action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; if ( packet_id > highest_packet_id ) highest_packet_id = packet_id; if ( start_time[packet_id] == 0 ) start_time[packet_id] = time; if ( flow_id == 2 && action != "d" ) { if( action == "r" ) { end_time[packet_id] = time; } else { end_time[packet_id] = -1; } } } 16
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("%f %f\n",start, packet_duration); } } }
17
~$ awk -f delay.awk out.tr > delay.txt delay.txt:
18
Jitter represents the variance of delay
Jitter = ( (EndTime(j)-StartTime(j)) - (EndTime(i)-StartTime(i)) ) / (j – i)
In this example, we calculate the jitter for the
19
BEGIN { highest_packet_id=0; } { action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; if ( packet_id > highest_packet_id ) highest_packet_id = packet_id; if ( start_time[packet_id] == 0 ) { pkt_seqno[packet_id] = seq_no; start_time[packet_id] = time; } if ( flow_id == 2 && action != "d" ) { if( action == "r" ) { end_time[packet_id] = time; } else { end_time[packet_id] = -1; } } } 20
END { last_sequno = 0; last_delay = 0; seqno_diff = 0; 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 ) { seqno_diff = pkt_seqno[packet_id]-last_seqno; delay_diff = packet_duration - last_delay; if ( seqno_diff == 0 ) { jitter = 0; } else { jitter = delay_diff/seqno_diff; } printf("%f %f\n",start, jitter); last_seqno = pkt_seqno[packet_id]; last_delay = packet_duration; } } } 21
~$ awk jitter.awk out.tr > jitter.txt
22
In the transmission, some of the packets may
In this example, we calculate the packet loss for
s2 r d Start Time End Time 23
BEGIN { fsDrops = 0; numFs = 0; } { action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; if ( from == 1 && to == 2 && action == "+" ) { numFs++; } if ( flow_id == 2 && action == "d" ) { fsDrops++; } } END{ printf("number of packets sent:%d lost:%d\n",numFs, fsDrops); } 24
To calculate the average throughput of the cbr
Average Throughput = Total Recieved Bytes / Elapsed Time
Once node 3 recieve a packet, print out the
25
A picture paints a thousand words In a paper, figures(plots) are always the
Tools for figure drawing
Matlab Mathematica GNUplot
26
Portable command-line driven graphing utility Support Linux, Windows, Mac OS... It allows scientists and students to visualize
Supports many types of plots in either 2D and
http://www.gnuplot.info/ Installation in Ubuntu from source
sudo apt-get install gnuplot
27
Enter the GNUplot model Draw a plot
~$ gnuplot gnuplot > plot ”delay.txt” To denote the gnuplot model To denote the gnuplot model The command for drawing The command for drawing The file name The file name 28
29
Set Axis
Range Step
Example
For x axis Showing range
gnuplot > set xtics -10,1,10 gnuplot > plot sin(x) gnuplot > set yrange [-2:2] gnuplot > plot sin(x) ` ` 30
Show grid
gnuplot > set grid gnuplot > plot sin(x) 31
Labels
gnuplot > set title ”CBR Delay” gnuplot > set xlabel ”Simulation Time (s)” gnuplot > set ylabel ”Delay (s)” gnuplot > unset key gnuplot > set label ”constant delay = 0.387606 sec” at 0.1,0.05 gnuplot > set arrow from 0.5,0.05 to 0.5,0.04 gnuplot > plot ”delay.txt” with linespoints ylabel ylabel xlabel xlabel title title label label arrow arrow 32
Styles
lines
points
linespoints
impulses
dots
steps
errorbars points impulses lines steps 33
Output
#set the picture format gnuplot > set terminal png #set the output file name gnuplot > set output ”delay.png” #draw the plot gnuplot > plot ”delay.txt” with linespoints 34
It is inconvenient to input commands
Typos make errors We may redraw the plot for many times
Solution
Write the GPL script as gpl file Run the script in the terminal
~$ gnuplot -persist delay.gpl set title "CBR Delay" set xlabel "Simulation Time (s)" set ylabel "Delay (s)" unset key set label "constant delay = 0.387606 sec" at 0.1,0.05 set arrow from 0.5,0.05 to 0.5,0.04 set terminal png set output "cbr_delay.png" plot "delay.txt" with linespoints 35