Professional Documents
Culture Documents
Vanet TCL
Vanet TCL
;# ;# ;# ;# ;#
RXThresh_ 1.0e-12 bandwidth_ 6.0e6 Pt_ 0.0003754 freq_ 5.9e+9 L_ 1.0 set set set
set pathlossExp_ std_db_ seed_ dist0_ 2.7 4.0 0 1.0
;# -90 dBm
# perform clean up at the end of the program proc finish {} { global ns_ tracefd
namtracefd opt $ns_ flush-trace close $tracefd if {$opt(nam_tr) != ""} { close
$namtracefd } $ns_ halt exit 0 } # set the options from the command line arguments
proc getopt {argc argv} { global opt lappend optlist cp nn seed sc stop tr x y
bc_size nam_tr cw 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]] } } # log the movement of a node every 0.1
seconds proc log-movement {} { global logtimer ns_ ns set ns $ns_ source
../tcl/mobility/timer.tcl Class LogTimer -superclass Timer LogTimer instproc
timeout {} { global opt node_; for {set i 0} {$i < $opt(nn)} {incr i} { $node_($i)
log-movement } $self sched 0.1 } set logtimer [new LogTimer] $logtimer sched 0.1
#get command line arguments getopt $argc $argv Mac/802_11 set CWMin_ $opt(cw) puts
"x: $opt(x), y: $opt(y)" puts "CW: $opt(cw)" if {$opt(seed) > 0} { puts "Seeding
Random number generator with $opt(seed)\n" ns-random $opt(seed) } # create a new
simulator set ns_ [new Simulator] # set up the traces set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd # set the topology set topo [new Topography] $topo
load_flatgrid $opt(x) $opt(y) set god_ [ create-god $opt(nn) ] set chan_ [new
Channel/WirelessChannel]
# Set up the nam trace if desired. if {$opt(nam_tr) != ""} { set namtracefd [open
$opt(nam_tr) w] $ns_ namtrace-all-wireless $namtracefd $opt(x) $opt(y) } #
configure the nodes of the simulation $ns_ node-config -adhocRouting $opt(rp) \
-llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \
-antType $opt(ant) \ -propInstance [new $opt(prop)] \ -phyType $opt(netif) \
-topoInstance $topo \ -channel $chan_ \ -agentTrace $opt(at) \ -routerTrace
$opt(rt) \ -macTrace $opt(mact) \ -movementTrace $opt(movt) set y 0 set x 0 #
Create the mobile nodes for the simulation. for {set i 0} {$i < $opt(nn)} {incr i}
{ set node_($i) [$ns_ node] $ns_ initial_node_pos $node_($i) 10 } # Source the
mobility scenario file. source $opt(sc) # Attach a new
Agent/MessagePassing/PeriodicBroadcast to each node on port $MESSAGE_PORT for {set
i 0} {$i < $opt(nn)} {incr i} { set bc_agent($i) [new
Agent/MessagePassing/PeriodicBroadcast] $node_($i) attach $bc_agent($i)
$MESSAGE_PORT } # log movement if { $opt(lm) == "ON" } { puts "Logging movement..."
log-movement }
# Source the file that contains the broadcast traffic. source $opt(cp) $ns_ at
$opt(stop) "finish" # Add to the trace simulation parameters. puts $tracefd "M 0.0
nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)" #puts $tracefd "M 0.0 cp $opt(cp) seed
$opt(seed)"
puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)" puts "Starting Simulation..."
$ns_ run