# Define options
set val(chan) Channel/WirelessChannel ;#Channel type
set val(prop) Propagation/TwoRayGround ;#Propogation model
set val(netif) Phy/WirelessPhy ;#Medium
set val(mac) Mac/802_11 ;#Standard
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL ;#Logical link layer
set val(ant) Antenna/OmniAntenna ;#Antenna
set val(x) 1000 ;# X dimension of the topography
set val(y) 1000 ;# Y dimension of the topography
set val(ifqlen) 100000;# max packet in ifq
set val(seed) 0.0
set val(adhocRouting) AODV
set val(adhocRouting) INSENS
set val(adhocRouting) SMECN
set val(nn) 70 ;# how many nodes are simulated
set val(cp) us1
set val(sc) us2
set val(stop) 200.0 ;# simulation time
set val(traffic) cbr
#
==========================================================
===========
# Main Program
#
==========================================================
===========
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# setup topography object
set topo [new Topography]
# create trace object for ns and nam
set tracefd [open us.tr w]
set namtrace [open usor.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# define topology
$topo load_flatgrid $val(x) $val(y)
#
# Create God
#
set god_ [create-god $val(nn)]
#
# define how node should be created
#
#global node setting
$ns_ node-config -adhocRouting AODV \
-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
#
# Create the specified number of nodes [$val(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
set n_($i) [$ns_ node]
$n_($i) random-motion 0 ;# disable random motion
}
#
# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)
#
# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)
# Define node initial position in nam
#node's size
for {set i 0} {$i < $val(nn)} {incr i} {
$ns_ initial_node_pos $n_($i) 40
}
#Reset all the nodes at 20.0
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$n_($i) reset";
}
#finish procedure
proc finish {} {
global ns_ tracefd namtrace
close $tracefd
close $namtrace
exec nam usor.nam &
exec awk -f graph1.awk us.tr > INSENS-SMECN.xgr
exec awk -f graph2.awk us.tr > CBDS.xgr
#exec awk -f graph3.awk us.tr > AODV.xgr
exec xgraph INSENS-SMECN.xgr CBDS.xgr -x "Number of mobile nodes" -y
"packet delivery ratio" -bg "Black" -fg "white" &
exec awk -f graph4.awk us.tr > nl_INSENS-SMECN
exec awk -f graph5.awk us.tr > nl_CBDS
#exec awk -f graph6.awk us.tr > nl_AODV
exec xgraph nl_INSENS-SMECN nl_CBDS -x "Number of mobile nodes" -y
"Network Lifetime" -bg "Black" -fg "white" &
exec awk -f graph14.awk us.tr > TP_CBDS
exec awk -f graph15.awk us.tr > TP_INSENS-SMECN
#exec awk -f graph16.awk us.tr > TP_AODV
exec xgraph TP_CBDS TP_INSENS-SMECN -x "Number of mobile nodes" -y
"Security" -bg "Black" -fg "white" &
exec awk -f graph17.awk us.tr > EC_CBDS
exec awk -f graph16.awk us.tr > EC_INSENS-SMECN
#exec awk -f graph16.awk us.tr > TP_AODV
exec xgraph EC_CBDS EC_INSENS-SMECN -x "Number of mobile nodes" -y
"Energy_Consumption" -bg "Black" -fg "white" &
exec awk -f graph10.awk us.tr > TP_INSENS-SMECN
#exec awk -f graph11.awk us.tr > TP_Existing
exec awk -f graph12.awk us.tr > TP_CBDS
exec xgraph TP_INSENS-SMECN TP_CBDS -x "Number of mobile nodes" -y
"Throughput" -bg "Black" -fg "white" &
#stop the simulation at 20.0001
$ns_ at $val(stop).0001 "finish"
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
puts "Starting Simulation..."
#Run the NS2 code
$ns_ run