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) \ -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 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 nam
for {set i 0} {$i < $val(nn)} { incr i } { $ns initial_node_pos $node_($i) 30 }

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; }

# Ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10.01 "puts \"end simulation\"; $ns halt"

#stop procedure:
proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless1.nam & } $ns run

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

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 $ns at 0.nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON # Creating node objects. set tracefd [open wireless2.#-------Event scheduler object creation--------# set ns [new Simulator] #Creating trace file and nam file..0 "$node_($i) color cyan" .tr w] set namtrace [open wireless2.

0 $node_(3) set Y_ 160.0 $node_(6) set X_ 400.01 "puts \"end simulation\" .0 $node_(7) set X_ 3s50.0 $node_(4) set Y_ 250.0 $node_(0) set Y_ 30.0 $node_(1) set Z_ 0.0 $node_(0) set Z_ 0.0 $node_(1) set Y_ 25.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 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".0 $node_(6) set Z_ 0.0 $node_(2) set X_ 200.0 $node_(4) set Z_ 0.0 $node_(6) set Y_ 350.0 $node_(3) set X_ 350.0 $node_(7) set Z_ 0.0 $node_(2) set Z_ 0.0 $node_(7) set Y_ 470.0 $node_(3) set Z_ 0.0 $node_(5) set Y_ 100.0 $node_(5) set X_ 300.} # Provide initial location of mobilenodes $node_(0) set X_ 5. $ns halt" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace .0 $node_(4) set X_ 100.0 $node_(1) set X_ 50. } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10.0 $node_(5) set Z_ 0.0 $node_(2) set Y_ 90.

tcl # snapshot of the program output Tcl script to create dynamic wirless nodes with AODV. there is no any other connection between the nodes. Set node_ ($i) [$ns node] is used to create the nodes. After that $Val (stop) is used to tell to nodes when the simulation ends. File name: “wireless1. After creating the nam file and trace file.nam & } $ns run # How to run the program $ns wireless2. Otherwise it will cause error.tcl” . The main thing of the program is how much node u has to give that much node only will create. we set up topography object. Here nodes have color. Description: In this program used to generate the nodes only.exec nam wireless2. Here we set the initial position for the every node by using initial_node_pos.

of.tcl <no.tr w] set namtrace [open wireless1.if {$argc != 1} { error "\nCommand: ns 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) \ -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 \ .mobile-nodes>\n\n " } #-------Event scheduler object creation--------# set ns [new Simulator] #creating the trace file and nam file set tracefd [open wireless1.

0 $node_(4) set Z_ 0.0 $node_(10) set X_ 505.0 "$node_($i) color yellow" } # Provide initial location of mobilenodes $node_(0) set X_ 27.0 $node_(4) set X_ 562.0 $node_(1) set Z_ 0.0 $node_(0) set Y_ 260.0 $node_(5) set X_ 279.0 $node_(4) set Y_ 267.0 $node_(2) set Y_ 235.0 $node_(7) set Z_ 0.0 $node_(1) set X_ 137.0 $node_(7) set Y_ 269.0 $node_(5) set Y_ 447.0 $node_(7) set X_ 727.0 $node_(1) set Y_ 348.0 $node_(2) set Z_ 0.0 $node_(3) set X_ 414. 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_(8) set Y_ 126.0 $node_(3) set Y_ 342.0 $node_(6) set X_ -128.0 $node_(8) set X_ 130.0 $node_(6) set Y_ 260.0 $node_(3) set Z_ 0.0 $node_(9) set Y_ 45.0 $node_(8) set Z_ 0.0 $node_(2) set X_ 294.-movementTrace ON ## Creating node objects.0 $node_(10) set Z_ 0.0 $node_(9) set Z_ 0.0 $node_(0) set Z_ 0.0 $node_(6) set Z_ 0.0 ..0 $node_(10) set Y_ 446.0 $node_(9) set X_ 318.0 $node_(5) 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 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".0 $node_(11) set Z_ 0.01 "puts \"end simulation\" .$node_(11) set X_ 421.tcl # snapshot of the program output . } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10.nam & } $ns run # How to run the program $ns wireless1.0 $node_(11) set Y_ 158. $ns halt" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless1.

tcl <no.tcl” if {$argc != 1} { error "\nCommand: ns wireless3.of. After creating the nam file and trace file. Here we set the initial position for the every node by using initial_node_pos. Description: In this program used to generate the nodes only.mobile-nodes>\n\n " } .Tcl script to create dynamic wirless nodes.set initial postion.and set color of node with AODV. Set node_ ($i) [$ns node] is used to create the nodes. we set up topography object. Here nodes have color. there is no any other connection between the nodes. File name: “wireless3. Otherwise it will cause error. After that $Val (stop) is used to tell to nodes when the simulation ends. The main thing of the program is how much node you has to give that much node only will create.

tr w] set namtrace [open wireless3..nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON ## Creating node objects. for {set i 0} {$i < $val(nn) } { incr i } { .#-------Event scheduler object creation--------# set ns [new Simulator] #creating the trace file and nam file set tracefd [open wireless3.

0 "$node_($i) color gold" } ## Provide initial location of mobilenodes..tcl # snapshot of the program output . } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10..nam & } $ns run # How to run the program $ns wireless3. $ns halt" #stop procedure. proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless3.. for {set i 0} {$i < $val(nn) } { incr i } { set xx [expr rand()*600] set yy [expr rand()*600] $node_($i) set X_ $xx $node_($i) set Y_ $yy } # Define node initial position in nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".set node_($i) [$ns node] } for {set i 0} {$i < $val(nn) } {incr i } { $node_($i) color gold $ns at 0.01 "puts \"end simulation\" .

Description: This network has 4 nodes. Here nodes has change its color randomly.Tcl script to change the nodes color at a time. After creating the nam file and trace file. Set node_ ($i) [$ns node] is used to create the nodes. we set up topography object.tcl” . After that $Val (stop) is used to tell to nodes when the simulation ends. File name: “wireless1. Here we set the initial position for the every node by using initial_node_pos. there is no any other connection between the nodes.

set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] ## Color Descriptions.56962e-11 set dist(50m) 1.#-------Event scheduler object creation--------# set ns [new Simulator] ## Create a trace file and nam file.56962e-07 set dist(40m) 1.. $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) ## set up topography object.33527e-06 set dist(13m) 1.07645e-07 set dist(30m) 2. set tracefd [open wireless1.20174e-13 #Phy/WirelessPhy set CSThresh_ $dist(50m) #Phy/WirelessPhy set RXThresh_ $dist(50m) .13774e-06 set dist(25m) 3. $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..tr w] set namtrace [open wireless1....58908e-06 set dist(12m) 1.92278e-06 set dist(11m) 1..13643e-07 set dist(35m) 1. # For model 'TwoRayGround' set dist(5m) 7. set colorname(0) blue set colorname(1) cyan set colorname(2) green set colorname(3) red set colorname(4) gold set colorname(5) magenta ## Setting The Distance Variables..56962e-10 set dist(45m) 1.37381e-06 set dist(10m) 1.69113e-06 set dist(9m) 2.nam w] ## Trace the nam and trace details from the main simulation.

$ns at 0. 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. for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam. $ns at $val(stop) "stop" proc stop {} { ....0 } ## Define node initial position in nam.3 set 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 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.## Setting node config event with set of inputs.0 "$node_($i) color blue" } ## Provide initial location of mobilenodes. $ns initial_node_pos $node_($i) 30 } ## Dynamic color procedure....0 "dynamic-color" proc dynamic-color {} { global ns val node_ colorname set time 0.

global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace puts "running nam.tcl # snapshot of the program: .... $ns wireless1.nam & exit 0 } $ns runs #how to run this program." exec nam wireless1..

File name: “wireless3.tcl <no. After that $Val (stop) is used to tell to nodes when the simulation ends.of. Set node_ ($i) [$ns node] is used to create the nodes. There is no any other connection between the nodes. Here different nodes have different color.tcl” if {$argc != 1} { error "\nCommand: ns test2. we set up topography object. Here we set the initial position for the every node by using initial_node_pos.mobile-nodes>\n\n " } .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. After creating the nam file and trace file.

set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] ## Color Descriptions..37381e-06 set dist(10m) 1..nam w] ## Trace the nam and trace details from the main simulation...13774e-06 set dist(25m) 3.07645e-07 set dist(30m) 2.13643e-07 set dist(35m) 1.tr w] set namtrace [open wireless2. set tracefd [open wireless2.. # For model 'TwoRayGround' set dist(5m) 7.69113e-06 set dist(9m) 2. $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.58908e-06 set dist(12m) 1. $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) ## set up topography object.#-------Event scheduler object creation--------# set ns [new Simulator] ## Create a trace file and nam file.56962e-10 set dist(45m) 1.56962e-07 set dist(40m) 1.33527e-06 set dist(13m) 1.92278e-06 set dist(11m) 1.56962e-11 .

$node_(0) set X_ 27.20174e-13 #Phy/WirelessPhy set CSThresh_ $dist(50m) #Phy/WirelessPhy set RXThresh_ $dist(50m) ## Setting node config event with set of inputs.0 "$node_($i) color yellow" } for {set i 4} {$i < 10 } {incr i } { $node_($i) color red $ns at 3.0 $node_(3) set X_ 414.0 $node_(2) set X_ 294.0 $node_(4) set X_ 562.0 $node_(1) set Z_ 0.0 "$node_($i) color blue" } ## Provide initial location of mobilenodes. $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.set dist(50m) 1..0 $node_(2) set Y_ 235.0 $node_(3) set Y_ 342..0 $node_(1) set X_ 137. 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_(2) set Z_ 0.0 "$node_($i) color red" } for {set i 10} {$i < 15 } {incr i } { $node_($i) color blue $ns at 5.0 ..0 $node_(0) set Y_ 260.0 $node_(0) set Z_ 0.0 $node_(1) set Y_ 348.0 $node_(3) set Z_ 0.

0 $node_(7) set Y_ 269.0 $node_(8) set Z_ 0..0 $node_(7) set Z_ 0.0 $node_(11) set Y_ 158. $ns initial_node_pos $node_($i) 30 } ## Stop procedure.0 $node_(12) set Y_ 397.0 "destination" proc destination {} { global ns val node_ set time 1.0 $node_(5) set X_ 279.0 $node_(10) set Y_ 446.0 $node_(4) set Z_ 0..0 $node_(6) set Y_ 260.0 $node_(12) set X_ 72.0 $node_(11) set X_ 421..0 $node_(11) set Z_ 0.0 $node_(5) set Y_ 447.0 $node_(6) set Z_ 0.0 $node_(6) set X_ -128.$node_(4) set Y_ 267.0 } } ## Define node initial position in nam.0 $node_(12) set Z_ 0.0 $node_(9) set Y_ 45.0 $node_(10) set Z_ 0. for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam.0 $node_(10) set X_ 505.0 $node_(7) set X_ 727.0 $node_(5) set Z_ 0. $ns at 0.0 $node_(8) set Y_ 126.0 $node_(9) set Z_ 0.0 $node_(8) set X_ 130.0 $node_(9) set X_ 318.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 set now [$ns now] for {set i 0} {$i<$val(nn)} {incr i} { set xx [expr rand()*600] set yy [expr rand()*500] .

tcl #snapshot of the program: ." exec nam wireless2.$ns at $now "$node_($i) setdest $xx $yy 20.nam & exit 0 } $ns run # How to run the program: $ns wireless2...0" } $ns at [expr $now+$time] "destination" } $ns at $val(stop) "stop" #stop procedure: proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace puts "running nam.

As default. the nodes have Tcp connection.0 sec and stop at 150. the maximum size of a packet that a "tcp" agent can generate is 1KByte. we set up topography object.Tcl script to make tcp communication between wireless nodes.node1 and node2. File name: “wireless1. and a connection is established to a tcp "sink" agent attached to node0. A "tcp" agent is attached to Client1. Description: This network consists of 3 nodes. After creating the nam file and trace file. Here we were using AODV routing protocol.tcl” #-------Event scheduler object creation--------# set ns [new Simulator] #creating trace file and nam file set tracefd [open wireless1. Set node_ ($i) [$ns node] is used to create the nodes.tr w] set namtrace [open wireless1. A tcp "sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. After that $Val (stop) is used to tell to nodes when the simulation ends. The ftp is set to start at 10.tr w] set windowVsTime2 [open win.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) 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) \ . Here we set the initial position for the every node by using initial_node_pos.0 sec.

0 $node_(1) set X_ 490.0" # Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_(0) $tcp $ns attach-agent $node_(1) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 10.0 "$node_(0) setdest 250.0 $node_(2) set X_ 150.0 $node_(0) set Y_ 5.0 250.0 5.0 $node_(0) set Z_ 0.01 set now [$ns now] set cwnd [$tcpSource set cwnd_] .0 "$ftp start" set tcp [new Agent/TCP/Newreno] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_(1) $tcp $ns attach-agent $node_(2) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 10.-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" $ns at 15.0 285.0 $node_(2) set Y_ 240.0 $node_(1) set Z_ 0.0 $node_(2) set Z_ 0.0 5.0" $ns at 19.0 "$ftp start" # Printing the window size proc plotWindow {tcpSource file} { global ns set time 0.0 $node_(1) set Y_ 285.0 3.0 "$node_(2) setdest 480.0 300.0 # Generation of movements $ns at 10.0 "$node_(1) setdest 45.

0 "plotWindow $tcp $windowVsTime2" # Define node initial position in nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10. } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 150.01 "puts \"end simulation\" . $ns halt" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam simwrls.tcl #snapshot of the program: .nam & } $ns run # How to run the program: $ns wireless1.

Here we were using DSR routing protocol.0 sec. After that $Val (stop) is used to tell to nodes when the simulation ends. Set node_ ($i) [$ns node] is used to create the nodes. A tcp "sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. the maximum size of a packet that a "tcp" agent can generate is 1KByte. The ftp is set to start at 10. After creating the nam file and trace file. the nodes have Tcp connection.Tcl script for implementing DSR routing protocol in wireless network. Description: This network consists of 3 nodes. we set up topography object.tcl” . and a connection is established to a tcp "sink" agent attached to node0 and node1. A "tcp" agent is attached to Client1. Here we set the initial position for the every node by using initial_node_pos. File name: “Dsr.0 sec and stop at 150. As default.

0 .#-------Event scheduler object creation--------# set ns [new Simulator] #Creating trace file and nam file set tracefd [open dsr.0 $node_(0) set Y_ 5.tr w] set windowVsTime2 [open win.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) 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.tr w] set namtrace [open dsr.

0" $ns at 15.0 5.0" # Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_(0) $tcp $ns attach-agent $node_(1) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 10.0 # Generation of movements $ns at 10.0 $node_(1) set Z_ 0.0 "$ftp start" # Printing the window size proc plotWindow {tcpSource file} { global ns set time 0.0 "$node_(0) setdest 480.01 set now [$ns now] set cwnd [$tcpSource set cwnd_] puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.0 $node_(2) set Y_ 240. $ns halt" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace .$node_(0) set Z_ 0.0 "$node_(1) setdest 45.0 250.0 $node_(1) set Y_ 285. } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 150.0 $node_(1) set X_ 490.0 3.0" $ns at 110.0 $node_(2) set Z_ 0.0 $node_(2) set X_ 150.0 300.0 5.01 "puts \"end simulation\" .0 285.1 "plotWindow $tcp $windowVsTime2" # Define node initial position in nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".0 "$node_(0) setdest 250.

nam & exit 0 } $ns run # How to run the program: $ns dsr.tcl #snapshot of the program: .exec nam dsr.

the maximum size of a packet that "udp" agent can generate is 1KByte. An "udp" agent is attached to node0. Here we set the initial position for the every node by using initial_node_pos.1 sec. Here we were using AODV routing protocol. Set node_ ($i) [$ns node] is used to create the nodes. File name: “Aodv. After creating the nam file and trace file. As default. the nodes have Tcp connection. Description: This network consists of 22 nodes. A tcp "null" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets.0 sec and stop at 4. After that $Val (stop) is used to tell to nodes when the simulation ends. and a connection is established to udp "null" agent attached to server1 and node18 and etc. The annotation trace is used to trace the details. The Cbr is set to start at 0. we set up topography object. server1 and server2 also created in this program..Tcl script for implementing AODV routing protocol in wireless network.tcl” .

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) \ .13643e-07 set dist(35m) 1.58908e-06 set dist(12m) 1.80696e-07 set dist(25m) 3.54570e-07 set dist(16m) 7.56962e-07 set dist(40m) 1.56962e-10 set dist(45m) 1.69113e-06 set dist(9m) 2.37381e-06 set dist(10m) 1.33527e-06 set dist(13m) 1.### Setting The Simulator Objects set ns_ [new Simulator] #create the nam and trace file: set tracefd [open aodv.81011e-07 set dist(15m) 8.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.56962e-11 set dist(50m) 1.92278e-06 set dist(11m) 1.07645e-07 set dist(30m) 2.51087e-07 set dist(20m) 4.13774e-06 set dist(14m) 9.

-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.0 $Server1 set Z_ 0.0 $Server2 set Y_ 474.1 set a [ns-random $opt(seed)] set i 0 while {$i < 5} { incr i } ### Setting The Initial Positions of Nodes $Server1 set X_ 513.0 $Server1 set Y_ 517.0 $Server2 set Z_ 0.0 $n2 set Z_ 0.0 $n2 set X_ 36.0 $n2 set Y_ 529.0 $Server2 set X_ 1445.0 .

0 $n5 set Z_ 0.0 $n13 set Z_ 0.0 $n6 set Y_ 291.0 $n10 set Z_ 0.0 $n11 set Y_ 194.0 $n3 set Y_ 666.0 $n5 set Y_ 403.0 $n12 set Y_ 361.0 $n13 set Y_ 167.0 $n8 set Y_ 335.0 $n9 set X_ 334.0 $n6 set Z_ 0.0 $n10 set X_ 304.0 $n7 set Y_ 419.0 $n6 set X_ 230.0 $n12 set Z_ 0.0 $n4 set Y_ 552.0 $n14 set Z_ 0.0 $n8 set Z_ 0.0 $n14 set Y_ 546.0 $n4 set Z_ 0.0 $n10 set Y_ 777.0 $n16 set X_ 489.0 .0 $n14 set X_ 349.0 $n8 set X_ 363.0 $n11 set Z_ 0.0 $n11 set X_ 412.0 $n13 set X_ 569.0 $n3 set Z_ 0.0 $n16 set Z_ 0.0 $n15 set Z_ 0.0 $n4 set X_ 201.0 $n5 set X_ 147.0 $n16 set Y_ 794.0 $n7 set X_ 295.0 $n12 set X_ 519.0 $n7 set Z_ 0.0 $n15 set Y_ 668.$n3 set X_ 143.0 $n9 set Z_ 0.0 $n15 set X_ 466.0 $n9 set Y_ 647.

0" $ns_ at 0.0 $n17 set Y_ 711.0 624.0 487.0" $ns_ at 1.50 "$n8 setdest 505.0 799.0 20.0 $n21 set Z_ 0.75 "$n22 setdest 839.0 25.0 302.0 $n19 set Z_ 0.0 757.0 27.0" ## Setting The Node Size $ns_ initial_node_pos $Server1 75 $ns_ initial_node_pos $Server2 75 $ns_ initial_node_pos $n2 40 $ns_ initial_node_pos $n3 40 $ns_ initial_node_pos $n4 40 $ns_ initial_node_pos $n5 40 $ns_ initial_node_pos $n6 40 .0 $n17 set Z_ 0.0" $ns_ at 0.75 "$n3 setdest 556.25 "$n13 setdest 551.0 $n18 set Y_ 626.0" $ns_ at 1.25 "$n11 setdest 899.0 $n20 set X_ 741.0 20.0" $ns_ at 1.50 "$n12 setdest 598.0 20.0" $ns_ at 0.0 20.0 728.0 $n20 set Z_ 0.0 25.0" $ns_ at 0.75 "$n2 setdest 379.0 349.0 $n18 set X_ 630.0 548.0 $n21 set Y_ 264.0 809.0 $n22 set Z_ 0.20 "$n4 setdest 309.0 25.0" $ns_ at 1.0 25.0 25.25 "$n10 setdest 494.75 "$n18 setdest 741.0" $ns_ at 0.0 $n21 set X_ 882.0 $n19 set X_ 666.0" $ns_ at 0.0 $n22 set Y_ 441.0" $ns_ at 1.0 ## Giving Mobility to Nodes $ns_ at 0.75 "$n19 setdest 437.0" $ns_ at 1.20 "$n20 setdest 159.0" $ns_ at 1.25 "$n15 setdest 748.0 20.0 25.0 25.0 688.0 211.0" $ns_ at 0.0 $n18 set Z_ 0.75 "$n6 setdest 139.25 "$n16 setdest 842.0" $ns_ at 0.0 20.25 "$n9 setdest 274.0 333.0 20.0" $ns_ at 0.0 475.0" $ns_ at 1.0 $n22 set X_ 761.0" $ns_ at 1.0 20.0 350.25 "$n17 setdest 678.0 20.0 722.25 "$n21 setdest 700.0 $n20 set Y_ 152.0" $ns_ at 0.0 20.0 63.0 623.0 124.25 "$n5 setdest 179.0 647.0" $ns_ at 1.0 $n19 set Y_ 347.0 20.0 20.0 20.25 "$n14 setdest 397.75 "$n7 setdest 320.$n17 set X_ 606.0 444.0 20.

71 "$n9 color blue" $n5 color blue $ns_ at 7.29 "$n2 color blue" $n16 color blue $ns_ at 7.0ms" # COLORING THE NODES $n9 color blue $ns_ at 4.55 "$n9 label \"\"" $n12 color blue $ns_ at 7.0 "$Server2 label Server2" #Setting Color For Server $Server1 color maroon $ns_ at 0.44 "$n9 color maroon" $ns_ at 7.0 "$Server1 color maroon" $Server2 color maroon $ns_ at 0.0 "$ns_ set-animation-rate 15.0 "$n5 color blue" $n2 color blue $ns_ at 7.59 "$n16 color blue" $n9 color maroon $ns_ at 7.85 "$n12 color blue" #### Establishing Communication set udp0 [$ns_ create-connection UDP $Server1 LossMonitor $n18 0] .0 "$Server2 color maroon" ## SETTING ANIMATION RATE $ns_ at 0.$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.43 "$n9 label TTLover" $ns_ at 7.

1 "$cbr1 start" $ns_ at 4.$udp0 set fid_ 1 set cbr0 [$udp0 attach-app Traffic/CBR] $cbr0 set packetSize_ 1000 $cbr0 set interval_ .1 "$cbr3 stop" set udp4 [$ns_ create-connection UDP $Server1 LossMonitor $n14 0] $udp4 set fid_ 1 set cbr4 [$udp4 attach-app Traffic/CBR] $cbr4 set packetSize_ 1000 $cbr4 set interval_ 5 $ns_ at 4.0 "$cbr4 start" $ns_ at 4.1 "$cbr6 stop" set udp7 [$ns_ create-connection UDP $n14 LossMonitor $n4 0] $udp7 set fid_ 1 set cbr7 [$udp7 attach-app Traffic/CBR] .07 $ns_ at 0.1 "$cbr4 stop" set udp5 [$ns_ create-connection UDP $n15 LossMonitor $n16 0] $udp5 set fid_ 1 set cbr5 [$udp5 attach-app Traffic/CBR] $cbr5 set packetSize_ 1000 $cbr5 set interval_ 5 $ns_ at 4.1 "$cbr2 stop" set udp3 [$ns_ create-connection UDP $Server1 LossMonitor $n15 0] $udp3 set fid_ 1 set cbr3 [$udp3 attach-app Traffic/CBR] $cbr3 set packetSize_ 1000 $cbr3 set interval_ 5 $ns_ at 4.1 "$cbr5 stop" set udp6 [$ns_ create-connection UDP $n15 LossMonitor $n17 0] $udp6 set fid_ 1 set cbr6 [$udp6 attach-app Traffic/CBR] $cbr6 set packetSize_ 1000 $cbr6 set interval_ 5 $ns_ at 4.0 "$cbr3 start" $ns_ at 4.1 "$cbr1 stop" set udp2 [$ns_ create-connection UDP $n21 LossMonitor $n20 0] $udp2 set fid_ 1 set cbr2 [$udp2 attach-app Traffic/CBR] $cbr2 set packetSize_ 1000 $cbr2 set interval_ .0 "$cbr0 stop" set udp1 [$ns_ create-connection UDP $Server1 LossMonitor $n22 0] $udp1 set fid_ 1 set cbr1 [$udp1 attach-app Traffic/CBR] $cbr1 set packetSize_ 1000 $cbr1 set interval_ .07 $ns_ at 2.0 "$cbr6 start" $ns_ at 4.0 "$cbr5 start" $ns_ at 4.07 $ns_ at 0.4 "$cbr2 start" $ns_ at 4.0 "$cbr0 start" $ns_ at 4.

71 "$ns_ trace-annotate \"NODE10 CACHE THE DATA\"" ### PROCEDURE TO STOP proc stop {} { global ns_ tracefd $ns_ flush-trace .1 "$cbr8 stop" set udp9 [$ns_ create-connection UDP $n4 LossMonitor $n3 0] $udp9 set fid_ 1 set cbr9 [$udp9 attach-app Traffic/CBR] $cbr9 set packetSize_ 1000 $cbr9 set interval_ 5 $ns_ at 4.0 "$cbr12 start" $ns_ at 4.0 "$cbr9 start" $ns_ at 4.59 "$ns_ trace-annotate \"PACKET LOSS AT NODE27\"" $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_ 1 set cbr12 [$udp12 attach-app Traffic/CBR] $cbr12 set packetSize_ 1000 $cbr12 set interval_ 5 $ns_ at 4.1 "$cbr7 stop" set udp8 [$ns_ create-connection UDP $n14 LossMonitor $n9 0] $udp8 set fid_ 1 set cbr8 [$udp8 attach-app Traffic/CBR] $cbr8 set packetSize_ 1000 $cbr8 set interval_ 5 $ns_ at 4.1 "$cbr12 stop" #ANNOTATIONS DETAILS $ns_ at 0.0 "$ns_ trace-annotate \"MOBILE NODE MOVEMENTS\"" $ns_ at 4.0 "$cbr7 start" $ns_ at 4.1 "$cbr10 stop" set udp11 [$ns_ create-connection UDP $n9 LossMonitor $n16 0] $udp11 set fid_ 1 set cbr11 [$udp11 attach-app Traffic/CBR] $cbr11 set packetSize_ 1000 $cbr11 set interval_ 5 $ns_ at 4.1 "$cbr9 stop" set udp10 [$ns_ create-connection UDP $n4 LossMonitor $n2 0] $udp10 set fid_ 1 set cbr10 [$udp10 attach-app Traffic/CBR] $cbr10 set packetSize_ 1000 $cbr10 set interval_ 5 $ns_ at 4.$cbr7 set packetSize_ 1000 $cbr7 set interval_ 5 $ns_ at 4.0 "$cbr8 start" $ns_ at 4.0 "$cbr10 start" $ns_ at 4.1 "$ns_ trace-annotate \"NODE27 CACHE THE DATA FRO SERVER\"" #$ns_ at 4.

" $ns_ at 25. The nodes have Udp connection. the maximum size of a packet that "udp" agent can generate is ... As default.. server1 and server2 also created in this program. Set node_ ($i) [$ns node] is used to create the nodes...tcl #snapshot of the program: Tcl script for implementing DSDV routing protocol in wireless network. An "udp" agent is attached to node0. and a connection is established to udp "null" agent attached to node0 and node1 and etc. After that $Val (stop) is used to tell to nodes when the simulation ends.... After creating the nam file and trace file. Here we set the initial position for the every node by using initial_node_pos.close $tracefd exec nam datacache. Description: This network consists of 3 nodes.nam & exit 0 } puts "Starting Simulation.. we set up topography object.0 "stop" $ns_ run # How to run the program: $ns aodv1.

File name: “dsdv. An udp "null" agent generates and sends ACK packets to the sender (udp agent) and frees the received packets. Here we were using DSDV routing protocol.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) 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] } .tcl” #Creating trace file and nam file set tracefd [open dsdv.1KByte. The Cbr is set to start at 0.tr w] set windowVsTime2 [open win.tr w] set namtrace [open dsdv.1 sec.0 sec and stop at 4.

# 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_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_(0) $tcp $ns attach-agent $node_(1) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 10.0 "$ftp start"

# Printing the window size
proc plotWindow {tcpSource file} { global ns set time 0.01 set 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 nam
for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 }

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; }

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 150.01 "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefd namtrace

$ns flush-trace close $tracefd close $namtrace exec nam dsdv.nam & exit 0 } $ns run

# How to run the program: $ns dsdv.tcls #snapshot of the program:

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 options
set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(ifq) Queue/DropTail/PriQueue ;# interface queue type set val(ll) LL ;# link layer type set val(ant) Antenna/OmniAntenna ;# antenna model set val(ifqlen) 50 ;# max packet in ifq set val(nn) 5 ;# number of mobilenodes set val(rp) AODV ;# routing protocol set val(x) 500 ;# X dimension of topography set 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 object
set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)]

# configure the nodes
$ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON

## Creating node objects..
for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] } for {set i 0} {$i < $val(nn) } {incr i } { $node_($i) color black

0 "destination" proc destination {} { global ns val node_ set time 1..0 set 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. } #Destination procedure.0" } $ns at [expr $now+$time] "destination" } $ns at $val(stop) "stop" #Stop procedure proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless1.tcl . 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 nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset". $ns at 0.nam & } $ns run # How to run the program: $ns wireless1.$ns at 0..0 "$node_($i) color black" } ## Provide initial location of mobilenodes.

#snapshot of the program: Tcl script to set nodes destination and color randomly .0 sec.# interface queue type set val(ll) LL .# radio-propagation model set val(netif) Phy/WirelessPhy . The number of nodes has different colors. After that $Val (stop) is used to tell to nodes when the simulation ends. Here we set the initial position for the every node by using initial_ node_ pos. AODV routing protocol are used.tcl” # Define setting options set val(chan) Channel/WirelessChannel . In this process we were set Random destination node using destination method.# network interface type set val(mac) Mac/802_11 . Set node_ ($i) [$ns node] is used to create the nodes. After creating the nam file and trace file. we set up topography object. The nam and simulation end at 10.# max packet in ifq .# link layer type set val(ant) Antenna/OmniAntenna .# antenna model set val(ifqlen) 50 .# channel type set val(prop) Propagation/TwoRayGround .# MAC type set val(ifq) Queue/DropTail/PriQueue . Destination: This network has 8 nodes. The nodes are generating dynamically using destination procedure. File name: “wireless2. there is no any other connection between the nodes.

nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON ## Creating node objects.# Y dimension of topography set val(stop) 10 .tr w] set namtrace [open wireless2.# X dimension of topography set val(y) 400 .# number of mobilenodes set val(rp) AODV .0 "$node_($i) color cyan" } for {set i 5} {$i < 8 } { incr i } { set node_($i) [$ns node] } . 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 < 5 } {incr i } { $node_($i) color cyan $ns at 0.set val(nn) 8 ..# time of simulation end set ns [new Simulator] #Creating nam and trace file: set tracefd [open wireless2.# routing protocol set val(x) 500 .

.0 set 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..tcl . $ns at $val(stop) "stop" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless2.nam & } $ns run # How to run the program: $ns wireless2. $ns at 0.0 "$node_($i) color red" } ## Provide initial location of mobilenodes.. } # dynamic destination setting procedure.for {set i 5} {$i < 8 } {incr i } { $node_($i) color red $ns at 0.0" } $ns at [expr $now+$time] "destination" } #stop procedure. 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 nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".0 "destination" proc destination {} { global ns val node_ set time 1.

AODV routing protocol are used.# link layer type set val(ant) Antenna/OmniAntenna .0 sec and node 6 to 8 varies at 2. The nam and simulation end at 10.0 sec. The number of nodes has different colors.0 sec. node4 to 6 have color at 1. In this process we were set Random destination node using destination method. After creating the nam file and trace file.# channel type set val(prop) Propagation/TwoRayGround . we set up topography object. File name: “wireless3. Destination: This network has 8 nodes.# MAC type set val(ifq) Queue/DropTail/PriQueue . The nodes are generating dynamically using destination procedure.0 sec.# antenna model . Set node_ ($i) [$ns node] is used to create the nodes. there is no any other connection between the nodes.tcl” # Define options set val(chan) Channel/WirelessChannel . Here we set the initial position for the every node by using initial_ node_ pos.Node0 to 3 have color at 0.# interface queue type set val(ll) LL .# radio-propagation model set val(netif) Phy/WirelessPhy .#snapshot of the program: Tcl script to set nodes initail and destination position randomly. After that $Val (stop) is used to tell to nodes when the simulation ends.# network interface type set val(mac) Mac/802_11 .

# max packet in ifq set val(nn) 8 .tr w] set namtrace [open wireless3.# X dimension of topography set val(y) 400 .# Y dimension of topography set val(stop) 10 .set val(ifqlen) 50 .0 "$node_($i) color cyan" } for {set i 6} {$i < 8 } { incr i } { .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.# routing protocol set val(x) 500 .# number of mobilenodes set val(rp) AODV .nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON ## Creating node objects..# time of simulation end #Creating simulation: set ns [new Simulator] #Creating nam and trace file: set tracefd [open wireless3. 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.

. $ns at $val(stop) "stop" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless3.0 "destination" proc destination {} { global ns val node_ set time 1. $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 nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"..set node_($i) [$ns node] } for {set i 5} {$i < 8 } {incr i } { $node_($i) color red $ns at 2..0 set 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.nam & } $ns run # How to run the program: . } # dynamic destination setting procedure.

there is no any other connection between the nodes. File name: “graph1. Here we set the initial position for the every node by using initial_node_pos.tcl” .tcl #snapshot of the program: Tcl script to draw the graph and set x and y coordinates randomly. X and Y parameter generate randomly. After creating the nam file and trace file. Here we make graph using graph procedure. AODV routing protocol were used here.$ns wireless3. In this program used to generate the nodes only. we set up topography object. Here nodes have no color. Description: This network has 3 nodes. After that $Val (stop) is used to tell to nodes when the simulation ends. Set node_ ($i) [$ns node] is used to create the nodes.

. 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.tr w] set namtrace [open Graph1.nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON ## Creating node objects.# Creating simulation set ns [new Simulator] #Creating nam and trace file set tracefd [open Graph1.0 "$node_($i) color black" .

tr w] proc Graph {} { global ns g set time 1. } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10.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 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".0 $node_(2) set X_ 300.0 $node_(1) set Y_ 250.} # Provide initial location of mobilenodes $node_(0) set X_ 50.0 "Graph" set g [open graph.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 200. $ns at 1.0 $node_(2) set Y_ 300. $ns halt" #Graph procedure.01 "puts \"end simulation\" .0 set now [$ns now] puts $g "[expr rand()*8] [expr rand()*6]" $ns at [expr $now+$time] "Graph" } #Stop proceture proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec xgraph -M -bb -geometry 700X800 graph.0 $node_(0) set Y_ 50.nam & exit 0 } .0 $node_(2) set Z_ 0.tr & exec nam Graph1..0 $node_(1) set Z_ 0.

Here we set the initial position for the every node by using initial_node_pos. In this program used to generate the nodes only. there is no any other connection between the nodes. we set up topography object. After creating the nam file and trace file. AODV routing protocol were used here. Description: This network has 3 nodes. X and Y parameter generate randomly.$ns run # How to run the program $ns Graph1. Here we make two graph using graph procedure.tcl # snapshot of the program output Tcl script to generate graph at take two parameter files as input. File name: “graph2. After that $Val (stop) is used to tell to nodes when the simulation ends.tcl” . Here nodes have no color. Set node_ ($i) [$ns node] is used to create the nodes.

nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON ## Creating node objects..# Creating simulation set ns [new Simulator] #Creating nam and trace file set tracefd [open Graph2.tr w] set namtrace [open Graph2. 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" .

01 "puts \"end simulation\" .0 "Graph" set g [open graph.0 set 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" } #stop procedure: proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec xgraph -P -bb -geometry 700X800 graph.0 $node_(1) set Z_ 0. } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10.nam & exit 0 .tr graph1.0 $node_(2) set X_ 300.0 $node_(2) set Y_ 300.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 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".0 $node_(2) set Z_ 0.tr & exec nam Graph2.tr w] set g1 [open graph1. $ns halt" #Graph procedure.0 $node_(1) set X_ 200.. #procedure. $ns at 1.0 $node_(0) set Z_ 0..0 $node_(0) set Y_ 50.0 $node_(1) set Y_ 250.} # Provide initial location of mobilenodes $node_(0) set X_ 50.tr w] proc Graph {} { global ns g g1 set time 1.

and a member function called "greet" for each class. and instvar checks if the following variable name is already declared in its class or in its superclass. the keyword new is used. to create an object instance. each object instance is declared.tcl” # Add a member function call”greet” Class Teacher Teacher instproc init {subject} { . Description: An OTcl script that defines two object classes. 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. Finally. In defining member functions. $self acts same as the "this" pointer in C++.} $ns run # How to run the program $ns Graph2. where "Student" is the child class of "teacher". 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. After the class definitions.tcl # snapshot of the program output Otcl coding to create classes and objects. File name: “Otcl. "teacher" and "student".

Here we set the initial position for the every node by using initial_node_pos. Set node_ ($i) [$ns node] is used to create the nodes. Misbehaviour_NODE graph. There is no any other connection between the nodes. Here we use some procedure.tcl # output snapshot AWK file for data filettering.Dsr routing protocol were used here. Here different nodes have different color. Description: The main thing of the program is how much node you have to give that much node only will create. After that $Val (stop) is used to tell to nodes when the simulation ends.$self instvar subject_ set subject_ $subject } # Creating a child class of teacher and student Teacher instproc greet {} { $self instvar subject_ puts "$subject_ teacher ask which subject u studied?" } #creating a teacher and student object Class student -superclass Teacher student instproc greet {} { $self instvar subject_ puts "$subject_ say i studied maths" } # calling member function “greet” of each node set a [new Teacher maths] set b [new student Jey] $a greet $b greet #how to run $ns <filename>. we set up topography object. . that is pktDeliveryRatio graph. After creating the nam file and trace file. for RouteOverhead graph. Count file is used to filtering the ack packets.

. drop packets.92278e-06 set dist(11m) 1.forwarded packets. File name: “test..33527e-06 set dist(13m) 1.tcl” ## Create a simulator object(nothing but. $ns color 1 dodgerblue $ns color 2 blue $ns color 3 cyan $ns color 4 green $ns color 5 yellow ## Setting The Distance Variables.51087e-07 .tr w] set namtrace [open scheme. $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) ## set up topography object.nam w] ## Trace the nam and trace details from the main simulation.69113e-06 set dist(9m) 2..13774e-06 set dist(14m) 9.. send packets. set tracefd [open scheme.54570e-07 set dist(16m) 7. a scheduler's object).37381e-06 set dist(10m) 1. set ns [new Simulator] ## Create a trace file and nam file. # For model 'TwoRayGround' set dist(5m) 7..58908e-06 set dist(12m) 1.81011e-07 set dist(15m) 8. receving packets.. set topo [new Topography] $topo load_flatgrid $val(x) $val(y) set god_ [create-god $val(nn)] ## Color Descriptions.

20174e-13 #Phy/WirelessPhy set CSThresh_ $dist(50m) #Phy/WirelessPhy set RXThresh_ $dist(50m) ## Setting node config event with set of inputs.56962e-07 set dist(40m) 1.80696e-07 set dist(25m) 3.13643e-07 set dist(35m) 1.#if{$xx<=200} {set xx [expr 350+(rand()*150)]} set yy [expr rand()*500]. 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 darkgreen $ns at 0.56962e-10 set dist(45m) 1..56962e-11 set dist(50m) 1..07645e-07 set dist(30m) 2.0 "$node_($i) color darkgreen" } ## Provide initial location of mobilenodes. 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.0 } .set dist(20m) 4.#if{$yy<=200} {set yy [expr 350+(rand()*150)]} $node_($i) set X_ $xx $node_($i) set Y_ $yy $node_($i) set Z_ 0. if {$val(nn) >0} { for {set i 1} {$i < $val(nn) } { incr i } { set xx [expr rand()*600]...

$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..tcl".tcl" source "$rootPath/setdest.0 "commn" proc commn {} { global ns node_ rootPath set now [$ns now] set time 0.0 set moveTime 0. $ns at 1.0 "Mobility" proc Mobility {} { global ns node_ rootPath val set ns_ [Simulator instance] set time 1.5 set now [$ns now] #source "$rootPath/setdest1. $ns at 0.tcl" ## Telling nodes when the simulation ends.} ## set god distance.0 source "$rootPath/commn2. $ns initial_node_pos $node_($i) 30 } ## Set a TCP connection between node_(0) and node_(1).$ns at [expr $now+$time1] "commn" } ## Generation of movements-Destination setting. . for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam...tcl" $ns_ at [expr $now+$time] "Mobility" } #source "$rootPath/annotate..6 set time1 1...

01.2 set now [$ns_ now] source "$rootPath/RouteOverHead. } ## Ending nam and the simulation.for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset". set pktStatus [open PktStatus..# $ns halt ## Procedure for pktDeliveryRatio graph.0 set now [$ns_ now] .tr w] $ns at 0.set MisBehRatio 0} if {$now>1.98.tr w] $ns at 0.98 set MisBehRatio 0 set rohgraph [open routeOH(Scheme). $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 16.2} {set PktDelRatio 0.98 set MisBehRatio 0 set pdrgraph [open pdratio(Scheme).tcl" 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 RouteOverhead 0. set PktDelRatio 0.set MisBehRatio 0} if {$now>1..1 "Overhead_Cal" proc Overhead_Cal {} { global ns rootPath rohgraph RouteOverhead MisBehRatio routeoverhead misbehratio set ns_ [Simulator instance] set time 1.2} {set RouteOverhead 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..tr w] proc misbehaviour_Node {} { global ns_ set time 2.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..01 "puts \"end simulation\" " .

set mon [new Monitor list] source "..0 "ThroughPut" proc ThroughPut {} { global ns_ rootPath edsr dsr neux edsrgraph neutgraph set ns_ [Simulator instance] set time 1. set ackFile [open AckFile...tr w] set neutgraph [open Neu. source "... set selectRouteNode 0 $ns_ at [expr $now+$time] "misbehaviour_Node" } ## Procedure for 2Ack call.0 set now [$ns_ now] $self instvar avgTime event source ".tr > AckFile..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./remove_RouteList.tcl" $ns_ at [expr $now+$time] "ThroughPut" } ..tcl" set nodeAnalysis_INFO [lindex $args(0) $args(1)] puts "The receive and forward packet calculation done here.tr } if {$7!="ack"} { put "It is not Ack field" } } ## Procedure for Throughput.. \ ## Normally the misbehaviour node omit from the routing list./2Ack_CAL.tcl" if {$7=="ack"} { put $ackFile [lindex $2 $7] 2Ack.tr w] set edsr 100 set neux 0 $ns at 0. set edsrgraph [open Scheme(ThruPut)..5 set now [$ns_ now] source "$rootPath/fig. ## Remove route node detection." 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.tr w] proc 2Ack_CAL {} { global ns_ set time 2../Analysis_node.

tr > "$dropPath/drop1.nam & exec xgraph -m -bb -geometry 700X400 -t Scheme(EDSR) -x MaliCSNode -y ThruPut edsr(tput).0 && $now<3.doc ## Filtering the received pkts from total simulation.tr & exit 0 } $ns run # rootpath #commn set interval 0.1 if {$now>=1.. exec grep "^f" "Scheme. exec grep "^r" "Scheme. exec grep "^s" "Scheme.05 $ns at $now "$ftp(1) start" $ns at [expr $now+$time] "$ftp(1) stop" } if {$now>=3.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] .tr" > tempsend. exec grep "ack" "Scheme. proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace ## Filtering the ack pkts from total simulation.doc ## Filtering the sent pkts from total simulation.tr" > temprxve..tr" > tempack.tr" ## Filtering the dropped pkts from total simulation.doc ## Filtering the forwarded pkts from total simulation.doc #exec grep "0 1 0 800" tempdrop..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_ .## Stop procedure.tr & exec xgraph -m -bb -geometry 700X400 -t Scheme(EDSR) -x MaliCSNode -y Total_Drop edsr(drop)...tr" > tempforward..doc exec nam scheme. exec grep "^D" "Scheme.tr" > tempdrop.0 && $now<4.

28 "$ns trace-annotate \"Time: 1.$ftp(2) set packetSize_ 1000 $ftp(2) set interval_ .tcl #set edsr 100 #set dsr 90 #set neux 0 if {$now<=6.0 20.0 321.0 192.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.0" #### Counting the no of pkts Filename: count.awk" "/home/tamil/ rootpath /temprxve.\"" # RouteOverhead Class RouteOverhead_ -superclass Agent/TCP/Newreno RouteOverhead_ instproc init {routeOverhead_ misBehRatio_} { $self instvar routeOverhead $self instvar misBehRatio set routeOverhead $routeOverhead_ set misBehRatio $misBehRatio_ } # fig.0 20..\"" $ns at 1.0" $ns at $now "$node_(2) setdest 242.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_ .2812 node_(2) act as misbehaviour.05 #$ns at $now "$ftp(4) start" #$ns at [expr $now+$time] "$ftp(4) stop" } #anno $ns at 1.txt awk 'BEGIN {print "_________________\nCounting RxvePkts"}' awk -f "/home/rootpath/count.1025 Pkt Transfer Path thru node_(2).0 145..0 20.tcl $ns at $now "$node_(0) setdest 2.0" $ns at $now "$node_(1) setdest 94.\"" $ns at 1.2812 TrustValue Calculation..doc" .5} { set Aflow [expr rand()*8].1025 "$ns trace-annotate \"Time: 1.28 "$ns trace-annotate \"Time: 1.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_ .

doc" # How to run $ ns test.awk" "/home/tamil/ rootpath /tempsend.doc" awk 'BEGIN {print "_________________\nCounting SendPkts"}' awk -f "/home/ rootpath /scheme/count.txt # output .awk" "/home/ rootpath /scheme/tempack.awk 'BEGIN {print "_________________\nCounting ForwardPkts"}' awk -f "/home/ rootpath /scheme/count.doc" awk 'BEGIN {print "_________________\nCounting AckPkts"}' awk -f "/home/ rootpath /count.tcl count.awk" "/home/tamil/ rootpath /tempforward.

.

# network interface type set val(mac) Mac/802_11 .# MAC type .TCL Script for wireless udp communication with bidirectioal Nodes communication.#Channel Type set val(prop) Propagation/TwoRayGround .# radio-propagation model set val(netif) Phy/WirelessPhy . set val(chan) Channel/WirelessChannel .

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.# max packet in ifq set val(nn) 15 .# antenna model set val(ifqlen) 50 .# link layer type set val(ant) Antenna/OmniAntenna .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 $ns_ color 5 yellow .# interface queue type set val(ll) LL .# routing protocol set val(x) 1800 set val(y) 840 ########## Setting The Simulator Objects set ns_ [new Simulator] set tracefd [open wireless.# number of mobilenodes set val(rp) AODV .set val(ifq) Queue/DropTail/PriQueue .

/test.58908e-06 set dist(12m) 1.80696e-07 set dist(25m) 3.13774e-06 set dist(14m) 9.92278e-06 set dist(11m) 1.33527e-06 set dist(13m) 1.69113e-06 set dist(9m) 2.56962e-07 .54570e-07 set dist(16m) 7.13643e-07 set dist(35m) 1.81011e-07 set dist(15m) 8.07645e-07 set dist(30m) 2.37381e-06 set dist(10m) 1.$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 ".51087e-07 set dist(20m) 4.tcl" ########## Setting The Distance Variables # For model 'TwoRayGround' set dist(5m) 7.

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] set n4 [$ns_ node] .set dist(40m) 1.56962e-10 set dist(45m) 1.56962e-11 set dist(50m) 1.

0 $n3 set Z_ 0.0 $n2 set X_ 900.0 $n5 set X_ 980.1f" [expr $xx+[expr rand()*30]]] set yy [expr rand()] .set n5 [$ns_ node] set n6 [$ns_ node] # Setting The Initail Positions of NODE $n1 set X_ 1053.0 $n4 set X_ 850.0 $n1 set Y_ 635.0 $n5 set Y_ 452.500 $n4 set Z_ 0.0 $n1 set Z_ 0.0 $n6 set Y_ 435.0 $n2 set Y_ 700.498 $n6 set Z_ 0.0 $n5 set Z_ 0.70 $n2 set Z_ 0.0 $n6 set X_ 675.078 $n4 set Y_ 324.0 $n3 set X_ 700.0 $n3 set Y_ 600.0 set xx [expr rand()] set xx [expr round($xx * 900)] set xx [format "%.

0" $ns_ at $now "$n4 setdest $xx $yy 10.0" $ns_ at $now "$n5 setdest $xx $yy 10.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 "$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.0" $ns_ at $now "$n3 setdest $xx $yy 10.0 "$n2 label N2" $ns_ at 0.set yy [expr round($yy * 900)] set yy [format "%.0" $ns_ at $now "$n2 setdest $xx $yy 10.tr w] #$ns_ trace-all $tracefd #Setting The Labels For Nodes $ns_ at 0.0 "$n3 label N3" .0 "$n1 label N1" $ns_ at 0.

8 "$cbr0 stop" $ns_ at 1.2 "$cbr0 start" $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_ .0 "$n5 label N5" $ns_ at 0.07 $ns_ at 0.0 "$n4 label N4" $ns_ at 0.2 "$cbr0 start" $ns_ at 1.$ns_ at 0.0 "$n6 label N6" #Setting Color For nodes $ns_ at 0.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] $cbr1 set packetSize_ 500 .1 "$ns_ trace-annotate \"BEFORE IMPLEMENTING RDBFA\"" $n1 color green $ns_ at 0.0 "$ns_ trace-annotate \"1-2 BIDIRECTION \"" $ns_ at 0.0 "$n1 color green" $n2 color green $ns_ at 0.8 "$cbr0 stop" $ns_ at 1.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE2\"" $ns_ at 0.

6 "$ns_ trace-annotate \"NODE4 send pacts to NODE2\"" $ns_ at 3.5 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE2 to NODE4 \"" $ns_ at 3.5 "$cbr1 start" $ns_ at 0.2 "$cbr2 start" $ns_ at 3.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 0.5 "$ns_ trace-annotate \"NODE2 send pacts to NODE1\"" $ns_ at 0.2 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE2 to NODE4 \"" $ns_ at 2.6 "$cbr3 start" .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 2.07 $ns_ at 3.5 "$cbr2 stop" $n1 color black $ns_ at 2.$cbr1 set interval_ .8 "$cbr1 stop" $ns_ at 1.6 "$cbr1 start" $ns_ at 2.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE4\"" $ns_ at 2.

6 "$ns_ trace-annotate \"NODE4 send pacts to NODE6\"" $ns_ at 4.6 "$cbr3 stop" $ns_ at 3.$ns_ at 3.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_ .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.5 "$ns_ trace-annotate \"NOW BRA USES THE DISTANCE VECTOR ALGORITHM\"" $ns_ at 4.6 "$cbr6 start" $ns_ at 7.07 $ns_ at 4.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_ .6 "$cbr4 start" $ns_ at 6.5 "$cbr6 stop" set udp5 [$ns_ create-connection UDP $n6 LossMonitor $n2 0] $udp5 set fid_ 1 set cbr5 [$udp5 attach-app Traffic/CBR] $cbr5 set packetSize_ 1000 .07 $ns_ at 4.

6 "$cbr8 start" #$ns_ at 0.07 $ns_ at 4.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_ .0 "$cbr8 stop" set udp9 [$ns_ create-connection UDP $n5 LossMonitor $n4 0] .6 "$ns_ trace-annotate \"NODE4 send pacts to NODE6\"" $ns_ at 4.7 "$cbr5 start" $ns_ at 7.5 "$ns_ trace-annotate \"NODE4 send pacts to NODE5\"" $ns_ at 8.$cbr5 set interval_ .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_ .2 "$cbr8 stop" $ns_ at 8.6 "$cbr6 start" $ns_ at 7.07 $ns_ at 7.7 "$ns_ trace-annotate \"NOW NODE6 USE BIDR LINK TO NODE1\"" $ns_ at 4.6 "$cbr8 start" $ns_ at 10.07 $ns_ at 4.7 "$ns_ trace-annotate \"NODE6 send pacts to NODE1\"" $ns_ at 4.5 "$ns_ trace-annotate \"NOW BRA USES THE DISTANCE VECTOR ALGORITHM\"" $ns_ at 4.

8 "$cbr10 stop" $ns_ at 11.07 #$ns_ at 2.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_ .2 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE1 to NODE4 \"" #$ns_ at 2.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE4\"" $ns_ at 8.1 "$cbr10 start" #$ns_ at 0.0 "$cbr9 start" $ns_ at 8.5 "$ns_ trace-annotate \"NODE4 send pacts to NODE5\"" $ns_ at 10.07 $ns_ at 10.07 #$ns_ at 2.2 "$ns_ trace-annotate \"NODE1 send pacts to NODE4\"" .4 "$cbr10 start" $ns_ at 12.2 "$ns_ trace-annotate \"UNIDIRECTION LINK NODE1 to NODE4 \"" #$ns_ at 2.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_ .$udp9 set fid_ 1 set cbr9 [$udp9 attach-app Traffic/CBR] $cbr9 set packetSize_ 10000 $cbr9 set interval_ .

6 "$n2 color black" $n4 color black $ns_ at 7.0 "$n4 color black" $n2 color blue $ns_ at 4.0 "$n2 color black" $n4 color black $ns_ at 4.6 "$n6 color blue" $n2 color black $ns_ at 7.$ns_ at 10.2 "$n2 color brown" $n4 color brown $ns_ at 2.6 "$n4 color red" $n2 color black $ns_ at 4.2 "$n4 color brown" $n2 color red $ns_ at 3.6 "$n4 color blue" $n6 color blue $ns_ at 4.0 "$cbr11 stop" $n2 color brown $ns_ at 2.6 "$n2 color red" $n4 color red $ns_ at 3.6 "$n4 color black" $n6 color black .5 "$cbr11 start" $ns_ at 11.6 "$n2 color blue" $n4 color blue $ns_ at 4.

6 "$n6 color black" $n4 color green $ns_ at 7.0 "$n5 color blue" $ns_ at 16.7 "$cbr6 start" $ns_ at 13.$ns_ at 7.9 "$cbr11 start" $ns_ at 16.0 "$n4 color black" $n5 color black $ns_ at 12.6 "$n2 color blue" $ns_ at 16.6 "$n4 color green" $n5 color green $ns_ at 7.6 "$n6 label N6FAIL's" $n6 color yellow $ns_ at 12.4 "$n2 color black" $ns_ at 13.6 "$n6 color yellow" $ns_ at 12.5 "$cbr6 stop" $ns_ at 12.0 "$cbr11 stop" $n5 color blue $ns_ at 14.6 "$n2 color black" $ns_ at 12.5 "$n5 color black" $n2 color green $ns_ at 10.4 "$n5 color black" .2 "$n2 color green" $n2 color black $ns_ at 12.6 "$n5 color green" $n4 color black $ns_ at 10.

tr #exec grep "0 3 0 800" sample.4 "$n4 color black" $ns_ at 4.tr" > schemeld.2 "$ns_ trace-annotate \"AFTER IMPLEMENTING RDBFA\"" #SETTING ANIMATION RATE $ns_ at 0.tr" > tempdrop.3 "$cbr9 stop" source "graph.0 "$n4 color blue" $ns_ at 16.tr" exec nam wireless.$ns_ at 14.tr" exec grep "^r" "sample.tr" exec grep "^r" "sample.tr #exec grep "0 1 0 800" "sample.tr #exec grep "0 1 0 800" sample.tr > "mroute(30).tr #exec grep "0 2 0 800" sample.tr" > delay(benifit).tr > "route(2-30).tr" > "cache(benifit).0ms" #PROCEDURE TO STOP proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd exec grep "^D" "sample.0 "$ns_ set-animation-rate 10.tcl" $n4 color blue $ns_ at 14.0 "$cbr9 start" $ns_ at 16.tr" > route(1-25).nam & .tr" > maodvpd.tr > schemelc.tr" exec grep "^r" "sample.tr #exec grep "0 4 0 800" sample.tr > "maodvlc.tr exec grep "^D" "sample.

.tcl if {$argc != 0} { error "\nCommand: ns test.. # $ns test.." $ns_ at 25.. #how to run this program.......0 "stop" $ns_ run TCL script to find wireless packet dropping nodes.exit 0 } puts "Starting Simulation. set rootPath "./" ##--------------------------------------------------------------------------------------------## ## A wireless distributed intrusion detection system and a new attack model ## .tcl\n\n " } ## set the rootPath's.

.# time of simulation end ## Create a simulator object(nothing but.# X dimension of topography set val(y) 500 .# MAC type set val(ifq) Queue/DropTail/PriQueue .##--------------------------------------------------------------------------------------------## ## Setting The wireless Channels.# radio-propagation model set val(netif) Phy/WirelessPhy . set topo [new Topography] . set val(chan) Channel/WirelessChannel .# antenna model set val(ifqlen) 5 ... set tracefd [open dsr..nam w] ## Trace the nam and trace details from the main simulation. set ns [new Simulator] ## Create a trace file and nam file.# number of mobilenodes set val(rp) DSR .# Y dimension of topography set val(stop) 9.# network interface type set val(mac) Mac/802_11 .# interface queue type set val(ll) LL .95 .tr w] set namtrace [open dsr. $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) ## set up topography object.# channel type set val(prop) Propagation/TwoRayGround ..# link layer type set val(ant) Antenna/OmniAntenna .# max packet in ifq set val(nn) 8 . a scheduler's object).# routing protocol set val(x) 750 .

$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 $ns color 21 darkslategray $ns color 22 darkkhaki .

54570e-07 set dist(16m) 7.56962e-07 set dist(40m) 1..20174e-13 #Phy/WirelessPhy set CSThresh_ $dist(50m) #Phy/WirelessPhy set RXThresh_ $dist(50m) ## Setting node config event with set of inputs.80696e-07 set dist(25m) 3.37381e-06 set dist(10m) 1.58908e-06 set dist(12m) 1. # For model 'TwoRayGround' set dist(5m) 7.56962e-10 set dist(45m) 1.51087e-07 set dist(20m) 4.33527e-06 set dist(13m) 1.$ns color 23 darkorchid $ns color 24 darkviolet $ns color 25 darkcyan $ns color 26 darkmagenta ## Setting The Distance Variables.13774e-06 set dist(14m) 9.92278e-06 set dist(11m) 1.13643e-07 set dist(35m) 1..56962e-11 set dist(50m) 1.69113e-06 set dist(9m) 2.81011e-07 set dist(15m) 8. .07645e-07 set dist(30m) 2.

.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] #} 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.0 $node_(1) set Y_ 348.0 $node_(3) set X_ 414.0 $node_(3) set Y_ 342.0 .0 $node_(0) set Z_ 0. $node_(0) set X_ 27.0 $node_(1) set Z_ 0.0 $node_(1) set X_ 137.0 $node_(2) set X_ 294.0 $node_(2) set Y_ 235.0 $node_(2) set Z_ 0.0 $node_(0) set Y_ 260.

0 $node_(4) set Z_ 0.0 $node_(6) set Z_ 0.$node_(3) set Z_ 0..0 "commn" proc commn {} { global ns node_ rootPath set now [$ns now] set time 0. $ns at 1.0 $node_(6) set X_ -128.0 $node_(5) set Z_ 0.0 $node_(5) set X_ 279.0 $node_(4) set Y_ 267..0 $node_(4) set X_ 562.6 set time1 4.0 $node_(7) set X_ 727.0 $node_(7) set Z_ 0.1 .0 ## Define node initial position in nam.0 $node_(5) set Y_ 447. 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).0 $node_(6) set Y_ 260.0 $node_(7) set Y_ 269.

source "$rootPath/commn1..tcl" $ns_ at [expr $now+$time] "Mobility" } #source "$rootPath/annotate.0 "$ns trace-annotate \"Node1 Make the Periodicall data dropping Attack\"" $ns at 3.0 "$node_(1) color red" $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 set moveTime 0.0 "$ns trace-annotate \"Again node1 dropping some packets\"" $ns at 3. $ns at 0.0 "$ns trace-annotate \"Node1 Dropping some packets\"" $ns at 2. for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset".. .tcl".$ns at [expr $now+$time1] "commn" } $ns at 1.5 set now [$ns now] source "$rootPath/setdest.0 "Mobility" proc Mobility {} { global ns node_ rootPath set ns_ [Simulator instance] set time 1.tcl" ## Telling nodes when the simulation ends.0 "$node_(1) label Per_drop_attack" ## Generation of movements-Destination setting.

98 set MisBehRatio 0 set rohgraph [open routeOH(DSR).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.98.} ## Procedure for pktDeliveryRatio graph.1 "PktDelRatio" proc PktDelRatio {} { global ns rootPath pdrgraph PktDelRatio MisBehRatio pktdelratio misbehratio set ns_ [Simulator instance] set time 1.tr w] $ns at 0. set RouteOverhead 0..98 set MisBehRatio 0 set pdrgraph [open pdratio(DSR). set PktDelRatio 0..2} {set PktDelRatio 0.2 set now [$ns_ now] source "$rootPath/PDRatio.set MisBehRatio 0} if {$now>1.1 "Overhead_Cal" .tcl" if {$now<1.tr w] $ns at 0.

$ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 10..01 "puts \"end simulation\" .tcl" if {$now<1. proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd .. $ns at 0.set MisBehRatio 0} if {$now>1.01.proc Overhead_Cal {} { global ns rootPath rohgraph RouteOverhead MisBehRatio routeoverhead misbehratio set ns_ [Simulator instance] set time 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.2 set now [$ns_ now] source "$rootPath/RouteOverHead. $ns halt" ## Setting Animation Rate.0 "$ns set-animation-rate 6..50ms" ## Stop procedure.2} {set RouteOverhead 0.

tcl 15 \n\n" } ## set the rootPath's. how to run this program.Wireless Configuration --------------------------# set val(chan) Channel/WirelessChannel ..close $namtrace exec nam dsr.tcl if {$argc != 1} { error "\nCommand: ns test..# network interface type ..tcl <no_of_nodes> ex: ns bf.nam & exit 0 } Tcl script to High density wireless network. # $ns benefit.#Channel Type set val(prop) Propagation/TwoRayGround . #-------------------------.# radio-propagation model set val(netif) Phy/WirelessPhy .

# numberof mobilenodes set val(rp) AODV .92278e-06 .# MAC type set val(ifq) Queue/DropTail/PriQueue .37381e-06 set dist(10m) 1.Setting The Distance Variables # For model 'TwoRayGround' set dist(5m) 7.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)] #--------------------------.# routing protocol set val(x) 1000 set val(y) 1000 set val(stop) 10 #---------------------------.tr w] $ns_ trace-all $tracefd set namtrace [open test.# max packet in ifq set nn [lindex $argv 0] .Setting The Simulator Objects set ns_ [new Simulator] set tracefd [open test.set val(mac) Mac/802_11 .# interface queue type set val(ll) LL .69113e-06 set dist(9m) 2.# link layer type set val(ant) Antenna/OmniAntenna .# antenna model set val(ifqlen) 50 .

13774e-06 set dist(14m) 9.56962e-11 set dist(50m) 1.54570e-07 set dist(16m) 7.56962e-07 set dist(40m) 1.33527e-06 set dist(13m) 1.set dist(11m) 1.81011e-07 set dist(15m) 8.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 \ .58908e-06 set dist(12m) 1.07645e-07 set dist(30m) 2.20174e-13 Phy/WirelessPhy set CSThresh_ $dist(50m) Phy/WirelessPhy set RXThresh_ $dist(50m) #-----------------------.13643e-07 set dist(35m) 1.56962e-10 set dist(45m) 1.51087e-07 set dist(20m) 4.80696e-07 set dist(25m) 3.

-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 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 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} { 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" } 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 .

Sign up to vote on this title
UsefulNot useful