btl

Upload: le-khanh-vu

Post on 05-Mar-2016

217 views

Category:

Documents


1 download

DESCRIPTION

:)

TRANSCRIPT

Nhm 10

BO COC S MNG THNG TIN

ti 5o bng thng ca nhiu lung lu lng gi qua mt mng gm nhiu nt

Thnh vin trong nhm 101. L inh Khnh V 201228162. n Quang Khi 201219183. Phm Tun Long 20135936

MC LC

MC LC11.Yu cu bi tp ln12.Phn chia cng vic22.1 L inh Khnh V22.2 n Quang Khi22.3 Nguyn Tun Long23.Qu trnh thc hin23.1M phng h thng23.2Kt qu m phng114.Kt lun125.Ti liu tham kho12

Nhm 10

12 | Page

1. Yu cu bi tp ln

2. Phn chia cng vic2.1 L inh Khnh V Vit code m phng trn NS2:. To nt,to cc ng link. M phng qu trnh truyn d liu. M phng qu trnh Link3 bi t v tr li hot ng bnh thng. V th lu lng thc s ca cc Link1 va Link32.2 n Quang Khi Vit code m phng trn NS2 : Tnh v v bng thng ca cc lung lu lng To nt. To hng i. V bng thng ca lung lu lng. Xy dng Procedure Finish( )2.3 Nguyn Tun Long Vit code m phng trn NS2 : V th tc mt gi e(t). To nt. To cc lung lu lng gia cc Agent3. Qu trnh thc hin3.1 M phng h thngS dng cng c NS2 m phng h thng gm 3 lung lu lng gi qua 5 nt. Gi thit: di hng i: k = 6 3 lung d liu (S1,D1),(S2,D2),(S3,D3) pht gi vi di 145bytes. V khong thi gian gia cc gi l (S1)= 450kbit/s, (S2)=250kbit/s, (S3)= 600kbit/s. Cc link u c dung lng v tr nh nhau v bng:1Mb/s v 130ms.#===================================#To i tng#===================================set ns [new Simulator]#Set protocol (Auto-routting)$ns rtproto DV#Xc nh mu sc cho cc lung d liu$ns color 1 Blue$ns color 2 Red$ns color 3 Green# t kch thc set pksize 145.0set lambdas1 450.0set lambdas2 250.0set lambdas3 600.0#Set Queue Size#Default = 50set queuesize 6#Open the trace fileset TraceAll [open out.tr w]$ns trace-all $TraceAll

set f0 [open Flow_S1-D1.tr w]set f1 [open Flow_S2-D2.tr w]set f2 [open Flow_S3-D3.tr w]set f3 [open Flow_L1+L3.tr w]#M file Namset namFile [open out.nam w]$ns namtrace-all $namFile#To cc nt v mu sc#Ngunset s1 [$ns node]$s1 color Red$s1 shape box$s1 label "S1"set s2 [$ns node]$s2 color Red$s2 shape box$s2 label "S2"set s3 [$ns node]$s3 color Red$s3 shape box$s3 label "S3"#chset d1 [$ns node]$d1 color Black$d1 shape box$d1 label "D1"set d2 [$ns node]$d2 color Black$d2 shape box$d2 label "D2"set d3 [$ns node]$d3 color Black$d3 shape box$d3 label "D3"#Nt mngset n1 [$ns node]$n1 color Blue$n1 label "Router01"set n2 [$ns node]$n2 color Blue$n2 label "Router02"set n3 [$ns node]$n3 color Blue$n3 label "Router03"set n4 [$ns node]$n4 color Blue$n4 label "Router04"set n5 [$ns node]$n5 color Blue$n5 label "Router05"

#To ng nt gia cc nt

$ns duplex-link $n1 $n2 1Mb 130ms RED$ns duplex-link $n2 $n4 1Mb 130ms RED$ns duplex-link $n1 $n3 1Mb 130ms RED$ns duplex-link $n3 $n5 1Mb 130ms RED$ns duplex-link $n4 $n5 1Mb 130ms RED

#ng ni t ngun n mng$ns duplex-link $s1 $n1 10Mb 130ms DropTail$ns duplex-link $s2 $n3 10Mb 130ms DropTail$ns duplex-link $s3 $n3 10Mb 130ms DropTail

#ng ni t mng ti ch$ns duplex-link $n2 $d3 10Mb 130ms DropTail$ns duplex-link $n4 $d1 10Mb 130ms DropTail$ns duplex-link $n4 $d2 10Mb 130ms DropTail#To di v cch sp xp hng i$ns queue-limit $n1 $n2 $queuesize$ns queue-limit $n2 $n4 $queuesize$ns queue-limit $n1 $n3 $queuesize$ns queue-limit $n3 $n5 $queuesize$ns queue-limit $n5 $n4 $queuesize$ns duplex-link-op $n1 $n2 queuePos 0.5$ns duplex-link-op $n1 $n3 queuePos 0.5$ns duplex-link-op $n2 $n4 queuePos 0.5$ns duplex-link-op $n3 $n5 queuePos 0.5$ns duplex-link-op $n4 $n5 queuePos 0.5#Hin tc trn ng dn$ns duplex-link-op $n1 $n2 label " 1Mbps"$ns duplex-link-op $n1 $n3 label " 1Mbps"$ns duplex-link-op $n2 $n4 label " 1Mbps"$ns duplex-link-op $n3 $n5 label " 1Mbps"$ns duplex-link-op $n4 $n5 label " 1Mbps"

