Computer Networks Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 88

UNIVERSITY COLLEGE OF ENGINEERING - PATTUKKOTTAI

(Constituent college of Anna University: Chennai-25)

RAJAMADAM - 614701

RECORD NOTE BOOK


UNIVERSITY COLLEGE OF ENGINEERING

PATTUKKOTTAI

RAJAMADAM - 614701

ANNA UNIVERSITY:: CHENNAI 600025

RECORD NOTE BOOK

NAME :

REGISTER NUMBER :

SUBJECT CODE & SUBJECT NAME :

SEMESTER :

BRANCH :

ACADEMIC YEAR :
BONAFIDE CERTIFICATE

REGISTER NO:

Certified to be the bonafide record of work done by


Mr./Ms.__________________________________________________ of Semester
B.E/B.Tech________________________________________________ degree course
for_______________________________________________________ Laboratory in University
College of Engineering, Pattukkottai, Rajamadam during the academic year ________________.

Staff Incharge Head of the Department

Submitted for the University Practical Examination held on __________________ at University


college of Engineering, Pattukkottai, Rajamadam.

INTERNAL EXAMINER EXTERNAL EXAMINER


LIST OF EXPERIMENTS

EX.NO DATE Experiment Page Signature

Learn to use commands like tcpdump, netstat, ipconfig,


1 nslookup and traceroute. Capture ping and traceroute
PDUs using a network protocol analyzer and examine

2 Write a http web client program to download a web page


using tcp sockets

3.a Application using tcp socket for echo client and echo
server.
3.b Application using tcp socket for chat

3.c Application using tcp socket for file transfer

4 Simulation of dns using udp sockets

5 Write a code simulating ARP /RARP protocols


Study of network simulator (ns) and simulation of
6
congestion control algorithms using ns

7 TCP/UDP performance using Simulation tool

8.a Simulation of Distance Vector Routing Algorithm

8.b Simulation of Link State Routing Algorithm

9 Implementation of stop and wait protocol

10 Implementation of subnetting

11 Simulation of error correction code

12 Study of performance evaluation in routing protocols


Ex. No.1 Learn to use commands like tcpdump, netstat, ipconfig, nslookup and traceroute.
Pg.no:
Capture ping and traceroute PDUs using a network protocol analyzer and examine
Date:

1.a) Networking Commands


AIM:
Learn the basic networking commands.

COMMANDS:

C:\>arp –a

ARP is short form of address resolution protocol, It will show the IP address of your
computer along with the IP address and MAC address of your router.

C:\>hostname

This is the simplest of all TCP/IP commands. It simply displays the name of your
computer.

C:\>ipconfig

The ipconfig command displays information about the host (the computer your
sitting at) computer TCP/IP configuration.

C:\>ipconfig /all

This command displays detailed configuration information about your TCP/IP


connection including Router, Gateway, DNS, DHCP, and type of Ethernet
adapter in your system.

C:\>netstat

Netstat displays a variety of statistics about a computers active TCP/IP


connections. This tool is most useful when you’re having trouble with TCP/IP
applications such as HTTP, and FTP.

C:\>nslookup

Nslookup is used for diagnosing DNS problems. If you can access a resource by
specifying an IP address but not it’s DNS you have a DNS problem.
C:\>pathping

Pathping is unique to Window’s, and is basically a combination of the Ping and


Tracert commands. Pathping traces the route to the destination address then launches a
25 second test of each router along the way, gathering statistics on the rate of data loss
along each hop.
C:\>ping

Ping is the most basic TCP/IP command, and it’s main purpose is to place a phone call
or communicate to another computer on the network, and request an answer. Ping has 2
options it can use to place a phone call to another computer on the network. It can use
the computers name or IP address.

C:\>route

The route command displays the computers routing table. A typical computer,
with a single network interface, connected to a LAN, with a router is fairly
simple and generally doesn’t pose any network problems. But if you’re having
trouble accessing other computers on your network, you can use the route
command to make sure the entries in the routing table are correct.

C:\>tracert

The tracert command displays a list of all the routers that a packet has to go through
to get from the computer where tracert is run to any other computer on the internet.

C:\>tcpdump

The tcpdump is a common packet analyzer that runs under the command line. It allows
the user to display TCP/IP and other packets being transmitted or received over a
network to which the computer is attached.
OUTPUT:
RESULT:
Thus, the above list of primitives has been studied.
1.b) Capture ping and traceroute PDU’s using a network

protocol analyser and examine.


AIM:
Capture the ping and tracert PDU’s and examine.
ALGORITHM:
1. Start the program
2. Create process p.
3. Using Runtime.getRuntiume() command get IP address from local Network.
4. Run and execute the program.
5. Stop.
PROGRAM:
import java.io.*;
import java.net.*;
import java.util.*;
public class Ping_Tracert
{
public static void main(String[] args)
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the IP address : ");
String ipaddr = br.readLine();
Process p = Runtime.getRuntime().exec("Tracert "+ipaddr);
Scanner scan = new Scanner(p.getInputStream());
while(scan.hasNextLine())
{
System.out.println("Tracert :: "+scan.nextLine());
}
System.out.println("____________________________________");
Process p1 = Runtime.getRuntime().exec("ping -n 1 "+ipaddr);
Scanner scan1 = new Scanner(p1.getInputStream());
while(scan1.hasNextLine())
{
System.out.println("Ping :: "+scan1.nextLine());
}
}catch(Exception ex){ System.out.println("Error "+ex);}
}
}
Output:
Result:
Thus, the Ping and Tracert concepts are simulated and studied.
Ex. No:2
Write a HTTP web client program to download a web page using TCP sockets Pg.no:
Date:

AIM:
Writes the java program to download a webpage
ALGORITHM:
CLIENT SIDE:
1) Start the program.
2) Create a socket which binds the Ip address of server and the port address to acquire
service.
3) After establishing connection send the url to server.
4) Open a file and store the received data into the file.
5) Close the socket.
6) End the program.
SERVER SIDE:
1) Start the program.
2) Create a server socket to activate the port address.
3) Create a socket for the server socket which accepts the connection.
4) After establishing connection receive url from client.
5) Download the content of the url received and send the data to client.
6) Close the socket.
7) End the program.
CLIENT PROGRAM:
import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class WebClient{
public static void main(String args[]) throws Exception{
Socket soc;
BufferedImage img = null;
soc=new Socket("localhost",4000);
System.out.println("Client is running. ");
try {
System.out.println("Reading image from disk. ");
img = ImageIO.read(new File("pic1.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
System.out.println("Image sent to server. ");
dos.close();
out.close();
}catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}}
SERVER PROGRAM:
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class WebServer {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept();
System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
dis.close(); in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l); f.pack();
f.setVisible(true); }}
OUTPUT:
RESULT:

The webpage is successfully downloaded and the contents are displayed and verified.
Ex. No:3.a
APPLICATION USING TCP SOCKET FOR ECHO CLIENT AND ECHO SERVER. Pg.no:
Date:

AIM:
write a java program application using TCP socket for echo client and echo server.
ALGORITHM:
1. Start the program.
2. Import all necessary packages.
3. Create two new application client and server.
4. Connect both applications.
5. Send the input data into client through server.
6. Get the input in client.
PROGRAM:
ECHO SERVER
import java.io.*;
import java.net.*;

public class EchoServer


{
public static void main(String[] args) throws IOException
{
String serverHostname = new String ("127.0.0.1");
if (args.length > 0)
serverHostname = args[0];
System.out.println ("Attemping to connect to host " +
serverHostname + " on port 10007.");
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket(serverHostname, 10007);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
}
catch (UnknownHostException e) {
System.err.println("Don't know about host: " + serverHostname);
System.exit(1);
}
catch (IOException e) {
System.err.println("Couldn't get I/O for "+ "the connection to: " + serverHostname);
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
System.out.print ("input: ");
while ((userInput = stdIn.readLine()) != null)
{
out.println(userInput);
System.out.println("echo: " + in.readLine());
System.out.print ("input: ");
}
out.close();
in.close();
stdIn.close();
echoSocket.close(); }}
ECHO CLIENT
import java.net.*;
import java.io.*;

public class EchoClient


{
public static void main(String[] args) throws IOException
{
ServerSocket serverSocket = null;

try {
serverSocket = new ServerSocket(10007);
}
catch (IOException e)
{
System.err.println("Could not listen on port: 10007.");
System.exit(1);
}
Socket clientSocket = null;
System.out.println ("Waiting for connection.....");
try {
clientSocket = serverSocket.accept();
}
catch (IOException e)
{
System.err.println("Accept failed.");
System.exit(1);
}
System.out.println ("Connection successful");
System.out.println ("Waiting for input.....");
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader( clientSocket.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println ("Server: " + inputLine);
out.println(inputLine);
if (inputLine.equals("Bye."))
break;
}
out.close();
in.close();
clientSocket.close();
serverSocket.close();
}
}
OUTPUT:
ECHO SERVER:

ECHO CLIENT:
RESULT:

Thus, the application using TCP socket for echo client and echo server program
was written and the output was verified successfully.
Ex. No:3.b
APPLICATION USING TCP SOCKET FOR CHAT Pg.no:
Date:

AIM:
write a java program application using TCP socket for Chat between Server and Client.

Algorithm:

TCP Server

1. Create a socket

2. Bind it to the operating system.

3. Listen over it.

4. Accept connections.

5. Receive data from client and send it back to client.

6. Close the socket.

TCP Client

1.Create a socket.

2.connect to the server using connect().

3.send data to server and receive data from the server.

4.Close the socket.


PROGRAM:
Chat server:
import java.io.*;
import java.net.*;
public class ChatServer
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready for chatting");
Socket sock = sersock.accept( );
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
String receiveMessage, sendMessage;
while(true)
{
if((receiveMessage = receiveRead.readLine()) != null)
{
System.out.println(receiveMessage);
}
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush();
}
}
}
Chat client:

import java.io.*;
import java.net.*;
public class ChatClient
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Start the chitchat, type and press Enter key");
String receiveMessage, sendMessage;
while(true)
{
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush();
if((receiveMessage = receiveRead.readLine()) != null)
{
System.out.println(receiveMessage);
}
}
}
}
OUTPUT:
Server:

Client:
Result:
Thus, the application using TCP socket for Chat client and server program was
written and the output was verified successfully.
Ex. No:3.c
APPLICATION USING TCP SOCKET FOR FILE TRANSFER Pg.no:
Date:

AIM:

Create a Java program application using TCP socket for File Transfer client and server.

ALGORITHM:

1. Start the program.


2. Import all necessary packages.
3. Create two new application client and server.
4. Connect both applications.
5. Send the File to client through server.
6. Get the File in client.
PROGRAM:
File transfer server:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class FileTransferServer
{
public static void main(String[] args) throws Exception
{
ServerSocket ssock = new ServerSocket(5000);
Socket socket = ssock.accept();
InetAddress IA = InetAddress.getByName("localhost");
File file = new File("e:\\data1.bin");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
OutputStream os = socket.getOutputStream();
byte[] contents;
long fileLength = file.length();
long current = 0;
long start = System.nanoTime();
while(current!=fileLength)
{
int size = 10000;
if(fileLength - current >= size)
current += size;
else{
size = (int)(fileLength - current);
current = fileLength;
}
contents = new byte[size];
bis.read(contents, 0, size);
os.write(contents);
System.out.print("Sending file ... "+(current*100)/fileLength+"% complete!"); }
os.flush();
socket.close();
ssock.close();
System.out.println("File sent succesfully!");
}}
File transfer client:

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
public class FileTransferClient {
public static void main(String[] args) throws Exception{
Socket socket = new Socket(InetAddress.getByName("localhost"), 5000);
byte[] contents = new byte[10000];
FileOutputStream fos = new FileOutputStream("e:\\data2.bin");
BufferedOutputStream bos = new BufferedOutputStream(fos);
InputStream is = socket.getInputStream();
int bytesRead = 0;
while((bytesRead=is.read(contents))!=-1)
bos.write(contents, 0, bytesRead);
bos.flush();
socket.close();
System.out.println("File saved successfully!");
}
}
Output:
File transfer server:

File transfer client:


Result:
Thus, the application using TCP socket for File Transfer client and server program was
written and the output was verified successfully.
Ex. No:4
SIMULATION OF DNS USING UDP SOCKETS Pg.no:
Date:

Aim:
Create a java program for DNS application by using udp sockets.
Algorithm:
1.Start the program.
2.Get the frame size from the user
3.To create the frame based on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it will send
NACK signal to client.
6.Stop the program
Program:
Udp dns server:
import java.io.*;
import java.net.*;
public class Udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str)) return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");
while (true)
{
DatagramSocket serversocket=new DatagramSocket(1362); byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new DatagramPacket(receivedata, receivedata.length);
serversocket.receive(recvpack);
String sen = new String(recvpack.getData()); InetAddress ipaddress = recvpack.getAddress(); int
port = recvpack.getPort();
String capsent;
System.out.println("Request for host " + sen);
if(indexOf (hosts, sen) != -1) capsent = ip[indexOf (hosts, sen)]; else capsent = "Host Not
Found"; senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}}}
Udp dns client:

import java.io.*;
import java.net.*;
public class Udpdnsclient
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
byte[] senddata = new byte[1024];
byte[] receivedata = new byte[1024];
int portaddr = 1362;
System.out.print("Enter the hostname : ");
String sentence = br.readLine();
senddata = sentence.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,senddata.length, ipaddress,portaddr);
clientsocket.send(pack);
DatagramPacket recvpack =new DatagramPacket(receivedata,receivedata.length);
clientsocket.receive(recvpack);
String modified = new String(recvpack.getData()); System.out.println("IP Address: " +
modified);
}
}
Output:
Dns server:

dns client:
Result:
Thus, the program for simulation of udp socket was written and the output
was verified successfully.
Ex. No:5
Write a code simulating ARP /RARP protocols Pg.no:
Date:

5.a) ARP Client/Server


Aim:
know the physical address of a host when its logical address is known
using ARP protocol.
Algorithm:
Target/Server
1. Create a server socket.
2. Accept client connection.
3. Read IP address from the client request
4. Check its configuration file and compare with its logical address.
5. If there is a match, send the host physical address.
6. Stop
Client
1. Create a socket.
2. Send IP address to the target machine
3. Receive target's response
4. If it is a MAC address then display it and go to step 6
5. Display "Host not found"
6. Stop
5.b) RARP Client/Server
Aim:
To know the logical address of a host when its physical address is
known using RARP protocol.
Algorithm:
Target/Server
1. Create a server socket.
2. Accept client connection.
3. Read MAC address from the client request
4. Check its configuration file and compare with its physical address.
5. If there is a match, send the host logical address.
6. Stop
Client
1. Create a socket.
2. Send physical address to the target machine
3. Receive target's response
4. If it is a IP address then display it and go to step 6
5. Display "Host not found"
6. Stop
PROGRAM:
import java.io.*;
import java.net.*;
import java.util.*;
public class ARP_MAC{
public static void main(String[] args){
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter the IP address : ");
String ipaddr = br.readLine();
Process p = Runtime.getRuntime().exec("arp -a "+ipaddr);
Scanner scan = new Scanner(p.getInputStream());
System.out.println("\nSimulation of Address Resolution Protocol (ARP)");
System.out.println("_____________________________________________");
while(scan.hasNextLine())
{
System.out.println("\n"+scan.nextLine());
}
System.out.println("\nSimulation of Reverse Address Resolution Protocol (RARP)");
System.out.println("_____________________________________________");
Process p1 = Runtime.getRuntime().exec("getmac -s localhost");
Scanner scan1 = new Scanner(p1.getInputStream());
while(scan1.hasNextLine())
{
System.out.println("\n"+scan1.nextLine());
}
System.out.println("_______________________________");
}catch(Exception ex){ System.out.println("Error "+ex);}
}
}
Output:
RESULT:

Thus, the implementation of ARP and RARP is done & executed successfully.
Ex. No:6
Study of Network simulator (NS) and Simulation of Pg.no:
Congestion Control Algorithms using NS
Date:

Aim:

To Study of Network simulator (NS).and Simulation of Congestion Control Algorithms using NS

NETWORK SIMULATOR
overview

➢ Ns programming: A Quick start

➢ Case study I: A simple Wireless network

➢ Case study II: Create a new agent in Ns

Ns overview

➢ Ns Status

➢ Periodical release ( )

➢ Platform support

➢ FreeBSD, Linux, Solaris, Windows and Mac

Ns functionalities

Routing, Transportation, Traffic sources, Queuing disciplines, QoS

Wireless

Most of the commercial simulators are GUI driven, while some network simulators are CLI
driven. The network model / configuration describes the state of the network (nodes,routers,
switches, links) and the events (data transmissions, packet error etc.). An important output of
simulations are the trace files. Trace files log every packet, every event that occurred in the
simulation and are used for analysis. Network simulators can also provide other tools to
facilitate visual analysis of trends and potential trouble spots.

Most network simulators use discrete event simulation, in which a list of pending "events" is
stored, and those events are processed in order, with some events triggering future events—
such as the event of the arrival of a packet at one node triggering the event of the arrival of that
packet at a downstream node.

Simulation of networks is a very complex task. For example, if congestion is high, then
estimation of the average occupancy is challenging because of high variance. To estimate the
likelihood of a buffer overflow in a network, the time required for an accurate answer can be
extremely large. Specialized techniques such as "control variates" and "importance sampling"
have been developed to speed simulation.

Examples of network simulators

There are many both free/open-source and proprietary network simulators. Examples of
notable network simulation software are, ordered after how often they are mentioned in
research papers:

1. ns (open source)
2. OPNET (proprietary software)
3. NetSim (proprietary software)
4. Packet Tracer (open source)

Uses of network simulators

Network simulators serve a variety of needs. Compared to the cost and time involved in setting
up an entire test bed containing multiple networked computers, routers and data links, network
simulators are relatively fast and inexpensive. They allow engineers, researchers to test
scenarios that might be particularly difficult or expensive to emulate using real hardware - for
instance, simulating a scenario with several nodes or experimenting with a new protocol in the
network. Network simulators are particularly useful in allowing researchers to test new
networking protocols or changes to existing protocols in a controlled and reproducible
environment. A typical network simulator encompasses a wide range of networking
technologies and can help the users to build complex networks from basic building blocks such
as a variety of nodes and links. With the help of simulators, one can design hierarchical
networks using various types of nodes like computers, hubs, bridges, routers, switches, links,
mobile units etc.

Various types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local
Area Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a
typical simulator and the user can test, analyze various standard results apart from devising
some novel protocol or strategy for routing etc. Network simulators are also widely used to
simulate battlefield networks in Network-centric warfare

There are a wide variety of network simulators, ranging from the very simple to the very
complex. Minimally, a network simulator must enable a user to represent a network topology,
specifying the nodes on the network, the links between those nodes and the traffic between the
nodes. More complicated systems may allow the user to specify everything about the protocols
used to handle traffic in a network. Graphical applications allow users to easily visualize the
workings of their simulated environment. Text-based applications may provide a less intuitive
interface, but may permit more advanced forms of customization.

Packet loss
occurs when one or more packets of data travelling across a computer network fail to reach
their destination. Packet loss is distinguished as one of the three main error types encountered
in digital communications; the other two being bit error and spurious packets caused due to
noise.
Packets can be lost in a network because they may be dropped when a queue in the network
node overflows. The amount of packet loss during the steady state is another important property
of a congestion control scheme. The larger the value of packet loss, the more difficult it is for
transport layer protocols to maintain high bandwidths, the sensitivity to loss of individual
packets, as well as to frequency and patterns of loss among longer packet sequences is strongly
dependent on the application itself.
Throughput
This is the main performance measure characteristic, and most widely used. In
communication networks, such as Ethernet or packet radio, throughput or network throughput
is the average rate of successful message delivery over a communication channel. The
throughput is usually measured in bits per second (bit/s or bps), and sometimes in data
packets per second or data packets per time slot This measure how soon the receiver is able to
get a certain amount of data send by the sender. It is determined as the ratio of the total data
received to the end to end delay. Throughput is an important factor which directly impacts
the network performance
Delay
Delay is the time elapsed while a packet travels from one point e.g., source premise or network
ingress to destination premise or network degrees. The larger the value of delay, the more
difficult it is for transport layer protocols to maintain high bandwidths. We will calculate end
to end delay
Queue Length
A queuing system in networks can be described as packets arriving for service, waiting for
service if it is not immediate, and if having waited for service, leaving the system after being
served. Thus, queue length is very important characteristic to determine that how well the
active queue management of the congestion control algorithm has been working.
RESULT:
Network simulator (NS).and Simulation of Congestion Control Algorithms using NS
has been studied successfully.
Ex. No:7
TCP/UDP performance using Simulation tool Pg.no:
Date:

AIM:
Simulate the TCP and UDP performance using Simulation tool.
Procedure:
1.devolop a topology shown in below.
2.configure all end devices.
3. Generate the Network Traffic.
Topology:

Step1:
Generate traffic to populate Address Resolution Protocol(ARP) tables.
➢ Click Multi-Server and click the Desktop tab>Command Prompt.
➢ Enter the ping 192.168.1.255 command.
➢ This will take a few seconds as every device on the network responds to MultiServer.
➢ Close the MultiServer window.
Step2:
Generate web(HTTP) traffic.
➢ Switch to Simulation mode.
➢ Click HTTP Client and click the Desktop tab>Web Browser.
➢ In the URL field, enter 192.168.1.254 and click Go.
➢ Envelopes(PDUs) will appear in the simulation window.
➢ Minimize, but do not close, the HTTP Client configuration window.
Step3:
Generate FTP traffic.
➢ Click FTP Client and click the Desktop tab>Command Prompt.
➢ Enter the ftp 192.168.1.254 command.
➢ PDUs will appear in the simulation window.
➢ Minimize, but do not close, the FTP Client configuration window.

Step4:
Generate DNS traffic.
➢ Click DNS Client and click the Desktop tab>Command Prompt.
➢ Enter the nslookup multiserver.pt.ptu command.
➢ A PDU will appear in the simulation window.
➢ Minimize, but do not close, the DNS Client configuration window.

Step5:
Generate Email traffic.
➢ Click E-Mail Client and click the Desktop tab>Email tool.
➢ Click Compose and enter the following information:
➢ To: [email protected]
➢ Subject: Personalize the subject line
➢ E-Mail Body: Personalize the Email
➢ Click Send.
➢ Minimize, but do not close, the E-Mail Client configuration window.

Step6:
Verify that the traffic is generated and ready for simulation.
Every client computer should have PDUs listed in the Simulation Panel.
OUTPUT:

Simulation of both tcp and udp:

TCp:
UDP:
Result:
TCP/UDP performance has been studied successfully by using simulation tool.
Ex. No:8.a
Simulation of Distance Vector Routing Algorithm Pg.no:
Date:

Aim:
Configure a Network using Distance vector routing protocol.
Procedure:
➢ Develop a topology shown in below.
➢ Configure all routers.
➢ Implement RIP protocols in all router to configure network.

TOPOLOGY:

RouteR 1 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 10.1.1.1 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

Router(config-if)#exit
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 13.1.1.1 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route

Gateway of last resort is not set

C 10.0.0.0/8 is directly connected, FastEthernet1/0


C 13.0.0.0/8 is directly connected, FastEthernet0/0

Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 10.0.0.0
Router(config-router)#network 13.0.0.0
Router(config-router)#

RouteR 2 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 11.1.1.1 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 10.1.1.2 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Router(config-if)#sh ip route
^
% Invalid input detected at '^' marker.
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route

Gateway of last resort is not set

C 10.0.0.0/8 is directly connected, FastEthernet1/0


C 11.0.0.0/8 is directly connected, FastEthernet0/0

Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 10.0.0.0
Router(config-router)#network 11.0.0.0
Router(config-router)#

RouteR 3 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 11.1.1.2 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route

Gateway of last resort is not set

C 11.0.0.0/8 is directly connected, FastEthernet0/0


C 12.0.0.0/8 is directly connected, FastEthernet1/0

Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 11.0.0.0
Router(config-router)#network 12.0.0.0
Router(config-router)#
Router 4 configuration…
Router>
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#no ip address
Router(config-if)#ip address 13.1.1.2 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 12.1.1.2 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route

Gateway of last resort is not set

C 12.0.0.0/8 is directly connected, FastEthernet1/0


C 13.0.0.0/8 is directly connected, FastEthernet0/0

Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 12.0.0.0
Router(config-router)#network 13.0.0.0
Router(config-router)#
Rip protocols in routers:
Router 1:

Router>enable
Router#sh ip route rip
R 11.0.0.0/8 [120/1] via 10.1.1.2, 00:00:16, FastEthernet1/0
R 12.0.0.0/8 [120/1] via 13.1.1.2, 00:00:28, FastEthernet0/0

Router#
Router 2:

Router>enable
Router#sh ip route rip
R 12.0.0.0/8 [120/1] via 11.1.1.2, 00:00:08, FastEthernet0/0
R 13.0.0.0/8 [120/1] via 10.1.1.1, 00:00:15, FastEthernet1/0

Router#
Router 3:
Router>enable
Router#sh ip route rip
R 10.0.0.0/8 [120/1] via 11.1.1.1, 00:00:14, FastEthernet0/0
R 13.0.0.0/8 [120/1] via 12.1.1.2, 00:00:19, FastEthernet1/0

Router#
Router 4:
Router>enable
Router#sh ip route rip
R 10.0.0.0/8 [120/1] via 13.1.1.1, 00:00:22, FastEthernet0/0
R 11.0.0.0/8 [120/1] via 12.1.1.1, 00:00:16, FastEthernet1/0

Router#
Simulation of rip protocol:

Rip protocol-connected networks:


Result:
The Distance Vector Routing Algorithm has simulated successfully.
Ex. No:8.b
Simulation of Link State Routing Algorithm Pg.no:
Date:

Aim:
configure network using Link State routing protocol.
Procedure:
➢ Develop a Topology shown in figure given below.
➢ Configure all the workstation.
➢ Configure all switches.
➢ Configure all routers
➢ Implement OSPF protocols in router to configure network.

RouteR 1 configuRation…

Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 14.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 15.1.1.1 255.0.0.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 40
Router(config-router)#network 14.0.0.0 255.0.0.0 area 0
Router(config-router)#network 15.0.0.0 255.0.0.0 area 0
Router(config-router)#end
Router#

RouteR 2 configuRation…

Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial2/0
Router(config-if)#ip address 11.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to down
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to administratively down
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#no ip address
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial3/0, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 20
Router(config-router)#network 11.0.0.0 255.0.0.0 area 0
Router(config-router)#network 12.0.0.0 255.0.0.0 area 0

RouteR 3 configuRation…

Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial2/0
Router(config-if)#ip address 11.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to down
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to administratively down
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#no ip address
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial3/0, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 20
Router(config-router)#network 11.0.0.0 255.0.0.0 area 0
Router(config-router)#network 12.0.0.0 255.0.0.0 area 0

RouteR 4 configuRation…

Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial2/0
Router(config-if)#ip address 12.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#ip address 13.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial3/0, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#c
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
% Ambiguous command: "c"
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 30
Router(config-router)#network 12.0.0.0 255.0.0.0 area 0
Router(config-router)#network 13.0.0.0 255.0.0.0 area 0

RouteR 5 configuRation…

Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 15.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial0/0/0
Router(config-if)#ip address 13.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial0/0/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial0/0/1
Router(config-if)#ip address 17.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial0/0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet0/1
Router(config-if)#ip address 18.1.1.1 255.0.0.0
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0/1, changed state to up
no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 60
Router(config-router)#network 13.0.0.0 255.0.0.0 area 0
Router(config-router)#network 15.0.0.0 255.0.0.0 area 0
Router(config-router)#network 17.0.0.0 255.0.0.0 area 0
Router(config-router)#network 18.0.0.0 255.0.0.0 area 0

RouteR 6 configuRation…

Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 10.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet0/1
Router(config-if)#ip address 14.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
Router(config-if)#exit
Router(config)#interface Serial0/0/0
Router(config-if)#ip address 11.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial0/0/0, changed state to down
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial0/0/1
Router(config-if)#ip address 16.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial0/0/1, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 10
Router(config-router)#network 10.0.0.0 255.0.0.0 area 0
Router(config-router)#network 11.0.0.0 255.0.network 10.0.0.0 255.0.0.0 area 0network 14.0.0.0
255.0.0.0 area 0
Router(config-router)#network 16.0.0.0 255.0.0.0 area 0
Router(config-router)#end
Link state protocol- connected networks

Simulation of ospf:
Result:

The Link State Routing Algorithm has simulated successfully.


Ex. No:9
Implementation of stop and wait protocol Pg.no:
Date:

Aim:

write a java program to perform Stop and Wait protocol.

Algorithm:

Step1: Start the program.


Step2: Create the socket by specifying the address and establishes the connection
Step3: Send and receive information.
Step4: The sender sends one frame, stops until it receives confirmation from the receiver and
then sends the next frame.
Step5: If your frames reach the server it will send ACK signal to client otherwise it will send
NACK signal to client.
Step6: Stop the program
Program:
Sender:
import java.io.*;
import java.net.*;
import java.util.*;
public class receiver {
public static void main(String args[])
{
String h="Serverhost";
int q=5000;
int i;
try
{
ServerSocket ss2;
ss2 = new ServerSocket(8000);
Socket s1 =ss2.accept();
DataInputStream dd1= new DataInputStream(s1.getInputStream());
Integer i1 =dd1.read();
for(i=0;i<i1;i++)
{
ServerSocket ss1;
ss1 = new ServerSocket(9000+i);
Socket s =ss1.accept();
DataInputStream dd= new DataInputStream(s.getInputStream());
String sss1 = dd.readUTF();
System.out.println(sss1);
System.out.println("Frame "+ i+" received");
DataOutputStream d1 = new DataOutputStream(s.getOutputStream());
d1.write(i);
System.out.println("ACK sent for "+ i);
}
}
catch(Exception ex)
{
System.out.println("Error"+ex);
}
}
}
Client:
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class sender {
public static void main(String args[])
{
int p=9000,i,q=8000;
String h="localhost";
try
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of frames : ");
int number = scanner.nextInt();
if(number==0)
{
System.out.println("No frame is sent");
}
else
{
Socket s2;
s2= new Socket(h,q);
DataOutputStream d1 = new DataOutputStream(s2.getOutputStream());
d1.write(number);
}
String str1;
for (i=0;i<number;i++)
{
System.out.print("Enter message : ");
String name = scanner.next();
System.out.println("Frame " + i+" is sent");
Socket s1;
s1= new Socket(h,p+i);
DataOutputStream d = new DataOutputStream(s1.getOutputStream());
d.writeUTF(name);
DataInputStream dd= new DataInputStream(s1.getInputStream());
Integer sss1 = dd.read();
System.out.println("Ack for :" + sss1 + " is received");
}
}
catch(Exception ex)
{
System.out.println("ERROR :"+ex);
}
}
}
Output:
sender:

receiver:
Result:
The stop and wait protocol program has been executed and output verified successfully.
Ex. No:10
Implementation of subnetting Pg.no:
Date:

Aim:
find Subnet Mask and Network ID for given IP Address.

Algorithm:

Step1: Get the input from the user by using scanner method.
Step 2: Read the input by using nextLine() and store it.
Step 3: Split the string based on string by using split(“\\”)
Step4 : Convert it into binary.
Step 5: calculating the network mask by using math and logarithmic
Step 6: get the first address by ANDing the last n bits with 0.
Step7 : get the last address by ORing the last n bits with 1.
Program:
import java.util.Scanner;
class subnet{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("Ip address: ");
String ip = sc.nextLine();
String split_ip[] = ip.split("\\."); //SPlit the string after every .
String split_bip[] = new String[4]; //split binary ip
String bip = "";
for(int i=0;i<4;i++){
split_bip[i] = appendZeros(Integer.toBinaryString(Integer.parseInt(split_ip[i])));
bip += split_bip[i];
}
System.out.println("Binary Format "+bip);
System.out.print("Enter the number of addresses in each subnet: ");
int n = sc.nextInt();
int bits = (int)Math.ceil(Math.log(n)/Math.log(2));
int mask = 32-bits;
System.out.println("Subnet mask = "+mask);
int fbip[] = new int[32];
for(int i=0; i<32;i++) fbip[i] = (int)bip.charAt(i)-48; //convert cahracter 0,1 to integer 0,1
for(int i=31;i>31-bits;i--)//Get first address by ANDing last n bits with 0
fbip[i] &= 0;
String fip[] = {"","","",""};
for(int i=0;i<32;i++)
fip[i/8] = new String(fip[i/8]+fbip[i]);
System.out.print("Network address is = ");
for(int i=0;i<4;i++){
System.out.print(Integer.parseInt(fip[i],2));
if(i!=3) System.out.print(".");
}
System.out.println();
int lbip[] = new int[32];
for(int i=0; i<32;i++) lbip[i] = (int)bip.charAt(i)-48; //convert cahracter 0,1 to integer 0,1
for(int i=31;i>31-bits;i--)//Get last address by ORing last n bits with 1
lbip[i] |= 1;
String lip[] = {"","","",""};
for(int i=0;i<32;i++)
lip[i/8] = new String(lip[i/8]+lbip[i]);
System.out.print("Broadcast address is = ");
for(int i=0;i<4;i++){
System.out.print(Integer.parseInt(lip[i],2));
if(i!=3) System.out.print(".");
}
System.out.println();
}
static String appendZeros(String s){
String temp = new String("00000000");
return temp.substring(s.length())+ s;
}
}
OUTPUT:
Result:
The program for subnetting has been executed successfully.
Ex. No:11
Simulation of error correction code Pg.no:
Date:

AIM:
Implement the hamming code using java programming language for error correction.

Algorithm:
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in
binary form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in
the least significant position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in
the second position from the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in
the third position from the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in
the fourth position from the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general each parity bit covers all bits where the bitwise AND of the parity
position and the bit position is non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.
Program:
import java.util.*;
public class HammingCode {
static void print(int ar[])
{
for (int i = 1; i < ar.length; i++) {
System.out.print(ar[i]);
}
System.out.println();
}
static int[] calculation(int[] ar, int r)
{
for (int i = 0; i < r; i++) {
int x = (int)Math.pow(2, i);
for (int j = 1; j < ar.length; j++) {
if (((j >> i) & 1) == 1) {
if (x != j)
ar[x] = ar[x] ^ ar[j];
}
}
System.out.println("r" + x + " = "+ ar[x]);
}
return ar;
}
static int[] generateCode(String str, int M, int r)
{
int[] ar = new int[r + M + 1];
int j = 0;
for (int i = 1; i < ar.length; i++) {
if ((Math.ceil(Math.log(i) / Math.log(2)) - Math.floor(Math.log(i) / Math.log(2)))== 0)
{
ar[i] = 0;
}
else {
ar[i] = (int)(str.charAt(j) - '0');
j++;
}
}
return ar;
}
public static void main(String[] args)
{
System.out.println("Enter the data ");
Scanner sc=newF Scanner(System.in);
String str = sc.nextLine();
int M = str.length();
int r = 1;
while (Math.pow(2, r) < (M + r + 1))
{
r++;
}
int[] ar = generateCode(str, M, r);
System.out.println("Generated hamming code ");
ar = calculation(ar, r);
print(ar);
}
}
OUTPUT:
Result:
Thus, the program for error correction has executed and output was verified.
Ex. No:12
Study of performance evaluation in routing protocols Pg.no:
Date:

Aim:
To study about the various routing protocols and evaluates their performance.
Dynamic routing protocols:
An aggregate of networks linked by routers is known as an internet. When a packet is sent
from source to destination there can be such a lot of passes through many routers until it reaches the
router attached to the destination network. Autonomous system (AS) that's a group of routers under
a common place management is also referred to as routing domains. Depending on the independent
device,
there are two sorts of routing protocols:

1. Interior Gateway Protocols (IGP):


It is likewise known as intra-AS routing as it is used for routing inside an AS. RIP, EIGRP,
OSPF, and IS-IS are a number of the examples of IGPs.
2. Exterior Gateway Protocols (EGP):
It is likewise known as inter-AS routing that is used for routing between independent
systems. The Border Gateway Protocol (BGP) is the only currently available EGP and is
used by the internet formally.
Interior Gateway Protocols (IGP) may be
Categorized in groups:
A. Distance Vector protocols
Distance vector manner that routes are advertised the usage of characteristics:
➢ Distance:
a feature which identifies how a long way it is to the destination network from the source
based totally on a metric inclusive of the hop depend, value, bandwidth, delay, and greater.
➢ Vector:

characteristic that specifies the route of the subsequent-hop router or exit interface to reach
the destination. Characteristics of Distance Vector Protocols:
➢ Collects statistics of the records of the routing desk of its neighbors.
➢ Determines the better direction, adding the metric cost that is acquired as the routing facts
happens from router to some other one.
➢ The updates for the alternate of topology consist of periodic updates of the tables.
➢ Slower convergence. RIP and EIGRP are a number of the examples of distance vector routing
protocols.

B. The Link State Routing Protocols


The Link state routing protocol creates an entire view or the topology of the community through
gathering statistics from all of the different routers and all link-state routers are the use of an
identical map of the network. The link-state information is utilized by the link - state router to
create a topology map and choose the first-class path to all destination networks inside the
topology. This protocol does not use periodic updates, but the network has converged, a link-
state update is most effective sent if there may be a change in the topology. Link-state protocols
work quality in conditions in which:
➢ The network is big and hierarchical design is needed
➢ Fast convergence of the community is essential
➢ The administrators have top understanding of how the implemented link state routing
protocol Link state threats:
➢ The link state routing obtains a great print of the topology of entire internetwork amassing
all the essential LSA.
➢ Each router independently calculates its very own shorter direction, in the direction of the
networks destiny.
➢ Updates are induced typically by using – in the topology.
➢ Faster times of convergence while there may be any exchange of the topology because of
the relatively small LSA that have long past to all of the other routers.
OSPF, IS-IS are examples of link state routing protocol.

1.routing information protocol(RIP):

The Routing Information Protocol (RIP) is one of the interarea (interior) routing protocols
used in an autonomous system. It is one of the distance vector routing protocols that is quite
simple protocol. RIP implements distance vector routing immediately with some concerns.
RIP traits:
➢ Distance Vector routing protocol.
➢ It metric is the wide variety of hops
➢ The maximum number of hops is 15
➢ One updates each 30 second.
➢ Now not always it selects the fastest path with
➢ a minimum quantity of hope
➢ It generates traffic of community with updates.
There are variations of RIP, particularly RIPv1 and RIPv2.

2.EIGRP ROUTING PROTOCOL:


Enhanced interior Routing protocol (EIGRP) incorporates features of distance vector protocols,
and link state protocols and is called a hybrid protocol. It is far a Cisco proprietary routing
protocol, making use of the Diffusing update algorithm (dual). EIGRP is IGP which uses the
idea of autonomous systems to organize routers, which carry out the identical duties. It gets
records about the routes from updates of different routers, but unlike different Distance vector
protocols it maintains a partial topology of the network. There are three tables to make routing
selections in EIGRP. Those are; The Routing table, the Neighbour table and the Topology table.
EIGRP uses bandwidth and Delay as the metrics to determine the best route from the source to
end. And it could additionally use bandwidth MTU, Reliability, load as metrics.
EIGRP traits:
➢ Superior distance vector
➢ Uses bandwidth, delay, MTU, Reliability and
➢ load as metrics.
➢ The maximum amount of hops is 255
➢ Used in massive community
➢ Quicker convergence

3.OPEN SHORTEST Path FIRST (OSPF):


Open Shortest Path First (OSPF) is one of the link state routing protocols which are
examples of interior routing protocols, operating in an autonomous system (AS). OSPF
detects link breakdowns, and converges inside the topology within seconds. And it uses
Dijkstra's set of rules, a shortest path first algorithm to compute the shortest path tree for
each way. The OSPF routing uses link state cost factors as a metric to construct a topology
table that is related to every routing interface. The distance of a router (round-trip time),
information throughput of a link, or link availability and reliability, expressed as simple
unit less numbers may be considered as cost elements. This presents traffic load balancing
between routes of equal value in a dynamic system.
There are five exceptional packet varieties of OSPF that have a unique motive in the root:
➢ Hello packet.
➢ Database description.
➢ Link state request packet.
➢ Link state update.
➢ Link state acknowledgement packet.

OSPF characteristics:

➢ OSPF constantly determines the loop free routes.


➢ Updates routinely if any adjustments occur inside the network.
➢ Low bandwidth usage.
➢ OSPF is primarily based on the cost of the interface.
➢ OSPF helps multiple routes for a single trip advertisement network.
EVALUATION OF RIP, EIGRP AND OSPF:

Contrast of protocols, features

FEATURE RIPV1 RIPV2 EIGRP OSPF

Variety Distance Distance Advance distance vector Link state


vector vector

Algorithm Bellman n- Ford Bellman n- Ford DUAL Dijkstra

Class full/classless Class full Classless Classless Classless

Delay and bandwidth


Metrics Hop count Hop count Cost

Update timer Automatic


30 30 Automatic

AD amount 120 120 Internal 110


90
External
170
Authentication No Yes MD5 MD5

Maximum Hop 15 15 255 NO

Convergence Slow Slow Very fast Fast

Update Type Full table Full table Only changes Only changes

VSLM support No Yes Yes Yes

Network size Small Small Large Very large

Split horizon No No Yes Yes

Area Type - - - 5 types


Result:
The dynamic routing protocols studied and the performance among them has been
evaluated.

You might also like