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.
Alternatively, put this as the first line of your script:
- perl progname.pl
...and run the script as /path/to/script.pl. Of course, it'll need to be executable first, so
- #!/usr/bin/env perl
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.
is there an awk code for calculating the remaining energy of the nodes.?
ReplyDeletelook awk codes given above
Deletegood job but how to show the analyse work??
ReplyDelete@said king: sorry,we don't get u, can u specify ur qstn
Deletehelp me to make tcl script
ReplyDeletescenario parameters are
1.how to make a single destination static node at the center of simulation area.
reagrds
help me to find out what is wrong in my tcl script
ReplyDeletescenario 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
you can change the position of the destination node from the tcl script itself
DeleteHow can i find the node density of aodv nodes in a network
ReplyDeletecan u xplain???
Deletesory..can u show me how to create the compromised node coding..i need this
ReplyDeletelink 5. For calculating network statistics, is die.can you fix link?
ReplyDeletethank you so much
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.
ReplyDeletehow to identify various paths from source to destination using awk script from trace file.
ReplyDeletethanking you.
i need tcl script for RIP & OSPF on NS2
ReplyDeletei need tcl script of FSR on NS2 please send me on my mail id richagoyal323@gmail.com
ReplyDeletei request u to send a tcl script for AntSense protocol
ReplyDeleteIs there any awk script to find next hop node?
ReplyDeleteInformative post, thanks for sharing.
ReplyDeletePerl Training
Perl Training Course
Perl Training online
Perl Programming Training
i want awk or perl script for maodv routing protocol
ReplyDeleteNice. great Article Thanks..
ReplyDeletewhen i write the program the BEGIN invalide
ReplyDeletehi...
ReplyDeleteam not able to downlaod awk scripts..pls help me
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
ReplyDeletevery informative post, thanks for sharing..
ReplyDeletePerl Training
This comment has been removed by the author.
ReplyDeleteyou have written an excellent blog.. keep sharing your knowledge...
ReplyDeletePerl Training in Chennai
Perl Course in Chennai
Great Content. It will useful for knowledge seekers. Keep sharing your knowledge through this kind of article.
ReplyDeleteNode JS Training in Chennai
Node JS Course in Chennai
slot siteleri
ReplyDeletekralbet
betpark
tipobet
mobil ödeme bahis
betmatik
kibris bahis siteleri
poker siteleri
bonus veren siteler
E5X