awk script for calculating energy for AODV protocol nodes, displays negative values.
Linux - Wireless NetworkingThis forum is for the discussion of wireless networking in Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
awk script for calculating energy for AODV protocol nodes, displays negative values.
I am new to tcl scripting and awk.
I have created 50 nodes with random movement.
Code:
set opt(chan) Channel/WirelessChannel ;
set opt(prop) Propagation/TwoRayGround ;
set opt(netif) Phy/WirelessPhy ;
set opt(mac) Mac/802_11 ;
set opt(ifq) Queue/DropTail/PriQueue ;
set opt(ll) LL ;
set opt(ant) Antenna/OmniAntenna ;
set opt(x) 500;
set opt(y) 500;
set opt(ifqlen) 50 ;
set opt(rp) AODV ;
set opt(nn) 50;
set opt(cp) "/home/dj/ns-allinone-2.35/ns-2.35/indep-utils/cmu-scen-gen/cbrgen_50.tcl";
set opt(sc) "/home/dj/ns-allinone-2.35/ns-2.35/indep-utils/cmu-scen-gen/setdest/setdest_50.tcl";
set opt(stop) 300;
### Setting The Simulator Objects
set ns_ [new Simulator]
#create the nam and trace file:
set nf [open aodv.tr w]
$ns_ use-newtrace
$ns_ trace-all $nf
set namtrace [open aodv.nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
create-god $opt(nn)
set chan_1_ [new $opt(chan)]
$ns_ node-config -adhocRouting $opt(rp) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-channel $chan_1_
$ns_ node-config -energyModel "EnergyModel" \
-idlePower 1.0 \
-rxPower 1.0 \
-txPower 1.0 \
-sleepPower 0.001 \
-transitionPower 0.2 \
-transitionTime 0.005 \
-initialEnergy 1000
set node_(0) [$ns_ node]
set node_(1) [$ns_ node]
set node_(2) [$ns_ node]
set node_(3) [$ns_ node]
set node_(4) [$ns_ node]
set node_(5) [$ns_ node]
set node_(6) [$ns_ node]
set node_(7) [$ns_ node]
set node_(8) [$ns_ node]
set node_(9) [$ns_ node]
set node_(10) [$ns_ node]
set node_(11) [$ns_ node]
set node_(12) [$ns_ node]
set node_(13) [$ns_ node]
set node_(14) [$ns_ node]
set node_(15) [$ns_ node]
set node_(16) [$ns_ node]
set node_(17) [$ns_ node]
set node_(18) [$ns_ node]
set node_(19) [$ns_ node]
set node_(20) [$ns_ node]
set node_(21) [$ns_ node]
set node_(22) [$ns_ node]
set node_(23) [$ns_ node]
set node_(24) [$ns_ node]
set node_(25) [$ns_ node]
set node_(26) [$ns_ node]
set node_(27) [$ns_ node]
set node_(28) [$ns_ node]
set node_(29) [$ns_ node]
set node_(30) [$ns_ node]
set node_(31) [$ns_ node]
set node_(32) [$ns_ node]
set node_(33) [$ns_ node]
set node_(34) [$ns_ node]
set node_(35) [$ns_ node]
set node_(36) [$ns_ node]
set node_(37) [$ns_ node]
set node_(38) [$ns_ node]
set node_(39) [$ns_ node]
set node_(40) [$ns_ node]
set node_(41) [$ns_ node]
set node_(42) [$ns_ node]
set node_(43) [$ns_ node]
set node_(44) [$ns_ node]
set node_(45) [$ns_ node]
set node_(46) [$ns_ node]
set node_(47) [$ns_ node]
set node_(48) [$ns_ node]
set node_(49) [$ns_ node]
source $opt(sc)
source $opt(cp)
proc stop {} {
global ns_ nf namtrace
$ns_ flush-trace
close $nf
close $namtrace
exec nam aodv.nam &
exit 0
}
$ns_ at 25.0 "stop"
$ns_ run
Then I created the awk script, as follows:
Code:
BEGIN {
initialenergy=90
maxenergy=0
n=50
node_id=999
}
{
# Trace line format: energy
event = $1
time = $2
if (event == "r" || event == "d" || event == "s"|| event== "f") {
node_id = $9
energy = $17
}
if (event== "N") {
node_id = $9
energy = $17
}
# Store remaining energy
finalenergy[node_id] = energy
}
END {
# Compute consumed energy for each node
for (i in finalenergy) {
consumenergy[i] = initialenergy-finalenergy[i]
totalenergy += consumenergy[i]
if(maxenergy < consumenergy[i]){
maxenergy = consumenergy[i]
node_id = i
}
}
###compute average energy
averagenergy=totalenergy/n
####output
for (i=0; i<n; i++) {
print("node",i,consumenergy[i])
}
print("average energy",averagenergy)
print("total energy",totalenergy)
}
P.S. : Your simulation code is incomplete, the files cbrgen_50.tcl, setdest_50.tcl are missing.
-
Thank you for replying me back.
I have already added my setdest and cbrgen files, first in the declaration and then where I called them.
Is there any other statement missing? I really tried hard to find an example which could illustrate the same but all I gathered is in the script.
THANK YOU!
It worked!
Now I am going to try for throughput, delay, and drop.
Are there any points to keep in mind while working on them. and also if you have the new trace file formats, please share.
Also, may you please suggest me some ideas on how I can proceed with a project on EE-AODV where I can use the awk files, graphs etc.
It would be a great help.
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511
Rep:
Re #12.
File naming : All files must have a unique name to keep track of the files.
"energy.awk, throughput.awk": Several students have already used these names for files with different content.
In real life (as an employee) things must be in a certain order.
I.e. follow the rules. No two items can have the same name / ID-number.
And software has version numbers : energy-da-1.awk, throughput-da-1.awk .
----
ns2 EE-AODV : A couple of hits with Google. No code.
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511
Rep:
Re #14. Delay scripts →
all-2.awk
Avg_Del.awk
Avg_Del_Flow.awk
Instnt_Del.awk
Instnt_Del_Flow.awk
-----------
delay_alterado_einar.awk
delay.awk
delay-e2e.awk
delay-link.awk
delay_original.awk
del-ratio.awk
insdelay_tcp-cbr-vbr.awk
measure-delay.awk
thr_drop_delay.awk
.... .... So please use a script which will fit the particular trace.tr: Not every random script will work. Please start with "the good ones". (And not all trace files.tr have usable information.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.