Sunteți pe pagina 1din 36

Introduction to NS-2

Part 3 !esult "nalysis


Min Chen School of Computer Science and Engineering Seoul National University

#utline

A Simulation and its results The Format of Trace File The AWK language Result Analysis

End-to-End Delay Jitter Pac et !oss $%&#lot

Figure "ut#ut

'

" Simulation$ %CP and U&P


T*P and &DP +ueuing
1 s . /-, s
ft# tc# sin

s1

s'

null

,-1 s . /-0 s

c(r

ud#

%he #%cl Script


set set set set s1 [$ns node] s2 [$ns node] r [$ns node] 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

%he #%cl Script


set $ns set $ns $ns tcp [new Agent/TCP] attach-agent $s1 $tcp sink [new Agent/TCPSink] attach-agent $d $sink connect $tcp $sink

$tcp set fid_ 1 set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP

%he #%cl Script


set $ns set $ns $ns udp [new Agent/UDP] attach-agent $s2 $udp null [new Agent/Null] attach-agent $d $null 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

%he #%cl Script


$ns $ns $ns $ns at at at at 0.1 1.0 4.0 4.5 "$cbr "$ftp "$ftp "$cbr start" start" stop" stop"

$ns at 4.5 "$ns detach-agent $s1 $tcp; $ns detach-agent $d $sink" $ns at 5.0 "finish"

N"M !esult

%race 'ile
+ 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 ...

%race 'ormat
+ 0.1 1 2 cbr 1000 ------- 2 1.0 3.1 0 0
Event Time From node To node Packet Type Packet Size Flags Flow ID Source address Destination address Sequence number Packet ID r: +: -: d: receive enqueue dequeue drop

src_node.port dest_node.port

1,

"() *anguage

Designed for te5t analysis Similar to * (ut more sim#le Read the records line (y line

6,7 the 8hole string in the corres#onding line 617 the first data in the corres#onding line 6'7 the second data in the corres#onding line --61 62 63 64 61, 611 61'
11

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


61 6' 6) 6/ 60

"() *anguage +Cont ,

Three #arts in the AWK code


9E$:% Process E%D

Process Procedure
1; Read one record '; &#date the #arameters ); Run the Pattern *ode /; Re#eat until no record remain
1'

"n "() E-ample


AWK *ode7 a8 -a8 file
9E$:%< sum=,> ? < if@61==ABA; < sumBB> ?

? E%D< #rintf@AThe num(er of enCueue is7 DdEnAFsum;> ?

1)

"n "() E-ample +Cont ,


&se the a8 -a8 to anlyGe the out-tr trace file .6 a8 -f a8 -a8 out-tr "ut#ut the results into sum-t5t .6 a8 -f a8 -a8 out-tr H sum-t5t

1/

"nalysis .$ End-to-End &elay

*alculate the duration of a #ac et


End to End Delay = End Time J Start Time
r d End Time s' Start Time

:n this e5am#leF 8e calculate the end-to-end delay for the c(r traffic Iia ud# transmission
10

"nalysis .$ End-to-End &elay+Cont ,


9E$:% < highestK#ac etKid=,> ? < action = 61> time = 6'> from = 6)> to = 6/> ty#e = 60> # tsiGe = 61> flo8Kid = 63> src = 64> dst = 61,> seCKno = 611> #ac etKid = 61'> if @ #ac etKid H highestK#ac etKid ; highestK#ac etKid = #ac etKid> if @ startKtimeL#ac etKidM == , ; startKtimeL#ac etKidM = time> if @ flo8Kid == ' NN action O= AdA ; < if@ action == ArA ; < endKtimeL#ac etKidM = time> ? else < endKtimeL#ac etKidM = -1> ? ? ?

11

"nalysis .$ End-to-End &elay+Cont ,


E%D < for@#ac etKid=,> #ac etKid P highestK#ac etKid> #ac etKidBB; < start = startKtimeL#ac etKidM> end = endKtimeL#ac etKidM> #ac etKduration = end-start> if@ start P end ; < #rintf@ADf DfEnAFstartF #ac etKduration;> ? ? ?

12

"nalysis .$ End-to-End &elay+Cont ,

.6 a8 -f delay-a8 out-tr H delay-t5t delay-t5t7


,-1,,,,, ,-,)32,1 ,-1,3,,, ,-,)32,1 ,-111,,, ,-,)32,1 ,-1'/,,, ,-,)32,1 ,-1)',,, ,-,)32,1 ,-1/,,,, ,-,)32,1 ,-1/3,,, ,-,)32,1 ,-101,,, ,-,)32,1
13

"nalysis 2$ /itter

Jitter re#resents the Iariance of delay


Jitter = @ @EndTime@R;-StartTime@R;; - @EndTime@i;-StartTime@i;; ; S @R J i;

:n this e5am#leF 8e calculate the Ritter for the c(r traffic Iia ud# transmission

14

"nalysis 2$ /itter+Cont ,
9E$:% < highestK#ac etKid=,> ? < action = 61> time = 6'> from = 6)> to = 6/> ty#e = 60> # tsiGe = 61> flo8Kid = 63> src = 64> dst = 61,> seCKno = 611> #ac etKid = 61'> if @ #ac etKid H highestK#ac etKid ; highestK#ac etKid = #ac etKid> if @ startKtimeL#ac etKidM == , ; < # tKseCnoL#ac etKidM = seCKno> startKtimeL#ac etKidM = time> ? if @ flo8Kid == ' NN action O= AdA ; < if@ action == ArA ; < endKtimeL#ac etKidM = time> ? else < endKtimeL#ac etKidM = -1> ? ? ?

