⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise2.tcl

📁 有需要的自己下载查看 内部有图有程序
💻 TCL
字号:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac)   Mac/802_11
set val(ifq)   Queue/DropTail/PriQueue
set val(ll)    LL
set val(ant)   Antenna/OmniAntenna
set val(ifqlen) 10
set val(nn)     2
set val(rp)     AODV
set val(x)      500
set val(y)       500

set ns [new Simulator]

set tracefd [open exercise2.tr w]
$ns trace-all $tracefd
set namtracefd [open exercise2.nam w]
$ns namtrace-all-wireless $namtracefd $val(x) $val(y)

proc finish {} {
     global ns tracefd namtracefd
     $ns flush-trace
     close $tracefd
     close $namtracefd
     exec nam exercise2.nam &
     exit 0
}
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

$ns node-config -addressType def
$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  OFF

for  {set i 0} {$i<$val(nn)} {incr i} {
     set node_($i) [$ns node]
     $node_($i) random-motion 0
}

$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0

$ns at 10.0 "$node_(0) setdest 30.0 30.0 2.0"
$ns at 50.0 "$node_(1) setdest 32.0 32.0 15.0"
$ns at 100.0 "$node_(1) setdest 450.0 450.0 15.0"

set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

for {set i 0}  {$i<$val(nn)} {incr i} {
    $ns at 150.0 "$node_($i)  reset";
}
$ns at 150.0 "finish"

$ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -