LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to set different energy levels to different nodes in ns2 (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-different-energy-levels-to-different-nodes-in-ns2-4175517149/)

pon 09-02-2014 07:36 AM

How to set different energy levels to different nodes in ns2
 
Hi all,

I used following part of code to set energy of the node in ns2.

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/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)            8                          ;# number of mobilenodes
set val(rp)            AODV                      ;# routing protocol
set val(x)              500                        ;# X dimension of topography
set val(y)              400                        ;# Y dimension of topography
set val(energymodel)    EnergyModel                ;# Energy Model
set val(initialenergy)  77                        ;# Value
set val(stop)          150                        ;# time of simulation end

...
...

  $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 $val(energymodel) \
            -initialEnergy $val(initialenergy) \
            -rxPower 35.28e-3 \
            -txPower 31.32e-3 \
            -idlePower 712e-6 \
            -sleepPower 144e-9


but above codes sets uniform energy to all nodes.how could i set different energy levels to each nodes?

Thanks

Pon

selmanhizal 07-30-2018 08:30 AM

Set different energy levels to wireless nodes
 
Hi,

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

bharaths248 05-02-2019 11:36 PM

energy parameters has to be set in aodv.cc and aodv.h
 
But the energy parameters has to be set in aodv.cc and aodv.h right? Could you please send a sample code of how to do it.

rtmistler 05-03-2019 07:45 AM

@bharaths248,

Please refrain from opening old threads, and especially with additional questions as opposed to offering information to help resolve the original problem.

Instead, a suggestion is to open a new thread with your specific question and refer by link to an associated thread in support of your question.


All times are GMT -5. The time now is 12:47 PM.