📄 zwireless1.tcl
字号:
# 采用了参数传递的形式,可以直接通过命令行方便的模仿ad hoc的所有平面路由协议
if {$argc !=1} {
puts "Usage: ./ns zwireless1.tcl Routing_Protocol "
puts "Example:ns zwireless1.tcl AODV "
exit
}
set par1 [lindex $argv 0]
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
if { $par1=="DSR"} {
set val(ifq) CMUPriQueue
}
else {
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
}
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(x) 1000 ;# X dimension of the topography
set val(y) 1000 ;# Y dimension of the topography
set val(ifqlen) 50 ;# max packet in ifq
set val(seed) 1.0
set val(adhocRouting) $par1
set val(nn) 100 ;# how many nodes are simulated
set val(cp) "../ns-2.27/indep-utils/cmu-scen-gen/mycbr2"
set val(sc) "../ns-2.27/indep-utils/cmu-scen-gen/setdest/my2"
set val(stop) 400.0 ;# simulation time
# =====================================================================
# Main Program
# ======================================================================
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# create trace object for ns and nam
set tracefd [open zwireless1_out.tr w]
set namtrace [open zwireless1_out.nam w]
$ns_ use-newtrace
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# setup topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $val(x) $val(y)
#
# Create God
#
set god_ [create-god $val(nn)]
#
#global node setting
set chan [new $val(chan)]
$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) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF
#
# Create the specified number of nodes [$val(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
#
# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)
#
# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
}
$ns_ at $val(stop) "stop"
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
}
puts "Starting Simulation..."
$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -