Hi All, Our website moved to a new URL. Please bookmark the new link: https://ns2bloggers.blogspot.com/

AWK AND PERL SCRIPTING ON NS2 WITH SCRIPTS

AWK Script

AWK is a high level programming language which is used to process text files,named after its three orginal author's name:

A  : Alfred Aho
W : Peter Weinberger
K  : Brian Kernighan 

AWK Scripts are very good in processing the data from the log (trace files) which we get from NS2. If you want to process the trace file manually.

AWK PROGRAM STRUCTURE

Awk program structure contains mainly three parts;
1. Begin
2. Content
3. End

BEGIN {<initialization>}

   <pattern1> {<actionSet1>}
   <pattern2> {<actionSet2>}
   . . .


END {<final finalActionSet>}

BEGIN : Begin deals with what to be executed prior to text file processing,normally which is used to initialize variable values or constants.

CONTENT : Script which process the text file. In this part, AWK moves lines by lines (i.e., records by records) and executes the <actionSet> if the current line match with the pattern. The actions repeats until AWK reaches the end of the file. 

END : This part explains what to be executed after the text file processing ie. what to print on the terminal or to show output in terminal.

EXECUTION
Awk has two types of execution;

1) Plain Execution.
2) Match and Execute.

Plain Execution : Simply AWK statements.

Match and execute : The second type of execution is “Match and Execute”, when executes plain execution statements only if the current line (of the input text file) matches with a predefined pattern. The pattern can be either : 1. Logical Expression 2. Regular Expression.

Sample Awk Script



TRACE FILE AND AWK SCRIPT
Here is a sample of trace file from NS2 , to know more about trace file click here

AWK Scripts are very good in processing the data column wise. For example the first column in the above trace file represents r, s which indicates receive, sent respectively. If we want to trace the entire r and s alone from this trace file we can represent it as $1
So
$1 : Action (r,s,d.f)
$2 Time
$3 Time value
$4 node id
$5 node id value
$6 id of next hop
$7 next hop id value
.
.
.
More description of trace file is in above link.

To run awk script, we have to use terminal window.

For that first we have to install gawk in Linux.for that we have to write following code in terminal;

sudo apt-get install gawk



after installing gawk, we have to  run the awk script using command; 

gawk -f <awk file name> <trace file name> 

gawk -f file.awk file.tr

The ‘-f’ instructs the awk utility to get the awk program from the source file i.e from .awk file.

After entering command you will get values.



AWK SCRIPTS

1. For calculating Throughput, Click here
2. For calculating End to End Delay,Routing Load and Packet Density Fraction, Click here
3. For calculating Jitter,  Click here
4. For calculating energy, Click here 
5. For calculating network statistics, Click here
6. For printing congestion window, Click here
7. For calculating all network statistics, Click here
8. For calculating final node position and energy of node, Click here

Note : 
1. This awk script is for new trace format files.
2. Copy this awk files to the directory where tcl script is saved.
3. Change initial values as per your need.


PERL Script

Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.
The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features are that it's easy to use, supports both procedural and object-oriented (OO) programming, has powerful built-in support for text processing, and has one of the world's most impressive collections of third-party modules.
Like awk script, perl script can also be used to perform post analysis of trace files. Perl script are simple any tiny than awk scripts.

To run a Perl program from the Unix command line:
  1. perl progname.pl
Alternatively, put this as the first line of your script:
  1. #!/usr/bin/env perl
...and run the script as /path/to/script.pl. Of course, it'll need to be executable first, so chmod 755 script.pl (under Unix).
(This start line assumes you have the env program. You can also put directly the path to your perl executable, like in #!/usr/bin/perl ).

after running your tcl file copy and paste the perl script to the same directory and then the perl script can be run from your terminal by typing the following command.

perl filename.p tracefilename.tr

1. Perl script for calculating packet sent, packet received, packet dropped, routing overhead, packet delivery ratio and average path length can be downloaded for here. Click here. 
2. Perl script to calculate average end to end delay can be downloaded from here. Click here.

Note : Copy and paste this perl script to the directory where tcl script is saved.

28 comments :

  1. is there an awk code for calculating the remaining energy of the nodes.?

    ReplyDelete
  2. good job but how to show the analyse work??

    ReplyDelete
    Replies
    1. @said king: sorry,we don't get u, can u specify ur qstn

      Delete
  3. help me to make tcl script
    scenario parameters are


    1.how to make a single destination static node at the center of simulation area.
    reagrds

    ReplyDelete
  4. help me to find out what is wrong in my tcl script
    scenario parameters are
    (area=1000*1000 , total nodes=150 , mobile nodes=75, device speed=6 m/s , pause time=0.5 , number of data source=5and50 ,Transport layer=TCP, application=FTP, data rate per source=1 and 12 kbps )

    1. how to make a single destination static node at the center of simulation area.
    reagrds

    ReplyDelete
    Replies
    1. you can change the position of the destination node from the tcl script itself

      Delete
  5. How can i find the node density of aodv nodes in a network

    ReplyDelete
  6. sory..can u show me how to create the compromised node coding..i need this

    ReplyDelete
  7. link 5. For calculating network statistics, is die.can you fix link?
    thank you so much

    ReplyDelete
  8. I use awk script in Section 2. For End to End Delay Calculating, Routing and Packet Load Density Fraction and 7. For Calculating network statistics, the average end to end delay for different results? you can explain it to me? thank you so much.

    ReplyDelete
  9. how to identify various paths from source to destination using awk script from trace file.
    thanking you.

    ReplyDelete
  10. i need tcl script for RIP & OSPF on NS2

    ReplyDelete
  11. i need tcl script of FSR on NS2 please send me on my mail id richagoyal323@gmail.com

    ReplyDelete
  12. i request u to send a tcl script for AntSense protocol

    ReplyDelete
  13. Is there any awk script to find next hop node?

    ReplyDelete
  14. i want awk or perl script for maodv routing protocol

    ReplyDelete
  15. when i write the program the BEGIN invalide

    ReplyDelete
  16. hi...

    am not able to downlaod awk scripts..pls help me

    ReplyDelete
  17. Phone Number Extractor Files is great Phone Number Extracting tool and is cheapest software available on the internet. How to Extract Numbers From different Files

    ReplyDelete
  18. very informative post, thanks for sharing..
    Perl Training

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. you have written an excellent blog.. keep sharing your knowledge...
    Perl Training in Chennai
    Perl Course in Chennai

    ReplyDelete
  21. Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
    Node JS Training in Chennai
    Node JS Course in Chennai

    ReplyDelete