Skip to main content

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
 : 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.

Comments

Popular posts from this blog

Link State Routing Protocol

Link state routing is a method in which each router shares its neighborhood’s knowledge with every other router on the internetwork. In this algorithm, each router in the network understands the network topology and then makes a routing table depending on this topology. Each router will share data about its connection to its neighbor, who will, consecutively, reproduce the data to its neighbors, etc. This appears just before all routers have constructed a topology of the network. In LSP, each node transmits its IP address and the MAC to its neighbor with its signature. Neighbors determine the signature and maintain a record of the combining IP address and the MAC. The Neighbor Lookup Protocol (NLP) of LSP derives and maintains the MAC and IP address of every network frame accepted by a node. The extracted data can support the mapping of MACs and IP addresses. The link-state flooding algorithm prevents the general issues of broadcast in the existence of loops by having every node mainta...

Matter: A next generation home standard

The smart home is evolving. To date, if you've wanted to get into developing a smart home, you've had to deal with the multitude of smart home ecosystems, and making sure that each device you buy is compatible. That, however, may soon change — thanks to new smart home standard called Matter. Matter isn't available just yet, but when it is finally released, it could completely change how you buy smart home products, for the better. All of the best smart home devices could soon support the standard, helping them all work together nicely, and ensuring that no matter what products you buy, you'll be able to use them. Matter is basically the name of a new smart home connectivity standard . But this standard is a little unlike others. That's because of the fact that it's being developed by the Connectivity Standards Alliance, which counts hundreds of companies as members. That includes the likes of Google, Alexa, and Apple. So, whether you prefer to use Google Assista...

New interactive stickers for Stories

Instagram has introduced several new features to Stories, offering interactive ways to share music, photos, and videos. One of the most interesting additions is a feature called Reveal , which blurs the content of a story post and requires viewers to DM the person who shared it in order to see it. Instagram's head, Adam Mosseri, has emphasized the importance of direct messages on the platform, with stories and DMs driving most of Instagram's growth. Requiring a DM to view content represents the next step in boosting engagement, and creators are likely to use it as a tactic to increase their stories' engagement. Another new feature, Frames, adds a Polaroid overlay to images that initially appear gray. Users can shake their phone to reveal the photo, resembling the process many people associate with Polaroid pictures, despite the fact that shaking Polaroids is not recommended by the company during development. Instagram has also introduced a music-based template feature calle...