#my code is
# Our aim is to make a real time application
# 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) 4 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 300 ;# X dimension of topography
set val(y) 200 ;# Y dimension of topography
set val(stop) 10 ;# time of simulation end
set ns [new Simulator]
set tracefd [open simple-dsdv.tr w]
#set windowVsTime2 [open win.tr w]
set namtrace [open simwrls.nam w]
$ns trace-all $tracefd
$ns use-newtrace
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#
# configure the nodes
$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) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
# for source node
set node_(0) [$ns node]
$node_(0) set X_ 100.0
$node_(0) set Y_ 100.0
$node_(0) set Z_ 0.0
# for new nodes
for {set i 1} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}
# for random placement
for {set i 1} {$i < $val(nn)} {incr i} {
set xi($i) [expr rand()*$val(x)]
set yi($i) [expr rand()*$val(y)]
$node_($i) set X_ $xi($i)
$node_($i) set Y_ $yi($i)
$node_($i) set Z_ 0
#puts "Initial Position = $xi($i)"
}
# for random movement
for {set i 1} {$i < $val(nn)} {incr i} {
set xf($i) [expr rand()*$val(x)]
set yf($i) [expr rand()*$val(y)]
set t($i) [expr rand()*($val(stop)-1)]
$ns at $t($i) "$node_($i) setdest $xf($i) $yf($i) 5.0"
#puts "final position = $xf($i)"
puts "time = $t($i)"
}
for {set i 0} {$i < $val(stop)} {incr i} { # for time from 0
for {set j 1} {$j < $val(nn)} {incr j} { # for every node/time
#puts "xi($j)= $xi($j)"
#puts "xf($j)= $xf($j)"
#puts "t($j)= $t($j)"
if { $i <= $t($j) && ($i+1) > $t($j) } {
puts "for loop no : $i"
puts "OK $j $xi($j) $xf($j) $yi($j) $yf($j) $t($j)"
#calculating angle of each node
set sl1 [expr {$xf($j)-$xi($j)}]
set sl2 [expr {$yf($j)-$yi($j)}]
set sf [expr {$sl2/$sl1} ]
set sloper($j) [expr {atan($sf)}]
set sloped($j) [expr {$sloper($j)*57.324}]
puts "the angle of direction node $j is : $sloped($j)"
#comparing the movement of node with the source node
# Distance between 2 nodes in initial
set dxi [expr 100.0 - $xi($j)]
set dyi [expr 100.0 - $yi($j)]
set dxi2 [expr $dxi * $dxi]
set dyi2 [expr $dyi * $dyi]
set hi2 [expr $dxi2 + $dyi2]
set hi(0-1) [expr pow($hi2, 0.5)]
puts "$hi(0-1)"
# Distance between 2 nodes in final
set dxf [expr 100.0 - $xf($j)]
set dyf [expr 100.0 - $yf($j)]
set dxf2 [expr $dxf * $dxf]
set dyf2 [expr $dyf * $dyf]
set hf2 [expr $dxf2 + $dyf2]
set hf(0-1) [expr pow($hf2, 0.5)]
puts "$hf(0-1)"
}
}
}
# Set a TCP connection between node_(0) and node_(3)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(3) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 1 "$ftp start"
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";
}
# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts "end simulation" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam simwrls.nam &
}
$ns run
result is :---
i am getting different angle for different node and i am able to know which node is going far and which will come near in future but the problem is that how to calculate and remove the far going nodes from the path in aodv