
import queue
import queue import time q = queue.Queue() def task(n): print("Task", n, "Running") time.sleep(1) print("Task", n, "Completed") for i i
import queue
import time
q = queue.Queue()
def task(n):
print("Task", n, "Running")
time.sleep(1)
print("Task", n, "Completed")
for i in range(1, 4):
q.put(i)
print("TinyOS Started")
while not q.empty():
task(q.get())
print("All Tasks Completed")
#2 tossim
import time
print("TOSSIM Started")
for i in range(1, 6):
print("Mote", i, "Booted")
print("Timer Fired - LED ON")
time.sleep(1)
print("Timer Fired - LED OFF")
print("Simulation Completed")
#7 Practical: AODV Routing Protocol Simulation using NS2
Ns
Nam
cd ~/Desktop
nano aodv_sim.tcl
tcl
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all-wireless $nf 500 500
set topo [new Topography]
$topo load_flatgrid 500 500
create-god 3
$ns node-config -adhocRouting AODV \
-llType LL -macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-topoInstance $topo
for {set i 0} {$i<3} {incr i} {
set n($i) [$ns node]
}
$n(0) set X_ 50
$n(0) set Y_ 100
$n(1) set X_ 250
$n(1) set Y_ 100
$n(2) set X_ 450
$n(2) set Y_ 100
set udp [new Agent/UDP]
set null [new Agent/Null]
$ns attach-agent $n(0) $udp
$ns attach-agent $n(2) $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$ns at 1.0 "$cbr start"
$ns at 10.0 "$cbr stop"
$ns at 11.0 "finish"
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
$ns run
nano aodv.tcl
nam aodv_sim.nam
Practical8 : DSR Routing Protocol Simulation using NS2
set ns [new Simulator]
set f [open dsr.nam w]
$ns namtrace-all-wireless $f 500 500
set t [new Topography]
$t load_flatgrid 500 500
create-god 2
$ns node-config -adhocRouting DSR \
-llType LL -macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-topoInstance $t
set a [$ns node]
set b [$ns node]
set u [new Agent/UDP]
set n [new Agent/Null]
$ns attach-agent $a $u
$ns attach-agent $b $n
$ns connect $u $n
set c [new Application/Traffic/CBR]
$c attach-agent $u
$ns at 1 "$c start"
$ns at 5 "$c stop"
$ns at 6 "finish"
proc finish {} {
global ns f
$ns flush-trace
close $f
exec nam dsr.nam &
exit 0
}
$ns run
ns dsr.tcl


