0% found this document useful (0 votes)
172 views

CS3591 Computer Networks Lab manual finalized (3)

Uploaded by

Viola Sharon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views

CS3591 Computer Networks Lab manual finalized (3)

Uploaded by

Viola Sharon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

DMI COLLEGE OF ENGINEERING

PALANCHUR CHENNAI – 600 123

DEPARTMENT OF INFORMATION TECHNOLOGY

LABORATORY MANUAL

SUB CODE : CS 3591


SUBJECT TITLE : COMPUTER NETWORKS LABARATORY

SEMESTER : V

YEAR : III
DEPARTMENT : INFORMATION TECHNOLOGY
CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

Vision of the Department

To achieve academic excellence by producing competent IT professionals


by inculcating self discipline and ethical values.
Mission of the Department
DM1: To provide quality education by maintaining high standards
DM 2: To enhance their knowledge and skills in the field of Information Technology.
DM 3: To create Professionals with personal responsibility and ethical leadership.

PROGRAM EDUCATIONAL OBJECTIVES (PEOs)

PEO I: Technical Proficiency with Employability Skills:


To offer a strong foundation in mathematical, logical and engineering core concepts
necessary to plan, analyze and solve engineering problem’s and to prepare them for
employability skills.
PEO II: Continuous Learning:
To promote students to peruse higher studies and to continue the learning process
through research and development in effective technical aspects.
PEO III: Inculcating Entrepreneurial Skills:
To prepare the students to be an active team player, possessing strong interpersonal
skills and leadership qualities with entrepreneurial ability.
PEO IV: Ethical Values:
To inculcate ethical values in students on both professional and personal practices.

DMI College Of Engineering 1


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

PROGRAM OUTCOMES (POs)

The Program Outcomes (POs) are described as.

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering

problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,

natural sciences, and engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering problems and


design system components or processes that meet the specified needs with appropriate

consideration for the public health and safety, and the cultural, societal, and environmental
considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research


methods including design of experiments, analysis and interpretation of data, and synthesis of

the information to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant

to the professional engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering


solutions in societal and environmental contexts, and demonstrate the knowledge of, and need

for sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
DMI College Of Engineering 2
CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive

clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one's own work, as a member and

leader in a team, to manage projects and in multidisciplinary environments.

12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

PROGRAM SPECIFIC OUTCOMES (PSOs):

 PSO1: Analytical Thinking: Identify, formulate and solve engineering problems by


applying mathematical foundations and algorithmic principles in IT environment to meet
challenges.
 PSOII: Principles Of Information Technology: Analyze, design and develop
Software, Multimedia, Web Applications and Networking Technologies for an efficient
design of Information based systems with high professional skills.
 PSOIII: Engineering Ethics: Understand best practices, ethical standards and replicate the
same for the industry, research and social needs.

DMI College Of Engineering 3


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

INSTRUCTIONS TO STUDENTS FOR WRITING THE RECORD

In the record, the index page should be filled properly by writing the corresponding
experiment number, experiment name , date on which it was done and the page number.

On the right side page of the record following has to be written:

1. Title: The title of the experiment should be written in the page in capital letters.
2. In the left top margin, experiment number and date should be written.
3. Aim: The purpose of the experiment should be written clearly.

4. Procedure/Algorithm: Steps for doing the experiment should be briefly


described
5. Results: The results of the experiment must be summarized in writing and should be
fulfilling the aim.
Observations:

i) Data should be clearly recorded using Tabular Columns.

DMI College Of Engineering 4


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

CS3591 COMPUTER NETWORK LABORATORY LTP C


3091

LIST OF EXPERIMENTS
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

c. File Transfer

4. Simulation of DNS using UDP sockets.

5. Write a code simulating ARP /RARP protocols.

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

7. Study of TCP/UDP performance using Simulation tool.

8. Simulation of Distance Vector/ Link State Routing algorithm.

9. Performance evaluation of Routing protocols using Simulation tool.

10. Simulation of error correction code (like CRC).

LIST OF EQUIPMENT FOR A BATCH OF 30 STUDENTS:

HARDWARE:
Standalone desktops 30 Nos

SOFTWARE:
C / C++ / Java / Python / Equivalent Compiler 30
Network simulator like NS2/Glomosim/OPNET/ Packet Tracer / Equivalent

TOTAL: 30 PERIODS

DMI College Of Engineering 5


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

Course outcomes

CO1 Implement various protocols using TCP and UDP.


CO2 Compare the performance of different transport layer protocols.

CO3 Use simulation tools to analyze the performance of various network protocols.
CO4 Analyze various routing algorithms.

CO5 Implement error correction codes.

CO, PO, PSO Mappings.

Course Program Outcomes PSO


Code and
CO
Course
name 1 2 3 4 5 6 7 8 9 1 11 12 1 2 3
0
CS3591 CO1 - 2 - - - - - - - - - - 3 - -
Computer
Networks CO2 - 1 - - 2 - - - - - - 2 - 2 -
lab
CO3 - 2 - - 3 - - - - - - - - 3 -

CO4 - - - 1 2 - - - - 3 - - - - -

CO5 - 3 2 - - - - - - - - - - - 3

Average - 1 - - 1 - - - - 1 - - - 1 1

DMI College Of Engineering 6


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 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.

AIM:
To study the basic networking commands.
NETWORKING 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:\>Ipconfig /renew: Using this command will renew all your IP addresses that
you are currently (leasing) borrowing from the DHCP server. This command is
a quick problem solver if you are having connection issues, but does not work if
you have been configured with a static IP address.
C:\>Ipconifg /release: This command allows you to drop the IP lease from the
DHCP server.
C:\>ipconfig /flushdns: This command is only needed if you’re having trouble
with your networks DNS configuration. The best time to use this command is
after network configuration frustration sets in, and you really need the computer
to reply with flushed.
C:\>nbtstat –a: This command helps solve problems with NetBIOS name
resolution. (Nbt stands for NetBIOS over TCP/IP)
C:\>netdiag: Netdiag is a network testing utility that performs a variety of
network diagnostic tests, allowing you to pinpoint problems in your network.
Netdiag isn’t installed by default, but can be installed from the Windows XP CD
after saying no to the install. Navigate to the CD ROM drive letter and open the

DMI College Of Engineering 7


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

support\tools folder on the XP CD and click the setup.exe icon in the


support\tools folder.
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 the same as placing
a phone call to your best friend. You pick up your telephone and dial a number,
expecting your best friend to reply with “Hello” on the other end. Computers
make phone calls to each other over a network by using a Ping command. The
Ping commands main purpose is to place a phone call 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.

RESULT:
Thus the above list of primitive has been studied

DMI College Of Engineering 8


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 2. WRITE A HTTP WEB CLIENT PROGRAM TO DOWNLOAD


A WEB PAGE USING TCP SOCKETS

AIM:
To Write a HTTP web client program to download a web page using TCP
sockets.
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.

DMI College Of Engineering 9


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

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 Client{
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("digital_image_processing.JPEG"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close(); System.out.println("Sending image to server. ");

DMI College Of Engineering 10


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

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 Server {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");

DMI College Of Engineering 11


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

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.

DMI College Of Engineering 12


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 3. A. SOCKET PROGRAM FOR ECHO

AIM :
To write a socket program for implementation of echo.

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 a data to server.
4. Receive and print the same data from server.
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 the data from client.
5. Print and send the same data to client.
6. Close the socket.
7. End the program.

DMI College Of Engineering 13


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

PROGRAM:

ECHO CLIENT
import java.io.*;
import java.net.*;
public class eclient {
public static void main(String args[]) {
Socket c = null;
String line;
BufferedReader userInput = null;
BufferedReader serverInput = null;
PrintWriter os = null;
try {
c = new Socket("localhost", 8080);
userInput = new BufferedReader(new InputStreamReader(System.in));
serverInput = new BufferedReader(new
InputStreamReader(c.getInputStream()));
os = new PrintWriter(c.getOutputStream(), true);
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
try {
do {
System.out.println("client");
line = userInput.readLine();
os.println(line);
if (!line.equals("exit"))

DMI College Of Engineering 14


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

System.out.println("server: " + serverInput.readLine());


} while (!line.equals("exit"));
} catch (IOException e) {
System.out.println("socket closed");
} finally {
try {
if (userInput != null) userInput.close();
if (serverInput != null) serverInput.close();
if (os != null) os.close();
if (c != null) c.close();
} catch (IOException e) {
System.out.println("Error while closing resources");
}
}
}
}

ECHO SERVER
import java.io.*;
import java.net.*;
public class eserver {
public static void main(String args[]) throws IOException {
ServerSocket serverSocket = null;
BufferedReader clientInput = null;
PrintWriter clientOutput = null;
Socket clientSocket = null;

DMI College Of Engineering 15


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

try {
serverSocket = new ServerSocket(8080);
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
try {
clientSocket = serverSocket.accept();
clientInput = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
clientOutput = new PrintWriter(clientSocket.getOutputStream(), true);
String line;
while ((line = clientInput.readLine()) != null) {
System.out.println("msg received and sent back to client");
clientOutput.println(line);
}
} catch (IOException e) {
System.out.println(e);
} finally {
try {
if (clientInput != null) clientInput.close();
if (clientOutput != null) clientOutput.close();
if (clientSocket != null) clientSocket.close();
if (serverSocket != null) serverSocket.close();
} catch (IOException e) {
System.out.println("Error while closing resources");
}
}

DMI College Of Engineering 16


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

}
}

OUTPUT:
CLIENT
Enter the IP address 127.0.0.1
CONNECTION ESTABLISHED
Enter the data CSE
Client received CSE

SERVER
CONNECTION ACCEPTED
Server received CSE

RESULT:
Thus the program for simulation of echo server was written & executed

DMI College Of Engineering 17


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 3.B. CLIENT- SERVER APPLICATION FOR CHAT

AIM :
To write a client-server application for chat using TCP

ALGORITHM:

CLIENT
1. Start the program
2. Include necessary package in java
3. To create a socket in client to server.
4. The client establishes a connection to the server.
5. The client accept the connection and to send the data from client to
server.
6. The client communicates the server to send the end of the message
7. Stop the program.

SERVER
1. Start the program
2. Include necessary package in java
3. To create a socket in server to client
4. The server establishes a connection to the client.
5. The server accept the connection and to send the data from server to
client and
6. vice versa
7. The server communicate the client to send the end of the message.
8. Stop the program.

DMI College Of Engineering 18


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

PROGRAM:
TCPclient1
import java.io.*;
import java.net.*;
public class TCPclient1 {
public static void main(String arg[]) {
Socket c = null;
String line;
BufferedReader userInput = null;
BufferedReader serverInput = null;
PrintWriter os = null;
try {
c = new Socket("localhost", 9999); // Replace "localhost" with the server
IP address if needed
userInput = new BufferedReader(new InputStreamReader(System.in));
serverInput = new BufferedReader(new
InputStreamReader(c.getInputStream()));
os = new PrintWriter(c.getOutputStream(), true);
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
try {
do {
System.out.println("Client:");
line = userInput.readLine();

DMI College Of Engineering 19


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

os.println(line);
System.out.println("Server: " + serverInput.readLine());
} while (!line.equalsIgnoreCase("quit"));
} catch (IOException e) {
System.out.println("Socket Closed! Message Passing is over");
} finally {
try {
if (userInput != null) userInput.close();
if (serverInput != null) serverInput.close();
if (os != null) os.close();
if (c != null) c.close();
} catch (IOException e) {
System.out.println("Error while closing resources");
}
}
}
}

TCPserver1
import java.io.*;
import java.net.*;
public class TCPserver1 {
public static void main(String arg[]) {
ServerSocket serverSocket = null;
String line;
BufferedReader clientInput = null;
BufferedReader serverOperatorInput = null;

DMI College Of Engineering 20


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

PrintWriter clientOutput = null;


Socket clientSocket = null;
try {
serverSocket = new ServerSocket(9999);
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
try {
clientSocket = serverSocket.accept();
clientInput = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
serverOperatorInput = new BufferedReader(new
InputStreamReader(System.in));
clientOutput = new PrintWriter(clientSocket.getOutputStream(), true);
do {
line = clientInput.readLine();
System.out.println("Client: " + line);
System.out.println("Server:");
line = serverOperatorInput.readLine();
clientOutput.println(line);
} while (!line.equalsIgnoreCase("quit"));
} catch (IOException e) {
System.out.println(e);
} finally {
try {
if (clientInput != null) clientInput.close();
if (serverOperatorInput != null) serverOperatorInput.close();

DMI College Of Engineering 21


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

if (clientOutput != null) clientOutput.close();


if (clientSocket != null) clientSocket.close();
if (serverSocket != null) serverSocket.close();
} catch (IOException e) {
System.out.println("Error while closing resources");
}
}
}
}

OUTPUT :

SERVER
C:\Program Files\Java\jdk1.5.0\bin>javac TCPserver1.java Note:
TCPserver1.java uses or overrides a deprecated API. Note:
Recompile with -deprecation for details. C:\Program
Files\Java\jdk1.5.0\bin>java TCPserver1
Client: Hai Server
Server:Hai Client
Client: How are you
Server:Fine
Client: quit
Server:quit

CLIENT
C:\Program Files\Java\jdk1.5.0\bin>javac TCPclient1.java
Note: TCPclient1.java uses or overrides a deprecated API.

DMI College Of Engineering 22


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

Note: Recompile with -deprecation for details. C:\Program


Files\Java\jdk1.5.0\bin>java TCPclient1
Client:Hai Server
Server: Hai Client
Client:How are you
Server: Fine
Client:quit
Server: quit

RESULT:
Thus the above program a client-server application for chat using TCP / IP was
executed and successfully

DMI College Of Engineering 23


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 3.C. FILE TRANSFER IN CLIENT & SERVER

AIM:
To Perform File Transfer in Client & Server Using TCP/IP.

ALGORITHM:
CLIENT SIDE
1. Start.
2. Establish a connection between the Client and Server.
3. Socket ss=new Socket(InetAddress.getLocalHost(),1100);
4. Implement a client that can send two requests.
i) To get a file from the server.
ii) To put or send a file to the server.
5. After getting approval from the server ,the client either get file from the
server or send
6. file to the server.

SERVER SIDE
1. Start.
2. Implement a server socket that listens to a particular port number.
3. Server reads the filename and sends the data stored in the file for the‘get’
request.
4. It reads the data from the input stream and writes it to a file in theserver for
the ‘put’
instruction.
5. Exit upon client’s request.
6. Stop.

DMI College Of Engineering 24


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

PROGRAM:
CLIENT SIDE
import java.net.*;
import java.io.*;
public class FileClient {
public static void main(String[] args) throws IOException {
int filesize = 6022386; // filesize temporary hardcoded
long start = System.currentTimeMillis();
int bytesRead;
int current = 0;
// localhost for testing
Socket sock = new Socket("127.0.0.1", 13267);
System.out.println("Connecting...");
// receive file
byte[] mybytearray = new byte[filesize];
InputStream is = sock.getInputStream();
FileOutputStream fos = new FileOutputStream("source-copy.pdf");
BufferedOutputStream bos = new BufferedOutputStream(fos);
do {
bytesRead = is.read(mybytearray, current, (mybytearray.length -
current));
if (bytesRead >= 0) {
current += bytesRead;
}
} while (bytesRead > -1);
bos.write(mybytearray, 0, current);
bos.flush();

DMI College Of Engineering 25


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

long end = System.currentTimeMillis();


System.out.println("Transfer time: " + (end - start) + " milliseconds.");
bos.close();
sock.close();
}
}

SERVER SIDE
import java.net.*;
import java.io.*;
public class FileServer
{
public static void main (String [] args ) throws IOException {
ServerSocket servsock = new ServerSocket(13267); while (true)
{
System.out.println("Waiting...");
Socket sock = servsock.accept();
System.out.println("Accepted connection : " + sock);
File myFile = new File ("source.pdf");
byte [] mybytearray = new byte [(int)myFile.length()];
FileInputStream fis = new FileInputStream(myFile);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(mybytearray,0,mybytearray.length);
OutputStream os = sock.getOutputStream();
System.out.println("Sending...");
os.write(mybytearray,0,mybytearray.length);

DMI College Of Engineering 26


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

os.flush();
sock.close();
System.out.println("File Transfered Successfully");
}
}
}

OUTPUT:
SERVER OUTPUT
C:\Program Files\Java\jdk1.6.0\bin>javac FServer.java
C:\Program Files\Java\jdk1.6.0\bin>java FServer
Waiting for clients...
Connection Established
Client wants file:network.txt

CLIENT OUTPUT
C:\Program Files\Java\jdk1.6.0\bin>javac FClient.java
C:\Program Files\Java\jdk1.6.0\bin>java FClient
Connection request.....Connected
Enter the filename: network.txt
Computer networks: A computer network, often simply referred to as a network,
is a collection of computers and devices connected by communications
channels that facilitates communications among users and allows users to share
resources with other user

RESULT:
Thus the File transfer Operation is done & executed successfully.

DMI College Of Engineering 27


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 4. SIMULATION OF DNS USING UDP SOCKETS

AIM:
To write a program to Simulation of DNS 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 Client
Udpdnsclient.java
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

DMI College Of Engineering 28


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

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);
clientsocket.close();
}
}

//UDP DNS Server


Udpdnsserver.java
import java.io.*;
import java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();

DMI College Of Engineering 29


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

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);

DMI College Of Engineering 30


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

serversocket.send(pack);
serversocket.close();
}
}
}

OUTPUT :
Server
javac udpdnsserver.java
java udpdnsserver
Press Ctrl + C to Quit Request for host yahoo.com
Request for host cricinfo.com
Request for host youtube.com
Client
javac udpdnsclient.java
java udpdnsclient
Enter the hostname : yahoo.com
IP Address: 68.180.206.184
java udpdnsclient
Enter the hostname : cricinfo.com
IP Address: 80.168.92.140
java udpdnsclient
Enter the hostname : youtube.com
IP Address: Host Not Found

RESULT:
Thus the above program a client-server application for chat using UDP was
executed and successfully

DMI College Of Engineering 31


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 5.A.WRITE A CODE SIMULATING ARP PROTOCOLS

AIM
To implement Address Resolution Protocol .

ALGORITHM
CLIENT SIDE
1. Establish a connection between the Client and Server. Socket
ss=new Socket(InetAddress.getLocalHost(),1100);
2. Create instance output stream writer
PrintWriter ps=new PrintWriter(s.getOutputStream(),true);
3. Get the IP Address to resolve its physical address.
4. Send the IPAddress to its output Stream.ps.println(ip);
5. Print the Physical Address received from the server.

SERVER SIDE
1. Accept the connection request by the client.
ServerSocket ss=new ServerSocket(2000);Socket s=ss.accept();
2. Get the IPaddress from its inputstream.
BufferedReader br1=new
BufferedReader(newInputStreamReader(s.getInputStream()));
ip=br1.readLine();
3. During runtime execute the processRuntime r=Runtime.getRuntime();
Process p=r.exec("arp -a "+ip);
4. Send the Physical Address to the client.

DMI College Of Engineering 32


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

PROGRAM
ARP CLIENT
import java.io.*;
import java.net.*;
class ArpClient {
public static void main(String[] args) {
try {
Socket s = new Socket(InetAddress.getLocalHost(), 1100);
PrintStream ps = new PrintStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new
InputStreamReader(s.getInputStream()));
BufferedReader userInput = new BufferedReader(new
InputStreamReader(System.in));
String ip;
System.out.println("Enter the IP Address:");
ip = userInput.readLine();
ps.println(ip);
String str;
System.out.println("ARP From Server:");
while ((str = br.readLine()) != null && !str.equalsIgnoreCase("end")) {
System.out.println(str);
}
// Close resources
br.close();
ps.close();
s.close();
} catch (IOException e) {
System.out.println("Error: " + e);

DMI College Of Engineering 33


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

}
}
}

ARPSERVER
import java.io.*;
import java.net.*;
import java.util.*;
class ArpServer {
public static void main(String[] args) throws IOException {
try {
ServerSocket ss = new ServerSocket(1100);
Socket s = ss.accept();
PrintStream ps = new PrintStream(s.getOutputStream());
BufferedReader br1 = new BufferedReader(new
InputStreamReader(s.getInputStream()));
String ip;
ip = br1.readLine();
String arpInfo = getArpTableInfo(ip);
ps.println(arpInfo);
// Close resources
br1.close();
ps.close();
s.close();
ss.close();
} catch (IOException e) {
System.out.println("Error: " + e);
}

DMI College Of Engineering 34


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

}
private static String getArpTableInfo(String ipAddress) {
StringBuilder result = new StringBuilder();
try {
InetAddress inetAddress = InetAddress.getByName(ipAddress);
NetworkInterface networkInterface =
NetworkInterface.getByInetAddress(inetAddress);
if (networkInterface != null) {
byte[] mac = networkInterface.getHardwareAddress();
if (mac != null) {
result.append("IP Address: ").append(ipAddress).append("\n");
result.append("MAC Address: ");
for (byte b : mac) {
result.append(String.format("%02X:", b));
}
result.setLength(result.length() - 1);
} else {
result.append("No MAC address found for the provided IP
address.");
}
} else {
result.append("Invalid IP address.");
}
} catch (UnknownHostException | SocketException e) {
result.append("Error: ").append(e.getMessage());
}
return result.toString();
}}

DMI College Of Engineering 35


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

OUTPUT
C:\Networking Programs>java ArpServer
C:\Networking Programs>java ArpClient
Enter the IPADDRESS:
192.168.11.58
ARP From Server::
Interface: 192.168.11.57 on Interface 0x1000003
Internet Address Physical Address Type
192.168.11.58 00-14-85-67-11-84 dynamic

RESULT
Thus the implementation of ARP is done & executed successfully

DMI College Of Engineering 36


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 5.B. WRITE A CODE SIMULATING RARP PROTOCOLS

AIM:
To write a java program for simulating RARP protocols.

ALGORITHM:
CLIENT
1.Start the program
2. using datagram sockets UDP function is established.
2.Get the MAC address to be converted into IP address.
3.Send this MAC address to server.
4.Server returns the IP address to client.

SERVER
1. Start the program.
2. Server maintains the table in which IP and corresponding MAC addresses are
stored.
3. Read the MAC address which is send by the client.
4. Map the IP address with its MAC address and return the IP address to client.

PROGRAM
SERVER
Serverrarp12
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp12
{

DMI College Of Engineering 37


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

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();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String
mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;

DMI College Of Engineering 38


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
CLIENT
Clientrarp12
import java.io.*; import
java.net.*; import
java.util.*;
class Clientrarp12
{
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));

DMI College Of Engineering 39


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

System.out.println("Enter the Physical address (MAC):");


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("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

OUTPUT:
I:\ex>java Serverrarp12
I:\ex>java Clientrarp12
Enter the Physical address (MAC):
6A:08:AA:C2
The Logical Address is(IP): 165.165.80.80
RESULT:
Thus the implementation of RARP is done & executed successfully

DMI College Of Engineering 40


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 6. STUDY OF NETWORK SIMULATOR(NS) AND


SIMULATION OF CONGESTION CONTROL
ALGORITHM USING NS
OBJECTIVE:
To study of network simulator (ns) and simulation of congestion control
algorithms using ns.
SYSTEM REQUIREMENTS:
PC: Pentium or higher
One LAN card onboard or on PCI slot with 10/100Mbps speed.
128MB RAM
500MB free space on Hard drive CD ROM drive
Serial port, LPT port & USB port installed on system Operating System:
Windows 2000 or higher
THEORY:
LTS-01 Local area network / wireless local area network trainer system:
It is designed to help students understand the basic concepts, modes of
operation and protocols involved in networking. The trainer has integrated
hardware flow control on panel board for better understanding of different types
of LAN topologies involved in networking. The trainer system is provided with
windows-based user friendly software with analysis of protocols, different
layers, network and measurement of error rate and throughput.
Students can easily do connections in different topologies and can learn actual
data transfer either through hardware or through simulated network concept.
Facility is provided into system software to introduce errors into packets being
sent and analyze the effect of error on different protocols and hence find the
effect on through put graph as well.
Trainer and its various types of experimentation using this system. This system
works into server-client base. For any topology user has to select one server and
select the network type whether it is LAN or WLAN. To understand the
topology concept user can connect two or more clients to hardware. Depending
on the topology selected user will have option to select protocols for the
selected topology. Upon selection of protocol user can then create network of
connected computers.

DMI College Of Engineering 41


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

In any network which is created by user server can send or can communicate
with any of the clients however clients can communicate only with server, no
client to client communication is possible. Transmitter port protocol & network
analysis can be done after communication is over between server and clients.
Throughput v/s Packet size graph can be plotted for which at least two file
transfers should be carried out. This plot can be printed to attach in the lab
exercise sheet.
For the LAN network LAN cards must be installed prior to start work on this
trainer. For wire less LAN USB ports should be available on the computers
which are to be used for experimentation. In WLAN wireless access cards gets
connected to computer USB ports and access point gets connected to hardware
device.

L-SIM LAN Protocol Simulator & Analyzer Software:


It is designed to teach the basic concepts, topologies & various protocols
involved in networking. The software is provided with analysis of protocols,
different layers, network and measurement of error rate and throughput. Facility
is provided to introduce errors into packets being sent and analyze the effect of
error on different protocols and hence find the effect on throughput graph as
well. Software is supported with neat operating instruction manual and online
help.
MODEL WINDOW DIAGRAM FOR L-SIM

N-SIM Network simulation software:

DMI College Of Engineering 42


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

It is developed to provide basic understanding and implementation of various


advanced concepts in networking. The software provides an opportunity to
understand network fundamentals through animations & simulations. The
simulation provides for network experimentation with various LAN and WAN
protocols, network devices, routers, encryption, decryption, file transfer, error
insertion and analysis of error rate and throughput etc. This software covers
Ethernet LAN, wireless LAN and router. All networking theory is explained
using simulation and animation.

MODEL WINDOW DIAGRAM FOR N-SIM

Rapid advances in computer & communication technologies have resulted in the


increasing merger of these two fields. The lines have blurred among computing,
switching & digital transmission equipment; and the same digital techniques are
being used for data, audio & video transmission. Merging & evolving
technologies, coupled with increasing demands for efficient & timely collection,
processing & dissemination of information, have led to the development of
integrated systems that transmit & process all types of data.
These integrated systems are broadly divided as follows
- DATA COMMUNICATION dealing with transmission, transmission
media, signal decoding, interfacing, data link control & multiplexing
- NETWORKING deals with the technology & architecture of
communication network
- COMMUNICATION PROTOCOLS which covers the architecture as
well
as analysis of individual protocols at various layers depending on the hardware
& software Network laboratory is designed & developed considering the
curriculum offered by Anna University. Trainers offered under network
laboratory are designed for students at all level to study and understand all the
concepts of data communication, data transfer using serial and parallel ports,

DMI College Of Engineering 43


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

Ethernet and wireless LAN with complete protocol understanding and actual
hands on with hardware & software with ease.

Network laboratory consists of DCT-03 Data communication trainer kit, LTS-


01 LAN / Wireless LAN training system, L-SIM LAN / WLAN protocol
simulator and analyzer software & N-SIM Network simulation software.

The DCT-03: Data communication trainer is a unique trainer kit for the
development of exercises and theoretical-experimental courses to understand
the basic concept and working of modes and protocols in serial and parallel
communication.

The trainer kit consists of functional blocks for serial and parallel
communication system.
The trainer kit is highly innovative from a technological as well as an
educational point of view. The trainer kit is used as “basic unit” to examine all
the peculiar operating standards of serial and parallel communication system.
The only external equipments required are two Computers with serial and
parallel communication ports and an Oscilloscope. Utmost care has been laid in
the design and quality control of all circuits, to ensure the repeatability of the
results of the experiments.

Data communication is a term referred when the sender and receiver are digital
devices, which communicate with each other by means of binary information.
The objective of this trainer kit is to clear the various aspects of the data
communications which comprise of

• The information source or sender.


• The medium for carrying information.
• The information receiver.
• The communication protocols, which ensure proper transfer of data.

DMI College Of Engineering 44


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

With an increasing demand in information exchange the field of data


communication technique is emerging as the only solution, to satisfy the various
needs of today’s communication sector and to achieve very high bandwidth
along with highest accuracy. The communication media is shifting from analog
signal transfer towards digital communication.
With PC becoming the biggest storage devices in digital form, it becomes the
main source and destination for information exchange. With rapid growth in
both the communication technologies as well as computer hardware and
software technologies, these two fields are merged to form a data
communication network. Now the digital data is used for data, voice and image
transmission.
Depending upon the application the communication link can be of point to point
communication between two devices or a multipoint communication between at
least 3 devices and data transfer can be serial or in parallel form.

RESULT:
The study of network simulator (ns) and simulation of congestion control
algorithms using ns is executed and verified.

DMI College Of Engineering 45


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 7. STUDY OF TCP/UDP PERFORMANCE USING


SIMULATION TOOLS

AIM:
To Study of TCP/UDP performance using Simulation tool.
TOOLS USED:
Opnet Simulator.
INTRODUCTION:
The transport layer protocols provide connection- oriented sessions and reliable
data delivery services. This paper seeks to reflect a comparative analysis
between the two transport layer protocols, which are TCP/IP and UDP/IP, as
well to observe the effect of using these two protocols in a client server
network. The similarities and differences between TCP and UDP over the
Internet are also presented in our work. We implement a network structure using
Opnet Modeler and finally, based on the practical results obtained we present
the conclusions-showing the difference between these two protocols and how
they work.
The transport layer is not just another layer. It is the heart of the whole protocol
hierarchy. Its task is to provide reliable, cost-effective data transport from the
source machine to the destination machine, independently of the physical
network or networks currently in use.TCP and UDP are transport layer
components that provide the connection point through which applications
access network services. TCP and UDP use IP, which is a lower-layer best effort
delivery service. IP encapsulates TCP packets and UDP datagrams and delivers
this information across router-connected internet works.The ultimate goal of the
transport layer is to provide efficient, reliable, and cost-effective service to its
users, normally processes in the application layer. To achieve this goal, the
transport layer makes use of the services provided by the network layer. Without
the transport layer, the whole concept of layered protocols would make little
sense e.g. The Transport Layer prepares applications data for transport over the
network and processes network data to be used by applications. It is responsible
for the end-to-end transfer of data over the network and is the four of the OSI
model. The Transport layer meets a number of functions:

DMI College Of Engineering 46


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

- enabling the applications to communicate over the network at the same time
when using a single device;
- ensure that all amount of data is receive by the correct application;
- responsible for fragmentation and reassembly;
- develop mechanism for handling errors.

Comparison Between TCP And UDP

Service TCP UDP


Flow controls The receiver can signal ACKs, which are used in
the sender to slow down. TCP to control packet
flow, are not returned.
Connection setup It takes time, but with No connection is
TCP reliability is required
ensured.
Guaranteed message Returns UDP does not return
delivery acknowledgments. ACKs, the receiver can’t
signal that packets have
been successfully
delivered
Congestion controls Network devices can If ACK, are missing, the
take advantage of TCP network cannot signal
ACK to control the congestion to the sender.
behavior of sender.

A big difference between TCP and UDP is the congestion control algorithm. For
the TCP, congestion algorithm prevents the sender from overrunning the
network capacity, while TCP can adapt the sender’s rate with the network
capacity and attempt to avoid potential congestions problems.
User Datagram Protocol (UDP), another transport protocol in IP networks, is
described e.g. The User Datagram Protocol (UDP) provides an unreliable
connectionless delivery service using IP to transport messages between
machines e.g. [5]. It uses IP to carry messages, but adds the ability to distinguish
among multiple destinations within a given host computer. Is a connectionless
protocol which doesn’t provide flow control, reliability or error recovery and
DMI College Of Engineering 47
CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

the retransmissions of data in case of errors must be ordered by other protocols.


UDP is designed for applications that do not have to recompose the data
segment that arrives from the sender. In another way, application-level protocols
are directly responsible for the security of data transmitted.Difference from the
TCP is that there is no mechanism for error detections. If applications that use
UDP doesn’t have their own mechanism for information retrieval can lose those
data and be forced to retransmitted again. On the other side this applications are
not slow down by the confirmation process and the memory will be available
for work much faster.
SIMULATION RESULTS:
The simulation time is set for two hours data transfer between LAN
network and the server with no packet latency and packet discard ratio of 0%
while packets traverse thru the WAN. The task response time, in seconds, Fig. 1,
shows how long the application need to be completed. The time when using
TCP to complete the task is greater that the one using UDP. When using TCP,
source and destination need to perform a three-way handshake before starting
sending data and all amount of data need to be acknowledge by the destination
when it is receive, so is taking more time than UDP, which doesn’t perform this
tasks.

1.Response time for TCP and UDP

DMI College Of Engineering 48


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

TCP

UDP

2.Traffic received (packets/sec) for the server

TCP TCP

UDP UDP

3.Traffic/Link utilization from the WAN to the server

DMI College Of Engineering 49


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

TCP

UDP

Link utilization with a 0.5% packets discard ratio

The main difference between these two protocols is that TCP provides
reliability and congestion control services, while UDP is orientated to improve
performance.
The most important and common thing that TCP and UDP are using is the
ability to set a host-to-host communication channel, so the packets will be
delivered between processes running on two different computers. UDP is the
right choice for application where reliability is not a must but the speed and
performance is. Instead, TCP, even if it takes more time for the processes, has
additional functions like same order delivery, reliability and flow control. As
future work, we plan to conductseveral studies regarding packets routing in
computer networks to improve the fairness of data transmissions using different
network protocols.

RESULT:
Thus the TCP/UDP performance has been simulated successfully using
OPNET.

DMI College Of Engineering 50


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 8.SIMULATION OF DISTANCE VECTOR ROUTING

ALGORITHM

AIM:

To implement the Distance – Vector Routing Algorithm

APPARATUS REQUIRED:

1. VI-RTSIM software.

2. Personal computer.

THEORY:

Distance Vector Algorithm:

❖ A Distance vector routing, each router periodically share its knowledge about
the entire network with it’s neighbors.

❖ The three keys to under this algorithm are

1. Knowledge about the whole network.

2. Routing only to neighbor.

3. Information sharing at regular intervals.

Knowledge about the whole work:

❖ Each router shares its knowledge about entire network. It sends all of its
collected knowledge about the network to its neighbors.

Routing only to neighbor:

DMI College Of Engineering 51


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

❖ Each router periodically sends its knowledge about the network only to those
routers to which it has direct links. It sends whatever knowledge it
has.Information sharing at regular intervals:

❖ The every 30 seconds, each router sends its information about the whole
network to its neighbors.

Sharing Information:

❖ LAN’s are connected by router, represented by the assuming A, B, C, D, E


and F.

❖ Distance vector routing simplifies the routing process by assuming a lost of


one unit for every link.

❖ The efficiency of transmission is a function only of the number of links


required to reach a destination. In this, the cost on hop count.

Routing Table:

❖ Each router gets its initial knowledge about the internet work and how it uses
shared information to update that knowledge.

❖ The routing table has e columns network lost router ID.

❖ The first block is final destination of packet.

❖ The second block is no of hop count.

❖ The third block is that to which a packet delivers must.

Updating algorithm:

❖ Updating algorithm requires that the router first has one hop to the hop count
field for each advertised router.

DMI College Of Engineering 52


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

❖ The router should apply the below rules to each router, if the advertised
destination is not in routing table

❖ If next hop field is same, router should replace the entry in the table with
advertised one.

❖ If next hop field is same, router should replace the entry in the table with
advertised one.

❖ . If next hop field is not the same, advertised hop count is smaller than the
one in the table, the router should replace the entry in the table with new one.

❖ IF advertised hop count is not smaller, the router should do no routing.

PROCEDURE

1. Open VI-RTSIM software from desktop

2. Click the Simulation menu bar

3. Select the “Distance – Vector Routing Algorithm” option from Routing


algorithm menu bar.

4. Network with routers connected through link is drawn by using option in


editor(add router, join

link, delete router, delete link, Add caption to link, add caption to router)

5. Select any two nodes to find the shortest distance between them.

6. Click the Find path Button to run the program.

7. Now the shortest paths between the two nodes are calculated.

DMI College Of Engineering 53


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DMI College Of Engineering 54


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

RESULT:

Thus Distance Vector routing algorithm has been implemented and shortest-
path has been circulated

DMI College Of Engineering 55


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 9.SIMULATION OF LINK STATE ROUTING ALGORITHM

AIM:

To implement the Link State Routing Algorithm

APPARATUS REQUIRED:

1. VI-RTSIM software.

2. Personal computer.

THEORY:

Link State Vector Algorithm:

 In Link state routing, each router share its information of its neighbors
with every other router in the inter-network.

Knowledge about the neighborhood:

 Instead of sending its entire routing table, a router sends information


about its neighborhood only.
To all router:

 Each router send this information to every other router on the


internetworking, not just to its neighbors.
 If s does so by a process called “flooding” it means that a router sends its
information. Information sharing when there is a Change:
 Each router sends out information about the neighbors when there is a
change.
Information sharing:

 Link state routing process use the same internet work as distance vector
algorithm.
 Here each other sends its knowledge about is neighbors to every other
router in the internet work.

DMI College Of Engineering 56


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

 Cost is applied only by routers and not by any other station on a network,
if cost was added by every station, instead of by routers alone, it would
accumulate unpredictably.
 Cost is applied as a packet leaves the router rather then as if enters. Most
networks are broadcast networks. When a packet is in network every
station, including the router, can pick it up, we cannot assign any cost to a
packet.
Link state packet:
 When a router floods the network with information about its
neighborhood, it is said to be advertising. The basis of this advertising is
a short packet called a link state packet (LSP).

Advertiser Network Cost Neighbor

Getting information about neighbors:

 A router gets its information about its neighbors by periodically sending


them a short greeting packet.
 If the neighbor responds to the greeting as expected, it is assumed to be
alive and functioning.
Initialization:

 Imagine that all routers in our sample internet work come up at the same
time.
 Each router sends a greeting packet to its neighbors to find out the state of
each link.
Link – State Database:

 Every router every LSP and puts the information into a link-state
database.
 Because every router receives the same LSPs every router builds the
same database.

DMI College Of Engineering 57


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

 It stores this database on its disk and uses it to calculate its routing table.
If a router is added to be deleted from the system, the whole database
must be shared for fast updating.

PROCEDURE

1. Open VI-RTSIM software from desktop


2. Click the Simulation menu bar

3. Select the “Link State Routing Algorithm” option from Routing algorithm
menu bar.
4. Network with routers connected through link is drawn by using option in

editor(add router, join link, delete router, delete link, Add caption to link,
add caption to router)
5. Select any two nodes to find the shortest distance between them.
6. Click the Find path Button to run the program.
7. Now the shortest paths between the two nodes using link state routing

algorithm was calculated.

DMI College Of Engineering 58


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

RESULT:

Thus Link-State routing algorithm has been implemented and shortest-


path has been circulated.

DMI College Of Engineering 59


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

DATE: 10. SIMULATION OF ERROR CORRECTION CODE


(LIKE CRC)

AIM:
To implement and check the error detection/error correction techniques in
networks using a c program.

APPARATUS REQUIRED:
1. Pc-ino
2. C/c++compiler

THEORY:
Error Detection
• Bit errors occur in frames due to electrical interference or thermal noise.
• Detecting errors is one part of the problem; correcting errors is the other.
• What happens when an error is detected?
• Two basic approaches:
– Notify the sender that message is corrupt so the sender can retransmit it; (
most often
used in every day applications)
– Use an error-correcting code to reconstruct the correct message
Transmission Errors
· External electromagnetic signals can cause incorrect delivery of data
- · Data can be received incorrectly
- · Data can be lost
- · Unwanted data can be generated
· Any of these problems are called transmission errors

DMI College Of Engineering 60


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

Error Detection
• Detecting Transmission Errors: basic idea is to add redundant information to a
frame that can
determine if errors have been introduced.
Error Correction or Error Detection?
• When error is detected, frame is discarded and resent, using bandwidth and
causing latency,
waiting for its arrival.
• Error correction requires additional bit to be sent with every frame.
• Correction is useful when
• 1) errors are probable or
• 2) the cost of retransmission is too high
Cyclic Redundancy Check (CRC)
CRC is a different approach to detect if the received frame contains valid data.
This technique involves binary division of the data bits being sent. The divisor
is generated using polynomials. The sender performs a division operation on the
bits being sent and calculates the remainder. Before sending the actual bits, the
sender adds the remainder at the end of the actual bits. Actual data bits plus the
remainder is called a codeword. The sender transmits data bits as code words

DMI College Of Engineering 61


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

divisor. If the remainder contains all zeros the data bits are accepted, otherwise
it is considered as there some data corruption occurred in transit.

PROCEDURE:
• Start the process.
• Give the data which is the message.
• Compile and run the program.
• Enter the received hamming code.
• The error is corrected codeword
PROGRAM FOR CODE GENERATION FOR ERROR DETECTION AND
CORRECTION
#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];
printf("Enter data as a binary bit stream (7 bits):\n");
scanf("%s", data);
for (i = 1, j = 0, k = 0; i < 12; i++)
{
if (i == (int)pow(2, j))
{
dw[i] = '?';
j++;
}
else

DMI College Of Engineering 62


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

{
dw[i] = data[k];
k++;
}
}
for (i = 0; i < 4; i++)
{
count = 0;
for (j = (int)pow(2, i); j < 12; j += (int)pow(2, i))
{
for (k = 0; k < (int)pow(2, i); k++)
{
if (dw[j] == '1')
count++;
j++;
}
}
if (count % 2 == 0)
dw[(int)pow(2, i)] = '0';
else
dw[(int)pow(2, i)] = '1';
}
printf("\nIn code word is:\n\n");
for (i = 1; i < 12; i++)
printf("%c", dw[i]);
printf("\n\nEnter the received hamming code:\n\n");
scanf("%s", cw);

DMI College Of Engineering 63


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

for (i = 12; i > 0; i--)


cw[i] = cw[i - 1];

for (i = 0; i < 4; i++)


{
count = 0;
for (j = (int)pow(2, i); j < 12; j += (int)pow(2, i))
{
for (k = 0; k < (int)pow(2, i); k++)
{
if (cw[j] == '1')
count++;
j++;
}
}
if (count % 2 != 0)
err_pos = err_pos + (int)pow(2, i);
}
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");

DMI College Of Engineering 64


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

printf("Sorry! Hamming code cannot correct 2 or more errors.\n");


flag = 1;
}
else
{
printf("There 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\n");
for (i = 1; i < 12; i++)
printf("%c", cw[i]);
}
}
}
printf("\n\n");
return 0;
}

OUTPUT:
Enter data as binary bit stream(7 bits):
1110110
Code word is
11101100110
Enter the received hamming code
10101100110
There is an error in bit position 2 of received code word corrected code word is

DMI College Of Engineering 65


CS 3591 COMPUTER NETWORK LAB Dept. of Information Technology

11101100110
Enter data as binary bit stream(7 bits)
11101110
Code word is
11101100110
Enter the received hamming code
00101100110
There are 2 or more error in received code…
Sorry…!

RESULT:
Thus the error detection/error correction techniques were implemented
successfully

DMI College Of Engineering 66

You might also like