#===================================#Setup Position for Topo#Chu y: De co dinh vi tri cho moi node can phai viet cap node giong nhu thu tu da tao link giua cac node#===================================$ns duplex-link-op $n1 $n2 orient right$ns duplex-link-op $n2 $n4 orient down$ns duplex-link-op $n1 $n3 orient left-down$ns duplex-link-op $n3 $n5 orient right$ns duplex-link-op $n4 $n5 orient left

$ns duplex-link-op $s1 $n1 orient right-down$ns duplex-link-op $s2 $n3 orient right-down$ns duplex-link-op $s3 $n3 orient right

$ns duplex-link-op $n2 $d3 orient right-up$ns duplex-link-op $n4 $d1 orient right$ns duplex-link-op $n4 $d2 orient right-up

#===================================#Creat protocol, traffic#===================================set udp0 [new Agent/UDP]$udp0 set class_ 1$ns attach-agent $s1 $udp0set udp1 [new Agent/UDP]$udp1 set class_ 2$ns attach-agent $s2 $udp1set udp2 [new Agent/UDP]$udp2 set class_ 3$ns attach-agent $s3 $udp2

#Enable monitor loss packetset sink0 [new Agent/LossMonitor]$ns attach-agent $d1 $sink0set sink1 [new Agent/LossMonitor]$ns attach-agent $d2 $sink1set sink2 [new Agent/LossMonitor]$ns attach-agent $d3 $sink2

#Connect the traffic sources$ns connect $udp0 $sink0$ns connect $udp1 $sink1$ns connect $udp2 $sink2

set InterArrivalTime0 [new RandomVariable/Exponential]$InterArrivalTime0 set avg_ [expr 1/$lambdas1]set InterArrivalTime1 [new RandomVariable/Exponential]$InterArrivalTime1 set avg_ [expr 1/$lambdas2]set InterArrivalTime2 [new RandomVariable/Exponential]$InterArrivalTime2 set avg_ [expr 1/$lambdas3]

#===================================#Send packet#===================================proc sendpacket0 {} {global ns udp0 InterArrivalTime0 pksize#Get the current timeset time [$ns now]#Schedule for next send packet time $ns at [expr $time + [$InterArrivalTime0 value]] "sendpacket0"$udp0 send $pksize}

proc sendpacket1 {} {global ns udp1 InterArrivalTime1 pksizeset time [$ns now]$ns at [expr $time + [$InterArrivalTime1 value]] "sendpacket1"$udp1 send $pksize}

proc sendpacket2 {} {global ns udp2 InterArrivalTime2 pksizeset time [$ns now]$ns at [expr $time + [$InterArrivalTime2 value]] "sendpacket2"$udp2 send $pksize}

#2. Do bang thong cac luon (Si,Di) su dungproc record_bandwidth {} {global sink0 sink1 sink2 f0 f1 f2 f3#Get an instance of the simulatorset ns [Simulator instance]#Set the time get sampleset time 0.1#How many bytes have been tranfer by the traffic sinkset bw0 [$sink0 set bytes_]set bw1 [$sink1 set bytes_]set bw2 [$sink2 set bytes_]#Get the current timeset now [$ns now]#Calculate the bandwidth in Kbit/s (Si, Di)#S1-D1puts $f0 "$now [expr $bw0/$time*8/1000]" #S2-D2puts $f1 "$now [expr $bw1/$time*8/1000]" #S3-D3puts $f2 "$now [expr $bw2/$time*8/1000]"#Traffic over L1 + L3puts $f3 "$now [expr ($bw0+$bw1+$bw2)/$time*8/1000]"#Reset the bytes_ value$sink0 set bytes_ 0$sink1 set bytes_ 0$sink2 set bytes_ 0

#Re-Schedule the procedure$ns at [expr $now + $time] "record_bandwidth"}

proc finish {} {global ns namFile f0 f1 f2 f3 TraceAll$ns flush-trace#Close trace fileclose $namFileclose $f0close $f1close $f2close $f3close $TraceAll#Execute nam on the trace fileexec nam -a out.nam &exec awk -f lost_pkt.awk out.tr > Lost_p.trexec xgraph Flow_S1-D1.tr Flow_S2-D2.tr Flow_S3-D3.tr Flow_L1+L3.tr -geometry 800x400 -t "Bng thng theo lung" -x "Thi gian(s)" -y "Tc (Kbit/s)" &exec xgraph Lost_p.tr -geometry 800x400 -t "Mt gi" -x "Thi gian(s)" -y "Gi" &exit 0}$ns at 0.0 "record_bandwidth"$ns at 0.1 "sendpacket0"$ns at 0.1 "sendpacket1"$ns at 0.1 "sendpacket2"$ns rtmodel-at 45.0 down $n4 $n5$ns rtmodel-at 95.0 up $n4 $n5$ns at 100.0 "finish"$ns run

3.2 Kt qu m phng

Hnh 1: M phng cc nt mng trn NAM

Hnh 2: th bng thng cc lung

Hnh 3: th mt gi4. Kt lun Cc ngun lu lng phn chia ti nguyn bng thng rt ph hp thc t v l thuyt. NS-2 l mt cng c m phng kh mi, li vit trn ngn ng tcl nn trong qu trnh lm bi tp ln nhm chng em gp phi nhiu kh khn, v vn cha hon thnh c cng vic c giao: Cha tnh ton chnh xc nht Lu Lng ca Link3.5. Ti liu tham kho http://www.isi.edu/nsnam/ns/tutorial/index.html http://vntelecom.org/diendan/forumdisplay.php?f=53http://forum.ubuntu-vn.org