;#Channel Type
;# network interface type
;# MAC type
Channel/WirelessChannel
Propagation/TwoRayGround ;# radio-propagation model
Phy/WirelessPhy
Mac/802_11
Queue/DropTail/PriQueue ;# interface queue type
LL
Antenna/OmniAntenna
50
20
"tcp-20n.txt"
"scen-20n"
;# link layer type
;# antenna model
;# max packet in ifq
;# number of mobilenodes
;#流量生成器生成的流量文件
;#随机场景生成器生成的随机场景
set val(chan)
set val(prop)
set val(netif)
set val(mac)
set val(ifq)
set val(ll)
set val(ant)
set val(ifqlen)
set val(nn)
set val(cp)
set val(sp)
set val(adhocRouting)
set val(x)
set val(y)
set val(stop)
# Initialize Global Variables
set ns_
AODV
550
550
30.0
[new Simulator]
[open example.tr w]
set tracefd
$ns_ trace-all $tracefd
set namtrace [open example.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo
[new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create God
set god_ [create-god $val(nn)]
# Create channel
set chan_ [new $val(chan)]
# configure node, please note the change below.
$ns_ node-config -adhocRouting $val(adhocRouting) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns_ node $i]
$node_($i) random-motion 0
$god_ new_node $node_($i)
$ns_ initial_node_pos $node_($i) 20
}
source $val(cp)
source $val(sp)
;#关闭节点随机移动
# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 28.0 "$node_($i) reset";
}
$ns_ at 29.0 "stop"
$ns_ at 29.51 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
exec nam example.nam &
exit 0
}
puts "Starting Simulation..."
$ns_ run