0% found this document useful (0 votes)
28 views65 pages

Ilovepdf Merged Removed

Important questions

Uploaded by

anbesivam548
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views65 pages

Ilovepdf Merged Removed

Important questions

Uploaded by

anbesivam548
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

CS3591- COMPUTER NETWORKS LABORATORY

LIST OF EXPERIMENTS :

1. Learn to use commands like tcpdump, netstat, ifconfig, 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. Applications using TCP sockets like:
a) Echo client and echo server
b) Chat
4. Simulation of DNS using UDP sockets.
5. Use a tool like Wireshark to capture packets and examine the packets.
6. Write a code simulating ARP /RARP protocols.
7. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS.
8. Study of TCP/UDP performance using Simulation tool.
9. Simulation of Distance Vector/ Link State Routing algorithm.
10. Simulation of an error correction code (like CRC).
EX.No:1 NETWORKING COMMANDS
DATE:

AIM:

To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute ping.

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.

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.

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: tcpdump is a command-line tool that allows you to capture, filter, and analyze network
traffic. It's invaluable for network administrators and security professionals to troubleshoot network issues,
monitor network activity, and identify potential security threats.

Viva Questions and Answers:

1. What is the use of arp –a?


It will show the IP address of your computer along with the IP address and MAC address of your
router.

2. What is the use of 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.

3. What is the use of ipconfig?


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

4. What is the use of ping?


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.

5. What is the use of 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 various networks commands like tcpdump, netstat, ifconfig, nslookup and traceroute ping
are executed successfully.
Ex.No: 2 HTTP WEB CLIENT - WEB PAGE USING TCP SOCKETS
DATE:

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.

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.jpg"));
bByteArrayOutputStream 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 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");
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

Viva Questions and Answers:

1. What is meant by socket?


A socket is a software object that acts as an end point establishing a bidirectional network
communication link between a server-side and a client-side program.

2. Define HTTP.
HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by the World
Wide Web and this protocol defines how messages are formatted and transmitted, and what actions Web
servers and browsers should take in response to various commands.

3. What is meant by client server communication?


Client–server model is a distributed application structure that partitions tasks or workloads
between the providers of a resource or service, called servers, and service requesters, called clients.

4. Define webpage.
A web page or webpage is a document commonly written in HTML (Hypertext Markup Language)
that is accessible through the Internet or other networks using an Internet browser.

5. Define URL.
URL stands for Uniform Resource Locator, and is used to specify addresses on the World Wide
Web. A URL is the fundamental network identification for any resource connected to the web (e.g.,
hypertext pages, images, and sound files). The protocol specifies how information from the link is
transferred.

RESULT :
The webpage is successfully downloaded and the contents are displayed and verified.
EX. No: 3a TCP SOCKETS APPLICATION – ECHO CLIENT & SERVER
DATE:

AIM
To write a socket program for implementation of echo Client and Server.

ALGORITHM

CLIENT

1. Start
2. Create the TCP socket
3. Establish connection with the server
4. Get the message to be echoed from the user
5. Send the message to the server
6. Receive the message echoed by the server
7. Display the message received from the server
8. Terminate the connection
9. Stop

SERVER

1. Start
2. Create TCP socket, make it a listening socket
3. Accept the connection request sent by the client for connection establishment
4. Receive the message sent by the client
5. Display the received message
6. Send the received message to the client from which it receives
7. Close the connection when client initiates termination and server becomes a listening server,
waiting for clients.
8. Stop.

PROGRAM:
EchoServer.java
import java.net.*;
import java.io.*;
public class EServer
{
public static void main(String args[])
{
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try {
s=new ServerSocket(9000);
}
catch(IOException e)
}

try
{
System.out.println(e);
}
c=s.accept();
is=newDataInputStream(c.getInputStream());
ps=new PrintStream(c.getOutputStream());
while(true) {
line=is.readLine();
ps.println(line);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}

EClient.java
import java.net.*;
import java.io.*;
public class EClient
{
public static void main(String arg[])
{
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
{
InetAddress ia = InetAddress.getLocalHost();
c=new Socket(ia,9000);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
while(true)
{
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine()); }
}

catch(IOException e)
{
System.out.println("Socket Closed!");
}
}
}

OUTPUT

Server
C:\Program Files\Java\jdk1.5.0\bin>javac
EServer.java C:\Program
Files\Java\jdk1.5.0\bin>java EServer
C:\Program Files\Java\jdk1.5.0\bin>

Client
C:\Program Files\Java\jdk1.5.0\bin>javac
EClient.java C:\Program
Files\Java\jdk1.5.0\bin>java EClient Client:
Hai Server
Server:Hai
Server Client:
Hello
Server:Hello
Client:end
Server:end Client:ds
Socket Closed!
Viva Questions and Answers:

1. what is meant by socket programming?

Socket programs are used to communicate between various processes usually running on
different systems. It is mostly used to create a client-server environment.

2. what is the use of java.net?


The java.net package provides 4 kinds of Sockets: Socket is a TCP client API, and will
typically be used to connect to a remote host. ServerSocket is a TCP server API, and will
typically accept connections from client sockets. DatagramSocket is a UDP endpoint API and is
used to send and receive datagram packets.

3. Define echo.
Echo describes when data is sent to a computer or other networkdevices, and that
information is sent back to verify the information was received. Echo can be a command used
with operating systems, network devices, or a function of a device.

RESULT:
Thus the above program a client-server application for echo using TCP / IP was
executed and successfully.
EX.No: 3b TCP SOCKETS APPLICATION - CHAT
DATE:

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.

PROGRAM

TCPserver1.java

import java.net.*;
import java.io.*;

public class TCPserver1


{
public static void main(String arg[])
{
ServerSocket s=null;
String line;
DataInputStream is=null,is1=null;
PrintStream os=null;
Socket c=null;
try {
s=new ServerSocket(9999);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
c=s.accept();
is=newDataInputStream(c.getInputStream());
is1=new DataInputStream(System.in);
os=new PrintStream(c.getOutputStream());
do
{
line=is.readLine();
System.out.println("Client:"+line);
System.out.println("Server:");
line=is1.readLine();
os.println(line);
}
while(line.equalsIgnoreCase("quit")==false);
is.close();
os.close();
}
Catch (IOException e)
{
System.out.println(e);
}
}
}

TCPclient1.java
import java.net.*;
import java.io.*;

public class TCPclient1


{
public static void main(String arg[])
{
Socket c=null;
String line;
DataInputStreamis,is1;
PrintStream os;
try
{
c=new Socket("10.0.200.36",9999);
}
catch(IOException e)
{
System.out.println(e);
} try
{
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=newDataInputStream(c.getInputStream());
do
{
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine());
}
while(line.equalsIgnoreCase("quit")==false;
is1.close();
os.close(); }
catch(IOException e)
{
System.out.println("Socket Closed!Message Passing is over");

}
}

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.
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
Viva Questions and Answers:

1. Define chat.
A real-time communication via keyboard between two or more users on a local network (LAN) or
over the Internet

2. Define TCP.
TCP/IP stands for Transmission Control Protocol/Internet Protocol, which is a set of
networking protocols that allows two or more computers to communicate. The Defense Data Network,
part of the Department of Defense, developed TCP/IP, and it has been widely adopted as a networking
standard.

3. what is socket API?


A socket API is an application programming interface (API), usually provided by the operating
system, that allows application programs to control and use network sockets. Internet socket APIs are
usually based on the Berkeley sockets standard.

RESULT:

Thus the above program a client-server application for chat using TCP / IP was executed
and successfully.
Ex.No:3c FILE TRANSFER IN CLIENT & SERVER

DATE:

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

bytesRead = is.read(mybytearray,0,mybytearray.length);

current = bytesRead;

// thanks to A. Cádiz for the bug fix do { bytesRead =

is.read(mybytearray, current, (mybytearray.length-current));

if(bytesRead >= 0)

current += bytesRead;
while(bytesRead > -1);

bos.write(mybytearray, 0 , current);

bos.flush();

long end = System.currentTimeMillis();

System.out.println(end-start);

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

os.flush();

sock.close();

}
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


acollection of computers and devices connected by communications channels
thatfacilitates communications among users and allows users to shareresources with
other user
Viva Questions and Answers:

1. What is socket address?

A socket address is the combination of an IP address and a port number, much


like one end of a telephone connection is the combination of a phone number and a
particular extension. Based on this address, internet sockets deliver incoming data
packets to the appropriate application process or thread.

2. What are the local socket address?

Local socket address: Local IP address and port number

3.Define File transfer.

File transfer is the process of copying or moving a file from one computer to
another over a network or Internet connection. It enables sharing, transferring or
transmitting a file or a logical data object between different users and/or computers
both locally and remotely.

4. what is called as socket pairs?

Communicating local and remote sockets are called socket pairs.

RESULT:

Thus the File transfer Operation is done & executed successfully.


Ex.No: 4 SIMULATION OF DNS USING UDP SOCKETS

DATE:

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 Server


Udpdnsserver.java
import java.io.*;
import java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
st = 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 –


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
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("IPAddress: " + modified);
clientsocket.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
Viva Questions and Answers:

1. Define DNS.

DNS. (Domain Name System) The Internet's system for converting alphabetic names into
numeric IP addresses. For example, when a Web address (URL) is typed into a browser, DNSservers
return the IP address of the Web server associated with that name.
2. Define UDP.

User Datagram Protocol (UDP) is part of the Internet Protocol suite used by programs running on
different computers on a network. UDP is used to send short messages called datagrams but overall, it is
an unreliable, connectionless protocol.

3. what is meant by MACaddress?


A MAC address is a hardware identification number that uniquely identifies each device on a
network.

4. What is meant by IP address?

An Internet Protocol address (IP address) is a numerical label assigned to each device connected to
a computer network that uses the Internet Protocol for communication. An IP address serves two
principal functions: host or network interface identification and location addressing.

5. List the IP address class.

Class 1st Octet Decimal Range Default Subnet Mask


1 – 126* 255.0.0.0
128 – 191 255.255.0.0
A 192 – 223 255.255.255.0
224 – 239 Reserved for
B Multicasting

D
RESULT :

Thus the above program a client-server application for chat using UDP was executed and
successfully
Ex.No: 5 TOOL – WIRESHARK TO CAPTURE &EXAMINE PACKETS
DATE:

WIRESHARK TO CAPTURE PACKETS

Wireshark is a free and open-source packet analyzer. It is used for network troubleshooting, analysis,
software and communications protocol development, and education. It works similar to tcpdump in
linux but the problem is that there is no GUI for tcpdump. Wireshark is having a nice interface through
which we can differentiate the data as per the different parameters and then we can analyze the packet
transfer process.

Steps to Capture Packet

Whenever we want to do an analysis of any data packet the first step is to capture the packet which is
coming and outgoing then we use packet analyzer tool named Wireshark.

Step 1:
First we need to download and install Wireshark on our machine as per our operating system.
Wireshark is available to download and install on all the most used platforms

Step 2:
We need to start the Wireshark with administrative permission it will show the below window. Here we
need to select the appropriate interface through which we want to capture the packets.

Step 3:
Once we select the interface then Wireshark starts capturing packets and showing the list of packets and
live to capture packet window. Wireshark will keep capturing live packets until we stop capturing.

Step 4:
If We want to continue the live capturing then we can keep capturing the packet and if we want to stop
capturing then we can click on stop capturing packet menu in the toolbar.

Step 5:
The various column in the Wireshark window i.e. no. Time, Source, Destination, and protocol, etc.
Now we can select the appropriate packet which we want to analyze.
Step 6:
As per the various packet format we can select and analyze that how the packets are being transferred
over the internet.

Analyze the packet then we can see which protocol is used at various layer. What is the size of actual
message and and size of various header. Identify the various segments of the original message because a
large message reach to destination from source in the form of segments.

EXAMINE A CAPTURED PACKET USING WIRESHARK

Wireshark is a useful tool for capturing network traffic data. Network pros can make the most of the
tool by analyzing captured packets to see what that data means for troubleshooting.
Capturing network traffic with tools such as Wireshark and tcpdump is fairly straightforward. Where
many administrators run into trouble is understanding what they've captured.
This article explains the primary components of captured data and relates this information to the
TCP/IP model. The article's purpose is not covering how to use Wireshark or its features and
options.
The basic steps to capture packets -- enough for you to grab a packet and apply the interpretive
information provided throughout.
Take the following steps to initiate a capture in Wireshark:

1. Open Wireshark.

2. Set a capture filter, and select the interface on which to capture.

3. Start the capture.


4. Generate traffic by connecting to a website, pinging a remote device or attempting any other network
connection.

5. Stop the capture.

Start a capture with the shark fin button in the upper left of the Wireshark tool.

Wireshark captures an immense amount of data quickly if filter not used. While this might be what you
want, be sure to set an effective filter if you know the protocols for the service you're troubleshooting.
And don't run the capture any longer than you must. Wireshark has various search and filter options, but
a targeted capture is much easier to work with.

I use Wireshark in this article because it is common, has a relatively simple GUI and is flexible. But many
other powerful protocol analyzers are available, such as tcpdump. You can analyze the content you
capture with those tools using the information below.

Wireshark is powerful and has many options beyond this article's scope, including network analysis and
performance information. Also, note that Wireshark v3 organizes the output into three vertically stacked
window panes. Wireshark v4 uses the same three panes, but the Packet Details pane is in the lower-left
corner -- it was the middle pane in v3 -- and the Packet Bytes pane is in the lower-right corner.
Three panes in the main Wireshark window

Select a frame in the Packet List pane

In the new Wireshark interface, the top pane summarizes the capture. It displays one or more frames,
along with the packet number, time, source, destination, protocol, length and info fields.

Use the protocols, source and destination addresses, and ports columns to help you decide which frame
to examine. Click on a frame to select it, and then look at the two lower panes for details.

The sample capture for these screenshots is a simple. This example generates DNS and other traffic that
is handy for the explanations below.
RESULT :
Thus the Wireshark tool is used to Captured and examined Packets successfully
Ex.No:6a CODE FOR SIMULATING ARP PROTOCOLS DATE:

AIM

To implement Address Resolution Protocol for simulation.

ALGORITHM

CLIENT

1. Start the program


2. Create socket and establish connection with the server.
3. Get the IP address to be converted into MAC address from the user.
4. Send this IP address to server.
5. Receive the MAC address for the IP address from the server.
6. Display the received MAC address
7. Terminate the connection

SERVER

1. Start the program


2. Create the socket, bind the socket created with IP address and port number and make it a
listening socket.
3. Accept the connection request when it is requested by the client.
4. Server maintains the table in which IP and corresponding MAC addresses are stored.
5. Receive the IP address sent by the client.
6. Retrieve the corresponding MAC address for the IP address and send it to the client.
7. Close the connection with the client and now the server becomes a listening server waiting
for the connection request from other clients
8. Stop

PROGRAM
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139)
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Logical address(IP):");
String str1=in.readLine();
dout.writeBytes(str1+'\n'; String str=din.readLine());
System.out.println("The Physical Address is: "+str);
t.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}

Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
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(str.equals(ip[i]))
{
dout.writeBytes(mac[i]+'\n');
break;
}
}
obj.close();
}
}
System.out.println(e);
}
}
}
Output:
E:\networks>java
Serverarp
E:\networks>java
Clientarp Enter the
Logical
address(IP):
165.165.80.80
The Physical Address is: 6A:08:AA:C2

Viva Questions and Answers:

1. Define ARP.
The address resolution protocol (arp) is a protocol used by the Internet Protocol (IP)
[RFC826], specifically IPv4, to map IP network addresses to the hardware addresses used by a
data link protocol.

2. Define IPv4.
IPv4 (Internet Protocol Version 4) is the fourth revision of the Internet Protocol (IP) used to to
identify devices on a network through an addressing system.

RESULT :
Thus the implementation of ARP is done & executed successfully.
EX.No: 6b CODE FOR SIMULATING RARP PROTOCOLS
DATE:

AIM
To write a java program for simulating RARP protocols.

ALGORITHM

CLIENT

1. Start the program


2. Using datagram sockets UDP function is established.
3. Get the MAC address to be converted into IP address.
4. Send this MAC address to server.
5.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.

CLIENT:
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(newInputStreamReader(Sysem.in))
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);
}
}
}

SERVER:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp12
{
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 Datagram Packet (sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
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

Viva Questions and Answers:

1. Define RARP.
RARP (Reverse Address Resolution Protocol) is a protocol by which a physical machine in a local
area network can request to learn its IP address from a gateway server's Address Resolution Protocol
(ARP) table .

2. What is the use of RARP?


RARP is used for the opposite purpose; namely, to convert an ethernet address to an IP address. Its
linux-network-administration purpose is to enable diskless machines, such as X workstations, to find out
their IP address at boot time.

RESULT:
Thus the implementation of RARP is done & executed successfully.
EX.No: 7 STUDY OF NETWORK SIMULATOR (NS) AND
DATE: SIMULATION OF CONGESTION CONTROL
ALGORITHMS USING NS

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

NET WORK SIMULATOR (NS2)

Ad hoc routing, mobile IP, sensor-MAC Tracing, visualization and various utilitie NS(Network
Simulators)
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)

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
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 transportlayer 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
Throughput 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. Throughput is usually measured inbitsper
second (bit/s orbps), and sometimes in data packets per second or data packets per time slot. This
measures 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 highbandwidths. 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.

Congestion control Algorithms


Slow-start is used in conjunction with other algorithms to avoid sending more data than the network is
capable of transmitting, that is, to avoid causing network congestion.

The additive increase/multiplicative decrease (AIMD) algorithm is a feedback control algorithm.


AIMD combines linear growth of the congestion window with an exponential reduction when a
congestion takes place. Multiple flows using AIMD congestion control will eventually converge to use
equal amounts of a contended link. Fast Retransmit is an enhancement to TCP that reduces the time a
sender waits before retransmitting a lost segment.
Program:
include <wifi_lte/wifi_lte_rtable.h>
struct r_hist_entry *elm, *elm2;
int num_later = 1;
elm = STAILQ_FIRST(&r_hist_);
while (elm != NULL && num_later <= num_dup_acks_)
{
num_later;
elm = STAILQ_NEXT(elm, linfo_);
}
if (elm != NULL)
{
elm = findDataPacketInRecvHistory(STAILQ_NEXT(elm,linfo_));
if (elm != NULL)
{
elm2 = STAILQ_NEXT(elm, linfo_);
while(elm2 != NULL)
{
if (elm2->seq_num_ < seq_num && elm2->t_recv_ < time)
{
STAILQ_REMOVE(&r_hist_,elm2,r_hist_entry,linfo_);
delete elm2;
}
else
elm = elm2;
elm2 = STAILQ_NEXT(elm, linfo_);
}
}
}
}
void DCCPTFRCAgent::removeAcksRecvHistory()
{
struct r_hist_entry *elm1 = STAILQ_FIRST(&r_hist_);
struct r_hist_entry *elm2;
int num_later = 1;
while (elm1 != NULL && num_later <= num_dup_acks_)
{
num_later;
elm1 = STAILQ_NEXT(elm1, linfo_);
}
if(elm1 == NULL)
return;
elm2 = STAILQ_NEXT(elm1, linfo_);
while(elm2 != NULL)
{
if (elm2->type_ == DCCP_ACK)
{
STAILQ_REMOVE(&r_hist_,elm2,r_hist_entry,linfo_); delete elm2;
}
else
{
elm1 = elm2;
}
elm2 = STAILQ_NEXT(elm1, linfo_);
}
}
inline r_hist_entry *DCCPTFRCAgent::findDataPacketInRecvHistory(r_hist_entry *start)
{
while(start != NULL && start->type_ == DCCP_ACK)
start = STAILQ_NEXT(start,linfo_);
return start;
}

Viva Questions and Answers:


1. Define NS.
A Network Simulator is an object oriented, event driven discrete simulator written in C++, with an
object oriented tool command language (OTCL) interpreter as a front end.

2. What protocols does NS support?


A lot! Almost all variants of TCP, several forms of multicast, wired networking, several ad hoc
routing protocols and propagation models (but not cellular phones), data diffusion, satellite, and other
stuff. See the documentation (described above) for details, or download ns and look.

3. Define data communication.


Data communication is a term referred when the sender and receiver are digital devices, which
communicate with each other by means of binary information.

4. List of Network Simulators:


Ns2 (Network Simulator 2).
Ns3 (Network Simulator 3).
OPNET.
OMNeT++.
NetSim.
REAL.
QualNet. J-Sim.

5. Define OPNET.
OPNET Network Simulator. OPNET Network simulator is a tool to simulate the behavior and
performance of any type of network. The main difference Opnet Network Simulator comparing to other
simulators lies in its power and versatility. IT Guru provides pre-built models of protocols and devices.
RESULT :
Thus we have Studied Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.
EX.No:8 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL
DATE:

AIM
To Study of TCP/UDP performance using Simulation tool.

TCP Performance

Algorithm
1. Create a Simulator object.
2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the tcp agent.
8. Connect tcp and tcp sink.
9. Run the simulation.

PROGRAM

set ns [new Simulator]


$ns color 0 Blue $ns color 1 Red
$ns color 2 Yellow set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set f [open
tcpout.tr w]
$ns trace-all $f
set nf [open tcpout.nam w]
$ns namtrace-all $nf
$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5 set tcp [new Agent/TCP]
$tcp set class_ 1
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $tcp
$ns attach-agent $n3 $sink $ns connect $tcp
$sink set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 1.2 "$ftp start"
$ns at 1.35 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n3 $sink"
$ns at 3.0 "finish" proc finish {} { global ns f nf

$ns flush-trace close $f


close $nf
puts "Running nam.."
exec xgraph tcpout.tr -geometry 600x800 & exec nam tcpout.nam &
exit 0 }
$ns run

OUTPUT

UDP Performance

ALGORITHM

1. Create a Simulator object.


2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the UDP agent.
8. Connect udp and null agents.
9. Run the simulation.

PROGRAM

set ns [new Simulator]


$ns color 0 Blue
$ns color 1 Red
$ns color 2 Yellow set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]
set f [open udpout.tr w] $ns trace-all $f
set nf [open udpout.nam w]
$ns namtrace-all $nf
$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5 set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0 set udp1 [new Agent/UDP]
$ns attach-agent $n3 $udp1 $udp1
set class_ 0
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1 set null0 [new Agent/Null]
$ns attach-agent $n1 $null0 set null1 [new Agent/Null]
$ns attach-agent $n1 $null1
$ns connect $udp0 $null0
$ns connect $udp1 $null1
$ns at 1.0 "$cbr0 start" $ns
at 1.1 "$cbr1 start"
puts [$cbr0 set packetSize_] puts [$cbr0 set interval_]
$ns at 3.0 "finish" proc finish {} {
global ns f nf $ns flush-trace
close $f close $nf
puts "Running nam.." exec nam udpout.nam & exit 0
}
$ns run

OUTPUT
RESULT :

Thus the study of TCP/UDP performance is done successfully.


Ex.No:9a SIMULATION OF DISTANCE VECTOR ROUTING ALGORITHM
DATE:

AIM:

To implement the Distance – Vector Routing Algorithm

Distance vector Routing

In computer communication theory relating to packet-switched networks, a distance- vector


routing protocol is one of the two major classes of routing protocols, the other major class being the
link-state protocol. Distance-vector routing protocols use the Bellman–Ford algorithm, Ford– Fulkerson
algorithm, or DUAL FSM (in the case of Cisco Systems's protocols) to calculate paths.
A distance-vector routing protocol requires that a router informs its neighbors of topology
changes periodically. Compared to link-state protocols, which require a router to inform all the nodes in
a network of topology changes, distance-vector routing protocols have less computational complexity
and message overhead.
The term distance vector refers to the fact that the protocol manipulates vectors (arrays) of
distances to other nodes in the network. The vector distance algorithm was the original ARPANET
routing algorithm and was also used in the internet under the name of RIP (Routing Information
Protocol).Examples of distance-vector routing protocols include RIPv1 and RIPv2 and IGRP.

Method
Routers using distance-vector protocol do not have knowledge of the entire path to a destination.
Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any link in a
network. "Direction" usually means the next hop address and the exit interface. "Distance" is a measure
of the cost to reach a certain node. The least cost route between any two nodes is the route with minimum
distance. Each node maintains a vector (table) of minimum distance to

every node. The cost of reaching a destination is calculated using various route metrics. RIP uses
the hop count of the destination whereas IGRP takes into account other information such as node delay
and available bandwidth.
Updates are performed periodically in a distance-vector protocol where all or part of a router's
routing table is sent to all its neighbors that are configured to use the same distance- vector routing
protocol. RIP supports cross-platform distance vector routing whereas IGRP is a Cisco Systems
proprietary distance vector routing protocol. Once a router has this information it is able to amend its
own routing table to reflect the changes and then inform its neighbors of the changes. This process has
been described as ‗routing by rumor‘ because routers are relying on the information they receive from
other routers and cannot determine if the information is actually valid and true. There are a number of
features which can be used to help with instability and inaccurate routing information.
EGP and BGP are not pure distance-vector routing protocols because a distance-vector protocol
calculates routes based only on link costs whereas in BGP, for example, the local route preference value
takes priority over the link cost.

Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers from the
count-to-infinity problem. The core of the count-to-infinity problem is that if A tells B that it has a path
somewhere, there is no way for B to know if the path has B as a part of it.

To see the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and let the metric
between the routers be "number of jumps". Now suppose that A is taken offline. In the vector-
updateprocess B notices that the route to A, which was distance 1, is down – B does not receive the
vector update from A. The problem is, B also gets an update from C, and C is still not aware of the fact
that A is down – so it tells B that A is only two jumps from C (C to B to A), which is false. This slowly
propagates through the network until it reaches infinity (in which case the algorithm corrects itself, due
to the relaxation property of Bellman–Ford).

ALGORITHM

1. Create a simulator object


2. Set routing protocol to Distance Vector routing
3. Trace packets on all links onto NAM trace and text trace file
4.Define finish procedure to close files, flush tracing and run NAM
5.Create eight nodes
6.Specify the link characteristics between nodes
7.Describe their layout topology as a octagon
8.Add UDP agent for node n1
9.Create CBR traffic on top of UDP and set traffic parameters.
10.Add a sink agent to node n4
11. Connect source and the sink
12.Schedule events as follows:
a. Start traffic flow at 0.5
b. Down the link n3-n4 at 1.0
c. Up the link n3-n4 at 2.0
d. Stop traffic at 3.0
e. Call finish procedure at 5.0
13.Start the scheduler
14.Observe the traffic route when link is up and down
15.View the simulated events and trace file analyze it
16.Stop

PROGRAM

#Distance vector routing protocol – distvect.tcl #Create a simulator object


set ns [new Simulator] #Use distance vector routing
$ns rtproto DV
#Open the nam trace file set nf [open out.nam w]
$ns namtrace-all $nf
# Open tracefile
set nt [open trace.tr w] $ns
trace-all $nt
#Define 'finish' procedure proc
finish {}
{
global ns nf
$ns flush-trace #Close the trace file close $nf
#Execute nam on the trace file exec nam -a out.nam & exit 0
}
# Create 8 nodes set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node]
set n6 [$ns node] set n7 [$ns node] set n8 [$ns node]
# Specify link characterestics
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n6 1Mb 10ms DropTail
$ns duplex-link $n6 $n7 1Mb 10ms DropTail
$ns duplex-link $n7 $n8 1Mb 10ms DropTail
$ns duplex-link $n8 $n1 1Mb 10ms DropTail # specify layout as a octagon
$ns duplex-link-op $n1 $n2 orient left-up
$ns duplex-link-op $n2 $n3 orient up
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n4 $n5 orient right
$ns duplex-link-op $n5 $n6 orient right-down
$ns duplex-link-op $n6 $n7 orient down
$ns duplex-link-op $n7 $n8 orient left-down
$ns duplex-link-op $n8 $n1 orient left #Create a UDP agent and attach it to node n1 set udp0 [new
Agent/UDP]
$ns attach-agent $n1 $udp0
#Create a CBR traffic source and attach it to udp0set cbr0 [new Application/Traffic/CBR] $cbr0
set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n4 set null0 [new Agent/Null] $ns
attach-agent $n4 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.0 "$n1 label Source"
$ns at 0.0 "$n4 label Destination"
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n3 $n4
$ns rtmodel-at 2.0 up $n3 $n4
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish" #Run the simulation
$ns run
OUTPUT

$ ns distvect.tcl
Viva questions and answers:

1. what is distance vector routing protocol?

In distance vector routing the least cost route between any two nodes is the route with minimum
distance. In this each node maintains a vector table of minimum distances to every node. The table at
each node also guides the packets to the desired node by showing the next stop in the route.

2. What is advantage in distance vector routing protocol?

In this each node shares its routing table with its immediate neighbors periodically and when there is a
change.

3. What are the routing protocols?


• Intra domain routing protocols

• Interdomain routing protocols

4. What is intradomain routing protocols?

Routing inside an autonomous system is referred to as intradomain routing protocols.

5. What is RIP?

RIP(routing information protocol) is an intradomain routing protocol used inside an autonomous


system. it is very simple protocol based on distance vector routing.

RESULT:

Thus the simulation for Distance vector routing protocols was done using NS2 Ex.No: 9b
Ex.No: 9b SIMULATION OF LINK STATE ROUTING ALGORITHM
DATE:

AIM:
To implement the Link State Routing Algorithm

LINK STATE ROUTING

Routing is the process of selecting best paths in a network. In the past, the term routing was also
used to mean forwarding network traffic among networks. However this latter function is much better
described as simply forwarding. Routing is performed for many kinds of networks, including the
telephone network (circuit switching), electronic data networks (such as the Internet), and
transportation networks. This article is concerned primarily with routing in electronic data networks
using packet switching technology.
In packet switching networks, routing directs packet forwarding (the transit of logically addressed
network packets from their source toward their ultimate destination) through intermediate nodes.
Intermediate nodes are typically network hardware devices such as routers, bridges, gateways,
firewalls, or switches. General-purpose computers can also forward packets and perform routing,
though they are not specialized hardware and may suffer from limited performance. The routing
process usually directs forwarding on the basis of routing tables which maintain a record of the routes
to various network destinations. Thus, constructing routing tables, which are held in the router's
memory, is very important for efficient routing. Most routing algorithms use only one network path
at a time. Multipath routing techniques enable the use of multiple alternative paths. In case of
overlapping/equal routes, the following elements are considered in order to decide which routes get
installed into the routing table (sorted by priority):
1. Prefix-Length: where longer subnet masks are preferred (independent of whether it is
within a routing protocol or over different routing protocol)
2. Metric: where a lower metric/cost is preferred (only valid within one and the same
routing protocol)
3. Administrative distance: where a lower distance is preferred (only valid between
different routing protocols)
Routing, in a more narrow sense of the term, is often contrasted with bridging in its assumption that
network addresses are structured and that similar addresses imply proximity within the network.
Structured addresses allow a single routing table entry to represent the route to a group of devices. In
large networks, structured addressing (routing, in the narrow sense) outperforms unstructured
addressing (bridging). Routing has become the dominant form of addressing on the Internet. Bridging
is still widely used within localized environments.

b. Flooding
Flooding is a simple routing algorithm in which every incoming packet is sent through every outgoing
link except the one it arrived on. Flooding is used in bridging and in systems such as Usenet and peer-
to-peer file sharing and as part of some routing protocols, including OSPF, DVMRP, and those used
in ad-hoc wireless networks.There are generally two types of flooding available, Uncontrolled
Flooding and Controlled Flooding. Uncontrolled Flooding is the fatal law of flooding. All nodes have
neighbours and route packets indefinitely. More than two neighbours creates a broadcast storm.
Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence Number
Controlled Flooding) and RPF (Reverse Path Flooding).
In SNCF, the node attaches its own address and sequence number to the packet, since every node has
a memory of addresses and sequence numbers.
If it receives a packet in memory, it drops it immediately while in RPF, the node will only send the
packet forward. If it is received from the next node, it sends it back to the sender.

ALGORITHM

1. Create a Simulator object.


2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the udp agent.
8. Connect udp and null..
9. At 1 sec the link between node 1 and 2 is broken.
10. At 2 sec the link is up again.
11. Run the simulation.

PROGRAM

set ns [new Simulator] $ns


rtproto LS
set nf [open linkstate.nam w]
$ns namtrace-all
$nf set f0 [open linkstate.tr w]
$ns trace-all
$f0 proc finish {}
{
global ns f0 nf
$ns flush-trace close
$f0 close
$nf exec nam linkstate.nam &
exit 0
}
for {set i 0} {$i <7} {incr i}
{
set n($i) [$ns node]
}
for {set i 0} {$i <7} {incr i}
{
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}
set udp0 [new Agent/UDP] $ns
attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0 set null0 [new Agent/Null]
$ns attach-agent $n(3) $null0
$ns connect $udp0 $null0
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)

