A homepage subtitle here And an awesome description here!

29 October 2023

AWK and NS2 Tracefile | NS2 Tutorial 3

AWK

Awk is abbreviated from the names of the developers – Aho, Weinberger, and Kernighan.

Awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators.

AWK is one of the most prominent text-processing utilities on GNU/Linux. It is very powerful and uses a simple programming language.

Awk is a utility that enables a programmer to write tiny but effective programs in the form of statements that define text patterns that are to be searched for in each line of a document and the action that is to be taken when a match is found within a line.

1. AWK Operations:

(a) Scans a file line by line

(b) Splits each input line into fields

(c) Compares input line/fields to pattern

(d) Performs action(s) on matched lines

2. AWK Useful For:

(a) Transform data files

(b) Produce formatted reports

Syntax:

$ awk options 'selection _criteria {action }' input-file > output-file

Or

$ gawk options 'selection _criteria {action }' input-file > output-file

Options:

-f program-file: Reads the AWK program source from the file

 

Awk is not just a command, but a programming language too. In other words, awk utility is a pattern scanning and processing language. It searches one or more files to see if they contain lines that match specified patterns and then performs associated actions, such as writing the line to the standard output or incrementing a counter each time it finds a match.

Variables

Awk allows the user to use variables of their choice. You can now print a serial number, using the variable count, and apply it to those directors drawing a salary exceeding 6700:

$ awk –F "|" '$3 == "director" && $6 > 6700 {
kount = kount+1
printf " %3f %20s %-12s %d\n", kount,$2,$3,$6 }' empn.lst


THE –f OPTION: STORING awk PROGRAMS IN A FILE

You should hold large awk programs in separate files and provide them with the awk extension for easier identification. Let's first store the previous program in the file
empfile.awk:

$ cat empfile.awk

Observe that this time we haven't used quotes to enclose the awk program. You can
now use awk with the –f
filename option to obtain the same output:

$ gawk –F "|" –f empfile.awk empn.lst

THE BEGIN AND END SECTIONS

Awk statements are usually applied to all lines selected by the address, and if there are no addresses, then they are applied to every line of input. But, if you have to print something before processing the first line, for example, a heading, then the BEGIN section can be used gainfully. Similarly, the end section useful in printing some totals after processing is over.

The BEGIN and END sections are optional and take the form
BEGIN {action}

END {action}

These two sections, when present, are delimited by the body of the awk program. You
can use them to print a suitable heading at the beginning and the average salary at the end.

BUILT-IN VARIABLES

Awk has several built-in variables. They are all assigned automatically, though it is also possible for a user to reassign some of them. You have already used NR, which signifies the record number of the current line. We'll now have a brief look at some of the other variables.

The FS Variable:

as stated elsewhere, awk uses a contiguous string of spaces as the default field delimiter. FS redefines this field separator, which in the sample database happens to be the |. When used at all, it must occur in the BEGIN section so that the body of the program knows its value before it starts processing:

BEGIN {FS="|"}

This is an alternative to the –F option which does the same thing. The OFS Variable: when you used the print statement with comma-separated arguments, each argument was separated from the other by a space. This is awk's default output field separator, and can reassigned using the variable OFS in the BEGIN section:
BEGIN { OFS="~" }

When you reassign this variable with a ~ (tilde), awk will use this character for delimiting the print arguments. This is a useful variable for creating lines with delimited fields. The NF variable: NF comes in quite handy for cleaning up a database of lines that don't contain the right number of fields. By using it on a file, say emp.lst, you can locate those lines not having 6 fields, and which have crept in due to faulty data entry:

$awk 'BEGIN {FS = "|"}
NF! =6 {
Print "Record No ", NR, "has", "fields"}' empx.lst

Output NS2 Trace file:

The Trace file contains 12 columns: Event type, Event time, From Node To Node, Packet Type, Packet Size, Flags  (indicated by --------), Flow ID, Source address, Destination Address, Sequence ID, Packet ID

 

Structure of Trace Files

When tracing into an output ASCII file, the trace is organized in 12 fields as follows in fig shown below,

 

The meaning of the fields is:

1. The first field is the event type. It is given by one of four possible symbols r, +, -, d which correspond respectively to receive (at the output of the link), enqueued, dequeued, and dropped.
2. The second field gives the time at which the event occurs.
3. Gives the input node of the link at which the event occurs.

4. Gives the output node of the link at which the event occurs.
5. Gives the packet type (eg CBR or TCP)
6. Gives the packet size
7. Some flags
8. This is the flow-id (fid) of IPv6 that a user can set for each flow at the input OTcl script
one can further use this field for analysis purposes; it is also used when specifying a stream
color for the NAM display.

9. This is the source address given in the form of "node. port".
10. This is the destination address, given in the same form.
11. This is the network layer protocol's packet sequence number. Even though UDP
implementations in a real network do not use sequence numbers, ns keeps track of UDP
packet sequence number for analysis purposes

12. The last field shows the unique id of the packet.

Google LLC, 1600 Amphitheatre Parkway, Mountain View, CA 94043, USA
You have received this email because acadprj@gmail.com shared a document with you from Google Docs.
Google

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04

