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

📄 ns-route.tcl

📁 跑leach需要的
💻 TCL
📖 第 1 页 / 共 2 页
字号:
	#}	#puts "Completed populating classifiers at \		time: [clock format [clock seconds] -format %X]"}Simulator instproc get-link-head { n1 n2 } {    $self instvar link_    return [$link_($n1:$n2) head]}## Hierarchical routing support#Simulator instproc hier-topo {rl} {	#	# if topo info not found, use default values	#	AddrParams instvar domain_num_ cluster_num_ nodes_num_     	if ![info exists cluster_num_] {		if {[AddrParams hlevel] > 1} {			### set default value of clusters/domain 			set def [AddrParams set def_clusters]			puts "Default value for cluster_num set to $def\n"			for {set i 0} {$i < $domain_num_} {incr i} {				lappend clusters $def			}		} else {			### how did we reach here instead of flat routing?			puts stderr "hierarchy level = 1; should use flat-rtg instead of hier-rtg" 			exit 1		}		AddrParams set cluster_num_ $clusters	}	### set default value of nodes/cluster	if ![info exists nodes_num_ ] {		set total_node 0		set def [AddrParams set def_nodes]		puts "Default value for nodes_num set to $def\n"		for {set i 0} {$i < $domain_num_} {incr i} {			set total_node [expr $total_node + \					[lindex $clusters $i]]		}		for {set i 0} {$i < $total_node} {incr i} {			lappend nodes $def		}		AddrParams set nodes_num_ $nodes	}	# Eval is necessary because these *_num_ are usually lists; eval 	# will break them into individual arguments	eval $rl send-num-of-domains $domain_num_	eval $rl send-num-of-clusters $cluster_num_	eval $rl send-num-of-nodes $nodes_num_}Simulator instproc compute-hier-routes {} {	$self instvar Node_ link_	set r [$self get-routelogic]        $self cmd get-routelogic $r ;# propagate rl in C++    	# send hierarchical data :	# array of cluster size, #clusters, #domains	# assuming 3 levels of hierarchy --> this should be extended to support	# n-levels of hierarchy	#        if ![info exists link_] {		return	}        set level [AddrParams hlevel]        $r hlevel-is $level	$self hier-topo $r	foreach ln [array names link_] {		set L [split $ln :]	        set srcID [[$self get-node-by-id [lindex $L 0]] node-addr]		set dstID [[$self get-node-by-id [lindex $L 1]] node-addr]		if { [$link_($ln) up?] == "up" } {			$r hier-insert $srcID $dstID [$link_($ln) cost?]		} else {			$r hier-reset $srcID $dstID		}	}	$r hier-compute	# Set up each classifier (n for n levels of hierarchy) 	# for every node		# classifier-population part moved to C++: this results in > 50%         # improvement of simulation run time. -Padma, 02/01.	set n [Node set nn_]	$self populate-hier-classifiers $n	#$self gen-map#	for {set i 0} {$i < $n} {incr i} {#		if ![info exists Node_($i)] {#			continue#		}#		set n1 $Node_($i)#		set addr [$n1 node-addr]#		set L [AddrParams split-addrstr $addr]		#		# for each hierarchy level, populate classifier for that level		##		for {set k 0} {$k < $level} {incr k} {#			set csize [AddrParams elements-in-level? $addr $k]			#			# for each element in that level (elements maybe 			# nodes or clusters or domains 			##			if {$k > 0} {#				set prefix [$r append-addr $k $L]#			}#			for {set m 0} {$m < $csize} {incr m} {#				if { $m == [lindex $L $k]} {#					continue#				}#				if {$k > 0} {#					set str $prefix#					append str . $m#				} else {#					set str $m#				}#				set nh [$r hier-lookup $addr $str]				# add entry in clasifier only if hier-lookup 				# returns a value. #				if {$nh == -1} { #					continue#				}#				set node [$self get-node-id-by-addr $nh]#				if { $node >= 0 } {#					$n1 sp-add-route $str \#							[$link_($i:$node) head]#				}#			}#		}#	}#}}## Now source the dynamic routing protocol methods#source ../rtglib/route-proto.tclsource ../rtglib/dynamics.tclsource ../rtglib/algo-route-proto.tclSimulator instproc compute-algo-routes {} {	$self instvar Node_ link_	#	# Compute all the routes using the route-logic helper object.	#	set r [$self get-routelogic]	$r BFS	$r compute	#	# Set up each classifer (aka node) to act as a router.	# Point each classifer table to the link object that	# in turns points to the right node.	#	set i 0	set n [Node set nn_]	while { $i < $n } {		if ![info exists Node_($i)] {		    incr i		    continue		}		set n1 $Node_($i)		$n1 set rtsize_ 1 		set j 0		while { $j < $n } {		    if { $i != $j } {			# shortened nexthop to nh, to fit add-route in			# a single line			set nh [$r lookup $i $j]			# puts "$i $j $nh"			if { $nh >= 0 } {			    $n1 add-route $j [$link_($i:$nh) head]			    ###$n1 incr-rtgtable-size			}		    } 		    incr j		}		incr i	}}# Asim routines # Debojyoti DuttaSimulator instproc asim-run { } {    $self instvar asim_    set asim_ [new Asim]    $self asim-dump ddt    $asim_ readinput ddt    $asim_ run}Simulator instproc asim-dump { file } {	$self instvar routingTable_ Node_ link_        $self instvar nconn_ conn_ sflows_ nsflows_                set tf_ [open "$file" w]    	set r [$self get-routelogic]		$self cmd get-routelogic $r  ;# propagate rl in C++	# populate the route logic 	foreach ln [array names link_] {		set L [split $ln :]		set srcID [lindex $L 0]		set dstID [lindex $L 1]		if { [$link_($ln) up?] == "up" } {			$r insert $srcID $dstID [$link_($ln) cost?]		} else {			$r reset $srcID $dstID		}	}	# now compute routes	$r compute	puts $tf_ "# Dumping Approx-Sim Data"  	set n [Node set nn_]	puts $tf_ "m [Link set nl_] "        foreach qn [array names link_] {                set l $link_($qn)	        set q [$l queue]	        set t [$q info class]	    if {[lindex [split $t "/"] 1] == "DropTail"} {                puts $tf_ "link [expr [$l set id_] + 1] [$l delay] [expr [$l bw] / 8000] [expr [$l bw] / 8000]  [$l qsize] $t"	    }	    if {[lindex [split $t "/"] 1] == "RED"} {                puts $tf_ "link [expr [$l set id_] + 1] [$l delay] [expr [$l bw] / 8000] [expr [$l bw] / 8000] [$l qsize] red [$q set thresh_] 0 [$q set maxthresh_] [expr 1.0 / [$q set linterm_] ]"	    }        }	puts $tf_ ""	puts $tf_ "n [expr $nconn_ + $nsflows_]"		set i 0	foreach x $conn_ {		set len 0		set str ""		set list [split $x ":"] 		set srcid [lindex $list 0]		set dstid [lindex $list 1]		while { $srcid != $dstid } {			incr len			# shortened nexthop to nh, to fit add-route in			# a single line			set nh [$r lookup $srcid $dstid]			# print the route 			append str " " [expr [$link_($srcid:$nh) id] + 1] 			set srcid  $nh		}				puts $tf_ "route [expr $i + 1] $len $str"		incr i	}	foreach x $sflows_ {		set len 0		set str ""		set list [split $x ":"] 		set srcid [lindex $list 0]		set dstid [lindex $list 1]	        set lambda [lindex $list 2]	        set mu [lindex $list 3]		while { $srcid != $dstid } {			incr len			# shortened nexthop to nh, to fit add-route in			# a single line			set nh [$r lookup $srcid $dstid]			# print the route 			append str " " [expr [$link_($srcid:$nh) id] + 1] 			set srcid  $nh		}				puts $tf_ "route [expr $i + 1] $len $str sh $lambda $mu"		incr i	}	close $tf_}Simulator instproc asim-getLinkDelay { link } {    $self instvar asim_    set t [$asim_ get-link-delay [$link set id_] ]    return $t}Simulator instproc asim-getLinkDrop { link } {    $self instvar asim_    set t [$asim_ get-link-drop [$link set id_] ]    return $t}Simulator instproc asim-getLinkTput { link } {    $self instvar asim_    set t [$asim_ get-link-tput [$link set id_] ]    return $t}Simulator instproc asim-getAggrTput { srcnode dstnode } {    $self instvar conn_    $self instvar asim_     set src [$srcnode id]    set dst [$dstnode id]#    puts "searching $src:$dst in $conn_"    set tt [lsearch -exact $conn_ $src:$dst]    set t [$asim_ get-flow-tput $tt ]    return $t}Simulator instproc asim-getFlowTput { agent } {    $self instvar conn_    $self instvar asim_    set srcnode [$self get-node-by-addr [$agent set agent_addr_]]    set dstnode [$self get-node-by-addr [$agent set dst_addr_]]    set src [$srcnode id]    set dst [$dstnode id]    set sport [$agent set agent_port_]    set dport [$agent set dst_port_]#    puts "searching $src:$dst in $conn_"    set tt [lsearch -exact $conn_ $src:$dst:$sport:$dport]    set t [$asim_ get-flow-tput $tt ]    return $t}Simulator instproc asim-getFlowDrop { agent } {    $self instvar conn_    $self instvar asim_    set srcnode [$self get-node-by-addr [$agent set agent_addr_]]    set dstnode [$self get-node-by-addr [$agent set dst_addr_]]    set src [$srcnode id]    set dst [$dstnode id]    set sport [$agent set agent_port_]    set dport [$agent set dst_port_]#    puts "searching $src:$dst in $conn_"    set tt [lsearch -exact $conn_ $src:$dst:$sport:$dport]    set t [$asim_ get-flow-drop $tt ]    return $t}

⌨️ 快捷键说明

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