CN Lab Manual
CN Lab Manual
CN Lab Manual
CS3591-COMPUTER NETWORKS
NAME :
REGISTER NO :
YEAR : III
SEMESTER : V
ACADEMIC YEAR : 2023-2024(ODD SEM)
BATCH :
1
COMPUTER SCIENCE AND ENGINEERING
Bonafide Certificate
Reg.No……………………
2
INDEX
S. DATE NAME OF THE EXPERIMENT PAG MARKS FACULTY
NO. E SIGNATUR
NO. E
Learn to use commands like tcpdump, netstat,
ifconfig, nslookup and traceroute. Capture ping
and trace route PDUs using a network protocol
1. analyzer and examine.
3
Ex. No: 01 Learn to use commands like tcpdump, netstat, ifconfig, nslookup
Date: and traceroute. Capture ping and trace route PDUs using a
network protocol analyzer and examine.
AIM:
To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
PROCEDURE:
1. Tcpdump
The tcpdump utility allows you to capture packets that flow
within your network to assist in network troubleshooting. The
following are several examples of using tcpdump with different
options. Traffic is captured based on a specified filter.
Options Description
-D Print a list of network interfaces.
-i Specify an interface on which to capture.
-c Specify the number of packets to receive.
-v, -vv, -vvv Increase the level of detail(verbosity).
-w Write captured data to a file.
-r Read captured data from a file.
4
4. Filtering based on source or destination port
To filter based on a
source or destination
port: # tcpdump src
port ftp
# tcpdump dst port http
2. Nslookup
3. Traceroute
Traceroute is a network diagnostic tool used to track the pathway taken by a packet
on an IP network from source to destination. Traceroute also records
the time taken for each hop the packet makes during its route to the
destination.
Traceroute uses Internet Control Message Protocol (ICMP) echo packets with
variable time to live (TTL) values. The response time of each hop is calculated. To
guarantee accuracy, each hop is queried multiple times (usually three times) to
better measure the response of that
particular hop.
tracert www.google.com
5
Result:
Thus the above list of primitive networking commands has been executed successfully.
6
Ex. No: 02
Write a HTTP web client program to download a web page using
Date:
TCP sockets.
AIM
To develop HTTP client java program to download a webpage using TCP sockets.
ALGORITHM:
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 to the web server.
4. Open a file and store the received data into the file.
5. Print content of the file.
6. Close the socket.
7. End the program.
PROGRAM:
import java.io.*;
import java.net.URL;
public class a2_TcpScoket { //classname as same as the filename
7
Output:
Result:
The webpage is successfully downloaded and the contents are displayed.
8
Ex. No: 03 a
Applications using TCP sockets like: Echo client and echo server.
Date:
AIM
To create a java program for implementing socket program of TCP Echo client and
Echo server
ALGORITHM:
PROGRAM:
Echo client program:
import java.io.*;
import java.net.*;
public class a3_Echo_CL{
public static void main(String args[])throws Exception
{
Socket c = null;
DataInputStream usr_inp = null;
DataInputStream din = new DataInputStream(System.in);
DataOutputStream dout = null;
try
{
c=new Socket("127.0.0.1",5678);
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
9
catch(IOException e)
{ }
if(c!=null || usr_inp!=null || dout!=null)
{
String unip;
while((unip=din.readLine())!=null)
{
dout.writeBytes(""+unip);
dout.writeBytes("\n");
System.out.println("\n the echoed message");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}
import java.io.*;
import java.net.*;
public class a3_Echo_SER
{
public static void main(String args[])throws Exception
{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataOutputStream dout=null;
try
{
m=new ServerSocket(5678);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{ }
if(c!=null || usr_inp!=null)
{
while(true)
{
System.out.println("\nMessage from Client...");
String m1=(usr_inp.readLine());
10
System.out.println(m1);
dout.writeBytes(""+m1);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();
}
}
Output:
Client:
hi
Server:
Message from Client...
hi
Result:
Thus the program for implementing TCP Echo client and server is successfully
executed using java program.
11
Ex. No: 03 b
Applications using TCP sockets like: Chat.
Date:
AIM
To create a java program for implementing of TCP chat socket program
ALGORITHM:
PROGRAM:
Talk client:
import java.io.*;
import java.net.Socket;
12
if (c != null || usr_inp != null || dout != null) {
String unip;
System.out.println("\nEnter the message for server:");
while ((unip = din.readLine()) != null) {
dout.writeBytes("" + unip);
dout.writeBytes("\n");
System.out.println("reply");
System.out.println(usr_inp.readLine());
System.out.println("\n enter your message:");
}
System.exit(0);
}
din.close();
usr_inp.close();
c.close();
}
}
Talk server:
import java.io.*;
import java.net.*;
13
unip=din.readLine();
dout.writeBytes(""+unip);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();
}
}
Output:
Client:
Enter the message for server:
hello
reply
hi
enter your message:
Server:
message from client:
hello
enter your message:
hi
message from client:
Result:
Thus the socket program for implementation of TCP talk is successfully executed.
14
Ex. No: 04
Simulation of DNS using UDP sockets.
Date:
AIM
To develop a java program to simulate Domain Name Server using UDP socket.
ALGORITHM:
1. Start the program.
2. Create a socket which binds the Ip address of server and the port address to acquire
3. After establishing connection Client sends the domain name to the Server.
4. Server resolves the Domain Name to IP Address and sends back to Client.
5. Close the socket.
6. End the program.
PROGRAM:
UDP DNS Server:
import java.io.*;
import java.net.*;
15
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
import java.io.*;
import java.net.*;
16
DatagramPacket pack = new DatagramPacket(senddata,senddata.length,
ipaddress,portaddr);
clientsocket.send(pack);
DatagramPacket recvpack =new
DatagramPacket(receivedata,receivedata.length);
clientsocket.receive(recvpack);
Output:
Server:
Press Ctrl + C to Quit
Request for host gmail.com
Client:
Enter the hostname : gmail.com
IP Address: 209.85.148.19
Result:
Thus the Domain Name Server program to convert domain name to IP address is
successfully executed.
17
Ex. No: 05 Use a tool like Wireshark to capture packets and examine the
Date: packets.
Aim:
To use a tool like Wireshark to capture packets and examine the packets.
Wireshark:
Wireshark captures the data coming or going through the NICs on its device by using
an underlying packet capture library. By default, Wireshark captures on-device data only,
but it can capture almost all the data on its LAN if run in promiscuous mode. Currently,
Wireshark uses NMAP’s Packet Capture library(called npcap).
Getting Up and Running: After installation launch Wireshark, approve the administrator or
superuser privileges and you will be presented with a window that looks like this:
This window shows the interfaces on your device. To start sniffing select one
interface and click on the bluefin icon on the top left. The data capture screen has three
panes. The top pane shows real-time traffic, the middle one shows information about the
chosen packet and the bottom pane shows the raw packet data. The top pane shows source
address(IPv4 or IPv6) destination address, source and destination ports, protocol to which
the packet belongs to and additional information about the packet.
18
Since there are a lot of packets going in and out every second, looking at all of them
or searching for one type of packets will be tedious. This is why packet filters are provided.
Packets can be filtered based on many parameters like IP address, port number or protocol
at capture level or at display level. As obvious a display level filter will not affect the packets
being captured.
Some of the general capture filters are:
19
There is also a concept of colouring rules. Each protocol/port/other element is provided a
unique colour to make it easily visible for quick analysis. More details on colouring rules
is here
Plugins are extra pieces of codes that can be embedded into the native Wireshark. Plugins
help in analysis by:
With just the basic capability to see all the traffic going through your device or in your LAN
and the tools and plugins to help you in analysis, you can do a great deal of things with your
device. Like:
Result:
Thus, the packets capturing and examine the packets using a tool like Wireshark was
done and verified.
20
Ex. No: 06 a
Write a code simulating ARP using TCP.
Date:
AIM
To write a java program for simulating ARP protocols using TCP.
ALGORITHM
CLIENT
1. Start the program
2. Using socket connection is established between client and server.
3. Get the IP address to be converted into MAC address.
4. Send this IP address to server.
5. Server returns the MAC address to client.
SERVER
1. Start the program
2. Accept the socket which is created by the client.
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the IP address which is send by the client.
5. Map the IP address with its MAC address and return the MAC address to client.
PROGRAM:
CLIENT:
import java.io.*;
import java.net.Socket;
21
System.out.println("The Physical Address is: "+str);
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
22
Output:
Enter the Logical address(IP):
165.165.80.80
Result:
Thus the program for simulating ARP protocols using TCP is successfully executed.
23
Ex. No: 06 b
Write a code simulating RARP protocols.
Date:
AIM
To write a java program for simulating RARP protocols using TCP.
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.
PROGRAM:
CLIENT:
import java.io.*;
import java.net.*;
24
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.net.*;
25
break;
}
server.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
Enter the Physical address (MAC):
6A:08:AA:C2
Result:
Thus the simulation for RARP protocol using UDP is successfully executed.
26
Ex. No: 07
Study of Network simulator (NS) and Simulation of Congestion
Date: Control Algorithms using NS.
AIM:
To Study of Network simulator (NS).and Simulation of Congestion Control Algorithms
using NS.
• Ns Status
• Periodical release (ns-2.26, Feb 2003)
• Platform support
• FreeBSD, Linux, Solaris, Windows and Mac
Ns unctionalities
Routing, Transportation, Traffic sources,Queuing disciplines, QoS
Wireless
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.
27
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)
28
occurs when one or morepacketsof data travelling across a computer networkfail to
reachtheir destination. Packet loss is distinguished as one of the three main error types
encountered in digital communications; the other two being bit errorand 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
This is the main performance measure characteristic, and most widely used.
Incommunicationnetworks, such asEthernetorpacket radio, throughputor network
throughputis the average rate of successfulmessage delivery over a communication channel.
The throughput is usually measured inbitsper second (bit/s orbps), andsometimes indata
packetsper second or data packets pertime slotThis measure how soon the receiver is able
to get a certain amount of data send by the sender. It is determined as the ratio of the total
data received to the end to end delay. Throughput is an important factor which directly
impacts the network performance
Delay
Delay is the time elapsed while a packet travels from one point e.g., source premise or
network ingress to destination premise or network degrees. The larger the valueof 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 thesystem after being
served. Thus queue length is very important characteristic to determine that how well the
active queue management of the congestion control
algorithm has been working.
RESULT
Thus the study of Network simulator (NS2)was studied.
29
Ex. No: 08
Study of TCP/UDP using simulation tool
Date:
Aim:
Study of TCP/UDP using simulation tool.
PROCEDURE:
To study the performance of TCP (Transmission Control Protocol) and UDP (User
Datagram Protocol) using simulation tools, you can use network simulators like Network
Simulator (NS), ns-3, or OMNeT++ that provide support for simulating these protocols.
Here's an overview of the process:
Network Topology Design:
Start by designing the network topology that you want to simulate. Determine the
number of nodes, their interconnections, and the characteristics of the links (e.g.,
bandwidth, delay, loss rate). Consider the network scenario that best represents your
study, such as a local area network (LAN) or wide area network (WAN).
TCP Header Format:
30
Protocol Configuration:
Configure the simulation environment to use TCP and UDP protocols. Specify
the parameters and settings related to these protocols, such as TCP congestion control
algorithms (e.g., Reno, Cubic) or UDP packet sizes.
Traffic Generation:
Define the traffic patterns and flows that will be generated in the network. Decide
on the types of traffic, such as bulk transfers, video streaming, or real-time
communications. Set the traffic characteristics, such as arrival rates, sizes, and
destinations, to mimic real-world scenarios.
Simulation Execution:
Run the simulation using the chosen simulation tool. During the simulation, the tool
will model the behaviourof TCP and UDP based on the configured parameters and
network conditions. Packets will be sent, routed, and received by the simulated
31
nodes, and the protocols' mechanisms will be employed, such as TCP congestion control
or UDP's best-effort delivery.
Performance Metrics Collection:
Monitor and collect performance metrics during the simulation to evaluate the
TCP and UDP performance. Common metrics include throughput, latency, packet loss rate,
end-to-end delay, fairness,and congestion indicators. The simulation tool should provide
mechanisms to gather these metrics foranalysis.
Analysis and Comparison:
Analyse the collected data to assess the performance of TCP and UDP. Compare their
behaviour under different scenarios, varying network conditions, or congestion levels.
Evaluate the impact of protocol settings, such as window size or timeout values, on the
performance metrics. Identify strength, weaknesses, and trade-offs between TCP and UDP
in the simulated environment.
Validation and Verification:
Validate the simulation results by comparing them with theoretical expectations or
known behaviours of TCP and UDP. If possible, validate the results against real-world
measurements or experiments to ensure the simulation accurately represents the protocol
performance.
Simulation tools like NS, ns-3, or OMNeT-++ provide extensive documentation,
example scenarios, and libraries that facilitate the simulation of TCP and UDP. You can
consult their documentation and resources to learn more about using these tools to study
the performance of TCP and UDP protocols in different network scenarios.
Keep in mind that while simulations provide valuable insights, they may not fully
capture the complexity of real-world networks. Therefore, it's important to complement the
simulation results with real-world experiments whenever possible to validate and verify the
findings.
Result:
Thus, the above study of TCP/UDP protocol has been studied and understood properly.
32
Ex. No: 09 a
Simulation of Distance Vector Routing algorithm.
Date:
AIM:
To implement the concept of distance vector routing using NetSim.
ALGORITHM:
DESCRIPTION:
To begin with the experiment, open NetSim
Click on Programming from the file panel and select Distance Vector Routing.
When you select the User mode, you have to write your own program in C/C+
+, compile and link to NetSim software for validation.
34
OUTPUT:
RESULT:
Thus the concept of Distance Vector Routing was implemented successfully and the output
was verified.
35
Ex. No: 09 b
Simulation of Link State Routing algorithm.
Date:
AIM:
To implement the concept Link state routing Algorithm using a Netsim.
INTRODUCTION:
The router is one of the main devices used in a wide area network. The main
task of the router is routing. It forms the routing table and delivers the packets
depending upon the routes in the table – either directly or via an intermediate
device (perhaps another router).
Link state algorithm is a method used to find the shortest path between a
source router
and a destination router based on the distance and route the packets through
that route.
ALGORITHM:
Click on Programming from the file panel and select Link State Routing
36
When you select the User mode, you have to write your own program in
C/C++, compile and link to NetSim software for validation.
Click on the button for details on how to proceed with your own
RESULT:
Thus the concept of Link State Routing was implemented using netsim and output was
verified.
37
Ex. No: 10
Simulation of an error correction code (like CRC).
Date:
AIM:
To write a c program to implement the concept of Cyclic Redundancy Check(CRC).
ALGORITHM:
Program:
#include<stdio.h>
#include<string.h>
#include<conio.h>
// length of the generator polynomial
#define N strlen(gen_poly)
// data to be transmitted and received
char data[28];
// CRC value
char check_value[28];
// generator polynomial
char gen_poly[10];
// variables
int data_length,i,j;
void CRC(void);
// function that performs XOR operation
void XOR( )
{
// if both bits are the same, the output is 0
// if the bits are different the output is 1
for(j = 1;j < N; j++)
check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');
}
// Function to check for errors on the receiver side
void receiver()
38
{
// get the received data
printf("Enter the received data: ");
scanf("%s", data);
printf("\n-----------------------------\n");
printf("Data received: %s", data);
// Cyclic Redundancy Check
CRC( );
// Check if the remainder is zero to find the error
for(i=0;(i<N-1) && (check_value[i]!='1');i++);
if(i<N-1)
printf("\nError detected\n\n");
else
printf("\nNo error detected\n\n");
}
void CRC()
{
// initializing check_value
for(i=0;i<N;i++)
check_value[i]=data[i];
do{
// check if the first bit is 1 and calls XOR function
if(check_value[0]=='1')
XOR();
// Move the bits by 1 position for the next computation
for(j=0;j<N-1;j++)
check_value[j]=check_value[j+1];
// appending a bit from data
check_value[j]=data[i++];
}while(i<=data_length+N-1);
// loop until the data ends
}
int main()
{
// get the data to be transmitted
printf("\nEnter data to be transmitted: ");
scanf("%s",data);
printf("\n Enter the Generating polynomial: ");
// get the generator polynomial
scanf("%s",gen_poly);
// find the length of data
data_length=strlen(data);
// appending n-1 zeros to the data
for(i=data_length;i<data_length+N-1;i++)
data[i]='0';
printf("\n----------------------------------------");
39
// print the data with padded zeros
printf("\n Data padded with n-1 zeros : %s",data);
printf("\n----------------------------------------");
// Cyclic Redundancy Check
CRC();
// print the computed check value
printf("\nCRC or Check value is : %s",check_value);
// Append data with check_value(CRC)
for(i=data_length;i<data_length+N-1;i++)
data[i]=check_value[i-data_length];
printf("\n----------------------------------------");
// printing the final data to be sent
printf("\n Final data to be sent : %s",data);
printf("\n----------------------------------------\n");
// Calling the receiver function to check errors
receiver();
getch();
return 0;
}
Output:
Result:
Thus the c program to implement the concept of Cyclic Redundancy Check(CRC) was
successfully executed and output was verified
40