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

📄 ns-lib.tcl

📁 Ns2下Wimax的代码
💻 TCL
📖 第 1 页 / 共 5 页
字号:
	} elseif [info exists namtraceSomeFile_] {		puts $namtraceSomeFile_ $str	}}# namConfigFile is used for writing color/link/node/queue/annotations. # XXX It cannot co-exist with namtraceAll.Simulator instproc namtrace-config { f } {	$self instvar namConfigFile_	set namConfigFile_ $f}Simulator instproc get-nam-config {} {	$self instvar namConfigFile_	if [info exists namConfigFile_] {		return $namConfigFile_	} else {		return ""	}}# Used only for writing nam configurations to trace file(s). This is different# from puts-nam-traceall because we may want to separate configuration # informations and actual tracing informationSimulator instproc puts-nam-config { str } {	$self instvar namtraceAllFile_ namConfigFile_		if [info exists namConfigFile_] {		puts $namConfigFile_ $str	} elseif [info exists namtraceAllFile_] {		puts $namtraceAllFile_ $str	} elseif [info exists namtraceSomeFile_] {		puts $namtraceSomeFile_ $str	}}Simulator instproc color { id name } {	$self instvar color_	set color_($id) $name}Simulator instproc get-color { id } {	$self instvar color_	return $color_($id)}# you can pass in {} as a null fileSimulator instproc create-trace { type file src dst {op ""} } {	$self instvar alltrace_	set p [new Trace/$type]	$p tagged [Simulator set TaggedTrace_]	if [catch {$p set src_ [$src id]}] {		$p set src_ $src	}	if [catch {$p set dst_ [$dst id]}] {		$p set dst_ $dst	}	lappend alltrace_ $p	if {$file != ""} {		$p ${op}attach $file			}	return $p}Simulator instproc create-eventtrace {type owner } {	$self instvar alltrace_ 	$self instvar eventTraceAll_ eventtraceAllFile_ namtraceAllFile_		if ![info exists eventTraceAll_] return	if { $eventTraceAll_ == 1 } {				set et [new BaseTrace/$type]		$owner cmd eventtrace $et				lappend alltrace_ $et		$et attach $eventtraceAllFile_		if [info exists namtraceAllFile_] {			$et namattach $namtraceAllFile_		}	}}Simulator instproc namtrace-queue { n1 n2 {file ""} } {	$self instvar link_ namtraceAllFile_	if {$file == ""} {		if ![info exists namtraceAllFile_] return		set file $namtraceAllFile_	}	$link_([$n1 id]:[$n2 id]) nam-trace $self $file    	# Added later for queue specific tracing events other than enque, 	# deque and drop as of now nam does not understand special events. 	# Changes will have to be made to nam for it to understand events 	# like early drops if they are prefixed differently than "d". - ratul	set queue [$link_([$n1 id]:[$n2 id]) queue]	$queue attach-nam-traces $n1 $n2 $file}Simulator instproc trace-queue { n1 n2 {file ""} } {	$self instvar link_ traceAllFile_	if {$file == ""} {		if ![info exists traceAllFile_] return		set file $traceAllFile_	}	$link_([$n1 id]:[$n2 id]) trace $self $file		# Added later for queue specific tracing events other than enque, 	# deque and drop - ratul	set queue [$link_([$n1 id]:[$n2 id]) queue]	$queue attach-traces $n1 $n2 $file}## arrange for queue length of link between nodes n1 and n2# to be tracked and return object that can be queried# to learn average q size etc.  XXX this API still rough#Simulator instproc monitor-queue { n1 n2 qtrace { sampleInterval 0.1 } } {	$self instvar link_	return [$link_([$n1 id]:[$n2 id]) init-monitor $self $qtrace $sampleInterval]}Simulator instproc queue-limit { n1 n2 limit } {	$self instvar link_	[$link_([$n1 id]:[$n2 id]) queue] set limit_ $limit	if {[[$link_([$n1 id]:[$n2 id]) queue] info class] == "Queue/XCP"} {		[$link_([$n1 id]:[$n2 id]) queue] queue-limit $limit	}}Simulator instproc drop-trace { n1 n2 trace } {	$self instvar link_	[$link_([$n1 id]:[$n2 id]) queue] drop-target $trace}Simulator instproc cost {n1 n2 c} {	$self instvar link_	$link_([$n1 id]:[$n2 id]) cost $c}# Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001Simulator instproc multihome-attach-agent { core agent } {      	$agent set-multihome-core [$core entry]      	foreach interface [$core set multihome_interfaces_] {  		set ifNode [lindex $interface 0]		set coreLink [lindex $interface 1]      		# attach agent to the node for each interface      		$ifNode attach $agent      		set addr [$agent set agent_addr_]      		set port [$agent set agent_port_]      		set entry [$ifNode entry]      		# give the interface info to the agent		$agent add-multihome-interface $addr $port $entry $coreLink			      		$agent instvar multihome_bindings_      		set binding_ {}      		lappend binding_ $addr      		lappend binding_ $port      		lappend multihome_bindings_ $binding_      	}}Simulator instproc attach-agent { node agent } {	$node attach $agent	# $agent set nodeid_ [$node id]        # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001 	#	# list of tuples (addr, port)	# This is NEEDED so that single homed agents can play with multihomed	# ones!	# multihoming only for SCTP agents -Padma H.	if {[lindex [split [$agent info class] "/"] 1] == "SCTP"} {		$agent instvar multihome_bindings_		set binding_ {}		set addr [$agent set agent_addr_]		set port [$agent set agent_port_]		lappend binding_ $addr		lappend binding_ $port		lappend multihome_bindings_ $binding_	}}Simulator instproc attach-tbf-agent { node agent tbf } {	$node attach $agent	$agent attach-tbf $tbf}Simulator instproc detach-agent { node agent } {	# Debo added this	$self instvar conn_ nconn_ sflows_ nsflows_ useasim_	if {$useasim_ == 1} {		set list "" 		set s [$node id]		set d [[$self get-node-by-addr [$agent set dst_addr_]] id]		foreach x $conn_ {			set t [split $x ":"] 			if {[string compare [lindex $t 0]:[lindex $t 1] $s:$d] != 0} {				lappend list_ $x			}		}		set conn_ list		set nconn_ [expr $nconn_ -1]		# ---------------------------------------	}	$self instvar nullAgent_	$node detach $agent $nullAgent_}##   Helper proc for setting delay on an existing link#Simulator instproc delay { n1 n2 delay {type simplex} } {	$self instvar link_	set sid [$n1 id]	set did [$n2 id]	if [info exists link_($sid:$did)] {		set d [$link_($sid:$did) link]		$d set delay_ $delay	}	if {$type == "duplex"} {		if [info exists link_($did:$sid)] {			set d [$link_($did:$sid) link]			$d set delay_ $delay		}	}}# #   Helper proc for setting bandwidth on an existing link#Simulator instproc bandwidth { n1 n2 bandwidth {type simplex} } {        $self instvar link_        set sid [$n1 id]        set did [$n2 id]        if [info exists link_($sid:$did)] {                set d [$link_($sid:$did) link]                $d set bandwidth_ $bandwidth        }         if {$type == "duplex"} {                if [info exists link_($did:$sid)] {                        set d [$link_($did:$sid) link]                        $d set bandwidth_ $bandwidth                }        }}#XXX need to check that agents are attached to nodes alreadySimulator instproc connect {src dst} {	$self instvar conn_ nconn_ sflows_ nsflows_ useasim_        # Armando L. Caro Jr. <acaro@@cis,udel,edu>	# does the agent type support multihoming??	# @@@ do we need to worry about $useasim_ below?? (wasn't in 2.1b8)    	if {[lindex [split [$src info class] "/"] 1] == "SCTP"} {    		$self multihome-connect $src $dst    	}	$self simplex-connect $src $dst	$self simplex-connect $dst $src	# Debo	if {$useasim_ == 1} {		set sid [$src nodeid]		set sport [$src set agent_port_]		set did [$dst nodeid]		set dport [$dst set agent_port_]				if {[lindex [split [$src info class] "/"] 1] == "TCP"} {			lappend conn_ $sid:$did:$sport:$dport			incr nconn_			# set $nconn_ [expr $nconn_ + 1]			# puts "Set a connection with id $nconn_ between $sid and $did"		}	}	return $src}# Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/12/2001Simulator instproc multihome-connect {src dst} {	        set destNum 0	foreach binding [$src set multihome_bindings_] {		incr destNum  		set addr [lindex $binding 0]  		set port [lindex $binding 1]      		$dst add-multihome-destination $addr $port    	}	if {$destNum == 0} {	        # src isn't multihomed, so make sure we do an		# add-multihome-destination		$dst add-multihome-destination \				[$src set agent_addr_] [$src set agent_port_]	}	        set destNum 0	foreach binding [$dst set multihome_bindings_] {		incr destNum  		set addr [lindex $binding 0]  		set port [lindex $binding 1]      		$src add-multihome-destination $addr $port    	}	if {$destNum == 0} {	        # dst isn't multihomed, so make sure we do an		# add-multihome-destination		$src add-multihome-destination \				[$dst set agent_addr_] [$dst set agent_port_]	}}Simulator instproc simplex-connect { src dst } {	$src set dst_addr_ [$dst set agent_addr_] 	$src set dst_port_ [$dst set agent_port_]        # Polly Huang: to support abstract TCP simulations        if {[lindex [split [$src info class] "/"] 1] == "AbsTCP"} {	    $self at [$self now] "$self rtt $src $dst"	    $dst set class_ [$src set class_]        }	return $src}## Here are a bunch of helper methods.#Simulator proc instance {} {	set ns [Simulator info instances]	if { $ns != "" } {		return $ns	}	foreach sim [Simulator info subclass] {		set ns [$sim info instances]		if { $ns != "" } {			return $ns		}	}	error "Cannot find instance of simulator"}Simulator instproc get-number-of-nodes {} {	return  [$self array size Node_]}Simulator instproc get-node-by-id id {	$self instvar Node_	return $Node_($id)}# Given an node's address, Return the node-idSimulator instproc get-node-id-by-addr address {	$self instvar Node_	set n [Node set nn_]	for {set q 0} {$q < $n} {incr q} {		set nq $Node_($q)		if {[string compare [$nq node-addr] $address] == 0} {			return $q		}	}	error "get-node-id-by-addr:Cannot find node with given address"}# Given an node's address, return the node Simulator instproc get-node-by-addr address {	return [$self get-node-by-id [$self get-node-id-by-addr $address]]}Simulator instproc all-nodes-list {} {	$self instvar Node_	set nodes ""	foreach n [lsort -dictionary [array names Node_]] {		lappend nodes $Node_($n)	}	return $nodes}Simulator instproc link { n1 n2 } {        $self instvar Node_ link_        if { ![catch "$n1 info class Node"] } {		set n1 [$n1 id]	}        if { ![catch "$n2 info class Node"] } {		set n2 [$n2 id]	}	if [info exists link_($n1:$n2)] {		return $link_($n1:$n2)	}	return ""}# Creates connection. First creates a source agent of type s_type and binds# it to source.  Next creates a destination agent of type d_type and binds# it to dest.  Finally creates bindings for the source and destination agents,# connects them, and  returns the source agent.Simulator instproc create-connection {s_type source d_type dest pktClass} {	set s_agent [new Agent/$s_type]	set d_agent [new Agent/$d_type]	$s_agent set fid_ $pktClass	$d_agent set fid_ $pktClass	$self attach-agent $source $s_agent	$self attach-agent $dest $d_agent	$self connect $s_agent $d_agent		return $s_agent}# Creates a highspeed connection. Similar to create-connection # above except the sink agent requires additional work -- SylviaSimulator instproc create-highspeed-connection {s_type source d_type dest pktClass} {        set s_agent [new Agent/$s_type]        set d_agent [new Agent/$d_type]        $d_agent resize_buffers        $s_agent set fid_ $pktClass        $d_agent set fid_ $pktClass        $self attach-agent $source $s_agent        $self attach-agent $dest $d_agent        $self connect $s_agent $d_agent        return $s_agent}# Creates connection. First creates a source agent of type s_type and binds# it to source.  Next creates a destination agent of type d_type and binds# it to dest.  Finally creates bindings for the source and destination agents,# connects them, and  returns a list of source agent and destination agent.Simulator instproc create-connection-list {s_type source d_type dest pktClass} {    set s_agent [new Agent/$s_type]    set d_agent [new Agent/$d_type]    $s_agent set fid_ $pktClass    $d_agent set fid_ $pktClass    $self attach-agent $source $s_agent    $self attach-agent $dest $d_agent    $self connect $s_agent $d_agent

⌨️ 快捷键说明

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