code:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(ant) Antenna/OmniAntenna
set val(ll) LL
set val(ifq) Queue/DropTail/PriQueue
set val(ifqlen) 50
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(rp) DSDV
set val(nn) 15
set val(x) 700
set val(y) 500
set val(stop) 130
set ns [new Simulator]
set tracefd [open trust.tr w]
set windowVsTime2 [open win.tr w]
set namtrace [open trust.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god (1)
#create-god (3)
$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 OFF\
-energyModel "EnergyModel" \
-initialEnergy 50
# Energy model
$ns node-config -energyModel EnergyModel \
-initialEnergy 50 \
-txPower 0.75
#-rxPower 0.25 \
#idlePower 0.0 \
#sensePower 0.0
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
}
$ns at 0.0 "$ns trace-annotate \"MOBILE NODE MOVEMENTS\""
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_(3) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
#setting initial position:
for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $node_($i) 30
}
#$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 130.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam trust.nam &
}
$ns run
this code run but the mobile nodes are dynamic each time how to make the dynamic mobile nodes to static?
how to make it static mobile nodes and need to do randomized overhearing in the ns2 tcl code
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
$node_($i) random-motion 0 ;# disable random motion
}
for {set i 0} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500]
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
$node_($i) set Z_ 0.0
}
This code sets the mobility of the nodes. You can comment this code and see. The nodes should then be static.
Related
I tried making a mobility node from the existing NS-2.35 M-DART protocol by modifying some of the script line. But when I run the sccript there is an error says:
anal2#ubuntu:~/Downloads/test2$ ns 1_mdart-EM.tcl
num_nodes is set 10
INITIALIZE THE LIST xListHead
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.2, distCST_ = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0
SORTING LISTS ...DONE!
SORTING LISTS ...DONE!
ns: _o23 setdest 175.0 90.0 0.0:
(_o23 cmd line 1)
invoked from within
"_o23 cmd setdest 175.0 90.0 0.0"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o23" line 2)
(SplitObject unknown line 2)
invoked from within
"_o23 setdest 175.0 90.0 0.0"
The area of the mobility nodes supposedly set at the node density. I also had set the destination for the mobile nodes, yet the error still persist. Did I do wrong somewhere? I provide my script for reference below. Thanks :D
EDITED: I forgot to put the node movement speed at the setdest node. But the same error still pop out, even after I put the speed value.
###########################################
# Define Option
###########################################
set val(chan) Channel/WirelessChannel; #channel type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(propagation) Shado; #propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(ll) LL; #link layer type
set val(ifq) Queue/DropTail; #interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(mac) Mac/802_11; #MAC type
set val(rp) MDART; #routing protocol
set val(n) 10 ; #node number
set val(density) 4096; #node density [node/km^2]
set val(end) 206.0; #simulation time [s]
set val(dataStart) 100.0; #data start time [s]
set val(dataStop) [expr $val(end) - 6.0]; #data stop time [s]
set val(seed) 1; #general pseudo-random sequence generator
set val(macFailed) true; #ATR protocol: ns2 MAC failed callback
set val(etxMetric) true; #ATR protocol: ETX route metric
set val(throughput) 5.40; #CBR rate (<= 5.4Mb/s)
#########################################
# Channel Model
#########################################
#Setting antenna at center of node, 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.2
Antenna/OmniAntenna set Gt_ 1.0 ;#transmitter gain
Antenna/OmniAntenna set Gr_ 1.0 ;#receiver gain
Phy/WirelessPhy set L_ 1.0 ;#system loss factor
if {$val(propagation) == "TwoRay"} {
set val(prop) Propagation/TwoRayGround
set prop [new $val(prop)]
Phy/WirelessPhy set CPThresh_ 10.0 ;#capt. thresh. in Watt
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#carr. sens. thresh.
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#receive signal thresh
Phy/WirelessPhy set freq_ 2.4e9 ;#chan. freq. (Hz)
Phy/WirelessPhy set Pt_ 0.28 ;#trans. signal power (Watt)
}
if {$val(propagation) == "Shado"} {
set val(prop) Propagation/Shadowing
set prop [new $val(prop)]
$prop set pathlossExp_ 3.8 ;#path loss exponent
$prop set std_db_ 2.0 ;#shadowing deviation (dB)
$prop set seed_ 1 ;#RNG seed
$prop set dist0_ 1.0 ;#ref. distance (m)
$prop set CPThresh_ 10.0 ;#capt. thresh (Watt)
$prop set RXThresh_ 2.37e-13 ;#rec. sign. thresh
$prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;#carr. sens. thresh
$prop set freq_ 2.4e9 ;#chann. freq (Hz)
Phy/WirelessPhy set Pt_ 0.28
}
#####################################################
# Topology Definition
#####################################################
#Scenario creation according to chosen node density
set val(dim) [expr $val(n) / $val(density)]
set val(x) [expr [expr sqrt($val(dim))] * 1000]
set val(y) [expr [expr sqrt($val(dim))] * 1000]
####################################################
# Pseudo-random sequence generator
####################################################
#General pseudo-random sequence geneator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 1.0
$randomSeed set max_ 100.0
#Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]
#Mobility model: Y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]
#Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(n) - 1]
################################
# General definition
################################
#Instantiate the simulator
set ns [new Simulator]
#Define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create GOD
create-god $val(n)
##############################
# Trace file definition
##############################
;#create trace object for ns, nam, monitor and inspect
set tracefile [open ns.tr w] ;#Adding this
$ns trace-all $tracefile ;#adding this
;#new format for wireless traces
$ns use-newtrace
#set namTr [open nam.tr w]
#$ns namtrace-all-wireless $namTr $val(x) $val(y)
set scenarioTr [open scenario.tr w]
#nam file creation
set namfile [open mdart.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
#set chan [new $val(chan)];
#create channel
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
$prop topography $topo
#Global node setting
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance $prop \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
################################
# Nodes definition
################################
;# Create the specified number of nodes [$val(n)] and "attach" them to the channel.
#for {set i 0} {$i < $val(n) } {incr i} {
# set node($i) [$ns node]
# $node($i) random-motion 0 ; #disabled random motion
#$ns initial_node_pos $n($i) 20 ;
#}
################################
# Node conode(figurationode(
################################
;#node initial coordinates
set node(0) [$ns node]
$node(0) random-motion 0
$node(0) set X_ 20.0
$node(0) set Y_ 65.0
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
set node(1) [$ns node]
$node(1) random-motion 0
$node(1) set X_ 50.0
$node(1) set Y_ 10.0
$node(1) set Z_ 0.0
$ns initial_node_pos $node(1) 20
set node(2) [$ns node]
$node(2) random-motion 0
$node(2) set X_ 0.0
$node(2) set Y_ 0.0
$node(2) set Z_ 0.0
$ns initial_node_pos $node(2) 20
set node(3) [$ns node]
$node(3) random-motion 0
$node(3) set X_ 95.0
$node(3) set Y_ 35.0
$node(3) set Z_ 0.0
$ns initial_node_pos $node(3) 20
set node(4) [$ns node]
$node(4) random-motion 0
$node(4) set X_ 8.0
$node(4) set Y_ 50.0
$node(4) set Z_ 0.0
$ns initial_node_pos $node(4) 20
$ns node-config \
-channel $chan_2_
set node(5) [$ns node]
$node(5) random-motion 0
$node(5) set X_ 150.0
$node(5) set Y_ 165.0
$node(5) set Z_ 0.0
$ns initial_node_pos $node(5) 20
set node(6) [$ns node]
$node(6) random-motion 0
$node(6) set X_ 30.0
$node(6) set Y_ 70.0
$node(6) set Z_ 0.0
$ns initial_node_pos $node(6) 20
set node(7) [$ns node]
$node(7) random-motion 0
$node(7) set X_ 65.0
$node(7) set Y_ 114.0
$node(7) set Z_ 0.0
$ns initial_node_pos $node(7) 20
set node(8) [$ns node]
$node(8) random-motion 0
$node(8) set X_ 50.0
$node(8) set Y_ 165.0
$node(8) set Z_ 0.0
$ns initial_node_pos $node(8) 20
set node(9) [$ns node]
$node(9) random-motion 0
$node(9) set X_ 180.0
$node(9) set Y_ 100.0
$node(9) set Z_ 0.0
$ns initial_node_pos $node(9) 20
###################################
# Nodes placement
###################################
#parameters for trace Inspect
puts $scenarioTr "# nodes: $val(n), max time: $val(end)"
puts $scenarioTr "# nominal range: 250"
for {set i 0} {$i < $val(n)} {incr i} {
set X [expr [$randomNodeX value] ]
$node($i) set X_ $X
set Y [expr [$randomNodeY value] ]
$node($i) set Y_ $Y
$node($i) set Z_ 0.0
$ns initial_node_pos $node($i) 20
puts $scenarioTr "\$node_($i) set X_ $X"
puts $scenarioTr "\$node_($i) set Y_ $Y"
puts $scenarioTr "\$node_($i) set Z_ 0.0"
}
###################################
# moving nodes
###################################
$ns at 3.0 "$node(0) setdest 175.0 90.0 15.0"
#$ns at 3.0 "$node(6) setdest 52.0 12.0 25.0"
#############################
# Data load
#############################
set udp0 [new Agent/UDP]
$ns attach-agent $node(0) $udp0
set null0 [new Agent/Null]
$ns attach-agent $node(6) $null0
$ns connect $udp0 $null0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 1000
$cbr0 attach-agent $udp0
$cbr0 set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
$ns at $val(dataStart) "$cbr0 start"
$ns at $val(dataStop) "$cbr0 stop"
###############################
# Routing model (for M-DART)
###############################
if {$val(rp) == "M-DART"} {
Agent/ATR set macFailed_ $val(macFailed)
Agent/ATR set etxMetric_ $val(etxMetric)
}
############################
# Tracing
############################
;#Simulation time print
proc timeTrace { tracePause} {
global ns
set now [$ns now]
$ns at [expr $now + $tracePause] "timeTrace $tracePause"
puts "$now simulation seconds"
}
$ns at 10.0 "timeTrace 10.0"
if {$val(rp) == "MDART"} {
for {set i 0} {$i < $val(n)} {incr i} {
# printing the routing table
$ns at [expr $val(end) - 1.0] "[$node($i) agent 255] routingTablePrint"
# printing the dht table
$ns at [expr $val(end) - 0.5] "[$node($i) agent 255] dhtTablePrint"
}
}
#########################
# Start and end
#########################
for {set i 0} {$i < $val(n) } {incr i} {
$ns at $val(end) "$node($i) reset";
}
$ns at $val(end) "fileTrace"
$ns at $val(end) "$ns halt"
proc fileTrace {} {
#global ns tracefile namTr
global ns tracefile scenarioTr
$ns flush-trace
close $tracefile ;#adding tis
#close $scenarioTr
#close $namTr
#exec nam nam.tr &
}
$ns run
I modified the M-DART tcl file in NS2 to run multi-channels instead of single channel. I already assigned the sending and receiving nodes but the packets did not forwarded to the destination node. The only action is send, receive and dropping packets. This is my modified script:
###########################################
# Define Option
###########################################
set val(chan) Channel/WirelessChannel; #channel type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(propagation) Shado; #propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(ll) LL; #link layer type
set val(ifq) Queue/DropTail; #interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(mac) Mac/802_11; #MAC type
set val(rp) MDART; #routing protocol
set val(n) 10 ; #node number
set val(density) 4096; #node density [node/km^2]
set val(end) 206.0; #simulation time [s]
set val(dataStart) 100.0; #data start time [s]
set val(dataStop) [expr $val(end) - 6.0]; #data stop time [s]
set val(seed) 1; #general pseudo-random sequence generator
set val(macFailed) true; #ATR protocol: ns2 MAC failed callback
set val(etxMetric) true; #ATR protocol: ETX route metric
set val(throughput) 5.40; #CBR rate (<= 5.4Mb/s)
#########################################
# Channel Model
#########################################
#Setting antenna at center of node, 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.2
Antenna/OmniAntenna set Gt_ 1.0 ;#transmitter gain
Antenna/OmniAntenna set Gr_ 1.0 ;#receiver gain
Phy/WirelessPhy set L_ 1.0 ;#system loss factor
if {$val(propagation) == "TwoRay"} {
set val(prop) Propagation/TwoRayGround
set prop [new $val(prop)]
Phy/WirelessPhy set CPThresh_ 10.0 ;#capt. thresh. in Watt
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#carr. sens. thresh.
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#receive signal thresh
Phy/WirelessPhy set freq_ 2.4e9 ;#chan. freq. (Hz)
Phy/WirelessPhy set Pt_ 0.28 ;#trans. signal power (Watt)
}
if {$val(propagation) == "Shado"} {
set val(prop) Propagation/Shadowing
set prop [new $val(prop)]
$prop set pathlossExp_ 3.8 ;#path loss exponent
$prop set std_db_ 2.0 ;#shadowing deviation (dB)
$prop set seed_ 1 ;#RNG seed
$prop set dist0_ 1.0 ;#ref. distance (m)
$prop set CPThresh_ 10.0 ;#capt. thresh (Watt)
$prop set RXThresh_ 2.37e-13 ;#rec. sign. thresh
$prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;#carr. sens. thresh
$prop set freq_ 2.4e9 ;#chann. freq (Hz)
Phy/WirelessPhy set Pt_ 0.28
}
#####################################################
# Topology Definition
#####################################################
#Scenario creation according to chosen node density
set val(dim) [expr $val(n) / $val(density)]
set val(x) [expr [expr sqrt($val(dim))] * 1000]
set val(y) [expr [expr sqrt($val(dim))] * 1000]
####################################################
# Pseudo-random sequence generator
####################################################
#General pseudo-random sequence geneator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 1.0
$randomSeed set max_ 100.0
#Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]
#Mobility model: Y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]
#Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(n) - 1]
################################
# General definition
################################
#Instantiate the simulator
set ns [new Simulator]
#Define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create GOD
create-god $val(n)
##############################
# Trace file definition
##############################
;#create trace object for ns, nam, monitor and inspect
set tracefile [open ns.tr w] ;#Adding this
$ns trace-all $tracefile ;#adding this
;#new format for wireless traces
$ns use-newtrace
#set namTr [open nam.tr w]
#$ns namtrace-all-wireless $namTr $val(x) $val(y)
#set scenarioTr [open scenario.tr w]
#nam file creation
set namfile [open mdart.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
#set chan [new $val(chan)];
#create channel
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
$prop topography $topo
#Global node setting
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance $prop \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
################################
# Nodes definition
################################
;# Create the specified number of nodes [$val(n)] and "attach" them to the channel.
#for {set i 0} {$i < $val(n) } {incr i} {
# set node($i) [$ns node]
# $node($i) random-motion 0 ; #disabled random motion
#$ns initial_node_pos $n($i) 20 ;
#}
################################
# Node conode(figurationode(
################################
;#node initial coordinates
set node(0) [$ns node]
$node(0) random-motion 0
$node(0) set X_ 20.0
$node(0) set Y_ 65.0
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
set node(1) [$ns node]
$node(1) random-motion 0
$node(1) set X_ 50.0
$node(1) set Y_ 10.0
$node(1) set Z_ 0.0
$ns initial_node_pos $node(1) 20
set node(2) [$ns node]
$node(2) random-motion 0
$node(2) set X_ 0.0
$node(2) set Y_ 0.0
$node(2) set Z_ 0.0
$ns initial_node_pos $node(2) 20
set node(3) [$ns node]
$node(3) random-motion 0
$node(3) set X_ 95.0
$node(3) set Y_ 35.0
$node(3) set Z_ 0.0
$ns initial_node_pos $node(3) 20
set node(4) [$ns node]
$node(4) random-motion 0
$node(4) set X_ 8.0
$node(4) set Y_ 50.0
$node(4) set Z_ 0.0
$ns initial_node_pos $node(4) 20
$ns node-config \
-channel $chan_2_
set node(5) [$ns node]
$node(5) random-motion 0
$node(5) set X_ 150.0
$node(5) set Y_ 165.0
$node(5) set Z_ 0.0
$ns initial_node_pos $node(5) 20
set node(6) [$ns node]
$node(6) random-motion 0
$node(6) set X_ 30.0
$node(6) set Y_ 70.0
$node(6) set Z_ 0.0
$ns initial_node_pos $node(6) 20
set node(7) [$ns node]
$node(7) random-motion 0
$node(7) set X_ 65.0
$node(7) set Y_ 114.0
$node(7) set Z_ 0.0
$ns initial_node_pos $node(7) 20
set node(8) [$ns node]
$node(8) random-motion 0
$node(8) set X_ 50.0
$node(8) set Y_ 165.0
$node(8) set Z_ 0.0
$ns initial_node_pos $node(8) 20
set node(9) [$ns node]
$node(9) random-motion 0
$node(9) set X_ 180.0
$node(9) set Y_ 100.0
$node(9) set Z_ 0.0
$ns initial_node_pos $node(9) 20
###################################
# Nodes placement
###################################
#parameters for trace Inspect
#puts $scenarioTr "# nodes: $val(n), max time: $val(end)"
#puts $scenarioTr "# nominal range: 250"
#for {set i 0} {$i < $val(n)} {incr i} {
# set X [expr [$randomNodeX value] ]
# $node($i) set X_ $X
# set Y [expr [$randomNodeY value] ]
# $node($i) set Y_ $Y
# $node($i) set Z_ 0.0
# $ns initial_node_pos $node($i) 20
# puts $scenarioTr "\$node_($i) set X_ $X"
# puts $scenarioTr "\$node_($i) set Y_ $Y"
# puts $scenarioTr "\$node_($i) set Z_ 0.0"
#}
###################################
# moving nodes
###################################
#$ns at 3.0 "$node(0) setdest 175.0 90.0 0.0"
#$ns at 3.0 "$node(6) setdest 52.0 12.0 0.0"
#############################
# Data load
#############################
set udp0 [new Agent/UDP]
$ns attach-agent $node(0) $udp0
set null0 [new Agent/Null]
$ns attach-agent $node(6) $null0
$ns connect $udp0 $null0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 1000
$cbr0 attach-agent $udp0
$cbr0 set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
$ns at $val(dataStart) "$cbr0 start"
$ns at $val(dataStop) "$cbr0 stop"
###############################
# Routing model (for M-DART)
###############################
if {$val(rp) == "M-DART"} {
Agent/ATR set macFailed_ $val(macFailed)
Agent/ATR set etxMetric_ $val(etxMetric)
}
############################
# Tracing
############################
;#Simulation time print
proc timeTrace { tracePause} {
global ns
set now [$ns now]
$ns at [expr $now + $tracePause] "timeTrace $tracePause"
puts "$now simulation seconds"
}
$ns at 10.0 "timeTrace 10.0"
if {$val(rp) == "MDART"} {
for {set i 0} {$i < $val(n)} {incr i} {
# printing the routing table
$ns at [expr $val(end) - 1.0] "[$node($i) agent 255] routingTablePrint"
# printing the dht table
$ns at [expr $val(end) - 0.5] "[$node($i) agent 255] dhtTablePrint"
}
}
#########################
# Start and end
#########################
for {set i 0} {$i < $val(n) } {incr i} {
$ns at $val(end) "$node($i) reset";
}
$ns at $val(end) "fileTrace"
$ns at $val(end) "$ns halt"
proc fileTrace {} {
#global ns tracefile namTr
global ns tracefile scenarioTr
$ns flush-trace
close $tracefile ;#adding tis
#close $scenarioTr
#close $namTr
#exec nam nam.tr &
}
$ns run
This one only produce sent and drop packets. While this one:
###########################################
# Define Option
###########################################
set val(chan) Channel/WirelessChannel; #channel type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(propagation) Shado; #propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(ll) LL; #link layer type
set val(ifq) Queue/DropTail; #interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(mac) Mac/802_11; #MAC type
set val(rp) MDART; #routing protocol
set val(n) 16 ; #node number
set val(density) 4096; #node density [node/km^2]
set val(end) 206.0; #simulation time [s]
set val(dataStart) 100.0; #data start time [s]
set val(dataStop) [expr $val(end) - 6.0]; #data stop time [s]
set val(seed) 1; #general pseudo-random sequence generator
set val(macFailed) true; #ATR protocol: ns2 MAC failed callback
set val(etxMetric) true; #ATR protocol: ETX route metric
set val(throughput) 5.40; #CBR rate (<= 5.4Mb/s)
#########################################
# Channel Model
#########################################
#Setting antenna at center of node, 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.2
Antenna/OmniAntenna set Gt_ 1.0 ;#transmitter gain
Antenna/OmniAntenna set Gr_ 1.0 ;#receiver gain
Phy/WirelessPhy set L_ 1.0 ;#system loss factor
if {$val(propagation) == "TwoRay"} {
set val(prop) Propagation/TwoRayGround
set prop [new $val(prop)]
Phy/WirelessPhy set CPThresh_ 10.0 ;#capt. thresh. in Watt
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#carr. sens. thresh.
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#receive signal thresh
Phy/WirelessPhy set freq_ 2.4e9 ;#chan. freq. (Hz)
Phy/WirelessPhy set Pt_ 0.28 ;#trans. signal power (Watt)
}
if {$val(propagation) == "Shado"} {
set val(prop) Propagation/Shadowing
set prop [new $val(prop)]
$prop set pathlossExp_ 3.8 ;#path loss exponent
$prop set std_db_ 2.0 ;#shadowing deviation (dB)
$prop set seed_ 1 ;#RNG seed
$prop set dist0_ 1.0 ;#ref. distance (m)
$prop set CPThresh_ 10.0 ;#capt. thresh (Watt)
$prop set RXThresh_ 2.37e-13 ;#rec. sign. thresh
$prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;#carr. sens. thresh
$prop set freq_ 2.4e9 ;#chann. freq (Hz)
Phy/WirelessPhy set Pt_ 0.28
}
#####################################################
# Topology Definition
#####################################################
#Scenario creation according to chosen node density
set val(dim) [expr $val(n) / $val(density)]
set val(x) [expr [expr sqrt($val(dim))] * 1000]
set val(y) [expr [expr sqrt($val(dim))] * 1000]
####################################################
# Pseudo-random sequence generator
####################################################
#General pseudo-random sequence geneator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 1.0
$randomSeed set max_ 100.0
#Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]
#Mobility model: Y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]
#Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(n) - 1]
################################
# General definition
################################
#Instantiate the simulator
set ns [new Simulator]
#Define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create GOD
create-god $val(n)
##############################
# Trace file definition
##############################
;#create trace object for ns, nam, monitor and inspect
set tracefile [open ns.tr w] ;#Adding this
$ns trace-all $tracefile ;#adding this
;#new format for wireless traces
$ns use-newtrace
set namTr [open nam.tr w]
$ns namtrace-all-wireless $namTr $val(x) $val(y)
set scenarioTr [open scenario.tr w]
#nam file creation
#set namfile [open mdart.nam w]
#$ns namtrace-all $namfile
#$ns namtrace-all-wireless $namfile $val(x) $val(y)
#set chan [new $val(chan)];
#create channel
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
$prop topography $topo
#Global node setting
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance $prop \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
################################
# Nodes definition
################################
;# Create the specified number of nodes [$val(n)] and "attach" them to the channel.
#for {set i 0} {$i < $val(n) } {incr i} {
# set node($i) [$ns node]
# $node($i) random-motion 0 ; #disabled random motion
#$ns initial_node_pos $n($i) 20 ;
#}
################################
# Node conode(figurationode(
################################
;#node initial coordinates
set node(0) [$ns node]
$node(0) random-motion 0
$node(0) set X_ 20.0
$node(0) set Y_ 65.0
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
set node(1) [$ns node]
$node(1) random-motion 0
$node(1) set X_ 50.0
$node(1) set Y_ 10.0
$node(1) set Z_ 0.0
$ns initial_node_pos $node(1) 20
set node(2) [$ns node]
$node(2) random-motion 0
$node(2) set X_ 0.0
$node(2) set Y_ 0.0
$node(2) set Z_ 0.0
$ns initial_node_pos $node(2) 20
set node(3) [$ns node]
$node(3) random-motion 0
$node(3) set X_ 95.0
$node(3) set Y_ 35.0
$node(3) set Z_ 0.0
$ns initial_node_pos $node(3) 20
set node(4) [$ns node]
$node(4) random-motion 0
$node(4) set X_ 8.0
$node(4) set Y_ 50.0
$node(4) set Z_ 0.0
$ns initial_node_pos $node(4) 20
set node(5) [$ns node]
$node(5) random-motion 0
$node(5) set X_ 65.0
$node(5) set Y_ 20.0
$node(5) set Z_ 0.0
$ns initial_node_pos $node(5) 20
set node(6) [$ns node]
$node(6) random-motion 0
$node(6) set X_ 146.0
$node(6) set Y_ 5.0
$node(6) set Z_ 0.0
$ns initial_node_pos $node(6) 20
set node(7) [$ns node]
$node(7) random-motion 0
$node(7) set X_ 20.0
$node(7) set Y_ 146.0
$node(7) set Z_ 0.0
$ns initial_node_pos $node(7) 20
$ns node-config \
-channel $chan_2_
set node(8) [$ns node]
$node(8) random-motion 0
$node(8) set X_ 70.0
$node(8) set Y_ 70.0
$node(8) set Z_ 0.0
$ns initial_node_pos $node(8) 20
set node(9) [$ns node]
$node(9) random-motion 0
$node(9) set X_ 130.0
$node(9) set Y_ 180.0
$node(9) set Z_ 0.0
$ns initial_node_pos $node(9) 20
set node(10) [$ns node]
$node(10) random-motion 0
$node(10) set X_ 160.0
$node(10) set Y_ 0.0
$node(10) set Z_ 0.0
$ns initial_node_pos $node(10) 20
set node(11) [$ns node]
$node(11) random-motion 0
$node(11) set X_ 150.0
$node(11) set Y_ 165.0
$node(11) set Z_ 0.0
$ns initial_node_pos $node(11) 20
set node(12) [$ns node]
$node(12) random-motion 0
$node(12) set X_ 110.0
$node(12) set Y_ 80.0
$node(12) set Z_ 0.0
$ns initial_node_pos $node(12) 20
set node(13) [$ns node]
$node(13) random-motion 0
$node(13) set X_ 65.0
$node(13) set Y_ 114.0
$node(13) set Z_ 0.0
$ns initial_node_pos $node(13) 20
set node(14) [$ns node]
$node(14) random-motion 0
$node(14) set X_ 50.0
$node(14) set Y_ 165.0
$node(14) set Z_ 0.0
$ns initial_node_pos $node(14) 20
set node(15) [$ns node]
$node(15) random-motion 0
$node(15) set X_ 180.0
$node(15) set Y_ 100.0
$node(15) set Z_ 0.0
$ns initial_node_pos $node(15) 20
###################################
# Nodes placement
###################################
#parameters for trace Inspect
puts $scenarioTr "# nodes: $val(n), max time: $val(end)"
puts $scenarioTr "# nominal range: 250"
for {set i 0} {$i < $val(n)} {incr i} {
set X [expr [$randomNodeX value] ]
$node($i) set X_ $X
set Y [expr [$randomNodeY value] ]
$node($i) set Y_ $Y
$node($i) set Z_ 0.0
$ns initial_node_pos $node($i) 20
puts $scenarioTr "\$node_($i) set X_ $X"
puts $scenarioTr "\$node_($i) set Y_ $Y"
puts $scenarioTr "\$node_($i) set Z_ 0.0"
}
###################################
# moving nodes
###################################
#$ns at 3.0 "$n1 setdest 62.0 55.0 25.0"
#$ns at 3.0 "$n7 setdest 52.0 12.0 5.0"
#############################
# Data load
#############################
for {set i 0} {$i < $val(n)} {incr i} {
set udp($i) [new Agent/UDP]
$ns attach-agent $node($i) $udp($i)
set dest [expr round([$randomNode value])]
while {$dest == $i} {
set dest [expr round([$randomNode value])]
}
set monitor($dest) [new Agent/LossMonitor]
$ns attach-agent $node($dest) $monitor($dest)
$ns connect $udp($i) $monitor($dest)
set cbr($i) [new Application/Traffic/CBR]
$cbr($i) attach-agent $udp($i)
$cbr($i) set packetSize_ 1000
$cbr($i) set random_ false
$cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
$ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
$ns at $val(dataStop) "$cbr($i) stop"
}
###################################
# Nodes mobility (data load)
###################################
#for {set i 0} {$i < $val(n)} {incr i} {
# set udp($i) [new Agent/UDP]
# $ns attach-agent $n0 $udp($i)
# set dest [expr round([$randomNode value])]
# while {$dest == $i} {
# set dest [expr round([$randomNode value])]
# }
# set monitor($dest) [new Agent/LossMonitor]
# $ns attach-agent $n($dest) $monitor($dest)
# $ns connect $udp1 $monitor($dest)
# set cbr($i) [new Application/Traffic/CBR]
# $cbr($i) attach-agent $udp($i)
# $cbr($i) set packetSize_ 1000
# $cbr($i) set random_ false
# $cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
# $ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
# $ns at $val(dataStop) "$cbr($i) stop"
#}
###############################
# Routing model (for M-DART)
###############################
if {$val(rp) == "M-DART"} {
Agent/ATR set macFailed_ $val(macFailed)
Agent/ATR set etxMetric_ $val(etxMetric)
}
############################
# Tracing
############################
;#Simulation time print
proc timeTrace { tracePause} {
global ns
set now [$ns now]
$ns at [expr $now + $tracePause] "timeTrace $tracePause"
puts "$now simulation seconds"
}
$ns at 10.0 "timeTrace 10.0"
if {$val(rp) == "MDART"} {
for {set i 0} {$i < $val(n)} {incr i} {
# printing the routing table
$ns at [expr $val(end) - 1.0] "[$node($i) agent 255] routingTablePrint"
# printing the dht table
$ns at [expr $val(end) - 0.5] "[$node($i) agent 255] dhtTablePrint"
}
}
#########################
# Start and end
#########################
for {set i 0} {$i < $val(n) } {incr i} {
$ns at $val(end) "$node($i) reset";
}
$ns at $val(end) "fileTrace"
$ns at $val(end) "$ns halt"
proc fileTrace {} {
global ns tracefile namTr
global ns tracefile scenarioTr
$ns flush-trace
close $tracefile ;#adding tis
close $scenarioTr
#close $namTr
#exec nam nam.tr &
}
$ns run
This script produce sent, receive and drop but no forward... The difference between this two script is at the Data Load part... Thanks :D
I modified the M-DART tcl files and when I run NS2 animation, it pops out this:
Skipping duplicate node (1), etc...
The modified script:
###########################################
# Define Option
###########################################
set val(chan) Channel/WirelessChannel; #channel type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(propagation) Shado; #propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(ll) LL; #link layer type
set val(ifq) Queue/DropTail; #interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(mac) Mac/802_11; #MAC type
set val(rp) MDART; #routing protocol
set val(n) 16 ; #node number
set val(density) 4096; #node density [node/km^2]
set val(end) 206.0; #simulation time [s]
set val(dataStart) 100.0; #data start time [s]
set val(dataStop) [expr $val(end) - 6.0]; #data stop time [s]
set val(seed) 1; #general pseudo-random sequence generator
set val(macFailed) true; #ATR protocol: ns2 MAC failed callback
set val(etxMetric) true; #ATR protocol: ETX route metric
set val(throughput) 5.40; #CBR rate (<= 5.4Mb/s)
#########################################
# Channel Model
#########################################
#Setting antenna at center of node, 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.2
Antenna/OmniAntenna set Gt_ 1.0 ;#transmitter gain
Antenna/OmniAntenna set Gr_ 1.0 ;#receiver gain
Phy/WirelessPhy set L_ 1.0 ;#system loss factor
if {$val(propagation) == "TwoRay"} {
set val(prop) Propagation/TwoRayGround
set prop [new $val(prop)]
Phy/WirelessPhy set CPThresh_ 10.0 ;#capt. thresh. in Watt
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#carr. sens. thresh.
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#receive signal thresh
Phy/WirelessPhy set freq_ 2.4e9 ;#chan. freq. (Hz)
Phy/WirelessPhy set Pt_ 0.28 ;#trans. signal power (Watt)
}
if {$val(propagation) == "Shado"} {
set val(prop) Propagation/Shadowing
set prop [new $val(prop)]
$prop set pathlossExp_ 3.8 ;#path loss exponent
$prop set std_db_ 2.0 ;#shadowing deviation (dB)
$prop set seed_ 1 ;#RNG seed
$prop set dist0_ 1.0 ;#ref. distance (m)
$prop set CPThresh_ 10.0 ;#capt. thresh (Watt)
$prop set RXThresh_ 2.37e-13 ;#rec. sign. thresh
$prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;#carr. sens. thresh
$prop set freq_ 2.4e9 ;#chann. freq (Hz)
Phy/WirelessPhy set Pt_ 0.28
}
#####################################################
# Topology Definition
#####################################################
#Scenario creation according to chosen node density
set val(dim) [expr $val(n) / $val(density)]
set val(x) [expr [expr sqrt($val(dim))] * 1000]
set val(y) [expr [expr sqrt($val(dim))] * 1000]
####################################################
# Pseudo-random sequence generator
####################################################
#General pseudo-random sequence geneator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 1.0
$randomSeed set max_ 100.0
#Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]
#Mobility model: Y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]
#Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(n) - 1]
################################
# General definition
################################
#Instantiate the simulator
set ns [new Simulator]
#Define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create GOD
create-god $val(n)
##############################
# Trace file definition
##############################
;#create trace object for ns, nam, monitor and inspect
set tracefile [open ns.tr w] ;#Adding this
$ns trace-all $tracefile ;#adding this
;#new format for wireless traces
$ns use-newtrace
set namTr [open nam.tr w]
$ns namtrace-all-wireless $namTr $val(x) $val(y)
set scenarioTr [open scenario.tr w]
#nam file creation
#set namfile [open mdart.nam w]
#$ns namtrace-all $namfile
#$ns namtrace-all-wireless $namfile $val(x) $val(y)
#set chan [new $val(chan)];
#create channel
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
$prop topography $topo
#Global node setting
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance $prop \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
################################
# Nodes definition
################################
;# Create the specified number of nodes [$val(n)] and "attach" them to the channel.
#for {set i 0} {$i < $val(n) } {incr i} {
# set node($i) [$ns node]
# $node($i) random-motion 0 ; #disabled random motion
#$ns initial_node_pos $n($i) 20 ;
#}
################################
# Node conode(figurationode(
################################
;#node initial coordinates
set node(0) [$ns node]
$node(0) random-motion 0
$node(0) set X_ 20.0
$node(0) set Y_ 65.0
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
set node(1) [$ns node]
$node(1) random-motion 0
$node(1) set X_ 50.0
$node(1) set Y_ 10.0
$node(1) set Z_ 0.0
$ns initial_node_pos $node(1) 20
set node(2) [$ns node]
$node(2) random-motion 0
$node(2) set X_ 0.0
$node(2) set Y_ 0.0
$node(2) set Z_ 0.0
$ns initial_node_pos $node(2) 20
set node(3) [$ns node]
$node(3) random-motion 0
$node(3) set X_ 95.0
$node(3) set Y_ 35.0
$node(3) set Z_ 0.0
$ns initial_node_pos $node(3) 20
set node(4) [$ns node]
$node(4) random-motion 0
$node(4) set X_ 8.0
$node(4) set Y_ 50.0
$node(4) set Z_ 0.0
$ns initial_node_pos $node(4) 20
set node(5) [$ns node]
$node(5) random-motion 0
$node(5) set X_ 65.0
$node(5) set Y_ 20.0
$node(5) set Z_ 0.0
$ns initial_node_pos $node(5) 20
set node(6) [$ns node]
$node(6) random-motion 0
$node(6) set X_ 146.0
$node(6) set Y_ 5.0
$node(6) set Z_ 0.0
$ns initial_node_pos $node(6) 20
set node(7) [$ns node]
$node(7) random-motion 0
$node(7) set X_ 20.0
$node(7) set Y_ 146.0
$node(7) set Z_ 0.0
$ns initial_node_pos $node(7) 20
$ns node-config \
-channel $chan_2_
set node(8) [$ns node]
$node(8) random-motion 0
$node(8) set X_ 70.0
$node(8) set Y_ 70.0
$node(8) set Z_ 0.0
$ns initial_node_pos $node(8) 20
set node(9) [$ns node]
$node(9) random-motion 0
$node(9) set X_ 130.0
$node(9) set Y_ 180.0
$node(9) set Z_ 0.0
$ns initial_node_pos $node(9) 20
set node(10) [$ns node]
$node(10) random-motion 0
$node(10) set X_ 160.0
$node(10) set Y_ 0.0
$node(10) set Z_ 0.0
$ns initial_node_pos $node(10) 20
set node(11) [$ns node]
$node(11) random-motion 0
$node(11) set X_ 150.0
$node(11) set Y_ 165.0
$node(11) set Z_ 0.0
$ns initial_node_pos $node(11) 20
set node(12) [$ns node]
$node(12) random-motion 0
$node(12) set X_ 110.0
$node(12) set Y_ 80.0
$node(12) set Z_ 0.0
$ns initial_node_pos $node(12) 20
set node(13) [$ns node]
$node(13) random-motion 0
$node(13) set X_ 65.0
$node(13) set Y_ 114.0
$node(13) set Z_ 0.0
$ns initial_node_pos $node(13) 20
set node(14) [$ns node]
$node(14) random-motion 0
$node(14) set X_ 50.0
$node(14) set Y_ 165.0
$node(14) set Z_ 0.0
$ns initial_node_pos $node(14) 20
set node(15) [$ns node]
$node(15) random-motion 0
$node(15) set X_ 180.0
$node(15) set Y_ 100.0
$node(15) set Z_ 0.0
$ns initial_node_pos $node(15) 20
###################################
# Nodes placement
###################################
#parameters for trace Inspect
puts $scenarioTr "# nodes: $val(n), max time: $val(end)"
puts $scenarioTr "# nominal range: 250"
for {set i 0} {$i < $val(n)} {incr i} {
set X [expr [$randomNodeX value] ]
$node($i) set X_ $X
set Y [expr [$randomNodeY value] ]
$node($i) set Y_ $Y
$node($i) set Z_ 0.0
$ns initial_node_pos $node($i) 20
puts $scenarioTr "\$node_($i) set X_ $X"
puts $scenarioTr "\$node_($i) set Y_ $Y"
puts $scenarioTr "\$node_($i) set Z_ 0.0"
}
###################################
# moving nodes
###################################
#$ns at 3.0 "$n1 setdest 62.0 55.0 25.0"
#$ns at 3.0 "$n7 setdest 52.0 12.0 5.0"
#############################
# Data load
#############################
for {set i 0} {$i < $val(n)} {incr i} {
set udp($i) [new Agent/UDP]
$ns attach-agent $node($i) $udp($i)
set dest [expr round([$randomNode value])]
while {$dest == $i} {
set dest [expr round([$randomNode value])]
}
set monitor($dest) [new Agent/LossMonitor]
$ns attach-agent $node($dest) $monitor($dest)
$ns connect $udp($i) $monitor($dest)
set cbr($i) [new Application/Traffic/CBR]
$cbr($i) attach-agent $udp($i)
$cbr($i) set packetSize_ 1000
$cbr($i) set random_ false
$cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
$ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
$ns at $val(dataStop) "$cbr($i) stop"
}
###################################
# Nodes mobility (data load)
###################################
#for {set i 0} {$i < $val(n)} {incr i} {
# set udp($i) [new Agent/UDP]
# $ns attach-agent $n0 $udp($i)
# set dest [expr round([$randomNode value])]
# while {$dest == $i} {
# set dest [expr round([$randomNode value])]
# }
# set monitor($dest) [new Agent/LossMonitor]
# $ns attach-agent $n($dest) $monitor($dest)
# $ns connect $udp1 $monitor($dest)
# set cbr($i) [new Application/Traffic/CBR]
# $cbr($i) attach-agent $udp($i)
# $cbr($i) set packetSize_ 1000
# $cbr($i) set random_ false
# $cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
# $ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
# $ns at $val(dataStop) "$cbr($i) stop"
#}
###############################
# Routing model (for M-DART)
###############################
if {$val(rp) == "M-DART"} {
Agent/ATR set macFailed_ $val(macFailed)
Agent/ATR set etxMetric_ $val(etxMetric)
}
############################
# Tracing
############################
;#Simulation time print
proc timeTrace { tracePause} {
global ns
set now [$ns now]
$ns at [expr $now + $tracePause] "timeTrace $tracePause"
puts "$now simulation seconds"
}
$ns at 10.0 "timeTrace 10.0"
if {$val(rp) == "MDART"} {
for {set i 0} {$i < $val(n)} {incr i} {
# printing the routing table
$ns at [expr $val(end) - 1.0] "[$node($i) agent 255] routingTablePrint"
# printing the dht table
$ns at [expr $val(end) - 0.5] "[$node($i) agent 255] dhtTablePrint"
}
}
#########################
# Start and end
#########################
for {set i 0} {$i < $val(n) } {incr i} {
$ns at $val(end) "$node($i) reset";
}
$ns at $val(end) "fileTrace"
$ns at $val(end) "$ns halt"
proc fileTrace {} {
global ns tracefile namTr
global ns tracefile scenarioTr
$ns flush-trace
close $tracefile ;#adding tis
close $scenarioTr
#close $namTr
#exec nam nam.tr &
}
$ns run
The original scripts already has assigned a random nodes generator lines, but I added a fixed node positioning. My question is, is it ok for me to just ignore it? Because if I comment the RNG part, there will be no data transfer between nodes. Thanks :)
I am simulating Wireless Sensor Network Using NS2.35 and I get an error
ns: _o108malicious: invalid command name "_o108malicious"
while executing "o108malicious"
when i add $ns at 3.2 "[$node($id) set ragent_]malicious"this line i get
this error.
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(ifqlen) 150
set val(nn) 25
set val(rp) AODV
set val(x) 800
set val(y) 500
set val(stop) 150
#-------Event scheduler object creation--------#
set ns [new Simulator]
#used to schedule the events that are running at the same time
$ns use-scheduler Heap
#Creating trace file and nam file
set tracefd [open aodv.tr w]
set namtrace [open 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)
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
# node creation
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
$node_($i) color "black"
$node_($i) label Node$i
}
#initial location of nodes
for {set i 0} {$i < $val(nn)} {incr i} {
$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0
$node_($i) color "green"
}
for {set i 0} {$i < $val(nn)} {incr i} {
$ns at 0.1 "$node_($i) color darkviolet"
$ns at 0.1 "$node_($i) label Node$i"
}
#generation of movements
$ns at 2.0 "$node_(0) setdest 20.0 10.0 0.0"
$ns at 5.0 "$node_(24) setdest 60.0 50.0 50.0"
$ns at 7.0 "$node_(2) setdest 120.0 100.0 50.0"
$ns at 0.0 "$node_(17) setdest 140.0 150.0 50.0"
$ns at 0.0 "$node_(20) setdest 160.0 180.0 50.0"
$ns at 12.0 "$node_(19) setdest 130.0 230.0 6.0"
$ns at 23.0 "$node_(5) setdest 40.0 165.0 9.0"
$ns at 20.0 "$node_(7) setdest 50.0 180.0 13.0"
$ns at 3.0 "$node_(4) setdest 80.0 156.0 5.0"
$ns at 6.0 "$node_(10) setdest 56.0 200.0 10.0"
$ns at 13.0 "$node_(15) setdest 88.0 20.0 45.0"
$ns at 6.0 "$node_(3) setdest 177.0 120.0 45.0"
$ns at 23.0 "$node_(1) setdest 140.0 70.0 20.0"
set fp2 [open "/opt/ns-allinone-2.35/ns-2.35/input.txt" r]
set filed [read $fp2]
puts $filed
set data [split $filed "\n"]
puts $data
foreach line2 $data {
set length2 [string length $line2]
if {$length2 != 0} {
lassign $line2 src dest
puts $src
set tcp1 [new Agent/TCP/Newreno]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns attach-agent $node_($src) $tcp1
$ns attach-agent $node_($dest) $sink1
$ns connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 3.0 "$node_($src) color brown"
$ns at 3.0 "$node_($dest) color brown"
$ns at 3.0 "$ftp1 start"
}
}
close $fp2
set fp1 [open "/opt/ns-allinone-2.35/ns-2.35/mali.txt" r]
set file_data [read $fp1]
set data1 [split $file_data "\n"]
foreach line $data1 {
set length1 [string length $line]
if {$length1 !=0} {
set id $line
$ns at 3.2 "[$node_($id) set ragent_]malicious"
$ns at 3.2 "$node_($id) color red"
$ns at 3.2 "$node_($id) label malicious"
}
}
close $fp1
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 20 defines the node size for nam
$ns initial_node_pos $node_($i) 20
}
# 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 149.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam aodv.nam &
exit 0
}
#$ns at 150.01 "puts \"end simulation\" ; $ns halt"
$ns run
enter code here
input.txt
5 4
3 9
6 10
1 0
mali.txt
5
3
When the "set malicious" line $ns at 3.2 "[$node_($id) set ragent_]malicious" ... is edited to $ns at 3.2 "[$node_($id) set ragent_] hacker" ... then your files are working fairly OK :
$ ns235-malicious mal-wsn.tcl
num_nodes is set 25
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
5 4
3 9
6 10
1 0
{5 4} {3 9} {6 10} {1 0 } {}
5
3
6
1
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
ns: scheduler going backwards in time from 6.000000 to 0.000000.
The files aodv.nam 200.0kB, aodv.tr 184.0kB are created. $ nam aodv.nam & : OK animation and communication. $ awk -f tess-Packets.awk aodv.tr : OK, the output file "Packets-arrival-time.txt" has 338 lines.
Not quite stable. Can also end the simulation with
SORTING LISTS ...DONE !
Direction for pkt-flow not specified; Sending pkt up the stack on default.
... And NAM opens OK. The files are now: aodv.nam 328.0kB, aodv.tr 308.0kB .
Perfect. Ends with SORTING LISTS ...DONE!. Animation: Perfect. Files are aodv.nam 7.0 MB, aodv.tr 5.7 MB .
Direction for pkt-flow not specified; Sending pkt up the stack on default.
check_pktRTS:Invalid MAC Control subtype
... Conclusion : You will have to run the file several times to get a perfect result. Can be 10 times if Ubuntu. 3 - 4 times if an rpm based OS.
Malicious build example https://groups.google.com/forum/?fromgroups#!searchin/ns-users/malicious%7Csort:date/ns-users/-3JfDWhN2fY/BiOwZuWSBwAJ → 11/10/17.
When I try to run my own tcl script (10.tcl) in ns2.34, it gives me this error.
couldn't read file "/home/bony/ns-2.34/ns-allinone-2.34/ns-2.34.aodv":
no such file or directory
while executing
"source.orig /home/bony/ns-2.34/ns-allinone-2.34/ns-2.34.aodv"
("uplevel" body line 1)
invoked from within
"uplevel source.orig [list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
..."
(procedure "source" line 8)
invoked from within
"$ns_ $path.$valrp"
(file "10.tcl" line 20)
This is the 10.tcl code I'm using. when I try to run this 10.tcl file in ns2 in Fedora, it gives me above error.
#===================================
# Simulation parameters setup
#===================================
set ns_ source
set path /home/bony/ns-2.34/ns-allinone-2.34/ns-2.34
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) 10 ;# number of mobilenodes
set valrp aodv ;# routing protocol
set val(x) 943 ;# X dimension of topography
set val(y) 567 ;# Y dimension of topography
set val(stop) 20.0 ;# time of simulation end
set speed 10
$ns_ $path.$valrp
set packet_size 512;#packetsize
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#Setup topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $valrp \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 10 nodes
set n(0) [$ns node]
$n(0) set X_ 284
$n(0) set Y_ 380
$n(0) set Z_ 0.0
$ns initial_node_pos $n(0) 20
set n(1) [$ns node]
$n(1) set X_ 343
$n(1) set Y_ 195
$n(1) set Z_ 0.0
$ns initial_node_pos $n(1) 20
set n(2) [$ns node]
$n(2) set X_ 411
$n(2) set Y_ 308
$n(2) set Z_ 0.0
$ns initial_node_pos $n(2) 20
set n(3) [$ns node]
$n(3) set X_ 468
$n(3) set Y_ 460
$n(3) set Z_ 0.0
$ns initial_node_pos $n(3) 20
set n(4) [$ns node]
$n(4) set X_ 567
$n(4) set Y_ 363
$n(4) set Z_ 0.0
$ns initial_node_pos $n(4) 20
set n(5) [$ns node]
$n(5) set X_ 586
$n(5) set Y_ 194
$n(5) set Z_ 0.0
$ns initial_node_pos $n(5) 20
set n(6) [$ns node]
$n(6) set X_ 698
$n(6) set Y_ 343
$n(6) set Z_ 0.0
$ns initial_node_pos $n(6) 20
set n(7) [$ns node]
$n(7) set X_ 698
$n(7) set Y_ 467
$n(7) set Z_ 0.0
$ns initial_node_pos $n(7) 20
set n(8) [$ns node]
$n(8) set X_ 783
$n(8) set Y_ 186
$n(8) set Z_ 0.0
$ns initial_node_pos $n(8) 20
set n(9) [$ns node]
$n(9) set X_ 843
$n(9) set Y_ 361
$n(9) set Z_ 0.0
$ns initial_node_pos $n(9) 20
for {set i 0} { $i < $val(nn)} {incr i} {
set tcp($i) [new Agent/TCP]
$ns attach-agent $n($i) $tcp($i)
set sink($i) [new Agent/LossMonitor]
$ns attach-agent $n($i) $sink($i)
}
#===================================
# Agents Definition
#===================================
#===================================
# Applications Definition
#===================================
proc attach-CBR-traffic { node sink size interval } {
#Get an instance of the simulator
set ns [Simulator instance]
#Create a CBR agent and attach it to the node
set cbr [new Agent/CBR]
$ns attach-agent $node $cbr
$cbr set packetSize_ $size
$cbr set interval_ .05
#Attach CBR source to sink;
$ns connect $cbr $sink
return $cbr
}
set cbr00 [attach-CBR-traffic $n(0) $sink(9) 512 $interval]
$ns at 1.21 "$cbr00 start"
$ns at 0.86 "$n(0) add-mark MARK darkgreen square"
$ns at 0.86 "$n(0) label Sender"
$ns at 0.86 "$n(9) add-mark MARK magenta circle"
$ns at 0.86 "$n(9) label Receiver"
for {set i 0} {$i < $val(nn) } {incr i} {
set timemin 1
set timemax 10
set timemaxFactor [expr [expr $timemax + 1] - $timemin]
set timevalue [expr int([expr rand() * 100])]
set timevalue [expr [expr $timevalue % $timemaxFactor] + $timemin]
set xmin 500
set xmax 1200
set xmaxFactor [expr [expr $xmax + 1] - $xmin]
set xvalue [expr int([expr rand() * 100])]
set xvalue [expr [expr $xvalue % $xmaxFactor] + $xmin]
set ymin 50
set ymax 800
set ymaxFactor [expr [expr $ymax + 1] - $ymin]
set yvalue [expr int([expr rand() * 100])]
set yvalue [expr [expr $yvalue % $ymaxFactor] + $ymin]
$ns at $timevalue "$n($i) setdest $xvalue $yvalue $speed"
}
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec sed -i "/d -t /d" out.nam
exec nam out.nam &
exec awk -f pdf.awk out.tr > Results
exec awk -f e2edelay.awk out.tr >> Results
exec awk -f throughput.awk out.tr >> Results
exec awk -f control_overhead.awk out.tr >> Results
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n($i) reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run