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

📄 ns-lib.tcl

📁 运行于linux上的CIMS套件
💻 TCL
📖 第 1 页 / 共 3 页
字号:
Simulator instproc create-node-instance { args } {              $self instvar routingAgent_              set nodeclass Node/MobileNode	      # DSR is a special case	      if {$routingAgent_ == "DSR"} {		  set nodeclass [$self set-dsr-nodetype]	      }	      	      if {$args != "{}" && $args != "{{}}"} {		  set node [new $nodeclass $args]	      } else {		  set node [new $nodeclass]	      }	      return $node}Simulator instproc set-dsr-nodetype {} {       $self instvar wiredRouting_               set nodetype SRNodeNew       # MIP mobilenode       if [Simulator set mobile_ip_] {	   set nodetype SRNodeNew/MIPMH       }       # basestation dsr node       if { [info exists wiredRouting_] && $wiredRouting_ == "ON"} {	   set nodetype Node/MobileNode/BaseStationNode       }              return $nodetype}Simulator instproc create-tora-agent { node } {        set ragent [new Agent/TORA [$node id]]        #delay till after add interface        #       $node attach $ragent 255        #$ragent if-queue [$node set ifq_(0)]    ;# ifq between LL and MAC        #        # XXX: The routing protocol and the IMEP agents needs handles        # to each other.        #        #$ragent imep-agent [$node set imep_(0)]        #[$node set imep_(0)] rtagent $ragent   	#	# Drop Target (always on regardless of other tracing)	#	#set drpT [$self mobility-trace Drop "RTR" $node]	#$ragent drop-target $drpT        #set tracefd [$self get-ns-traceall]        #if {$tracefd != "" } {	    #	    # Log Target	    #	#    set T [new Trace/Generic]	#    $T target [$ns_ set nullAgent_]	#    $T attach $tracefd	#    $T set src_ $id	#    $ragent log-target $T	#}            #        # XXX: let the IMEP agent use the same log target.        #        #[$node set imep_(0)] log-target $T	$node set ragent_ $ragent	return $ragent}Simulator instproc create-dsdv-agent { node } {    # Create a dsdv routing agent for this node    set ragent [new Agent/DSDV]    ## setup address (supports hier-addr) for dsdv agent    ## and mobilenode    set addr [$node node-addr]    $ragent addr $addr    $ragent node $node    if [Simulator set mobile_ip_] {        $ragent port-dmux [$node set dmux_]    }    $node addr $addr    $node set ragent_ $ragent    #delay till after add interface #   $node attach $ragent 255    $self at 0.0 "$ragent start-dsdv"    ;# start updates    return $ragent}# JCWSimulator instproc create-noah-agent { node } {    # Create a noah routing agent for this node    set ragent [new Agent/NOAH]    ## setup address (supports hier-addr) for noah agent    ## and mobilenode    set addr [$node node-addr]    $ragent addr $addr    $ragent node $node    if [Simulator set mobile_ip_] {        $ragent port-dmux [$node set dmux_]    }    $node addr $addr    $node set ragent_ $ragent    #delay till after add interface #   $node attach $ragent 255    #$self at 0.0 "$ragent start-noah"    ;# start updates    return $ragent}Simulator instproc create-aodv-agent { node } {        #        #  Create the Routing Agent and attach it to port 255.        #        set ragent [new Agent/AODV [$node id]]        #set ragent_($id) [new $opt(ragent) $id]        #set ragent $ragent_($id)        #$node attach $ragent 255        #$ragent if-queue [$node set ifq_(0)]    ;# ifq between LL and MAC        $self at 0.0 "$ragent start"     ;# start BEACON/HELLO Messages        #        # Drop Target (always on regardless of other tracing)        #        #set drpT [cmu-trace Drop "RTR" $node]        #$ragent drop-target $drpT        #        # Log Target        #        #set T [new Trace/Generic]        #$T target [$ns_ set nullAgent_]        #$T attach $tracefd        #$T set src_ $id        #$ragent log-target $T            $node set ragent_ $ragent        return $ragent}Simulator instproc use-newtrace {} {       $self instvar newTraceFormat           set newTraceFormat 1} Simulator instproc mobility-trace {ttype atype node} {        $self instvar newTraceFormat        set tracefd [$self get-ns-traceall]        if { $tracefd == "" } {	        puts "Warning: You have not defined you tracefile yet!"	        puts "Please use trace-all command to define it."		return ""	}	set T [new CMUTrace/$ttype $atype]	if { [info exist newTraceFormat] && $newTraceFormat == "1" } {	    $T newtrace 1	} 	$T target [$self set nullAgent_]	$T attach $tracefd        $T set src_ [$node id]        $T node $node	return $T}Simulator instproc hier-node haddr { 	error "now create hier-nodes with just [$ns_ node $haddr]"}Simulator instproc now {} {	$self instvar scheduler_	return [$scheduler_ now]}Simulator instproc at args {	$self instvar scheduler_	return [eval $scheduler_ at $args]}Simulator instproc at-now args {	$self instvar scheduler_	return [eval $scheduler_ at-now $args]}Simulator instproc cancel args {	$self instvar scheduler_	return [eval $scheduler_ cancel $args]}Simulator instproc after {ival args} {        eval $self at [expr [$self now] + $ival] $args}## check if total num of nodes exceed 2 to the power n # where <n=node field size in address>#Simulator instproc check-node-num {} {	AddrParams instvar nodebits_ 	if {[Node set nn_] > [expr pow(2, $nodebits_)]} {		error "Number of nodes exceeds node-field-size of $nodebits_ bits"	}	if [Simulator set EnableHierRt_] {# 		$self chk-hier-field-lengths	}}## Check if number of items at each hier level (num of nodes, or clusters or domains)# exceed size of that hier level field size (in bits). should be modified to support # n-level of hierarchies#Simulator instproc chk-hier-field-lengths {} {	AddrParams instvar domain_num_ cluster_num_ nodes_num_ NodeMask_		if [info exists domain_num_] {		if {[expr $domain_num_ - 1]> $NodeMask_(1)} {			error "\# of domains exceed dom-field-size "		}	} 	if [info exists cluster_num_] {		set maxval [expr [find-max $cluster_num_] - 1] 		if {$maxval > [expr pow(2, $NodeMask_(2))]} {			error "\# of clusters exceed clus-field-size "		}	}	if [info exists nodes_num_] {		set maxval [expr [find-max $nodes_num_] -1]		if {$maxval > [expr pow(2, $NodeMask_(3))]} {			error "\# of nodess exceed node-field-size"		}	}}Simulator instproc run {} {	#$self compute-routes	$self check-node-num	$self rtmodel-configure			;# in case there are any	[$self get-routelogic] configure	$self instvar scheduler_ Node_ link_ started_ 		set started_ 1		#	# Reset every node, which resets every agent.	#	foreach nn [array names Node_] {		$Node_($nn) reset	}	#	# Also reset every queue	#	foreach qn [array names link_] {		set q [$link_($qn) queue]		$q reset	}	# Do all nam-related initialization here	$self init-nam	return [$scheduler_ run]}Simulator instproc halt {} {	$self instvar scheduler_	$scheduler_ halt}Simulator instproc dumpq {} {	$self instvar scheduler_	$scheduler_ dumpq}Simulator instproc is-started {} {	$self instvar started_	return [info exists started_]}Simulator instproc clearMemTrace {} {	$self instvar scheduler_	$scheduler_ clearMemTrace}Simulator instproc simplex-link { n1 n2 bw delay qtype args } {	$self instvar link_ queueMap_ nullAgent_	set sid [$n1 id]	set did [$n2 id]		if [info exists queueMap_($qtype)] {		set qtype $queueMap_($qtype)	}	# construct the queue	set qtypeOrig $qtype	switch -exact $qtype {		ErrorModule {			if { [llength $args] > 0 } {				set q [eval new $qtype $args]			} else {				set q [new $qtype Fid]			}		}		intserv {			set qtype [lindex $args 0]			set q [new Queue/$qtype]		}		default {			set q [new Queue/$qtype]		}	}	# Now create the link	switch -exact $qtypeOrig {		RTM {                        set c [lindex $args 1]                        set link_($sid:$did) [new CBQLink       \                                        $n1 $n2 $bw $delay $q $c]                }                CBQ -                CBQ/WRR {                        # assume we have a string of form "linktype linkarg"                        if {[llength $args] == 0} {                                # default classifier for cbq is just Fid type                                set c [new Classifier/Hash/Fid 33]                        } else {                                set c [lindex $args 1]                        }                        set link_($sid:$did) [new CBQLink       \                                        $n1 $n2 $bw $delay $q $c]                }		FQ      {			set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $q]		}                intserv {                        #XX need to clean this up                        set link_($sid:$did) [new IntServLink   \                                        $n1 $n2 $bw $delay $q	\						[concat $qtypeOrig $args]]                }                default {                        set link_($sid:$did) [new SimpleLink    \                                        $n1 $n2 $bw $delay $q]                }        }	$n1 add-neighbor $n2		#XXX yuck	if {[string first "RED" $qtype] != -1} {		$q link [$link_($sid:$did) set link_]	}		set trace [$self get-ns-traceall]	if {$trace != ""} {		$self trace-queue $n1 $n2 $trace	}	set trace [$self get-nam-traceall]	if {$trace != ""} {		$self namtrace-queue $n1 $n2 $trace	}		# Register this simplex link in nam link list. Treat it as 	# a duplex link in nam	$self register-nam-linkconfig $link_($sid:$did)}## This is used by Link::orient to register/update the order in which links # should created in nam. This is important because different creation order# may result in different layout.## A poor hack. :( Any better ideas?#Simulator instproc register-nam-linkconfig link {    $self instvar linkConfigList_ link_    if [info exists linkConfigList_] {	# Check whether the reverse simplex link is registered,	# if so, don't register this link again.	# We should have a separate object for duplex link.	set i1 [[$link src] id]	set i2 [[$link dst] id]	if [info exists link_($i2:$i1)] {	    set pos [lsearch $linkConfigList_ $link_($i2:$i1)]	    if {$pos >= 0} {		set a1 [$link_($i2:$i1) get-attribute "ORIENTATION"]		set a2 [$link get-attribute "ORIENTATION"]		if {$a1 == "" && $a2 != ""} {		    # If this duplex link has not been 		    # assigned an orientation, do it.		    set linkConfigList_ \			[lreplace $linkConfigList_ $pos $pos]		} else {		    return		}	    }	}	# Remove $link from list if it's already there	set pos [lsearch $linkConfigList_ $link]	if {$pos >= 0} {	    set linkConfigList_ \		[lreplace $linkConfigList_ $pos $pos]	}    }    lappend linkConfigList_ $link}## GT-ITM may occasionally generate duplicate links, so we need this check# to ensure duplicated links do not appear in nam trace files.#Simulator instproc remove-nam-linkconfig {i1 i2} {	$self instvar linkConfigList_ link_	if ![info exists linkConfigList_] {		return	}	set pos [lsearch $linkConfigList_ $link_($i1:$i2)]	if {$pos >= 0} {		set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]		return	}	set pos [lsearch $linkConfigList_ $link_($i2:$i1)]	if {$pos >= 0} {		set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]	}}Simulator instproc duplex-link { n1 n2 bw delay type args } {	$self instvar link_	set i1 [$n1 id]	set i2 [$n2 id]	if [info exists link_($i1:$i2)] {		$self remove-nam-linkconfig $i1 $i2	}	eval $self simplex-link $n1 $n2 $bw $delay $type $args	eval $self simplex-link $n2 $n1 $bw $delay $type $args}Simulator instproc duplex-intserv-link { n1 n2 bw pd sched signal adc args } {	eval $self duplex-link $n1 $n2 $bw $pd intserv $sched $signal $adc $args}Simulator instproc simplex-link-op { n1 n2 op args } {	$self instvar link_	eval $link_([$n1 id]:[$n2 id]) $op $args}Simulator instproc duplex-link-op { n1 n2 op args } {	$self instvar link_	eval $link_([$n1 id]:[$n2 id]) $op $args	eval $link_([$n2 id]:[$n1 id]) $op $args}Simulator instproc flush-trace {} {	$self instvar alltrace_	if [info exists alltrace_] {		foreach trace $alltrace_ {			$trace flush		}	}}Simulator instproc namtrace-all file   {	$self instvar namtraceAllFile_	if {$file != ""} {		set namtraceAllFile_ $file	} else {		unset namtraceAllFile_	}}Simulator instproc energy-color-change {level1 level2} {	$self instvar level1_ level2_ 	set level1_ $level1 	set level2_ $level2}Simulator instproc namtrace-all-wireless {file optx opty} {

⌨️ 快捷键说明

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