TN Lab Manual 1
TN Lab Manual 1
Lab Manual
1
ECE, JIIT NOIDA EVEN SEMESTER
LIST OF EXPERIMENTS
1. (a) To learn about network simulator, and use NS2 for conducting network simulation including
LINUX commands.
(b) To learn installing NS2 in Fedora.
2. (a) Introduction to OSI, TCP & UDP.
(b) To set up a network with two nodes; link them with duplex link, 10ms propagation delay,
1Mbps rate and DropTail procedure. Use Agent UDP with CBR traffic source.
3. To set up a network with two nodes; link them with duplex link, 10ms propagation delay, 1Mbps
rate and DropTail procedure. Use FTP over Agent TCP.
4. To implement wired LAN connection in NS2.
5. To create a mobile ad-hoc network with 3 nodes in 500*400 topography with following initial
positions and movements:
Node 0 (5, 5) Node 1 (490,285) Node 2 (150,240) At t = 10, 0
moves towards (250,250) at 3m/sec.
2
ECE, JIIT NOIDA EVEN SEMESTER
10. To create a network with 5 nodes, and apply uniform, exponential and constant error model with
error rate 1% on 3 different links.
11. Simulate an Ethernet LAN using ‘n’ nodes and set multiple traffic nodes and determine the
collision across different nodes.
12. Write a program for error detecting code using CRC-CCITT (16bit).
13. To simulate a link failure and to observe distance vector routing protocol.
14. Write a program for distance vector algorithm to find suitable path for transmission.
15. Write a program for congestion control using Leaky Bucket algorithm.
http://vlabs.iitkgp.ernet.in/ant/
3
ECE, JIIT NOIDA EVEN SEMESTER
1.Real-Time Scheduling:-This lab implements a soft real-time scheduler which ties event execution
within the simulator to real time.
2. Educational uses:
3. Other applications:
(i) Research using NAM (Network Animator)
(ii) Topology Generation for large simulations
(iii) Scenario generation in ns.
4
ECE, JIIT NOIDA EVEN SEMESTER
1. Real system are too complex to model. i.e. they have complicated structure.
2. The simulator virtual time should closely track real-time. If the simulator becomes too slow to
keep up with elapsing real time, a warning is continually produced if the skew exceeds a pre-
specified constant “slope factor'' (currently 10ms).
4. Modeling is a very complex and time-consuming task in NS-2, since it has no GUI and one needs
to learn scripting language, queuing theory and modeling techniques. Also, of late, there have
been complaints that results are not consistent (probably because of continuous changes in the
code base) and that certain protocols have unacceptable bug
5. Precautions should be taken while programming because it is a very highly case sensitive
language.
5
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 1
AIM: -(a) To learn about network simulator, and use NS2 for conducting network simulation
including LINUX commands.
(b) To learn installing NS2 in Fedora.
THEORY: -
History and UNIX
In order to understand the popularity of Linux, we need to travel back in time, about 30 years ago.
Imagine computers as big as houses, even stadiums. While the sizes of those computers posed
substantial problems, there was one thing that made this even worse: every computer had a different
operating system. Software was always customized to serve a specific purpose, and software for one
given system didn't run on another system. Being able to work with one system didn't automatically
mean that you could work with another. It was difficult, both for the users and the system
administrators. Computers were extremely expensive then, and sacrifices had to be made even after
the original purchase just to get the users to understand how they worked. The total cost per unit of
computing power was enormous.
Technologically the world was not quite that advanced, so they had to live with the size for another
decade. In 1969, a team of developers in the Bell Labs laboratories started working on a solution for
the software problem, to address these compatibility issues. They developed a new operating
system, which was
1. Simple and elegant.
2. Written in the C programming language instead of in assembly code.
3. Able to recycle code.
The Bell Labs developers named their project "UNIX."
6
ECE, JIIT NOIDA EVEN SEMESTER
The code recycling features were very important. Until then, all commercially available computer
systems were written in a code specifically developed for one system. UNIX on the other hand
needed only a small piece of that special code, which is now commonly named the kernel. This
kernel is the only piece of code that needs to be adapted for every specific system and forms the
base of the UNIX system. The operating system and all other functions were built around this kernel
and written in a higher programming language, C.
By the beginning of the 90s home PCs were finally powerful enough to run a full blown UNIX.
Linus Torvalds, a young man studying computer science at the University of Helsinki, thought it
would be a good idea to have some sort of freely available academic version of UNIX, and promptly
started to code.
He started to ask questions, looking for answers and solutions that would help him get UNIX on his
PC.
From the start, it was Linus' goal to have a free system that was completely compliant with the
original UNIX. That is why he asked for POSIX standards, POSIX still being the standard for
UNIX. In those days plug-and-play wasn't invented yet, but so many people were interested in
having a UNIX system of their own, that this was only a small obstacle. New drivers became
available for all kinds of new hardware, at a continuously rising speed. Almost as soon as a new
piece of hardware became available, someone bought it and submitted it to the Linux test, as the
system was gradually being called, releasing more free code for an ever wider range of hardware.
These coders didn't stop at their PC's; every piece of hardware they could find was useful for Linux.
Back then, those people were called "nerds" or "freaks", but it didn't matter to them, as long as the
supported hardware list grew longer and longer. Thanks to these people, Linux is now not only ideal
to run on new PC's, but is also the system of choice for old and exotic hardware that would be
useless if Linux didn't exist. Two years after Linus' post, there were 12000 Linux users. The project,
popular with hobbyists, grew steadily, all the while staying within the bounds of the POSIX
standard. All the features of UNIX were added over the next couple of years, resulting in the mature
7
ECE, JIIT NOIDA EVEN SEMESTER
operating system Linux has become today. Linux is a full UNIX clone, fit for use on workstations as
well as on middle-range and high-end servers. Today, a lot of the
important players on the hard- and software market each have their team of Linux developers; at
your local dealer's you can even buy pre-installed Linux systems with official support –even though
there is still a lot of hard- and software that is not supported, too.
Logging in, activating the user interface and logging out – Introduction
In order to work on a Linux system directly, you will need to provide a user name and password.
You always need to authenticate to the system. Most PC-based Linux systems have two basic modes
for a system to run in: either quick and sober in text console mode, which looks like DOS with
mouse, multitasking and multi-user features, or in graphical mode, which looks better but eats more
system resources.
Graphical mode
This is the default nowadays on most desktop computers. You know you will connect to the system
using graphical mode when you are first asked for your user name, and then, in a new window, to
type your password. To log in, make sure the mouse pointer is in the login window, provide your
user name and password to the system and click OK or press enter.
After entering your user name/password combination, it can take a little while before the graphical
environment is started, depending on the CPU speed of your computer, on the software you use and
on your personal settings.
To continue, you will need to open a terminal window or xterm for short (X being the name for the
underlying software supporting the graphical environment). This program can be found in the
Applications->Utilities, System Tools or Internet menu, depending on what window manager you
are using. There might be icons that you can use as a shortcut to get an xterm window as well, and
clicking the right mouse button on the desktop background will usually present you with a menu
containing a terminal window application.
8
ECE, JIIT NOIDA EVEN SEMESTER
While browsing the menus, you will notice that a lot of things can be done without entering
commands via the keyboard. For most users, the good old point-'n'-click method of dealing with the
computer will do. But this guide is for future network and system administrators, who will need to
meddle with the heart of the system. They need a stronger tool than a mouse to handle all the tasks
they will face. This tool is the shell, and when in graphical mode, we activate our shell by opening a
terminal window.
The terminal window is your control panel for the system. Almost everything that follows is done
using this simple but powerful text tool. A terminal window should always show a command prompt
when you open one. This terminal shows a standard prompt, which displays the user's login name,
and the current working directory, represented by the twiddle (~):
Terminal window
9
ECE, JIIT NOIDA EVEN SEMESTER
open applications back on your screen when you connect again, which takes longer and is not
always the desired effect. However, this behavior is configurable.
When you see the login screen again, asking to enter user name and password, logout was
successful.
Absolute basics
General remarks
You type these commands after the prompt, in a terminal window in graphical mode or in text mode,
followed by Enter.
Commands can be issued by themselves, such as ls. A command behaves different when you specify
an option, usually preceded with a dash (-), as in ls -a. The same option character may have a
different meaning for another command. GNU programs take long options, preceded by two dashes
(--), like ls --all. Some commands have no options.
The argument(s) to a command are specifications for the object(s) on which you want the command
to take effect. An example is ls /etc, where the directory /etc is the argument to the ls command.
10
ECE, JIIT NOIDA EVEN SEMESTER
This indicates that you want to see the content of that directory, instead of the default, which would
be the content of the current directory, obtained by just typing ls followed by Enter. Some
commands require arguments, sometimes arguments are optional.
You can find out whether a command takes options and arguments, and which ones are valid, by
checking the online help for that command.
In Linux, like in UNIX, directories are separated using forward slashes, like the ones used in web
addresses (URLs). The symbols . and .. have special meaning when directories are concerned.
Command Description
11
ECE, JIIT NOIDA EVEN SEMESTER
f1 go-rwx.
Symbols used:
u->user, g->group, o->others, a->all, r->read, w>write, x->execute,’+’
-> add permissions,’- ‘->take away the permissions.
gzip f1 Produces a compressed a file with .gz extension.
gunzip f1 Decompress a file compressed with gzip.
lpr Prints a file.
sort options f1 Sorts a file in the order specified in the options.
head-n f1 Displays first 10 lines of file f1 unless specified using ‘n’.
tail f1 –n no Displays the last 10 lines of file unless specified using ‘no’.
more f1 Shows first part of file just as such as will fit on screen.
less f1 It has the extended capability of allowing both forward and backward
navigation through the file.
grep string f1 Prints all lines of file that contain the string.
grep-v string f1 Prints all lines of the file except those that contain the string.
tar-cvf f.tar f1 To combine multiple files into a single file.
f2
tar-xvf f.tar To separate an archive created by tar into separate files.
ln f1 link Creates a hard link forfile f1 .
ln-s f1 link Creates a symbolic link for file f1 .
tee f1 Place the data flowing through a pipe, in file f1.
Command Description
12
ECE, JIIT NOIDA EVEN SEMESTER
Command Description
13
ECE, JIIT NOIDA EVEN SEMESTER
Command Description
put <absolute To put a file from local machine to the remote machine.
path on local
machine>
System related commands:
Commands Description
14
ECE, JIIT NOIDA EVEN SEMESTER
Command Description
Command Description
Echo variable Prints the value of its arguments. To print the value of a variable, we
must prefix the variable’s name with $ symbol.
Variable Description
Command Description
15
ECE, JIIT NOIDA EVEN SEMESTER
Background on NS2:
NS began development in 1989 as a variant of REAL network simulator. By 1995, NS had gained
support from DARPA, the VINT project at LBL, Xerox PARC, UCB and USC/ISI. Ns is now
developed in collaboration between number of different researchers and institution, including
SAMAN (supported by DARPA), CONSER (through the NSF), and ICIR (former ACIRI). Long-
running contributions have also come from Sun Microsystems and the UCB Daedelus and Carnegie
Mellon Monarch projects, cited by the NS homepage for wireless code additions. NS is based on
two languages, an object oriented simulator written in C++ and an Otcl interpreter, used to execute
users command scripts. Ns have a rich library network and protocol objects. There are two class
hierarchies: the compiled c++ hierarchy and the interpreted Otcl one, with one to one
correspondence between them. NS-2 is a discrete event simulator, which means that events (e.g.
packets to send, timeouts, etc) are scheduled in a global event queue according to their time of
execution. When a simulation is run, the simulator removes events from the head of the queue,
moves the simulator time to that of the currently removed event and executes it. When done, it
continues to the next event and so forth.
Each simulation is defined by a scenario that contains a number of predefined events that define the
scenario. NS-2 scenarios are implemented in TCL scripts that contain the command to initialize the
simulator and to create the nodes and their configuration. Each simulation run generates a trace file
containing all the data packets that are sent between the nodes during the course of the scenario. By
analyzing this file it is possible to determine the performance effect of parameter variations,
different routing protocols and more. A simulation can be very useful because it is possible to scale
the networks easily and therefore to eliminate the need for time consuming and costly real world
experiments. While the simulator is a powerful tool, it is important to remember that the ability to do
predictions about the performance in the real world is dependent on the accuracy of the models in
the simulator.
16
ECE, JIIT NOIDA EVEN SEMESTER
NS-2 can be easily extended by 2 ways, modifying the OTcl or C++ code. In order to add a new
component in ns2, modification on C++ code is the most efficient way to do it, because the C++
code represent the core of the simulator and by it we can able to modify and access every class
variable or function or derive every kind of object in the c ++ hierarchy. Before new component will
be added in to NS2, there are some guidelines. NS2 support two distinct types of monitoring traces
and monitors. A trace use to record each individual packet as it arrives, departs or is dropped at a
link or queue. Tracing in NS2 could be trace packets on all links or just for specific event by using a
simple OTcl code. Since NS2 is a packet level simulator the trace is tracing packet in all link during
simulation. Packet traces describe packets as they travel through the network. It can trace
transmission of the packet on a link, the receipt of the packet and packet drops as well. The NS2
contains various trace formats for suitable use in different simulation such as wireless trace format,
Ad hoc On Demand Distance Vector (AODV), routing algorithm trace format, Dynamic
Destination- Sequenced Distance Vector Routing (DSDV) routing algorithm trace format and
others. The network simulator uses two languages because simulator has two different kinds of
things it needs to do. On one hand detailed simulations of protocols requires a systems programming
language which can efficiently manipulate bytes, packet headers and implement algorithms that run
over large data sets.
For these tasks run-time speed is important and turn –around time (run simulation, find bug, Fix
bug, Recompile, Re-run) is less important.
17
ECE, JIIT NOIDA EVEN SEMESTER
The simulator is initialized using the TCL interface. It is in this file that a new simulation object is
created and several tcl commands relating to the network formation and its properties are added.
When a new simulation object is created, the initialization procedure performs the following tasks:
initializes the packet formats
create a scheduler
create a null agent
Packets may be handed to NS Objects at scheduled points in time since a node is an event handler
and a tasks performed over a packet is an event. Tasks over a packet should be the only type of
event scheduled on a node. The initialization of the packet formats will set up the field offsets used
for the entire simulation. The scheduler is an event driven time management mechanism, which
launches the earliest scheduled event, executing it to completion and returning back to execute the
next event. An event comprises of the time at which it need to be launched along with a handler
function. One property of the scheduler to be noted here is when two or more events occur at the
same time (meaning, they have to be executed at the same time). Under these circumstances it
would decide the precedence based on the order in which they have been scheduled.
NS2 Architecture:
As shown in the simplified user’s view of figure below. NS is an Object-oriented Tcl (OTCl) script
interpreter that has a simulation event scheduler and network component object libraries and
network set-up (plumbing) module libraries.
The event scheduler in NS-2 performs the following tasks:
Organizes the simulation timer.
Fires events in the event queue.
Invokes network components in the simulation.
Depending on the user’s purpose for an OTcl simulation script, Simulation Results are stored as
trace files which can be loaded for analysis by an external application:
1. A NAM trace file (file. nam) for use with the Network Animator Tool
2. A Trace file (file.tr) for use with XGraph or Trace graph.
18
ECE, JIIT NOIDA EVEN SEMESTER
NS2 uses two languages. NS-2 is written in C++ with OTcl interpreter as a front end. For efficiency
reason NS separates the data path implementation from control path implementations.
·Tells traffic sources when to start /stop transmitting packets through the event scheduler.
A user can add OTcl modules to NS – 2 by writing a new object class in OTcl. These then have to
be compiled together with original source code. TclCL is the language used to provide a linkage
between C ++ and OTcl. Toolkit Command Language (Tcl/OTcl) scripts are written to set
up/configure network topologies .TclCL provides linkage for class hierarchy, object instantiation,
variable binding and command dispatching. OTcl is used for periodic or triggered events NAM.
NAM provides a visual interpretation of the network topology created. The application was
developed as part of the VINT project. Its features are as follows.
Provides a visual interpretation of the network created
Can be executed directly from a Tcl script
Controls include play, stop ff, rw, pause, a display speed controller and a packet monitor facility.
Presents information such as throughput, number packets on each link.
Provides a drag and drop interface for creating topologies.
NAM is an animation tool for viewing network simulation traces and real world packet trace data.
The design theory behind nam was to create an animator that is able to read large animation data
sets and be extensible enough so that it could be used indifferent network visualization situations.
Under this constraint nam was designed to read simple animation event commands from a large
trace file. In order to handle large animation data sets a minimum amount of information is kept in
memory. Event commands are kept in the file and reread from the file whenever necessary. The first
step to use nam is to produce the trace file. The trace file contains topology information, e.g. nodes.
Links, as well as packet traces. Usually, the trace file is generated by NS. During an NS simulation,
user can produce topology configurations, layout information, and packet traces using tracing events
in Ns. However any application can generate a nam trace file. When the trace file is generated, t is
ready to be animated by nam. Upon startup, nam will read the trace file, create topology, pop up a
window, do layout if necessary, and then pause at time 0, through its user interface, nam provides
control over many aspects of animation.
Starting up nam will first create the nam console window. You can have multiple animations
running under the same nam instance. At the top of all nam windows is a menu bar. For the nam
20
ECE, JIIT NOIDA EVEN SEMESTER
console there are ‘File’ and ‘Help’ menus. Under the File there is a ‘New’ command for creating a
NS topology using the nam editor, an ‘Open’ command which allows you to open existing trace
files, a ‘Win List’ commands that popup a window will the names of all currently opened trace files,
and a ‘Quit’ command which exits nam. The ‘Help’ menu contains a very limited popup help screen
and a command to show version and copyright information. Once a tracefile has been loaded into
nam (either by using the Open menu command or by specifying the tracefile on the command line)
an animation window will appear. It has a ‘Save layout’ command which will save the current
network layout to a file and a ‘Print’ command which will print the current network layout.
XGraph
XGraph is an X-Windows application that includes:
Interactive plotting and graphing
Animation and derivatives
To use XGraph in NS-2 the executable can be called within a TCL Script. This will then load a
graph displaying the information visually displaying the information of the trace file produced from
the simulation. Trace Graph is a trace file analyzer that runs under Windows, Linux and UNIX
Systems. Trace Graph supports the following trace file formats.
Wired
Satellite
Wireless (old and new trace)
PROCEDURE: -
#define nodes
set n0 [$ns node]
set n1 [$ns node]
#link
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns run
22
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT – 2
THEORY: -
OSI
1. Application Layer
2. Presentation Layer
3. Session Layer
4. Transport Layer
5. Network Layer
7. Physical Layer
Physical Layer
The physical layer defines the means of transmitting raw bits rather than logical data packets over a
physical link connecting network nodes. The bit stream may be grouped into code words or symbols
23
ECE, JIIT NOIDA EVEN SEMESTER
and converted to a physical signal that is transmitted over a hardware transmission medium. The
physical layer provides an electrical, mechanical, and procedural interface to the transmission
medium.
Handles special data frames (packets) between the Network layer and the Physical layer. At the
receiving end, this layer packages raw data from the physical layer into data frames for delivery to
the Network layer. At the sending end this layer handles conversion of data into raw formats that
can be handled by the Physical Layer. The data link layer is responsible for moving frames from one
hop (node) to the next.
Network Layer
Handles addressing messages for delivery, as well as translating logical network addresses and
names into their physical counterparts. It is responsible for deciding how to route transmissions
between computers. This layer also handles the decisions needed to get data from one point to the
next point along a network path. This layer also handles packet switching and network congestion
control. The network layer is responsible for the delivery of individual packets from the source host
to the destination host.
Transport Layer
It manages the transmission of data across a network. Manages the flow of data between parties by
segmenting long data streams into smaller data chunks (based on allowed “packet” size for a given
transmission medium). Reassembles chunks into their original sequence at the receiving end
Provides acknowledgements of successful transmissions and requests resends for packets which
arrive with errors. The transport layer is responsible for the delivery of a message from one process
to another.
24
ECE, JIIT NOIDA EVEN SEMESTER
Session Layer
It enables two networked resources to hold ongoing communications (called a session) across a
network. Applications on either end of the session are able to exchange data for the duration of the
session. This layer is Responsible for initiating, maintaining and terminating sessions, responsible
for security and access control to session information (via session participant
identification),Responsible for synchronization services, and for checkpoint services . The session
layer is responsible for dialog control and synchronization.
Presentation Layer
Application Layer
Provides a set of interfaces for sending and receiving applications to gain access to and use network
services, such as: networked file transfer, message handling and database query processing. The
application layer is responsible for providing services to the user.
TCP
The Transmission Control Protocol (TCP) is one of the core protocols of the Internet Protocol Suite.
TCP is one of the two original components of the suite, complementing the Internet Protocol (IP),
and therefore the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered
delivery of a stream of bytes from a program on one computer to another program on another
25
ECE, JIIT NOIDA EVEN SEMESTER
UDP
The User Datagram Protocol (UDP) is one of the core members of the Internet Protocol Suite, the
set of network protocols used for the Internet. With UDP, computer applications can send messages,
in this case referred to as datagrams, to other hosts on an Internet Protocol (IP) network without
requiring prior communications to set up special transmission channels or data paths. The protocol
was designed by David P. Reed in 1980 and formally defined in RFC 768. UDP uses a simple
transmission model without implicit handshaking dialogues for providing reliability, ordering, or
data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order,
appear duplicated, or go missing without notice. UDP assumes that error checking and correction is
either not necessary or performed in the application, avoiding the overhead of such processing at the
network interface level. Time sensitive applications often use UDP because dropping packets is
preferable to waiting for delayed packets, which may not be an option in a real-time system.[1] If
error correction facilities are needed at the network interface level, an application may use the
Transmission Control Protocol (TCP) or Stream Control Transmission Protocol (SCTP) which are
designed for this purpose.
TCP UDP
26
ECE, JIIT NOIDA EVEN SEMESTER
request the lost part. There is no don't know if it'll get there, it could get
corruption while transferring a message. lost on the way. There may be corruption
while transferring a message.
Ordered: If you send two messages along Ordered: If you send two messages out,
a connection, one after the other, you you
know the first message will get there
don't know what order they'll arrive in i.e.
first. You don't have to worry about data
no ordered.
arriving in the wrong order.
27
ECE, JIIT NOIDA EVEN SEMESTER
PROCEDURE:-
CODE:
#create CBR
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set rate_ 0.05ms
$cbr0 attach-agent $udp0
# connect agents
$ns connect $udp0 $null0
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run
Exercise: Create a wired network with 4 or more nodes with UDP agent.
29
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 3
AIM: - To set up a network with two nodes; link them with duplex link, 10ms propagation
delay, 1Mbps rate and DropTail procedure. Use FTP over Agent TCP.
THEORY: -
TCP: - The Transmission Control Protocol (TCP) is one of the core protocols of the Internet
Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet
Protocol (IP), and therefore the entire suite is commonly referred to as TCP/IP. TCP provides
reliable, ordered delivery of a stream of bytes from a program on one computer to another program
on another computer. TCP provides a communication service at an intermediate level between an
application program and the Internet Protocol (IP). That is, when an application program desires to
send a large chunk of data across the Internet using IP, instead of breaking the data into IP-sized
pieces and issuing a series of IP requests, the software can issue a single request to TCP and let TCP
handle the IP details
Difference between TCP and TCP
TCP UDP
30
ECE, JIIT NOIDA EVEN SEMESTER
Ordered: If you send two messages along Ordered: If you send two messages out,
a connection, one after the other, you you don't know what order they'll arrive
know the first message will get there first. in i.e. no ordered
You don't have to worry about data
arriving in the wrong order.
Examples: World Wide Web (Apache Examples: Domain Name System (DNS
TCP port 80), e-mail (SMTP TCP port 25 UDP port 53), streaming media
Postfix MTA), File Transfer Protocol applications such as IPTV or movies,
(FTP port 21) and Secure Shell Voice over IP (VoIP), Trivial File
(OpenSSH port 22) etc. Transfer Protocol (TFTP) and online
multiplayer games etc
31
ECE, JIIT NOIDA EVEN SEMESTER
PROCEDURE: -
CODE: -
#define nodes
set n0 [$ns node]
set n1 [$ns node]
#link
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#create tcp agent
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
#create a tcpsink agent [TCPSink]
set sink0 [new Agent/TCPSink]
32
ECE, JIIT NOIDA EVEN SEMESTER
Exercise: Create a wired network with 4 or more nodes with TCP agent as well as UDP agent.
33
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 4
THEORY: -
NS simulator simulates the levels related to the local area network: link layer Protocols (such as
ARQ (automatic repeat request), the MAC protocol (Ethernet or token ring)) and the physical
channel.
The best way to define a LAN through which a group of nodes is connected is by the command
2. the delay ,
3. the bandwidth
As an eg, consider the network in the figure below in which node n3,n4,n5 are put on a common
LAN.
34
ECE, JIIT NOIDA EVEN SEMESTER
This means that the TCP packets designated to node n4 arrive also at node n5(and area dropped
there), TCP acknowledgements sent by node n4 to node n0 also arrive at node n5(and are dropped
there) and the UDP packets Designated to node n5 also arrive at node n4 (and are dropped there).
PROCEDURE:-
Code:
set lan [$ns newLan “$n3 $n4 $n5” 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
Exercise: Create a LAN connection in network involving seven nodes; such as node1 and node2 are
linked with duplex link, (10ms propagation delay, 1Mbps rate), node 2 and node 3 with 10ms
propagation delay, 2Mbps rate, such as node 3 and node4 are linked with duplex link, 10ms
35
ECE, JIIT NOIDA EVEN SEMESTER
propagation delay, 1Mbps rate while node 4,5 ,6 ,7 are put on a common LAN. Node 2 is acting as a
TCP host while node 5 is acting as TCP sink, and node 1 is acting as UDP host and node 3 as UDP
sink and label all the node.
36
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 5
AIM: - To Create a mobile ad-hoc network with 3 nodes in 500*400 topography with following initial
positions and movements:
THEORY: -
There are two approaches for wireless communication between two hosts. The first is the centralized
cellular network in which each mobile is connected to one or more fixed base stations, so that a
communication between two mobile stations require to involve one or more base stations. A second
decentralized approach is based on adhoc network between users that wish to communicate between each
other. Due to the more limited range of a mobile terminal (with respect to a fixed base station) this
requires the mobile nodes not only to be sources or destination of packets but also to forward packets
between mobiles. Cellular station has much larger range than ad-hoc networks. However, ad-hoc networks
have the advantage of being quickly deployable as they do not require an existing infrastructure.
Simulating scenario:
We start by presenting simple script that runs a single TCP connection over a 3- node network over an
area of size of 500m x 400m depicted below. The location process is as follows:
37
ECE, JIIT NOIDA EVEN SEMESTER
1. The initial locations of nodes 0, 1 and 2 are respectively (5, 5), (490,285) and (150,240) ( the z –
coordinate is assumed throughout to be 0).
2. At time 10, node 0 starts moving towards point (250,250) at a speed of 3 m/sec.
At time 15, node 1 starts moving towards point (45,285) at a speed of 5 m/sec.
At time 110, node 0 starts moving towards point (480,300) at a speed of 5 m/sec.
The simulations lasts 150 sec. At time 10, a TCP connection is initiated between node 0 and node 1.
PROCEDURE:-
We begin our script wireless1xx.tcl with a list of these different parameters described above, as follows:
# Define options
set val(chan) Channel/WirelessChannel ; # channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(ant) Antenna/OmniAntenna # Antenna type
set val(ll) LL # Link layer type
38
ECE, JIIT NOIDA EVEN SEMESTER
After creation of ns, the simulator instance, open a file (wireless1-out.tr) for wireless traces. Also we are
going to set up nam traces.
Next create a topology object that keeps track of movements of mobile nodes within the topological
boundary.
39
ECE, JIIT NOIDA EVEN SEMESTER
We had earlier mentioned that mobile nodes move within a topology of 500mX400m. We provide the
topography object with x and y co-ordinates of the boundary, (x = 500, y = 400):
The topography is broken up into grids and the default value of grid resolution is 1. A different value can
be passed as a third parameter to load_flatgrid {} above.
create-god $val(nn)
Quoted from CMU document on god, "God (General Operations Director) is the object that is used to
store global information about the state of the environment, network or nodes that an omniscient observer
would have, but that should not be made known to any participant in the simulation." Currently, God
object stores the total number of mobile nodes and a table of shortest number of hops required to reach
from one node to another. The next hop information is normally loaded into god object from movement
pattern files, before simulation begins, since calculating this on the fly during simulation runs can be quite
time consuming. However, in order to keep this example simple we avoid using movement pattern files
and thus do not provide God with next hop information.
The procedure create-god is defined in ~ns/tcl/mobility/com.tcl, which allows only a single global
instance of the God object to be created during a simulation. In addition to the evaluation functionalities,
the God object is called internally by MAC objects in mobile nodes. So even though we may not utilize
God for evaluation purposes, (as in this example) we still need to create God.
# Configure nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
40
ECE, JIIT NOIDA EVEN SEMESTER
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-channelType $val(chan) \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF
The random-motion for nodes is disabled here, as we are going to provide node position and movement
(speed & direction) directives next. Now that we have created mobile nodes, we need to give them a
position to start with,
# Provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)
41
ECE, JIIT NOIDA EVEN SEMESTER
42
ECE, JIIT NOIDA EVEN SEMESTER
This sets up a TCP connection between the two nodes with a TCP source on node0.
Next add the following lines for providing initial position of nodes in nam.
43
ECE, JIIT NOIDA EVEN SEMESTER
# 20 defines the node size in nam, must adjust it according to your scenario size.
Then we need to define stop time when the simulation ends and tell mobile nodes to reset which actually
resets their internal network components,
44
ECE, JIIT NOIDA EVEN SEMESTER
proc stop {} {
close $tracefd
close $namtrace
At time 150.0s, the simulation shall stop. The nodes are reset at that time and the "$ns_ halt" is called at
150.0002s, a little later after resetting the nodes. The procedure stop{} is called to flush out traces and
close the trace file.
$ns run
Save the file wireless1xx.tcl. Next run the simulations in the usual way (type at prompt: "ns
wireless1xx.tcl")
45
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 6
THEORY: -
The wireless simulation described in experiment -4 supports multi-hop ad-hoc networks. But we may need
to simulate a topology of multiple LANs connected through wired nodes, or in other words we need to
create a wired-cum-wireless topology.
In this section we are going to extend the simple wireless topology to create a mixed scenario consisting
of a wireless and a wired domain, where data is exchanged between the mobile and non-mobile nodes. We
are going to make modifications to the tcl script called wirelessxx.tcl and name the resulting wired-cum-
wireless scenario file wireless2xx.tcl.
For the mixed scenario, we are going to have 2 wired nodes, W(0) and W(1), connected to our wireless
domain consisting of 3 mobile nodes (nodes 0, 1 & 2) via a base-station node, BS. Base station nodes are
like gateways between wireless and wired domains and allow packets to be exchanged between the two
types of nodes.
46
ECE, JIIT NOIDA EVEN SEMESTER
Let us begin by checking what changes need to be made to the list of variables defined at the beginning of
wireless1xx.tcl.
The Adhoc routing protocol is changed to DSDV. Also, we define TCP and CBR connections between the
wired and wireless nodes in the script itself. So we won't need to use the connection pattern file used in
earlier simulation. Also change the simulation stop time. Note here that we use array opt() instead of val()
simply to illustrate that this is no longer a global array variable and its scope is defined only in the test
script.
PROCEDURE:-
47
ECE, JIIT NOIDA EVEN SEMESTER
Also add the following line to define number of wired and base-station nodes:
set num_wired_nodes 2
set num_bs_nodes 1
Now we move to the main part of the program. For mixed simulations we need to use hierarchical routing
in order to route packets between wireless and wired domains. The routing information for wired nodes
are based on connectivity of the topology, i.e., how are nodes connected to one another through Links.
This connectivity information is used to populate the forwarding tables in each wired node. However
wireless nodes have no concept of "links". Packets are routed in a wireless topology using their adhoc
routing protocols which build forwarding tables by exchanging routing queries among its neighbours. So,
in order to exchange packets among these wired and wireless nodes, we use base-stations which act as
gateways between the two domains. We segregate wired and wireless nodes by placing them in different
domains. Domains and sub-domains (or clusters as they are called here) are defined by means of
hierarchical topology structure as shown below. After line "set ns [new Simulator]", add the following
lines:
48
ECE, JIIT NOIDA EVEN SEMESTER
In the above lines we first configure the node object to have address type as Hierarchical.
Next the topology hierarchy is defined. Number of domains in this topology is 2 (one for the wired nodes
and one for the wireless). Number of clusters in each of these domains is defined as "2 1" which indicates
the first domain (wired) to have 2 clusters and the second (wireless) to have 1 cluster. The next line
defines the number of nodes in each of these clusters which is "1 1 4"; i.e, one node in each of the first 2
clusters (in wired domain) and 4 nodes in the cluster in the wireless domain. So the topology is defined
into a 3-level hierarchy (see the topology figure above).
Next we setup tracing for the simulation. Note here that for wired-cum-wireless simulation traces may be
generated for both wired and wireless domains. Both the traces are written into the same output file
defined here as wireless2-out.tr. In order to differentiate wireless traces from wired ones, all wireless
traces begin with "WL". We also setup nam traces.
49
ECE, JIIT NOIDA EVEN SEMESTER
Next we need to create the wired, wireless and base-station nodes. Note here that for all node creations,
you have to pass the hierarchical address of the node.
Create god, edit the following lines for creating wired nodes:
In order to create base-station node, we need to configure the node structure. Since base-station nodes are
gateways between wired and wireless domains they need to have wired routing mechanism turned on
which is done by setting node-config option -wiredRouting ON. After creating the base-station node we
reconfigure for wireless node and so turn wiredRouting OFF. All other node-config options used for base-
station remains the same for mobile node. Also the BS(0) node is assigned as the base-station node for all
the mobile nodes in the wireless domain, so that all packets originating from mobile nodes and destined
outside the wireless domain, will be forwarded by mobile nodes towards their assigned base-station.
Note that it is important for the base-station node to be in the same domain as the wireless nodes. This is
so that all packets originating from the wired domain, and destined for a wireless node will reach the base-
station which then uses its adhoc routing protocol to route the packet to its correct destination. Thus in a
mixed simulation involving wired and wireless nodes its necessary:
50
ECE, JIIT NOIDA EVEN SEMESTER
3) To have one base-station node in every wireless domain, through which the wireless nodes may
communicate with nodes outside their domain.
Let us go step by step for this example to see how the hierarchy is created. Here we have two domains,
domain 0, for wired and domain 1, for wireless. The two wired nodes are placed in 2 separate clusters, 0
and 1; thus their addresses look like 0(domain 0).0(cluster 0).0(only node) and 0 (same domain
0).1(cluster 1).0(again only node).
As for the wireless nodes, they are in domain 1; we have defined one cluster (0), so all nodes are in this
cluster. Hence the addresses are:
Base-station: 1(second domain,1).0(cluster 0).0(first node in cluster)
WL node#1 : 1.0.1(second node in cluster)
WL node#2 : 1.0.2(third node)
WL node#3 : 1.0.3(fourth node)
We could have placed the two wired nodes in the same cluster in wired domain 0. Also we could have
placed other wireless nodes in different clusters in wireless domain 1. Also depending on our topology we
may have got rid of clusters alltogether, and simply have had 2 layers of hierarchy, the domains and the
nodes.
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
51
ECE, JIIT NOIDA EVEN SEMESTER
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan)
-topoInstance $topo \
-wiredRouting ON \ ;
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF
set temp {1.0.0 1.0.1 1.0.2 1.0.3} ;# hier address to be used for
;# wireless domain.
52
ECE, JIIT NOIDA EVEN SEMESTER
# Note there has been a change of the earlier AddrParams function 'set-hieraddr' to
'addr2id'.
Next connect wired nodes and BS and setup TCP traffic between wireless node, node_(0) and wired node
W(0), and between W(1) and node_(2), as shown below:
53
ECE, JIIT NOIDA EVEN SEMESTER
54
ECE, JIIT NOIDA EVEN SEMESTER
This would be followed by the remaining lines from wireless1xx.tcl (defining mobile nodes position and
movement, and telling mobile nodes when to stop and finally running ns).
Run the script. The ns and nam trace files are generated at the end of simulation run. Running wireless2-
out.nam shows the movement of mobile nodes and traffic in the wired domain. In trace file wireless2-
out.tr we see traces for both wired domain and wireless domain (preceding with "WL" for wireless). At
160.0s, a TCP connection is setup between _3_, (which is node_(0)) and 0, (which is W(0)). Note that the
node-ids are created internally by the simulator and are assigned in the order of node creation. At 170s,
another TCP connection is setup in the opposite direction, from the wired to the wireless domain.
55
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 7
AIM: - To Interpret data trace file (.tr) of Wired, Wireless and LAN Networks.
THEORY: -
NS simulation can produce both the visualization trace (NAM) as well as an ASCII file trace
corresponding to the events registered at the network.When we use tracing ns inserts four objects in the
link: EnqT, DeqT, RecvT and DrpT asindicated below:
EnqT registers information concerning a packet that arrives and is queued at the input queue of the link. If
the packet overflows then information concerning the dropped packet are handled by the DrpT. DeqT
registers information at the instant the packet is dequed .Finally RecvT gives us information about packets
that have been received at the output of the link.
56
ECE, JIIT NOIDA EVEN SEMESTER
12. Packet Unique ID: The last field shows the unique id of the packet.
To find the interpretation of all possible trace format when you do the wireless simulation, you'd better
read the code of ns2 in file ns2home/trace/cmu-trace{.h, .cc} Mostly, the format would be as
Exercise: Interpret data trace file (.tr) of Wired, LAN, Mobile and Heterogeneous Networks.
59
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 8
PROCEDURE: -
Throughput.awk
BEGIN {
FromNode=1;
toNode=2;
lineCount = 0;
totalBits = 0;
60
ECE, JIIT NOIDA EVEN SEMESTER
/^r/&&$3==fromNode&&$4==toNode {
totalBits += 8*$6;
if ( lineCount==0 ) {
} else {
timeEnd = $2;
};
};
END{
duration = timeEnd-timeBegin;
print “Output: “;
};
61
ECE, JIIT NOIDA EVEN SEMESTER
Again, an AWK usually consists of three sections: BEGIN, Pattern matching, and END.
The Beginning
Again, the initialization of an AWK program is given in curly braces following the keyword “BEGIN”.
Here we set the beginning node fromNode to 1 and ending node toNode to 2. We also reset totalBits and
lineCount to zero.
The End
This is where we process the results (see the program in the curly braces following END):
• Throughput is computed as the total number of bits (totalBits) divided by the simulation duration
(duration)
Pattern Matching
This is where the real fun begins. It’s the place we filter out the unnecessary information. The main line
here is
/^r/&&$3==fromNode&&$4==toNode {
};
which simply says that if a line match “/^r/&&$3==fromNode&&$4==toNode”, do whatever in the curly
braces {…}.
62
ECE, JIIT NOIDA EVEN SEMESTER
1. totalBit: Total number of bits transmitted over the link connecting the node fromNode
Total number of bits is defined as the number of bits leaving node fromNode and arrive node toNode.
Therefore, it corresponds to the lines which matches 3 following conditions:
/^r/&&$3==fromNode&&$4==toNode
For a line matching with the above condition, we shall do things in the curly braces. The first thing here is
totalBits += 8*$6;
which is to add up the 6th column of the line to totalBits. From [ NS Trace Format ( exp 7 )], the 6th
column is the packet size in bytes. By doing this, we add up all data bytes which leaves node fromNode
and arrives node toNode.
Simulation Duration
• The time corresponds to the first matching records (timeBegin); i.e., the time that the
63
ECE, JIIT NOIDA EVEN SEMESTER
first data packet leaving node fromNode arrives the node toNode
• The time corresponds to timeBegin is set the last matching records (timeEnd); i.e., the time that the last
In order to differentiate the first from other records, a counter is used to count which initialized to zero at
the beginning of the program. When count is zero (meaning the first matching line), to the value in the
2nd column (i.e., time of the record). For any other matched record, the time is also recorded into
timeEnd. So at the end of process time corresponding to the last matched record would be stored in
timeEnd.
64
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 9
AIM: - To Create a network with 4 nodes 0-2, 1-2, 2-3 with TCP from 0-3 and UDP from 1-3. Apply
an error model on link 2-3 with error rate 0.2 and uniform distribution. Apply queue monitor on 2-3 link
and interpret any five lines of qm.out file.
THEORY: - Error model simulates link-level errors or loss by either marking the packet’s error flag or
dumping the packet to a drop target. In simulations, errors can be generated from a simple model such as
the packet error rate, or from more complicated statistical and empirical models. To support a wide variety
of models, the unit of error can be specified in term of packet, bits, or time-based.
Queue monitoring refers to the capability of tracking the dynamics of packets at a queue (or other object).
A queue monitortracks packet arrival/departure/drop statistics, and may optionally compute averages of
these values. Monitoring may be applied to all packets (aggregate statistics), or per-flow statistics (using a
Flow Monitor).
PROCEDURE: -
CODE:
proc finish {} {
global ns tracefile1 namfile
65
ECE, JIIT NOIDA EVEN SEMESTER
$ns flush-trace
close $tracefile1
close $namfile
exec nam out.nam &
exit 0
}
#define nodes
set n0 [$ns node] #node n0 created
$n0 label "N0"
set n1 [$ns node]
$n1 label "N1"
set n2 [$ns node]
$n2 label "N2"
set n3 [$ns node]
$n3 label "N3"
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n0 $n2 color "green"
$ns duplex-link-op $n0 $n2 label "Link1"
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link-op $n1 $n2 orient up-right
$ns duplex-link-op $n1 $n2 color "blue"
$ns duplex-link-op $n1 $n2 label "Link2"
#create [SINK]
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcpo $sink
$tcpo set packetsize_ 500
#connect nodes
$ns connect $udpo $nullo
$ns at 0.1 "$cbro start"
$ns at 124 "$cbro stop"
$ns at 160 "finish"
#queue monitoring
set queue [$ns monitor-queue $n2 $n3 [open qm.out w] 0.1];
[$ns link $n2 $n3] queue-sample-timeout;
$ns queue-limit $n2 $n3 30
Exercise: Create a network with 6 nodes 0-2, 2-3, 4-6, 1-5-4 with TCP from 0-3 and UDP from 1-3.
Apply an error model on link 2-3 with error rate 0.2 and uniform distribution. Apply queue monitor on 2-3
link and interpret any five lines of qm.out file
68
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 10
AIM: - To create a network with 5 nodes, and apply uniform, exponential and constant error model with
error rate 1% on 3 different links.
THEORY: - In addition to the basic class ErrorModel described in details below, there are several
other types of error modules not being completely documented yet, which include:
To use an error model for wired networks, at first it has to be inserted into a SimpleLink object. Because a
SimpleLink is a composite object, an error model can be inserted to many places. Currently we provide
the following methods to insert an error module into three different places.
Insert an error module in a SimpleLink BEFORE the queue module. This is provided by the
following two OTcl methods:
rX SimpleLink::errormodule args & When an error model is given as a parameter, it inserts the
error module into the simple link, right after the queue module, and set the drop-target of the error
model to be the drop trace object of the simple link. Note that this requires the following
configuration order: ns namtrace-all followed by link configurations, followed by error model
69
ECE, JIIT NOIDA EVEN SEMESTER
insertion. When no argument is given, it returns the current error model in the link, if there's any.
This method is defined in ns/tcl/lib/ns-link.tcl
Simulator::lossmodel em src dst & Call SimpleLink::errormodule to insert the given error module
into the simple link (src, dst). It's simply a wrapper for the above method. This method is defined
in ns/tcl/lib/ns-lib.tcl.
Insert an error module in a SimpleLink AFTER the queue but BEFORE the delay link. This is
provided by the following two methods:
The nam traces generated by error models inserted using these two methods do not require special
treatment and can be visualized using an older version of nam.
Insert an error module in a Link AFTER the delay link module. This can be done by Link::install-
error. Currently this API doesn't produce any trace. It only serves as a placeholder for possible
future extensions.
PROCEDURE:-
The following is a list of error-model related commands commonly used in simulation scripts:
70
ECE, JIIT NOIDA EVEN SEMESTER
This is a simple example of how to create and configure an error model. The commands to place the error-
model in a simple link will be shown next.
$simplelink errormodule args: This command inserts the error-model before the queue object in simple
link. However, in this case the error-model's drop-target points to the link's drophead_ element.
$ns_ lossmodel em src dst: This command places the error-model before the queue in a simplelink defined
by the <src> and <dst> nodes. This is basically a wrapper for the above method.
$simplelink insert-linkloss args: This inserts a loss-module after the queue, but right before the delay link_
element in the simple link. This is because nam can visualize a packet drop only if the packet is on the link
or in the queue. The error-module's drop-target points to the link's drophead_ element.
$ns_ link-lossmodel em src dst: This too is a wrapper method for insert-linkloss method described above.
That is this inserts the error-module right after the queue element in a simple link (src-dst).
Exercise: Performance analysis of a 4 nodes network after the introduction of any of the error model
discussed above.
71
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 11
AIM: -Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion
window for different source/destination.
THEORY: -Ethernet Local Area Network (ELAN) enables any-to-any connectivity for businesses that
need to connect all their locations on a single network. It is the most widely installed local area network
(LAN) technology. Ethernet is a link layer protocol in the TCP/IP stack, describing how networked
devices can format data for transmission to other network devices on the same network segment, and how
to put that data out on the network connection. It touches both Layer 1 (the physical layer) and Layer 2
(the data link layer) on the OSI network protocol model. Ethernet defines two units of transmission,
packet and frame. The frame includes not just the "payload" of data being transmitted but also addressing
information identifying the physical "Media Access Control" (MAC) addresses of both sender and
receiver, VLAN tagging and quality of service information, and error-correction information to detect
problems in transmission. Each frame is wrapped in a packet, which affixes several bytes of information
used in establishing the connection and marking where the frame starts.
Specified in the family of standards known as IEEE802.3, Ethernet was originally developed by Xerox in
the 1970s. Ethernet was initially designed to run over coaxial cables, but a typical Ethernet LAN now uses
special grades of twisted pair cables, or fiber optical cabling. Wi-Fi standards (IEEE 802.11a, b, g, n and
now ac) define the equivalent of Ethernet for Wireless LANs.) Ethernet standards are steadily evolving to
embrace new media, higher transmission speeds and changes in frame content (e.g., 802.3ac to
accommodate VLAN and priority tagging) and functional requirements (e.g., 802.3af, defining Power
Over Ethernet [POE] crucial to most Wi-Fi and IP telephony deployments).
Ethernet initially assumed a shared medium: multiple devices on each segment of the network, connected
daisy chain at first but later in star topology via Ethernet hubs (which replicated all traffic received on any
port to every other port). It therefore defines a means of sharing the medium: Carrier Sense Multiple
72
ECE, JIIT NOIDA EVEN SEMESTER
Access with Collision Detection (CSMA/CD). Ethernet devices will check to see if anyone else is
transmitting at the moment (carrier sense of multiple access) and if so (collision detection) will wait a
short time before retrying the transmission.
Over time, though, hubs were replaced by switches, which send to each port only the traffic directed to the
device on that port. That, combined with the migration from coaxial to twisted pair cabling (with
dedicated pairs for sending and receiving data) and optical fiber, made shared-medium problems a thing of
the past.
So, basically ELAN provides a multipoint-to-multipoint Ethernet WAN that extends your
LAN to a Wide Area Network that allows your company’s business-critical applications and data to travel
seamlessly across the entire network. ELAN can move large amounts of information between sites,
quickly and securely. ELAN brings together cost effectiveness, speed, simplicity and flexibility in a
broadly customizable Ethernet solution.
• Privacy: All data travels within the secure domain of a Layer 2 dedicated, high capacity, point-to-
point connection at native Ethernet speeds.
• Standards-Based: Depend on Ethernet Local Area Network from the 1st North American Service
Provider to earn all 8 MEF CE 2.0 Certifications.
• Single Interconnection: A hub aggregates all data traffic on a single network linking all your
business locations.
• Traffic Separation: Maintain discrete pathways when you consolidate previously separate domains
for specific applications or departments onto a single network.
• Cost Savings: A single handoff reduces network equipment and management costs.
PROGRAM OUTLINES:
2). Open trace and NAM trace file, finish Procedure and execute the NAM animation file.
73
ECE, JIIT NOIDA EVEN SEMESTER
5). Consider the nodes n (3), n(4) and n(5) under LAN connection and apply orientation to the nodes.
6). Set up queue between two nodes n(2) and n(3) and monitor the queue.
7). Setup TCP connection between n(0) and n(4) nodes and apply FTP application over TCP.
8). Setup another TCP connection between n(5) and n(1) and apply FTP application on it.
Code:-
#Create Simulator
set ns [new Simulator]
74
ECE, JIIT NOIDA EVEN SEMESTER
#Finish Procedure
proc Finish {} {
#Dump all trace data and Close the files
global ns ntrace namfile
$ns flush-trace
close $ntrace
close $namfile
77
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 12
AIM: - Write a program for Error Detection using CRC-CCITT (16 bits)
THEORY: -
In the CRC method, a certain number of check bits, often called a checksum, are appended to the message
being transmitted. The receiver can determine whether or not the check bits agree with the data, to
ascertain with a certain degree of probability whether or not an error occurred in transmission.
If an error occurred, the receiver sends a "negative acknowledgement" (NAK) back to the sender,
requesting that the message be retransmitted. The technique is also sometimes applied to data storage
devices, such as a disk drive. In this situation each block on the disk would have check bits, and the
hardware might automatically initiate a reread of the block when an error is detected, or it might report the
error to software. The material that follows speaks in terms of a "sender" and a "receiver" of a "message,"
but it should be understood that it applies to storage writing and reading as well.
algorithm
1. Start
2. Enter the message to be transmitted
3. Append the message with 16(since it is 16-bit CRC) 0`s (i.e. if you input 5 digit message, the
appeneded message should be 21-bits.)
4. XOR appended message and transmit it.(Here, you compare with an already exisitng string such
as 10001000000100001 and replace the bits the same way XOR operation works)
78
ECE, JIIT NOIDA EVEN SEMESTER
5. Verify the message that is received is the same as the one sent.
6. End
Code:-
#include <iostream>
#include <string.h>
int crc (char *ip, char *op, char *poly, int mode)
if (mode) {
strcat(op, "0");
if (op[i] == '1') {
if (op[i + j] == poly[j])
Op [i + j] = '0';
else
79
ECE, JIIT NOIDA EVEN SEMESTER
Op [i + j] = '1';
if (op[i] == '1')
return 0;
return 1;
int main()
cout << "The transmitted message is: " << ip << op + strlen(ip) <<endl;
cin >>
80
ECE, JIIT NOIDA EVEN SEMESTER
recv;
else
81
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 13
THEORY: -
In the wired network, a link between any two nodes can be broken to demonstrate the link failure. In real
time applications such as online games, video conferencing, telephony, and trading systems, link failure
occurs due to several reasons. Such link failure even if it exists only for a short period, it leads to
unbearable performance degradations. In simulation, the link between any two nodes can be failed and
recovered using the command “rtmodel-at” along with keyword “down” and “up” respectively and with
the time specification. The test4.tcl illustrates the link failure between two nodes in the wired network.
82
ECE, JIIT NOIDA EVEN SEMESTER
83
ECE, JIIT NOIDA EVEN SEMESTER
84
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 14
AIM: -Write a program for distance vector algorithm to find suitable path for transmission.
THEORY: - Distance Vector algorithm is a decentralized routing algorithm that requires that each
router simply inform its neighbors of its routing table. For each network path, the receiving routers pick
the neighbor advertising the lowest cost, then add this entry into its routing table for re-advertisement. To
find the shortest path, Distance Vector algorithm is based on one of two basic algorithms: the Bellman-
Ford and the Dijkstra algorithms. Routers that use this algorithm have to maintain the distance tables
(which is a one-dimension array -- "a vector"), which tell the distances and shortest path to sending
packets to each node in the network. The information in the distance table is always upd by exchanging
information with the neighboring nodes. The number of data in the table equals to that of all nodes in
networks (excluded itself). The columns of table represent the directly attached neighbors whereas the
rows represent all destinations in the network. Each data contains the path for sending packets to each
destination in the network and distance/or time to transmit on that path (we call this as "cost"). The
measurements in this algorithm are the number of hops, latency, the number of outgoing packets, etc.
The starting assumption for distance-vector routing is each node knows the cost of the link of each
of its directly connected neighbors. Next, every node sends a configured message to its directly connected
neighbors containing its own distance table. Now, every node can learn and up its distance table with cost
and next hops for all nodes network. Repeat exchanging until no more information between the
neighbors. Consider a node A that is interested in routing to destination H via a directly attached neighbor
J. Node A's distance table entry, Dx(Y,Z) is the sum of the cost of the direct-one hop link between A and
J, c(A,J), plus neighboring J's currently known minimum-cost path (shortest path) from itself(J) to H.
That is Dx(H,J) = c(A,J) + minw{Dj(H,w)} The minw is taken over all the J's This equation suggests that
the form of neighbor-to-neighbor communication that will take place in the DV algorithm - each node
85
ECE, JIIT NOIDA EVEN SEMESTER
must know the cost of each of its neighbors' minimum-cost path to each destination. Hence, whenever a
node computes a new minimum cost to some destination, it must inform its neighbors of this new
minimum cost.
Implementation algorithm: -
86
ECE, JIIT NOIDA EVEN SEMESTER
proc finish {} {
87
ECE, JIIT NOIDA EVEN SEMESTER
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
$ns rtproto DV
$ns run
89
ECE, JIIT NOIDA EVEN SEMESTER
EXPERIMENT - 15
AIM: - Write a program for congestion control using Leaky Bucket algorithm
THEORY: - Network congestion in data networking and queueing theory is the reduced quality of
service that occurs when a network node is carrying more data than it can handle. Typical effects include
queueing delay, packet loss or the blocking of new connections. A consequence of the latter two effects is
that an incremental increase in offered load leads either only to a small increase or even a decrease in
network throughput.
Network protocols that use aggressive retransmissions to compensate for packet loss due to congestion
can increase congestion, even after the initial load has been reduced to a level that would not normally
have induced network congestion. Such networks exhibit two stable states under the same level of load.
The stable state with low throughput is known as congestive collapse. Networks use congestion control
and congestion avoidance techniques to try to avoid congestion collapse. These include exponential back-
off in protocols such as 802.11CSMA/CA and the original Ethernet, window reduction in TCP, and fair
queueing in devices such as routers. Another method is to implement priority schemes, transmitting some
packets with higher priority than others. Priority schemes help to alleviate the effects of congestion for
services such as 802.1p.
The Leaky Bucket Algorithm is based on, and gets it name from, analogy of a bucket that has a hole in
the bottom through which any water it contains will leak away at a constant rate, until or unless it is
empty. Water can be added intermittently, i.e. in bursts, but if too much is added at once, or it is added at
too high an average rate, the water will exceed the capacity of the bucket, which will overflow. Hence,
this leaky bucket determines whether adding some amount of water would exceed or conform to a limit
on the average rate at which water can be added, set by the leak rate, and a limit on how much water can
be added in a burst, set by the depth of the bucket. The leaky bucket algorithm is used in packet switched
computer networks and telecommunications.
90
ECE, JIIT NOIDA EVEN SEMESTER
PROGRAM OUTLINES: -
1). Start with include and define buffer size. i.e. 10.
2). By using the struct and printf command design the leaky bucket algorithm by using proper for loop.
Code: -
#include<stdio.h>
#include<stdlib.h>
#defineNOF_PACKETS10
Int rand(int a)
Return rn==0?1:rn;
}
91
ECE, JIIT NOIDA EVEN SEMESTER
Int main()
#include<stdio.h>for(i=0;i<NOF_PACKETS;++i)
Packet_sz[i]=rand(6)*10;
For(i=0;NOF_PACKETS;++i)
Printf(“\npacket[%d bytes\t”,I,packet_sz[i]);
Scanf(“%d,&o_rate);
Scanf(“%d,&b_size);
For (i=0;i<NOF_PACKETS;++i)
If ((packet_sz[i] +p_sz_rm)>b_size)
REJECTED “,packet_sz[i],b_size);
Else
Else
Else
92
ECE, JIIT NOIDA EVEN SEMESTER
P_sz_rm+=packet_sz[i];
P_time=rand(4)*10;
For(clk=10;clk<=p_time;clk+=10)
Sleep(1);
If (p_sz_rm)
Op=p_sz_rm,p_sz_rm=0;
Else
Op=o_rate,p_sz_rm=o_rate;
else
}}}}
93