📄 parking_lot_topo.tcl
字号:
# ------- Test XCP Performance over a a sequence of bottlenecks ---------------### Author: Dina Katabi <dk@mit.edu># Last Update : 09/09/2002## Descrp: parking lot topo# Agent/TCP set minrto_ 1 #-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Utility Functions -*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-##--------------- CC Eprimental TOPOLOGY: Control Transfer -------------------------------## - This topology is useful for experimenting with the behavior of a # connection when its bottleneck moves from one node to another# # n0 ------------ n1 .... n[numHops-1]------------n[numHops] # proc create-string-topology {numHops BW_list d_list qtype_list qsize_list } { global ns set numNodes [expr $numHops + 1 ] # first sanity check if { [llength $BW_list] != [llength $d_list] || [llength $qtype_list] != [llength $qsize_list]} { error "Args sizes don't match with $numHops hops" if { [llength $BW_list] != $numHops || $numHops != [llength $qsize_list]} { puts "error in using proc create-string-topology" error "Args sizes don't match with $numHops hops" } } # compute the pipe assuming packet size is 1000 bytes, delays are in msec and BWs are in Mbits set forwarddelay 0; global minBW; set minBW [lindex $BW_list 0]; for { set i 0} { $i < $numHops } { incr i } { set forwarddelay [expr $forwarddelay + [lindex $d_list $i]] if {$minBW > [lindex $BW_list $i] } { set $minBW [lindex $BW_list $i] } } set pipe [expr round([expr $minBW /8 * $forwarddelay * 2])] for { set i 0} { $i < $numNodes } { incr i } { global n$i set n$i [$ns node] } for { set i 0} { $i < $numHops } { incr i } { set qsize [lindex $qsize_list $i] set bw [lindex $BW_list $i] set delay [lindex $d_list $i] set qtype [lindex $qtype_list $i] puts "$i bandwidth $bw" if {$qsize == 0} { set qsize $pipe} $ns duplex-link [set n$i] [set n[expr $i +1]] [set bw]Mb [set delay]ms $qtype $ns queue-limit [set n$i] [set n[expr $i + 1]] $qsize $ns queue-limit [set n[expr $i + 1]] [set n$i] $qsize # Give a global handle to the Queues to allow setting the RED paramters global q$i; set q$i [ [$ns link [set n$i] [set n[expr $i + 1]]] queue] global rq$i; set rq$i [ [$ns link [set n[expr $i + 1]] [set n$i]] queue] global l$i; set l$i [$ns link [set n$i] [set n[expr $i + 1]]] global rl$i; set rl$i [$ns link [set n[expr $i + 1]] [set n$i]] }}proc set-red-params { qsize } { #Queue/RED set thresh_ [expr 0.6 * $qsize] #Queue/RED set maxthresh_ [expr 0.8 * $qsize] #Queue/RED set q_weight_ 0.001 Queue/RED set linterm_ 10 Queue/RED set bytes_ false ; Queue/RED set queue_in_bytes_ false ; Agent/TCP set old_ecn_ true Queue/RED set setbit_ true}proc flush-files { files } { foreach file $files { global "$file" if {[info exists $file]} { puts "flush $file" flush [set $file] close [set $file] } }}#------- Sender Class :# This is essentially an ftp senderClass GeneralSender -superclass Agent # otherparams are "startTime TCPclass .."GeneralSender instproc init { id node rcvrTCP otherparams } { global ns $self next $self instvar tcp_ id_ ftp_ node_ tcp_rcvr_ tcp_type_ set id_ $id set node_ $node if { [llength $otherparams] > 1 } { set TCP [lindex $otherparams 1] } else { set TCP "TCP/Reno" } set tcp_type_ $TCP set tcp_ [new Agent/$TCP] $tcp_ set packetSize_ 1000 $tcp_ set class_ $id set ftp_ [new Source/FTP] $ftp_ set agent_ $tcp_ $ns attach-agent $node $tcp_ $ns connect $tcp_ $rcvrTCP set tcp_rcvr_ $rcvrTCP set startTime [lindex $otherparams 0] $ns at $startTime "$ftp_ start" puts "initialized Sender $id_ at $startTime"}GeneralSender instproc trace-xcp parameters { $self instvar tcp_ id_ tcpTrace_ global ftracetcp$id_ set ftracetcp$id_ [open xcp$id_.tr w] set tcpTrace_ [set ftracetcp$id_] $tcp_ attach-trace [set ftracetcp$id_] if { -1 < [lsearch $parameters cwnd] } { $tcp_ tracevar cwnd_ } if { -1 < [lsearch $parameters seqno] } { $tcp_ tracevar t_seqno_ }}#--- Command line argumentsproc set-cmd-line-args { list_args } { global argv set i 0 foreach a $list_args { global $a set $a [lindex $argv $i] puts "$a = [set $a]" incr i }}#-------------- Plotting functions -----------## plot a xcp traced varproc plot-xcp { TraceName nXCPs PlotTime what } { exec rm -f xgraph.tcp set f [open xgraph.tcp w] puts $f "TitleText: $TraceName" puts $f "Device: Postscript" foreach i $nXCPs { #the TCP traces are flushed when the sources are stopped exec rm -f temp.tcp exec touch temp.tcp global ftracetcp$i if [info exists ftracetcp$i] { flush [set ftracetcp$i] } set result [exec awk -v PlotTime=$PlotTime -v what=$what { { if (( $6 == what ) && ($1 > PlotTime)) { print $1, $7 >> "temp.tcp"; } } } xcp$i.tr] puts "$i : $result" puts $f \"$what$i exec cat temp.tcp >@ $f puts $f "\n" flush $f } close $f exec xgraph -nl -m -x time -y $what xgraph.tcp & return }# Takes as input the the label on the Y axis, the time it starts plotting, and the trace file tcl varproc plot-red-queue { TraceName PlotTime traceFile } { exec rm -f xgraph.red_queue exec rm -f temp.q temp.a temp.p temp.avg_enqueued temp.avg_dequeued temp.x temp.y exec touch temp.q temp.a temp.p temp.avg_enqueued temp.avg_dequeued temp.x temp.y exec awk -v PT=$PlotTime { { if (($1 == "Q" && NF>2) && ($2 > PT)) { print $2, $3 >> "temp.q" } else if (($1 == "a" && NF>2) && ($2 > PT)){ print $2, $3 >> "temp.a" } else if (($1 == "p" && NF>2) && ($2 > PT)){ print $2, $3 >> "temp.p" } } } $traceFile set ff [open xgraph.red_queue w] puts $ff "TitleText: $TraceName" puts $ff "Device: Postscript \n" puts $ff \"queue exec cat temp.q >@ $ff puts $ff \n\"ave_queue exec cat temp.a >@ $ff puts $ff \n\"prob_drop exec cat temp.p >@ $ff close $ff exec xgraph -P -x time -y queue xgraph.red_queue &}#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Initializing Simulator -*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-## BW is in Mbs and delay is in msset-cmd-line-args " numHops PostProcess seed qType BW nAllHopsTCPs delay"set numNodes [expr $numHops + 1 ]set ns [new Simulator]set rtg [new RNG]$rtg seed $seed#-----Global Variables-----------##set qType Vq#set BW [expr 10.0 * 1]#set delay 50set tracefd [open out.tr w]$ns trace-all $tracefdset qSize [expr round([expr ($BW / 8.0) * 2.0 * $delay * 10 ])]#set qSize [expr round([expr ($BW / 8.0) * $delay * 1000 ])]puts "queue is $qSize" set qEffective_RTT [expr 20 * $delay * 0.001]#set-red-params $qSizeset BW2 [expr $BW / 2.0]puts "BW2 = $BW2"set BW_list {}set qType_list {}set delay_list {}set qSize_list {}set nTCPsPerHop_list {}set StartTime_list {}for {set i 0} {$i < $numHops} {incr i} { lappend BW_list $BW lappend qType_list $qType lappend delay_list $delay lappend qSize_list $qSize lappend nTCPsPerHop_list 30 lappend StartTime_list 0}set tracedQueues ""set tracedXCPs "0 1 2 3 4 5 6 7 8"#set nAllHopsTCPs 30; #num of TCPs crossing all hopsset rTCPs 30; #traverse all of the reverse pathset SimStartTime 0.0set SimStopTime 20set PlotTime 0#---------- Create the simulation --------------------## Create topologycreate-string-topology $numHops $BW_list $delay_list $qType_list $qSize_list; #all except the first are listsset i 0;while { $i < $numHops } { set qtype [lindex $qType_list $i] set bw [lindex $BW_list $i] switch $qtype { "RED" {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -