📄 ns2aodv.txt
字号:
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 50 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 100 ;# time of simulation end
set ns_ [new Simulator]
# 命名规则:
# 协议名-节点数-暂停时间-序号(-文件类型).(tr/nam…)
set tracefd [open Tracefd-1-AODV-10-0 w]
#set windowVsTime2 [open Win-1-AODV-10-0 w]
#set namtrace [open Nam-1-AODV-10-0 w]
$ns_ trace-all $tracefd
#$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
set god_ [create-god $val(nn)]
#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#
# configure the nodes
$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 ON
for {set i 0} {$i < $val(nn) } { in
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns_ node]
}
#
# nodes: 50, max conn: 10, send rate: 0.125, seed: 1.0
#
#
#Total sources/connections: 7/10
#
#
# nodes: 50, pause: 0.00, max speed: 20.00, max x: 1000.00, max y: 500.00
#
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns_ at $val(stop) "$node_($i) reset";
}
# ending nam and the simulation
#$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop) "stop"
$ns_ at 100.01 "puts \"end simulation\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd #namtrace
$ns_ flush-trace
close $tracefd
#close $namtrace
}
$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -