Wireless TCL Scripts
Wireless TCL Scripts
Wireless TCL Scripts
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
#stop procedure:
proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless1.nam & } $ns run
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
# How to run the program $ns wireless2.tcl # snapshot of the program output
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 nodes when the simulation ends. File name: wireless1.tcl
-movementTrace ON
# How to run the program $ns wireless1.tcl # snapshot of the program output
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 " }
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" }
#stop procedure...
proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless3.nam & } $ns run
# How to run the program $ns wireless3.tcl # snapshot of the program output
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
## Trace the nam and trace details from the main simulation..
$ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y)
## 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
## stop procedure..
$ns at $val(stop) "stop" proc stop {} {
global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace puts "running nam..." exec nam wireless1.nam & exit 0 } $ns runs
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 " }
## Trace the nam and trace details from the main simulation..
$ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y)
## 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
set dist(50m) 1.20174e-13 #Phy/WirelessPhy set CSThresh_ $dist(50m) #Phy/WirelessPhy set RXThresh_ $dist(50m)
$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 } }
## Stop procedure..
$ns at 0.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()*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-trace close $tracefd close $namtrace puts "running nam..." exec nam wireless2.nam & exit 0 } $ns run
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
-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] }
# 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"
puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.0 "plotWindow $tcp $windowVsTime2"
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
$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"
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
-antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace ON \ -movementTrace ON \ -channel $chan_1_
$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 $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
$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
$udp0 set fid_ 1 set 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_ 1 set 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_ 1 set 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_ 1 set 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_ 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 "$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.0 "$cbr5 start" $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 "$cbr6 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]
$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_ 1 set 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_ 1 set 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_ 1 set 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_ 1 set 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_ 1 set 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\"" $ns_ at 4.71 "$ns_ trace-annotate \"NODE10 CACHE THE DATA\""
close $tracefd exec nam datacache.nam & exit 0 } puts "Starting Simulation........" $ns_ at 25.0 "stop" $ns_ run
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 file set 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)
# 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"
$ns flush-trace close $tracefd close $namtrace exec nam dsdv.nam & exit 0 } $ns run
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.
#Destination procedure..
$ns at 0.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.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.nam & } $ns run
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 simulation end at 10.0 sec. File name: wireless2.tcl # Define setting 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) 8 ;# 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]
for {set i 5} {$i < 8 } {incr i } { $node_($i) color red $ns at 0.0 "$node_($i) color red" }
#stop procedure..
$ns at $val(stop) "stop" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless2.nam & } $ns run
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 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 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) 8 ;# 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
#Creating simulation:
set ns [new Simulator]
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" }
#stop procedure..
$ns at $val(stop) "stop" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam wireless3.nam & } $ns run
Tcl script to draw the graph and set x and y coordinates randomly.
Description: 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 simulation
set ns [new Simulator]
#Graph procedure..
$ns at 1.0 "Graph" set g [open graph.tr w] proc Graph {} { global ns g set time 1.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.tr & exec nam Graph1.nam & exit 0 }
$ns run
# How to run the program $ns Graph1.tcl # snapshot of the program output
Description: 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 simulation
set ns [new Simulator]
#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 g1 set time 1.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.tr graph1.tr & exec nam Graph2.nam & exit 0
} $ns run
# How to run the program $ns Graph2.tcl # snapshot of the program output
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, 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 callgreet
Class Teacher Teacher instproc init {subject} {
$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
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
## Color Descriptions..
$ns color 1 dodgerblue $ns color 2 blue $ns color 3 cyan $ns color 4 green $ns color 5 yellow
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)
for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; }
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" }
## Stop procedure..
proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace
# rootpath #commn
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 misBehRatio set routeOverhead $routeOverhead_ set misBehRatio $misBehRatio_ }
# 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"
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"
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 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 $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 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] 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]]] 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" $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] $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\"" $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] $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" 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 \"" #$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" $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" $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" exec nam wireless.nam &
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 "./" ##--------------------------------------------------------------------------------------------## ## 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) ## 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 $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) #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] #} 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 $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] 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.. 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 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 $ns flush-trace close $tracefd
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 --------------------------# 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' 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) \ -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 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