⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 behavior.tcl

📁 这个代码是tcl程序
💻 TCL
字号:
################################################### General High-Speed TCP Behavior - behavior.tcl ## L. Xu, K. Harfoush, and I. Rhee                ## based on scripts from S. Floyd and E. Souza    ###################################################set begintime  [clock second]# simulation end timeset endtime [lindex $argv 0]# bottleneck parameter: bandwidth, delay, RED/DropTail, BufferSizeset bandwidth [lindex $argv 1]set delay [lindex $argv 2]set queue [lindex $argv 3]set buffer [lindex $argv 4]# high-speed flow type, num, extra delayset hstcpflows_type [lindex $argv 5]set hstcpflows_num  [lindex $argv 6]set hstcpflows_delay  [lindex $argv 7]# regular long-lived tcp flow numset regtcpflows_num [lindex $argv 8]# bk trafficset bgtraffic [lindex $argv 9]# parameters for CUBICset cubic_tcp_mode [lindex $argv 10]if { $hstcpflows_type == 8} {# HSTCP  set low_window 31} elseif { $hstcpflows_type == 9 } {# STCP  set low_window 16} elseif { $hstcpflows_type == 12 } {# BIC  set low_window 14} else {# All other protocols  set low_window 0}set high_window 83000set high_p 0.0000001set high_decrease 0.1set hstcp_fix 1if { $bgtraffic == 0 } {  set rev_regtcpflows 0  set max_nrnodes 0  set smalltcp_cwnd 0  set for_smalltcpflows 0  set rev_smalltcpflows 0  set for_web_sessions 0  set rev_web_sessions 0} elseif { $bgtraffic == 1 } {  set rev_regtcpflows 4  set max_nrnodes 25  set smalltcp_cwnd 8  set for_smalltcpflows 10  set rev_smalltcpflows 5  set for_web_sessions 10  set rev_web_sessions 10} elseif { $bgtraffic == 2 } {  set rev_regtcpflows 4  set max_nrnodes 25  set smalltcp_cwnd 64  set for_smalltcpflows 25  set rev_smalltcpflows 5  set for_web_sessions 100  set rev_web_sessions 10} elseif { $bgtraffic == 3 } {  set rev_regtcpflows 10  set max_nrnodes 250  set smalltcp_cwnd 64  set for_smalltcpflows 250  set rev_smalltcpflows 50  set for_web_sessions 300  set rev_web_sessions 50}remove-all-packet-headers       ; # removes all except commonadd-packet-header Flags IP TCP  ; # hdrs reqd for TCPsource utils.tclsource web.tclset frep [open report.txt w]set urep [open util.out w]puts "---------------------------------------------------------------"puts "---------------------------------------------------------------"puts [pwd]printlegendset ns [new Simulator]ns-random 0set n1 [$ns node]set n2 [$ns node]Agent/TCP set timestamps_ 1Agent/TCP set ecn_ 1             Agent/TCP set window_ 100000Agent/TCP set packetSize_ 1000    Agent/TCP set overhead_ 0.000008Agent/TCP set max_ssthresh_ 100Agent/TCP set maxburst_ 2# BICAgent/TCP set bic_beta_ 0.8Agent/TCP set bic_B_ 4Agent/TCP set bic_max_increment_ 32Agent/TCP set bic_min_increment_ 0.01Agent/TCP set bic_fast_convergence_ 1Agent/TCP set bic_low_utilization_threshold_ 0Agent/TCP set bic_low_utilization_checking_period_ 2 Agent/TCP set bic_delay_min_ 0Agent/TCP set bic_delay_avg_ 0Agent/TCP set bic_delay_max_ 0Agent/TCP set bic_low_utilization_indication_ 0# CUBICAgent/TCP set cubic_beta_ 0.8Agent/TCP set cubic_max_increment_ 16Agent/TCP set cubic_fast_convergence_ 1Agent/TCP set cubic_scale_ 0.4Agent/TCP set cubic_tcp_friendliness_ $cubic_tcp_modeAgent/TCP set cubic_low_utilization_threshold_ 0 Agent/TCP set cubic_low_utilization_checking_period_ 2Agent/TCP set cubic_delay_min_ 0Agent/TCP set cubic_delay_avg_ 0Agent/TCP set cubic_delay_max_ 0Agent/TCP set cubic_low_utilization_indication_ 0set bf_size [expr $bandwidth*$delay*2*1000*$buffer/[Agent/TCP set packetSize_]/8]puts "BufferSize(Packets) $bf_size"puts $frep "BufferSize(Packets) $bf_size"Queue/RED set gentle_ true Queue/RED set adaptive_ 1 Queue/RED set bottom_ 0.001Queue/RED set thresh_ 0Queue/RED set maxthresh_ 0Queue/RED set q_weight_ 0 Queue/RED set drop_tail_ 0Queue/RED set setbit_ 0Queue/RED set targetdelay_ [expr $bf_size*8*0.05*[Agent/TCP set packetSize_]/$bandwidth/1000000]if {$queue == 0} {  $ns duplex-link $n1 $n2 [expr $bandwidth]Mb [expr $delay]ms RED   puts "Set to RED"  puts $frep "Set to RED"  puts "Queue/RED targetdelay_(sec) [Queue/RED set targetdelay_]"  puts $frep "Queue/RED targetdelay_(sec) [Queue/RED set targetdelay_]"} else {  $ns duplex-link $n1 $n2 [expr $bandwidth]Mb [expr $delay]ms DropTail  puts "Set to DropTail"  puts $frep "Set to DropTail"}$ns queue-limit $n1 $n2 $bf_size$ns queue-limit $n2 $n1 $bf_sizeset qmon [$ns monitor-queue $n1 $n2 ""]set qfp [open queue.out w]      print-queue 0.1 $qfpset fmon [$ns makeflowmon Fid]$ns attach-fmon [$ns link $n1 $n2] $fmon# back path fmonset fmon2 [$ns makeflowmon Fid]$ns attach-fmon [$ns link $n2 $n1] $fmon2set rng_ [new RNG]  for {set i 0} {$i < $hstcpflows_num} {incr i} {   set hsnode(s$i) [$ns node]  set hsnode(r$i) [$ns node]  set del [expr [$rng_ uniform 0.1 1.9]+$hstcpflows_delay]    $ns duplex-link $hsnode(s$i) $n1 10000Mb [expr $del]ms DropTail  $ns duplex-link $hsnode(r$i) $n2 10000Mb [expr 1.0]ms DropTail  puts "hstcp$i, forwardlink delay=[format %.2f $del] ms"  puts $frep "hstcp$i, forwardlink delay=$del ms"  puts "hstcp$i, RTT=[format %.2f [expr ($del+1.0+$delay)*2 ]]ms"  puts $frep "hstcp$i, RTT=[expr ($del+1.0+$delay)*2 ]ms"    $ns queue-limit $hsnode(s$i) $n1 100000   $ns queue-limit $n1 $hsnode(s$i) 100000   $ns queue-limit $n2 $hsnode(r$i) 100000  $ns queue-limit $hsnode(r$i) $n2 100000  set hstcp$i [$ns create-connection TCP/SackTS $hsnode(s$i) TCPSink/Sack1 $hsnode(r$i) $i]  [set hstcp$i] set windowOption_ $hstcpflows_type  [set hstcp$i] set low_window_ $low_window  [set hstcp$i] set high_window_ $high_window  [set hstcp$i] set high_p_ $high_p  [set hstcp$i] set high_decrease_ $high_decrease  [set hstcp$i] set hstcp_fix_ $hstcp_fix  set hsftp$i [[set hstcp$i] attach-app FTP]  set sec [expr int([$rng_ uniform 1 [expr $endtime/10]])]  set frac [expr int([$rng_ uniform 0 25])]  set starttime($i) $sec.$frac  set lastBytes($i) 0  $ns at $starttime($i) "[set hsftp$i] start"  $ns at [expr $endtime+5] "[set hsftp$i] stop"  # print this connection start time  puts "hstcp$i starttime: $starttime($i)"  puts $frep "hstcp$i starttime: $starttime($i)"  set cfp_hs($i) [open cwnd_hstcp$i.out w]        if { $hstcpflows_type == 12 } {    print-cwnd-bic [set hstcp$i] 0.1 $cfp_hs($i)  } else {    print-cwnd [set hstcp$i] 0.1 $cfp_hs($i)  }  set lastKBytes($i) 0  print-th-one $i $fmon 1}for {set i 0} {$i < $regtcpflows_num} {incr i} {   set fid [expr 1000 +$i]  set tcpnode(s$i) [$ns node]  set tcpnode(r$i) [$ns node]  set del [$rng_ uniform 0.1 1.9]    puts "regtcp$i, forwardlink delay=[format %.2f $del] ms"  puts $frep "regtcp$i, forwardlink delay=$del ms"  puts "regtcp$i, RTT=[format %.2f [expr ($del+1.0+$delay)*2 ]]ms"  puts $frep "regtcp$i, RTT=[expr ($del+1.0+$delay)*2 ]ms"  $ns duplex-link $tcpnode(s$i) $n1 10000Mb [expr $del]ms DropTail  $ns duplex-link $tcpnode(r$i) $n2 10000Mb [expr 1.0]ms DropTail  $ns queue-limit $tcpnode(s$i) $n1 100000   $ns queue-limit $n1 $tcpnode(s$i) 100000   $ns queue-limit $n2 $tcpnode(r$i) 100000  $ns queue-limit $tcpnode(r$i) $n2 100000  set regtcp$i [$ns create-connection TCP/SackTS $tcpnode(s$i) TCPSink/Sack1 $tcpnode(r$i) $fid]    set regftp$i [[set regtcp$i] attach-app FTP]  set sec [expr int([$rng_ uniform 1 [expr $endtime/10]])]  set frac [expr int([$rng_ uniform 0 25])]  set starttime($fid) $sec.$frac  set lastBytes($fid) 0  $ns at $starttime($fid) "[set regftp$i] start"  $ns at [expr $endtime+5] "[set regftp$i] stop"  puts "regtcp$i, starttime: $starttime($fid)"  puts $frep "regtcp$i, starttime: $starttime($fid)"  set cfp_reg($i) [open cwnd_regtcp$i.out w]        print-cwnd [set regtcp$i] 0.1 $cfp_reg($i)  set lastKBytes($fid) 0  print-th-one $fid $fmon 10}# reg TCP traffic from the back pathfor {set i 0} {$i < $rev_regtcpflows} {incr i} {   set fid [expr 2000 +$i]  set revtcpnode(s$i) [$ns node]  set revtcpnode(r$i) [$ns node]  $ns duplex-link $revtcpnode(s$i) $n1 10000Mb [expr $i]ms DropTail  $ns duplex-link $revtcpnode(r$i) $n2 10000Mb [expr (10*$i+1.0)]ms DropTail  $ns queue-limit $revtcpnode(s$i) $n1 100000   $ns queue-limit $n1 $revtcpnode(s$i) 100000   $ns queue-limit $n2 $revtcpnode(r$i) 100000  $ns queue-limit $revtcpnode(r$i) $n2 100000  set regbacktcp$i [$ns create-connection TCP/SackTS $revtcpnode(r$i) TCPSink/Sack1 $revtcpnode(s$i) $fid]  set regbackftp$i [[set regbacktcp$i] attach-app FTP]  set sec [expr int([$rng_ uniform 0 5])]  set frac [expr int([$rng_ uniform 0 25])]  set starttime($fid) $sec.$frac  set lastBytes($fid) 0  $ns at $starttime($fid) "[set regbackftp$i] start"  $ns at [expr $endtime+5] "[set regbackftp$i] stop"  puts "regbacktcp$i, starttime: $starttime($fid)"  puts $frep "regbacktcp$i, starttime: $starttime($fid)"}set count 1add_web_traffic $delay $for_web_sessions 4 10 10 3000 0set lastBytes(3000) 0set count 1add_web_traffic $delay $rev_web_sessions 4 10 10 4000 1set lastBytes(4000) 0for {set i 0} {$i < $max_nrnodes} {incr i} {   set node_(s$i) [$ns node]  set node_(k$i) [$ns node]  $ns duplex-link $node_(s$i) $n1 10000Mb [expr $i]ms DropTail  $ns duplex-link $node_(k$i) $n2 10000Mb [expr (10*$i+1.0)]ms DropTail}for {set i 0} {$i < $for_smalltcpflows} {incr i} {  set srcnode [expr int([$rng_ uniform 0 [expr $max_nrnodes - 0.01] ])]  set dstnode [expr int([$rng_ uniform 0 [expr $max_nrnodes - 0.01] ])]  set tcp [$ns create-connection TCP/SackTS $node_(s$srcnode) TCPSink/Sack1 $node_(k$dstnode) 5000]    $tcp set window_ [expr $smalltcp_cwnd]  set ftp [$tcp attach-app FTP]  set starttime(5000) [$rng_ uniform 0 [expr $endtime/10]]   set lastBytes(5000) 0  $ns at $starttime(5000) "$ftp start"   $ns at [expr $endtime+5] "$ftp stop" }for {set i 0} {$i < $rev_smalltcpflows} {incr i} {  set srcnode [expr int([$rng_ uniform 0 [expr $max_nrnodes - 0.01] ])]  set dstnode [expr int([$rng_ uniform 0 [expr $max_nrnodes - 0.01] ])]  set tcp [$ns create-connection TCP/SackTS $node_(k$srcnode) TCPSink/Sack1 $node_(s$dstnode) 6000]  $tcp set window_ [expr $smalltcp_cwnd]  set ftp [$tcp attach-app FTP]  set starttime(6000) [$rng_ uniform 0 [expr $endtime/10]]   set lastBytes(6000) 0  $ns at $starttime(6000) "$ftp start"   $ns at [expr $endtime+5] "$ftp stop" }  set halftime [expr $endtime / 2]  for {set i 0} {$i < $hstcpflows_num} {incr i} {    $ns at $halftime "print-stat-one-pre $i $fmon"    $ns at $endtime "print-stat-one $i $fmon"  }  for {set i 1000} {$i < [expr 1000 + $regtcpflows_num]} {incr i} {    $ns at $halftime "print-stat-one-pre $i $fmon"    $ns at $endtime "print-stat-one $i $fmon"  }  for {set i 2000} {$i < [expr 2000 + $rev_regtcpflows]} {incr i} {    $ns at $halftime "print-stat-one-pre $i $fmon2"    $ns at $endtime "print-stat-one $i $fmon2"  }  $ns at $halftime "print-stat-one-pre 3000 $fmon"  $ns at $endtime "print-stat-one 3000 $fmon"  $ns at $halftime "print-stat-one-pre 4000 $fmon2"  $ns at $endtime "print-stat-one 4000 $fmon2"  $ns at $halftime "print-stat-one-pre 5000 $fmon"  $ns at $endtime "print-stat-one 5000 $fmon"  $ns at $halftime "print-stat-one-pre 6000 $fmon2"  $ns at $endtime "print-stat-one 6000 $fmon2"  $ns at $halftime "print-stat-all-pre"  $ns at $endtime "print-stat-all"  $ns at $endtime "printlegend"  $ns at $endtime "finish"  $ns at 0 "timeReport 1"  $ns at 0.1 "print-util 0.1 0" $ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -