Está en la página 1de 22

TRNG I HC BCH KHOA H NI VIN IN T - VIN THNG

BO CO BI TP LN MN C S TRUYN S LIU BI S 1
GING VIN HNG DN: TS. PHM VN TIN

NHM SINH VIN THC HIN: NHM S 8


Nguyn Hu Quang ng Vn Qun Trn Ngc Qun Bi Xun Quyt Phm Hng Sn o c Tn T12 - K54 T2 - K54 T3 - K54 T9 - K54 T10 - K54 T7 - K54 20092085 20092109 20092150 20092165 20092268 20092325

H NI 11/2012
1

MC LC I. bi v yu cu .. 3 II. Phn tch yu cu.. 4 1. Phn tch yu cu... 4 2. Thc hin yu cu.. 4 III. Lp k hoch v phn cng cng vic. 5 1. Lp k hoch.. 5 2. Phn cng cng vic . 5 IV. Qu trnh thc hin6 1. Giao thc truyn dn UDP...6 2. Cc phng thc nh tuyn6 3. Theo di s kin trn h thng v cng c Xgraph7 4. Thc hin cc yu cu.9 a. T l chim dng b m...9 b. Phn b Poisson...10 c. Gim gi tin.10 d. Bng thng ca tng lung..12 e. Tr mi lung...12 5. Thc hin m phng..13 a. Kch bn m phng13 b. Kt qu m phng..14 Kt lun..21 Ti liu tham kho.22

I.

bi v yu cu Cho mng thng tin vi cu hnh nh Hnh 1 di y. Nt s1 pht ra lung gi gi

ti u cui d1, trong khi nt s2 to ra hai lung gi gi ti nt d1 v ti nt d2. C 3 lung thng tin ni trn u s dng giao thc truyn UDP. Kch thc gi do s1 v s2 pht ra tng ng l 1300 byte v 1000 byte; s lng gi pht ra trn mi lung tun theo phn b Poisson, tc ln lt l 1000 gi/s, 1500 gi/s v 2000 gi/s.

1. Dng kch bn m phng h thng thng tin ni trn vi thi gian m phng di hn 5 pht. 2. Thu thp s liu m phng v v th t l chim dng cc b m tt c cc b nh tuyn. 3. Trong mt phin chy m phng, tc pht sinh gi ca mi lung gim i 50 gi/s sau mi khong thi gian 30s, thng k v v th hiu sut s dng bng thng ca cc lin kt trong mi khong thi gian . 4. Thay i tham s chiu di gi v tc pht sinh gi, v th biu din tr truyn thng ca cc lung. Nhn xt kt qu thu c.

II.

Phn tch yu cu 1. Phn tch yu cu Yu cu chung : ci t ubuntu , ci t ns2 , tm hiu cc thao tc c bn trn h iu hnh m ngun m, cc m phng c bn ca ns2 . Yu cu bi : To c m hnh mng thng tin trn ns2 Tm hiu v nh tuyn Thit lp c s lng gi pht sinh theo phn b Poisson Tm hiu v cc giao thc truyn thng UDP Cc hm, th tc thay i s lng gi pht sinh Tm hiu v cng c x l s liu v v th trn ns2

2. Thc hin yu cu a. T l chim dng cc b m c tnh nh sau: 100% 50 Vi queueLength l chiu di hng i tc thi. Chiu di hng i tc thi bng s gi n tr s gi i v s gi b rt b. Gim tc gi v hiu sut s dng bng thng gim tc gi : dng 1 th tc v c sau 30s th th tc c gi li 1 ln. Tnh hiu sut s dng bng thng : Tnh bng thng ca tng lung bng cch s dng Agent LossMonitor lu li nhng gi truyn, sau khi tnh c bng thng trong 1 chu k th lm sch Agent v thc hin li chu k tip theo. c. Tnh tr truyn thng ca cc lung Xy dng hm trch xut d liu trong trace-file .tr. tr c tnh bng thi im nhn c gi tin tr i thi im pht gi tin.

III. Lp k hoch v phn cng cng vic 1. Lp k hoch Bi tp ln thc hin trong vng 7 tun (bt u t tun 5 v kt thc vo tun 12) Tun 1: Ci t ubuntu v ns2, tm hiu cc thao tc lm vic n gin trn ubuntu, bu trng nhm, tm hiu yu cu v xy dng k hoch thc hin bi tp ln. Tun 2: Tm hiu giao thc UDP, pht gi tin theo phn b Poisson. Thc hin m phng 1 s h thng thng tin n gin trn ns2 Tun 3: Code m hnh mng thng tin ca bi s 1 Tun 4: Tm cch gn cc ngun d liu vo cc node v truyn nh yu cu bi Tun 5, 6: Thu thp v tnh ton s liu v hiu sut s dng hng i, bng thng, tr truyn thng ca mng v v th t s liu thu thp c. Tun 7: Hon thin v kim tra li code, vit bo co v chun b bo v. Cng vic chung: tt c cc thnh vin trong nhm u phi ci t ubuntu v ns2, m phng c cc h thng mng n gin; tm hiu giao thc truyn UDP, bo co cng vic mnh lm c hng tun i vi cc bn cn li trong nhm, hp nhm nh k 2ln/tun vo cui mi bui hc v chiu th 7. Cng vic tng thnh vin STT 1 H v Tn Nguyn Hu Quang o c Tn Cng vic Tm hiu cng c xgraph v AWK. Tnh ton t l chim dng b m v v th. 2 ng Vn Qun Bi Xun Quyt Gim tc pht sinh gi ca mi lung i 50 gi/s sau mi khong thi gian 30s, thng k v v th hiu sut s dng bng Hon thnh Trng thi Hon thnh 2. Phn cng cng vic

thng ca cc lin kt trong mi khong thi gian . 3 Trn Ngc Qun Phm Hng Sn Xy dng tin trnh Poisson, v th biu din tr truyn thng ca cc lung. Hon thnh

IV. Qu trnh thc hin 1. Giao thc truyn dn UDP Giao thc UDP (User Datagram Protocol) hay cn gi l giao thc gi ngi dng l mt trong hai giao thc ct li ca giao thc TCP/IP, cho php ngi dng c th gi nhng d liu ngn c gi l datagram t my tnh ny n my tnh khc. UDP khng m bo s tin cy v th t truyn nhn, cc gi d liu c th n khng ng th t hoc b mt m khng c thng bo. Tuy nhin, UDP nhanh v hiu qu hn i vi nhng mc tiu nh kch thc nh v yu cu kht khe v thi gian, giao thc ny hu dng i vi vic tr li cc truy vn vi s lng ln ngi yu cu. Nhng ng dng ph bin s dng UDP nh DNS (Domain Name System), ng dng streaming media, Voice over IP, Trivial File Transfer Protocol (TFTP), v game trc tuyn.

2. Cc phng thc nh tuyn


NS2 thc thi ba chnh sch nh tuyn: static routing (nh tuyn tnh), session routing (nh tuyn phin), DV routing (nh tuyn vc t khong cch) v Link-state (trng thi lin kt). Dng phng thc rtproto trong lp Simulator xc nh chnh sch nh tuyn c dng. o $ns rtproto <type>
o type: Static, Session, DV, cost, multicast-path, LS.

- Link-state : s dng thut ton SPF (shortest path first) cp nht cc thng tin
v c ch nh tuyn cho cc node trn h thng mng. Mi node s gi bng m t trng thi ca cc lin kt ring ca mnh ln mng. Ch cc thay i mi c gi i. u im l tc cao, khng chim dng bng thng nhiu nh thut ton DV tuy nhin thc hin phc tp. i vi m hnh ln thut ton ny c th lm tng tr truyn gi tin.

- Distance vector : (cn gi l thut ton Bellman-Ford) gi bng nh tuyn ti


cc node ln cn theo mt chu k nht nh. u im l d thc hin, d kim tra. Tuy nhin thi gian cp nht lu, chim dng bng thng ln trn mng.

- Static routing : Phng thc tnh ton nh tuyn Static l phng thc tnh
ton ng truyn mc nh trong NS-2. Phng thc ny s dng thut ton SPF. Thut ton tnh ng truyn chy chnh xc mt ln ti lc khi ng m phng. Khi cu trc mng thay i phi cp nht li, do ch thch hp trong h thng n gin, c kt ni n v ng truyn d liu c xc nh trc.

- Session: S dng thut ton SPF tnh ton ti u ng truyn, bng nh


tuyn s c cp nht ngay lp tc khi topo mng c s thay i. 3. Theo di s kin trn h thng v cng c Xgraph a. Cc lnh c bn dng theo di cc s kin trn h thng

- Cn bng cp pht b m cho tt c cc file theo di: $ns flush-trace - To mt i tng theo di:
Cu trc: create-trace {type filename scr dst} V d : $ns create-trace Drop $tf $n0 $n2

- Theo di tt c cc s kin trn h thng:


$ns trace-all $trace_file b. Cu trc file trace

Mi mt lnh theo di trong cc lnh trn s c cc cu trc u ra khc nhau. y chng ta ch xt n cu trc file u ra ca lnh trace -all. Vi cc cng c phn tch file d liu c sn nh awk, grep, perl,. Chng ta c th c c tt c cc thng tin mong mun trong qu trnh h thng mng c m phng bng cch phn tch file trace-all. File trace c t chc trong 12 trng nh trong hnh di

- Trng u tin m t loi s kin, c cho bi mt trong 4 k t r, +, -, d


tng ng vi cc trng hp nhn ( u ra ca link), xp vo trong hng i (enqueued), ri khi hng i (dequeued), b hy (dropped)

- Trng th hai biu din thi gian s kin xut hin. - Thng bo node input ca link ni s kin xy ra. - Thng bo node ouput ca link ni s kin xy ra. - Loi gi tin ( v d TCP, CBR, tn loi tng ng vi tn ca application m
chng ta t, v d trong phn trc th application TCP c gi l tcp).

Kch c gi tin. Mt vi loi c. Chng ta s xt phn sau. Flow id (fid) ca Ipv6 m ngi dng thit lp cho mi lung (flow) ti u vo OTcl cript. Ta c th dng trng ny phn tch kt qu, cng nh thit lp mu sc cho cc lung trong m phng NAM.

a ch ca ngun, ni pht gi tin, c cho di dng node.port.

- a ch ca ngun ch, ni nhn gi tin, c cho vi cng dng nh trn. - S chui cc gi tin ca mt lp giao thc mng. Mc d thnh phn UDP
trong mng thc t khng c s cc chui nhng ns vn gi li cc vt (track) phn tch kt qu.
8

- Trng cui cng ghi ch s id ca gi tin (unique id of packet).


c. Xgraph Xgrap l mt cng c v th c cung cp bi ns. Xgraph cho php chng ta to ra cc file postcript , nh , v 1 s nh dng khc bng cch n vo Hdcpy. cu lnh gi Xgraph c th c khai bo trong kch bn TCL do c th xut ra ngay th khi kt thc m phng . u vo ca Xgraph l 1 hoc nhiu file cha mi cp gi tr x-y trn 1 dng (mi dng s cha ta ca 1 im trn th ) . V d lnh : Xgraph f1 f2 s v ra trn cng 1 th ca file f1,f2 Mt s la chn khi s dng Xgraph :

