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

📄 ns-lib.tcl

📁 NS-2.28的802.11e协议扩展源代码
💻 TCL
📖 第 1 页 / 共 4 页
字号:
	    TORA {		set imepflag_ ON		set ragent [$self create-tora-agent $node]	    }	    DIFFUSION/RATE {		$node addr $args		set ragent [$self create-diffusion-rate-agent $node]	    }	    DIFFUSION/PROB {		$node addr $args		set ragent [$self create-diffusion-probability-agent $node]	    }	    FLOODING {		$node addr $args		set ragent [$self create-flooding-agent $node]	    }	    OMNIMCAST {		$node addr $args		set ragent [$self create-omnimcast-agent $node]	    }	    default {		puts "Wrong node routing agent!"		exit	    }	}	# add main node interface	$node add-interface $chan $propInstance_ $llType_ $macType_ \	       $ifqType_ $ifqlen_ $phyType_ $antType_	# attach agent	if {$routingAgent_ != "DSR"} {	     $node attach $ragent 255	}	if {$routingAgent_ == "DIFFUSION/RATE" ||            $routingAgent_ == "DIFFUSION/PROB" ||            $routingAgent_ == "FLOODING" ||            $routingAgent_ == "OMNIMCAST" } {	    $ragent port-dmux [$node set dmux_]	    $node instvar ll_	    $ragent add-ll $ll_(0)	}	if {$routingAgent_ == "BSS"} {		$node instvar mac_		$ragent mac $mac_(0)	}	# bind routing agent and mip agent if existing	# basestation address setting        if { [info exist wiredRouting_] && $wiredRouting_ == "ON" } {	    if { $routingAgent_ != "DSR" } {	        $node mip-call $ragent	    }	}	#        # This Trace Target is used to log changes in direction        # and velocity for the mobile node.        #		set tracefd [$self get-ns-traceall]        if {$tracefd != "" } {	    $node nodetrace $tracefd	    $node agenttrace $tracefd	}		set namtracefd [$self get-nam-traceall]		if {$namtracefd != "" } {	    	    $node namattach $namtracefd	}	if [info exists energyModel_] {             if  [info exists level1_] {	       set l1 $level1_	     } else {	       set l1 0.5	     }             if  [info exists level2_] {	       set l2 $level2_	     } else {	       set l2 0.2	     }	     $node addenergymodel [new $energyModel_ $initialEnergy_ $l1 $l2]        }        if [info exists txPower_] {	    $node setPt $txPower_        }        if [info exists rxPower_] {	    $node setPr $rxPower_        }        if [info exists idlePower_] {	    $node setPidle $idlePower_        }	$node topography $topoInstance_	return $node}#Class BaseNode -superclass {HierNode Node/MobileNode}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}Simulator instproc create-bss-agent { node } {    # Create a bss routing agent for this node    set ragent [new Agent/BSS]    ## setup address (supports hier-addr) for bss agent    ## and mobilenode    $ragent node $node    if [Simulator set mobile_ip_] {        $ragent port-dmux [$node set dmux_]    }    $node set ragent_ $ragent    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 {		if { [llength $args] == 0} {		    set q [new Queue/$qtype]		} else {		    set q [new Queue/$qtype $args]		}	    }	}	# 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]

⌨️ 快捷键说明

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