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 :)
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 used VBF routing, in aqua-sim. However, i noticed that the source packet never reaches the sink! and consumed energy exceed the initial energy!
what is the causes for that?
Here is the tcl file
set opt(chan) Channel/UnderwaterChannel
set opt(prop) Propagation/UnderwaterPropagation
set opt(netif) Phy/UnderwaterPhy
set opt(mac) Mac/UnderwaterMac/BroadcastMac
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(energy) EnergyModel
set opt(txpower) 2.0
set opt(rxpower) 0.75
set opt(initialenergy) 10000
set opt(idlepower) 0.008
set opt(ant) Antenna/OmniAntenna
set opt(filters) GradientFilter ;# options can be one or more of
;# TPP/OPP/Gear/Rmst/SourceRoute/Log/TagFilter
set opt(minspeed) 0.2 ;#minimum speed of node
set opt(maxspeed) 3 ;#maximum speed of node
set opt(speed) 0.5 ;#speed of node
set opt(position_update_interval) 0.3 ;# the length of period to update node's position
set opt(packet_size) 50 ;#50 bytes
set opt(routing_control_packet_size) 20 ;#bytes
set opt(ifqlen) 500 ;# max queue length in if
set opt(nn) 401 ;# number of nodes
set opt(x) 3000 ;# X dimension of the topography
set opt(y) 3000 ;# Y dimension of the topography
set opt(z) 1000
set opt(seed) 11
set opt(stop) 5000 ;# simulation time
set opt(prestop) 4990 ;# time to prepare to stop
set opt(tr) "test.tr" ;# trace file
set opt(datafile) "test.data"
set opt(nam) "test.nam" ;# nam file
set opt(adhocRouting) Vectorbasedforward
set opt(width) 100
set opt(interval) 10.0
set opt(range) 500 ;#range of each node in meters
if { $argc > 0 } {
set opt(seed) [lindex $argv 0]
set opt(nn) [lindex $argv 1]
set opt(datafile) [lindex $argv 2]
}
puts "the file name is $opt(datafile)"
puts "the sending interval is $opt(interval)"
# ==================================================================
LL set mindelay_ 50us
LL set delay_ 25us
LL set bandwidth_ 0 ;# not used
Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
#Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Z_ 0.05
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
Agent/Vectorbasedforward set hop_by_hop_ 0
Mac/UnderwaterMac set bit_rate_ 1.0e4 ;#10kbps
Mac/UnderwaterMac set encoding_efficiency_ 1
Mac/UnderwaterMac/BroadcastMac set packetheader_size_ 0 ;# #of bytes
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/UnderwaterPhy set CPThresh_ 10 ;#10.0
Phy/UnderwaterPhy set CSThresh_ 0 ;#1.559e-11
Phy/UnderwaterPhy set RXThresh_ 0 ;#3.652e-10
#Phy/WirelessPhy set Rb_ 2*1e6
Phy/UnderwaterPhy set Pt_ 0.2818
Phy/UnderwaterPhy set freq_ 25 ;# 25khz
Phy/UnderwaterPhy set K_ 2.0 ;# spherical spreading
# Initialize Global Variables
#
#set sink_ 1
set ns_ [new Simulator]
set topo [new Topography]
$topo load_cubicgrid $opt(x) $opt(y) $opt(z)
#$ns_ use-newtrace
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd
set nf [open $opt(nam) w]
$ns_ namtrace-all-wireless $nf $opt(x) $opt(y)
set data [open $opt(datafile) a]
set total_number [expr $opt(nn)-1]
set god_ [create-god $opt(nn)]
$ns_ at 0.0 "$god_ set_filename $opt(datafile)"
set chan_1_ [new $opt(chan)]
global defaultRNG
$defaultRNG seed $opt(seed)
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
#-channelType $opt(chan) \
-agentTrace OFF \
-routerTrace OFF \
-macTrace ON\
-topoInstance $topo\
-energyModel $opt(energy)\
-txPower $opt(txpower)\
-rxPower $opt(rxpower)\
-initialEnergy $opt(initialenergy)\
-idlePower $opt(idlepower)\
-channel $chan_1_
puts "Width=$opt(width)"
#Set the Sink node
set node_(0) [ $ns_ node 0]
$node_(0) set sinkStatus_ 1
$god_ new_node $node_(0)
$node_(0) set X_ 2000
$node_(0) set Y_ 2000
$node_(0) set Z_ 1
$node_(0) set -cx 2000
$node_(0) set -cy 2000
$node_(0) set -cz 1
$node_(0) set passive 1
set rt [$node_(0) set ragent_]
$rt set control_packet_size $opt(routing_control_packet_size)
set a_(0) [new Agent/UWSink]
$ns_ attach-agent $node_(0) $a_(0)
$a_(0) attach-vectorbasedforward $opt(width)
$a_(0) cmd set-range $opt(range)
$a_(0) cmd set-target-x 2000
$a_(0) cmd set-target-y 2000
$a_(0) cmd set-target-z 1
$a_(0) cmd set-filename $opt(datafile)
$a_(0) cmd set-packetsize $opt(packet_size) ;# # of bytes
for { set i 1 } { $i<$opt(nn)-1 } {incr i } {
set node_($i) [$ns_ node $i]
$node_($i) set sinkStatus_ 1
$god_ new_node $node_($i)
$node_($i) set passive 1
set rt [$node_($i) set ragent_]
$rt set control_packet_size $opt(routing_control_packet_size)
$node_($i) set max_speed $opt(maxspeed)
$node_($i) set min_speed $opt(minspeed)
#$node_($i) set position_update_interval_ $opt(position_update_interval)
set a_($i) [new Agent/UWSink]
$ns_ attach-agent $node_($i) $a_($i)
$a_($i) attach-vectorbasedforward $opt(width)
$a_($i) cmd set-range $opt(range)
$a_($i) cmd set-target-x -20
$a_($i) cmd set-target-y -10
$a_($i) cmd set-target-z -20
$a_($i) cmd set-filename $opt(datafile)
$a_($i) cmd set-packetsize $opt(packet_size) ;
}
Then i give the position of all my nodes from 1-399, as the following
$node_(1) set X_ 2136.167656
$node_(1) set Y_ 295.493365
$node_(1) set Z_ 584.859352
$node_(2) set X_ 38.448393
$node_(2) set Y_ 1111.699107
$node_(2) set Z_ 375.380589
$node_(3) set X_ 1937.160663
$node_(3) set Y_ 1171.175274
$node_(3) set Z_ 532.478177
..
$node_(399) set X_ 234.898387
$node_(399) set Y_ 1004.866538
$node_(399) set Z_ 985.310608
the source node and the rest of tcl file is:
#Set the source node
set node_($total_number) [$ns_ node $total_number]
$god_ new_node $node_($total_number)
$node_($total_number) set sinkStatus_ 1
$node_($total_number) set X_ 1650.370304
$node_($total_number) set Y_ 1166.115416
$node_($total_number) set Z_ 274.908599
$node_($total_number) set-cx 1650.370304
$node_($total_number) set-cy 1166.115416
$node_($total_number) set-cz 274.908599
set rt [$node_($total_number) set ragent_]
$rt set control_packet_size $opt(routing_control_packet_size)
set a_($total_number) [new Agent/UWSink]
$ns_ attach-agent $node_($total_number) $a_($total_number)
$a_($total_number) attach-vectorbasedforward $opt(width)
$a_($total_number) cmd set-range $opt(range)
$a_($total_number) cmd set-target-x 2000
$a_($total_number) cmd set-target-y 2000
$a_($total_number) cmd set-target-z 1
$a_($total_number) cmd set-filename $opt(datafile)
$a_($total_number) cmd set-packetsize $opt(packet_size) ;# # of bytes
set start_time 1.33
for { set j 1 } { $i<$opt(nn)-1 } {incr j } {
$a_($j) set data_rate_ [expr 1.0/$opt(interval)]
$ns_ at $start_time "$a_($j) cbr-start"
set start_time [expr $start_time+0.5 ]
$ns_ at $opt(stop).001 "$a_($j) terminate"
}
# make nam workable
set node_size 10
for {set k 0} { $k<$opt(nn)} {incr k} {
$ns_ initial_node_pos $node_($k) $node_size
}
set opt(stop2) [expr $opt(stop)+200]
puts "Node $total_number is sending first!!"
#$ns_ at 1.33 "$a_($total_number) cbr-start"
#$ns_ at $opt(stop).001 "$a_($total_number) terminate"
$ns_ at $opt(stop2).002 "$a_(0) terminate"
$ns_ at $opt(stop2).003 "$god_ compute_energy"
$ns_ at $opt(stop2).004 "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop2).005 "puts \"NS EXISTING...\"; $ns_ halt"
puts $data "New simulation...."
puts $data "nodes = $opt(nn), maxspeed = $opt(maxspeed), minspeed = $opt(minspeed), random_seed = $opt(seed), sending_interval_=$opt(interval), width=$opt(width)"
puts $data "x= $opt(x) y= $opt(y) z= $opt(z)"
close $data
puts "starting Simulation..."
$ns_ run
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
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.