Tcl script to create dynamic wirless nodes,set initial postion,and set color of node with AODV.


      In this program used to generate the nodes only; there is no any other connection between the nodes. After creating the nam file and trace file, we set up topography object. The main thing of the program is how much node you has to give that much node only will create. Otherwise it will cause error. Here nodes have color. Set node_ ($i) [$ns node] is used to create the nodes. Here we set the initial position for the every node by using initial_node_pos. After that $Val (stop) is used to tell to nodes when the simulation ends.

File name: “wireless3.tcl”

if {$argc != 1} {
       error “\nCommand: ns wireless3.tcl <>\n\n ”

#——-Event scheduler object creation——–#

set ns [new Simulator]

#creating the trace file and nam file

set tracefd [open w]
set namtrace [open wireless3.nam w]   

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

set god_ [create-god $val(nn)]

# 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

## Creating node objects..               
      for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]     
      for {set i 0} {$i < $val(nn) } {incr i } {
            $node_($i) color gold
            $ns at 0.0 “$node_($i) color gold”
## Provide initial location of mobilenodes..
            for {set i 0} {$i < $val(nn) } { incr i } {
                  set xx [expr rand()*600]
                  set yy [expr rand()*600]
                  $node_($i) set X_ $xx
                  $node_($i) set Y_ $yy
# 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 10.01 “puts \”end simulation\” ; $ns halt”

#stop procedure…
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
exec nam wireless3.nam &

$ns run

# How to run the program

$ns wireless3.tcl

# snapshot of the program output

Enjoy 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s