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

NS2 INSTALLATION IN UBUNTU 21.04

  Hello, this post explains how to install ns2 in Ubuntu 21.04.  1) First you have to download ns2 all-in-one package from following link;    http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download 2) Extract the downloaded zip file 'ns-allinone-2.35.tar.gz file' to home folder. 3)  Now you need to download some essential packages for ns2,these packages can be downloaded by using the following commands :  applications>accessories>terminal or dashhome>terminal   and   then type the below lines one by one on the terminal window sudo apt-get update sudo apt-get dist-upgrade sudo apt-get update 4) Install the basic libraries; sudo apt install build-essential autoconf automake libxmu-dev 5) Install gcc and g++ and for that please do following; open the file using sudo mode sudo nano /etc/apt/sources.list Include the following line in list;  deb http://in.archive.ubuntu.com/ubuntu bionic main universe then open terminal and exec

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

HP NETWORK SIMULATOR: A COMWARE OS LEARNING TOOL

  Comware v7 is a network operating system that runs on HP high-end network devices. The HP Network Simulator is an ideal Comware v7 learning tool, which allows users to create, configure, and connect simulated networks. Benefits Beginners  – The HP Network Simulator tool is helpful for users who are new to networking and want to learn how to configure network devices (switches, routers), various topologies, or different routing and switching protocols and features. Experienced users  – The HP Network Simulator learning tool is helpful for users who have experience with non-HP networking devices and want to learn the Comware CLI and features. Extra devices  – Users can create devices using the HP Network Simulator and use them with their physical devices to configure and test topologies that aren’t configurable with just the physical devices they have. For example – A user wants to configure OSPF using 3 or more devices but has only 1 physical router. User can create 2 or more routers