Wireless Tcl Scripts

112
Tcl script to create fixed wirless nodes with AODV. Description: This network consists of 3 nodes. In this program we generate nodes only; there is no any other connection between the nodes. After creating than am file and trace file, we set up topography object. 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. The end nam and end simulation at 10.0 sec. AODV routing protocol were used here. File name: “wireless1.tcl” #-------Event scheduler object creation--------# set ns [new Simulator] # Creating trace file and nam file set tracefd [open wireless1.tr w] set namtrace [open wireless1.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) \

Transcript of Wireless Tcl Scripts

Page 1: Wireless Tcl Scripts

Tcl script to create fixed wirless nodes with AODV.

Description:

This network consists of 3 nodes. In this program we generate nodes only; there is no any other connection between the nodes. After creating than am file and trace file, we set up topography object. 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. The end nam and end simulation at 10.0 sec. AODV routing protocol were used here.

File name: “wireless1.tcl”

#-------Event scheduler object creation--------#

set ns [new Simulator]

# Creating trace file and nam file

set tracefd [open wireless1.tr w]set namtrace [open wireless1.nam w]

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

# set up topography objectset 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) \

Page 2: Wireless Tcl Scripts

-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 black$ns at 0.0 "$node_($i) color black"}

# Provide initial location of mobile nodes$node_(0) set X_ 50.0$node_(0) set Y_ 50.0$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0$node_(1) set Y_ 250.0$node_(1) set Z_ 0.0

$node_(2) set X_ 300.0$node_(2) set Y_ 300.0$node_(2) set Z_ 0.0

# Define node initial position in namfor {set i 0} {$i < $val(nn)} { incr i } {$ns initial_node_pos $node_($i) 30}

# Telling nodes when the simulation endsfor {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-traceclose $tracefdclose $namtraceexec nam wireless1.nam &}

$ns run

Page 3: Wireless Tcl Scripts

# How to run the program

$ns wireless1.tcl

# snapshot of the program output

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

Description:

This network consists of 8 nodes. In this program generate nodes only; there is no any other connection between the nodes. After creating than am file and trace file, we set up topography object. 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. The end nam and end simulation at 10.0 sec. AODV routing protocol were used here.

File name: “wireless2.tcl”

Page 4: Wireless Tcl Scripts

#-------Event scheduler object creation--------#

set ns [new Simulator]

#Creating trace file and nam file.set tracefd [open wireless2.tr w]set namtrace [open wireless2.nam w]

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

# set up topography objectset 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 cyan

Page 5: Wireless Tcl Scripts

$ns at 0.0 "$node_($i) color cyan"}

# Provide initial location of mobilenodes$node_(0) set X_ 5.0$node_(0) set Y_ 30.0$node_(0) set Z_ 0.0

$node_(1) set X_ 50.0$node_(1) set Y_ 25.0$node_(1) set Z_ 0.0

$node_(2) set X_ 200.0$node_(2) set Y_ 90.0$node_(2) set Z_ 0.0

$node_(3) set X_ 350.0$node_(3) set Y_ 160.0$node_(3) set Z_ 0.0

$node_(4) set X_ 100.0$node_(4) set Y_ 250.0$node_(4) set Z_ 0.0

$node_(5) set X_ 300.0$node_(5) set Y_ 100.0$node_(5) set Z_ 0.0

$node_(6) set X_ 400.0$node_(6) set Y_ 350.0$node_(6) set Z_ 0.0

$node_(7) set X_ 3s50.0$node_(7) set Y_ 470.0$node_(7) set Z_ 0.0

# Define node initial position in namfor {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 endsfor {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"proc stop {} {global ns tracefd namtrace$ns flush-trace

Page 6: Wireless Tcl Scripts

close $tracefdclose $namtraceexec nam wireless2.nam &}

$ns run

# How to run the program

$ns wireless2.tcl

# snapshot of the program output

Tcl script to create dynamic wirless nodes with AODV.

Description:

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 u 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

Page 7: Wireless Tcl Scripts

nodes when the simulation ends.

File name: “wireless1.tcl”

if {$argc != 1} {error "\nCommand: ns wireless1.tcl <no.of.mobile-nodes>\n\n " }

#-------Event scheduler object creation--------#

set ns [new Simulator]

#creating the trace file and nam file

set tracefd [open wireless1.tr w]set namtrace [open wireless1.nam w]

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

# set up topography objectset 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) \

Page 8: Wireless Tcl Scripts

-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 yellow$ns at 0.0 "$node_($i) color yellow"}

# Provide initial location of mobilenodes$node_(0) set X_ 27.0$node_(0) set Y_ 260.0$node_(0) set Z_ 0.0

$node_(1) set X_ 137.0$node_(1) set Y_ 348.0$node_(1) set Z_ 0.0

$node_(2) set X_ 294.0$node_(2) set Y_ 235.0$node_(2) set Z_ 0.0

$node_(3) set X_ 414.0$node_(3) set Y_ 342.0$node_(3) set Z_ 0.0

$node_(4) set X_ 562.0$node_(4) set Y_ 267.0$node_(4) set Z_ 0.0

$node_(5) set X_ 279.0$node_(5) set Y_ 447.0$node_(5) set Z_ 0.0

$node_(6) set X_ -128.0$node_(6) set Y_ 260.0$node_(6) set Z_ 0.0

$node_(7) set X_ 727.0$node_(7) set Y_ 269.0$node_(7) set Z_ 0.0

$node_(8) set X_ 130.0$node_(8) set Y_ 126.0$node_(8) set Z_ 0.0

$node_(9) set X_ 318.0

Page 9: Wireless Tcl Scripts

$node_(9) set Y_ 45.0$node_(9) set Z_ 0.0

$node_(10) set X_ 505.0$node_(10) set Y_ 446.0$node_(10) set Z_ 0.0

$node_(11) set X_ 421.0$node_(11) set Y_ 158.0$node_(11) set Z_ 0.0

# Define node initial position in namfor {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 endsfor {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"proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceexec nam wireless1.nam &}

$ns run

# How to run the program

$ns wireless1.tcl

# snapshot of the program output

Page 10: Wireless Tcl Scripts

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

Description:

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 <no.of.mobile-nodes>\n\n " }

Page 11: Wireless Tcl Scripts

#-------Event scheduler object creation--------#

set ns [new Simulator]

#creating the trace file and nam file

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

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

# set up topography objectset 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..

Page 12: Wireless Tcl Scripts

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 namfor {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 endsfor {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-traceclose $tracefdclose $namtraceexec nam wireless3.nam &}

$ns run

# How to run the program

$ns wireless3.tcl

# snapshot of the program output

Page 13: Wireless Tcl Scripts

Tcl script to change the nodes color at a time.

Description:

This network has 4 nodes; there is no any other connection between the nodes. After creating the nam file and trace file, we set up topography object. Here nodes has change its color randomly. 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: “wireless1.tcl”

Page 14: Wireless Tcl Scripts

#-------Event scheduler object creation--------#

set ns [new Simulator]

## Create a trace file and nam file..set tracefd [open wireless1.tr w]set namtrace [open wireless1.nam w]

## Trace the nam and trace details from the main simulation..$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)]

## Color Descriptions..$ns color 1 dodgerblue$ns color 2 blue$ns color 3 cyan $ns color 4 green$ns color 5 yellow$ns color 6 black$ns color 7 magenta$ns color 8 gold$ns color 9 red

## Array for dynamic color settings...set colorname(0) blueset colorname(1) cyanset colorname(2) greenset colorname(3) redset colorname(4) goldset colorname(5) magenta

## Setting The Distance Variables..# For model 'TwoRayGround'

Page 15: Wireless Tcl Scripts

set dist(5m) 7.69113e-06set dist(9m) 2.37381e-06set dist(10m) 1.92278e-06set dist(11m) 1.58908e-06set dist(12m) 1.33527e-06set dist(13m) 1.13774e-06set dist(25m) 3.07645e-07set dist(30m) 2.13643e-07set dist(35m) 1.56962e-07set dist(40m) 1.56962e-10set dist(45m) 1.56962e-11set dist(50m) 1.20174e-13#Phy/WirelessPhy set CSThresh_ $dist(50m)#Phy/WirelessPhy set RXThresh_ $dist(50m)

## Setting node config event with set of inputs..$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 blue$ns at 0.0 "$node_($i) color blue"}

## Provide initial location of mobilenodes...for {set i 0} {$i < $val(nn) } { incr i } {set xx [expr rand()*600]set yy [expr rand()*500]$node_($i) set X_ $xx$node_($i) set Y_ $yy$node_($i) set Z_ 0.0}

## 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}

Page 16: Wireless Tcl Scripts

## Dynamic color procedure..$ns at 0.0 "dynamic-color"proc dynamic-color {} {global ns val node_ colornameset time 0.3set now [$ns now]set Rand [expr round(rand()*5)]for {set i 0} {$i < $val(nn) } {incr i } {$node_($i) color $colorname($Rand)$ns at $now "$node_($i) color $colorname($Rand)"}$ns at [expr $now+$time] "dynamic-color"}## stop procedure..$ns at $val(stop) "stop"proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceputs "running nam..."exec nam wireless1.nam &exit 0}

$ns runs

#how to run this program...

$ns wireless1.tcl

# snapshot of the program:

Page 17: Wireless Tcl Scripts
Page 18: Wireless Tcl Scripts

Tcl script to change nodes color one by one at particular interval

Description:

The main thing of the program is how much node you have to give that much node only will create. Here different nodes have different color. There is no any other connection between the nodes. After creating the nam file and trace file, we set up topography object. 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 test2.tcl <no.of.mobile-nodes>\n\n " }

Page 19: Wireless Tcl Scripts

#-------Event scheduler object creation--------#

set ns [new Simulator]

## Create a trace file and nam file..set tracefd [open wireless2.tr w]set namtrace [open wireless2.nam w]

## Trace the nam and trace details from the main simulation..$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)]

## Color Descriptions..$ns color 1 dodgerblue$ns color 2 blue$ns color 3 cyan $ns color 4 green$ns color 5 yellow$ns color 6 black$ns color 7 magenta$ns color 8 gold$ns color 9 red## Setting The Distance Variables..# For model 'TwoRayGround'set dist(5m) 7.69113e-06set dist(9m) 2.37381e-06set dist(10m) 1.92278e-06set dist(11m) 1.58908e-06set dist(12m) 1.33527e-06set dist(13m) 1.13774e-06set dist(25m) 3.07645e-07set dist(30m) 2.13643e-07set dist(35m) 1.56962e-07set dist(40m) 1.56962e-10

Page 20: Wireless Tcl Scripts

set dist(45m) 1.56962e-11set dist(50m) 1.20174e-13#Phy/WirelessPhy set CSThresh_ $dist(50m)#Phy/WirelessPhy set RXThresh_ $dist(50m)

## Setting node config event with set of inputs..

$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 < 4 } {incr i } {$node_($i) color yellow$ns at 0.0 "$node_($i) color yellow"}for {set i 4} {$i < 10 } {incr i } {$node_($i) color red$ns at 3.0 "$node_($i) color red"}for {set i 10} {$i < 15 } {incr i } {$node_($i) color blue$ns at 5.0 "$node_($i) color blue"}

## Provide initial location of mobilenodes..$node_(0) set X_ 27.0$node_(0) set Y_ 260.0$node_(0) set Z_ 0.0

$node_(1) set X_ 137.0$node_(1) set Y_ 348.0$node_(1) set Z_ 0.0

$node_(2) set X_ 294.0$node_(2) set Y_ 235.0$node_(2) set Z_ 0.0

$node_(3) set X_ 414.0$node_(3) set Y_ 342.0

Page 21: Wireless Tcl Scripts

$node_(3) set Z_ 0.0

$node_(4) set X_ 562.0$node_(4) set Y_ 267.0$node_(4) set Z_ 0.0

$node_(5) set X_ 279.0$node_(5) set Y_ 447.0$node_(5) set Z_ 0.0$node_(6) set X_ -128.0$node_(6) set Y_ 260.0$node_(6) set Z_ 0.0

$node_(7) set X_ 727.0$node_(7) set Y_ 269.0$node_(7) set Z_ 0.0

$node_(8) set X_ 130.0$node_(8) set Y_ 126.0$node_(8) set Z_ 0.0

$node_(9) set X_ 318.0$node_(9) set Y_ 45.0$node_(9) set Z_ 0.0

$node_(10) set X_ 505.0$node_(10) set Y_ 446.0$node_(10) set Z_ 0.0

$node_(11) set X_ 421.0$node_(11) set Y_ 158.0$node_(11) set Z_ 0.0

$node_(12) set X_ 72.0$node_(12) set Y_ 397.0$node_(12) set Z_ 0.0

if {$val(nn) >12} {for {set i 13} {$i < $val(nn) } { incr i } {set xx [expr rand()*600]set yy [expr rand()*500] $node_($i) set X_ $xx$node_($i) set Y_ $yy$node_($i) set Z_ 0.0}}## 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}## Stop procedure..$ns at 0.0 "destination"proc destination {} {global ns val node_

Page 22: Wireless Tcl Scripts

set time 1.0set now [$ns now]for {set i 0} {$i<$val(nn)} {incr i} {set xx [expr rand()*600]set yy [expr rand()*500]$ns at $now "$node_($i) setdest $xx $yy 20.0"}$ns at [expr $now+$time] "destination"}

$ns at $val(stop) "stop"

#stop procedure:proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceputs "running nam..."exec nam wireless2.nam &exit 0}

$ns run

# How to run the program:

$ns wireless2.tcl

#snapshot of the program:

Page 23: Wireless Tcl Scripts

Tcl script to make tcp communication between wireless nodes.

Description:

This network consists of 3 nodes. After creating the nam file and trace file, we set up topography object. 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. the nodes have Tcp connection. A "tcp" agent is attached to Client1, and a connection is established to a tcp "sink" agent attached to node0,node1 and node2. As default, the maximum size of a packet that a "tcp" agent can generate is 1KByte. A tcp "sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. The ftp is set to start at 10.0 sec and stop at 150.0 sec. Here we were using AODV routing protocol. File name: “wireless1.tcl”

Page 24: Wireless Tcl Scripts

#-------Event scheduler object creation--------#

set ns [new Simulator]#creating trace file and nam fileset tracefd [open wireless1.tr w]set windowVsTime2 [open win.tr w] set namtrace [open wireless1.nam w]

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

# set up topography objectset topo [new Topography]

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

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

for {set i 0} {$i < $val(nn) } { incr i } {set node_($i) [$ns node] }

# Provide initial location of mobilenodes$node_(0) set X_ 5.0$node_(0) set Y_ 5.0

Page 25: Wireless Tcl Scripts

$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

# Generation of movements$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"$ns at 19.0 "$node_(2) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)set tcp [new Agent/TCP/Newreno]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"

set tcp [new Agent/TCP/Newreno]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(1) $tcp$ns attach-agent $node_(2) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"

# Printing the window sizeproc plotWindow {tcpSource file} {global nsset time 0.01set now [$ns now]set cwnd [$tcpSource set cwnd_]puts $file "$now $cwnd"$ns at [expr $now+$time] "plotWindow $tcpSource $file" }$ns at 10.0 "plotWindow $tcp $windowVsTime2"

# Define node initial position in namfor {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 endsfor {set i 0} {$i < $val(nn) } { incr i } {$ns at $val(stop) "$node_($i) reset";

Page 26: Wireless Tcl Scripts

}

# 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-traceclose $tracefdclose $namtraceexec nam simwrls.nam &}

$ns run# How to run the program:

$ns wireless1.tcl

#snapshot of the program:

Page 27: Wireless Tcl Scripts

Tcl script for implementing DSR routing protocol in wireless network.

Description:This network consists of 3 nodes. After creating the nam file and trace file, we set up topography object. 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. the nodes have Tcp connection. A "tcp" agent is attached to Client1, and a connection is established to a tcp "sink" agent attached to node0 and node1. As default, the maximum size of a packet that a "tcp" agent can generate is 1KByte. A tcp "sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. The ftp is set to start at 10.0 sec and stop at 150.0 sec. Here we were using DSR routing protocol.File name: “Dsr.tcl”

#-------Event scheduler object creation--------#

set ns [new Simulator]#Creating trace file and nam file set tracefd [open dsr.tr w]set windowVsTime2 [open win.tr w] set namtrace [open dsr.nam w]

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

# set up topography objectset topo [new Topography]

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

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) \

Page 28: Wireless Tcl Scripts

-topoInstance $topo \-agentTrace ON \-routerTrace ON \-macTrace OFF \-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i } {set node_($i) [$ns node] }

# Provide initial location of mobilenodes$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

# Generation of movements$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)set tcp [new Agent/TCP/Newreno]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"

# Printing the window sizeproc plotWindow {tcpSource file} {global nsset time 0.01set now [$ns now]set cwnd [$tcpSource set cwnd_]puts $file "$now $cwnd"$ns at [expr $now+$time] "plotWindow $tcpSource $file" }$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in namfor {set i 0} {$i < $val(nn)} { incr i } {# 30 defines the node size for nam$ns initial_node_pos $node_($i) 30}

Page 29: Wireless Tcl Scripts

# Telling nodes when the simulation endsfor {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-traceclose $tracefdclose $namtraceexec nam dsr.nam &exit 0}

$ns run

# How to run the program:

$ns dsr.tcl

#snapshot of the program:

Page 30: Wireless Tcl Scripts
Page 31: Wireless Tcl Scripts

Tcl script for implementing AODV routing protocol in wireless network.

Description:

This network consists of 22 nodes. After creating the nam file and trace file, we set up topography object. 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. server1 and server2 also created in this program. After that $Val (stop) is used to tell to nodes when the simulation ends. the nodes have Tcp connection. An "udp" agent is attached to node0, and a connection is established to udp "null" agent attached to server1 and node18 and etc.. As default, the maximum size of a packet that "udp" agent can generate is 1KByte. A tcp "null" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. The Cbr is set to start at 0.0 sec and stop at 4.1 sec. Here we were using AODV routing protocol. The annotation trace is used to trace the details.

File name: “Aodv.tcl”

Page 32: Wireless Tcl Scripts

### Setting The Simulator Objects

set ns_ [new Simulator]#create the nam and trace file:set tracefd [open aodv.tr w]$ns_ trace-all $tracefd

set namtrace [open aodv.nam w]$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]$topo load_flatgrid $val(x) $val(y)create-god $val(nn)set chan_1_ [new $val(chan)]

#### Setting The Distance Variables

# For model 'TwoRayGround'set dist(5m) 7.69113e-06set dist(9m) 2.37381e-06set dist(10m) 1.92278e-06set dist(11m) 1.58908e-06set dist(12m) 1.33527e-06set dist(13m) 1.13774e-06set dist(14m) 9.81011e-07set dist(15m) 8.54570e-07set dist(16m) 7.51087e-07set dist(20m) 4.80696e-07set dist(25m) 3.07645e-07set dist(30m) 2.13643e-07set dist(35m) 1.56962e-07set dist(40m) 1.56962e-10set dist(45m) 1.56962e-11set dist(50m) 1.20174e-13Phy/WirelessPhy set CSThresh_ $dist(50m)Phy/WirelessPhy set RXThresh_ $dist(50m)

# Defining Node Configuration

$ns_ node-config -adhocRouting $val(rp) \-llType $val(ll) \-macType $val(mac) \

Page 33: Wireless Tcl Scripts

-ifqType $val(ifq) \-ifqLen $val(ifqlen) \-antType $val(ant) \-propType $val(prop) \-phyType $val(netif) \-topoInstance $topo \-agentTrace ON \-routerTrace ON \-macTrace ON \-movementTrace ON \-channel $chan_1_

### Creating The WIRELESS NODES

set Server1 [$ns_ node]set Server2 [$ns_ node]set n2 [$ns_ node]set n3 [$ns_ node]set n4 [$ns_ node]set n5 [$ns_ node]set n6 [$ns_ node]set n7 [$ns_ node]set n8 [$ns_ node]set n9 [$ns_ node]set n10 [$ns_ node]set n11 [$ns_ node]set n12 [$ns_ node]set n13 [$ns_ node]set n14 [$ns_ node]set n15 [$ns_ node]set n16 [$ns_ node]set n17 [$ns_ node]set n18 [$ns_ node]set n19 [$ns_ node]set n20 [$ns_ node]set n21 [$ns_ node]set n22 [$ns_ node]

set opt(seed) 0.1set a [ns-random $opt(seed)]set i 0while {$i < 5} {incr i}

### Setting The Initial Positions of Nodes

$Server1 set X_ 513.0$Server1 set Y_ 517.0$Server1 set Z_ 0.0

$Server2 set X_ 1445.0$Server2 set Y_ 474.0$Server2 set Z_ 0.0

$n2 set X_ 36.0$n2 set Y_ 529.0

Page 34: Wireless Tcl Scripts

$n2 set Z_ 0.0

$n3 set X_ 143.0$n3 set Y_ 666.0$n3 set Z_ 0.0

$n4 set X_ 201.0$n4 set Y_ 552.0$n4 set Z_ 0.0

$n5 set X_ 147.0$n5 set Y_ 403.0$n5 set Z_ 0.0

$n6 set X_ 230.0$n6 set Y_ 291.0$n6 set Z_ 0.0

$n7 set X_ 295.0$n7 set Y_ 419.0$n7 set Z_ 0.0

$n8 set X_ 363.0$n8 set Y_ 335.0$n8 set Z_ 0.0

$n9 set X_ 334.0$n9 set Y_ 647.0$n9 set Z_ 0.0

$n10 set X_ 304.0$n10 set Y_ 777.0$n10 set Z_ 0.0

$n11 set X_ 412.0$n11 set Y_ 194.0$n11 set Z_ 0.0

$n12 set X_ 519.0$n12 set Y_ 361.0$n12 set Z_ 0.0

$n13 set X_ 569.0$n13 set Y_ 167.0$n13 set Z_ 0.0

$n14 set X_ 349.0$n14 set Y_ 546.0$n14 set Z_ 0.0

$n15 set X_ 466.0$n15 set Y_ 668.0$n15 set Z_ 0.0

