📄 run.tcl
字号:
# ======================================================================# Default Script Options# ======================================================================set opt(chan) Channelset opt(prop) Propagation/TwoRayGroundset opt(netif) NetIf/SharedMediaset opt(mac) Mac/802_11set opt(ifq) Queue/DropTail/PriQueueset opt(ll) LLset opt(ant) Antenna/OmniAntennaset opt(x) 0 ;# X dimension of the topographyset opt(y) 0 ;# Y dimension of the topographyset opt(cp) "" ;# connection pattern fileset opt(sc) "" ;# scenario fileset opt(progress) 4 ;# how many progress markers to showset opt(ifqlen) 50 ;# max packet in ifqset opt(nn) 50 ;# number of nodesset opt(seed) 0.0set opt(stop) 900.0 ;# simulation timeset opt(tr) out.tr ;# trace fileset opt(rp) "" ;# routing protocol scriptset opt(lm) "off" ;# log movementset opt(imep) "OFF"set opt(debug) "OFF"# ======================================================================set AgentTrace ONset RouterTrace ONset MacTrace OFFLL set mindelay_ 50usLL set delay_ 25usLL set bandwidth_ 0 ;# not usedLL set off_prune_ 0 ;# not usedLL set off_CtrMcast_ 0 ;# not usedAgent/Null set sport_ 0Agent/Null set dport_ 0Agent/CBR set sport_ 0Agent/CBR set dport_ 0Agent/TCPSink set sport_ 0Agent/TCPSink set dport_ 0Agent/TCP set sport_ 0Agent/TCP set dport_ 0Agent/TCP set packetSize_ 1460Agent/IMEP set sport_ 0Agent/IMEP set dport_ 0Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1# unity gain, omni-directional antennas# set up the antennas to be centered in the node and 1.5 meters above itAntenna/OmniAntenna set X_ 0Antenna/OmniAntenna set Y_ 0Antenna/OmniAntenna set Z_ 1.5Antenna/OmniAntenna set Gt_ 1.0Antenna/OmniAntenna set Gr_ 1.0# Initialize the SharedMedia interface with parameters to make# it work like the 914MHz Lucent WaveLAN DSSS radio interfaceNetIf/SharedMedia set CPThresh_ 10.0NetIf/SharedMedia set CSThresh_ 1.559e-11NetIf/SharedMedia set RXThresh_ 3.652e-10NetIf/SharedMedia set Rb_ 2*1e6NetIf/SharedMedia set Pt_ 0.2818NetIf/SharedMedia set freq_ 914e+6 NetIf/SharedMedia set L_ 1.0# ======================================================================proc usage { argv0 } { puts "Usage: $argv0" puts "\tmandatory arguments:" puts "\t\t\[-sc scenariofile\]" puts "\tmandatory, but may be set by scenario file:" puts "\t\t\[-x MAXX\] \[-y MAXY\]" puts "\toptional arguments (defaults provided by run.tcl):" puts "\t\t\[-cp conn pattern\] \[-nn nodes\] \[-rp routing-protocol-script\]" puts "\t\t\[-seed seed\] \[-stop sec\] \[-tr output-tracefile\]\n"}proc getopt {argc argv} { global opt lappend optlist cp nn seed sc stop tr x y for {set i 0} {$i < $argc} {incr i} { set arg [lindex $argv $i] if {[string range $arg 0 0] != "-"} continue set name [string range $arg 1 end] set opt($name) [lindex $argv [expr $i+1]] }}proc cmu-trace { ttype atype node } { global ns_ tracefd if { $tracefd == "" } { return "" } set T [new CMUTrace/$ttype $atype] $T target [$ns_ set nullAgent_] $T attach $tracefd $T set src_ [$node id] $T node $node return $T}proc create-god { nodes } { global ns_ god_ tracefd set god_ [new God] $god_ num_nodes $nodes}proc log-movement {} { global logtimer ns_ ns set ns $ns_ source tcl/ex/timer.tcl Class LogTimer -superclass Timer LogTimer instproc timeout {} { global opt node_; for {set i 1} {$i <= $opt(nn)} {incr i} { $node_($i) log-movement } $self sched 0.1 } set logtimer [new LogTimer] $logtimer sched 0.1}# ======================================================================# Main Program# ======================================================================getopt $argc $argv## Source External TCL Scripts#source cmu/scripts/mobile_node.tclif { $opt(rp) != "" } { source $opt(rp)} elseif { [catch { set env(NS_PROTO_SCRIPT) } ] == 1 } { puts "\nenvironment variable NS_PROTO_SCRIPT not set and no -rp option provided!\n" usage $argv0 exit 1} else { puts "\n*** using script $env(NS_PROTO_SCRIPT)\n\n"; source $env(NS_PROTO_SCRIPT)}source cmu/scripts/cmu-trace.tcl# read through the scenario file to see if it sets any optionsif { $opt(sc) == "" } { puts "\nNo scenario file specified with -sc option" usage $argv0 exit 1}set f [open $opt(sc) r]set r1 {^# nodes: *([0-9]+).*time: *([0-9]+\.[0-9]+).*x: *([0-9]+\.[0-9]+).*y: *([0-9]+\.[0-9]+)}set r2 {^#}while {[gets $f line] >= 0} { if {[regexp $r2 $line]} { regexp $r1 $line junk opt(nn) opt(stop) opt(x) opt(y) } else { break }}close $f# do the getopt again in case the routing protocol file added some more# options to look for, or the user wants to override options set by the# scenario filegetopt $argc $argvif { $opt(x) == 0 || $opt(y) == 0 } { usage $argv0 exit 1}if {$opt(seed) > 0} { puts "Seeding Random number generator with $opt(seed)\n" ns-random $opt(seed)}## Initialize Global Variables#set ns_ [new Simulator]set chan [new $opt(chan)]set prop [new $opt(prop)]set topo [new Topography]set tracefd [open $opt(tr) w]for {set i 1} {$i <= $opt(progress)} {incr i} { set t [expr $i * $opt(stop) / ($opt(progress) + 1)] $ns_ at $t "puts \"completed through $t secs...\""}$topo load_flatgrid $opt(x) $opt(y)$prop topography $topo## Create God#create-god $opt(nn)## log the mobile nodes movements if desired#if { $opt(lm) == "on" } { log-movement}## Create the specified number of nodes $opt(nn) and "attach" them# the channel.# Each routing protocol script is expected to have defined a proc# create-mobile-node that builds a mobile node and inserts it into the# array global $node_($i)#for {set i 1} {$i <= $opt(nn) } {incr i} { create-mobile-node $i}## Source the Connection and Movement scripts#if { $opt(cp) == "" } { puts "*** NOTE: no connection pattern specified." set opt(cp) "none"} else { source $opt(cp)}## Tell all the nodes when the simulation ends#for {set i 1} {$i <= $opt(nn) } {incr i} { $ns_ at $opt(stop).000000001 "$node_($i) reset";}$ns_ at $opt(stop).00000001 "puts \"NS EXITING...\" ; $ns_ halt"if { $opt(sc) == "" } { puts "*** NOTE: no scenario file specified." set opt(sc) "none"} else { puts "Loading scenario file..." source $opt(sc) puts "Load complete..."}puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)"puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"puts "Starting Simulation..."$ns_ run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -