CN Lab Manual

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

KATHIR COLLEGE OF ENGINEERING

Approved by AICTE / Affiliated to Anna University


Accredited by NAAC with ‘A+’ Grade
Neelambur, Coimbatore–641062

COMPUTER SCIENCE AND ENGINEERING

CS3591-COMPUTER NETWORKS

NAME :
REGISTER NO :
YEAR : III
SEMESTER : V
ACADEMIC YEAR : 2023-2024(ODD SEM)
BATCH :

1
COMPUTER SCIENCE AND ENGINEERING

Bonafide Certificate

This is to certify that the record work for CS3591-

COMPUTER NETWORKS is the bonafide record of work done by


Mr./Ms. .……………………………………………

Reg.No……………………

in V Semester of B.E Computer Science and Engineering during the academic


year 2023– 2024(ODD SEM).

Staff in-Charge Head of the Department

Submitted for the Practical Examination held on …………………

Internal Examiner External Examiner

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.

2. Write a HTTP web client program to download a


web page using TCP sockets.

Applications using TCP sockets like:


a) Echo client and echo server
3.
b) Chat

4. Simulation of DNS using UDP sockets.

5. Use a tool like Wireshark to capture packets


and examine the packets
6. a)Write a code simulating ARP protocols
b)Write a code simulating 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.
a)Simulation of Distance Vector Routing
algorithm.
9.
b)Simulation of Link State Routing algorithm.

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

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.

Many other options and arguments can be used with tcpdump.


The following are some specific examples of the power of the
tcpdump utility.
1. Display traffic between 2 hosts
To display all traffic between two hosts (represented by
variables host1 and host2): # tcpdump host host1 and host2

2. Display traffic from a source or destination host only


To display traffic from only a source (src) or
destination (dst) host: # tcpdump src host
# tcpdump dst host

3. Display traffic for a specific protocol

Provide the protocol as an argument to display only traffic for a specific


protocol, for example tcp, udp, icmp, arp:
# tcpdump protocol
For example to display traffic
only for the tcp traffic : #
tcpdump tcp

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

The nslookup (which stands for name server lookup) command is a


network utility program used to obtain information about internet
servers. It finds name server information for domains by querying
the Domain Name System.

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

public static void main(String[] args) {


try {
String filename = "java_programming.jpg";
String website =
"https://www.tutorialspoint.com/java/images/"+ filename;
URL url = new URL(website);
InputStream inputStream = url.openStream();
OutputStream outputStream = new FileOutputStream(filename);
byte[] buffer = new byte[2048];
int length = 0;
while ((length=inputStream.read(buffer)) != -1) {
System.out.println("Buffer Read of length: " + length);
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
}

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:

Step 1: Start the program.


Step 2: Create the client and server socket.
Step 3: Bind the server address in the client socket.
Step 4: Send message from client socket to server socket.
Step 5: Server socket reads the message from client socket display it and rewrite back to
client socket.
Step 6: Client socket display the echoed message from server socket.
Step 7: Stop the program.

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

Echo server program:

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

the echoed message


hi

enter your message

Server:
Message from Client...
hi

Message from Client...

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:

Step 1: Start the program.


Step 2:Create the client and server socket.
Step 3: Bind the server address in the client socket.
Step 4: Send message from client socket to server socket.
Step 5: Server socket reads the message from client socket , display it and give response
message back to client socket.
Step 6: Client socket in term reads message from server socket and write reply message
back to server socket.
Step 7: Repeat this above procedure until user enters exit message.
Step 8: Stop the program.

PROGRAM:
Talk client:
import java.io.*;
import java.net.Socket;

public class b3_Talk_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", 1234);
usr_inp = new DataInputStream(c.getInputStream());
dout = new DataOutputStream(c.getOutputStream());
} catch (IOException e) {
}

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

public class b3_Talk_SER {


public static void main(String args[])throws Exception
{
ServerSocket m=null;
Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new DataInputStream(System.in);
DataOutputStream dout=null;
try
{
m=new ServerSocket(1234);
c=m.accept();
usr_inp=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(IOException e)
{ }
if(c!=null||usr_inp!=null)
{
String unip;
while(true)
{
System.out.println("\nmessage from client:");
String m1=usr_inp.readLine();
System.out.println(m1);
System.out.println("enter your message:");

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

public class a4_DNS_UDP_SER {


private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str))
return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com",
"facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140",
"69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");
while (true)
{

15
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];

DatagramPacket recvpack = new DatagramPacket(receivedata,


receivedata.length);
serversocket.receive(recvpack);

String sen = new String(recvpack.getData());


InetAddress ipaddress = recvpack.getAddress();

int port = recvpack.getPort();


String capsent;
System.out.println("Request for host " + sen);
if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts, sen)];
else capsent = "Host Not Found";
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket (senddata,
senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}
}
}

UDP DNS Client:

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

public class a4_DNS_UDP_CL {


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

16
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();
}
}

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:

• host (capture the traffic through a single target)


