📄 ad_hoc.tcl
字号:
#====================================================================
# Define options
# ======================================================================
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) 2400;#500 ;# X dimension of the topography
set opt(y) 800;#500 ;# Y dimension of the topography
set opt(ifqlen) 50 ;# max packet in ifq
set opt(seed) 0.0
set opt(nam) "nam.tr"
set opt(tr) temp3.tr ;# trace file
set opt(adhocRouting) AODV
set opt(nn) 100;#50 ;# how many nodes are simulated
set opt(cp) "scenarios/cbr-100-test";#"scenarios/cbr-50-5-4"
set opt(sc) "scenarios/setdest-100-test";#"scenarios/temp1"
set opt(stop) 100.0 ;# simulation time
#======================================================================
# Main Program
# ======================================================================
# Initialize Global Variables
# create simulator instance
set ns_ [new Simulator]
# set wireless channel, radio-model and topography objects
set wtopo [new Topography]
# create trace object for ns and nam
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd
set namtracefd [open $opt(nam) w]
$ns_ namtrace-all-wireless $namtracefd $opt(x) $opt(y)
# use new trace file format
#$ns_ use-newtrace
# define topology
$wtopo load_flatgrid $opt(x) $opt(y)
# Create God
set god_ [create-god $opt(nn)]
# define how node should be created
#global node setting
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan) \
-topoInstance $wtopo \
-agentTrace OFF\
-routerTrace ON \
-macTrace OFF
# Create the specified number of nodes [$opt(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $opt(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 $opt(cp)
# Define traffic model
puts "Loading scenario file..."
source $opt(sc)
# Define node initial position in nam
for {set i 0} {$i < $opt(nn)} {incr i} {
# 20 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
$ns_ initial_node_pos $node_($i) 20
}
# Tell nodes when the simulation ends
for {set i 0} {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).000000001 "$node_($i) reset";
}
# tell nam the simulation stop time
#$ns_ at $opt(stop) "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop).000000001 "puts \"NS EXITING...\" ; $ns_ halt"
puts "Starting Simulation..."
$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -