【NS2仿真】TCP協議

#
# ftp
#  \    
#  tcp                        sink  
#    \                         /
#     n0--------5M 2ms---------n1
#
#

set ns [new Simulator]

set f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w]
$ns namtrace-all $nf

proc finish {} {
    global ns nf f
    $ns flush-trace
    close $f
    close $nf
    exec nam out.nam &
    exit 0
}

#設置並鏈接兩個節點
set n0 [$ns node]
set n1 [$ns node]

$ns duplex-link $n0 $n1 5M 2ms DropTail
$ns duplex-link-op $n0 $n1 orient right

#設置傳輸層並鏈接
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink

#設置應用層
set ftp [new Application/FTP]
$ftp attach-agent $tcp

#設置執行與中止順序
$ns at 0.01 "$ftp start"
$ns at 0.09 "finish"

$ns run
相關文章
相關標籤/搜索