Monday, August 5, 2013

NS2 energy analysis awk script

11:01 PM By Unknown , 25 comments

Hi All,

Awk programming is very easy to learn and simple to apply. Awk in NS2 takes the trace file for analysis. $1, $2, $3 etc are used to access column values from the trace file.

Generally an awk program will have a structure as shown below:

BEGIN {<initialization>}
<pattern 1> {<actions>}
<pattern 2> {<actions>}
.
.
.
<pattern N> {<actions>}
END {<final actions>}

Execution of AWK script:
        awk -f filename.awk tracefile.tr

Given below is the code for energy analysis using awk script.


BEGIN {
        seqno = -1;
        start_time = 0;

      }

{
action = $1;
time = $2;
node_id = $3;
layer = $4;
flags = $5;
seqno = $6;
type = $7;
size = $8;
a = $9;
b = $10;
c = $11;
d = $12;
energy = $14;

if(seqno < $6 && node_id == "_4_" && (action == "r" || action == "s")) {
        seqno = $6;
        remaining_energy = energy;
        start_time = time;
        printf("%f\t%f\n",start_time,remaining_energy);
      }
}

END {
}

25 comments:

  1. what is the significance of node id _4_

    ReplyDelete
    Replies
    1. It is node id , you can monitor energy level of specific node during the course of operation by mentioning the node id

      Delete
  2. Thanks Fallen Angel ... the code works and its a great help for beginner like me

    Shubh

    ReplyDelete
  3. if i want all node reamin energy into one file and print node id in to file then what i have to do..

    vis

    ReplyDelete
  4. Hi this code is not working can u please help me how to use this code and what about the tcl script

    ReplyDelete
  5. Can the echo statement be used instead of print?

    ReplyDelete
  6. i didnot get any error but nothing is displayed as output

    ReplyDelete
  7. What is the CSthresh and RXthresh values of 802.15.4??

    ReplyDelete