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

📄 ns-lib.tcl

📁 Ns2下Wimax的代码
💻 TCL
📖 第 1 页 / 共 5 页
字号:
	    rxPower_ txPower_ idlePower_ sleepPower_ sleepTime_ transitionPower_ \	    transitionTime_ satNodeType_ eotTrace_        if [info exists macTrace_] {		Simulator set MacTrace_ $macTrace_	}        if [info exists routerTrace_] {		Simulator set RouterTrace_ $routerTrace_	}        if [info exists agentTrace_] {		Simulator set AgentTrace_ $agentTrace_	}        if [info exists movementTrace_] {		Simulator set MovementTrace_ $movementTrace_	}	# change wrt Mike's code	if [info exists eotTrace_] {                Simulator set EotTrace_ $eotTrace_        }        # hacking for matching old cmu add-interface        # not good style, for back-compability ONLY	#	# Only create 1 instance of prop	if {[info exists propInstance_]} {		if {[info exists propType_] && [Simulator set propInstCreated_] == 0} {			warn "Both propType and propInstance are set. propType is ignored."		}	} else {		if {[info exists propType_]} {			set propInstance_ [new $propType_]			Simulator set propInstCreated_ 1		}	}		# Add multi-interface support: 	# User can only specify either channelType_ (single_interface as 	# before) or channel_ (multi_interface) 	# If both variables are specified, error! 	if {[info exists channelType_] && [info exists channel_]} { 		error "Can't specify both channel and channelType, error!"	} elseif {[info exists channelType_] && ![info exists satNodeType_]} {		# Single channel, single interface		warn "Please use -channel as shown in tcl/ex/wireless-mitf.tcl"		if {![info exists chan]} {			set chan [new $channelType_]		} 	} elseif {[info exists channel_]} {		# Multiple channel, multiple interfaces		set chan $channel_ 	}	if [info exists topoInstance_] {		$propInstance_  topography $topoInstance_	}	# set address type, hierarchical or expanded	if {[string compare $addressType_ ""] != 0} {		$self set-address-format $addressType_ 	}	# set mobileIP flag	if { [info exists mobileIP_] && $mobileIP_ == "ON"} {		Simulator set mobile_ip_  1	} else {		if { [info exists mobileIP_] } {			Simulator set mobile_ip_ 0		}	}}# 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_        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_        }	# 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	}		# wireless-ready node	if { [info exists routingAgent_] && ($routingAgent_ != "") } {		set node [eval $self create-wireless-node $args]		# 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	}		# 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_ sleepPower_ sleepTime_ transitionPower_ transitionTime_ \	    topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_	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 {		    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]	    }	    OMNIMCAST {		    eval $node addr $args		    set ragent [$self create-omnimcast-agent $node]	    }	    DumbAgent {		    set ragent [$self create-dumb-agent $node]	    }	    ManualRtg {		    set ragent [$self create-manual-rtg-agent $node]	    }	    default {		    eval $node addr $args		    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	$node add-interface $chan $propInstance_ $llType_ $macType_ \	    $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ \			$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_        }#	if [info exists sleepPower_] {		$node setPsleep $sleepPower_        }	if [info exists sleepTime_] {		$node setTSleep $sleepTime_        }	if [info exists transitionPower_] {		$node setPtransition $transitionPower_        }	if [info exists transitionTime_] {		$node setTtransition $transitionTime_        }	#	$node topography $topoInstance_		return $node}Simulator instproc create-node-instance args {	$self instvar routingAgent_	# DSR is a special case	if {$routingAgent_ == "DSR"} {		set nodeclass [$self set-dsr-nodetype]	} else {		set nodeclass Node/MobileNode	}	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}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-manual-rtg-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/ManualRtgAgent]	$node set ragent_ $ragent	$node attach $ragent [Node set rtagent_port_]		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])]} {

⌨️ 快捷键说明

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