$ns rtmodel-at 2.0 up $n(1) $n(2)


$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run

OUTPUT
Viva questions and answers:
1. What is link state routing protocol?

It has a different concept from that of distance vector routing. In this each node in the
domain has the entire topology of the domain-the list of nodes and links, how they are connected
including the type, cost and condition of the links.

2. What is other name of link state routing protocol?

Dijkstra’s algorithm.

3. What is advantage of link state routing protocol? The link state


packet can carry a large amount of information. It has topology

4. How the routing table is builded?

By formation of a shortest path tree for each node. Calculation of a routing table based on
the shortest path tree. Creation of the states of the links by each node.

5. What is periodic update?

A node sends its routing table, normally every 30’s in a periodic update. The period depends
on the protocol that is using distance vector routing.
RESULT :

Thus the simulation for Link State routing protocols was done using NS2.
EX.No:10 SIMULATION OF ERROR CORRECTION CODE (LIKE CRC)
DATE:

AIM
To implement error checking code using java.

ALGORITHM
1. Start the Program
2. Given a bit string, append 0S to the end of it (the number of 0s is the same as the degree of the
generator polynomial) let B(x) be the polynomial corresponding to B.
3.Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and determine the remainder
R(x). This division is to be done using Modulo 2 Division.
4. Define T(x) = B(x) –R(x)
5. (T(x)/G(x) => remainder 0)
6. Transmit T, the bit string corresponding to T(x).
7. Let T’ represent the bit stream the receiver gets and T’(x) the associated polynomial
8. The receiver divides T1(x) by G(x). If there is a 0 remainder, the receiver concludes T = T’ and no
error occurred otherwise, the receiver concludes an error occurred and requires a retransmission
9. Stop the Program

PROGRAM

import java.io.*;
class crc_gen
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] data; int[] div;
int[] divisor;
int[] rem; int[] crc;
int data_bits, divisor_bits, tot_length;
System.out.println("Enter number of data bits : ");
data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits];
System.out.println("Enter Divisor bits : ");
for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());
System.out.print("Data bits are : ");
for(int i=0; i< data_bits; i++)
System.out.print(data[i]);
System.out.println();
System.out.print("divisor bits are : ");
for(int i=0; i< divisor_bits; i++)
System.out.print(divisor[i]);
System.out.println();
*/ tot_length=data_bits+divisor_bits-1;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
/* CRC GENERATION */
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print("Dividend (after appending 0's) are : ");
for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();
for(int j=0; j<div.length; j++)
{
rem[j] = div[j];
}
rem=divide(div, divisor, rem);
for(int i=0;i<div.length;i++)
{
//append dividend and remainder crc[i]=(div[i]^rem[i]);
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
System.out.println("Enter CRC code of "+tot_length+" bits : ");
for(int i=0; i<crc.length; i++)
crc[i]=Integer.parseInt(br.readLine());
System.out.print("crc bits are : ");
for(int i=0; i< crc.length; i++)
System.out.print(crc[i]);
System.out.println();
for(int j=0; j<crc.length; j++)
{
rem[j] = crc[j];
}
rem=divide(crc, divisor, rem);
for(int i=0; i< rem.length; i++)
{
if(rem[i]!=0)
{
System.out.println("Error");
break;
}
if(i==rem.length-1)
System.out.println("No Error");
}
System.out.println("THANK YOU. )");
}
static int[] divide(int div[],int divisor[], int rem[])
{

int cur=0;
while(true)
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
while(rem[cur]==0 && cur!=rem.length-1)
cur++;
if((rem.length-cur)<divisor.length)
break;
}
return rem;
}
}

OUTPUT :
Enter number of data bits :
7
Enter data bits :
1
0
1
1
0
0
1
Enter number of bits in divisor :
3
Enter Divisor bits :
1
0
1
Dividend (after appending 0's) are : 101100100 CRC code :
101100111
Enter CRC code of 9 bits : 1
0
1
1
0
0
1
0 1 crc bits are : 101100101
Error
THANK YOU. )
BUILD SUCCESSFUL

Viva questions and answers:


1. Define CRC.
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital
networks and storage devices to detect accidental changes to raw data.

2. Define error detection.


Error detection is the detection of errors caused by noise or other impairments during
transmission from the transmitter to the receiver. Error correction is thedetection of errors and
reconstruction of the original, error-free data.

3. List error detecting methods.


There are three main techniques for detecting errors in frames: Parity Check, Checksum and
Cyclic Redundancy Check (CRC).

4. Define parity check.


A parity check is the process that ensures accurate data transmission between nodes during
communication. A parity bit is appended to the original data bits to create an even or odd bit
number; the number of bits with value one.

RESULT :

Thus the error detection/error correction techniques were implemented successfully.

You might also like