📄 dsdvtest.tcl
字号:
# A 3-node example for ad-hoc with DSDV
#define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-pripagation 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 ;# maxpacket in ifq
set val(nn) 3 ;# number of mobile nodes
set val(rp) DSDV ;# routing protocol
set val(x) 600 ;# X dimension of topography
set val(y) 600 ;# Y dimension of topography
set val(stop) 130 ;# time of simulation end
set ns [new Simulator]
set tracefd [open trace01.tr w]
set windowVsTime2 [open win01.tr w]
set namtrace [open simwrls01.nam 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)
create-god $val(nn)
#
# Createnn 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) } { incr i } {
set node_($i) [$ns node]
}
# Provide initial location of mobilenodes
$node_(0) set X_ 300.0
$node_(0) set Y_ 300.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 100.0
$node_(1) set Y_ 460.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 500.0
$node_(2) set Y_ 130.0
$node_(2) set Z_ 0.0
# Generation of movements
$ns at 15.0 "$node_(1) setdest 500.0 340.0 5.2"
$ns at 35.0 "$node_(1) setdest 500.0 480.0 5.2"
$ns at 55.0 "$node_(1) setdest 500.0 440.0 5.2"
$ns at 75.0 "$node_(1) setdest 500.0 310.0 5.2"
$ns at 95.0 "$node_(1) setdest 500.0 460.0 5.2"
$ns at 15.0 "$node_(2) setdest 100.0 200.0 5.0"
$ns at 30.0 "$node_(2) setdest 100.0 40.0 5.0"
$ns at 50.0 "$node_(2) setdest 100.0 140.0 5.0"
$ns at 70.0 "$node_(2) setdest 100.0 240.0 5.0"
$ns at 90.0 "$node_(2) setdest 100.0 140.0 5.0"
# Set a TCP connection between node_(1) & node_(2)
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_(2) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
# Printing the window size
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file"
}
$ns at 10.1 "plotWindow $tcp $windowVsTime2"
# Define node initial position in nam
for {set i 0} {$i < $val(nn) } { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}
# 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 130.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 + -