Nodes with different energies
by JAFAR-KEFAH from LinuxQuestions.org on (#5JVFR)
I am working on my project. It is about detection of selfish nodes depending on the energy of the node. Here I have 20 nodes of the same energy, then I added 5 more but with different energies. The program shows that there is an error (as listed at the end of the code).
My code
```
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 100000 ;# max packet in ifq
set val(nn) 20 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(seed) 0.0
set val(cp) "cbr-20"
set val(sc) "setdest-20"
set val(stop) 200.0 ;# time of simulation end
set ns_ [new Simulator]
set tracefile [open aodvnode50.tr w]
#set windowVsTime2 [open win.tr w]
$ns_ trace-all $tracefile
$ns_ use-newtrace
#$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#Open the NAM trace file
set namfile [open manet.nam w]
$ns_ namtrace-all $namfile
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
set god_ [create-god $val(nn)]
set chan_1_ [new $val(chan)]
#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#
# 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) \
-channel $chan_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-energyModel "EnergyModel" \
-initialEnergy 100.0 \
-txPower 2.0522 \
-rxPower 0.0591 \
-idlePower 0.00006 \
-sleepPower 0.000003 \
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
$ns_ node-config -initialEnergy 500
set node_(20) [$ns_ node]
$ns_ node-config -initialEnergy 20
set node_(21) [$ns_ node]
$ns_ node-config -initialEnergy 30
set node_(22) [$ns_ node]
$ns_ node-config -initialEnergy 100
set node_(23) [$ns_ node]
$ns_ node-config -initialEnergy 100
set node_(24) [$ns_ node]
# 21 connecting to 24 at time 20.48548468411224
#
set udp_(8) [new Agent/UDP]
$ns_ attach-agent $node_(21) $udp_(8)
set null_(8) [new Agent/Null]
$ns_ attach-agent $node_(24) $null_(8)
set cbr_(8) [new Application/Traffic/CBR]
$cbr_(8) set packetSize_ 512
$cbr_(8) set interval_ 1.0
$cbr_(8) set random_ 1
$cbr_(8) set maxpkts_ 10000
$cbr_(8) attach-agent $udp_(8)
$ns_ connect $udp_(8) $null_(8)
$ns_ at 20.48548468411224 "$cbr_(8) start"
#
# 22 connecting to 9 at time 76.258212521792487
#
set udp_(9) [new Agent/UDP]
$ns_ attach-agent $node_(22) $udp_(9)
set null_(9) [new Agent/Null]
$ns_ attach-agent $node_(9) $null_(9)
set cbr_(9) [new Application/Traffic/CBR]
$cbr_(9) set packetSize_ 512
$cbr_(9) set interval_ 1.0
$cbr_(9) set random_ 1
$cbr_(9) set maxpkts_ 10000
$cbr_(9) attach-agent $udp_(9)
$ns_ connect $udp_(9) $null_(9)
$ns_ at 76.258212521792487 "$cbr_(9) start"
puts "Loading connection pattern..."
source $val(cp)
puts "Loading scenario file..."
source $val(sc)
proc finish {} {
global ns_ tracefile namfile
$ns_ flush-trace
close $tracefile
close $namfile
exec nam manet.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).000000001 "$node_($i) reset";
}
$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop).000000001 "puts "NS EXITING..."; $ns_ halt"
puts "Start Simulation..."
$ns_ run
```
The error
```
num_nodes is set 20
INITIALIZE THE LIST xListHead
Loading connection pattern...
Loading scenario file...
Start Simulation...
SORTING LISTS ...DONE!
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 24, dst 21, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
[suppressing additional MAC cache_ warnings]
NS EXITING...
```
My code
```
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 100000 ;# max packet in ifq
set val(nn) 20 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(seed) 0.0
set val(cp) "cbr-20"
set val(sc) "setdest-20"
set val(stop) 200.0 ;# time of simulation end
set ns_ [new Simulator]
set tracefile [open aodvnode50.tr w]
#set windowVsTime2 [open win.tr w]
$ns_ trace-all $tracefile
$ns_ use-newtrace
#$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#Open the NAM trace file
set namfile [open manet.nam w]
$ns_ namtrace-all $namfile
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
set god_ [create-god $val(nn)]
set chan_1_ [new $val(chan)]
#
# Create nn mobilenodes [$val(nn)] and attach them to the channel.
#
# 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) \
-channel $chan_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-energyModel "EnergyModel" \
-initialEnergy 100.0 \
-txPower 2.0522 \
-rxPower 0.0591 \
-idlePower 0.00006 \
-sleepPower 0.000003 \
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
$ns_ node-config -initialEnergy 500
set node_(20) [$ns_ node]
$ns_ node-config -initialEnergy 20
set node_(21) [$ns_ node]
$ns_ node-config -initialEnergy 30
set node_(22) [$ns_ node]
$ns_ node-config -initialEnergy 100
set node_(23) [$ns_ node]
$ns_ node-config -initialEnergy 100
set node_(24) [$ns_ node]
# 21 connecting to 24 at time 20.48548468411224
#
set udp_(8) [new Agent/UDP]
$ns_ attach-agent $node_(21) $udp_(8)
set null_(8) [new Agent/Null]
$ns_ attach-agent $node_(24) $null_(8)
set cbr_(8) [new Application/Traffic/CBR]
$cbr_(8) set packetSize_ 512
$cbr_(8) set interval_ 1.0
$cbr_(8) set random_ 1
$cbr_(8) set maxpkts_ 10000
$cbr_(8) attach-agent $udp_(8)
$ns_ connect $udp_(8) $null_(8)
$ns_ at 20.48548468411224 "$cbr_(8) start"
#
# 22 connecting to 9 at time 76.258212521792487
#
set udp_(9) [new Agent/UDP]
$ns_ attach-agent $node_(22) $udp_(9)
set null_(9) [new Agent/Null]
$ns_ attach-agent $node_(9) $null_(9)
set cbr_(9) [new Application/Traffic/CBR]
$cbr_(9) set packetSize_ 512
$cbr_(9) set interval_ 1.0
$cbr_(9) set random_ 1
$cbr_(9) set maxpkts_ 10000
$cbr_(9) attach-agent $udp_(9)
$ns_ connect $udp_(9) $null_(9)
$ns_ at 76.258212521792487 "$cbr_(9) start"
puts "Loading connection pattern..."
source $val(cp)
puts "Loading scenario file..."
source $val(sc)
proc finish {} {
global ns_ tracefile namfile
$ns_ flush-trace
close $tracefile
close $namfile
exec nam manet.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).000000001 "$node_($i) reset";
}
$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop).000000001 "puts "NS EXITING..."; $ns_ halt"
puts "Start Simulation..."
$ns_ run
```
The error
```
num_nodes is set 20
INITIALIZE THE LIST xListHead
Loading connection pattern...
Loading scenario file...
Start Simulation...
SORTING LISTS ...DONE!
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 24, dst 21, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 21, dst 24, size 20)!
[suppressing additional MAC cache_ warnings]
NS EXITING...
```