Documente Academic
Documente Profesional
Documente Cultură
#------------------------Environmental Settings-----------------
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Node
Deploy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
proc mobility { tm } {
global node_ ns_
$ns_ at $tm "$node_(1) setdest [expr (rand()*50)+020.889 ] [expr
(rand()*50)+1055.421] [expr rand()*10]"
$ns_ at $tm "$node_(2) setdest [expr (rand()*50)+230.526 ] [expr
(rand()*50)+1055.723] [expr rand()*10]"
$ns_ at $tm "$node_(3) setdest [expr (rand()*50)+450.681 ] [expr
(rand()*50)+1055.145] [expr rand()*10]"
$ns_ at $tm "$node_(4) setdest [expr (rand()*50)+680.131 ] [expr
(rand()*50)+1055.195] [expr rand()*10]"
$ns_ at $tm "$node_(5) setdest [expr (rand()*50)+920.770 ] [expr
(rand()*50)+1055.176] [expr rand()*10]"
$ns_ at $tm "$node_(6) setdest [expr (rand()*50)+1170.252] [expr
(rand()*50)+1055.490] [expr rand()*10]"
proc nnode { } {
global node_ ns_
set r [open "NNode.tr" w]
puts $r
"----------------------------------------------------------"
puts $r "Node\t\tNeighbors\tx-cor\ty-cor \tDistance"
puts $r
"----------------------------------------------------------"
for { set i 0 } { $i <51 } { incr i } {
set x1 [$node_($i) set X_]
set y1 [$node_($i) set Y_]
for { set j 0 } { $j <51 }
{ incr j } {
set x2 [$node_($j) set X_]
set y2 [$node_($j) set Y_]
set dis [expr sqrt(pow([expr $x2 -
$x1],2)+pow([expr $y2 - $y1],2))]
if { $dis <251 && $i!= $j } {
set x2 [expr int($x1)] ; set y2
[expr int($y1)]
puts $r "$i\t\t
$j\t\t$x2\t$y2\t$dis" } }
}
close $r
}
#--------------- Input File for Broadcast ----------------
proc finish {} {
global ns_ namtrace
$ns_ flush-trace
close $namtrace
exec nam -r 8m Nam.nam &
exit 0
}
#------------------------Environmental Settings-----------------
#----------------------------- Node
Creation---------------------------
proc mobility { tm } {
global node_ ns_ sink dp
set min49 250
set min50 250
set x49 [$node_(49) set X_]
set y49 [$node_(49) set Y_]
set tm 2.0
proc finish {} {
global ns_ namtrace
$ns_ flush-trace
close $namtrace
global pr tp dp
close $pr ; close $tp ; close $dp
exec nam -r 8m Nam.nam &
exec xgraph Ex_PDR.xg -t "Packet delivary Ratio" -x "Time"
-y "PDR" &
exec xgraph Ex_Throughput.xg -t "Throughput" -x "Time"
-y "Throughput" &
exec xgraph Ex_Drop.xg -t "Drop" -x "Time" -y "Drop" &
exit 0
}
#----------------------------- Node
Creation---------------------------
if { $sv==0} {
$ns_ at 0.05 "$node_(49) setdest [expr rand()*500] 142.805
805.852890202170"
$ns_ at 0.05 "$node_(50) setdest [expr rand()*950] 141.098
810.961861003206"
}
if { $sv==1 } {
set x1 837
$ns_ at 0.05 "$node_(49) setdest $x1 1000.805
805.852890202170"
$ns_ at 0.05 "$node_(50) setdest [expr $x1+225] 1000.098
810.961861003206"
}
set avs 0
set posb 0
proc mobility { tm } {
if { $dist>300 } {
if { $sv==0 } {
set gp [expr $tm % 5]
if { $gp == 0 } { puts $dp "$tm 0" }
$ns_ at [expr $tm+0.00035] "$ns_ trace-annotate \"Node -
$nnod50 Sends the Sensed data about 50th node(OBJECT) Arraival to
the Base station - 0 but the Replica is recevied data and inject
false data to Base station-0 \""
}
if { $sv==1 } {
set gp [expr $tm % 5] ; set we [expr int(rand()*5)]
if { $gp == 0 } { puts $dp "$tm $we" }
$ns_ at [expr $tm+0.00035] "$ns_ trace-annotate \"Node -
$nnod50 Sends the Sensed data about 50th node(OBJECT) Arraival to
the Base station - 0 but the Replica is recevied data and Droped
All datas \""
}
proc nnode { nm } {
global node_ ns_
set r [open "NNode.tr" w]
puts $r
"----------------------------------------------------------"
puts $r "Node\t\tNeighbors\tx-cor\ty-cor \tDistance"
puts $r
"----------------------------------------------------------"
for { set i 0 } { $i <$nm } { incr i } {
set x1 [$node_($i) set X_]
set y1 [$node_($i) set Y_]
for { set j 0 } { $j <$nm }
{ incr j } {
set x2 [$node_($j) set X_]
set y2 [$node_($j) set Y_]
set dis [expr sqrt(pow([expr $x2 -
$x1],2)+pow([expr $y2 - $y1],2))]
if { $dis <251 && $i!= $j } {
set x2 [expr int($x1)] ; set y2
[expr int($y1)]
puts $r "$i\t\t
$j\t\t$x2\t$y2\t$dis" } }
}
close $r
}
proc finish {} {
global ns_ namtrace posb
global pr tp dp
close $pr ; close $tp ; close $dp
if { $posb==0 } { puts "\n\n Goto Terminate !!!\n
Run Again \n\n" ; exit 0 }
$ns_ flush-trace
close $namtrace
exec nam -r 8m Nam.nam &
exec xgraph PDR.xg -t "Packet delivary Ratio" -x "Time" -y
"PDR" &
exec xgraph Throughput.xg -t "Throughput" -x "Time" -y
"Throughput" &
exec xgraph Ex_Drop.xg Drop.xg -t "Drop" -x "Time" -ly 0,15
-y "Drop" &
exit 0
}