for {set i 0} {$i < $val(nn) } { incr i } {
set n($i) [$ns node]
}
for {set i 1} {$i < $val(nn) } { incr i } {
$n($i) set X_ [ expr {$val(x) * rand()} ]
$n($i) set Y_ [ expr {$val(y) * rand()} ]
$n($i) set Z_ 0
}
#Lable the sink node
$n(0) set X_ [expr {$val(x)/2} ]
$n(0) set Y_ [expr {$val(y)/2} ]
$n(0) set Z_ 0
$ns at 0.0 "$n(0) NodeLabel Sink"
# defines the node size in nam
for {set i 0} {$i < $val(nn)} {incr i} {
$ns initial_node_pos $n($i) 10
}
2012年4月21日 星期六
2012年4月3日 星期二
NS-2 The first part: pre-definition
1.建立一個模擬器物件 (Must)
set ns [new Simulator]
2.開啟一個nam trace 檔案 (Option)
set nf [open out.nam w]
ns namtrace-all $nf
3.宣告一個finish程序(Must)
proc finish{}
{
global ns nf #設nf為全域變數
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam &
exit 0
}
data source: http://www.scribd.com/doc/76224756/Network-Simulator-NS-2
set ns [new Simulator]
2.開啟一個nam trace 檔案 (Option)
set nf [open out.nam w]
ns namtrace-all $nf
3.宣告一個finish程序(Must)
proc finish{}
{
global ns nf #設nf為全域變數
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam &
exit 0
}
data source: http://www.scribd.com/doc/76224756/Network-Simulator-NS-2
訂閱:
文章 (Atom)