You can set different initial energy to each wireless node separately. Your TCL script example is below.
set opt(initialenergy) 1000 ; # Initial energy in Joules
# Define Mobile Node Configurations
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-energyModel $opt(energymodel) \
-idlePower 1.0 \
-rxPower 1.0 \
-txPower 1.0 \
-sleepPower 0.001 \
-transitionPower 0.2 \
-transitionTime 0.005 \
-initialEnergy $opt(initialenergy)
....
....
set node_(0) [$ns node] # This will be generate node with initial energy 1000 Joules
$ns node-config -initialEnergy 500
set node_(1) [$ns node]
$ns node-config -initialEnergy 20
set node_(2) [$ns node]
$ns node-config -initialEnergy 30
set node_(3) [$ns node]
$ns node-config -initialEnergy 100
set node_(4) [$ns node]
...
You can find an example of 5 Nodes with different energy levels / AODV Routing Protocol in NS 2.35 below.
# wireless-qeaodv.tcl
# 5 Nodes with different energy levels / AODV Routing Protocol Example
# ======================================================================
# Define Values
# ======================================================================
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) AODV ;
set val(nn) 5 ;
set opt(energymodel) EnergyModel ;
set opt(initialenergy) 1000 ; # Initial energy in Joules
set opt(lm) "off" ;# log movement
set opt(logenergy) "on" ;# log energy every 150 seconds
set val(x) 500 ;
set val(y) 500 ;
set val(stop) 60;
set filename $val(rp)_$val(nn)_$val(x)_$val(y);
set ns [new Simulator]
# open trace file
set tracefd [open $filename.tr w]
$ns trace-all $tracefd
#Open the nam trace file
set namtrace [open $filename.nam w]
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
set WirelessNewTrace_ ON
#set AgentTrace ON
#set RouterTrace OFF
#set MacTrace ON
# ------------------------------------------------------------------------------
# Ağ topolojisi tanımı
# ------------------------------------------------------------------------------
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# General Operations Director (GOD)
create-god $val(nn)
# nn miktarınca düğüm [$val(nn)] oluştur ve kanala ilişkilendir.
set chan_1 [new $val(chan)]
# düğümleri konfigure et
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-energyModel $opt(energymodel) \
-idlePower 1.0 \
-rxPower 1.0 \
-txPower 1.0 \
-sleepPower 0.001 \
-transitionPower 0.2 \
-transitionTime 0.005 \
-initialEnergy $opt(initialenergy)
#for {set i 0} {$i < $val(nn) } { incr i } {
# set node_($i) [$ns node]
# $node_($i) random-motion 0 ;# disable random motion
#}
# Set initialEnergy values for Nodes
$ns node-config -initialEnergy 500
set node_(0) [$ns node]
$node_(0) color blue
$node_(0) shape box
$node_(0) label "Source"
# Set initial_node_pos
$node_(0) set X_ 40.0
$node_(0) set Y_ 280.0
$ns node-config -initialEnergy 500
set node_(1) [$ns node]
$ns node-config -initialEnergy 20
set node_(2) [$ns node]
$ns node-config -initialEnergy 20
set node_(3) [$ns node]
$ns node-config -initialEnergy 100
set node_(4) [$ns node]
# $node color [color] ;# sets color of node
# $node shape [shape] ;# sets shape of node
# $node label [label] ;# sets label on node
# $node label-color [lcolor] ;# sets color of label
# $node label-at [ldirection] ;# sets position of label
# $node add-mark [name] [color] [shape] ;# adds a mark to node
# $node delete-mark [name] ;# deletes mark from node
$node_(1) set X_ 420.0
$node_(1) set Y_ 280.0
$node_(1) color "red"
$node_(1) label "Destination"
$node_(2) set X_ 220.0
$node_(2) set Y_ 380.0
$node_(2) color "green"
$node_(3) set X_ 360.0
$node_(3) set Y_ 280.0
$node_(3) color "green"
$node_(4) set X_ 220.0
$node_(4) set Y_ 180.0
$node_(4) color "green"
for {set i 0} {$i < $val(nn) } { incr i } {
$ns initial_node_pos $node_($i) 30;
}
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp
set null [new Agent/Null]
$ns attach-agent $node_(1) $null
$ns connect $udp $null
$udp set fid_ 1
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packetSize_ 48; # 48 byte 384bit
$cbr set rate_ 64000; # 0.064Mb || 64kb || 64000bit || bits per second
# interval_=0.0060000000000000001 || bit per second || 384/64000
# Packets in one second = 64000/384= 166,6packet
$cbr set random_ false
$ns at 10.0 "$cbr start"
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";
}
$ns at 60.0 "$cbr stop"
# ------------------------------------------------------------------------------
# nam ve simulation end
# ------------------------------------------------------------------------------
# $ns at 15 "$node_(0) print_rtable"
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
#$ns at $val(stop) "$awk -f _packet.awk AODV_5_500_500.tr"
$ns at 70 "stop"
$ns at 70 "puts "end simulation" ; $ns halt"
proc stop {} {
global ns tracefd namtrace filename
$ns flush-trace
close $tracefd
close $namtrace
exec nam $filename.nam; #Execute nam on the trace file
exec awk -f _packet.awk $filename.tr
}
$ns run
set opt(initialenergy) 1000 ; # Initial energy in Joules
# Define Mobile Node Configurations
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-energyModel $opt(energymodel) \
-idlePower 1.0 \
-rxPower 1.0 \
-txPower 1.0 \
-sleepPower 0.001 \
-transitionPower 0.2 \
-transitionTime 0.005 \
-initialEnergy $opt(initialenergy)
....
....
set node_(0) [$ns node] # This will be generate node with initial energy 1000 Joules
$ns node-config -initialEnergy 500
set node_(1) [$ns node]
$ns node-config -initialEnergy 20
set node_(2) [$ns node]
$ns node-config -initialEnergy 30
set node_(3) [$ns node]
$ns node-config -initialEnergy 100
set node_(4) [$ns node]
...
You can find an example of 5 Nodes with different energy levels / AODV Routing Protocol in NS 2.35 below.
# wireless-qeaodv.tcl
# 5 Nodes with different energy levels / AODV Routing Protocol Example
# ======================================================================
# Define Values
# ======================================================================
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) AODV ;
set val(nn) 5 ;
set opt(energymodel) EnergyModel ;
set opt(initialenergy) 1000 ; # Initial energy in Joules
set opt(lm) "off" ;# log movement
set opt(logenergy) "on" ;# log energy every 150 seconds
set val(x) 500 ;
set val(y) 500 ;
set val(stop) 60;
set filename $val(rp)_$val(nn)_$val(x)_$val(y);
set ns [new Simulator]
# open trace file
set tracefd [open $filename.tr w]
$ns trace-all $tracefd
#Open the nam trace file
set namtrace [open $filename.nam w]
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
set WirelessNewTrace_ ON
#set AgentTrace ON
#set RouterTrace OFF
#set MacTrace ON
# ------------------------------------------------------------------------------
# Ağ topolojisi tanımı
# ------------------------------------------------------------------------------
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# General Operations Director (GOD)
create-god $val(nn)
# nn miktarınca düğüm [$val(nn)] oluştur ve kanala ilişkilendir.
set chan_1 [new $val(chan)]
# düğümleri konfigure et
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-energyModel $opt(energymodel) \
-idlePower 1.0 \
-rxPower 1.0 \
-txPower 1.0 \
-sleepPower 0.001 \
-transitionPower 0.2 \
-transitionTime 0.005 \
-initialEnergy $opt(initialenergy)
#for {set i 0} {$i < $val(nn) } { incr i } {
# set node_($i) [$ns node]
# $node_($i) random-motion 0 ;# disable random motion
#}
# Set initialEnergy values for Nodes
$ns node-config -initialEnergy 500
set node_(0) [$ns node]
$node_(0) color blue
$node_(0) shape box
$node_(0) label "Source"
# Set initial_node_pos
$node_(0) set X_ 40.0
$node_(0) set Y_ 280.0
$ns node-config -initialEnergy 500
set node_(1) [$ns node]
$ns node-config -initialEnergy 20
set node_(2) [$ns node]
$ns node-config -initialEnergy 20
set node_(3) [$ns node]
$ns node-config -initialEnergy 100
set node_(4) [$ns node]
# $node color [color] ;# sets color of node
# $node shape [shape] ;# sets shape of node
# $node label [label] ;# sets label on node
# $node label-color [lcolor] ;# sets color of label
# $node label-at [ldirection] ;# sets position of label
# $node add-mark [name] [color] [shape] ;# adds a mark to node
# $node delete-mark [name] ;# deletes mark from node
$node_(1) set X_ 420.0
$node_(1) set Y_ 280.0
$node_(1) color "red"
$node_(1) label "Destination"
$node_(2) set X_ 220.0
$node_(2) set Y_ 380.0
$node_(2) color "green"
$node_(3) set X_ 360.0
$node_(3) set Y_ 280.0
$node_(3) color "green"
$node_(4) set X_ 220.0
$node_(4) set Y_ 180.0
$node_(4) color "green"
for {set i 0} {$i < $val(nn) } { incr i } {
$ns initial_node_pos $node_($i) 30;
}
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp
set null [new Agent/Null]
$ns attach-agent $node_(1) $null
$ns connect $udp $null
$udp set fid_ 1
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packetSize_ 48; # 48 byte 384bit
$cbr set rate_ 64000; # 0.064Mb || 64kb || 64000bit || bits per second
# interval_=0.0060000000000000001 || bit per second || 384/64000
# Packets in one second = 64000/384= 166,6packet
$cbr set random_ false
$ns at 10.0 "$cbr start"
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";
}
$ns at 60.0 "$cbr stop"
# ------------------------------------------------------------------------------
# nam ve simulation end
# ------------------------------------------------------------------------------
# $ns at 15 "$node_(0) print_rtable"
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
#$ns at $val(stop) "$awk -f _packet.awk AODV_5_500_500.tr"
$ns at 70 "stop"
$ns at 70 "puts "end simulation" ; $ns halt"
proc stop {} {
global ns tracefd namtrace filename
$ns flush-trace
close $tracefd
close $namtrace
exec nam $filename.nam; #Execute nam on the trace file
exec awk -f _packet.awk $filename.tr
}
$ns run
No comments:
Post a Comment