• net( capture the traffic through a network or sub-network). “net” can be prefixed
with “src” or “dst” to indicate whether the data coming from or going to the target
host(s).)
• port (capture the traffic through or from a port). “port” can be prefixed with “src” or
“dst” to indicate whether the data coming from or going to the target port.
• “and”, “not” and “or” logical connectives.(Used to combine multiple filters together).
There are some more basic filters and they can be combined very creatively. Another range
of filters, display filters are used to create abstraction on captured data. These basic
examples should provide a basic idea of their syntax:

• tcp.port==80/udp.port==X shows the tcp/udp traffic at port X.


• http.request.uri matches “parameter=value$” shows packets that are HTTP requests
at the application layer level and their URI ends with a parameter with some value.
• The logical connective and or and not work here too.
• ip.src==192.168.0.0/16 and ip.dst==192.168.0.0/16 will show traffic to and from
workstations and servers.

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:

• Showing parameter specific statistics and insights.


• Handling capture files and issues related to their formats.
• Collaborating with other tools and frameworks to set up an all-in-one network
monitoring solution.

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:

• Troubleshooting Internet connectivity problems with your device or WiFi.


• Monitoring your device for unwanted traffic that may be an indication of a malware
infection.
• Testing the working of your application that involve networking.
• Using it to just understand how computer networks work.

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;

public class a6_ARP_CL {


public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",1122);
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();

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

public class a6_ARP_SER {


public static void main(String args[])
{
try
{
ServerSocket obj=new
ServerSocket(1122);
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();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

22
Output:
Enter the Logical address(IP):

165.165.80.80

The Physical Address is: 6A:08:AA:C2

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

public class b6_RARP_CL {


public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1"); byte[]
sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the Physical address (MAC):");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,1309);

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

public class b6_RAAP_SER {


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

25
break;
}
server.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Output:
Enter the Physical address (MAC):

6A:08:AA:C2

The Logical Address is(IP): 165.165.80.80

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.

NET WORK SIMULATOR (NS2)


• Ns overview
• Ns programming: A Quick start
• Case study I: A simple Wireless network
• Case study II: Create a new agent in Ns
Ns overview

• Ns Status
• Periodical release (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)

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

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:

UDP 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.

DISTANCE VECTOR ROUTING:

Distance Vector Routing is one of the routing algorithms used in a Wide


Area Network for computing shortest path between source and
destination.
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).
Each router initially has information about its all neighbors (i.e., it is
directly connected). After a period of time, each router exchanges its routing
table among its neighbors. After certain number of exchanges, all routers
will have the full routing information about the area of the network.
After each table exchange, router re computes the shortest path
between the routers.
The algorithm used for this routing is called Distance Vector Routing.

ALGORITHM:

• Repeat the following steps until there is no change in the


routing table for all routers.
1. Take the Next Router routing table and its neighbor routing table.
2. Add the router entry that is not in your own routing table,
but exists in any one of the other routing tables. If the
new router entry exists in more than one neighbor, then
find the minimum cost among them. The minimum cost
value details are taken as a new entry: such as source
router, intermediate router, destination router and cost
value, etc.
3. Update the source router routing table cost value if
both the destination router and the intermediate router
field value have the same value as any one of the
neighbors’ routing entry.
4. Update the source router’s routing table entry with
the new advertised one if the intermediate router
value in the source table is not same, but the cost
value is greater than the its neighbor’s entry.
5. Write the next stage of routing table into the file. Repeat
33
steps 1 to 5 for all routers.

Check whether any changes are made in any of the routers. If


yes, then repeat the above steps, otherwise, quit the
process

DESCRIPTION:
To begin with the experiment, open NetSim

Click on Programming from the file panel and select Distance Vector Routing.

The scenario will be obtained as shown below. Follow the steps.

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 to view the file path.

Continue with the steps as given for sample mode.

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:

1. Start with the router: the root of the tree


2. Assign a cost of 0 to this router and make it the first permanent router.
3. Examine each neighbor router of the router that was the last permanent
router.
4. Assign a cumulative cost to each router and make it temporary.
5. Among the list of temporary routers
5. a. Find the router with the smallest cumulative cost and make it
permanent.
5. b. If a router can be reached from more than one direction
5. b.1. Select the direction with the shortest
cumulative cost.
2. Repeat steps 3 to 5 until every router becomes permanent.
Description To begin with the experiment, open NetSim

Click on Programming from the file panel and select Link State Routing

The scenario will be obtained as shown below. Follow the steps.

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

code. Click on the button to view the file path.

Continue with the steps as given for sample mode.

Inference (to be filled up by the


students)
Here, Router 1 is taken as the source and Router 3 as the destination. The paths
are connected with input as the distance. The figure indicated in red line shows the
shortest path.

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:

STEP 1: Start the program.


STEP 2: Get the input binary data and divisor bits from the user
STEP 3: Add divisor length minus one zero’s at the end of binary input data bits.
STEP 4: Divide input binary data bits with divisor bits using module XOR format.
STEP 5: Remainder bits are taken as CRC bits and replace the added zero in data
bits with the CRC code to make the transmitted data bits.
STEP 6: In receiver side ,divide the received data bits a (Data + CRC) with thesame
divisor. If remainder is zero accept (no error) or reject (Error detected).
STEP 7: Stop the program.

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

You might also like