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

📄 ns-lib.tcl

📁 impl茅mentation of OLSR pour ns2
💻 TCL
📖 第 1 页 / 共 4 页
字号:
		#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_	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]	    }	    OLSR {	            set ragent [$self create-olsr-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]	    }	    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	$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_        }	$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-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 create-olsr-agent { node } {	#  Create OLSR routing agent	set ragent [new Agent/OLSR [$node node-addr]]	$self at 0.0 "$ragent start"	$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 check-smac {} {	$self instvar macType_	if { [info exist macType_] && $macType_ == "Mac/SMAC" } {		if { [$macType_ set syncFlag_] } {			puts "\nNOTE: SMAC is running with sleep-wakeup cycles on. Please make sure to run yr applications AFTER the nodes get sync'ed which is about 40sec for the default settings.\n"		}	}}			Simulator instproc run {} {	# NIXVECTOR?	# global runstart	# set runstart [clock seconds]	$self check-smac                      ;# print warning if in sleep/wakeup cycle	$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]}# 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]		}		XCP {			set q [ $self create-XCPQ ]		}		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]		}                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]                }        }	if {$qtype == "RED/Pushback"} {		set pushback 1	} else {		set pushback 0	}	$n1 add-neighbor $n2 $pushback		#XXX yuck	if {[string first "RED" $qtype] != -1 || 	    [string first "PI" $qtype] != -1 || 	    [string first "Vq" $qtype] != -1 ||	    [string first "REM" $qtype] != -1 ||  	    [string first "GK" $qtype] != -1 ||  	    [string first "RIO" $qtype] != -1 ||	    [string first "XCP" $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

⌨️ 快捷键说明

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