📄 chooseroute1.tcl
字号:
#==========================================
#Define options
#==========================================
set val(chan) Channel/WirelessChannel; #channel type
set val(prop) Propagation/TwoRayGround; #radio-propagation model
set val(ant) Antenna/OmniAntenna; #Antenna type
set val(ll) LL; #Link layer type
set val(ifq) Queue/DropTail/PriQueue; #Interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(netif) Phy/WirelessPhy; #network interface type
set val(mac) Mac/802_11; #MAC type
set val(nn) 5; #number of mobilenodes
set val(rp) DSDV; #ad-hoc routing protocol
#initialize the sharedmedia interface with parameters
#Phy/WirelessPhy set RXThresh_ 1.47635e-07
#Phy/WirelessPhy set freq_ 2400e+6
Phy/WirelessPhy set CSThresh_ 3.652e-10
Mac/802_11 set RTSThreshold_ 0
set ns_ [new Simulator]
#设置颜色
$ns_ color 1 Blue
$ns_ color 2 Red
set tracefd [open chooseroute1.tr w]
$ns_ trace-all $tracefd
set namnf [open chooseroute1.nam w]
$ns_ namtrace-all-wireless $namnf 1000 1000
set topo [new Topography]
$topo load_flatgrid 500 500
create-god $val(nn)
#Configure 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) \
-topoInstance $topo \
-channelType $val(chan) \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0; #disable random motion
}
#provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)
$node_(0) set X_ 0.0
$node_(0) set Y_ 0.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 250.0
$node_(1) set Y_ 0.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 500.0
$node_(2) set Y_ 0.0
$node_(2) set Z_ 0.0
$node_(3) set X_ 300.0
$node_(3) set Y_ 300.0
$node_(3) set Z_ 0.0
$node_(4) set X_ 500.0
$node_(4) set Y_ 250.0
$node_(4) set Z_ 0.0
#for {set i 0} {$i < $val(nn) } {incr i} {
# set cmd "[$node_($i) set ragent_] routing $val(nn)"
# for {set to 0} {$to < $val(nn) } {incr to} {
# if {$to < $i} {
# set hop [expr $i - 1]
# } elseif {$to > $i} {
# set hop [expr $i + 1]
# } else {
# set hop $i
# }
# set cmd "$cmd $to $hop"
# }
# eval $cmd
#}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 30
}
#Agent/TCP/Newreno set packetSize_ 5
#Agent/TCP/Newreno set window_ 1
set tcp1 [new Agent/TCP/Newreno]
set tcp2 [new Agent/TCP/Newreno]
$tcp1 set class_ 2
$tcp2 set class_ 2
set sink1 [new Agent/TCPSink]
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp1
$ns_ attach-agent $node_(3) $tcp2
$ns_ attach-agent $node_(2) $sink1
$ns_ attach-agent $node_(2) $sink2
$ns_ connect $tcp1 $sink1
$ns_ connect $tcp2 $sink2
set ftp1 [new Application/FTP]
set ftp2 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp2 attach-agent $tcp2
$ns_ at 5 "$ftp1 start"
$ns_ at 1 "$ftp2 start"
proc record {} {
global ns tcp1
set now [$ns now]
puts "$now [$tcp1 set cwnd_]
$ns at [expr $now+0.01] "record"
}
#tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 500.0 "$node_($i) reset";
}
$ns_ at 500.0001 "stop"
$ns_ at 500.0002 "puts \"NS EXITING... \"; $ns_ halt"
proc stop {} {
global ns_ tracefd
global ns_ namnf
global ns_ tcp1 500
global ns_ tcp2 500
puts "[expr [$tcp1 set ack_] * [$tcp1 set packetSize_]*8/500] bps"
puts "[expr [$tcp2 set ack_] * [$tcp2 set packetSize_]*8/500] bps"
$ns_ flush-trace
close $tracefd
close $namnf
}
puts "Starting Simulation..."
$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -