Part 3. Result Analysis Min Chen School of Computer Science and - - PowerPoint PPT Presentation

part 3 result analysis
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Introduction to NS-2

Min Chen School of Computer Science and Engineering Seoul National University

Part 3. Result Analysis

1

slide-2
SLIDE 2

Outline

 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

slide-3
SLIDE 3

A Simulation: TCP and UDP

s2 s1 r d

tcp udp ftp cbr

3

sink null

TCP and UDP Queuing

0.1 s ~ 4.5 s 1 s ~ 4.0 s

slide-4
SLIDE 4

The OTcl Script

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

slide-5
SLIDE 5

The OTcl Script

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

slide-6
SLIDE 6

The OTcl Script

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

slide-7
SLIDE 7

The OTcl Script

$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

slide-8
SLIDE 8

NAM Result

8

slide-9
SLIDE 9

Trace File

+ 0.1 1 2 cbr 1000 ------- 2 1.0 3.1 0 0

  • 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

  • 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.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 + 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.124 1 2 cbr 1000 ------- 2 1.0 3.1 3 3

  • 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.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

slide-10
SLIDE 10

Trace Format

+ + 0.1 0.1 1 1 2 2 cbr cbr 1000 1000

  • 2

2 1.0 1.0 3.1 3.1

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

  • : dequeue
  • : dequeue

d: drop d: drop src_node.port src_node.port dest_node.port dest_node.port

10

slide-11
SLIDE 11

AWK Language

 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  ...

+ + 0.1 0.1 1 1 2 2 cbr cbr 1000 1000

  • 2

2 1.0 1.0 3.1 3.1

$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12

11

slide-12
SLIDE 12

AWK Language (Cont.)

 Three parts in the AWK code

 BEGIN  Process  END

 Process Procedure

1) Read one record 2) Update the parameters 3) Run the Pattern Code 4) Repeat until no record remain

12

slide-13
SLIDE 13

An AWK Example

AWK Code: awk.awk file

BEGIN{ sum=0; } { if($1=="+") { sum++; } } END{ printf("The number of enqueue is: %d\n",sum); }

13

slide-14
SLIDE 14

An AWK Example (Cont.)

 Use the awk.awk to anlyze the out.tr trace file

~$ awk -f awk.awk out.tr

 Output the results into sum.txt

~$ awk -f awk.awk out.tr > sum.txt

14

slide-15
SLIDE 15

Analysis 1: End-to-End Delay

 Calculate the duration of a packet  In this example, we calculate the end-to-end

delay for the cbr traffic via udp transmission

s2 r d Start Time End Time

End to End Delay = End Time – Start Time

15

slide-16
SLIDE 16

Analysis 1: End-to-End Delay(Cont.)

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

slide-17
SLIDE 17

Analysis 1: End-to-End Delay(Cont.)

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

slide-18
SLIDE 18

Analysis 1: End-to-End Delay(Cont.)

 ~$ awk -f delay.awk out.tr > delay.txt  delay.txt:

0.100000 0.038706 0.108000 0.038706 0.116000 0.038706 0.124000 0.038706 0.132000 0.038706 0.140000 0.038706 0.148000 0.038706 0.156000 0.038706 … ...

18

slide-19
SLIDE 19

Analysis 2: Jitter

 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

cbr traffic via udp transmission

19

slide-20
SLIDE 20

Analysis 2: Jitter(Cont.)

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

slide-21
SLIDE 21

Analysis 2: Jitter(Cont.)

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

slide-22
SLIDE 22

Analysis 2: Jitter(Cont.)

 ~$ awk jitter.awk out.tr > jitter.txt

0.100000 0.000000 0.108000 0.000000 0.116000 0.000000 0.124000 -0.000000 0.132000 0.000000 0.140000 0.000000 0.148000 0.000000 0.156000 -0.000000 … ...

22

slide-23
SLIDE 23

Analysis 3: Packet Loss

 In the transmission, some of the packets may

be lost due to the overflow of the queue

Loss = Packets_Sent - Packets_Recieve

 In this example, we calculate the packet loss for

the cbr traffic via udp transmission

s2 r d Start Time End Time 23

slide-24
SLIDE 24

Analysis 3: Packet Loss(Cont.)

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

slide-25
SLIDE 25

Practice 1: Throughput

 To calculate the average throughput of the cbr

traffic between node 2 and node 3

Average Throughput = Total Recieved Bytes / Elapsed Time

 Once node 3 recieve a packet, print out the

real-time thoughput

25

slide-26
SLIDE 26

Figure Output

 A picture paints a thousand words  In a paper, figures(plots) are always the

essential parts of the simulation and analysis section

 Tools for figure drawing

 Matlab  Mathematica  GNUplot

26

slide-27
SLIDE 27

GNUplot

 Portable command-line driven graphing utility  Support Linux, Windows, Mac OS...  It allows scientists and students to visualize

mathematical functions and data

 Supports many types of plots in either 2D and

3D.

 http://www.gnuplot.info/  Installation in Ubuntu from source

 sudo apt-get install gnuplot

27

slide-28
SLIDE 28

How to draw a figure

 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

slide-29
SLIDE 29

Result from the GNUplot

29

slide-30
SLIDE 30

Commands in GNUplot (1)

 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

slide-31
SLIDE 31

Commands in GNUplot (2)

 Show grid

gnuplot > set grid gnuplot > plot sin(x) 31

slide-32
SLIDE 32

Commands in GNUplot (3)

 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

slide-33
SLIDE 33

Commands in GNUplot (4)

 Styles

lines

points

linespoints

impulses

dots

steps

errorbars points impulses lines steps 33

slide-34
SLIDE 34

Command in GNUplot (5)

 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

slide-35
SLIDE 35

GPL script

 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

slide-36
SLIDE 36

Questions?

Thank you !