Sei sulla pagina 1di 7

A.1 Sample Scenario Code written in TCL script language. ###scenario:100sensorfield5x100.

tcl ####Author:Antonis Antoniou # Define options #======= set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(ifq) Queue/DropTail/PriQueue ;# interface queue type set val(ll) LL ;# link layer type set val(ant) Antenna/OmniAntenna ;# antenna model set val(ifqlen) 50 ;# max packet in ifq set val(nn) 100 ;# number of mobilenodes set val(rp) StaticRT ;# routing protocol set val(x) 500 ;# X dimension of topography set val(y) 500 ;# Y dimension of topography set val(finish) 40 ;# time of simulation end # ====================================================================== # Main Program

# ====================================================================== # Initialize Global Variables set ns [new Simulator] Antenna/OmniAntenna set X_ 0 Antenna/OmniAntenna set Y_ 0 Antenna/OmniAntenna set Z_ 1.5 Antenna/OmniAntenna set Gt_ 1.0 Antenna/OmniAntenna set Gr_ 1.0 Phy/WirelessPhy set CPThresh_ 10.0 Phy/WirelessPhy set CSThresh_ 2.13643e-07 # INTERFERENCE DISTANCE KAI COMMUNICATION DISTANCE ARE SAME ### distance 30m Phy/WirelessPhy set RXThresh_ 2.13643e-07 ### distance 30m Phy/WirelessPhy set bandwidth_ 2e6 Phy/WirelessPhy set Pt_ 0.28183815 Phy/WirelessPhy set freq_ 914e+6 Phy/WirelessPhy set L_ 1.0 Mac/802_11 set dataRate_ 2Mb # Enable RTS Mac/802_11 set RTSThreshold_ 0 ## RTS/CTS is Enabled ############Mac/802_11 set CWMin_ 256 ;# These parameters are setup for cw ###########Mac/802_11 set CWMax_ 1023 set tracefd [open 100sensorfield5x100.tr w] ###tracedile for this scenario set log [open output2.tr w] set f1 [open received.tr w] set f2 [open lost.tr w] set namtrace [open out2.nam w] $ns trace-all $tracefd $ns use-newtrace $ns namtrace-all-wireless $namtrace $val(x) $val(y) # Define a 'finish' procedure proc finish {} { global ns tracefd log namtrace f1 f2 $ns flush-trace close $tracefd close $namtrace 2

close $f1 close $f2 close $log exec nam out2.nam & ####animate results on mam } # Set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # Create God create-god $val(nn) #Create channel set channel1_ [new $val(chan)] # Create the specified number of mobilenodes [$val(nn)] and "attach" them to #the channel. # Here two nodes are created : node_(0) and node_(2) # Configure nodes according to scenario.... $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) \ -channel $channel1_ \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace ON \ -movementTrace OFF \ -energyModel EnergyModel \ -idlePower 0.2 \ -rxPower 1.0 \ -txPower 2.0 \ 3

-sleepPower 0.00 \ -initialEnergy 1000 # Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes #=================================== # - Node # creating nodes #=================================== set node_(0) [$ns node] $node_(0) set X_ 233 $node_(0) set Y_ 247 $node_(0) set Z_ 0.0 $ns initial_node_pos $node_(0) 20 set node_(1) [$ns node] $node_(1) set X_ 233 $node_(1) set Y_ 227 $node_(1) set Z_ 0.0 $ns initial_node_pos $node_(1) 20 .. .. set node_(99) [$ns node] $node_(99) set X_ 413 $node_(99) set Y_ 67 $node_(99) set Z_ 0.0 $ns initial_node_pos $node_(99) 20 # Setup traffic flow between nodes # UDP connections between nodes 0,1,10,20,2 and node_(45) #=================================== # TRAFFIC #=================================== (CBR-UDP) set udp0 [new Agent/UDP] $ns attach-agent $node_(0) $udp0 set null0 [new Agent/Null] $ns attach-agent $node_(45) $null0 4

$ns connect $udp0 $null0 $udp0 set fid_ 0 set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 $cbr0 set type_ CBR $udp0 set packetSize_ 120 $cbr0 set packet_size_ 100 $cbr0 set rate_ 100Kb ##$cbr0 set random_ false $ns at 10.0 "$cbr0 start" $ns at 20.0 "$cbr0 stop" (CBR-UDP) set udp1 [new Agent/UDP] $ns attach-agent $node_(10) $udp1 $ns connect $udp1 $null0 $udp1 set fid_ 1 set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent $udp1 $cbr1 set type_ CBR $udp1 set packetSize_ 120 $cbr1 set packet_size_ 100 ###packet size $cbr1 set rate_ 100Kb ##$cbr1 set random_ false $ns at 10.0 "$cbr1 start" ###trafffic starting time $ns at 20.0 "$cbr1 stop" ###traffic stop (CBR-UDP) set udp2 [new Agent/UDP] $ns attach-agent $node_(1) $udp2 $ns connect $udp2 $null0 $udp2 set fid_ 2 set cbr2 [new Application/Traffic/CBR] $cbr2 attach-agent $udp2 $cbr2 set type_ CBR $udp2 set packetSize_ 120 $cbr2 set packet_size_ 100 $cbr2 set rate_ 100Kb ##$cbr2 set random_ false $ns at 10.0 "$cbr2 start" $ns at 20.0 "$cbr2 stop" 5

(CBR-UDP) set udp4 [new Agent/UDP] $ns attach-agent $node_(20) $udp4 $ns connect $udp4 $null0 $udp4 set fid_ 4 set cbr4 [new Application/Traffic/CBR] $cbr4 attach-agent $udp4 $cbr4 set type_ CBR $udp4 set packetSize_ 120 $cbr4 set packet_size_ 100 $cbr4 set rate_ 100Kb ##$cbr4 set random_ false $ns at 10.0 "$cbr4 start" $ns at 20.0 "$cbr4 stop" (CBR-UDP) set udp5 [new Agent/UDP] $ns attach-agent $node_(2) $udp5 $ns connect $udp5 $null0 $udp5 set fid_ 5 set cbr5 [new Application/Traffic/CBR] $cbr5 attach-agent $udp5 $cbr5 set type_ CBR $udp5 set packetSize_ 120 $cbr5 set packet_size_ 100 $cbr5 set rate_ 100Kb ##$cbr4 set random_ false $ns at 10.0 "$cbr5 start" $ns at 20.0 "$cbr5 stop" #=================================== # #=================================== # Define node initial position in nam # Telling nodes when the simulation ends for {set i 0 } {$i < $val(nn) } {incr i} { $ns at $val(finish) "$node_($i) reset"; } # Ending nam and the simulation 6

$ns at $val(finish) "$ns nam-end-wireless $val(finish)" $ns at $val(finish) "finish" $ns at 40.01 "puts \"ns EXITING...\" ; $ns halt" puts "Starting Simulation..." $ns run

Potrebbero piacerti anche