Version 0 of node

Updated 2018-03-06 16:17:35 by rahul

# Define options set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(ant) Antenna/OmniAntenna ;# Antenna type set val(ll) LL ;# Link layer type set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type set val(ifqlen) 50 ;# max packet in ifq set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ; # MAC type set val(rp) DSDV ;# ad-hoc routing protocol set val (nn) 4 ;# number of mobile nodes set val(x) 500 ;# X dimension of the topography set val(y) 400 ;# Y dimension of the topography set val(stop) 150 ;# simulation time set ns new Simulator set tracefd open wireless1-out.tr w ;# for wireless traces $ns trace-all $tracefd set namtrace open wireless1-out.nam w ;# for nam tracing $ns namtrace-all-wireless $namtrace $val(x) $val(y) set topo new Topography $topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# Configure 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) \ -topoInstance $topo \ -channelType $val(chan) \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF

# Create mobile nodes

for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) $ns node $node_($i) random-motion 0 ;# disable random motion }

# Provide initial (X,Y, for now Z=0) co-ordinates for node_(0), node_(1),node(2) and node(3) $node_(0) set X_ 5.0 $node_(0) set Y_ 5.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 490.0 $node_(1) set Y_ 285.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 150.0 $node_(2) set Y_ 240.0 $node_(2) set Z_ 0.0 $node_(3) set X_ 200.0 $node_(3) set Y_ 150.0 $node_(3) set Z_ 0.0

# Node_(0) starts to move towards point 250,250 $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0" # Node_(1) starts to move towards point 45,285 $ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0" # Node_(0) starts to move towards point 480,300 $ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# TCP connections between node_(0) and node_(1) set tcp new Agent/TCP $tcp set class_ 2 set sink new Agent/TCPSink $ns attach-agent $node_(0) $tcp $ns attach-agent $node_(1) $sink $ns connect $tcp $sink set ftp new Application/FTP $ftp attach-agent $tcp $ns at 10.0 "$ftp start"

# Define node initial position in nam for {set i 0} {$i < $val(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario size. # The function must be called after mobility model is defined $ns initial_node_pos $node_($i) 20 } # Tell nodes when the simulation ends # for {set i 0} {$i < $val(nn) } {incr i} { $ns at 150.0 "$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.0002 "puts \"NS EXITING...\" ; $ns halt" proc stop {} { global ns tracefd namtrace close $tracefd close $namtrace exec nam wireless1-out.nam & } puts "Starting Simulation..." $ns run