You are on page 1of 19

set num_nodes 24

set MESSAGE_PORT 42
set BROADCAST_ADDR -1

# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation
model
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ll) LL ;# Link layer type
set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type
set val(ifqlen) 250 ;# max packet in ifq
set val(netif) Phy/WirelessPhy ;# network interface
type
set val(mac) Mac/802_11 ;# MAC type
set val(nn) 24 ;# number of
mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1000
set opt(energymodel) EnergyModel ;# TOTALLY 150 JOULES
set opt(initialenergy) 0.01 ;# Initial energy in Joules
set val(y) 1000

Phy/WirelessPhy set CPThresh_ 10.0


Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set bandwidth_ 2e6
Phy/WirelessPhy set Pt_ 0.2818 ;# for 250.0

Phy/WirelessPhy set freq_ 914e+6


Phy/WirelessPhy set L_ 1.0

set ns [new Simulator]

#ns-random 0

set f [open 1_out.tr w]


$ns trace-all $f
set namtrace [open cluster-rechange.nam w]
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
$ns use-newtrace

set f0 [open n2-packets_received.tr w]


set f1 [open n11-packets_received.tr w]
set f2 [open n20-packets_received.tr w]
set f3 [open n18-packets_received.tr w]

set f21 [open n0-packets_received.tr w]


set f22 [open n1-packets_received.tr w]
set f23 [open n3-packets_received.tr w]
set f24 [open n4-packets_received.tr w]
set f25 [open n5-packets_received.tr w]
set f26 [open n6-packets_received.tr w]
set f27 [open n7-packets_received.tr w]
set f28 [open n8-packets_received.tr w]
set f29 [open n9-packets_received.tr w]
set f30 [open n10-packets_received.tr w]
set f31 [open n12-packets_received.tr w]
set f32 [open n13-packets_received.tr w]
set f33 [open n14-packets_received.tr w]
set f34 [open n15-packets_received.tr w]
set f35 [open n16-packets_received.tr w]
set f36 [open n17-packets_received.tr w]
set f37 [open n19-packets_received.tr w]
set f38 [open n21-packets_received.tr w]
set f39 [open n22-packets_received.tr w]
set f40 [open n23-packets_received.tr w]

set f4 [open n2-pdr.tr w]


set f5 [open n11-pdr.tr w]
set f6 [open n18-pdr.tr w]
set f7 [open n20-pdr.tr w]

set f8 [open n2-energy.tr w]


set f9 [open n11-energy.tr w]
set f10 [open n18-energy.tr w]
set f11 [open n20-energy.tr w]

set f12 [open n2-econ.tr w]


set f13 [open n11-econ.tr w]
set f14 [open n18-econ.tr w]
set f15 [open n20-econ.tr w]

set f16 [open n2-edis.tr w]


set f17 [open n11-edis.tr w]
set f18 [open n18-edis.tr w]
set f19 [open n20-edis.tr w]

set f20 [open n20-lr.tr w]

set topo [new Topography]


$topo load_flatgrid 1000 1000

create-god $val(nn)
# CONFIGURE AND CREATE 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 ON \
-movementTrace ON \
-rxPower 0.3 \
-txPower 0.6 \

proc finish {} {

global ns f f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15


f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33
f34 f35 f36 f37 f38 f39 f40 namtrace
$ns flush-trace
close $namtrace
close $f0
close $f1
close $f2
close $f3
close $f4
close $f5
close $f6
close $f7
close $f8
close $f9
close $f10
close $f11
close $f12
close $f13
close $f14
close $f15
close $f16
close $f17
close $f18
close $f19
close $f20
close $f21
close $f22
close $f23
close $f24
close $f25
close $f26
close $f27
close $f28
close $f29
close $f30
close $f31
close $f32
close $f33
close $f34
close $f35
close $f36
close $f37
close $f38
close $f39
close $f40

exec ./xgraph n2-packets_received.tr n11-packets_received.tr n18-


packets_received.tr n20-packets_received.tr -geometry 800x400 -t
"Cluster-Throughput" -x "Time" -y "Number of Packets" &

exec xgraph n1-packets_received.tr n0-packets_received.tr n3-


packets_received.tr n4-packets_received.tr n5-packets_received.tr n6-
packets_received.tr n7-packets_received.tr n8-packets_received.tr n9-
packets_received.tr n10-packets_received.tr -geometry 800x400 -t
"Cluster-Throughput 1" -x "Time" -y "Number of Packets" &

exec xgraph n12-packets_received.tr n13-packets_received.tr n14-


packets_received.tr n15-packets_received.tr n16-packets_received.tr n17-
packets_received.tr n19-packets_received.tr n21-packets_received.tr n22-
packets_received.tr n23-packets_received.tr -geometry 800x400 -t
"Cluster-Throughput 1" -x "Time" -y "Number of Packets" &

exec ./xgraph n2-pdr.tr n11-pdr.tr n18-pdr.tr n20-pdr.tr -geometry


800x400 -t "Cluster-Packet-Delivery-Ratio" -x "Time" -y "Packet-Delivery"
&

exec ./xgraph n2-energy.tr n11-energy.tr n18-energy.tr n20-energy.tr


-geometry 800x400 -t "Total Power" -x "Time" -y "Energy" &

exec ./xgraph n2-econ.tr n11-econ.tr n18-econ.tr n20-econ.tr -geometry


800x400 -t "Energy Consumed" -x "Time" -y "Energy" &

exec ./xgraph n2-edis.tr n11-edis.tr n18-edis.tr n20-edis.tr -geometry


800x400 -t "Total Dissapated" -x "Time" -y "Energy" &

exec ./nam -r 5m cluster-rechange.nam &


exit 0
}
proc record {} {

global sink0 sink1 sink2 sink3 sink4 sink5 sink6 sink7 sink8 sink9
sink10 sink11 sink12 sink13 sink14 sink15 sink16 sink17 sink18 sink19
sink20 sink21 sink22 sink23 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13
f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31
f32 f33 f34 f35 f36 f37 f38 f39 f40

#Get An Instance Of The Simulator

set ns [Simulator instance]

#Set The Time After Which The Procedure Should Be Called Again

set time 0.05

#How Many Bytes Have Been Received By The Traffic Sinks?

set bw0 [$sink2 set npkts_]


set bw1 [$sink11 set npkts_]
set bw2 [$sink18 set npkts_]
set bw3 [$sink20 set npkts_]
set bw4 [$sink0 set npkts_]
set bw5 [$sink1 set npkts_]
set bw6 [$sink3 set npkts_]
set bw7 [$sink4 set npkts_]
set bw8 [$sink5 set npkts_]
set bw9 [$sink6 set npkts_]
set bw10 [$sink7 set npkts_]
set bw11 [$sink8 set npkts_]
set bw12 [$sink9 set npkts_]
set bw13 [$sink10 set npkts_]
set bw14 [$sink12 set npkts_]
set bw15 [$sink13 set npkts_]
set bw16 [$sink14 set npkts_]
set bw17 [$sink15 set npkts_]
set bw18 [$sink16 set npkts_]
set bw19 [$sink17 set npkts_]
set bw20 [$sink19 set npkts_]
set bw21 [$sink21 set npkts_]
set bw22 [$sink22 set npkts_]
set bw23 [$sink23 set npkts_]

#set Size [expr 500 * 64 ]

set Size .40


set Size1 .65
set Size2 .26
set Size3 .25

puts "No of Packets in 00th node: $bw4"


puts "No of Packets in 01th node: $bw5"
puts "No of Packets in 03th node: $bw6"
puts "No of Packets in 04th node: $bw7"
puts "No of Packets in 05th node: $bw8"
puts "No of Packets in 06th node: $bw9"
puts "No of Packets in 07th node: $bw10"
puts "No of Packets in 08th node: $bw11"
puts "No of Packets in 09th node: $bw12"
puts "No of Packets in 10th node: $bw13"
puts "No of Packets in 12th node: $bw14"
puts "No of Packets in 13th node: $bw15"
puts "No of Packets in 14th node: $bw16"
puts "No of Packets in 15th node: $bw17"
puts "No of Packets in 16th node: $bw18"
puts "No of Packets in 17th node: $bw19"
puts "No of Packets in 19th node: $bw20"
puts "No of Packets in 21th node: $bw21"
puts "No of Packets in 22th node: $bw22"
puts "No of Packets in 23th node: $bw23"

puts "No of Packets in 02th node: $bw0"


puts "No of Packets in 11th node: $bw1"
puts "No of Packets in 18th node: $bw2"
puts "No of Packets in 20th node: $bw3"

set pdr [expr $bw0/$Size]


set pdr1 [expr $bw1/$Size1]
set pdr2 [expr $bw2/$Size2]
set pdr3 [expr $bw3/$Size3]

set enr [expr $bw0*150]


set enr1 [expr $bw1*150/.80]
set enr2 [expr $bw2*150/.96]
set enr3 [expr $bw3*150/.88]

set econ [expr $bw0*150]


set econ1 [expr $bw1*150]
set econ2 [expr $bw2*150]
set econ3 [expr $bw3*150]

set edis [expr (0-$bw0)*0]


set edis1 [expr (65-$bw1)*150]
set edis2 [expr (26-$bw2)*150]
set edis3 [expr (25-$bw3)*150]

set Lr [expr ($bw3+$bw1+$bw2+$bw0)*150/4]

puts " Packet Delivery Ratio 02th node: $pdr"


puts " Packet Delivery Ratio 11th node: $pdr1"
puts " Packet Delivery Ratio 18th node: $pdr2"
puts " Packet Delivery Ratio 20th node: $pdr3"

puts " Energy of the 02th node: $enr"


puts " Energy of the 11th node: $enr1"
puts " Energy of the 18th node: $enr2"
puts " Energy of the 20th node: $enr3"

puts " Energy consumed in the 02th node: $econ"


puts " Energy consumed in the 11th node: $econ1"
puts " Energy consumed in the 18th node: $econ2"
puts " Energy consumed in the 20th node: $econ3"

puts " Energy disappated in the 02th node: $edis"


puts " Energy disappated in the 11th node: $edis1"
puts " Energy disappated in the 18th node: $edis2"
puts " Energy disappated in the 20th node: $edis3"

puts " Total Number of Rounds: $Lr"

#Get The Current Time


set now [$ns now]

#Save Data To The Files

puts $f4 "$now [expr $pdr]"


puts $f5 "$now [expr $pdr1]"
puts $f6 "$now [expr $pdr2]"
puts $f7 "$now [expr $pdr3]"
puts $f8 "$now [expr $enr]"
puts $f9 "$now [expr $enr1]"
puts $f10 "$now [expr $enr2]"
puts $f11 "$now [expr $enr3]"
puts $f12 "$now [expr $econ]"
puts $f13 "$now [expr $econ1]"
puts $f14 "$now [expr $econ2]"
puts $f15 "$now [expr $econ3]"
puts $f16 "$now [expr $edis]"
puts $f17 "$now [expr $edis1]"
puts $f18 "$now [expr $edis2]"
puts $f19 "$now [expr $edis3]"
puts $f0 "$now [expr $bw0]"
puts $f1 "$now [expr $bw1]"
puts $f2 "$now [expr $bw2]"
puts $f3 "$now [expr $bw3]"
puts $f21 "$now [expr $bw4]"
puts $f22 "$now [expr $bw5]"
puts $f23 "$now [expr $bw6]"
puts $f24 "$now [expr $bw7]"
puts $f25 "$now [expr $bw8]"
puts $f26 "$now [expr $bw9]"
puts $f27 "$now [expr $bw10]"
puts $f28 "$now [expr $bw11]"
puts $f29 "$now [expr $bw12]"
puts $f30 "$now [expr $bw13]"
puts $f31 "$now [expr $bw14]"
puts $f32 "$now [expr $bw15]"
puts $f33 "$now [expr $bw16]"
puts $f34 "$now [expr $bw17]"
puts $f35 "$now [expr $bw18]"
puts $f36 "$now [expr $bw19]"
puts $f37 "$now [expr $bw20]"
puts $f38 "$now [expr $bw21]"
puts $f39 "$now [expr $bw22]"
puts $f40 "$now [expr $bw23]"

#Re-Schedule The Procedure


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

# define color index


$ns color 0 purple
$ns color 1 blue
$ns color 2 chocolate
$ns color 3 red
$ns color 4 brown
$ns color 5 tan
$ns color 6 gold
$ns color 7 black

set n(0) [$ns node]


$n(0) color "0"
$n(0) shape "circle"
set n(1) [$ns node]
$n(1) color "blue"
$n(1) shape "circle"
set n(2) [$ns node]
$n(2) color "tan"
$n(2) shape "circle"
set n(3) [$ns node]
$n(3) color "red"
$n(3) shape "circle"
set n(4) [$ns node]
$n(4) color "tan"
$n(4) shape "circle"
set n(5) [$ns node]
$n(5) color "red"
$n(5) shape "circle"
set n(6) [$ns node]
$n(6) color "0"
$n(6) shape "circle"
set n(7) [$ns node]
$n(7) color "brown"
$n(7) shape "circle"
set n(8) [$ns node]
$n(8) color "black"
$n(8) shape "circle"
set n(9) [$ns node]
$n(9) color "red"
$n(9) shape "circle"
set n(10) [$ns node]
$n(10) color "tan"
$n(10) shape "circle"
set n(11) [$ns node]
$n(11) color "red"
$n(11) shape "circle"
set n(12) [$ns node]
$n(12) color "red"
$n(12) shape "circle"
set n(13) [$ns node]
$n(13) color "tan"
$n(13) shape "circle"
set n(14) [$ns node]
$n(14) color "red"
$n(14) shape "circle"

set n(15) [$ns node]


$n(15) color "tan"
$n(15) shape "circle"
set n(16) [$ns node]
$n(16) color "red"
$n(16) shape "circle"
set n(17) [$ns node]
$n(17) color "red"
$n(17) shape "circle"
set n(18) [$ns node]
$n(18) color "tan"
$n(18) shape "circle"
set n(19) [$ns node]
$n(19) color "red"
$n(19) shape "circle"

set n(20) [$ns node]


$n(20) color "tan"
$n(20) shape "circle"
set n(21) [$ns node]
$n(21) color "red"
$n(21) shape "circle"
set n(22) [$ns node]
$n(22) color "red"
$n(22) shape "circle"
set n(23) [$ns node]
$n(23) color "tan"
$n(23) shape "circle"

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


$ns initial_node_pos $n($i) 30+i*100
}

# subclass Agent/MessagePassing to make it do flooding

Class Agent/MessagePassing/Flooding -superclass Agent/MessagePassing

Agent/MessagePassing/Flooding instproc recv {source sport size data} {


$self instvar messages_seen node_
global ns BROADCAST_ADDR

# extract message ID from message


set message_id [lindex [split $data ":"] 0]
#puts "\nNode [$node_ node-addr] got message $message_id\n"

if {[lsearch $messages_seen $message_id] == -1} {


lappend messages_seen $message_id
$ns trace-annotate "[$node_ node-addr] received HELLO {$data}
from $source"
$ns trace-annotate "[$node_ node-addr] sending HELLO message
$message_id"
$self sendto $size $data $BROADCAST_ADDR $sport
} else {

}
}

Agent/MessagePassing/Flooding instproc send_message {size message_id data


port} {
$self instvar messages_seen node_
global ns MESSAGE_PORT BROADCAST_ADDR

lappend messages_seen $message_id


$ns trace-annotate "[$node_ node-addr] sending HELLO message
$message_id"
$self sendto $size "$message_id:$data" $BROADCAST_ADDR $port
}

$n(0) set X_ 0.0


$n(0) set Y_ 0.0
$n(0) set Z_ 0.0

$n(1) set X_ 0.0


$n(1) set Y_ 0.0
$n(1) set Z_ 0.0

$n(2) set X_ 0.0


$n(2) set Y_ 0.0
$n(2) set Z_ 0.0

$n(3) set X_ 0.0


$n(3) set Y_ 0.0
$n(3) set Z_ 0.0

$n(4) set X_ 0.0


$n(4) set Y_ 0.0
$n(4) set Z_ 0.0

$n(5) set X_ 0.0


$n(5) set Y_ 0.0
$n(5) set Z_ 0.0

$n(6) set X_ 0.0


$n(6) set Y_ 0.0
$n(6) set Z_ 0.0

$n(7) set X_ 0.0


$n(7) set Y_ 0.0
$n(7) set Z_ 0.0

$n(8) set X_ 0.0


$n(8) set Y_ 0.0
$n(8) set Z_ 0.0

$n(9) set X_ 0.0


$n(9) set Y_ 0.0
$n(9) set Z_ 0.0

$n(10) set X_ 0.0


$n(10) set Y_ 0.0
$n(10) set Z_ 0.0

$n(11) set X_ 0.0


$n(11) set Y_ 0.0
$n(11) set Z_ 0.0

$n(12) set X_ 0.0


$n(12) set Y_ 0.0
$n(12) set Z_ 0.0

$n(13) set X_ 0.0


$n(13) set Y_ 0.0
$n(13) set Z_ 0.0

$n(14) set X_ 0.0


$n(14) set Y_ 0.0
$n(14) set Z_ 0.0

$n(15) set X_ 0.0


$n(15) set Y_ 0.0
$n(15) set Z_ 0.0

$n(16) set X_ 0.0


