Professional Documents
Culture Documents
NS-2 Tutorial: Demokritos University of Thrace
NS-2 Tutorial: Demokritos University of Thrace
Demokritos University of Thrace Depts of: Data Analysis & Computer Networks
ns-2 overview
Collection of various protocols at multiple layers: TCP(reno, tahoe, vegas, sack) !C("#2$%%, "#2$&, T' !) !(-hoc )outing ('S'*, 'S), !+'*, T+)!) Sensor Net,ork ((iffusion, gaf) ulticast protocols, Satellite protocols, an( many others Co(es are contri-ute( from multiple research communities: .oo(: /arge set of simulation mo(ules 0a(: /evel of support an( (ocumentation varies The source co(e an( (ocumentation is currently maintaine( -y *1NT pro2ect at 1S1
ns-2 Environment
Simulation Scenario
1 2
Tcl Script
C++ Implementation
Contri"ute# from C$U%s $onarch pro&ect ' ireless e(tension to ns-2) *arious mo#ules were a##e# to ns-2 to simulate no#e mo"ility an# wireless networkin+ $o"ile No#e A#-hoc ,outin+'D!,- D!D*- T.,A- A.D*) $AC/02122 ,a#io 3ropa+ation $o#el Channel
A+ent ,esponsi"le for packet +enerations an# receptions Can think of it as an Application layer C4,'Constant 4it ,ate)- TC3- !ink- 5T3- etc1 ,Ta+ent'D!D*- T.,A- A.D*) or D!, A#-hoc network routin+ protocols Confi+ure multi hop routes for packets 66 '6ink 6ayer) ,uns #ata link protocols 5ra+mentation an# reassem"ly of packet ,uns A##ress ,esolution 3rotocol'A,3) to resolve 73 a##ress to $AC a##ress conversions
758 '7nterface 9ueue) 3ri9ueue is implemente# to +ive priority to routin+ protocol packets !upports filter to remove packets #estine# to specific a##ress $ac 6ayer 7EEE /02122 protocol is implemente# Uses ,T!:CT!:DATA:AC; pattern for all unicast pkts an# DATA for "roa#cast pkts
Net75 'Network 7nterfaces) <ar#ware interface use# "y mo"ileno#e to access the channel !imulates si+nal inte+rity- collision- t( error $ark each transmitte# packet with transmission powerwavelen+th etc1 ,a#io 3ropa+ation $o#el Uses 5riss-space attenuation'2:r2) at near #istance an# Two ray +roun# '2:r=) at far #istance Deci#es whether the packet can "e receive# "y the mo"ileno#e with +iven #istance- transmit power an# wavelen+th 7mplements .mni Directional Antenna mo#ule which has unity +ain for all #irection
Demux
R!agent (DSD")
Addr
LL
ARP
IFq
MAC
NetIF
C annel
DSR LL ARP
IFq
MAC
NetIF
C annel
,unnin+ a simulation-!cenario
#$$m
TCP
TCPsink
TCPsink TCPsink
node_(0)
node_(1)
node_(1)
!ettin+ Up *aria"les
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& % 'efine options %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& set (al(c)an) *)annel+,ireless*)annel "% c)annel t-pe set (al(prop) ropa.ation+/wo0a-1round "% radio2propa.ation model set (al(ant) 3ntenna+4mni3ntenna "% 3ntenna t-pe set (al(ll) 55 "% 5in6 la-er t-pe set (al(if7) 8ueue+'rop/ail+ ri8ueue "% 9nterface 7ueue t-pe set (al(if7len) :0 "% ma; pac6et in if7 set (al(netif) )-+,ireless )"% networ6 interface t-pe set (al(mac) Mac+<0=_11 "% M3* t-pe set (al(rp) 'S'> "% ad2)oc routin. protocol set (al(nn) = "% number of mobilenodes
!ettin+ Up *aria"les
Create simulator o-2ect:
set ns_ [new Simulator]
Create Topography:
set topo [new /opo.rap)-] $topo load_flat.rid :00 :00
Confi+urin+ $o"ileno#e
% *onfi.ure nodes $ns_ node2confi. 2ad)oc0outin. $(al(rp) @ 2ll/-pe $(al(ll) @ 2mac/-pe $(al(mac) @ 2if7/-pe $(al(if7) @ 2if75en $(al(if7len) @ 2ant/-pe $(al(ant) @ 2prop/-pe $(al(prop) @ 2p)-/-pe $(al(netif) @ 2topo9nstance $topo @ 2c)annel/-pe $(al(c)an) @ 2a.ent/race 4N @ 2router/race 4N @ 2mac/race 4AA @ 2mo(ement/race 4AA for {set i 0$ {$i B $(al(nn) $ {incr i$ { set node_($i) [$ns_ node ] $node_($i) random2motion 0 "% disable random motion $
Confi+urin+ $ovement
Configure 1nitial Position:
$node_(0) $node_(0) $node_(0) $node_(1) $node_(1) $node_(1) set set set set set set C_ D_ E_ C_ D_ E_ :?0 =?0 0?0 FG0?0 F<:?0 0?0
Create
ovement:
% Node_(1) starts to mo(e towards node_(0) $ns_ at :0?0 H$node_(1) setdest =:?0 =0?0 1:?0H $ns_ at 10?0 H$node_(0) setdest =0?0 1<?0 1?0H % Node_(1) t)en starts to mo(e awa- from node_(0) $ns_ at 100?0 H$node_(1) setdest IG0?0 I<0?0 1:?0H
FTP
TCP
Sink
node_(0)
node_(1)
c# into the #irectory an# type >ns simple-wireless1tcl? to run the simulation The simulation will +enerate a trace file name# >simple1tr?
Trace 5ile
r 100.381997477 _1_ AGT 1:0 32 1] [32 0] 1 0 --- 82 tcp 1060 [13a 1 0 800] ------- [0:0
r:receive event%##$&"%445655:time stamps7%7:no#e 2!.T:trace +enerate# "y a+ent"2:event'pkt) i#tcp: tcp packet%#8#:packet si@e%&a(he9):e(pecte# #uration of pkt transmission 'not workin+)%:sen#er mac i##:transmitter mac i#"##:pkt type 73 '/0A for A,3)- #:#: sen#er a##ress:portB %:#: receiver a##ress:portB&2: TT6 %: ne(t hop a##ress:&2 #;: TC3 se8uence B- ack B
Ne, <ireless Trace file: s -t %8&$##%=#&=2# ->s # ->( -2 -Ni # -N9 &##$## -Ny =##$## -N? #$## -Ne -%$###### -Nl !.T -N, --- - a # - ( # - s # - t # -1s #$# -1( 2$# -1t c-r -1l 2## -1f % -1i 55 -1v &2 -Pn c-r -Pi &2 -Pf # -Po # 3iel( #: event type s: sen( r: receive (: (rop 3ile( %: .eneral tag -t: time 3iel( &: Ne9t hop info ->s: i( for this no(e ->(: i( for ne9t hop to,ar(s the (estination f: for,ar(
!imulation-!cenario 77
C C C %###mF%###m net,ork ,ith & no(e C0)BG'P traffic -et,een no(e # to no(e 2 !t 2##s, no(e % moves from (=##, =##) to (=##, 4##), an( then at =##s from (4##, =##) to (=##, %##)$ Simulation time %###s$
1 ( 500, 900)
0 ( 350, 500)
150m
1 ( 500, 500)
150m
2 ( 650, 500)
1000m *1000m
( 500, 100)
!ettin+ Up *aria"les
H 'efine options H IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII set val(chan) ChannelB<irelessChannel JH channel type set val(prop) PropagationBT,o)ay.roun( JH ra(io-propagation mo(el set val(netif) PhyB<irelessPhy JH net,ork interface type set val(mac) acB"#27%% JH !C type set val(ifC) KueueB'ropTailBPriKueue JH interface Cueue type set val(ll) // JH link layer type set val(ant) !ntennaB+mni!ntenna JH antenna mo(el set val(9) %### JH L (imension of topology set val(y) %### JH M (imension of topology set val(cp) NN JH no(e movement mo(el file set val(sc) NN JH traffic mo(el file set val(ifClen) =# JH ma9 packet in ifC set val(nn) & JH num-er of mo-ileno(es set val(see() #$# set val(stop) %###$# JH simulation time set val(tr) e9p$tr JH trace file name set val(rp) 'S'* JH routing protocol set !gentTrace +N set )outerTrace +N set acTrace +33
!ettin+ Up *aria"les
H 1nitiali?e .lo-al *aria-les set nsD Enew !imulatorF GnsD color 2 4lue GnsD color 2 ,e# H +pen trace file GnsD use-newtrace HB Use new trace format set namf# Eopen nam-e(p1tr wF GnsD namtrace-all-wireless Gnamf# Gval'() Gval'y) set tracef# Eopen Gval'tr) wF GnsD trace-all Gtracef# H set up topography o-2ect set topo Enew Topo+raphyF Gtopo loa#Dflat+ri# Gval'() Gval'y) H create channel set chan Enew Gval'chan)F H Create .o( set +o#D Ecreate-+o# Gval'nn)F
Confi+urin+ $o"ileno#es
H Create the specifie( num-er of mo-ile no(es :Oval(nn); an( NattachN them H to the channel$ Three no(es are create( : no(e(#), no(e(%) an( no(e(2) GnsD no#e-confi+ -a#hoc,outin+ Gval'rp) I -llType Gval'll) I -macType Gval'mac) I -if8Type Gval'if8) I -if86en Gval'if8len) I -antType Gval'ant) I -propType Gval'prop) I -phyType Gval'netif) I -channel Gchan I -topo7nstance Gtopo I -a+entTrace .N I -routerTrace .N I -macTrace .55 I -movementTrace .55 for Jset i 0K JGi L Gval'nn) K Jincr iK J set no#eD'Gi) EGnsD no#eF Gno#eD'Gi) ran#om-motion 0 K
Confi+urin+ $ovement
H Provi(e initial (L,M, for no, PI#) co-or(inates for mo-ileno(es H Gno#eD'0) set MD NO010 Gno#eD'0) set PD O0010 Gno#eD'0) set QD 010 Gno#eD'2) set MD O0010 Gno#eD'2) set PD O0010 Gno#eD'2) set QD 010 Gno#eD'2) set MD AO010 Gno#eD'2) set PD O0010 Gno#eD'2) set QD 010 H /oa( the go( o-2ect ,ith shortest hop information H G+o#D set-#ist 2 2 2 G+o#D set-#ist 0 2 2 G+o#D set-#ist 0 2 2
!ewin+ Up
H'efine no(e initial position in nam, only fro nam for Jset i 0K JGi L Gval'nn)K Jincr iK J H The function must -e calle( after mo-ility mo(el is (efine($ GnsD initialDno#eDpos Gno#eD'Gi) A0 K H Tell no(es ,hen the simulation en(s for Jset i 0K JGi L Gval'nn) K Jincr iK J GnsD at Gval'stop) SGno#eD'Gi) resetSH K GnsD at Gval'stop) SstopS GnsD at Gval'stop) Sputs ISN! EM7T7NR111IS H GnsD haltS proc stop JK J +lo"al nsD tracef# namf# GnsD flush-trace close Gtracef# close Gnamf# K puts Gtracef# S$ 010 nn Gval'nn) ( Gval'() y Gval'y) rp Gval'rp)S puts Gtracef# S$ 010 sc Gval'sc) cp Gval'cp) see# Gval'see#)S puts Gtracef# S$ 010 prop Gval'prop) ant Gval'ant)S puts S!tartin+ !imulation111S GnsD run
C ( -t $2"646"525 ->s # ->( % -Ni # -N9 &=#$## -Ny =##$## -N? #$## -Ne -%$###### -Nl )T) -N, C0Q - a %&a - ( % - s # - t "## -1s #$# -1( 2$# -1t c-r -1l 22# -1f % -1i %56 -1v &2 -Pn c-r -Pi 4" -Pf # -Po &
Thank you R