Hướng phát triển đề tài.

Một phần của tài liệu tìm hiểu voip trên nền 802.11 (Trang 89 - 100)

Với ứng dụng voice chỉ là một phần của ứng dụng đa phương tiện trong mạng số. Để nghiên cứu thêm các thơng số khác phục vụ cho dịch vụ .Như kỹ thuật bảo mật, quản lý động, kỹ thuật Qos …

#---Khởi tạo thơng số--- global opt

set opt(chan) Channel/WirelessChannel

set opt(prop) Propagation/TwoRayGround ;# mơ hình truyền sĩng set opt(netif) Phy/WirelessPhy

set opt(mac) Mac/802_11

set opt(ifq) Queue/DropTail/PriQueue ;# interface queue

set opt(ll) LL ;# link layer

set opt(ant) Antenna/OmniAntenna set opt(x) 1000

set opt(y) 1000

set opt(ifqlen) 50 ;# length of queues set opt(tr) wcwqos2.tr ;# trace file

set opt(tr1) wcwqos21.tr

set opt(namtr) wcwqos2.nam ;# sim file set opt(namtr1) wcwqos21.nam

set opt(nn) 20 ;# numnode set opt(adhocRouting) DSDV

set opt(cp) ""

set opt(sc) "../mobility/scene/scen-20-test" ;# tạo vị trí các node set opt(stop) 2000 ;# thời gian dừng chương trình set num_wired_nodes 2

set num_bs_nodes 2 #khởi tạo theo dõi

set f0 [open out0.tr w] set f1 [open out1.tr w] set f2 [open out2.tr w] set f3 [open out50ms.tr w] proc init {} {

global f0 f1 f2 f3 set f0 [open out0.tr w] set f1 [open out1.tr w] set f2 [open out2.tr w] set f3 [open out50ms.tr w] }

LL set delay_ 25us LL set bandwidth_ 0

# ---chế độ hàng đợi--- Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1

#unity gain, omni-directional antennas

#set up the antennas to be centered in the node and 1.5 meters above it Antenna/OmniAntenna set X_ 0 Antenna/OmniAntenna set Y_ 0 Antenna/OmniAntenna set Z_ 1.5 Antenna/OmniAntenna set Gt_ 1.0 Antenna/OmniAntenna set Gr_ 1.0 #wireless-phy.cc

#Initialize the SharedMedia interface with parameters to make #it work like the 914MHz Lucent WaveLAN DSSS radio interface Phy/WirelessPhy set CPThresh_ 10.0 ;#threshold physical, Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#connection pattern Phy/WirelessPhy set RXThresh_ 3.652e-10

Phy/WirelessPhy set Rb_ 2*1e6 Phy/WirelessPhy set Pt_ 0.2818

Phy/WirelessPhy set freq_ 914e+6 ;#freq being used Phy/WirelessPhy set L_ 1.0

#-pl <path-loss-exponent> -std <shadowing-deviation> -Pt <transmit-power>-fr <frequency> -Gt <transmit-antenna-gain> -Gr <receive-antenna-gain>-L <system- loss> -ht <transmit-antenna-height> -hr <receive-antenna-height>-d0 <reference- distance>-r <receive-rate>-m <propagation-model>

# --- set ns_ [new Simulator]

$ns_ node-config -addressType hierarchical $ns_ color 0 Blue

$ns_ color 1 green $ns_ color 2 Red

;#(wired,wireless,wireless) AddrParams set cluster_num_ $cluster_num

lappend eilastlevel 1 1 4 1 ;#so luong node cua moi cluster AddrParams set nodes_num_ $eilastlevel

set tracefd [open $opt(tr) w] $ns_ trace-all $tracefd

set namtracefd [open $opt(namtr) w]

#---theo doi traffic ca wireless va wireline.--- $ns_ namtrace-all-wireless $namtracefd 800 600

#---tạo topo mang--- set topo [new Topography]

$topo load_flatgrid $opt(x) $opt(y)

# god needs to know the number of all wireless interfaces #General Operations Director (GOD) +

set god_ [create-god [expr $opt(nn) +$num_bs_nodes + $num_wired_nodes ]] #create wired nodes, domain=0

#each cluster each node in just one domain set temp {0.0.0 0.1.0}

for {set q 0} {$q < $num_wired_nodes} {incr q} { set W($q) [$ns_ node [lindex $temp $q]]

$W($q) color "#66660000ffff" }

$W(0) set X_ 00.0 $W(0) set Y_ 100.0

#---config BS node--- ---- $ns_ node-config -adhocRouting $opt(adhocRouting) \

-llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \

-phyType $opt(netif) \ -channel [new $opt(chan)] \ -topoInstance $topo \ -wiredRouting ON \ -agentTrace ON \ -routerTrace ON \ -macTrace ON #$mobilenode start set temp {1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 }

#domain.cluster.node for fist wireless domain

set BS(0) [$ns_ node [lindex $temp 0]] ;#gan cho bs(0)1.0.0 set BS(1) [$ns_ node 2.0.0] ;#gan cho bs(1)2.0.0 $BS(0) random-motion 1 $BS(1) random-motion 1 $BS(0) color "#ffff00000000" $BS(1) color "#ffff00000000" $ns_ at 0.0 "$BS(0) label BS(0)" $ns_ at 0.0 "$BS(1) label BS(1)"

#$ns_ initial_node_pos $BS(0) 100 ;#khoi tao kich thuoc cua node #$ns_ initial_node_pos $BS(1) 100

#---configure for mobilenodes--- --- $ns_ node-config -wiredRouting OFF\-wirelessRouting ON

#tao cac mobile node- co dia chi ke thua tu cac station cua no, chi thi trang thai ket noi #do tram nao quan ly

for {set j 0} {$j < $opt(nn)} {incr j} {

set node_($j) [ $ns_ node [lindex $temp [expr $j+1]] ] $node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]

$node_($j) random-motion 1 }

$ns_ duplex-link $W(1) $BS(0) 11Mb 2ms DropTail ;# $ns_ duplex-link $W(1) $BS(1) 11Mb 2ms DropTail #create the performance for 4 node

$ns_ duplex-link-op $W(0) $W(1) orient down $ns_ duplex-link-op $W(1) $BS(0) orient left-down $ns_ duplex-link-op $W(1) $BS(1) orient right-down #khoi tao vi tri cho cac node, kich co cua cac node wireless for {set q 0} {$q < $opt(nn)} {incr q} {

$ns_ initial_node_pos $node_($q) 20;#try to positor $node_($q) color "#33339999"

$ns_ at 0.0 " $node_($q) color #33339999f "

}

#---Define a 'finish' procedure--- --- proc finish {} {

global f0 f1 f2 f3 numnode t qe i pktsdelay delaychan loadper sim_interval #Close the output files

close $f0 close $f1 close $f2

puts "so luong node la $numnode"

puts "so luong tong packet tre vuot qua 50ms : $t" #so luong pkts tre cua moi kenh trong tung khoang sim for {set k 0} { $k < $numnode} { incr k } {

puts "so luong packet tre vuot qua 50ms channel$k: $pktsdelay($k)" }

for {set k1 0} { $k1 < $sim_interval} { incr k1 } {

puts "tai mang trong moi khoang thoi gian mo phong thu $k1 = $loadper($k1)" puts "num of channel delay not precede 50ms qe($k1)= $qe($k1)" puts $f3 " $loadper($k1) [expr $numnode - $qe($k1)]"

} close $f3

$pktsdelay($i)" } #Execute NAM on the trace file exec nam wcwqos2.nam

#Call xgraph to display the results

exec xgraph out0.tr -geometry 600x400 -t "timedelay " -x "secs" -y "secs" -m & #exec xgraph out1.tr -geometry 800x400 -t "bandwith" -x "secs" -y "kbps" & #exec xgraph out2.tr -geometry 800x200 -t "npkts" -x "secs" -y "pkts" & #exec xgraph out50ms.tr -geometry 600x400 -bd "green" -t "number of voice channel with delay 50ms" -x "Load(%)" -y "nvoicechannel" -m &

exec xgraph out50ms.tr -geometry 600x400 -bd "green" -t "so luong kenh voice thoa delay <50ms" -x "Load(%)" -y "nvoicechannel" -m &

exit 0 }

#---

#Define a procedure that attaches a UDP agent to a previously created node #'node' and attaches an Expoo traffic generator to the agent with the

#characteristic values 'size' for packet size 'burst' for burst time,

#'idle' for idle time and 'rate' for burst peak rate. The procedure connects #the source with the previously defined traffic sink 'sink' and returns the #source object.

proc attach-expoo-traffic { node sink size burst idle rate } { #Get an instance of the simulator

set ns_ [Simulator instance]

#Create a UDP agent and attach it to the node

set source [new Agent/UDP] ;#using udp protocol $ns_ attach-agent $node $source

$traffic set idle_time_ $idle ;#the average“off”time for the generator $traffic set rate_ $rate ;#the sending rate during“on”times ;#ttl--> time to live, default = 32

;#dung cho traffic khong day, Wlan #Attach traffic source to the traffic generator

$traffic attach-agent $source #Connect the source and the sink $ns_ connect $source $sink return $traffic

}

#--- set numnode 20 ;# so luong node

set start_rate 0.0 ;# thoi gian bat dau mo phong set time_sim 20.0 ;# khoang mo phong

set load 0.0 ;# tai mang

set num_chan 0 ;#so kenh thoa man set delay 0.0

for {set i 0} {$i < $numnode} {incr i} { set sink($i) [new Agent/LossMonitor] $ns_ attach-agent $W(0) $sink($i)

}

#kiem tra thoa man timedelay = 50ms,100ms

proc delaycheck { i timedelay LM startsim endsim} {

global M1 f0 f1 f2 maxdelay mindelay sink5 sink0 sink1 sink2 t pktsdelay1 global pktsdelay delaychan sumband

#Get an instance of the simulator set ns_ [Simulator instance]

#Set the time after which the procedure should be called again set time 0.01

#Get the current time set now [$ns_ now]

#Calculate the bandwidth (in MBit/s) and write it to the files # puts $f0 "$now [expr [expr $now - $bw0]/$time]"

if {$bw0 > 0} {

puts $f0 "$now [expr $now - $bw0]" }

#puts $f1 "$now [expr $bw1/$time*8/1000000]" #puts $f2 "$now [expr $bw2]"

puts "$now $bw0 [expr [expr $now - $bw0]*1000 ]"

if { ($now <= $endsim)& ([expr $now - $bw0] >= $timedelay) & ($bw0 > $startsim )} {

incr t

incr pktsdelay($i)

#puts "so luong packet tre vuot qua 50ms channel$i: $pktsdelay($i)" set intervaldelay [expr $now - $bw0]

#puts "*** $now---- $bw0 --- $intervaldelay *** " }

#Reset the bytes_ values on the traffic sinks $LM set lastPktTime_ 0

$LM set bytes_ 0 $LM set npkts_ 0 #Re-schedule the procedure if { ($now <= $endsim)} {

$ns_ at [expr $now+$time] "delaycheck $i $timedelay $LM $startsim $endsim" }

for {set i 0} {$i < $numnode} {incr i} {

set source($i) [attach-expoo-traffic $node_($i) $sink($i) $size $ontime $idle $rate] $ns_ at $start "$source($i) start"

$ns_ at $stop "$source($i) stop" }

}

#---tinh so kenh delay trong moi khoang thoi gian mo phong--- proc ndelaychan {numnode so } {

global pktsdelay qe

for {set i1 0 } {$i1 < $numnode } {incr i1 } { if { $pktsdelay($i1) >0.0 } { incr qe($so) }

puts "num of channel delay not precede 50ms at sim oder $so = , $qe($so) " }

}

set sim_interval 8 ;#so lan thuc hien mo phong theo tai set start 0 ;# thoi gian bat dau

set T_sim 20.0 ;# khoang thoi gian set end $T_sim

set rate 64000.0 ;# toc do cua cac kenh set size 252 ;#kich co packet

set ontime 2 ;# thoi gian on cua nguon set idle 1 ;# thoi gian off cua nguon set t 0 #tong so packet tre

set delaychan 0 # so kenh tre trong moi lan thuc hien for {set l 0} {$l < $sim_interval } { incr l} {

set qe($l) 0

$ns_ at $start "reset"

segment-sim $start $end $size $ontime $idle $rate for {set i 0 } {$i < $numnode } {incr i } {

set pktsdelay($i) 0

#if {[delaycheck $i 0.05 $sink($i) $start $end]== 1 } { incr numchan}; delaycheck $i 0.05 $sink($i) $start $end

set loadper($l) [expr $sumband($l)/11000000*100] $ns_ at $end " ndelaychan $numnode $l ";

set start [expr $start + $T_sim + 5.0] set end [expr $start + $T_sim]

set rate [expr $rate + 64000 ] }

#--- #Start logging the received bandwidth

$ns_ at [expr $end + 1.0] "finish" ;# thoi diem dung $ns_ at 0.0 "init"

#---reset lai nhung bo dem goi delay--- proc reset {} {

global numnode pktsdelay

for {set i 0 } {$i < $numnode } {incr i } { set pktsdelay($i) 0

} }

# Define node movement model puts "Loading scenario file..." source $opt(sc)

#---dung bien dich--- for {set p 0} {$p < $opt(nn) } {incr p} {

$ns_ at $opt(stop).0000010 "$node_($p) reset"; }

$ns_ at $opt(stop).0000010 "$BS(0) reset";

$ns_ at $opt(stop).1 "puts \"NS EXITING...\" ; $ns_ halt" puts "Starting Simulation..."

vào đường dẫn C:\cygwin\usr\local\ns-allinone-2.29\ns-2.29\tcl\mobility\scene

 Cĩ thể tham khảo thêm một số file ở trong thư mục này hay đọc hướng dẫn ở file ns-doc.pdf ở trang http://www.isi.edu/nsnam/ns/

 Để xem rõ cấu hình của từng thành phần, tham khảo thêm file : ns-lib.tcl và ns-default.tcl ở thư mục cài ns.

Một phần của tài liệu tìm hiểu voip trên nền 802.11 (Trang 89 - 100)