How to a create dynamic wireless network using NS2 simulator


The dynamic wireless network in ns2 can be modeled using rand function in Tool Command Language (TCL) script. The number of nodes in the network varies dynamically during the runtime. The dynamic wireless network allocates the dynamic location for each node. The sample3.tcl file shows the dynamic network with dynamic number of nodes specified during the execution that are deployed in the area of 500m  500m

#Filename: sample3.tcl

#***************Dynamic Wireless network **********************#

#******************Random Topology Creation********************#

#Run Time Argument

if {$argc != 1} {
error "\nCommand: ns sample3.tcl <no.of.nodes>\n\n "
set val(nn) [lindex $argv 0] ;# number of mobilenodes
#Random Location for nodes

for {set i 0} {$i < $val(nn)} {incr i} {

$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0