E-mail:
TCP/IP协议在现行网络中的重要地位,是不言而喻的啦! 为此我将整理与之相关的一些列博客,希望详尽地对TCP协议进行测试,使得自己对TCP的实现机制有更为深刻的了解!
同时这也将是一个NS2初学者进阶的必经阶段,一定要花费足够的的时间和精力,对TCP/IP的各种机制的仿真做详细的测试哦!
我的博文具体包括以下几个方面:
1. 无线网络和有线网络中TCP拥塞控制(滑动窗口)的演示;
2. 有线环境中TCP慢启动和快速恢复机制的具体演示;
3. NS2中已实现的各种TCP版本, 将具体进行测试;
将参考柯志亨老师的资料,具体给出详尽的TCL和注释,以及运行结果,少量的分析!
(包括:Tahoe、Reno、New Reno、Sack、Vegas等;)
4. TCP同步化现象的演示; (将参考柯老师的资料)
5. TCP机制的影响因素; (将参考柯老师的资料)
进阶实例10:
# 场景请看 运行结果的拓扑图,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 |
运行结果:
拓扑图:
效果图:
E-mail:
阅读(2627) | 评论(1) | 转发(1) |