- Title : -t ten_do_thi - Kch thc : -geometry xsize x ysize - Tiu cho cc trc : -x xtitle y ytitle - Mu ca ch v li v - Mu nn bg
4. Thc hin cc yu cu a. T l chim dng b m T l chim dng cc b m c tnh nh sau: 100% 50 Vi queueLength l chiu di hng i tc thi, c tnh bng s gi n tr s gi i v s gi b rt. Code: Vi hng i ca lin kt gia node 3 v node 4, t l chim dng hng i c lu trong file queuesize.tr set qfile [$ns monitor-queue $node_3 $node_4 [open queue.tr w] 0.5] [$ns link $node_3 $node_4] queue-sample-timeout; proc QueueLength {} { global ns qsize qfile node_3 node_4
9

# thoi gian lay mau la 0.5s set time 0.5 set now [$ns now] $qfile instvar parrivals_ pdepartures_ pdrops_ # ty le chiem dung bo dem: queueLength/50 *100% = queueLength*2 % puts $qsize "$now [expr 2.0*[expr $parrivals_-$pdepartures_$pdrops_]]" set bdepartures_ 0 $ns at [expr $now + $time] "QueueLength" } Sau khi c file queuesize.tr ta v c th t l theo cu lnh: exec xgraph queuesize.tr -geometry 800x400 -t "Queue occupancy rate" x "secs" -y "percentage(%)" & Hng i ca lin kt gia cc node khc c tnh tng t. b. Phn b Poisson Ta xy dng tin trnh Poisson qua mt i tng ExponentialOn/Off vi cc thnh phn tham s: . packetsize_ dung lng c nh ca gi d liu . burst_ time_ thi gian bt khi to . idle_ time_ thi gian tt khi to . rate_ tc ca gi to ra tin trnh Poisson ta cho tham s burst_time_ v 0 v idle_time bng
1

ca tin trnh Poisson.

c. Gim gi tin Ngun s1 pht cc gi tin vi tc l 1.3 MBps Ngun s2 pht ra 2 lung vi cc gi tin tc l 1.5MBps v 2MBps C sau 30s ngun s1 v s2 gim tc gi l 50 gi/s nn ta c lng gim sau 30s l
10

s1: 50 * 1300 = 65000 bytes s2: 50 * 1000 = 50000 bytes (2 lung) Khi thay i s gi () s dn n idle_time_ v rate_ thay i. Cch tnh idle_time_ nh sau:
1 __

= , vy sau khi gim th


1 50

idle_time_ = -

Rate c tnh nh sau: s1: rate_ = rate_ 65000 (bytes) s2: rate_ = rate_ 50000 (bytes)

Sau khi tnh c rate_ v idle_time ca 3 lung ta lu trong cc file trafficfile1.tr trafficfile2.tr trafficfile3.tr Code: set time30 30 proc PackageDecrease {} { global ns traffic1 traffic2 traffic3 time30 TrafficFile1 TrafficFile2 TrafficFile3 set now [$ns now] set idle1 [$traffic1 set idle_time_] set idle2 [$traffic2 set idle_time_] set idle3 [$traffic3 set idle_time_] set rate1 [$traffic1 set rate_] set rate2 [$traffic2 set rate_] set rate3 [$traffic3 set rate_] $traffic1 set idle_time_ [expr 1.0/[expr 1.0/$idle1 - 50]] $traffic2 set idle_time_ [expr 1.0/[expr 1.0/$idle2 - 50]] $traffic3 set idle_time_ [expr 1.0/[expr 1.0/$idle3 - 50]] $traffic1 set rate_ [expr $rate1 - 65000] $traffic2 set rate_ [expr $rate2 - 50000] $traffic3 set rate_ [expr $rate3 - 50000] # luu cac gia tri rate va idle_time vao file puts $TrafficFile1 "$now [$traffic1 set rate_] [$traffic1 set idle_time_]" puts $TrafficFile2 "$now [$traffic2 set rate_] [$traffic2 set idle_time_]" puts $TrafficFile3 "$now [$traffic3 set rate_] [$traffic3 set idle_time_]"
11

$ns at [expr $now + $time30] "PackageDecrease" } d. Tnh bng thng ca tng lung S dng Agent LossMonitor lu li nhng gi truyn, sau khi tnh c bng thng trong 1 chu k th lm sch Agent v thc hin li chu k tip theo. Code proc BandWidth {} { global ns sink1 sink2 sink3 BwFile1 BwFile2 BwFile3 set time 3 set bw1 [$sink1 set bytes_] set bw2 [$sink2 set bytes_] set bw3 [$sink3 set bytes_] set now [$ns now] puts $BwFile1 "$now [expr $bw1/$time*8/1000]" puts $BwFile2 "$now [expr $bw2/$time*8/1000]" puts $BwFile3 "$now [expr $bw3/$time*8/1000]" $sink1 set bytes_ 0 $sink2 set bytes_ 0 $sink3 set bytes_ 0 $ns at [expr $now+$time] "BandWidth" } e. Tnh tr ca mi lung Da vo nh dng ca file trace ta thu thp c s liu tnh tr xy ra trn ng truyn. Tr ca cc gi tin c tnh nh sau: thi im gi tin n node ch tr i thi im gi tin node gi. Vic ny c thc hin bng hm vit trong file .awk. Hm c vit nh sau(vi lung 1 t node 0 ti node 8) BEGIN {TimeSend[50000];TimeReceive[50000];Delay[50000]} { # doc gia tri trace-file theo cot action = $1; time = $2; from = $3;
12

to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; if((action=="+")&&(from == "0")) TimeSend[packet_id] = time; if((action=="r")&&(to == "8")) { Timereceive[packet_id]=time; Delay[packet_id] = Timereceive[packet_id]TimeSend[packet_id]; print packet_id" "Delay[packet_id]; } } END {} xut d liu ra file phc v vic v th ta dng cu lnh sau exec awk f <AWKFileName> <TraceFileName> > <DataFile> V. Thc hin m phng 1. Kch bn m phng Thi im(s) 0.0 Mc ch Bt u thc hin:

- Tnh bng thng - Tnh t l chim dng hng i - Lung 1,2,3 truyn d liu
30.0 Bt u gim tc gi 50 gi/s sau chu k 30s

13

300.0 301.0

Lung 1,2,3 kt thc truyn d liu ng cc file trace v data V th t l chim dng b m, hiu sut s dng bng thng v tr ng truyn Kt thc m phng

2 Kt qu m phng a. Mng cc lin kt

b. T l chim dng b m ca cc lin kt

14

Lin kt gia node 1 v node 3

Lin kt gia node 2 v node 3

15

Lin kt gia node 1 v node 4

Lin kt gia node 2 v node 6

16

Lin kt gia node 3 v node 4

Lin kt gia node 4 v node 5

17

Lin kt gia node 4 v node 6 c. Hiu sut s dng bng thng ng mu , xanh dng v xanh l cy tng ng vi cc lung 1, lung 2 v lung 3.

18

d. Tr ng truyn

Tr trn lung 1

Tr trn lung 2

19

Tr trn lung 3.

20

KT LUN
Mn c s truyn s liu l mt mn hc chuyn ngnh quan trng v hu ch. N cung cp nhng kin thc c bn nht cho sinh vin c nh hng theo chuyn ngnh in t vin thng. Theo quan im hc phi i i vi hnh, em thy vic nh trng v cc Thy c to iu kin chng em c c hi c lm bi tp ln l mt vic rt c ngha. bi chng em c giao cng rt ph hp vi trnh hin ti ca chng em. Sau khi hon thnh bi tp ny chng em hc hi v tch ly c rt nhiu kin thc. Trc tin phi k n l kin thc v mng thng tin, cc giao thc truyn v gi gi tin,.. Th hai phi k n l bit cch s dng phn mm m ngun m v cng c h tr thit k mng rt hu hiu l NS2. Mc d c gng ht sc nhng chc chn bi lm ca chng em cn nhiu thiu st, mong Thy gp cho chng em nhng nhn xt qu bu bi tp ln ny c hon thin hn. Li cui, nhm chng em xin knh chc Thy sc khe, cng tc tt, v gt hi c nhiu thnh cng hn na trong o to cng nh nghin cu! Nhm chng em xin chn thnh cm n!

21

Ti liu tham kho


1. Slide bi ging C s mng thng tin ca Thy Phm Vn Tin 2. Ti liu tham kho NS2 (Ns2_manual, Introduction to Network Simulator NS2 Teerawat Issariyakul) 3. Ti liu hng dn NS2 http://www.isi.edu/nsnam/ns/tutorial/

22