一个简单的区分服务范例

本例子是根据ns-allinone-2.xx/ns-2.xx/tcl/ex/diffserv下的ds-cbr-tb.tcl文件修改而来的。

原来的目的节点只有一个,我把它改成了两个。

代码如下:

#-------------------------------------------------------------------------------- # cbr-tb.tcl # Author: Jeremy Ethridge. # Dates: June 29-July 5, 1999. # Notes: A DS-RED script that uses CBR traffic agents and the Token Bucket policer. # # ---- # |s1|----------- # ---- 10 Mb / # 5 ms / # /---- ------ ---- ------ # |e1|-----------|core|----------|e2|-----------|dest| # /---- 10 Mb ------ 5 Mb ---- 10 Mb ------ # / 5 ms 5 ms 5 ms # ---- / # |s2|----------- # ---- 10 Mb # 5 ms # #-------------------------------------------------------------------------------- #souroot change the topo #data:Aug 8,2010 # ---- ---- # |s1|----------- -----------|d1| # ---- 10 Mb / / 10Mb ---- # 5 ms / / 5ms # /---- ------ ---- / # |e1|-----------|core|----------|e2| # /---- 10 Mb ------ 3 Mb ---- / # / 5 ms 5 ms / # ---- / / ---- # |s2|----------- ----------- |d2| # ---- 10 Mb 10Mb ---- # 5 ms 5ms set ns [new Simulator] set cir0 1000000 #单位bit,即1M/S set cbs0 3000 set rate0 500000 #单位bit,即s1的发送速率为500kb/S set cir1 1000000 set cbs1 10000 set rate1 3000000 #单位bit,即s1的发送速率为3M/S set testTime 10.0 set packetSize 1000 set file2 [open out.nam w] ;#Nam跟踪文件 $ns namtrace-all $file2 $ns color 1 Blue $ns color 2 Red $ns color 3 Green $ns color 4 Brown $ns color 5 Yellow $ns color 6 Black # Set up the network topology shown at the top of this file: set s1 [$ns node] set s2 [$ns node] set e1 [$ns node] set core [$ns node] set e2 [$ns node] set d1 [$ns node] set d2 [$ns node] $ns duplex-link $s1 $e1 10Mb 5ms DropTail $ns duplex-link $s2 $e1 10Mb 5ms DropTail $ns simplex-link $e1 $core 10Mb 5ms dsRED/edge $ns simplex-link $core $e1 10Mb 5ms dsRED/core $ns simplex-link $core $e2 3Mb 5ms dsRED/core #core 到 e2为瓶颈链路,两条数据流的流量加起来是3.5M/s 大于瓶颈链路的带宽,必然导致丢包。 #我们可以从nam仿真动画看到,丢弃的全部是第二条数据流的分组,从而起到了区分服务的作用 $ns queue-limit $core $e2 50 $ns simplex-link $e2 $core 5Mb 5ms dsRED/edge $ns duplex-link $e2 $d1 10Mb 5ms DropTail $ns duplex-link $e2 $d2 10Mb 5ms DropTail $ns duplex-link-op $s1 $e1 orient down-right $ns duplex-link-op $s2 $e1 orient up-right $ns duplex-link-op $e1 $core orient right $ns duplex-link-op $core $e2 orient right $ns duplex-link-op $e2 $d1 orient up-right $ns duplex-link-op $e2 $d2 orient down-right set qE1C [[$ns link $e1 $core] queue] set qE2C [[$ns link $e2 $core] queue] set qCE1 [[$ns link $core $e1] queue] set qCE2 [[$ns link $core $e2] queue] # Set DS RED parameters from Edge1 to Core: $qE1C meanPktSize $packetSize $qE1C set numQueues_ 1 $qE1C setNumPrec 2 $qE1C addPolicyEntry [$s1 id] [$d1 id] TokenBucket 10 $cir0 $cbs0 $qE1C addPolicyEntry [$s2 id] [$d2 id] TokenBucket 10 $cir1 $cbs1 $qE1C addPolicerEntry TokenBucket 10 11 $qE1C addPHBEntry 10 0 0 $qE1C addPHBEntry 11 0 1 $qE1C configQ 0 0 20 40 0.02 $qE1C configQ 0 1 10 20 0.10 # Set DS RED parameters from Edge2 to Core: $qE2C meanPktSize $packetSize $qE2C set numQueues_ 1 $qE2C setNumPrec 2 $qE2C addPolicyEntry [$d1 id] [$s1 id] TokenBucket 10 $cir0 $cbs0 $qE2C addPolicyEntry [$d2 id] [$s2 id] TokenBucket 10 $cir1 $cbs1 $qE2C addPolicerEntry TokenBucket 10 11 $qE2C addPHBEntry 10 0 0 $qE2C addPHBEntry 11 0 1 $qE2C configQ 0 0 20 40 0.02 $qE2C configQ 0 1 10 20 0.10 # Set DS RED parameters from Core to Edge1: $qCE1 meanPktSize $packetSize $qCE1 set numQueues_ 1 $qCE1 setNumPrec 2 $qCE1 addPHBEntry 10 0 0 $qCE1 addPHBEntry 11 0 1 $qCE1 configQ 0 0 20 40 0.02 $qCE1 configQ 0 1 10 20 0.10 # Set DS RED parameters from Core to Edge2: $qCE2 meanPktSize $packetSize $qCE2 set numQueues_ 1 $qCE2 setNumPrec 2 $qCE2 addPHBEntry 10 0 0 $qCE2 addPHBEntry 11 0 1 $qCE2 configQ 0 0 20 40 0.02 $qCE2 configQ 0 1 10 20 0.10 # Set up one CBR connection between each source and the destination: set udp0 [new Agent/UDP] $udp0 set fid_ 1 $ns attach-agent $s1 $udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 $cbr0 set packet_size_ $packetSize $udp0 set packetSize_ $packetSize $cbr0 set rate_ $rate0 set null0 [new Agent/Null] $ns attach-agent $d1 $null0 $ns connect $udp0 $null0 set udp1 [new Agent/UDP] $udp1 set fid_ 2 $ns attach-agent $s2 $udp1 set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent $udp1 $cbr1 set packet_size_ $packetSize $udp1 set packetSize_ $packetSize $cbr1 set rate_ $rate1 set null1 [new Agent/Null] $ns attach-agent $d2 $null1 $ns connect $udp1 $null1 proc finish {} { global ns file2 close $file2 exit 0 } $qE1C printPolicyTable $qE1C printPolicerTable $ns at 0.0 "$cbr0 start" $ns at 0.0 "$cbr1 start" # $ns at 20.0 "$qCE2 printStats" # $ns at 40.0 "$qCE2 printStats" # $ns at 60.0 "$qCE2 printStats" # $ns at 80.0 "$qCE2 printStats" $ns at $testTime "$cbr0 stop" $ns at $testTime "$cbr1 stop" $ns at [expr $testTime + 1.0] "finish" $ns run

你可能感兴趣的:(一个简单的区分服务范例)