$n(16) set Y_ 0.0
$n(16) set Z_ 0.0
$n(17) set X_ 0.0
$n(17) set Y_ 0.0
$n(17) set Z_ 0.0

$n(18) set X_ 0.0


$n(18) set Y_ 0.0
$n(18) set Z_ 0.0

$n(19) set X_ 0.0


$n(19) set Y_ 0.0
$n(19) set Z_ 0.0

$n(20) set X_ 0.0


$n(21) set Y_ 0.0
$n(21) set Z_ 0.0

$n(22) set X_ 0.0


$n(22) set Y_ 0.0
$n(22) set Z_ 0.0

$n(23) set X_ 0.0


$n(23) set Y_ 0.0
$n(23) set Z_ 0.0

$ns at 0.0 "$n(0) setdest 500.0 400.0 3000.0"


$ns at 0.0 "$n(1) setdest 510.0 440.0 3000.0"
$ns at 0.0 "$n(21) setdest 500.0 400.0 3000.0"
$ns at 0.0 "$n(3) setdest 500.0 300.0 3000.0"
$ns at 0.0 "$n(4) setdest 550.0 310.0 3000.0"
$ns at 0.0 "$n(5) setdest 560.0 400.0 3000.0"
$ns at 0.0 "$n(6) setdest 480.0 480.0 3000.0"
$ns at 0.0 "$n(7) setdest 840.0 410.0 3000.0"
$ns at 0.0 "$n(8) setdest 580.0 322.0 3000.0"
$ns at 0.0 "$n(9) setdest 580.0 394.0 3000.0"
$ns at 0.0 "$n(10) setdest 425.0 530.0 3000.0"
$ns at 0.0 "$n(11) setdest 640.0 563.0 3000.0"
$ns at 0.0 "$n(12) setdest 571.0 539.0 3000.0"
$ns at 0.0 "$n(13) setdest 546.0 495.0 3000.0"
$ns at 0.0 "$n(14) setdest 420.0 330.0 3000.0"
$ns at 0.0 "$n(15) setdest 460.0 481.0 3000.0"
$ns at 0.0 "$n(16) setdest 467.0 410.0 3000.0"
$ns at 0.0 "$n(17) setdest 371.0 367.0 3000.0"
$ns at 0.0 "$n(18) setdest 380.0 405.0 3000.0"
$ns at 0.0 "$n(19) setdest 468.0 457.0 3000.0"
$ns at 0.0 "$n(20) setdest 410.0 350.0 3000.0"
$ns at 0.0 "$n(2) setdest 335.0 498.0 3000.0"
$ns at 0.0 "$n(22) setdest 522.0 416.0 3000.0"
$ns at 0.0 "$n(23) setdest 312.0 463.0 3000.0"

$ns at 0.1 "$n(0) color Brown"


$ns at 0.1 "$n(6) color Brown"
$ns at 0.1 "$n(19) color Brown"
$ns at 0.1 "$n(13) color Brown"
$ns at 0.1 "$n(21) color Brown"
$ns at 0.1 "$n(9) color Brown"

$ns at 0.1 "$n(4) color green4"


$ns at 0.1 "$n(18) color green4"
$ns at 0.1 "$n(14) color green4"
$ns at 0.1 "$n(17) color green4"
$ns at 0.1 "$n(5) color green4"
$ns at 0.1 "$n(8) color green4"

$ns at 0.1 "$n(7) color Red"


$ns at 0.1 "$n(23) color Red"
$ns at 0.1 "$n(16) color Red"
$ns at 0.1 "$n(20) color Red"
$ns at 0.1 "$n(3) color Red"
$ns at 0.1 "$n(2) color Red"

#$ns at 1.0 "$n(0) setdest 110.0 110.0 2.0"


#$ns at 1.0 "$n(1) setdest 210.0 460.0 2.0"
#$ns at 1.0 "$n(2) setdest 310.0 210.0 2.0"
#$ns at 1.0 "$n(3) setdest 410.0 310.0 2.0"
#$ns at 1.0 "$n(4) setdest 570.0 320.0 2.0"
#$ns at 1.0 "$n(5) setdest 610.0 420.0 2.0"
#$ns at 1.0 "$n(6) setdest 190.0 90.0 2.0"
#$ns at 1.0 "$n(7) setdest 390.0 510.0 2.0"
#$ns at 1.0 "$n(8) setdest 610.0 350.0 2.0"
#$ns at 1.0 "$n(9) setdest 294.0 204.0 2.0"
#$ns at 1.0 "$n(10) setdest 235.0 430.0 2.0"
#$ns at 1.0 "$n(11) setdest 245.0 545.0 2.0"
#$ns at 1.0 "$n(12) setdest 48.0 520.0 2.0"
#$ns at 1.0 "$n(13) setdest 256.0 219.0 2.0"
#$ns at 1.0 "$n(14) setdest 530.0 340.0 2.0"
#$ns at 1.0 "$n(15) setdest 222.0 418.0 2.0"
#$ns at 1.0 "$n(16) setdest 377.0 413.0 2.0"
#$ns at 1.0 "$n(17) setdest 570.0 370.0 2.0"
#$ns at 1.0 "$n(18) setdest 660.0 225.0 2.0"
#$ns at 1.0 "$n(19) setdest 178.0 167.0 2.0"
#$ns at 1.0 "$n(20) setdest 513.0 419.0 2.0"
#$ns at 1.0 "$n(21) setdest 445.0 402.0 2.0"
#$ns at 1.0 "$n(22) setdest 216.0 390.0 2.0"
#$ns at 1.0 "$n(23) setdest 425.0 342.0 2.0"

#$ns at 15.0 "$n(16) setdest 410.0 767.0 3.0"


#$ns at 25.0 "$n(1) setdest 350.0 600.0 3.0"
#$ns at 30.0 "$n(19) setdest 500.0 580.0 3.0"
#$ns at 10.0 "$n(14) setdest 240.0 550.0 3.0"

#$ns at 3.0 "$n(1) add-mark c1 yellow hexagon"

$ns at 0.54 "$n(13) label CH"


$ns at 0.54 "$n(1) label CH"
$ns at 0.54 "$n(6) label S1"
$ns at 0.54 "$n(11) label D1"

$ns at 0.545 "$n(1) add-mark c1 yellow hexagon"


$ns at 0.545 "$n(13) add-mark c1 yellow hexagon"

$ns at 1.58 "$n(17) label CH"


$ns at 1.58 "$n(3) label CH"
$ns at 1.58 "$n(8) label S2"
$ns at 1.58 "$n(2) label D2"

$ns at 1.585 "$n(17) add-mark c1 yellow hexagon"


$ns at 1.585 "$n(3) add-mark c1 yellow hexagon"

$ns at 2.054 "$n(9) label CH"


$ns at 2.054 "$n(1) label CH"
$ns at 2.054 "$n(9) label S3"
$ns at 2.054 "$n(11) label D3"

$ns at 2.0545 "$n(1) add-mark c1 yellow hexagon"


$ns at 2.0545 "$n(9) add-mark c1 yellow hexagon"

$ns at 2.094 "$n(11) label C-CH"


$ns at 2.1 "$n(11) label - "
$ns at 2.094 "$n(9) label CH"
$ns at 2.094 "$n(22) label CH"
$ns at 2.094 "$n(9) label S3"
$ns at 2.094 "$n(11) label D3"

$ns at 2.095 "$n(9) add-mark c1 yellow hexagon"


$ns at 2.095 "$n(22) add-mark c1 yellow hexagon"

$ns at 3.02 "$n(17) label C-CH"


$ns at 3.02 "$n(3) label C-CH"
$ns at 3.05 "$n(17) label - "
$ns at 3.05 "$n(3) label - "
$ns at 3.01 "$n(8) label CH"
$ns at 3.01 "$n(20) label CH"
$ns at 3.01 "$n(8) label S2"
$ns at 3.01 "$n(2) label D2"

$ns at 3.015 "$n(8) add-mark c1 yellow hexagon"


$ns at 3.015 "$n(20) add-mark c1 yellow hexagon"

$ns at 3.18 "$n(1) label CH"


$ns at 3.18 "$n(3) label CH"
$ns at 3.18 "$n(15) label S4"
$ns at 3.18 "$n(20) label D4"

$ns at 3.19 "$n(1) add-mark c1 yellow hexagon"


$ns at 3.19 "$n(3) add-mark c1 yellow hexagon"

$ns at 4.05 "$n(4) label CH"


$ns at 4.05 "$n(7) label CH"
$ns at 4.05 "$n(10) label CH"
$ns at 4.05 "$n(22) label S5"
$ns at 4.05 "$n(18) label D5"

$ns at 4.055 "$n(4) add-mark c1 yellow hexagon"


$ns at 4.055 "$n(7) add-mark c1 yellow hexagon"
$ns at 4.055 "$n(10) add-mark c1 yellow hexagon"

#$ns at 56.0 "$n(7) add-mark c6 black hexagon"


#$ns at 56.0 "$n(7) label CH"
#$ns at 17.0 "$n(19) add-mark c7 black hexagon"
#$ns at 17.0 "$n(19) label CH"
#$ns at 100.0 "$n(9) add-mark c8 black hexagon"
#$ns at 100.0 "$n(9) label CH"
#$ns at 127.0 "$n(19) add-mark c9 black hexagon"
#$ns at 127.0 "$n(19) label Un-CH"
#$ns at 180.0 "$n(16) label Un_CH"
#$ns at 180.0 "$n(16) add-mark c10 black hexagon"
#$ns at 100.0 "$n(13) label CH"
#$ns at 100.0 "$n(13) add-mark c11 black hexagon"

#$ns at 2.0 "$n(16) add-mark c1 black hexagon"


#$ns at 2.0 "$n(16) label CH"
#$ns at 2.0 "$n(14) add-mark c2 black hexagon"
#$ns at 2.0 "$n(14) label CH"
#$ns at 2.0 "$n(19) add-mark c3 black hexagon"
#$ns at 2.0 "$n(19) label CH"
#$ns at 2.0 "$n(1) add-mark c4 black hexagon"
#$ns at 2.0 "$n(1) label CH"

#$ns at 65.0 "$n(21) add-mark c6 black hexagon"


#$ns at 65.0 "$n(21) label CH"
#$ns at 65.0 "$n(9) add-mark c6 black hexagon"
#$ns at 65.0 "$n(9) label CH"

$ns at 0.7 "$ns trace-annotate \"For 5 seconds mobiles nodes send HELLO
messages to establish 1-hop and 2-hop neighbors\""

# attach a new Agent/MessagePassing/Flooding to each node on port


$MESSAGE_PORT
for {set i 0} {$i < $num_nodes} {incr i} {
set a($i) [new Agent/MessagePassing/Flooding]
$n($i) attach $a($i) $MESSAGE_PORT
$a($i) set messages_seen {}
}

# now set up some events


$ns at 2.2 "$a(1) send_message 200 1 {first message} $MESSAGE_PORT"
$ns at 2.8 "$a([expr $num_nodes/2]) send_message 600 2 {some big message}
$MESSAGE_PORT"
$ns at 3.4 "$a([expr $num_nodes-2]) send_message 200 3 {another one}
$MESSAGE_PORT"

# CONFIGURE AND SET UP A FLOW

set sink0 [new Agent/LossMonitor]


set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
set sink3 [new Agent/LossMonitor]
set sink4 [new Agent/LossMonitor]
set sink5 [new Agent/LossMonitor]
set sink6 [new Agent/LossMonitor]
set sink7 [new Agent/LossMonitor]
set sink8 [new Agent/LossMonitor]
set sink9 [new Agent/LossMonitor]
set sink10 [new Agent/LossMonitor]
set sink11 [new Agent/LossMonitor]
set sink12 [new Agent/LossMonitor]
set sink13 [new Agent/LossMonitor]
set sink14 [new Agent/LossMonitor]
set sink15 [new Agent/LossMonitor]

set sink16 [new Agent/LossMonitor]


set sink17 [new Agent/LossMonitor]
set sink18 [new Agent/LossMonitor]
set sink19 [new Agent/LossMonitor]
set sink20 [new Agent/LossMonitor]
set sink21 [new Agent/LossMonitor]
set sink22 [new Agent/LossMonitor]
set sink23 [new Agent/LossMonitor]

$ns attach-agent $n(0) $sink0


$ns attach-agent $n(1) $sink1
$ns attach-agent $n(2) $sink2
$ns attach-agent $n(3) $sink3
$ns attach-agent $n(4) $sink4
$ns attach-agent $n(5) $sink5
$ns attach-agent $n(6) $sink6
$ns attach-agent $n(7) $sink7
$ns attach-agent $n(8) $sink8
$ns attach-agent $n(9) $sink9
$ns attach-agent $n(10) $sink10
$ns attach-agent $n(11) $sink11
$ns attach-agent $n(12) $sink12
$ns attach-agent $n(13) $sink13
$ns attach-agent $n(14) $sink14
$ns attach-agent $n(15) $sink15
$ns attach-agent $n(16) $sink16
$ns attach-agent $n(17) $sink17
$ns attach-agent $n(18) $sink18
$ns attach-agent $n(19) $sink19
$ns attach-agent $n(20) $sink20
$ns attach-agent $n(21) $sink21
$ns attach-agent $n(22) $sink22
$ns attach-agent $n(23) $sink23

set tcp0 [new Agent/TCP]


$tcp0 set prio_ 1
$ns attach-agent $n(0) $tcp0
set tcp1 [new Agent/TCP]
$tcp1 set prio_ 2
$ns attach-agent $n(1) $tcp1
set tcp2 [new Agent/TCP]
$tcp2 set prio_ 3
$ns attach-agent $n(2) $tcp2
set tcp3 [new Agent/TCP]
$ns attach-agent $n(3) $tcp3
set tcp4 [new Agent/TCP]
$tcp4 set prio_ 4

$ns attach-agent $n(4) $tcp4


set tcp5 [new Agent/TCP]
$ns attach-agent $n(5) $tcp5
set tcp6 [new Agent/TCP]
$ns attach-agent $n(6) $tcp6
set tcp7 [new Agent/TCP]
$ns attach-agent $n(7) $tcp7
set tcp8 [new Agent/TCP]
$ns attach-agent $n(8) $tcp8
set tcp9 [new Agent/TCP]
$ns attach-agent $n(9) $tcp9
set tcp10 [new Agent/TCP]
$ns attach-agent $n(10) $tcp10
set tcp11 [new Agent/TCP]
$tcp11 set prio_ 5
$ns attach-agent $n(11) $tcp11
set tcp12 [new Agent/TCP]
$tcp12 set prio_ 6
$ns attach-agent $n(12) $tcp12
set tcp13 [new Agent/TCP]
$tcp13 set prio_ 7
$ns attach-agent $n(13) $tcp13
set tcp14 [new Agent/TCP]
$tcp14 set prio_ 8
$ns attach-agent $n(14) $tcp14

set tcp15 [new Agent/TCP]


$ns attach-agent $n(15) $tcp15
set tcp16 [new Agent/TCP]
$ns attach-agent $n(16) $tcp16
set tcp17 [new Agent/TCP]
$ns attach-agent $n(17) $tcp17
set tcp18 [new Agent/TCP]
$ns attach-agent $n(18) $tcp18
set tcp19 [new Agent/TCP]
$ns attach-agent $n(19) $tcp19
set tcp20 [new Agent/TCP]
$tcp20 set prio_ 5
$ns attach-agent $n(20) $tcp20
set tcp21 [new Agent/TCP]
$tcp21 set prio_ 6
$ns attach-agent $n(21) $tcp21
set tcp22 [new Agent/TCP]
$tcp22 set prio_ 6
$ns attach-agent $n(22) $tcp22
set tcp23 [new Agent/TCP]
$tcp23 set prio_ 7
$ns attach-agent $n(23) $tcp23

proc attach-CBR-traffic { node sink size interval } {


#Get an instance of the simulator
set ns [Simulator instance]
#Create a CBR sink14 agent and attach it to the node
set cbr [new Agent/CBR]
$ns attach-agent $node $cbr
$cbr set packetSize_ $size
$cbr set interval_ $interval

#Attach CBR source to sink;


$ns connect $cbr $sink
return $cbr
}

set cbr0 [attach-CBR-traffic $n(9) $sink11 512 .042]


set cbr1 [attach-CBR-traffic $n(12) $sink20 512 .041]
set cbr2 [attach-CBR-traffic $n(6) $sink11 512 .041]
set cbr3 [attach-CBR-traffic $n(8) $sink2 512 .041]
set cbr4 [attach-CBR-traffic $n(22) $sink18 512 .041]

$ns at 0.0 "record"


$ns at 2.0 "$cbr0 start"
$ns at 3.1 "$cbr1 start"
$ns at 0.5 "$cbr2 start"
$ns at 1.5 "$cbr3 start"
$ns at 4.0 "$cbr4 start"

$ns at 1.98 "$cbr2 stop"


$ns at 2.9 "$cbr0 stop"
$ns at 4.0 "$cbr1 stop"

#$ns at 0.0 "record"


#$ns at 3.0 "$cbr0 start"
#$ns at 2.0 "$cbr1 start"
#$ns at 1.0 "$cbr3 start"
#$ns at 10.0 "$cbr2 start"
#$ns at 1.3 "$cbr4 start"
#$ns at 1.8 "$cbr4 stop"

$ns at 3.15 "$cbr3 stop"

$ns at 5.0 "finish"


puts "Start of simulation.."
$ns run

You might also like