',

"nalysis 2$ /itter+Cont ,
E%D < lastKseCuno = ,> lastKdelay = ,> seCnoKdiff = ,> for@#ac etKid=,> #ac etKid P highestK#ac etKid> #ac etKidBB; < start = startKtimeL#ac etKidM> end = endKtimeL#ac etKidM> #ac etKduration = end-start> if@ start P end ; < seCnoKdiff = # tKseCnoL#ac etKidM-lastKseCno> delayKdiff = #ac etKduration - lastKdelay> if @ seCnoKdiff == , ; < Ritter = ,> ? else < Ritter = delayKdiffSseCnoKdiff> ? #rintf@ADf DfEnAFstartF Ritter;> lastKseCno = # tKseCnoL#ac etKidM> lastKdelay = #ac etKduration> ? ? ? '1

"nalysis 2$ /itter+Cont ,

.6 a8 Ritter-a8 out-tr H Ritter-t5t


,-1,,,,, ,-,,,,,, ,-1,3,,, ,-,,,,,, ,-111,,, ,-,,,,,, ,-1'/,,, -,-,,,,,, ,-1)',,, ,-,,,,,, ,-1/,,,, ,-,,,,,, ,-1/3,,, ,-,,,,,, ,-101,,, -,-,,,,,, Q --''

"nalysis 3$ Pac0et *oss

:n the transmissionF some of the #ac ets may (e lost due to the oIerflo8 of the Cueue
!oss = Pac etsKSent - Pac etsKRecieIe
r d End Time s' Start Time

:n this e5am#leF 8e calculate the #ac et loss for the c(r traffic Iia ud# transmission
')

"nalysis 3$ Pac0et *oss+Cont ,


9E$:% < fsDro#s = ,> numFs = ,> ? < action = 61> time = 6'> from = 6)> to = 6/> ty#e = 60> # tsiGe = 61> flo8Kid = 63> src = 64> dst = 61,> seCKno = 611> #ac etKid = 61'> if @ from == 1 NN to == ' NN action == ABA ; < numFsBB> ? if @ flo8Kid == ' NN action == AdA ; < fsDro#sBB> ? ? E%D< #rintf@Anum(er of #ac ets sent7Dd lost7DdEnAFnumFsF fsDro#s;> ? '/

Practice .$ %hroughput

To calculate the aIerage through#ut of the c(r traffic (et8een node ' and node )
AIerage Through#ut = Total RecieIed 9ytes S Ela#sed Time

"nce node ) recieIe a #ac etF #rint out the real-time though#ut

'0

'igure #utput

A #icture #aints a thousand 8ords :n a #a#erF figures@#lots; are al8ays the essential #arts of the simulation and analysis section Tools for figure dra8ing

Tatla( Tathematica $%&#lot

'1

1NUplot

Porta(le command-line driIen gra#hing utility Su##ort !inu5F Windo8sF Tac "S--:t allo8s scientists and students to IisualiGe mathematical functions and data Su##orts many ty#es of #lots in either 'D and )Dhtt#7SS888-gnu#lot-infoS :nstallation in &(untu from source

sudo a#t-get install gnu#lot

'2

2o3 to dra3 a figure

Enter the $%&#lot model


.6 gnu#lot

Dra8 a #lot
gnu#lot H #lot Udelay-t5tU

To Todenote denotethe the gnu#lot model gnu#lot model

The Thecommand commandfor for dra8ing dra8ing

The Thefile filename name '3

!esult from the 1NUplot

'4

Commands in 1NUplot +.,

Set A5is

Range Ste# For 5 a5is

E5am#le

gnu#lot H set 5tics -1,F1F1, gnu#lot H #lot sin@5;

Sho8ing range

gnu#lot H set yrange L-'7'M gnu#lot H #lot sin@5;

VV

),

Commands in 1NUplot +2,

Sho8 grid
gnu#lot H set grid gnu#lot H #lot sin@5;

)1

Commands in 1NUplot +3,

!a(els

title title

yla(el yla(el arro8 arro8 5la(el 5la(el gnu#lot H set title U*9R DelayU gnu#lot H set 5la(el USimulation Time @s;U gnu#lot H set yla(el UDelay @s;U gnu#lot H unset ey gnu#lot H set la(el Uconstant delay = ,-)321,1 secU at ,-1F,-,0 gnu#lot H set arro8 from ,-0F,-,0 to ,-0F,-,/ gnu#lot H #lot Udelay-t5tU 8ith lines#oints

la(el la(el

)'

Commands in 1NUplot +4,


#oints

im#ulses

Styles

lines #oints lines#oints im#ulses dots ste#s error(ars lines ste#s

))

Command in 1NUplot +5,

"ut#ut
Wset the #icture format gnu#lot H set terminal #ng Wset the out#ut file name gnu#lot H set out#ut Udelay-#ngU Wdra8 the #lot gnu#lot H #lot Udelay-t5tU 8ith lines#oints

)/

1P* script

:t is inconIenient to in#ut commands

Ty#os ma e errors We may redra8 the #lot for many times Write the $P! scri#t as g#l file
set title A*9R DelayA set 5la(el ASimulation Time @s;A set yla(el ADelay @s;A unset ey set la(el Aconstant delay = ,-)321,1 secA at ,-1F,-,0 set arro8 from ,-0F,-,0 to ,-0F,-,/ set terminal #ng set out#ut Ac(rKdelay-#ngA #lot Adelay-t5tA 8ith lines#oints

Solution

Run the scri#t in the terminal


.6 gnu#lot -#ersist delay-g#l )0

6uestions7

Than you O

S-ar putea să vă placă și