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

📄 try.tcl

📁 NS-2.28的802.11e协议扩展源代码
💻 TCL
字号:
############################################################################################# Main tcl code to access various wireless lan scenarios# ####################################################################################################################################################################################### Set defaults; its important to set defaults before parsing# command line arguments, so that defaults can be overriddenset mode		DCF				;# mode for this test DCF/PCFset pcf_period		0				;# CFP period for pcf modeset pcf_duration	0				;# CFP duration for pcf modeset endtime		30.0				;# duration of the simulationset title_		""				;# default title for the scenarioset idea_mac		0				;# default cleverness of mac							;# 	0 - normal							;# 	1 - persistent slotting							;# 	0 - PDCFset val(chan)		Channel/WirelessChannel		;# Channel Typeset val(prop)		Propagation/TwoRayGround	;# radio-propagation modelset val(netif)		Phy/WirelessPhy			;# network interface typeset val(mac)		Mac/802_11			;# MAC typeset val(ifq)		Queue/DropTail/PriQueue		;# interface queue typeset val(ll)		LL				;# link layer typeset val(ant)		Antenna/OmniAntenna		;# antenna modelset val(ifqlen)		50				;# max packet in ifqset val(rp)		BSS				;# routing protocolset val(x)		500set val(y)		500Phy/WirelessPhy set CPThresh_	2000Phy/WirelessPhy set per_	0.0Mac/802_11 set bandwidth_	36MbPLevels set max_plevels_	8PLevels set plevels_		1MAC_MIB set RTSThreshold_	3000MAC_MIB set ShortRetryLimit_	7MAC_MIB set LongRetryLimit_	4PHY_MIB set MinimumBandwidth_	6MbPHY_MIB set SlotTime_		0.000009PHY_MIB set SIFS_		0.000016PHY_MIB set CWMin_0		15PHY_MIB set CWMax_0		1023PHY_MIB set CWOffset_0		0############################################################################################ Usageif {$argc < 1} {	puts stderr "usage: ns $argv0 <scenario> \[list of options\]"	puts stderr "       options:"	puts stderr "             varName=varValue"	puts stderr "             vectorName=value0,value1,value2..."	puts stderr "       option example:"	puts stderr "             num_nodes=15"	exit 1;}############################################################################################ Load up the scenario; allow it to override the above defaultsset scenario [lindex $argv 0]puts "% set scenario $scenario"puts "Running scenario $scenario"source $scenario-scenario.tcl############################################################################################ Parse remaining command line arguments to override any defaultsfor {set i 1} {$i < $argc} {incr i} {	scan [lindex $argv $i] {%[a-zA-Z0-9/_:]=%[a-zA-Z0-9_.,]} var value	if {![info exists value]} {		puts stderr "BAD ARGUMENTS to main.tcl!!"		exit 1;	}	if {[string match *::* $var]} {		scan $var {%[a-zA-Z0-9/_]::%[a-zA-Z0-9/_]} class var	} else {		if {[string match CW* $var] || [string match S* $var] || [string match MinimumBandwidth_ $var]} {			set class PHY_MIB		}		if {[string match RTSThreshold_ $var] || [string match *RetryLimit_ $var]} {			set class MAC_MIB		}		if {[string match *levels_ $var]} {			set class PLevels		}		if {[string match bandwidth_ $var]} {			set class Mac/802_11		}		if {[string match CPThresh_ $var] || [string match per_ $var]} {			set class Phy/WirelessPhy		}	}	scan $value {%[a-zA-Z0-9_.],%[a-zA-Z0-9_.,]} value tail	if {[info exists tail]} {		for {set n 0} {[info exists tail]} {incr n} {			set var_n [format "%s_%d" $var $n]			if {[info exists class]} {				puts "% $class set $var_n $value"				$class set $var_n $value			} else {				puts "% set $var_n $value"				set $var_n $value			}			set value $tail			unset tail			scan $value {%[a-zA-Z0-9_.],%[a-zA-Z0-9_.,]} value tail		}		set var_n [format "%s_%d" $var $n]		if {[info exists class]} {			puts "% $class set $var_n $value"			$class set $var_n $value		} else {			puts "% set $var_n $value"			set $var_n $value		}		unset var_n	} else {		if {[info exists class]} {			puts "% $class set $var $value"			$class set $var $value		} else {			if {$var == "phy"} {				if {$value == "11b"} {					puts "% setting PHY parameters to 802.11b"					Mac/802_11 set bandwidth_	11Mb					PHY_MIB set MinimumBandwidth_	1Mb					PHY_MIB set SlotTime_		0.000020					PHY_MIB set SIFS_		0.000010					PHY_MIB set CWMin_0		31				} elseif {$value != "11a"} {					puts stderr "BAD ARGUMENTS to main.tcl!!"					exit 1;				}			} else {				puts "% set $var $value"				set $var $value			}		}	}	if {[info exists class]} {		unset class	}	unset var value}############################################################################################ Setup other varsputs "Creating $num_nodes nodes"# cookie appended to scenario name for filenames that are createdif {[info exists cookie]} {	set outfile_ $scenario.$cookie} else {	set outfile_ $scenario}# num_bss_nodes describes the number of nodes in the BSS; the# remaining nodes are ADHOC; default: all nodes are in the BSSif {![info exists num_bss_nodes]} {	set num_bss_nodes $num_nodes}############################################################################################ Primary simulation objectsset ns_		[new Simulator]$ns_ use-newtraceset tracefd	[open $outfile_.tr w]$ns_ trace-all $tracefd# set namtrace	[open $outfile_.nam w]# $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)# set up topography objectset topo       [new Topography]$topo load_flatgrid $val(x) $val(y)# Create Godcreate-god $num_nodes############################################################################################ Generic WLAN simulation objects# Create channel #1set chan_1_ [new $val(chan)]# Configure nodes to be "attached" to channel #1$ns_ node-config -adhocRouting $val(rp) \		 -llType $val(ll) \		 -macType $val(mac) \		 -ifqType $val(ifq) \		 -ifqLen $val(ifqlen) \		 -antType $val(ant) \		 -propType $val(prop) \		 -phyType $val(netif) \		 -topoInstance $topo \		 -agentTrace ON \		 -routerTrace ON \		 -macTrace ON \		 -movementTrace OFF \		 -channel $chan_1_ # Create nodes with IFQ send tracing enabled,# random motion disabledfor {set i 0} {$i < $num_nodes} {incr i} {	set node_($i) [$ns_ node]	$node_($i) add-ifq-send-trace	$node_($i) random-motion 0	# set initial position for NAM	$ns_ initial_node_pos $node_($i) 20	# Provide initial (X,Y, for now Z=0) co-ordinates	set diff [expr ($i + 1) / 2]	if {[expr $i % 2] == 0} {		set diff [expr -$diff]	}	$node_($i) set X_ [expr $num_nodes + $diff]	$node_($i) set Y_ [expr $num_nodes + $diff]	$node_($i) set Z_ 0.0}# make node_(0) the AP for nodes in BSSset AP_ $node_(0)set AP_MAC [$AP_ getMacAddr]for {set i 0} {$i < $num_bss_nodes} {incr i} {	$node_($i) setMac bss_id $AP_MAC}############################################################################################ Scenario specific simulation objects (agents etc.)create_scenario############################################################################################ Modifications to the mac and/or other stuff dictated by the scenario!for {set i 0} {$i < $num_nodes} {incr i} {	if {$idea_mac} {		$node_($i) setMac IdeaMac $idea_mac		puts "% node_($i) setMac IdeaMac $idea_mac"	}	for {set p 0} {$p < [PLevels set plevels_]} {incr p} {		set difs_p [format "difs_%d" $p]		if {[info exists $difs_p]} {			set v [set $difs_p]			$node_($i) setMac difs $p $v			puts "% node_($i) setMac difs $p $v"		}	}	if {$mode == "PCF"} {		$node_($i) CFP $pcf_period $pcf_duration		if {$i == 0} {			puts "% node_($i) CFP $pcf_period $pcf_duration"		}	}}if {$title_ != ""} {	set titlefd [open $outfile_.title w]	puts $titlefd "$title_"	close $titlefd}# to set a different CWMin for a particular node# priority level parameter is optional (0 by default)# use same method for CWMax/CWOffset/difs also# for difs: to increase/decrease by n, say +2 slots# $node_($i) setMac CWMin [priority level] 15# to set number of priority levels supported on a paricular node# $node_($i) setPLevels 4############################################################################################ End of simulation conditions/operationsfor {set i 0} {$i < $num_nodes } {incr i} {    $ns_ at $endtime "$node_($i) reset";}$ns_ at $endtime "do_stop"set delta 0.01set endtime [expr $endtime + $delta]$ns_ at $endtime "do_halt"proc do_stop {} {	global ns_ tracefd	$ns_ flush-trace	close $tracefd}proc do_halt {} {	global ns_	puts "NS EXITING..."	$ns_ halt}############################################################################################ Start up the simulationputs "Starting Simulation..."$ns_ run

⌨️ 快捷键说明

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