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

📄 singlebottleneck.tcl

📁 NS2 simulation TCP westwood
💻 TCL
字号:
#select the forward traffic type: reno, westwood or vegasset conn_type [lindex $argv 0]#select the number of sources sharing the bottleneck on the forward path, the number of sources is equal to $node-3set node [lindex $argv 1]#select the capacity of the bottleneckset bw [lindex $argv 2]#select the time constant of the filter used by westwood (1.0 is a reasonable setting)set tau [lindex $argv 3]#the bottleneck queueu size is equal to $q times the bandwidth delay productset q [lindex $argv 4]#select the number of sources sharing the bottleneck on the backward path,the number of sources is equal to $rev-3set rev [lindex $argv 5]#select the filter used by westwood (set $filt=4 to simulate westwood+, $filt=3 to simulate westwood)set filt [lindex $argv 6]#the maximum, RTT is equal to 250ms times $rttset rtt [lindex $argv 7]#packet loss probability that affects the bottleneck on both forward and backward directionsset loss [lindex $argv 8]#puts "$conn_type $node $bw $th $wt $fmin $fmax $tau $interp $q $rev $filt $rtt $loss $alpha"#Create a simulator objectset ns [new Simulator]#Open the output filesset q0 [open q.tr w]#congestion window values of the forward connectionsset cwndf [open cwnd.tr w]#sequence numbers of the forward connectionsset snf [open sn.tr w]#bandwidth estimates of the forward connectionsset bwef [open bwe.tr w]#rtts measuered by the forward connectionsset rttf [open rtt.tr w]#slow start thtreshold of the forward connectionsset sstf [open sst.tr w]set buffer [expr round((($bw*250000*$q*$rtt)/(1500*8)))]set bw [expr ($bw*1000000)]#if you want to set up a minimum bound on the bottleneck queue length uncomment the following 3 lines#if ($buffer<20) {#	set buffer 20#		 }#uncomment the following 2 lines if you want to ontain the ns trace files at the end of the simulationset nf [open out.nam w]#$ns namtrace-all $nfset f [open out.tr w]#$ns trace-all $f#Create the nodesfor {set i 0} {$i < $node} {incr i} {        set n($i) [$ns node]        set nend($i) [$ns node]}for {set i 0} {$i < $rev} {incr i} {      set nrew($i) [$ns node]      set nendrew($i) [$ns node]}set delaybott [expr (0.005*$rtt)]$ns duplex-link $n(2) $n(1) $bw $delaybott DropTail$ns queue-limit $n(2) $n(1) $buffer$ns queue-limit $n(1) $n(2) $buffer#$ns duplex-link $n(1) $n(0) 1000Mb 1ms DropTail#$ns queue-limit $n(1) $n(0) 10000000#$ns queue-limit $n(0) $n(1) 100000000# error modelset good [new ErrorModel]$good unit pkt$good set rate_ $loss#set rv0 [new RandomVariable/Uniform]#$rv0 set avg_ 0.01#$good ranvar $rv0set bad [new ErrorModel]$bad unit pkt$bad set rate_   $loss#set rv1 [new RandomVariable/Uniform]#$rv1 set avg_ 0.07#$bad ranvar $rv1#rapporto tra i tempi good e bad 10:1set states [list $good $bad]#set periods [list 0.1 0.1]set periods [list 0.01 0.01]#set trans {{0.9875 0.0125} {0.025 0.975}}#set trans {{0.5 0.5} {0.5 0.5}}#set transunit pkt#set sttype time#set nstates 2#set start $good#set em1 [new ErrorModel/MultiState $states $periods $trans $transunit $sttype $nstates $start]#set em2 [new ErrorModel/MultiState $states $periods $trans $transunit $sttype $nstates $start]$ns lossmodel $good $n(2) $n(1)$ns lossmodel $bad $n(1) $n(2)set mymonitor_ [$ns monitor-queue $n(2) $n(1) size_]#RTTs are uniformly spread from 10ms+240ms/($node-3) to 250msset delta [expr ($rtt*0.06)/($node-3)]#Create links between the nodesfor {set i 3} {$i < $node} {incr i} {	set delay [expr ($i-2)*$delta]        $ns duplex-link $n($i) $n(2) 1000Mb $delay DropTail	$ns queue-limit $n($i) $n(2) 1000000        $ns queue-limit $n(2) $n($i) 1000000        switch $conn_type {    "reno" {         set tcp($i) [new Agent/TCP/Newreno]         }    "westwood"  {        set tcp($i) [new Agent/TCP/WestwoodNR]       }       "vegas"  {        set tcp($i) [new Agent/TCP/Vegas]       } }    	$tcp($i) set window_ 10000        $tcp($i) set maxcwnd_ 10000        $tcp($i) set windowInit_ 1	$tcp($i) set packetSize_ 1500	$tcp($i) set filter_type_ $filt	$tcp($i) set tau_ $tau	$tcp($i) set fr_alpha_ 0.9	#$tcp($i) set fr_a_ $th	$tcp($i) set fr_amin_ 10000	$tcp($i) set fr_amax_ 10000	$tcp($i) set west_type_ 3	$tcp($i) set useHeaders_ 0	$tcp($i) set interp_type_ 0	#$tcp($i) set timestamps_ 1	$tcp($i) set windowInitOption_ 2	$tcp($i) set newreno_changes_ 0	$tcp($i) set newreno_changes1_ 0	$tcp($i) set tcpTick_ 0.01	$ns attach-agent $n($i) $tcp($i)	set ftp($i) [new Application/FTP] }for {set i 3} {$i < $node} {incr i} {		set delay [expr ($i-2)*$delta]        $ns duplex-link $nend($i) $n(1) 1000Mb $delay DropTail	$ns queue-limit $nend($i) $n(1) 1000000        $ns queue-limit $n(1) $nend($i) 1000000	#set sink($i) [new Agent/TCPSink/DelAck]	set sink($i) [new Agent/TCPSink]	$ns attach-agent $nend($i) $sink($i)	$ns connect $tcp($i) $sink($i)	$ftp($i) attach-agent $tcp($i)	$ns at 0.0 "$ftp($i) start" } for {set i 3} {$i < $rev} {incr i} {	set delay [expr ($i-2)*$delta]        $ns duplex-link $nrew($i) $n(1) 1000Mb $delay DropTail	$ns queue-limit $nrew($i) $n(1) 1000000        $ns queue-limit $n(1) $nrew($i) 1000000        switch $conn_type {    "reno" {         set tcprew($i) [new Agent/TCP/Newreno]         }    "westwood"  {        set tcprew($i) [new Agent/TCP/WestwoodNR]       }       "vegas"  {        set tcprew($i) [new Agent/TCP/Vegas]       } }	#set tcprew($i) [new Agent/TCP/Newreno]	$tcprew($i) set window_ 1000        $tcprew($i) set maxcwnd_ 1000        $tcprew($i) set windowInit_ 1	$tcprew($i) set packetSize_ 1500	$tcprew($i) set filter_type_ $filt	$tcprew($i) set tau_ $tau	$tcprew($i) set fr_alpha_ 0.9	#$tcprew($i) set fr_a_ $th	$tcprew($i) set fr_amin_ 10000	$tcprew($i) set fr_amax_ 10000	$tcprew($i) set west_type_ 3	$tcprew($i) set useHeaders_ 0	$tcprew($i) set interp_type_ 0#	$tcprew($i) set timestamps_ 1	$tcprew($i) set windowInitOption_ 2	$ns attach-agent $nrew($i) $tcprew($i)	set ftprew($i) [new Application/FTP] } for {set i 3} {$i < $rev} {incr i} {	set delay [expr ($i-2)*$delta]        $ns duplex-link $nendrew($i) $n(2) 1000Mb $delay DropTail	$ns queue-limit $nendrew($i) $n(2) 1000000        $ns queue-limit $n(2) $nendrew($i) 1000000	set sinkrew($i) [new Agent/TCPSink/DelAck]	$ns attach-agent $nendrew($i) $sinkrew($i)	$ns connect $tcprew($i) $sinkrew($i)	$ftprew($i) attach-agent $tcprew($i)	$ns at 0.0 "$ftprew($i) start" }#Define a 'finish' procedureproc finish {} {	global node q0 cwndf snf nf ns bwef rttf sstf	#Close the output files	close $q0	close $cwndf	close $snf	close $bwef	close $rttf	close $sstf	$ns flush-trace	close $nf        exit 0}set coda 0#Define a procedure which periodically records the bandwidth received by the#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.proc record {} {        global ns bw coda sink0 sink1 sink2 q0 cwndf snf tcp mymonitor_ node bwef  rttf sstf rttmf conn_type bwevf bw tau q rev filt rtt loss alpha	#Set the time after which the procedure should be called again        set time 0.1        set now [$ns now]	#Calculate the bandwidth (in MBit/s) and write it to the files	set cwnd "$now"	set seq "$now"	#somma represents the total number of retransmitted packets times 0.001	set somma 0	set sommaq 0	#sommag represents the sum of the sequence numbers of all the sources times 0.001	set sommag 0	set sommaqg 0	set bwe "$now"	set data "$now"	set ack "$now"	set rttF "$now"	set sst "$now"	for {set i 3} {$i < $node} {incr i} {	set cwnd "$cwnd [$tcp($i) set cwnd_]"   	set seq "$seq [$tcp($i) set t_seqno_]" 	set num [expr ([$tcp($i) set nrexmitpack_]*0.001)]	set numg [expr ([$tcp($i) set t_seqno_])*0.001]	set somma [expr ($somma + $num)]	set sommag [expr ($sommag + $numg)]	set sommaqg [expr ($sommaqg + $numg*$numg)]	set rttF "$rttF [$tcp($i) set rtt_]"	set sst "$sst [$tcp($i) set ssthresh_]"		switch $conn_type {     		   "westwood"  {    	set bwe "$bwe [$tcp($i) set current_bwe_]"			} 	} }	if ($sommag>0) {	#comupte the fairness index	set indexg [expr ($sommag*$sommag/($sommaqg*($node-3)))]	}	set size  [$mymonitor_ set size_]	set size [expr ($size/1500)]      	puts $q0 "$now $size"	set coda [expr ($coda+$size/1000)]        puts $cwndf "$cwnd"	# puts $cwndf "$now $sommacwnd"    	puts $snf "$seq"    	puts $bwef "$bwe"    	puts $rttf "$rttF"    	puts $sstf "$sst"    	if {$now>=999.9} {    	puts "$conn_type $node $bw $tau $q $rev $filt $rtt $loss $indexg $somma $sommag [expr ($coda)]"    	}	$ns at [expr $now+$time] "record"}#Start logging the received bandwidth$ns at 0.0 "record"$ns at 1000.0 "finish"#Run the simulation$ns run

⌨️ 快捷键说明

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