$n16 set X_ 489.0

Page 35: Wireless Tcl Scripts

$n16 set Y_ 794.0$n16 set Z_ 0.0

$n17 set X_ 606.0$n17 set Y_ 711.0$n17 set Z_ 0.0

$n18 set X_ 630.0$n18 set Y_ 626.0$n18 set Z_ 0.0

$n19 set X_ 666.0$n19 set Y_ 347.0$n19 set Z_ 0.0

$n20 set X_ 741.0$n20 set Y_ 152.0$n20 set Z_ 0.0

$n21 set X_ 882.0$n21 set Y_ 264.0$n21 set Z_ 0.0

$n22 set X_ 761.0$n22 set Y_ 441.0$n22 set Z_ 0.0

## Giving Mobility to Nodes

$ns_ at 0.75 "$n2 setdest 379.0 349.0 20.0"$ns_ at 0.75 "$n3 setdest 556.0 302.0 20.0"$ns_ at 0.20 "$n4 setdest 309.0 211.0 20.0"$ns_ at 1.25 "$n5 setdest 179.0 333.0 20.0"$ns_ at 0.75 "$n6 setdest 139.0 63.0 20.0"$ns_ at 0.75 "$n7 setdest 320.0 27.0 20.0"$ns_ at 1.50 "$n8 setdest 505.0 124.0 20.0"$ns_ at 1.25 "$n9 setdest 274.0 487.0 20.0"$ns_ at 1.25 "$n10 setdest 494.0 475.0 20.0"$ns_ at 1.25 "$n11 setdest 899.0 757.0 25.0"$ns_ at 0.50 "$n12 setdest 598.0 728.0 25.0"$ns_ at 0.25 "$n13 setdest 551.0 624.0 25.0"$ns_ at 1.25 "$n14 setdest 397.0 647.0 25.0"$ns_ at 1.25 "$n15 setdest 748.0 688.0 25.0"$ns_ at 1.25 "$n16 setdest 842.0 623.0 25.0"$ns_ at 1.25 "$n17 setdest 678.0 548.0 25.0"$ns_ at 0.75 "$n18 setdest 741.0 809.0 20.0"$ns_ at 0.75 "$n19 setdest 437.0 799.0 20.0"$ns_ at 0.20 "$n20 setdest 159.0 722.0 20.0"$ns_ at 1.25 "$n21 setdest 700.0 350.0 20.0"$ns_ at 0.75 "$n22 setdest 839.0 444.0 20.0"

## Setting The Node Size

$ns_ initial_node_pos $Server1 75$ns_ initial_node_pos $Server2 75$ns_ initial_node_pos $n2 40

Page 36: Wireless Tcl Scripts

$ns_ initial_node_pos $n3 40$ns_ initial_node_pos $n4 40$ns_ initial_node_pos $n5 40$ns_ initial_node_pos $n6 40$ns_ initial_node_pos $n7 40$ns_ initial_node_pos $n8 40$ns_ initial_node_pos $n9 40$ns_ initial_node_pos $n10 40$ns_ initial_node_pos $n11 40$ns_ initial_node_pos $n12 40$ns_ initial_node_pos $n13 40$ns_ initial_node_pos $n14 40$ns_ initial_node_pos $n15 40$ns_ initial_node_pos $n16 40$ns_ initial_node_pos $n17 40$ns_ initial_node_pos $n18 40$ns_ initial_node_pos $n19 40$ns_ initial_node_pos $n20 40$ns_ initial_node_pos $n21 40$ns_ initial_node_pos $n22 40

#### Setting The Labels For Nodes

$ns_ at 0.0 "$Server1 label Server1"$ns_ at 0.0 "$Server2 label Server2"

#Setting Color For Server

$Server1 color maroon$ns_ at 0.0 "$Server1 color maroon"

$Server2 color maroon$ns_ at 0.0 "$Server2 color maroon"

## SETTING ANIMATION RATE $ns_ at 0.0 "$ns_ set-animation-rate 15.0ms"

# COLORING THE NODES $n9 color blue$ns_ at 4.71 "$n9 color blue"$n5 color blue$ns_ at 7.0 "$n5 color blue"$n2 color blue$ns_ at 7.29 "$n2 color blue"

$n16 color blue$ns_ at 7.59 "$n16 color blue"

$n9 color maroon$ns_ at 7.44 "$n9 color maroon"

$ns_ at 7.43 "$n9 label TTLover"$ns_ at 7.55 "$n9 label \"\""

$n12 color blue

Page 37: Wireless Tcl Scripts

$ns_ at 7.85 "$n12 color blue"

#### Establishing Communication

set udp0 [$ns_ create-connection UDP $Server1 LossMonitor $n18 0]$udp0 set fid_ 1set cbr0 [$udp0 attach-app Traffic/CBR]$cbr0 set packetSize_ 1000 $cbr0 set interval_ .07$ns_ at 0.0 "$cbr0 start"$ns_ at 4.0 "$cbr0 stop"

set udp1 [$ns_ create-connection UDP $Server1 LossMonitor $n22 0]$udp1 set fid_ 1set cbr1 [$udp1 attach-app Traffic/CBR]$cbr1 set packetSize_ 1000 $cbr1 set interval_ .07$ns_ at 0.1 "$cbr1 start"$ns_ at 4.1 "$cbr1 stop"

set udp2 [$ns_ create-connection UDP $n21 LossMonitor $n20 0]$udp2 set fid_ 1set cbr2 [$udp2 attach-app Traffic/CBR]$cbr2 set packetSize_ 1000 $cbr2 set interval_ .07$ns_ at 2.4 "$cbr2 start"$ns_ at 4.1 "$cbr2 stop"

set udp3 [$ns_ create-connection UDP $Server1 LossMonitor $n15 0]$udp3 set fid_ 1set cbr3 [$udp3 attach-app Traffic/CBR]$cbr3 set packetSize_ 1000 $cbr3 set interval_ 5$ns_ at 4.0 "$cbr3 start"$ns_ at 4.1 "$cbr3 stop"

set udp4 [$ns_ create-connection UDP $Server1 LossMonitor $n14 0]$udp4 set fid_ 1set cbr4 [$udp4 attach-app Traffic/CBR]$cbr4 set packetSize_ 1000 $cbr4 set interval_ 5$ns_ at 4.0 "$cbr4 start"$ns_ at 4.1 "$cbr4 stop"

set udp5 [$ns_ create-connection UDP $n15 LossMonitor $n16 0]$udp5 set fid_ 1set cbr5 [$udp5 attach-app Traffic/CBR]$cbr5 set packetSize_ 1000 $cbr5 set interval_ 5$ns_ at 4.0 "$cbr5 start"$ns_ at 4.1 "$cbr5 stop"

set udp6 [$ns_ create-connection UDP $n15 LossMonitor $n17 0]$udp6 set fid_ 1set cbr6 [$udp6 attach-app Traffic/CBR]$cbr6 set packetSize_ 1000

Page 38: Wireless Tcl Scripts

$cbr6 set interval_ 5$ns_ at 4.0 "$cbr6 start"$ns_ at 4.1 "$cbr6 stop"

set udp7 [$ns_ create-connection UDP $n14 LossMonitor $n4 0]$udp7 set fid_ 1set cbr7 [$udp7 attach-app Traffic/CBR]$cbr7 set packetSize_ 1000 $cbr7 set interval_ 5$ns_ at 4.0 "$cbr7 start"$ns_ at 4.1 "$cbr7 stop"

set udp8 [$ns_ create-connection UDP $n14 LossMonitor $n9 0]$udp8 set fid_ 1set cbr8 [$udp8 attach-app Traffic/CBR]$cbr8 set packetSize_ 1000 $cbr8 set interval_ 5$ns_ at 4.0 "$cbr8 start"$ns_ at 4.1 "$cbr8 stop"

set udp9 [$ns_ create-connection UDP $n4 LossMonitor $n3 0]$udp9 set fid_ 1set cbr9 [$udp9 attach-app Traffic/CBR]$cbr9 set packetSize_ 1000 $cbr9 set interval_ 5$ns_ at 4.0 "$cbr9 start"$ns_ at 4.1 "$cbr9 stop"

set udp10 [$ns_ create-connection UDP $n4 LossMonitor $n2 0]$udp10 set fid_ 1set cbr10 [$udp10 attach-app Traffic/CBR]$cbr10 set packetSize_ 1000 $cbr10 set interval_ 5$ns_ at 4.0 "$cbr10 start"$ns_ at 4.1 "$cbr10 stop"

set udp11 [$ns_ create-connection UDP $n9 LossMonitor $n16 0]$udp11 set fid_ 1set cbr11 [$udp11 attach-app Traffic/CBR]$cbr11 set packetSize_ 1000 $cbr11 set interval_ 5$ns_ at 4.0 "$cbr11 start"$ns_ at 4.1 "$cbr11 stop"

set udp12 [$ns_ create-connection UDP $n9 LossMonitor $n10 0]$udp12 set fid_ 1set cbr12 [$udp12 attach-app Traffic/CBR]$cbr12 set packetSize_ 1000 $cbr12 set interval_ 5$ns_ at 4.0 "$cbr12 start"$ns_ at 4.1 "$cbr12 stop"

#ANNOTATIONS DETAILS

$ns_ at 0.0 "$ns_ trace-annotate \"MOBILE NODE MOVEMENTS\""$ns_ at 4.1 "$ns_ trace-annotate \"NODE27 CACHE THE DATA FRO SERVER\""#$ns_ at 4.59 "$ns_ trace-annotate \"PACKET LOSS AT NODE27\""

Page 39: Wireless Tcl Scripts

$ns_ at 4.71 "$ns_ trace-annotate \"NODE10 CACHE THE DATA\""

### PROCEDURE TO STOP

proc stop {} {

global ns_ tracefd$ns_ flush-traceclose $tracefdexec nam datacache.nam & exit 0

}

puts "Starting Simulation........"$ns_ at 25.0 "stop"$ns_ run

# How to run the program:

$ns aodv1.tcl

#snapshot of the program:

Page 40: Wireless Tcl Scripts

Tcl script for implementing DSDV routing protocol in wireless network.

Description:This network consists of 3 nodes. After creating the nam file and trace file, we set up topography object. 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. server1 and server2 also created in this program. After that $Val (stop) is used to tell to nodes when the simulation ends. The nodes have Udp connection. An "udp" agent is attached to node0, and a connection is established to udp "null" agent attached to node0 and node1 and etc... As default, the maximum size of a packet that "udp" agent can generate is 1KByte. An udp "null" agent generates and sends ACK packets to the sender (udp agent) and frees the received packets. The Cbr is set to start at 0.0 sec and stop at 4.1 sec. Here we were using DSDV routing protocol.

File name: “dsdv.tcl”

#Creating trace file and nam fileset tracefd [open dsdv.tr w]set windowVsTime2 [open win.tr w] set namtrace [open dsdv.nam w]

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

# set up topography objectset topo [new Topography]

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

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 \

Page 41: Wireless Tcl Scripts

-agentTrace ON \-routerTrace ON \-macTrace OFF \-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i } {set node_($i) [$ns node] }

# Provide initial location of mobilenodes$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

# Generation of movements$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)set tcp [new Agent/TCP/Newreno]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"

# Printing the window sizeproc plotWindow {tcpSource file} {global nsset time 0.01set now [$ns now]set cwnd [$tcpSource set cwnd_]puts $file "$now $cwnd"$ns at [expr $now+$time] "plotWindow $tcpSource $file" }$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# Define node initial position in namfor {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

Page 42: Wireless Tcl Scripts

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-traceclose $tracefdclose $namtraceexec nam dsdv.nam &exit 0}

$ns run

# How to run the program:

$ns dsdv.tcls

#snapshot of the program:

Page 43: Wireless Tcl Scripts

Tcl script to set nodes destination randomly at particular time interval.

Destination:

This network has 5 nodes; there is no any other connection between the nodes. After creating the nam file and trace file, we set up topography object. 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. In this process we were set Random destination node using destination method. AODV routing protocol are used.

File name: “wireless1.tcl”

# Define optionsset val(chan) Channel/WirelessChannel ;# channel typeset val(prop) Propagation/TwoRayGround ;# radio-propagation modelset val(netif) Phy/WirelessPhy ;# network interface typeset val(mac) Mac/802_11 ;# MAC typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ll) LL ;# link layer typeset val(ant) Antenna/OmniAntenna ;# antenna modelset val(ifqlen) 50 ;# max packet in ifqset val(nn) 5 ;# number of mobilenodesset val(rp) AODV ;# routing protocolset val(x) 500 ;# X dimension of topographyset val(y) 400 ;# Y dimension of topography set val(stop) 10 ;# time of simulation end

set ns [new Simulator]

#Creating nam and trace file:

set tracefd [open wireless1.tr w]set namtrace [open wireless1.nam w]

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

# set up topography objectset 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 \

Page 44: Wireless Tcl Scripts

-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 black$ns at 0.0 "$node_($i) color black"}

## Provide initial location of mobilenodes..for {set i 0} {$i < $val(nn) } { incr i } {set xx [expr rand()*500]set yy [expr rand()*400]$node_($i) set X_ $xx$node_($i) set Y_ $yy

}# Define node initial position in namfor {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 endsfor {set i 0} {$i < $val(nn) } { incr i } {$ns at $val(stop) "$node_($i) reset";}

#Destination procedure..$ns at 0.0 "destination"proc destination {} {global ns val node_ set time 1.0set now [$ns now]for {set i 0} {$i<$val(nn)} {incr i} {set xx [expr rand()*500]set yy [expr rand()*400]$ns at $now "$node_($i) setdest $xx $yy 10.0"}$ns at [expr $now+$time] "destination"}

$ns at $val(stop) "stop"

#Stop procedure

proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefd

Page 45: Wireless Tcl Scripts

close $namtraceexec nam wireless1.nam &}

$ns run

# How to run the program:

$ns wireless1.tcl

#snapshot of the program:

Tcl script to set nodes destination and color randomly .

Destination:

This network has 8 nodes; there is no any other connection between the nodes. The nodes are generating dynamically using destination procedure. The number of nodes has different colors. After creating the nam file and trace file, we set up topography object. 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. In this process we were set Random destination node using destination method. AODV routing protocol are used. The nam and

Page 46: Wireless Tcl Scripts

simulation end at 10.0 sec.

File name: “wireless2.tcl”

# Define setting optionsset val(chan) Channel/WirelessChannel ;# channel typeset val(prop) Propagation/TwoRayGround ;# radio-propagation modelset val(netif) Phy/WirelessPhy ;# network interface typeset val(mac) Mac/802_11 ;# MAC typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ll) LL ;# link layer typeset val(ant) Antenna/OmniAntenna ;# antenna modelset val(ifqlen) 50 ;# max packet in ifqset val(nn) 8 ;# number of mobilenodesset val(rp) AODV ;# routing protocolset val(x) 500 ;# X dimension of topographyset val(y) 400 ;# Y dimension of topography set val(stop) 10 ;# time of simulation end

set ns [new Simulator]

#Creating nam and trace file:set tracefd [open wireless2.tr w]set namtrace [open wireless2.nam w]

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

# set up topography objectset 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 < 3 } { incr i } {set node_($i) [$ns node]

Page 47: Wireless Tcl Scripts

}for {set i 0} {$i < 3 } {incr i } {$node_($i) color blue$ns at 0.0 "$node_($i) color blue"}for {set i 3} {$i < 6 } { incr i } {set node_($i) [$ns node] }for {set i 3} {$i < 5 } {incr i } {$node_($i) color cyan$ns at 0.0 "$node_($i) color cyan"}for {set i 5} {$i < 8 } { incr i } {set node_($i) [$ns node] }for {set i 5} {$i < 8 } {incr i } {$node_($i) color red$ns at 0.0 "$node_($i) color red"}

## Provide initial location of mobilenodes..for {set i 0} {$i < $val(nn) } { incr i } {set xx [expr rand()*500]set yy [expr rand()*400]$node_($i) set X_ $xx$node_($i) set Y_ $yy

}

# Define node initial position in namfor {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 endsfor {set i 0} {$i < $val(nn) } { incr i } {$ns at $val(stop) "$node_($i) reset";}

# dynamic destination setting procedure..$ns at 0.0 "destination"proc destination {} {global ns val node_ set time 1.0set now [$ns now]for {set i 0} {$i<$val(nn)} {incr i} {set xx [expr rand()*500]set yy [expr rand()*400]$ns at $now "$node_($i) setdest $xx $yy 10.0"}$ns at [expr $now+$time] "destination"}

#stop procedure..$ns at $val(stop) "stop"

Page 48: Wireless Tcl Scripts

proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceexec nam wireless2.nam &}

$ns run

# How to run the program:

$ns wireless2.tcl

#snapshot of the program:

Tcl script to set nodes initail and destination position randomly.

Destination:

This network has 8 nodes; there is no any other connection between the nodes. The nodes are generating dynamically using destination procedure. The number of nodes has different colors.Node0 to 3 have color at 0.0 sec, node4 to 6 have color at 1.0 sec and node 6 to 8 varies at 2.0 sec. After creating the nam file and trace file, we set up topography object. Set node_ ($i) [$ns

Page 49: Wireless Tcl Scripts

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. In this process we were set Random destination node using destination method. AODV routing protocol are used. The nam and simulation end at 10.0 sec.

File name: “wireless3.tcl”

# Define optionsset val(chan) Channel/WirelessChannel ;# channel typeset val(prop) Propagation/TwoRayGround ;# radio-propagation modelset val(netif) Phy/WirelessPhy ;# network interface typeset val(mac) Mac/802_11 ;# MAC typeset val(ifq) Queue/DropTail/PriQueue ;# interface queue typeset val(ll) LL ;# link layer typeset val(ant) Antenna/OmniAntenna ;# antenna modelset val(ifqlen) 50 ;# max packet in ifqset val(nn) 8 ;# number of mobilenodesset val(rp) AODV ;# routing protocolset val(x) 500 ;# X dimension of topographyset val(y) 400 ;# Y dimension of topography set val(stop) 10 ;# time of simulation end

#Creating simulation: set ns [new Simulator]

#Creating nam and trace file: set tracefd [open wireless3.tr w]set namtrace [open wireless3.nam w]

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

# set up topography objectset 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

Page 50: Wireless Tcl Scripts

## Creating node objects.. for {set i 0} {$i < 3 } { incr i } {set node_($i) [$ns node] }for {set i 0} {$i < 3 } {incr i } {$node_($i) color blue$ns at 0.0 "$node_($i) color blue"}for {set i 3} {$i < 6 } { incr i } {set node_($i) [$ns node] }for {set i 3} {$i < 6 } {incr i } {$node_($i) color cyan$ns at 1.0 "$node_($i) color cyan"}for {set i 6} {$i < 8 } { incr i } {set node_($i) [$ns node] }for {set i 5} {$i < 8 } {incr i } {$node_($i) color red$ns at 2.0 "$node_($i) color red"}

## Provide initial location of mobilenodes..for {set i 0} {$i < $val(nn) } { incr i } {set xx [expr rand()*500]set yy [expr rand()*400]$node_($i) set X_ $xx$node_($i) set Y_ $yy

}

# Define node initial position in namfor {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 endsfor {set i 0} {$i < $val(nn) } { incr i } {$ns at $val(stop) "$node_($i) reset";}

# dynamic destination setting procedure..$ns at 0.0 "destination"proc destination {} {global ns val node_ set time 1.0set now [$ns now]for {set i 0} {$i<$val(nn)} {incr i} {set xx [expr rand()*500]set yy [expr rand()*400]$ns at $now "$node_($i) setdest $xx $yy 10.0"}$ns at [expr $now+$time] "destination"

Page 51: Wireless Tcl Scripts

}

#stop procedure..$ns at $val(stop) "stop"proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceexec nam wireless3.nam &}

$ns run

# How to run the program:

$ns wireless3.tcl

#snapshot of the program:

Tcl script to draw the graph and set x and y coordinates randomly.

Description:

Page 52: Wireless Tcl Scripts

This network has 3 nodes. 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. Here nodes have no 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. AODV routing protocol were used here. Here we make graph using graph procedure. X and Y parameter generate randomly.

File name: “graph1.tcl”

# Creating simulationset ns [new Simulator]

#Creating nam and trace fileset tracefd [open Graph1.tr w]set namtrace [open Graph1.nam w]

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

# set up topography objectset 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 \

Page 53: Wireless Tcl Scripts

-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 black$ns at 0.0 "$node_($i) color black"}

# Provide initial location of mobilenodes$node_(0) set X_ 50.0$node_(0) set Y_ 50.0$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0$node_(1) set Y_ 250.0$node_(1) set Z_ 0.0

$node_(2) set X_ 300.0$node_(2) set Y_ 300.0$node_(2) set Z_ 0.0

# Define node initial position in namfor {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 endsfor {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"

#Graph procedure..$ns at 1.0 "Graph"set g [open graph.tr w]proc Graph {} {global ns g set time 1.0set now [$ns now]puts $g "[expr rand()*8] [expr rand()*6]"

$ns at [expr $now+$time] "Graph"}

Page 54: Wireless Tcl Scripts

#Stop procetureproc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceexec xgraph -M -bb -geometry 700X800 graph.tr &exec nam Graph1.nam &exit 0}

$ns run

# How to run the program

$ns Graph1.tcl

# snapshot of the program output

Tcl script to generate graph at take two parameter files as input.

Description:

Page 55: Wireless Tcl Scripts

This network has 3 nodes. 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. Here nodes have no 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. AODV routing protocol were used here. Here we make two graph using graph procedure. X and Y parameter generate randomly.

File name: “graph2.tcl”

# Creating simulationset ns [new Simulator]

#Creating nam and trace fileset tracefd [open Graph2.tr w]set namtrace [open Graph2.nam w]

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

# set up topography objectset 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 \

Page 56: Wireless Tcl Scripts

-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 black$ns at 0.0 "$node_($i) color black"}

# Provide initial location of mobilenodes$node_(0) set X_ 50.0$node_(0) set Y_ 50.0$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0$node_(1) set Y_ 250.0$node_(1) set Z_ 0.0

$node_(2) set X_ 300.0$node_(2) set Y_ 300.0$node_(2) set Z_ 0.0

# Define node initial position in namfor {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 endsfor {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"

#Graph procedure..#procedure..$ns at 1.0 "Graph"set g [open graph.tr w]set g1 [open graph1.tr w]proc Graph {} {global ns g g1set time 1.0set now [$ns now]puts $g "[expr rand()*8] [expr rand()*6]"puts $g1 "[expr rand()*8] [expr rand()*6]"$ns at [expr $now+$time] "Graph"

Page 57: Wireless Tcl Scripts

}

#stop procedure:proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtraceexec xgraph -P -bb -geometry 700X800 graph.tr graph1.tr &

exec nam Graph2.nam &exit 0}

$ns run

# How to run the program

$ns Graph2.tcl

# snapshot of the program output

Otcl coding to create classes and objects.

Description:An OTcl script that defines two object classes, "teacher" and "student", where "Student" is the child class of "teacher", and a member function called "greet" for each class. After the class definitions,

Page 58: Wireless Tcl Scripts

each object instance is declared, the "subject" variable of each instance is set to maths for teacher and name for student and the "greet" member function of each object instance is called. The keyword Class is to create an object class and instproc is to define a member function to an object class. Class inheritance is specified using the keyword -superclass. In defining member functions, $self acts same as the "this" pointer in C++, and instvar checks if the following variable name is already declared in its class or in its superclass. Finally, to create an object instance, the keyword new is used.

File name: “Otcl.tcl”

# Add a member function call”greet”Class TeacherTeacher instproc init {subject} {$self instvar subject_set subject_ $subject}# Creating a child class of teacher and studentTeacher instproc greet {} {$self instvar subject_puts "$subject_ teacher askwhich subject u studied?"}#creating a teacher and student objectClass student -superclass Teacherstudent instproc greet {} {$self instvar subject_puts "$subject_ sayi studied maths"}# calling member function “greet” of each nodeset a [new Teacher maths]set b [new student Jey]$a greet$b greet

#how to run $ns <filename>.tcl

# output snapshot

Page 59: Wireless Tcl Scripts

AWK file for data filettering.

Description:

The main thing of the program is how much node you have to give that much node only will create. Here different nodes have different color. There is no any other connection between the nodes. After creating the nam file and trace file, we set up topography object. 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.Dsr routing protocol were used here. Here we use some procedure, that is pktDeliveryRatio graph, for RouteOverhead graph, Misbehaviour_NODE graph. Count file is used to filtering the ack packets, forwarded packets, send packets, receving packets, drop packets.

File name: “test.tcl”

## Create a simulator object(nothing but, a scheduler's object)..set ns [new Simulator]

## Create a trace file and nam file..set tracefd [open scheme.tr w]set namtrace [open scheme.nam w]

## Trace the nam and trace details from the main simulation..$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)]

## Color Descriptions..$ns color 1 dodgerblue$ns color 2 blue$ns color 3 cyan

Page 60: Wireless Tcl Scripts

$ns color 4 green$ns color 5 yellow

## Setting The Distance Variables..# For model 'TwoRayGround'set dist(5m) 7.69113e-06set dist(9m) 2.37381e-06set dist(10m) 1.92278e-06set dist(11m) 1.58908e-06set dist(12m) 1.33527e-06set dist(13m) 1.13774e-06set dist(14m) 9.81011e-07set dist(15m) 8.54570e-07set dist(16m) 7.51087e-07set dist(20m) 4.80696e-07set dist(25m) 3.07645e-07set dist(30m) 2.13643e-07set dist(35m) 1.56962e-07set dist(40m) 1.56962e-10set dist(45m) 1.56962e-11set dist(50m) 1.20174e-13#Phy/WirelessPhy set CSThresh_ $dist(50m)#Phy/WirelessPhy set RXThresh_ $dist(50m)

## Setting node config event with set of inputs..puts "Node Configuration Started here...\n \-channel $val(chan) \n \-adhocRouting $val(rp) \n \-llType $val(ll) \n \-macType $val(mac) \n \-ifqType $val(ifq) \n \-ifqLen $val(ifqlen) \n \-antType $val(ant) \n \-propType $val(prop) \n \-phyType $val(netif) \n"

$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] }

Page 61: Wireless Tcl Scripts

for {set i 0} {$i < $val(nn)} {incr i} {$node_($i) color darkgreen$ns at 0.0 "$node_($i) color darkgreen"}

## Provide initial location of mobilenodes..

if {$val(nn) >0} {for {set i 1} {$i < $val(nn) } { incr i } {set xx [expr rand()*600];#if{$xx<=200} {set xx [expr 350+(rand()*150)]}set yy [expr rand()*500];#if{$yy<=200} {set yy [expr 350+(rand()*150)]}$node_($i) set X_ $xx$node_($i) set Y_ $yy$node_($i) set Z_ 0.0}}

## set god distance..$god_ set-dist 0 1 2$god_ set-dist 0 2 2$god_ set-dist 0 3 2$god_ set-dist 0 4 1$god_ set-dist 0 5 2$god_ set-dist 1 2 3$god_ set-dist 1 3 3$god_ set-dist 1 4 2$god_ set-dist 1 5 2$god_ set-dist 2 3 3$god_ set-dist 2 4 2$god_ set-dist 2 5 2$god_ set-dist 2 6 4$god_ set-dist 3 4 2$god_ set-dist 3 5 3$god_ set-dist 3 6 3$god_ set-dist 4 5 2$god_ set-dist 4 6 2

## 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}

## Set a TCP connection between node_(0) and node_(1)..$ns at 1.0 "commn"proc commn {} {global ns node_ rootPathset now [$ns now]set time 0.6set time1 1.0source "$rootPath/commn2.tcl";$ns at [expr $now+$time1] "commn"

}

Page 62: Wireless Tcl Scripts

## Generation of movements-Destination setting..

$ns at 0.0 "Mobility"proc Mobility {} {global ns node_ rootPath valset ns_ [Simulator instance]set time 1.0set moveTime 0.5set now [$ns now]#source "$rootPath/setdest1.tcl"source "$rootPath/setdest.tcl"$ns_ at [expr $now+$time] "Mobility"}

#source "$rootPath/annotate.tcl"

## 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 16.01 "puts \"end simulation\" " ;# $ns halt

## Procedure for pktDeliveryRatio graph..set PktDelRatio 0.98set MisBehRatio 0set pdrgraph [open pdratio(Scheme).tr w]

$ns at 0.1 "PktDelRatio"proc PktDelRatio {} {global ns rootPath pdrgraph PktDelRatio MisBehRatio pktdelratio misbehratioset ns_ [Simulator instance]set time 1.2set now [$ns_ now]source "$rootPath/PDRatio.tcl"if {$now<1.2} {set PktDelRatio 0.98;set MisBehRatio 0}if {$now>1.2} {set PktDelRatio [expr $PktDelRatio-$pktdelratio]set MisBehRatio [expr $MisBehRatio+$misbehratio]}puts $pdrgraph "$MisBehRatio $PktDelRatio"$ns_ at [expr $now+$time] "PktDelRatio"}

## Procedure for RouteOverhead graph..set RouteOverhead 0.98set MisBehRatio 0set rohgraph [open routeOH(Scheme).tr w]

$ns at 0.1 "Overhead_Cal"proc Overhead_Cal {} {global ns rootPath rohgraph RouteOverhead MisBehRatio routeoverhead misbehratio

Page 63: Wireless Tcl Scripts

set ns_ [Simulator instance]set time 1.2set now [$ns_ now]source "$rootPath/RouteOverHead.tcl"if {$now<1.2} {set RouteOverhead 0.01;set MisBehRatio 0}if {$now>1.2} {set RouteOverhead [expr $RouteOverhead+$routeoverhead]set MisBehRatio [expr $MisBehRatio+$misbehratio]}puts $rohgraph "$MisBehRatio $RouteOverhead"$ns_ at [expr $now+$time] "Overhead_Cal"}

## Procedure for Misbehaviour_NODE graph..set pktStatus [open PktStatus.tr w]proc misbehaviour_Node {} {global ns_ set time 2.0set now [$ns_ now]set mon [new Monitor list]source "./Analysis_node.tcl"set nodeAnalysis_INFO [lindex $args(0) $args(1)]puts "The receive and forward packet calculation done here..."set pkt_recv_time [lindex $Rtime(0)]set pkt_forward_time [lindex $Ftime(1)]puts $pktStatus "$time $event"set event [lindex $pkt_recv_time $pkt_forward_time]## calculate the misbehaviourness for every node... \## Normally the misbehaviour node omit from the routing list...## Remove route node detection..source "./remove_RouteList.tcl"if {$remove_RouteList_node(0)==$remove_RouteList_node($6)} {puts $removeList "[lindex $totNodeList $remove_RouteList_node($6)]"}if {$remove_RouteList_node(0)==node_(2)} {set selectRouteNode node_($goodBehNode(0))}if {$remove_RouteList_node(0)==node_(5)} {set selectRouteNode node_($goodBehNode(0))}## Select the RouteNode list for every this procedure call..set selectRouteNode 0$ns_ at [expr $now+$time] "misbehaviour_Node"}

## Procedure for 2Ack call..set ackFile [open AckFile.tr w]proc 2Ack_CAL {} {global ns_ set time 2.0set now [$ns_ now]$self instvar avgTime eventsource "./2Ack_CAL.tcl"if {$7=="ack"} {put $ackFile [lindex $2 $7] 2Ack.tr > AckFile.tr }if {$7!="ack"} {

Page 64: Wireless Tcl Scripts

put "It is not Ack field" }}

## Procedure for Throughput..set edsrgraph [open Scheme(ThruPut).tr w]set neutgraph [open Neu.tr w]set edsr 100set neux 0$ns at 0.0 "ThroughPut"proc ThroughPut {} {global ns_ rootPath edsr dsr neux edsrgraph neutgraphset ns_ [Simulator instance]set time 1.5set now [$ns_ now]source "$rootPath/fig.tcl"$ns_ at [expr $now+$time] "ThroughPut"}

## Stop procedure..

proc stop {} {global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtrace

## Filtering the ack pkts from total simulation..exec grep "ack" "Scheme.tr" > tempack.doc #exec grep "0 1 0 800" tempdrop.tr > "$dropPath/drop1.tr"

## Filtering the dropped pkts from total simulation..exec grep "^D" "Scheme.tr" > tempdrop.doc

## Filtering the forwarded pkts from total simulation..exec grep "^f" "Scheme.tr" > tempforward.doc

## Filtering the received pkts from total simulation..exec grep "^r" "Scheme.tr" > temprxve.doc

## Filtering the sent pkts from total simulation..exec grep "^s" "Scheme.tr" > tempsend.docexec nam scheme.nam &exec xgraph -m -bb -geometry 700X400 -t Scheme(EDSR) -x MaliCSNode -y ThruPut edsr(tput).tr &exec xgraph -m -bb -geometry 700X400 -t Scheme(EDSR) -x MaliCSNode -y Total_Drop edsr(drop).tr &exit 0}

$ns run

# rootpath#commn

Page 65: Wireless Tcl Scripts

set interval 0.1

if {$now>=1.0 && $now<3.0} {set tcp(1) [$ns create-connection TCP/Newreno $node_(0) TCPSink $node_(4) 2]set ftp(1) [$tcp(1) attach-app FTP]$ftp(1) set packetSize_ 1000 $ftp(1) set interval_ .05$ns at $now "$ftp(1) start"$ns at [expr $now+$time] "$ftp(1) stop"}

if {$now>=3.0 && $now<4.0} {set tcp(1) [$ns create-connection TCP/Newreno $node_(0) TCPSink $node_(5) 2]set ftp(1) [$tcp(1) attach-app FTP]$ftp(1) set packetSize_ 1000 $ftp(1) set interval_ .05$ns at $now "$ftp(1) start"$ns at [expr $now+$time] "$ftp(1) stop"

set tcp(2) [$ns create-connection TCP/Newreno $node_(5) TCPSink $node_(4) 2]set ftp(2) [$tcp(2) attach-app FTP]$ftp(2) set packetSize_ 1000 $ftp(2) set interval_ .05$ns at $now "$ftp(2) start"$ns at [expr $now+$time] "$ftp(2) stop"

set tcp(3) [$ns create-connection TCP/Newreno $node_(5) TCPSink $node_(4) 2]set ftp(3) [$tcp(3) attach-app FTP]$ftp(3) set packetSize_ 1000 $ftp(3) set interval_ .05#$ns at $now "$ftp(3) start"#$ns at [expr $now+$time] "$ftp(3) stop"

set tcp(4) [$ns create-connection TCP/Newreno $node_(0) TCPSink $node_(4) 2]set ftp(4) [$tcp(4) attach-app FTP]$ftp(4) set packetSize_ 1000 $ftp(4) set interval_ .05#$ns at $now "$ftp(4) start"#$ns at [expr $now+$time] "$ftp(4) stop"}#anno$ns at 1.1025 "$ns trace-annotate \"Time: 1.1025 Pkt Transfer Path thru node_(2)..\""$ns at 1.28 "$ns trace-annotate \"Time: 1.2812 TrustValue Calculation..\""$ns at 1.28 "$ns trace-annotate \"Time: 1.2812 node_(2) act as misbehaviour..\""

# RouteOverhead Class RouteOverhead_ -superclass Agent/TCP/Newreno

RouteOverhead_ instproc init {routeOverhead_ misBehRatio_} {$self instvar routeOverhead$self instvar misBehRatioset routeOverhead $routeOverhead_set misBehRatio $misBehRatio_}

Page 66: Wireless Tcl Scripts

# fig.tcl

#set edsr 100#set dsr 90#set neux 0

if {$now<=6.5} {set Aflow [expr rand()*8];if {$Aflow<5} {set Aflow [expr 8+(rand()*3)]}#puts "$Aflow [expr $edsr-$Aflow]"set edsr [expr $edsr-$Aflow]puts $edsrgraph "$now $edsr"puts $neutgraph "$now $neux"}# setdest.tcl$ns at $now "$node_(0) setdest 2.0 145.0 20.0"$ns at $now "$node_(1) setdest 94.0 321.0 20.0"$ns at $now "$node_(2) setdest 242.0 192.0 20.0"

#### Counting the no of pktsFilename: count.txtawk 'BEGIN {print "_________________\nCounting RxvePkts"}'awk -f "/home/rootpath/count.awk" "/home/tamil/ rootpath /temprxve.doc"awk 'BEGIN {print "_________________\nCounting ForwardPkts"}'awk -f "/home/ rootpath /scheme/count.awk" "/home/tamil/ rootpath /tempsend.doc"awk 'BEGIN {print "_________________\nCounting SendPkts"}'awk -f "/home/ rootpath /scheme/count.awk" "/home/tamil/ rootpath /tempforward.doc"awk 'BEGIN {print "_________________\nCounting AckPkts"}'awk -f "/home/ rootpath /count.awk" "/home/ rootpath /scheme/tempack.doc"

# How to run$ ns test.tclcount.txt

# output

Page 67: Wireless Tcl Scripts
Page 68: Wireless Tcl Scripts
Page 69: Wireless Tcl Scripts

TCL Script for wireless udp communication with bidirectioal Nodes communication.

set val(chan) Channel/WirelessChannel ;#Channel Type

set val(prop) Propagation/TwoRayGround ;# radio-propagation model

set val(netif) Phy/WirelessPhy ;# network interface type

Page 70: Wireless Tcl Scripts

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) 15 ;# number of mobilenodes

set val(rp) AODV ;# routing protocol

set val(x) 1800

set val(y) 840

########## Setting The Simulator Objects

set ns_ [new Simulator]

set tracefd [open wireless.tr w]

$ns_ trace-all $tracefd

set namtrace [open wireless.nam w]

$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

set tracefd [open sample.tr w]

$ns_ trace-all $tracefd

set topo [new Topography]

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

create-god $val(nn)

set chan_1_ [new $val(chan)]

$ns_ color 1 dodgerblue

$ns_ color 2 blue

$ns_ color 3 cyan

$ns_ color 4 green

Page 71: Wireless Tcl Scripts

$ns_ color 5 yellow

$ns_ color 6 black

$ns_ color 7 magenta

$ns_ color 8 gold

$ns_ color 9 red

$ns_ color 10 cornflowerblue

$ns_ color 11 deepskyblue

$ns_ color 12 steelblue

$ns_ color 13 navy

#$ns_ color 14 darkolivergreen

#source "./test.tcl"

########## Setting The Distance Variables

# For model 'TwoRayGround'

set dist(5m) 7.69113e-06

set dist(9m) 2.37381e-06

set dist(10m) 1.92278e-06

set dist(11m) 1.58908e-06

set dist(12m) 1.33527e-06

set dist(13m) 1.13774e-06

set dist(14m) 9.81011e-07

set dist(15m) 8.54570e-07

set dist(16m) 7.51087e-07

set dist(20m) 4.80696e-07

set dist(25m) 3.07645e-07

set dist(30m) 2.13643e-07

Page 72: Wireless Tcl Scripts

set dist(35m) 1.56962e-07

set dist(40m) 1.56962e-10

set dist(45m) 1.56962e-11

set dist(50m) 1.20174e-13

Phy/WirelessPhy set CSThresh_ $dist(50m)

Phy/WirelessPhy set RXThresh_ $dist(50m)

########## Defining Node Configuration

$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 \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace ON \

-channel $chan_1_

########## Creating The WIRELESS NODES

set n1 [$ns_ node]

set n2 [$ns_ node]

set n3 [$ns_ node]

Page 73: Wireless Tcl Scripts

set n4 [$ns_ node]

set n5 [$ns_ node]

set n6 [$ns_ node]

# Setting The Initail Positions of NODE

$n1 set X_ 1053.0

$n1 set Y_ 635.0

$n1 set Z_ 0.0

$n2 set X_ 900.0

$n2 set Y_ 700.70

$n2 set Z_ 0.0

$n3 set X_ 700.0

$n3 set Y_ 600.0

$n3 set Z_ 0.0

$n4 set X_ 850.078

$n4 set Y_ 324.500

$n4 set Z_ 0.0

$n5 set X_ 980.0

$n5 set Y_ 452.0

$n5 set Z_ 0.0

$n6 set X_ 675.0

$n6 set Y_ 435.498

$n6 set Z_ 0.0

set xx [expr rand()]

set xx [expr round($xx * 900)]

set xx [format "%.1f" [expr $xx+[expr rand()*30]]]

Page 74: Wireless Tcl Scripts

set yy [expr rand()]

set yy [expr round($yy * 900)]

set yy [format "%.1f" [expr $yy+[expr rand()*30]]]

set zz [expr round(sqrt($xx*$xx+$yy*$yy))]

set zz [expr (1/cos($xx/$zz))*90]

set zz [expr round($zz)]

set now [$ns_ now]

$ns_ at $now "$n1 setdest $xx $yy 10.0"

$ns_ at $now "$n2 setdest $xx $yy 10.0"

$ns_ at $now "$n3 setdest $xx $yy 10.0"

$ns_ at $now "$n4 setdest $xx $yy 10.0"

$ns_ at $now "$n5 setdest $xx $yy 10.0"

$ns_ at $now "$n6 setdest $xx $yy 10.0"

#Setting The Node Size

$ns_ initial_node_pos $n1 60

$ns_ initial_node_pos $n2 80

$ns_ initial_node_pos $n3 60

$ns_ initial_node_pos $n4 60

$ns_ initial_node_pos $n5 40

$ns_ initial_node_pos $n6 60

#set tracefd [open schemels.tr w]

#$ns_ trace-all $tracefd

#Setting The Labels For Nodes

$ns_ at 0.0 "$n1 label N1"

$ns_ at 0.0 "$n2 label N2"

Page 75: Wireless Tcl Scripts

$ns_ at 0.0 "$n3 label N3"

$ns_ at 0.0 "$n4 label N4"

$ns_ at 0.0 "$n5 label N5"

$ns_ at 0.0 "$n6 label N6"

#Setting Color For nodes

$ns_ at 0.0 "$ns_ trace-annotate \"1-2 BIDIRECTION \""

$ns_ at 0.1 "$ns_ trace-annotate \"BEFORE IMPLEMENTING RDBFA\""

$n1 color green

$ns_ at 0.0 "$n1 color green"

$n2 color green

$ns_ at 0.0 "$n2 color green"

set udp0 [$ns_ create-connection UDP $n1 LossMonitor $n2 0]

$udp0 set fid_ 1

set cbr0 [$udp0 attach-app Traffic/CBR]

$cbr0 set packetSize_ 1000

$cbr0 set interval_ .07

$ns_ at 0.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE2\""

$ns_ at 0.2 "$cbr0 start"

$ns_ at 0.8 "$cbr0 stop"

$ns_ at 1.2 "$cbr0 start"

$ns_ at 1.8 "$cbr0 stop"

$ns_ at 1.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE2\""

set udp1 [$ns_ create-connection UDP $n2 LossMonitor $n1 0]

$udp1 set fid_ 9

set cbr1 [$udp1 attach-app Traffic/CBR]

Page 76: Wireless Tcl Scripts

$cbr1 set packetSize_ 500

$cbr1 set interval_ .07

$ns_ at 0.5 "$cbr1 start"

$ns_ at 0.5 "$ns_ trace-annotate \"NODE2 send pacts to NODE1\""

$ns_ at 0.8 "$cbr1 stop"

$ns_ at 1.6 "$cbr1 start"

$ns_ at 2.0 "$cbr1 stop"

set udp2 [$ns_ create-connection UDP $n2 LossMonitor $n4 0]

$udp2 set fid_ 1

set cbr2 [$udp2 attach-app Traffic/CBR]

$cbr2 set packetSize_ 10000

$cbr2 set interval_ .07

$ns_ at 2.2 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE2 to NODE4 \""

$ns_ at 2.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE4\""

$ns_ at 2.2 "$cbr2 start"

$ns_ at 3.5 "$cbr2 stop"

$n1 color black

$ns_ at 2.0 "$n1 color black"

set udp3 [$ns_ create-connection UDP $n4 LossMonitor $n2 0]

$udp3 set fid_ 1

set cbr3 [$udp3 attach-app Traffic/CBR]

$cbr3 set packetSize_ 10000

$cbr3 set interval_ .07

$ns_ at 3.5 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE2 to NODE4 \""

$ns_ at 3.6 "$ns_ trace-annotate \"NODE4 send pacts to NODE2\""

Page 77: Wireless Tcl Scripts

$ns_ at 3.6 "$cbr3 start"

$ns_ at 3.6 "$cbr3 stop"

$ns_ at 3.6 "$ns_ trace-annotate \"Node4-Node1 Failiar because there is no RDBFA\""

# REVERSE ROUTE

set udp4 [$ns_ create-connection UDP $n4 LossMonitor $n6 0]

$udp4 set fid_ 1

set cbr4 [$udp4 attach-app Traffic/CBR]

$cbr4 set packetSize_ 1000

$cbr4 set interval_ .07

$ns_ at 4.5 "$ns_ trace-annotate \"NOW NODE4 DISCOVER THE REVERSE ROUTE OF UNIDIRECTIONAL LINK N4->N1 TO N4->N6->N1\""

$ns_ at 4.6 "$ns_ trace-annotate \"NODE4 send pacts to NODE6\""

$ns_ at 4.6 "$cbr4 start"

$ns_ at 6.0 "$cbr4 stop"

set udp6 [$ns_ create-connection UDP $n2 LossMonitor $n6 0]

$udp6 set fid_ 1

set cbr6 [$udp6 attach-app Traffic/CBR]

$cbr6 set packetSize_ 2500

$cbr6 set interval_ .07

$ns_ at 4.5 "$ns_ trace-annotate \"NOW BRA USES THE DISTANCE VECTOR ALGORITHM\""

$ns_ at 4.6 "$ns_ trace-annotate \"NODE4 send pacts to NODE6\""

$ns_ at 4.6 "$cbr6 start"

$ns_ at 7.5 "$cbr6 stop"

set udp5 [$ns_ create-connection UDP $n6 LossMonitor $n2 0]

$udp5 set fid_ 1

set cbr5 [$udp5 attach-app Traffic/CBR]

Page 78: Wireless Tcl Scripts

$cbr5 set packetSize_ 1000

$cbr5 set interval_ .07

$ns_ at 4.7 "$ns_ trace-annotate \"NOW NODE6 USE BIDR LINK TO NODE1\""

$ns_ at 4.7 "$ns_ trace-annotate \"NODE6 send pacts to NODE1\""

$ns_ at 4.7 "$cbr5 start"

$ns_ at 7.5 "$cbr5 stop"

set udp7 [$ns_ create-connection UDP $n2 LossMonitor $n6 0]

$udp6 set fid_ 1

set cbr7 [$udp7 attach-app Traffic/CBR]

$cbr7 set packetSize_ 10000

$cbr7 set interval_ .07

$ns_ at 4.5 "$ns_ trace-annotate \"NOW BRA USES THE DISTANCE VECTOR ALGORITHM\""

$ns_ at 4.6 "$ns_ trace-annotate \"NODE4 send pacts to NODE6\""

$ns_ at 4.6 "$cbr6 start"

$ns_ at 7.5 "$cbr6 stop"

set udp8 [$ns_ create-connection UDP $n4 LossMonitor $n5 0]

$udp1 set fid_ 9

set cbr8 [$udp8 attach-app Traffic/CBR]

$cbr8 set packetSize_ 500

$cbr8 set interval_ .07

$ns_ at 7.6 "$cbr8 start"

#$ns_ at 0.5 "$ns_ trace-annotate \"NODE4 send pacts to NODE5\""

$ns_ at 8.2 "$cbr8 stop"

$ns_ at 8.6 "$cbr8 start"

$ns_ at 10.0 "$cbr8 stop"

Page 79: Wireless Tcl Scripts

set udp9 [$ns_ create-connection UDP $n5 LossMonitor $n4 0]

$udp9 set fid_ 1

set cbr9 [$udp9 attach-app Traffic/CBR]

$cbr9 set packetSize_ 10000

$cbr9 set interval_ .07

#$ns_ at 2.2 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE1 to NODE4 \""

#$ns_ at 2.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE4\""

$ns_ at 8.0 "$cbr9 start"

$ns_ at 8.6 "$cbr9 stop"

set udp10 [$ns_ create-connection UDP $n5 LossMonitor $n2 0]

$udp1 set fid_ 9

set cbr10 [$udp10 attach-app Traffic/CBR]

$cbr10 set packetSize_ 500

$cbr10 set interval_ .07

$ns_ at 10.1 "$cbr10 start"

#$ns_ at 0.5 "$ns_ trace-annotate \"NODE4 send pacts to NODE5\""

$ns_ at 10.8 "$cbr10 stop"

$ns_ at 11.4 "$cbr10 start"

$ns_ at 12.5 "$cbr10 stop"

set udp11 [$ns_ create-connection UDP $n2 LossMonitor $n5 0]

$udp11 set fid_ 1

set cbr11 [$udp11 attach-app Traffic/CBR]

$cbr11 set packetSize_ 1000

$cbr11 set interval_ .07

#$ns_ at 2.2 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE1 to NODE4 \""

Page 80: Wireless Tcl Scripts

#$ns_ at 2.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE4\""

$ns_ at 10.5 "$cbr11 start"

$ns_ at 11.0 "$cbr11 stop"

$n2 color brown

$ns_ at 2.2 "$n2 color brown"

$n4 color brown

$ns_ at 2.2 "$n4 color brown"

$n2 color red

$ns_ at 3.6 "$n2 color red"

$n4 color red

$ns_ at 3.6 "$n4 color red"

$n2 color black

$ns_ at 4.0 "$n2 color black"

$n4 color black

$ns_ at 4.0 "$n4 color black"

$n2 color blue

$ns_ at 4.6 "$n2 color blue"

$n4 color blue

$ns_ at 4.6 "$n4 color blue"

$n6 color blue

$ns_ at 4.6 "$n6 color blue"

$n2 color black

$ns_ at 7.6 "$n2 color black"

$n4 color black

$ns_ at 7.6 "$n4 color black"

Page 81: Wireless Tcl Scripts

$n6 color black

$ns_ at 7.6 "$n6 color black"

$n4 color green

$ns_ at 7.6 "$n4 color green"

$n5 color green

$ns_ at 7.6 "$n5 color green"

$n4 color black

$ns_ at 10.0 "$n4 color black"

$n5 color black

$ns_ at 12.5 "$n5 color black"

$n2 color green

$ns_ at 10.2 "$n2 color green"

$n2 color black

$ns_ at 12.6 "$n2 color black"

$ns_ at 12.6 "$n6 label N6FAIL's"

$n6 color yellow

$ns_ at 12.6 "$n6 color yellow"

$ns_ at 12.7 "$cbr6 start"

$ns_ at 13.5 "$cbr6 stop"

$ns_ at 12.6 "$n2 color blue"

$ns_ at 16.4 "$n2 color black"

$ns_ at 13.9 "$cbr11 start"

$ns_ at 16.0 "$cbr11 stop"

$n5 color blue

$ns_ at 14.0 "$n5 color blue"

Page 82: Wireless Tcl Scripts

$ns_ at 16.4 "$n5 color black"

$ns_ at 14.0 "$cbr9 start"

$ns_ at 16.3 "$cbr9 stop"

source "graph.tcl"

$n4 color blue

$ns_ at 14.0 "$n4 color blue"

$ns_ at 16.4 "$n4 color black"

$ns_ at 4.2 "$ns_ trace-annotate \"AFTER IMPLEMENTING RDBFA\""

#SETTING ANIMATION RATE

$ns_ at 0.0 "$ns_ set-animation-rate 10.0ms"

#PROCEDURE TO STOP

proc stop {} {

global ns_ tracefd

$ns_ flush-trace

close $tracefd

exec grep "^D" "sample.tr" > schemeld.tr

#exec grep "0 1 0 800" sample.tr > schemelc.tr

exec grep "^D" "sample.tr" > tempdrop.tr

#exec grep "0 2 0 800" sample.tr > "route(2-30).tr"

exec grep "^r" "sample.tr" > route(1-25).tr

#exec grep "0 3 0 800" sample.tr > "mroute(30).tr"

exec grep "^r" "sample.tr" > maodvpd.tr

#exec grep "0 4 0 800" sample.tr > "maodvlc.tr"

exec grep "^r" "sample.tr" > delay(benifit).tr

#exec grep "0 1 0 800" "sample.tr" > "cache(benifit).tr"

Page 83: Wireless Tcl Scripts

exec nam wireless.nam &

exit 0

}

puts "Starting Simulation........"

$ns_ at 25.0 "stop"

$ns_ run

TCL script to find wireless packet dropping nodes.

#how to run this program...

# $ns test.tcl

if {$argc != 0} {

error "\nCommand: ns test.tcl\n\n "

}

## set the rootPath's..

set rootPath "./"

Page 84: Wireless Tcl Scripts

##--------------------------------------------------------------------------------------------##

## A wireless distributed intrusion detection system and a new attack model ##

##--------------------------------------------------------------------------------------------##

## Setting The wireless Channels..

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) 5 ;# max packet in ifq

set val(nn) 8 ;# number of mobilenodes

set val(rp) DSR ;# routing protocol

set val(x) 750 ;# X dimension of topography

set val(y) 500 ;# Y dimension of topography

set val(stop) 9.95 ;# time of simulation end

## Create a simulator object(nothing but, a scheduler's object)..

set ns [new Simulator]

## Create a trace file and nam file..

set tracefd [open dsr.tr w]

set namtrace [open dsr.nam w]

## Trace the nam and trace details from the main simulation..

$ns trace-all $tracefd

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

Page 85: Wireless Tcl Scripts

## set up topography object..

set topo [new Topography]

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

create-god $val(nn)

## Color Descriptions..

$ns color 1 dodgerblue

$ns color 2 blue

$ns color 3 cyan

$ns color 4 green

$ns color 5 yellow

$ns color 6 black

$ns color 7 magenta

$ns color 8 gold

$ns color 9 red

$ns color 10 cornflowerblue

$ns color 11 deepskyblue

$ns color 12 steelblue

$ns color 13 navy

#$ns color 14 darkolivergreen

$ns color 15 brown

$ns color 16 darkorange

$ns color 17 orange

$ns color 18 darksalmon

$ns color 19 salmon

$ns color 20 greenyellow

Page 86: Wireless Tcl Scripts

$ns color 21 darkslategray

$ns color 22 darkkhaki

$ns color 23 darkorchid

$ns color 24 darkviolet

$ns color 25 darkcyan

$ns color 26 darkmagenta

## Setting The Distance Variables..

# For model 'TwoRayGround'

set dist(5m) 7.69113e-06

set dist(9m) 2.37381e-06

set dist(10m) 1.92278e-06

set dist(11m) 1.58908e-06

set dist(12m) 1.33527e-06

set dist(13m) 1.13774e-06

set dist(14m) 9.81011e-07

set dist(15m) 8.54570e-07

set dist(16m) 7.51087e-07

set dist(20m) 4.80696e-07

set dist(25m) 3.07645e-07

set dist(30m) 2.13643e-07

set dist(35m) 1.56962e-07

set dist(40m) 1.56962e-10

set dist(45m) 1.56962e-11

set dist(50m) 1.20174e-13

#Phy/WirelessPhy set CSThresh_ $dist(50m)

Page 87: Wireless Tcl Scripts

#Phy/WirelessPhy set RXThresh_ $dist(50m)

## Setting node config event with set of inputs..

puts "Node Configuration Started here...\n \

-channel $val(chan) \n \

-adhocRouting $val(rp) \n \

-llType $val(ll) \n \

-macType $val(mac) \n \

-ifqType $val(ifq) \n \

-ifqLen $val(ifqlen) \n \

-antType $val(ant) \n \

-propType $val(prop) \n \

-phyType $val(netif) \n"

$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 \

Page 88: Wireless Tcl Scripts

-movementTrace ON

## Creating node objects..

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

# set node_($i) [$ns node]

#}

set node_(0) [$ns node]

set node_(1) [$ns node]

$ns node-config -ifqLen 2

set node_(2) [$ns node]

$ns node-config -ifqLen 50

set node_(3) [$ns node]

set node_(4) [$ns node]

set node_(5) [$ns node]

set node_(6) [$ns node]

set node_(7) [$ns node]

## Provide initial location of mobilenodes..

$node_(0) set X_ 27.0

$node_(0) set Y_ 260.0

$node_(0) set Z_ 0.0

$node_(1) set X_ 137.0

$node_(1) set Y_ 348.0

$node_(1) set Z_ 0.0

$node_(2) set X_ 294.0

$node_(2) set Y_ 235.0

$node_(2) set Z_ 0.0

Page 89: Wireless Tcl Scripts

$node_(3) set X_ 414.0

$node_(3) set Y_ 342.0

$node_(3) set Z_ 0.0

$node_(4) set X_ 562.0

$node_(4) set Y_ 267.0

$node_(4) set Z_ 0.0

$node_(5) set X_ 279.0

$node_(5) set Y_ 447.0

$node_(5) set Z_ 0.0

$node_(6) set X_ -128.0

$node_(6) set Y_ 260.0

$node_(6) set Z_ 0.0

$node_(7) set X_ 727.0

$node_(7) set Y_ 269.0

$node_(7) set Z_ 0.0

## 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

}

## Set a TCP connection between node_(0) and node_(1)..

$ns at 1.0 "commn"

proc commn {} {

global ns node_ rootPath

set now [$ns now]

Page 90: Wireless Tcl Scripts

set time 0.6

set time1 4.1

source "$rootPath/commn1.tcl";$ns at [expr $now+$time1] "commn"

}

$ns at 1.0 "$ns trace-annotate \"Node1 Dropping some packets\""

$ns at 2.0 "$ns trace-annotate \"Again node1 dropping some packets\""

$ns at 3.0 "$ns trace-annotate \"Node1 Make the Periodicall data dropping Attack\""

$ns at 3.0 "$ns trace-annotate \"Now the Node1 activity is called Blackhole\""

$node_(0) color black

$node_(1) color black

$ns at 3.0 "$node_(1) color red"

$ns at 3.0 "$node_(1) label Per_drop_attack"

## Generation of movements-Destination setting..

$ns at 0.0 "Mobility"

proc Mobility {} {

global ns node_ rootPath

set ns_ [Simulator instance]

set time 1.0

set moveTime 0.5

set now [$ns now]

source "$rootPath/setdest.tcl"

$ns_ at [expr $now+$time] "Mobility"

}

#source "$rootPath/annotate.tcl"

## Telling nodes when the simulation ends..

Page 91: Wireless Tcl Scripts

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

$ns at $val(stop) "$node_($i) reset";

}

## Procedure for pktDeliveryRatio graph..

set PktDelRatio 0.98

set MisBehRatio 0

set pdrgraph [open pdratio(DSR).tr w]

$ns at 0.1 "PktDelRatio"

proc PktDelRatio {} {

global ns rootPath pdrgraph PktDelRatio MisBehRatio pktdelratio misbehratio

set ns_ [Simulator instance]

set time 1.2

set now [$ns_ now]

source "$rootPath/PDRatio.tcl"

if {$now<1.2} {set PktDelRatio 0.98;set MisBehRatio 0}

if {$now>1.2} {

set PktDelRatio [expr $PktDelRatio-$pktdelratio]

set MisBehRatio [expr $MisBehRatio+$misbehratio]

}

puts $pdrgraph "$MisBehRatio $PktDelRatio"

$ns_ at [expr $now+$time] "PktDelRatio"

}

## Procedure for RouteOverhead graph..

set RouteOverhead 0.98

set MisBehRatio 0

Page 92: Wireless Tcl Scripts

set rohgraph [open routeOH(DSR).tr w]

$ns at 0.1 "Overhead_Cal"

proc Overhead_Cal {} {

global ns rootPath rohgraph RouteOverhead MisBehRatio routeoverhead misbehratio

set ns_ [Simulator instance]

set time 1.2

set now [$ns_ now]

source "$rootPath/RouteOverHead.tcl"

if {$now<1.2} {set RouteOverhead 0.01;set MisBehRatio 0}

if {$now>1.2} {

set RouteOverhead [expr $RouteOverhead+$routeoverhead]

set MisBehRatio [expr $MisBehRatio+$misbehratio]

}

puts $rohgraph "$MisBehRatio $RouteOverhead"

$ns_ at [expr $now+$time] "Overhead_Cal"

}

## 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"

## Setting Animation Rate..

$ns at 0.0 "$ns set-animation-rate 6.50ms"

## Stop procedure..

proc stop {} {

global ns tracefd namtrace

Page 93: Wireless Tcl Scripts

$ns flush-trace

close $tracefd

close $namtrace

exec nam dsr.nam &

exit 0

}

Tcl script to High density wireless network.

how to run this program...

# $ns benefit.tcl

if {$argc != 1} {

error "\nCommand: ns test.tcl <no_of_nodes> ex: ns bf.tcl 15 \n\n"

}

## set the rootPath's..

#-------------------------- Wireless Configuration --------------------------#

Page 94: Wireless Tcl Scripts

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 nn [lindex $argv 0] ;# numberof mobilenodes

set val(rp) AODV ;# routing protocol

set val(x) 1000

set val(y) 1000

set val(stop) 10

#---------------------------- Setting The Simulator Objects

set ns_ [new Simulator]

set tracefd [open test.tr w]

$ns_ trace-all $tracefd

set namtrace [open test.nam w]

$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]

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

create-god $nn

set chan_1_ [new $val(chan)]

#--------------------------- Setting The Distance Variables

# For model 'TwoRayGround'

Page 95: Wireless Tcl Scripts

set dist(5m) 7.69113e-06

set dist(9m) 2.37381e-06

set dist(10m) 1.92278e-06

set dist(11m) 1.58908e-06

set dist(12m) 1.33527e-06

set dist(13m) 1.13774e-06

set dist(14m) 9.81011e-07

set dist(15m) 8.54570e-07

set dist(16m) 7.51087e-07

set dist(20m) 4.80696e-07

set dist(25m) 3.07645e-07

set dist(30m) 2.13643e-07

set dist(35m) 1.56962e-07

set dist(40m) 1.56962e-10

set dist(45m) 1.56962e-11

set dist(50m) 1.20174e-13

Phy/WirelessPhy set CSThresh_ $dist(50m)

Phy/WirelessPhy set RXThresh_ $dist(50m)

#------------------------ Defining Node Configuration

$ns_ node-config -adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

Page 96: Wireless Tcl Scripts

-propType $val(prop) \

-phyType $val(netif) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace ON \

-channel $chan_1_

#------------------------- Creating The WIRELESS NODES

set i 0

while {$i<$nn} {

set n($i) [$ns_ node]

#set ele(i) 2

incr i

}

set cbr_size 500

set ele(0) 2

set ele(1) 2

set ele(2) 2

set ele(3) 2

set ele(4) 2

set ele(5) 0

set ele(6) 2

set ele(7) 2

set ele(8) 2

Page 97: Wireless Tcl Scripts

set ele(9) 2

set ele(10) 2

set ele(11) 2

set ele(12) 2

set ele(13) 2

set ele(14) 2

#source "./intpos.tcl"

for {set a 0} {$a <$nn} {incr a} {

# if { $a!=1 && $a!=2 && $a!=13 } {

$ns_ initial_node_pos $n($a) 40

#}

$n($a) color blue

}

for {set i 0} {$i < $nn } { incr i } {

#set a [expr rand()*$i*200]

#set b [expr rand()*2000]

set xx [expr rand()*800]

set yy [expr rand()*800]

$n($i) set X_ $xx

$n($i) set Y_ $yy

$n($i) set Z_ 0.0

}

$ns_ at 0.0 "destination"

proc destination {} {

global ns_ n nn

Page 98: Wireless Tcl Scripts

set time 3.0

set now [$ns_ now]

for {set i 0} {$i<$nn} {incr i} {

set xx [expr rand()*200]

set yy [expr rand()*50]

set speed [expr rand()*15]

$ns_ at $now "$n($i) setdest $xx $yy 10"

if { $speed>7 && $speed<15 } {

$ns_ at $now "$n($i) setdest $xx $yy $speed"

}

}

$ns_ at [expr $now+$time] "destination"

}

for {set i 0} {$i < $nn } {incr i} {

set udp_($i) [new Agent/UDP]

set null_($i) [new Agent/Null]

}

#$ns_ attach-agent $n(0) $udp_(0)

#$ns_ attach-agent $n(7) $udp_(1)

#$ns_ attach-agent $n(2) $udp_(2)

#$ns_ attach-agent $n(7) $udp_(3)

#$ns_ attach-agent $n(6) $null_(0)

#$ns_ attach-agent $n(1) $null_(1)

#$ns_ attach-agent $n(8) $null_(2)

for {set i 0} {$i < $nn } {incr i} {

Page 99: Wireless Tcl Scripts

set k [expr $i*10]

if { $k==$i} {

set k [expr $k%($nn+1)]

}

if { $k>=$nn} {

set k [expr $k%$nn]

}

$ns_ attach-agent $n($i) $udp_($i)

$ns_ attach-agent $n($k) $null_($i)

$ns_ connect $udp_($i) $null_($i)

}

$ns_ at 0.0 "communication"

proc communication {} {

global ns_ n nn udp_ cbr_ cbr_size

set time 3.0

set now [$ns_ now]

for {set i 0} {$i < $nn } {incr i} {

set cbr_($i) [new Application/Traffic/CBR]

$cbr_($i) set packetSize_ $cbr_size

$cbr_($i) set interval_ 0.5

$cbr_($i) attach-agent $udp_($i)

$ns_ at $i "$cbr_($i) start"

}

#$ns_ at [expr $now+$time] "communication"

}

Page 100: Wireless Tcl Scripts

source "bra.tcl"

if {$nn > 15} {

source "topology.tcl"

}

proc stop {} {

global ns_ tracefd

$ns_ flush-trace

close $tracefd

exec nam test.nam &

exit 0

}

bra

$ns_ at 30.0 "stop"

$ns_ run