This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System

Since ns-2.35 is too old, it needs the following packages
gcc-4.8
g++-4.8
gawk
and some more libraries

Follow the video for more instructions


So, here are the steps to install this software:

To download and extract the ns2 software

Download the software from the following link

Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder)

$ tar zxvf ns-allinone-2.35.tar.gz
or Right click over the file and click extract here and select the home folder.

$ sudo apt update
$ sudo apt install build-essential autoconf automake libxmu-dev gawk

To install gcc-4.8 and g++-4.8

$ sudo gedit /etc/apt/sources.list make an entry in the above file
deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update

Since, it's ubuntu 22.04, you may get an error called GPG Error with a code like this "3B4FE6ACC0B21F32"
In case you get the GPG error, include the following command

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 $ sudo apt update $ sudo apt install gcc-4.8 g++-4.8 Make the changes in the following files
@CC@ to be replaced with gcc-4.8 @CPP@ to be replaced with g++-4.8 ns-allinone-2.35/Makefile.in /home/pradeepkumar/ns-allinone-2.35/otcl-1.14/Makefile.in nam-1.15/Makefile.in xgraph-12.2/Makefile.in In all the above places, change @CC@ to gcc-4.8 and @CPP@ @CXX@ to g++-4.8 Open the file ns-2.35/linkstate/ls.h in line number 137, change the line erase to this-erase Once the installation is over, Set the PATH and LD_LIBRARY_PATH information in the file located at /home/pradeepkumar/.bashrc export PATH=$PATH:/home/pradeepkumar/ns-allinone-2.35/bin:/home/pradeepkumar/ns-allinone-2.35/tcl8.5.10/unix:/home/pradeepkumar/ns-allinone-2.35/tk8.5.10/unix export LD_LIBRARY_PATH=/home/pradeepkumar/ns-allinone-2.35/otcl-1.14:/home/pradeepkumar/ns-allinone-2.35/lib
You can change /home/pradeepkumar to your home folder name. 
$ns $nam $ xgraph 
1 2
3 4
5 6
6 7
8 9
10 11
and press Control D (You can get a good graph) and that's it...


For video lectures of this kind, subscribe to my Channel https://www.youtube.com/tspradeepkumar


Introduction to Network Simulator 2 | NS2 Tutorial 1

Introduction to Network Simulator 2

NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator designed specifically for research in computer communication networks.

Network Simulator (Version 2), is simply an event-driven simulation tool that has proved useful in studying the dynamic nature of communication networks. Simulation of wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP) can be done using NS2. In general, NS2 provides users with a way of specifying such network protocols and simulating their corresponding behaviors. Due to its flexibility and modular nature, NS2 has gained constant popularity in the networking research community since its birth in 1989. Ever since, several revolutions and revisions have marked the growing maturity of the tool, thanks to substantial contributions from the players in the field. Among these are the University of California and Cornell University which developed the REAL network simulator,  the foundation on which NS is based. Since 1995 the Defense Advanced Research Projects Agency (DARPA) supported the development of NS through the Virtual Inter Network Testbed (VINT) project. Currently, the National Science Foundation (NSF) has joined the ride in development. Last but not least, the group of Researchers and developers in the community are constantly working to keep NS2 strong and versatile

 

Features of NS2

1. It is a discrete event simulator for networking research.

2. It provides substantial support to simulate a bunch of protocols like TCP, FTP, UDP, HTTP, and DSR.

3. It is primarily Unix-based.

4. Uses TCL as its scripting language.

5. Otcl: Object-oriented support

 6. Tclcl: C++ and otcl linkage

7.  Discrete event scheduler

The basic

The basic architecture of NS2

 

Figure shows the basic architecture of NS2. The NS2 provides users with executable command ns which takes on input argument, the name of a Tcl simulation scripting file. Users are feeding the name of a Tcl simulation script (which sets up a simulation) as an input argument of an NS2 executable command ns.

In most cases, a simulation trace file is created and is used to plot graphs and/or to create animation. NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl). While C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the OTcl sets up the simulation by assembling and configuring the objects as well as scheduling discrete events (i.e., a frontend).


The C++ and the OTcl are linked together using TclCL. Mapped to a C++ object, variables in the OTcl domains are sometimes referred to as handles. Conceptually, a handle (e.g., n as a Node handle) is just a string (e.g.,_o10) in the OTcl domain, and does not contain any functionality. Instead, the functionality (e.g., receiving a packet) is defined in th mapped C++ object (e.g., of class Connector). In the OTcl domain, a handle acts as a frontend that interacts with users and other OTcl objects.



Powered by Blogger.

About Me

Featured Post

5G Network Simulation in NS3 using mmWave | NS3 Tutorial 2024

5G Network Simulation in NS3 Using mmWave This post shows the installation of ns3mmwave in Ubuntu 24.04 and simulates 5G networks in ns3. In...

Contact form

Name

Email *

Message *

Total Pageviews

Search This Blog

Pages

Pages

Pages - Menu

Most Popular

Popular Posts