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

📄 test-suite-xcp.tcl

📁 ns-2的文件包。多多下载
💻 TCL
📖 第 1 页 / 共 2 页
字号:
## Copyright (c) 1998 University of Southern California.# All rights reserved.						  #								 # Redistribution and use in source and binary forms are permitted# provided that the above copyright notice and this paragraph are# duplicated in all such forms and that any documentation, advertising# materials, and other materials related to such distribution and use# acknowledge that the software was developed by the University of# Southern California, Information Sciences Institute.	The name of the# University may not be used to endorse or promote products derived from# this software without specific prior written permission.# # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.# # To run all tests: test-all-xcp# to run individual test:# ns test-suite-xcp.tcl simple-xcp# To view a list of available test to run with this script:# ns test-suite-xcp.tcl# This test-suite validate xcp congestion control scenarios along with xcp-tcp mixed flows through routers.# UPDATING GLOBAL DEFAULTS:Agent/TCP set minrto_ 1# default changed on 10/14/2004.Queue/RED set bytes_ false ;Queue/RED set queue_in_bytes_ false ;Queue/RED set maxthresh_ [expr 0.8 * [Queue set limit_]]Queue/RED set thresh_ [expr 0.6 * [Queue set limit_]]Queue/RED set q_weight_ 0.001Queue/RED set linterm_ 10if {![TclObject is-class Agent/TCP/Reno/XCP]} {	puts "xcp module is not present; validation skipped"	exit 2}Class TestSuiteproc usage {} {	global argv0	puts stderr "usage: ns $argv0 <tests> "	puts "Valid Tests: simple-xcp xcp-tcp parking-lot-topo"	exit 1}TestSuite instproc init {} {		$self instvar ns_ rtg_ tracefd_ qType_ qSize_ BW_ delay_ \	    tracedFlows_	set ns_ [new Simulator]	$ns_ use-scheduler Heap	set rtg_ [new RNG]	$rtg_ seed 472904}TestSuite instproc create-Bottleneck {} {	global R0 R1 Bottleneck rBottleneck l rl all_links	$self instvar ns_ qType_ qSize_ BW_ delay_		# create bottleneck nodes	set R0 [$ns_ node]	set R1 [$ns_ node]		$ns_ duplex-link $R0 $R1 [set BW_]Mb [set delay_]ms $qType_	$ns_ queue-limit $R0 $R1 $qSize_	$ns_ queue-limit $R1 $R0 $qSize_	# Give a global handle to the Bottleneck Queue to allow 	# setting the RED paramters	set	 Bottleneck  [[$ns_ link $R0 $R1] queue] 	set	 rBottleneck [[$ns_ link $R1 $R0] queue]	set	 l  [$ns_ link $R0 $R1]	 	set	 rl [$ns_ link $R1 $R0]	set all_links "$l $rl "}TestSuite instproc create-sidelinks {numSideLinks deltaDelay} {	global R0 R1 all_links n	$self instvar ns_ BW_ delay_ qSize_ qType_		set i 0	while { $i < $numSideLinks } {		set n($i)  [$ns_ node]		$ns_ duplex-link $n($i) $R0 [set BW_]Mb [expr $delay_ + $i * $deltaDelay]ms $qType_		$ns_ queue-limit $n($i)	 $R0  $qSize_		$ns_ queue-limit $R0 $n($i)   $qSize_		set  q$i   [[$ns_ link $n($i)  $R0] queue] 		set  rq$i  [[$ns_ link $R0 $n($i)] queue]		set  l$i    [$ns_ link $n($i)  $R0] 		set  rl$i   [$ns_ link $R0 $n($i)]		set all_links "$all_links [set l$i] [set rl$i] "		incr i	}}TestSuite instproc create-string-topology {numHops BW_list d_list qtype_list qsize_list } {	$self instvar ns_	global quiet n all_links	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 delays are in msec and BWs are in Mbits    set i 0; set forwarddelay 0; global minBW; set minBW [lindex $BW_list 0];    while { $i < $numHops } {	set forwarddelay [expr $forwarddelay + [lindex $d_list $i]]	if {$minBW > [lindex $BW_list $i] } { set $minBW [lindex $BW_list $i] }	incr i    }	# pipe in bytes,assuming pktsize as 1000bytes,BW in Mbps,delay in ms	set pipe [expr round([expr ($minBW * 2.0 * $forwarddelay)/8.0 ])]		set i 0	while { $i < $numNodes } {		set n($i) [$ns_ node]		incr i	}	set all_links ""	set  i 0 	while { $i < $numHops } {		set qsize [lindex $qsize_list $i]		set bw    [lindex $BW_list $i]		set delay [lindex $d_list $i]		set qtype [lindex $qtype_list $i]		if {$quiet == 0} {			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		set  l$i   [$ns_ link [set n($i)] [set n([expr $i + 1])]]		set  rl$i  [$ns_ link [set n([expr $i + 1])] [set n($i)]]		set all_links "$all_links [set l$i] [set rl$i] "		global q$i rq$i		set q$i  [[$ns_ link [set n($i)] [set n([expr $i + 1])]] queue]		set rq$i [[$ns_ link [set n([expr $i + 1])] [set n($i)]] queue]		incr i	}}TestSuite instproc process-parking-lot-data {what name flows PlotTime} {	global quiet	set tracedFlows $flows	exec rm -f temp.rands	set f [open temp.rands w]		foreach i $tracedFlows {		exec rm -f temp.c temp.out		exec touch temp.c temp.out		set result [exec awk -v PlotTime=$PlotTime -v what=$what {			{				if (($1 == what) && ($2 > PlotTime)) {					print $2, $3 >> "temp.c";				}			}		} ft_red_q$i.tr ]					exec awk -v L=$i \		    {BEGIN {sum=0.0; f=0;} {sum=sum+$2;f=f+1} \			 END {printf("%d %.2g\n", L+1, sum/f);} } \		    "temp.c" >> "temp.out"			exec cat temp.out >@ $f		flush $f	}	close $f	if {$quiet == 0} {		exec xgraph -m -x "link ID" -y $name temp.rands &	}}TestSuite instproc post-process {what PlotTime} {	global quiet	$self instvar tracedFlows_ src_	exec rm -f temp.rands	set f [open temp.rands w]		foreach i $tracedFlows_ {		exec rm -f temp.c 		exec touch temp.c		set result [exec awk -v PlotTime=$PlotTime -v what=$what {			{				if (($6 == what) && ($1 > PlotTime)) {					print $1, $7 >> "temp.c";				}			}		} xcp$i.tr ]				puts $f \"$what$i		exec cat temp.c >@ $f		puts $f "\n"		flush $f	}	close $f	if {$quiet == 0} {		exec xgraph -nl -m -x time -y $what temp.rands &	}}TestSuite instproc finish {} {	$self instvar ns_ tracefd_ tracedFlows_ src_ qtraces_	if [info exists tracedFlows_] {		foreach i $tracedFlows_ {			set file [[set src_($i)] set tcpTrace_]			if {[info exists file]} {				flush $file				close $file			}			}	}	if {[info exists tracefd_]} {		flush $tracefd_		close $tracefd_	}	if {[info exists qtraces_]} {		foreach file $qtraces_ {			if {[info exists file]} {				flush $file				close $file			}		}	}	$ns_ halt}Class GeneralSender  -superclass Agent #   otherparams are "startTime TCPclass .."GeneralSender instproc init { ns id srcnode dstnode otherparams } {	global quiet	$self next	$self instvar tcp_ id_ ftp_ snode_ dnode_ tcp_rcvr_ tcp_type_	set id_ $id		if { [llength $otherparams] > 1 } {		set TCP [lindex $otherparams 1]	} else { 		set TCP "TCP/Reno"	}		if [string match {TCP/Reno/XCP*} $TCP] {		set TCPSINK "XCPSink"	} else {		set TCPSINK "TCPSink"	}		if { [llength $otherparams] > 2 } {		set traffic_type [lindex $otherparams 2]	} else {		set traffic_type FTP	}		set	  tcp_type_ $TCP	set	  tcp_ [new Agent/$TCP]	set	  tcp_rcvr_ [new Agent/$TCPSINK]	$tcp_ set  packetSize_ 1000	  	$tcp_ set  class_  $id	switch -exact $traffic_type {		FTP {			set traf_ [new Application/FTP]			$traf_ attach-agent $tcp_		}		EXP {						set traf_ [new Application/Traffic/Exponential]			$traf_ set packetSize_ 1000			$traf_ set burst_time_ 250ms			$traf_ set idle_time_ 250ms			$traf_ set rate_ 10Mb			$traf_ attach-agent $tcp_		}		default {			puts "unsupported traffic\n"			exit 1		}	}	$ns	  attach-agent $srcnode $tcp_	$ns	  attach-agent $dstnode $tcp_rcvr_	$ns	  connect $tcp_	 $tcp_rcvr_	set	  startTime [lindex $otherparams 0]	$ns	  at $startTime "$traf_ start"	if {$quiet == 0} {		puts  "initialized Sender $id_ at $startTime"

⌨️ 快捷键说明

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