NS2-KD1
1 can phòng di?n tích 500x500m
-s? d?ng giao th?c AODV
- nút 1 gửi tin TCp 1024 kbyte tại t=0.05-> nút 3
- nút 2: tạii 0.01s -> nút 3
Th?i di?m 25s nút 2 di chuy?n sang t?a d? (200,400)
Th?i di?m 30s ra file out.nam, out.tr
N1: (50,300,0)
N2: (200,300,0)
N3: (350,300,0)
N4: (200,500,0)
# khongday.td
#define options- DN nút
Setval(chan) chanel/wireless chanel
Setval(prop) propagation/twoRayround
Setval(nenit) phy/wirelessPhy
Setval(mac) MAC/802.11
Setval(ifg ) queue / proptail/ priqueue
Setval(ll) LL
Setval(ant) Antena/ OmiAntena
Setval(rp) AODV
## t?o topo
set ns[new simulator]
set pkt size 1024
set val(x) 500
set val(y) 500
set t 30 // time mô ph?ng
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
# thiết lập topo dạng phẳng
set topo [new Topography ]
$topo load_fladgrid $val(x) $val(y)
Creat_god3
#c?u hình node - thi?t l?p thông s?
$ns node_config_adhoc Routing $val(rp)\
$ns node_config_llType $val(ll)\
$ns node_config_macType $val(mac)\
$ns node_config_ifgType $val(ifg)\
$ns node_config_antType $val(ant)\
$ns node_config_proType $val(prop)\
$ns node_config_PhyType $val(netif)\
$ns node_config_llType $val(mac)\
$ns node_config_chanelType $val(chn)\
$ns node_config_TopoInstance $topo\
$ns node_config_Agent Trace ON\
$ns node_config_Router Trace ON\
$ns node_config_Mac Trace ON\
$ns node_config_Moverment Trace ON\
#thi?t l?p v? trí
$n1 set X-50.0
$n1 set Y-300.0
$n1 set Z-0.0
Tuong t? v?i các node khác (n2,n3)
# t?o file bám v?t trace file và nam file
Set nf[open out.tr w] // w: write
$ns trace_all $nf
Set nd[open out.nam w]
$ns namtrace_all_wireless $nd $val(x) $val(y)
#Ð?nh nghia kích thu?c các node, kh?i t?o v? trí trong nam
For {set i 1} { $i<4} {incr i} {
$ns intinial_node_pos $n($i)30
}
#C?u hình TCP-> TCP connect
For {set i 1} {$i 3 } {incr i} {
Set tcp [new agent/TCP/new reno]
Set sink ($i) [New agent/ TCP sink]
$ns attach_agent $n($i) $tcp ($i)
$ns attach_agent $n(3) $tcp ($i)
}
#RUN- ch?y t? node 2 sang node 3
$ns at 0.0 "$tcp(1) start"
$ns at 0.01 "$tcp(2) start"
$ns at 25.0 "$n(2) set dest 200.0 400.0 0.0"
For {set i 0} {$i<3} { incr i} {
$ns at 30 "$tcp ($i) stop"
}
# th? t?c finish
Proc finish {}
{global ns nf nd $ns flink_trace
Close $nf
Close $nd
Exec nam out.nam
Exit 0}
Ns at 30.1 "finish"
$ns run
Bạn đang đọc truyện trên: Truyen247.Pro