无线场景下观察TCP滑动窗口大小的变化

原链接:http://blog.chinaunix.net/u3/105477/showart_2092083.html

 

   1. 无线网络和有线网络中TCP拥塞控制(滑动窗口)的演示;

   2. 有线环境中TCP慢启动和快速恢复机制的具体演示;
   3. NS2中已实现的各种TCP版本, 将具体进行测试;
      将参考柯志亨老师的资料,具体给出详尽的TCL和注释,以及运行结果,少量的分析!
     (包括:Tahoe、Reno、New Reno、Sack、Vegas等;)
   4. TCP同步化现象的演示; (将参考柯老师的资料)
   5. TCP机制的影响因素;   (将参考柯老师的资料)

# 场景请看 运行结果的拓扑图,TCP建立在节点0和9之间,是无线场景哦!

#======================================
# Define options
#======================================
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) 50
set val(nn)     10
set val(rp)     DSDV
set val(x)      500
set val(y)      400
set val(stop)   150

# Routine way of TCL code
set ns [new Simulator]
set tracefd [open fwd.tr w]
set windowVsTime2 [open fwdg.tr w]
set namtrace [open fwd.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
set god [create-god 10]

set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
# Configure for Wireless Node
$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)/
                -channel $chan_1_/
                -topoInstance $topo/
                -agentTrace ON/
                -routerTrace ON/
                -macTrace ON/
                -movementTrace ON
    
# 创建节点,并且指定物理位置,二维平面上的哦!
for {set i 0} {$i< $val(nn)} {incr i} {
        set node_($i) [$ns node]
}
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(1) set X_  200.0
$node_(1) set Y_  5.0
$node_(2) set X_  272.0
$node_(2) set Y_  349.0
$node_(3) set X_  40.0
$node_(3) set Y_  263
$node_(4) set X_  110.0
$node_(4) set Y_  210.0
$node_(5) set X_  450.0
$node_(5) set Y_  300.0
$node_(6) set X_  185.0
$node_(6) set Y_  400.0
$node_(7) set X_  20.0
$node_(7) set Y_  220.0
$node_(8) set X_  100.0
$node_(8) set Y_  120.0
$node_(9) set X_  300.0
$node_(9) set Y_  270.0
 
# 在节点间建立连接, 并且制定NAM中显示的相对位置
$ns duplex-link $node_(0) $node_(1) 1Mb 10ms DropTail
$ns duplex-link $node_(0) $node_(2) 1Mb 10ms SFQ
$ns duplex-link $node_(1) $node_(2) 1Mb 10ms DropTail
$ns duplex-link $node_(1) $node_(3) 1Mb 10ms SFQ
$ns duplex-link $node_(2) $node_(3) 1Mb 10ms DropTail
$ns duplex-link $node_(3) $node_(4) 1Mb 10ms SFQ
$ns duplex-link $node_(4) $node_(5) 1Mb 10ms DropTail
$ns duplex-link $node_(5) $node_(6) 1Mb 10ms SFQ
$ns duplex-link $node_(6) $node_(7) 1Mb 10ms DropTail
$ns duplex-link $node_(7) $node_(8) 1Mb 10ms SFQ
$ns duplex-link $node_(8) $node_(9) 1Mb 10ms DropTail
$ns duplex-link-op $node_(0) $node_(1) orient right
$ns duplex-link-op $node_(0) $node_(2) orient left-up
$ns duplex-link-op $node_(1) $node_(2) orient left-up
$ns duplex-link-op $node_(1) $node_(3) orient right-up
$ns duplex-link-op $node_(2) $node_(3) orient right-up
$ns duplex-link-op $node_(3) $node_(4) orient right-up
$ns duplex-link-op $node_(4) $node_(5) orient right
$ns duplex-link-op $node_(5) $node_(6) orient right
$ns duplex-link-op $node_(6) $node_(7) orient right-down
$ns duplex-link-op $node_(7) $node_(8) orient left-down
$ns duplex-link-op $node_(8) $node_(9) orient left-down

# 别管, 与NAM中节点显示大小有关
for {set i 0} {$i< $val(nn)} {incr i} {
    $ns initial_node_pos $node_($i) 30
}
#$ns rtproto Static
set tcp0 [new Agent/TCP/Newreno]
$tcp0 set class_ 2
#$tcp set window_ 2000
#Agent/TCPSink/DelAck
set interval_ 100ms
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp0
$ns attach-agent $node_(9) $sink
$ns connect $tcp0 $sink
$tcp0 set fid_ 1
set ftp [new Application/FTP]
$ftp attach-agent $tcp0
#采样函数,汗简单,照写; 有疑问请参考前面的博客文章哦!
proc record {tcp file} {
        global ns
        set time 0.1
        set cwnd [$tcp set cwnd_]
        set now [$ns now]
        puts $file "$now $cwnd"
        $ns at [expr $now+$time] "record $tcp $file"
  }
 
for {set i 0} {$i< $val(nn)} {incr i} {
    $ns at $val(stop) "$node_($i) reset";
}
proc stop {} {
        global ns tracefd namtrace
        $ns flush-trace
        close $tracefd
        close $namtrace
        exec nam fwd.nam &
        exec xgraph fwdg.tr -t "Packet flow" -x "Time" -y "Packets" &
        exit 0
}
#设定仿真中的时间模拟!
$ns at 1.0 "$ftp start"
$ns at 1.1 "record $tcp0 $windowVsTime2"
$ns at $val(stop)  "$ns nam-end-wireless $val(stop)"
$ns at $val(stop)  "stop"
$ns at 150.01 "puts /"end simulation/" ; $ns halt"
$ns run

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值