代码:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(ant) Antenna/OmniAntenna
set val(ll) LL
set val(ifq) Queue/DropTail/PriQueue
set val(ifqlen) 50
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(rp) DSDV
set val(nn) 15
set val(x) 700
set val(y) 500
set val(stop) 130
set ns [new Simulator]
set tracefd [open trust.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open trust.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god (1)
#create-god (3)
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF\
-energyModel "EnergyModel" \
-initialEnergy 50
# Energy model
$ns node-config -energyModel EnergyModel \
-initialEnergy 50 \
-txPower 0.75
#-rxPower 0.25 \
#idlePower 0.0 \
#sensePower 0.0
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
}
$ns at 0.0 "$ns trace-annotate \"MOBILE NODE MOVEMENTS\""
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(1) $tcp
$ns attach-agent $node_(3) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
#setting initial position:
for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $node_($i) 30
}
#$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 130.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam trust.nam &
}
$ns run
此代码运行但是移动节点每次都是动态的,如何使动态移动节点静态? 如何使它成为静态移动节点,并需要在ns2 tcl代码中进行随机偷听
答案 0 :(得分:0)
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
}
此代码设置节点的移动性。您可以评论此代码并查看。那么节点应该是静态的。
答案 1 :(得分:0)
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
$node_($i) random-motion 0 ;# disable random motion
}