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

📄 cbrgen-new.tcl

📁 在Linux下做的QuadTree的程序
💻 TCL
字号:
# ======================================================================# Default Script Options# ======================================================================set opt(nn)		0		;# Number of Nodesset opt(seed)		0.0set opt(mc)		0set opt(pktsize)	128set opt(rate)		0set opt(interval)	0.0		;# inverse of rateset opt(type)           ""# ======================================================================proc usage {} {    global argv0    puts "\nusage: $argv0 \[-type cbr|tcp\] \[-nn nodes\] \[-seed seed\] \[-mc connections\] \[-rate rate\]\n"}proc getopt {argc argv} {	global opt	lappend optlist nn seed mc rate type	for {set i 0} {$i < $argc} {incr i} {		set arg [lindex $argv $i]		if {[string range $arg 0 0] != "-"} continue		set name [string range $arg 1 end]		set opt($name) [lindex $argv [expr $i+1]]	}}proc create-cbr-connection { src dst } {	global rng cbr_cnt opt	set stime [$rng uniform 15.0 280.0]	puts "#\n# $src connecting to $dst at time $stime\n#"	puts "set cbr_($cbr_cnt) \[\$ns_ create-connection \		CBR \$node_($src) CBR \$node_($dst) 0\]";	puts "\$cbr_($cbr_cnt) set packetSize_ $opt(pktsize)"	puts "\$cbr_($cbr_cnt) set interval_ $opt(interval)"	puts "\$cbr_($cbr_cnt) set random_ 1"	puts "\$cbr_($cbr_cnt) set maxpkts_ 80"		puts "\$ns_ at $stime \"\$cbr_($cbr_cnt) start\""	incr cbr_cnt}proc create-tcp-connection { src dst } {	global rng cbr_cnt opt	set stime [$rng uniform 10.0 400.0]	puts "#\n# $src connecting to $dst at time $stime\n#"	puts "set tcp_($cbr_cnt) \[\$ns_ create-connection \		TCP \$node_($src) TCPSink \$node_($dst) 0\]";	puts "\$tcp_($cbr_cnt) set window_ 32"	puts "\$tcp_($cbr_cnt) set packetSize_ $opt(pktsize)"	puts "set ftp_($cbr_cnt) \[\$tcp_($cbr_cnt) attach-source FTP\]"	puts "\$ns_ at $stime \"\$ftp_($cbr_cnt) start\""	incr cbr_cnt}# ======================================================================getopt $argc $argvif { $opt(type) == "" } {    usage    exit} elseif { $opt(type) == "cbr" } {    if { $opt(nn) == 0 || $opt(seed) == 0.0 || $opt(mc) == 0 || $opt(rate) == 0 } {	usage	exit    }    set opt(interval) [expr 1 / $opt(rate)]    if { $opt(interval) <= 0.0 } {	puts "\ninvalid sending rate $opt(rate)\n"	exit    }}puts "#\n# nodes: $opt(nn), max conn: $opt(mc), send rate: $opt(interval), seed: $opt(seed)\n#"set rng [new RNG]$rng seed $opt(seed)set u [new RandomVariable/Uniform]$u set min_ 0$u set max_ 100$u use-rng $rng############## - yan 1 <= v <= 100??#############set v [new RandomVariable/Uniform]$v set min_ 0$v set max_ $opt(nn)$v use-rng $rng# list of counts of connections of all nodesset lst {}for {set j 1} {$j <= $opt(nn) } {incr j} {    lappend $lst 0}set cbr_cnt 0set src_cnt 0for {set i 0} {$i < $opt(nn) } {incr i} {	set x [$u value]        set y [expr int([$v value])]    	if {$x < 30} {continue;}	incr src_cnt		# might not terminate!!	while {($i == $y) || ([lindex $lst $y] > 2) } {	    set y [expr int([$v value])]	} 		set z [expr [lindex $lst $y] + 1]	lreplace $lst $y $y $z	set dst [expr $y + 1]	if { $opt(type) == "cbr" } {		create-cbr-connection [expr $i + 1] $dst	} else {		create-tcp-connection [expr $i + 1] $dst	}	if { $cbr_cnt == $opt(mc) } {		break	}}puts "#\n#Total sources/connections: $src_cnt/$cbr_cnt\n#"

⌨️ 快捷键说明

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