CS 3591 NETWORKS LAB MANUAL_UPDATED OCT_18(2024)
CS 3591 NETWORKS LAB MANUAL_UPDATED OCT_18(2024)
LAB MANUAL
Prepared by
Mrs.K.M.Sharmilee
Assistant Professor/CSE
LIST OF PRACTICAL EXERCISES :
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and trace route PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets.
3. Applications using TCP sockets like: a) Echo client and echo server b) Chat
4. Simulation of DNS using UDP sockets.
5. Use a tool like Wireshark to capture packets and examine the packets
6. Write a code simulating ARP /RARP protocols.
7. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS.
8. Study of TCP/UDP performance using Simulation tool.
9. Simulation of Distance Vector/ Link State Routing algorithm.
10. Simulation of an error correction code (like CRC)
1. Networking Commands
3c File transfer
AIM:
To study the basic networking commands.
NETWORKING COMMANDS:
tcpdump tcpdump is a most powerful and widely used command-line packets sniffer or package
analyzer tool which is used to capture or filter TCP/IP packets that received or transferred over a
network on a specific interface for analysis.
netstat
Displays active TCP connections, ports on which the computer is listening, Ethernet
statistics, IP routing table, IPv4 statistics and IPv6 statistics. It indicates state of a TCP connection.
it's a helpful tool in finding problems and determining the amount of traffic on the network as a
performance measurement.
ifconfig / ipconfig
Displays basic current TCP/IP network configuration. It is very useful to troubleshoot
networking problems. ipconfig/all is used to provide detailed information such as IP address, subnet
mask, MAC address, DNS server, DHCP server, default gateway etc. ipconfig/renew is used to
renew a DHCP assigned IP address whereas ipconfig/release is used to discard the assigned DHCP
IP address.
nslookup
It provides a command-line utility for querying DNS table of a DNS Server. It returns IP
address for the given host name.
traceroute / tracert
Displays the path taken to a destination by sending ICMP Echo Request messages to the
destination with TTL field values. The path displayed is the list of nearest router interfaces taken
along each hop in the path between source host and destination.
ping
Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control
Message Protocol (ICMP) Echo Request messages. The receipt of corresponding Echo Reply
messages are displayed, along with round-trip times. Ping is the primary TCP/IP command used to
troubleshoot connectivity, reachability, and name resolution.
RESULT:
Thus the TCP/IP network command utilities is studied in detail.
EX.NO. 2. HTTP WEB CLIENT PROGRAM
AIM:
To write a java HTTP web client program to download a web page using TCP sockets.
ALGORITHM:
Step 1: Start the program.
Step 2: Set a server port as 80.
Step 3: Using HTTP services create a Socket for server by specifying the server port.
Step 4: Use HTTP socket for connecting the client to the URL.
Step 5: Use BufferedReader to output stream to place the response from the server by the client.
Step 6: Close the Connection as soon the request is been serviced. Use Malformed URL exception
If any errors in grabbing the server. Step 7: Stop the program.
PROGRAM:
import java.io.*;
import java.net.*;
OUTPUT:
RESULT:
Thus the java HTTP web client program to download a web page using TCP sockets has
been executed successfully and output got verified.
EX.NO. 3A: ECHO CLIENT AND ECHO SERVER APPLICATIONS USING TCP
SOCKETS
AIM:
To write a socket program to implement echo client and echo server applications using
TCP sockets in java.
ALGORITHM:
ECHO SERVER:
ECHO CLIENT:
Code:
EchoServer
EchoClient
Step 1: Save Echo Server java file as EchoServer.java and Echo Client java file as
EchoClient.java.
Step 2: Open two cmd prompt for client and server.
Step 3: Set path for javac compiler and java interpreter in cmd prompt as follows
set path=” C:\Program Files\Java\jdk1.7.0_79\bin”; Step 4: Compile
your server java program as follows
javac EchoServer.java
It generates Bytecode file (or Object file) as EchoServer.class
Step 5: Compile your client java program as follows
javac EchoClient.java
It generates Bytecode file (or Object file) as EchoClient.class
Step 6: Execute your server java program as follows
java EchoServer
Step 7: Execute your client java program as follows
java EchoClient
OUTPUT:
RESULT:
Thus the socket program to implement echo client and echo server applications using
TCP sockets in java has been executed successfully and output got verified.
EX.NO. 3B: CHAT APPLICATION USING TCP SOCKETS
AIM:
To write a socket program to implement chat application using TCP sockets in java.
ALGORITHM:
CHAT SERVER:
Step 1: Start the program.
Step 2: Import necessary packages to access the predefined classes and its methods.
Step 3: Create server side socket using ServerSocket class.
Step 4: Accept connection from client by using accept() method.
Step 5: Initialize object for DataInputStream class with getInputStream() method of Socket class
to receive message from client.
Step 6: Initialize object for DataOutputStream class with getOutputStream() method of Socket
class to send message to client.
Step 7: Using readUTF() and writeUTF() method send and receive mesaage between client and
server. Step 8: Stop the program.
CHAT CLIENT:
ChatClient.java:
ChatServer.java:
EXECUTION:
Step 1: Save Chat Server java file as ChatServer.java and Chat Client java file as ChatClient.java.
Step 2: Open two cmd prompt for client and server.
Step 3: Set path for javac compiler and java interpreter in cmd prompt as follows
set path=” C:\Program Files\Java\jdk1.7.0_79\bin”; Step 4: Compile
your server java program as follows
javac ChatServer.java
It generates Bytecode file (or Object file) as ChatServer.class
Step 5: Compile your client java program as follows
javac ChatClient.java
It generates Bytecode file (or Object file) as ChatClient.class
Step 6: Execute your server java program as follows
java ChatServer
Step 7: Execute your client java program as follows
java ChatClient
OUTPUT:
RESULT:
Thus the socket program to implement chat application using TCP sockets in java has
been executed successfully and output got verified.
EX.NO. 3C: FILE TRANSFER APPLICATION USING TCP SOCKETS
AIM:
To write a socket program to implement file transfer application using TCP sockets in
java.
ALGORITHM:
FTP SERVER:
FTP CLIENT:
Code
FTPServer.java
FTPClient.java
EXECUTION:
Step 1: Save FTP Server java file as FTPServer.java and FTP Client java file as FTPClient.java.
Step 2: Open two cmd prompt for client and server.
Step 3: Set path for javac compiler and java interpreter in cmd prompt as follows
set path=” C:\Program Files\Java\jdk1.7.0_79\bin”; Step 4: Compile
your server java program as follows
javac FTPServer.java
It generates Bytecode file (or Object file) as FTPServer.class
Step 5: Compile your client java program as follows
javac FTPClient.java
It generates Bytecode file (or Object file) as FTPClient.class
Step 6: Execute your server java program as follows
java FTPServer
Step 7: Execute your client java program as follows
java FTPClient
OUTPUT:
RESULT:
Thus the socket program to implement file transfer application using TCP sockets in java
has been executed successfully and output got verified.
EX.NO. 4: SIMULATION OF DNS USING UDP SOCKETS
AIM:
To write a socket program for simulating DNS using UDP sockets in java.
ALGORITHM:
CLIENT
SERVER
Code
Server.java
import java.io.*;
import java.net.*;
import java.util.*; class
Server
{
public static void main(String args[])
{ try
{
DatagramSocket server=new DatagramSocket(1309); while(true)
{
byte[] sendbyte=new byte[1024]; byte[]
receivebyte=new byte[1024];
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);String str=new String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String
name[]={"www.aptitudeguru.com","www.downloadcyclone.blogspot.com"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(ip[i]))
{
sendbyte=name[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender); break; }
else if(s.equals(name[i]))
{ sendbyte=ip[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender); break; } } break; } }
catch(Exception e)
{
System.out.println(e);
}
}
}
Client.java
import java.io.*;
import java.net.*;
import java.util.*; class
Client{
public static void main(String args[])
{ try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024]; byte[]
receivebyte=new byte[1024]; BufferedReader in=new
BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the SERVER/DOMAIN NAME:");
String str=in.readLine(); sendbyte=str.getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData()); System.out.println("IP address is: "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
EXECUTION:
Step 1: Save Server java file as Server.java and Client java file as Client.java.
Step 2: Open two cmd prompt for client and server.
Step 3: Set path for javac compiler and java interpreter in cmd prompt as follows
set path=” C:\Program Files\Java\jdk1.7.0_79\bin”; Step 4: Compile
your server java program as follows
javac Server.java
It generates Bytecode file (or Object file) as Server.class
Step 5: Compile your client java program as follows
javac Client.java
It generates Bytecode file (or Object file) as Client.class
Step 6: Execute your server java program as follows
java Server
Step 7: Execute your client java program as follows
java Client
OUTPUT:
EX.NO. 5. WIRESHARK TOOL TO CAPTURE AND EXAMINE PACKETS
AIM:
To capture ping and traceroute PDUs using a network protocol analyzer and examine in
detail.
WIRESHARK TOOL
To start data capture it is first necessary to go to the Capture menu and select the Options choice.
The Options dialog provides a range of settings and filters which determines which and how much
data traffic is captured.
First, it is necessary to ensure that Wireshark is set to monitor the correct interface. From the
Interface drop-down list, select the network adapter in use. Typically, for a computer this will be
the connected Ethernet Adapter. Then other Options can be set. Among those available in Capture
Options, the two highlighted below are worth examination.
Clicking on the Start button starts the data capture process and a message box displays the
progress of this process.
As data PDUs are captured, the types and number are indicated in the message box
The examples above show the capture of a ping process and then accessing a web page. When the
Stop button is clicked, the capture process is terminated and the main screen is displayed. This main
display window of Wireshark has three panes.
The PDU (or Packet) List Pane at the top of the diagram displays a summary of each packet captured.
By clicking on packets in this pane, you control what is displayed in the other two panes. The PDU
(or Packet) Details Pane in the middle of the diagram displays the packet selected in the Packet List
Pane in more detail.
The PDU (or Packet) Bytes Pane at the bottom of the diagram displays the actual data (in
hexadecimal form representing the actual binary) from the packet selected in the Packet List Pane,
and highlights the field selected in the Packet Details Pane.
Step 1: After ensuring that the standard lab topology and configuration is correct, launch Wireshark
on a computer in a lab pod. Set the Capture Options as described above in the overview and start
the capture process. From the command line of the computer, ping the IP address of another network
connected and powered on end device on in the lab topology. In this case, ping the Eagle Server at
using the command ping 192.168.254.254. After receiving the successful replies to the ping in the
command line window, stop the packet capture.
Step 2: Examine the Packet List pane.
The Packet List pane on Wireshark should now look something like this:
Look at the packets listed above; we are interested in packet numbers 6, 7, 8, 9, 11, 12, 14 and 15.
Locate the equivalent packets on the packet list on your computer.
Step 3: Select (highlight) the first echo request packet on the list with the mouse. The Packet Detail
pane will now display something similar to: Click on each of the four "+" to expand the information.
The packet Detail Pane will now be similar to:
From this image we can observe ICMP echo reply message is sent from 8.8.8.8 (destination) to
192.168.1.101 (source) for TTL 22.
RESULT:
Thus the capturing of ping and traceroute PDUs using a network protocol analyzer
examined.
EX.NO. 6A: SIMULATING ARP PROTOCOL
AIM:
To write a socket program for simulating ARP protocol using TCP sockets in java.
ALGORITHM:
CLIENT
SERVER
Code
Server.java
class Server {
public static void main(String args[]) {
try {
ServerSocket obj = new ServerSocket(3636);
Socket obj1 = obj.accept();
if (!found) {
dout.writeBytes("MAC not found\n");
}
}
obj.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Client.java
import java.io.*;
import java.net.*;
class Client {
public static void main(String args[]) {
try {
// BufferedReader for user input
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
EXECUTION:
Step 1: Save Server java file as Server.java and Client java file as Client.java.
Step 2: Open two cmd prompt for client and server.
Step 3: Set path for javac compiler and java interpreter in cmd prompt as follows
set path=” C:\Program Files\Java\jdk1.7.0_79\bin”; Step 4: Compile
your server java program as follows
javac Server.java
It generates Bytecode file (or Object file) as Server.class
Step 5: Compile your client java program as follows
javac Client.java
It generates Bytecode file (or Object file) as Client.class
Step 6: Execute your server java program as follows
java Server
Step 7: Execute your client java program as follows
java Client
OUTPUT:
RESULT:
Thus the socket program for simulating ARP protocol using TCP sockets in java has
been executed successfully and output got verified.
EX.NO. 6B: SIMULATING RARP PROTOCOL
AIM:
To write a socket program for simulating RARP protocol using TCP sockets in java.
ALGORITHM:
CLIENT
SERVER
Code
Server.java
import java.io.*;
import java.net.*;
class Server {
public static void main(String args[]) {
try {
// Create a server socket on port 3000
ServerSocket obj = new ServerSocket(3000);
System.out.println("Server started, waiting for client...");
while (true) {
// Read the MAC address from the client
String str = din.readLine();
if (str == null) { break; // Exit the loop if input is
null (e.g., client disconnects)
}
if (!found) {
dout.writeBytes("IP not found\n");
}
}
Client.java
import java.io.*;
import java.net.*;
class Client {
public static void main(String args[]) {
try {
// BufferedReader for user input
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
EXECUTION:
Step 1: Save Server java file as Server.java and Client java file as Client.java.
Step 2: Open two cmd prompt for client and server.
Step 3: Set path for javac compiler and java interpreter in cmd prompt as follows
set path=” C:\Program Files\Java\jdk1.7.0_79\bin”; Step 4: Compile
your server java program as follows
javac Server.java
It generates Bytecode file (or Object file) as Server.class
Step 5: Compile your client java program as follows
javac Client.java
It generates Bytecode file (or Object file) as Client.class
Step 6: Execute your server java program as follows
java Server
Step 7: Execute your client java program as follows
java Client
OUTPUT:
RESULT:
Thus the socket program for simulating RARP using TCP sockets in java has been
executed successfully and output got verified.
EX.NO. 7. A. STUDY OF NETWORK SIMULATOR USING NS
AIM:
THEORY:
Network Simulator (Version 2), widely known as NS2, 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 who developed the REAL network simulator,1 the foundation
which NS is based on. Since 1995 the Defense Advanced Research Projects Agency (DARPA)
supported 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 the least,
the group of Researchers and developers in the community are constantly working to keep NS2
strong and versatile.
Figure 2.1 shows the basic architecture of NS2. NS2 provides users with an 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 graph and/or to create
animation. NS2 consists of two key languages: C++ and Object-oriented Tool Command Language
(OTcl). While the C++ defines the internal mechanism (i.e., a backend) of the simulation objects,
the OTcl sets up simulation by assembling and configuring the objects as well as scheduling discrete
events (i.e., a frontend).
BASIC ARCHITECTURE:
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 the mapped C++ object (e.g., of
class Connector). In the OTcl domain, a handle acts as a frontend which interacts with users and
other OTcl.
objects. It may defines its own procedures and variables to facilitate the interaction. Note that the
member procedures and variables in the OTcl domain are called instance procedures (instprocs) and
instance variables (instvars), respectively. Before proceeding further, the readers are encouraged to
learn C++ and OTcl languages. We refer the readers to [14] for the detail of C++, while a brief
tutorial of Tcl and OTcl tutorial are given in Appendices A.1 and A.2, respectively.
NS2 provides a large number of built-in C++ objects. It is advisable to use these C++ objects to set
up a simulation using a Tcl simulation script. However, advance users may find these objects
insufficient. They need to develop their own C++ objects, and use a OTcl configuration interface to
put together these objects. After simulation, NS2 outputs either text-based or animation-based
simulation results. To interpret these results graphically and interactively, tools such as NAM
(Network AniMator) and XGraph are used. To analyze a particular behaviour of the network, users
can extract a relevant subset of text-based data and transform it to a more conceivable presentation.
CONCEPT OVERVIEW:
NS 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. On the other hand, a large part of network research involves
slightly varying parameters or configurations, or quickly exploring a number of scenarios. In these
cases, iteration time (change the model and re-run) is more important. Since configuration runs once
(at the beginning of the simulation), run-time of this part of the task is less important. ns meets both
of these needs with two languages, C++ and OTcl. 1. Tcl scripting
Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage.
2. Basics of TCL
Syntax: command arg1 arg2 arg3
Variables
Command
Substitution set a 5
set len [string
length foobar]
set b $a set len [expr [string length foobar] + 9] 4.
Wired TCL Script Components
Create the event scheduler
Open new files & turn
on the tracing Create
the nodes Setup
the links
Configure the traffic type (e.g., TCP, UDP, etc)
Set the time of traffic generation (e.g., CBR, FTP)
Terminate the simulation
5. NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator. 2.
Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.
6. Initialization and Termination of TCL Script in NS-2
An ns simulation starts with the command
7. set ns [new Simulator]
Which is thus the first line in the tcl script. This line declares a new variable as using the set
command, you can call this variable as you wish, In general people declares it as ns because it is an
instance of the Simulator class, so an object the code[new Simulator] is indeed the installation of
the class Simulator using the reserved word new.
In order to have output files with data on the simulation (trace files) or files used for visualization
(nam files), we need to create the files using ―open command:
#Open the Trace file set
tracefile1 [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file set
namfile [open out.nam w]
$ns namtrace-all $namfile
The above creates a dta trace file called out.tr and a nam visualization trace file called out.nam.
Within the tcl script, these files are not called explicitly by their names, but instead by pointers that
are declared above and called ―tracefile1 and ―namfile respectively. Remark that they begins
with a # symbol. The second line open the file ―out.tr to be used for writing, declared with the
letter ―w. The third line uses a simulator method called trace-all that have as parameter the name
of the file where the traces will go.
Once we define several nodes, we can define the links that connect them. An example of a
definition of a link is:
9. $ns duplex-link $n0 $n2 10Mb 10ms DropTail
Which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of
propagation delay and a capacity of 10Mb per sec for each direction.
To define a directional link instead of a bi-directional one, we should replace ―duplex-link by
―simplex-link.
In ns, an output queue of a node is implemented as a part of each link whose input is that node.
We should also define the buffer capacity of the queue related to each link. An example would
be:
AIM:
To simulate a link failure and observe the congestion control algorithm using NS2.
ALGORITHM:
PROGRAM:
RESULT:
Thus the congestion controlling algorithm using ns2 has been executed successfully and
output got verified.
EX.NO. 8.A. STUDY OF TCP PERFORMANCE
AIM:
To study about TCP performance in detail.
Introduction :
The transmission Control Protocol (TCP) is one of the most important protocols of Internet
Protocols suite. It is most widely used protocol for data transmission in communication network
such as internet.
Features
● TCP is reliable protocol. That is, the receiver always sends either positive or negative
acknowledgement about the data packet to the sender, so that the sender always has bright
clue about whether the data packet is reached the destination or it needs to resend it.
● TCP ensures that the data reaches intended destination in the same order it was sent.
● TCP is connection oriented. TCP requires that connection between two remote points be
established before sending actual data.
● TCP provides error-checking and recovery mechanism.
● TCP provides end-to-end communication.
● TCP provides flow control and quality of service.
● TCP operates in Client/Server point-to-point mode.
● TCP provides full duplex server, i.e. it can perform roles of both receiver and sender.
Header
The length of TCP header is minimum 20 bytes long and maximum 60 bytes.
Source port address. This is a 16-bit field that defines the port number of the application
program in the host that is sending the segment.
Destination port address. This is a 16-bit field that defines the port number of the application
program in the host that is receiving the segment.
Source port address. This is a 16-bit field that defines the port number of the application
program in the host that is sending the segment.
Destination port address. This is a 16-bit field that defines the port number of the application
program in the host that is receiving the segment.
Sequence number. This 32-bit field defines the number assigned to the first byte of data
contained in this segment. TCP is a stream transport protocol. To ensure connectivity, each
byte to be transmitted is numbered. The sequence number tells the destination which byte in
this sequence is the first byte in the segment. During connection establishment each party
uses a random number generator to create an initial sequence number (ISN), which is
usually different in each direction.
Acknowledgment number. This 32-bit field defines the byte number that the receiver of the
segment is expecting to receive from the other party. If the receiver of the segment has
successfully received byte number x from the other party, it returns x + 1 as the
acknowledgment number. Acknowledgment and data can be piggybacked together.
Header length. This 4-bit field indicates the number of 4-byte words in the TCP header. The
length of the header can be between 20 and 60 bytes. Therefore, the value of this field is
always between 5 (5 × 4 = 20) and 15 (15 × 4 = 60).
Control. This field defines 6 different control bits or flags. One or more of these bits can be set
at a time. These bits enable flow control, connection establishment and termination,
connection abortion, and the mode of data transfer in TCP.
Window size. This field defines the window size of the sending TCP in bytes. Note that the
length of this field is 16 bits, which means that the maximum size of the window is 65,535
bytes. This value is normally referred to as the receiving window (rwnd) and is determined
by the receiver. The sender must obey the dictation of the receiver in this case.
Checksum. This 16-bit field contains the checksum. The calculation of the checksum for TCP
follows the same procedure as the one described for UDP. However, the use of the checksum
in the UDP datagram is optional, whereas
the use of the checksum for TCP is mandatory. The same pseudoheader, serving the same
purpose, is added to the segment. For the TCP pseudoheader, the value for the protocol field
is 6.
Urgent pointer. This 16-bit field, which is valid only if the urgent flag is set, is used when the
segment contains urgent data. It defines a value that must be added to the sequence number to
obtain the number of the last urgent byte in the data section of the segment. Options. There
can be up to 40 bytes of optional information in the TCP header.
Addressing
TCP communication between two remote hosts is done by means of port numbers (TSAPs).
Ports numbers can range from 0 – 65535 which are divided as:
● System Ports (0 – 1023)
● User Ports ( 1024 – 49151)
● Private/Dynamic Ports (49152 – 65535)
Connection Management
TCP communication works in Server/Client model. The client initiates the connection and the
server either accepts or rejects it. Three-way handshaking is used for connection management.
Establishment
Client initiates the connection and sends the segment with a Sequence number. Server
acknowledges it back with its own Sequence number and ACK of client’s segment which is one
more than client’s Sequence number. Client after receiving ACK of its segment sends an
acknowledgement of Server’s response.
Release
Either of server and client can send TCP segment with FIN flag set to 1. When the receiving
end responds it back by Acknowledging FIN, that direction of TCP communication is closed and
connection is released.
Bandwidth Management
TCP uses the concept of window size to accommodate the need of Bandwidth management.
Window size tells the sender at the remote end, the number of data byte segments the receiver at
this end can receive. TCP uses slow start phase by using window size 1 and increases the window
size exponentially after each successful communication.
For example, the client uses windows size 2 and sends 2 bytes of data. When the
acknowledgement of this segment received the windows size is doubled to 4 and next sent the
segment sent will be 4 data bytes long. When the acknowledgement of 4-byte data segment is
received, the client sets windows size to 8 and so on.
If an acknowledgement is missed, i.e. data lost in transit network or it received NACK, then
the window size is reduced to half and slow start phase starts again.
Multiplexing
The technique to combine two or more data streams in one session is called Multiplexing.
When a TCP client initializes a connection with Server, it always refers to a welldefined port number
which indicates the application process. The client itself uses a randomly generated port number
from private port number pools.
Using TCP Multiplexing, a client can communicate with a number of different application
process in a single session. For example, a client requests a web page which in turn contains different
types of data (HTTP, SMTP, FTP etc.) the TCP session timeout is increased and the session is kept
open for longer time so that the three-way handshake overhead can be avoided.
This enables the client system to receive multiple connection over single virtual
connection. These virtual connections are not good for Servers if the timeout is too long.
Congestion Control
When large amount of data is fed to system which is not capable of handling it, congestion
occurs. TCP controls congestion by means of Window mechanism. TCP sets a window size telling
the other end how much data segment to send. TCP may use three algorithms for congestion control:
∙ Additive increase, Multiplicative Decrease
∙ Slow Start ∙
Timeout React
Timer Management
TCP uses different types of timer to control and management various tasks:
Keep-alive timer:
∙ This timer is used to check the integrity and validity of a connection. ∙ When keep-alive
time expires, the host sends a probe to check if the connection still exists.
Retransmission timer:
∙ This timer maintains stateful session of data sent.
∙ If the acknowledgement of sent data does not receive within the Retransmission time, the data
segment is sent again.
Persist timer:
∙ TCP session can be paused by either host by sending Window Size 0.
∙ To resume the session a host needs to send Window Size with some larger value. ∙ If this segment
never reaches the other end, both ends may wait for each other for infinite time.
∙ When the Persist timer expires, the host re-sends its window size to let the other end know.
∙ Persist Timer helps avoid deadlocks in communication.
Timed-Wait:
∙ After releasing a connection, either of the hosts waits for a Timed-Wait time to terminate the
connection completely.
∙ This is in order to make sure that the other end has received the acknowledgement of its connection
termination request. ∙ Timed-out can be a maximum of 240 seconds (4 minutes).
Crash Recovery
TCP is very reliable protocol. It provides sequence number to each of byte sent in segment.
It provides the feedback mechanism i.e. when a host receives a packet, it is bound to ACK that
packet having the next sequence number expected (if it is not the last segment).
When a TCP Server crashes mid-way communication and re-starts its process it sends TPDU
broadcast to all its hosts. The hosts can then send the last data segment which was never
unacknowledged and carry onwards.
Algorithm
1. Create a simulator object
2. Define different flows for data flows
3. Trace all events in a nam file and text file
4. Create source nodes (s1, s2, s3), gateway (G) and receiver (r)
5. Describe their layout topology
6. Specify the link between nodes
7. Define the queue size between nodes G and r as 5
8. Monitor queue on all links vertically 90°
9. Create TCP agents tcp1, tcp2, tcp3 and attach it to nodes s1, s2 and s3 respectively
10. Create three TCP sinks and attach it to node r
11. Connect traffic sources to the sink
12. Create FTP agents ftp1, ftp2, ftp3 and attach it to tcp1, tcp2 and tcp3 respectively
13. Label the nodes at start time
14. Schedule ftp1, ftp2, ftp3 to start at 0.1 and stop at 5.0 seconds
15. Call finish procedure at 5.25 seconds
16. Run the simulation
17. Execute NAM on the trace file
18. Observe the simulated events on the NAM editor and packet flow on link G to r
19. View the trace file and analyse the events
20. Stop
#G acts as a gateway
set G [$ns node]
#r acts as a receiver
set r [$ns node]
#Define the queue size for the link between node G and r
$ns queue-limit $G $r 5
OUTPUT:
RESULT:
Thus the TCP performance is studied in detail.
EX.NO.8.B. STUDY OF UDP PERFORMANCE
AIM:
To study about UDP performance in detail.
Introduction :
The User Datagram Protocol (UDP) is simplest Transport Layer communication protocol
available of the TCP/IP protocol suite. It involves minimum amount of communication mechanism.
UDP is said to be an unreliable transport protocol but it uses IP services which provides best effort
delivery mechanism.
In UDP, the receiver does not generate an acknowledgement of packet received and in turn,
the sender does not wait for any acknowledgement of packet sent. This shortcoming makes this
protocol unreliable as well as easier on processing.
Requirement of UDP
A question may arise, why do we need an unreliable protocol to transport the data? We
deploy UDP where the acknowledgement packets share significant amount of bandwidth along with
the actual data. For example, in case of video streaming, thousands of packets are forwarded towards
its users. Acknowledging all the packets is troublesome and may contain huge amount of bandwidth
wastage. The best delivery mechanism of underlying IP protocol ensures best efforts to deliver its
packets, but even if some packets in video streaming get lost, the impact is not calamitous and can
be ignored easily. Loss of few packets in video and voice traffic sometimes goes unnoticed.
Features
∙ UDP is used when acknowledgement of data does not hold any significance.
∙ UDP is good protocol for data flowing in one direction.
∙ UDP is simple and suitable for query based communications.
∙ UDP is not connection oriented.
∙ UDP does not provide congestion control mechanism.
∙ UDP does not guarantee ordered delivery of data.
∙ UDP is stateless. ∙ UDP is suitable protocol for streaming applications such as VoIP,
multimedia streaming.
UDP Header
UDP header is as simple as its function.
UDP application
Here are few applications where UDP is used to transmit data:
∙ Domain Name Services
∙ Simple Network Management Protocol
∙ Trivial File Transfer Protocol
∙ Routing Information Protocol
∙ Kerberos
Algorithm
1. Create a simulator object
2. Define different color for data flows
3. Trace all events in a nam file.
4. Create four nodes n0, n1, n2 and n3
5. Describe their layout topology
6. Specify the link capacity between nodes
7. Monitor queue on the link n2 to n3 vertically 90°
8. Create a UDP agents udp0, udp1 and attach it to nodes n0 and n1 respectively
9. Create a CBR traffic cbr0, cbr1 and attach it to udp0 and udp1 respectively
10. Create a traffic sink and attach it to node n3
11. Connect sources to the sink
12. Label the nodes
13. Schedule cbr0 to start at 0.5 and stop at 4.5 seconds
14. Schedule cbr1 to start at 1.0 and stop at 4.0 seconds
15. Call finish procedure at 5.0 seconds
16. Run the simulation
17. Execute NAM on the trace file
18. Observe simulated events on the NAM and packet flow on link n2 to n3
19. Stop
RESULT:
Thus the UDP performance is studied in detail.
EX.NO. 9.A. SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM
AIM:
To simulate and observe traffic route of a network using distance vector routing protocol.
ALGORITHM:
Step 1: Create a simulator object
Step 2: Set routing protocol to Distance vector routing
Step 3: Trace packets on all links on to NAM trace and text trace file.
Step 4: Define finish procedure to close files, flash tracing and run NAM
Step 5: Create 5 nodes
Step 6: Specify the link characteristics between the nodes
Step 7: Describer their layout topology as a octagon
Step 8: Add UDP agent for node n0
Step 9: Create CBR traffic on the top of UDP and set traffic parameters
Step 10: Add NULL agent to node n3
Step 11: Connect source and sink
Step 12: Schedule as follows
● Start traffic flow at 1.0
● Down the link n1 – n2 at 15.0
● Up the link n1 – n2 at 25.0
● Call finish procedure at 35.0
Step 13: Start the scheduler
Step 14: Observe the traffic route when the link is up and down
Step 15: View the simulated events and trace file analyze it
Step 16: Stop.
PROGRAM:
# Create 8 nodes
set n1 [$ns node] set
n2 [$ns node] set n3
[$ns node] set n4
[$ns node] set n5
[$ns node] set n6
[$ns node] set n7
[$ns node]
set n8 [$ns node]
#Schedule events for the CBR agent and the network dynamics
$ns at 0.0 "$n1 label Source"
$ns at 0.0 "$n4 label Destination"
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n3 $n4
$ns rtmodel-at 2.0 up $n3 $n4
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish"
OUTPUT:
RESULT:
Thus the simulation of distance vector routing algorithm using ns2 has been executed
successfully and output got verified.
EX.NO. 9.B. SIMULATION OF LINK STATE ROUTING ALGORITHM
AIM:
To simulate and observe traffic route of a network using link state routing algorithm.
ALGORITHM:
Step 1: Create a simulator object
Step 2: Trace packets on all links on to NAM trace and text trace file.
Step 3: Define finish procedure to close files, flash tracing and run NAM
Step 4: Create 5 nodes
Step 5: Specify the link characteristics between the nodes
Step 6: Describer their layout topology as a octagon
Step 7: Add UDP agent for node n0
Step 8: Create CBR traffic on the top of UDP and set traffic parameters
Step 9: Add NULL agent to node n3
Step 10: Connect source and sink
Step 11: Set routing protocol to Distance vector routing
Step 12: Start the scheduler
Step 13: Observe the traffic route when the link is up and down
Step 14: View the simulated events and trace file analyze it
Step 15: Stop.
PROGRAM:
$ns rtproto LS
$ns at 45 "finish"
$ns run
OUTPUT:
RESULT:
Thus the simulation of link state routing algorithm using ns2 has been executed
successfully and output got verified.
EX.NO. 10. SIMULATION OF ERROR CORRECTION CODE (CRC)
AIM:
To simulate the error correction code like CRC using java.
ALGORITHM:
Step 1: Open the editor and type the program for error detection
Step 2: Get the input in the form of bits.
Step 3: Append the redundancy bits.
Step 4: Divide the appended data using a divisor polynomial.
Step 5: The resulting data should be transmitted to the receiver.
Step 6: At the receiver the received data is entered.
Step 7: The same process is repeated at the receiver.
Step 8: If the remainder is zero there is no error otherwise there is some error in the received
bits Step 9: Run the program.
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main() {
int i, j, k, count, err_pos = 0, flag = 0;
char dw[20], cw[20], data[20];
// Error detection
for (i = 0; i < 4; i++) {
count = 0;
for (j = (int)pow(2, i); j < 12; j += (int)pow(2, i) * 2) {
for (k = 0; k < (int)pow(2, i) && j + k < 12; k++) {
if (cw[j + k] == '1') count++;
}
}
if (count % 2 != 0) { err_pos
= err_pos + (int)pow(2, i);
}
}
// Error correction
if (err_pos == 0) {
printf("\n\nThere is no error in the received code word.\n");
} else {
if (cw[err_pos] == dw[err_pos]) { printf("\n\nThere are 2 or
more errors in the received code...\n"); printf("Sorry...! Hamming
code cannot correct 2 or more errors.\n"); flag = 1; } else {
printf("\n\nThere is an error in bit position %d of the received code word.\n",
err_pos); if (flag == 0) { cw[err_pos] = (cw[err_pos] == '1') ? '0' : '1';
printf("\n\nCorrected code word is:\n");
for (i = 1; i < 12; i++) {
printf("%c", cw[i]);
}
}
}
}
printf("\n\n");
return 0;
}
OUTPUT:
RESULT:
Thus the simulation of error correction code (like CRC) has been executed
successfully and output got verified.
EX.NO: 11
Simulation of Go Back N protocol
DATE:
AIM:
To Simulate and to study of Go Back N protocol.
THEORY:
Go Back N is a connection oriented transmission. The sender transmits the
frames continuously. Each frame in the buffer has a sequence number starting
from 1 and increasing up to the window size. The sender has a window i.e. a
buffer to store the frames. This buffer size is the number of frames to be
transmitted continuously. The size of the window depends on the protocol
designer.
OPERATIONS:
1. A station may send multiple frames as allowed by the window size.
2. Receiver sends an ACK i if frame i has an error. After that, the receiver
discards all incoming frames until the frame with error is correctly
retransmitted.
3. If sender receives an ACK i it will retransmit frame i and all packets i+1,
i+2,... which have been sent, but not been acknowledged
ALGORITHM:
1. The source node transmits the frames continuously.
2. Each frame in the buffer has a sequence number starting from 1 and
increasing up to the window size.
3. The source node has a window i.e. a buffer to store the frames. This buffer
size is the number of frames to be transmitted continuously.
4. The size of the window depends on the protocol designer.
5. For the first frame, the receiving node forms a positive acknowledgement
if the frame is received without error.
6. If subsequent frames are received without error (up to window size)
cumulative positive acknowledgement is formed.
7. If the subsequent frame is received with error, the cumulative
acknowledgment error-free frames are transmitted. If in the same window two
frames or more frames are received with error, the second and the subsequent
error frames are neglected. Similarly even the frames received without error
after the receipt of a frame with error are neglected.
8. The source node retransmits all frames of window from the first error
frame.
9. If the frames are errorless in the next transmission and if the
acknowledgment is error free, the window slides by the number of error-free
frames being transmitted.
10. If the acknowledgment is transmitted with error, all the frames of window
at source are retransmitted, and window doesn’t slide.
11. This concept of repeating the transmission from the first error frame in the
window is called as GOBACKN transmission flow control protocol
PROGRAM:
OUTPUT:
RESULT:
AIM:
To Simulate and to study of selective repeat ARQ protocol.
THEORY:
Selective Repeat ARQ is a specific instance of the Automatic Repeat-reQuest
(ARQ) Protocol. It may be used as a protocol for the delivery and
acknowledgement of message units, or it may be used as a protocol for the
delivery of subdivided message sub-units. When used as the protocol for the
delivery of messages, the sending process continues to send a number of
frames specified by a window size even after a frame loss. Unlike GoBack-N
ARQ, the receiving process will continue to accept and acknowledge frames
sent after an initial error. The receiver process keeps track of the sequence
number of the earliest frame it has not received, and sends that number with
every ACK it sends. If a frame from the sender does not reach the receiver,
the sender continues to send subsequent frames until it has emptied its
window. The receiver continues to fill its receiving window with the
subsequent frames, replying each time with an ACK containing the sequence
number of the earliest missing frame. Once the sender has sent all the frames
in its window, it re-sends the frame number given by the ACKs, and then
continues where it left off. The size of the sending and receiving windows
must be equal, and half the maximum sequence number (assuming that
sequence numbers are numbered from 0 to n-1) to avoid miscommunication
in all cases of packets being dropped. To understand this, consider the case
when all ACKs are destroyed. If the receiving window is larger than half the
maximum sequence number, some, possibly even all, of the packages that are
resent after timeouts are duplicates that are not recognized as such. The sender
moves its window for every packet that is acknowledged.
Advantage over Go Back N:
1. Fewer retransmissions.
Disadvantages:
1. More complexity at sender and receiver
2. Receiver may receive frames out of sequence
ALGORITHM:
1. The source node transmits the frames continuously.
2. Each frame in the buffer has a sequence number starting from 1 and
increasing up to the window size.
3. The source node has a window i.e. a buffer to store the frames. This buffer
size is the number of frames to be transmitted continuously.
4. The receiver has a buffer to store the received frames. The size of the buffer
depends upon the window size defined by the protocol designer.
5. The size of the window depends according to the protocol designer.
6. The source node transmits frames continuously till the window size is
exhausted. If any of the frames are received with error only those frames are
requested for retransmission (with a negative acknowledgement)
7. If all the frames are received without error, a cumulative positive
acknowledgement is sent.
8. If there is an error in frame 3, an acknowledgement for the frame 2 is sent
and then only Frame 3 is retransmitted. Now the window slides to get the next
frames to the window.
9. If acknowledgment is transmitted with error, all the frames of window are
retransmitted. Else ordinary window sliding takes place. (* In implementation
part, Acknowledgment error is not considered)
10. If all the frames transmitted are errorless the next transmission is carried
out for the new window.
11. This concept of repeating the transmission for the error frames only is
called Selective Repeat transmission flow control protocol.
PROGRAM:
RESULT: