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

📄 ns-lib.tcl

📁 对ns2软件进行UMTS扩展
💻 TCL
📖 第 1 页 / 共 4 页
字号:
# Default behavior is changed: consider nam as not initialized if# no shape OR color parameter is givenSimulator instproc node args {	$self instvar Node_ routingAgent_ wiredRouting_ satNodeType_ umtsType_        if { [Simulator info vars EnableMcast_] != "" } {                warn "Flag variable Simulator::EnableMcast_ discontinued.\n\t\                      Use multicast methods as:\n\t\t\                        % set ns \[new Simulator -multicast on]\n\t\t\                        % \$ns multicast"                $self multicast                Simulator unset EnableMcast_        }        if { [Simulator info vars NumberInterfaces_] != "" } {                warn "Flag variable Simulator::NumberInterfaces_ discontinued.\n\t\                      Setting this variable will not affect simulations."                Simulator unset NumberInterfaces_        }	# wireless-ready node	if { [info exists routingAgent_] && ($routingAgent_ != "") } {		set node [eval $self create-wireless-node $args]		# P.M. & P.B. modifications		if {[info exists umtsType_]} {			set Node_([$node id]) $node			#simulator's nodelist in C++ space			$self add-node $node [$node id]		} else {			# for base node			if {[info exists wiredRouting_] && $wiredRouting_ == "ON"} {				set Node_([$node id]) $node				#simulator's nodelist in C++ space				$self add-node $node [$node id]			}		}		return $node	}	# Satellite node	if { [info exists satNodeType_] } {		set node [eval $self create-satnode]		#simulator's nodelist in C++ space		if {[info exists wiredRouting_] && $wiredRouting_ == "ON"} {			# add node to simulator's nodelist in C++ space			$self add-node $node [$node id]			# Want to keep global state of wiredRouting info			SatRouteObject set wiredRouting_ true		}		return $node	}	# Enable-mcast is now done automatically inside Node::init{}	#	# XXX node_factory_ is deprecated, HOWEVER, since it's still used by	# mobile IP, algorithmic routing, manual routing, and backward	# compability tests of hierarchical routing, we should keep it around	# before all related code are wiped out.	set node [eval new [Simulator set node_factory_] $args]	set Node_([$node id]) $node	#add to simulator's nodelist in C++ space	$self add-node $node [$node id]	#set the nodeid in c++ Node - ratul	$node nodeid [$node id]	$node set ns_ $self	$self check-node-num	return $node}# XXX This is stupid hack. When old code (not using node-config) is used,# create-wireless-node{} will not be called, and IMEPFlag_ will remain empty# (as set in ns-default.tcl), then Node/MobileNode will use global proc# cmu-trace to create trace objects; otherwise mobility-trace{} will be# triggered.Simulator instproc imep-support {} {	return [Simulator set IMEPFlag_]}# XXX This should be moved into the node initialization procedure instead# of standing here in ns-lib.tcl.Simulator instproc create-wireless-node args {        $self instvar routingAgent_ wiredRouting_ propInstance_ llType_ \		macType_ ifqType_ ifqlen_ phyType_ chan antType_ energyModel_ \		initialEnergy_ txPower_ rxPower_ idlePower_ \		topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_ \		umtsType_ phyLayer_ rlcType_	Simulator set IMEPFlag_ OFF        # create node instance        set node [eval $self create-node-instance $args]        # basestation address setting        if { [info exist wiredRouting_] && $wiredRouting_ == "ON" } {		$node base-station [AddrParams addr2id [$node node-addr]]    	}        switch -exact $routingAgent_ {	    DSDV {		    puts "DSDV elegido"		    set ragent [$self create-dsdv-agent $node]	    }	    DSR {		    $self at 0.0 "$node start-dsr"	    }	    AODV {		    set ragent [$self create-aodv-agent $node]	    }	    TORA {		    Simulator set IMEPFlag_ ON		    set ragent [$self create-tora-agent $node]	    }	    DIFFUSION/RATE {		    eval $node addr $args		    set ragent [$self create-diffusion-rate-agent $node]	    }	    DIFFUSION/PROB {		    eval $node addr $args		    set ragent [$self create-diffusion-probability-agent $node]	    }	    Directed_Diffusion {		    eval $node addr $args		    set ragent [$self create-core-diffusion-rtg-agent $node]	    }	    FLOODING {		    eval $node addr $args		    set ragent [$self create-flooding-agent $node]	    }	    # P.M. & P.B. modifications	    NOAH {		    set ragent [$self create-noah-agent $node]          }	    OMNIMCAST {		    eval $node addr $args		    set ragent [$self create-omnimcast-agent $node]	    }	    DumbAgent {		    set ragent [$self create-dumb-agent $node]	    }	    default {		    puts "Wrong_ node routing agent!"		    exit	    }	}	# errProc_ and FECProc_ are an option unlike other        # parameters for node interface	if ![info exist inerrProc_] {		set inerrProc_ ""	}	if ![info exist outerrProc_] {		set outerrProc_ ""	}	if ![info exist FECProc_] {		set FECProc_ ""	}	# Add main node interface	# P.M. & P.B. modifications	if { [info exists rlcType_] && [info exists phyLayer_]} {		$node add-interface $chan $propInstance_ $llType_ $rlcType_ $macType_ \			$phyLayer_ $ifqType_ $ifqlen_ $phyType_ $antType_ \			$inerrProc_ $outerrProc_ $FECProc_	} else {		$node add-interface $chan $propInstance_ $llType_ $macType_ \			$ifqType_ $ifqlen_ $phyType_ $antType_ \			$inerrProc_ $outerrProc_ $FECProc_	}	# Attach agent	if {$routingAgent_ != "DSR"} {		$node attach $ragent [Node set rtagent_port_]	}	if {$routingAgent_ == "DIFFUSION/RATE" ||            $routingAgent_ == "DIFFUSION/PROB" ||            $routingAgent_ == "FLOODING" ||            $routingAgent_ == "OMNIMCAST" ||	    $routingAgent_ == "Directed_Diffusion" } {		$ragent port-dmux [$node demux]		$node instvar ll_		$ragent add-ll $ll_(0)	}	if { $routingAgent_ == "DumbAgent" } {		$ragent port-dmux [$node demux]	}	# 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_ $node \				$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}Simulator instproc create-node-instance args {	$self instvar routingAgent_ umtsType_	# DSR is a special case	if {$routingAgent_ == "DSR"} {		set nodeclass [$self set-dsr-nodetype]	} else {		# P.M. & P.B. modifications		set nodeclass Node/MobileNode		if {[info exists umtsType_]} {			set nodeclass_temp [$self get-nodetype]			set nodeclass Node/MobileNode/$nodeclass_temp		}	}	return [eval new $nodeclass $args]}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]]	$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 demux]	}	$node addr $addr	$node set ragent_ $ragent	$self at 0.0 "$ragent start-dsdv"    ;# start updates	return $ragent}# P.M. & P.B. modificationsSimulator 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-dumb-agent { node } {	# create a simple wireless agent	# that only forwards packets	# used for testing single hop brdcast/unicast mode	# for wireless macs	set ragent [new Agent/DumbAgent]	$node set ragent_ $ragent	return $ragent}Simulator instproc create-aodv-agent { node } {        #  Create AODV routing agent	set ragent [new Agent/AODV [$node node-addr]]        $self at 0.0 "$ragent start"     ;# start BEACON/HELLO Messages        $node set ragent_ $ragent        return $ragent}Simulator instproc use-newtrace {} {	Simulator set WirelessNewTrace_ 1}Simulator instproc use-taggedtrace { {tag ON} } {	Simulator set TaggedTrace_ $tag}Simulator instproc hier-node haddr { 	error "hier-nodes should be created with [$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 {} {	if {[Node set nn_] > [expr pow(2, [AddrParams nodebits])]} {		error "Number of nodes exceeds node-field-size of [AddrParams nodebits] bits"	}}## 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_	if [info exists domain_num_] {		if {[expr $domain_num_ - 1]> [AddrParams 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, [AddrParams 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, [AddrParams NodeMask 3])]} {			error "\# of nodess exceed node-field-size"		}	}}Simulator instproc run {} {	# NIXVECTOR?	# global runstart	# set runstart [clock seconds]	$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		# GFR Additions for NixVector Routing		if { [Simulator set nix-routing] } {			$Node_($nn) populate-objects		}	}	#	# 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	# NIXVECTOR xxx?	# global simstart	# set simstart [clock seconds]	return [$scheduler_ run]}# P.M. & P.B. modificationsSimulator instproc set-umts-routing { } {    Simulator set umts-routing 1    Node enable-module "Umts"}# johnh xxx?Simulator instproc log-simstart { } {        # GFR Modification to log actual start        global simstart        puts "Starting Actual Simulation"        set simstart [clock seconds]}Simulator instproc halt {} {	$self instvar scheduler_	#puts "time: [clock format [clock seconds] -format %X]"	$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_ useasim_	set sid [$n1 id]	set did [$n2 id]	# Debo	if { $useasim_ == 1 } {		set slink_($sid:$did) $self	}	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]                        } else {                                set c [lindex $args 0]                        }                        set link_($sid:$did) [new CBQLink       \                                        $n1 $n2 $bw $delay $q $c]                }		FQ      {			set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $q]

⌨️ 快捷键说明

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