zoukankan      html  css  js  c++  java
  • 【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
  • 相关阅读:
    bzoj3224
    [洛谷日报第62期]Splay简易教程 (转载)
    bzoj1588
    codeforces467C
    codeforces616B
    codeforces379C
    codeforces545C
    codeforces285C
    codeforces659C
    快读代码level.2
  • 原文地址:https://www.cnblogs.com/olvo/p/5640905.html
Copyright © 2011-2022 走看看