0% found this document useful (0 votes)
52 views34 pages

CS3591 - Computer Networks Record

The document outlines various network commands and programming exercises related to TCP and UDP sockets. It includes detailed instructions for using commands like tcpdump, netstat, ifconfig, nslookup, and tracert, as well as Java programs for an HTTP web client, echo client/server, TCP chat program, and a DNS simulation using UDP. Each section concludes with successful execution results for the respective programs.

Uploaded by

anirudhappu45
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)
52 views34 pages

CS3591 - Computer Networks Record

The document outlines various network commands and programming exercises related to TCP and UDP sockets. It includes detailed instructions for using commands like tcpdump, netstat, ifconfig, nslookup, and tracert, as well as Java programs for an HTTP web client, echo client/server, TCP chat program, and a DNS simulation using UDP. Each section concludes with successful execution results for the respective programs.

Uploaded by

anirudhappu45
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/ 34

EX NO: 1 Basic Commands

DATE:

AIM:
Learn to use commands like tcpdump, netstat, ifconfig, nslookup and tracert. Capture ping
and trace route PDUs using a network protocol analyzer and examine.

Commands:

1. Netstat:

 Netstat is a common command line TCP/IP networking available in most

versions of Windows, Linux, UNIX and other operating systems.

 Netstat provides information and statistics about protocols in use and current TCP/IP
network connections. The Windows help screen (analogous to a Linux or UNIX for

netstat reads as follows: displays protocol statistics and current TCP/IP network
connections.

2. TCP DUMP:

Display traffic between 2 hosts:

 To display all traffic between two hosts (represented by variables host1 and host2): #
tcpdump host host1 and host2
 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

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 Filtering based on source or destination port To filter based on a

source or destination Port.

# tcpdump src port ftp # tcpdump dst port http.

3. Ipconfig:

 In Windows, ipconfig is a console application designed to run from the Windows

command prompt. This utility allows you to get the IP address information of a

Windows computer. Using ipconfig

 From the command prompt, type ipconfig to run the utility with default options. The

output of the default command contains the IP address, network mask, and gateway for all

physical and virtual network adapter.

#ipconfig
4.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.

 The nslookup command is a powerful tool for diagnosing DNS problems. You know you're
experiencing a DNS problem when you can access a resource by specifying its IP address but
not its DNS name.

#nslookup

5.Trace route:
 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.

 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.
Traceroute sends packets with TTL values that gradually increase from packet to packet,
starting with TTL value of one. Routers decrement TTL values of packets by one when
routing and discard packets whose TTL value has reached zero, returning the ICMP error
message ICMP Time Exceeded.For the first set of packets, the first router receives the packet,
decrements the TTL value and drops the packet because it then has TTL value zero.

 The router sends an ICMP Time Exceeded message back to the source. The next set of
packets are given a TTL value of two, so the first router forwards the packets, but the second
 router drops them and replies with ICMP Time Exceeded.

 Proceeding in this way, traceroute uses the returned ICMP Time Exceeded messages to
build a list of routers that packets traverse, until the destination is reached and returns an
ICMP Echo Reply message.

 With the tracert command shown above, we're asking tracert to show us the path from the
local computer all the way to the network device with the hostname.

6.Ping:

The ping command sends an echo request to a host available on the network. Using this command,
you can check if your remote host is responding well or not. Tracking and isolating hardware and
software problems.The ping command operates by sending Internet Control Message Protocol
(ICMP) Echo Request messages to the destination computer and waiting for a response.

RESULT:

Thus the various networks commands like tcpdump, netstat, ifconfig, nslookup and tracert, ping
are executed successfully.
EX NO: 2 HTTP web client program to download a web page using
DATE: TCP sockets

AIM:

To write a HTTP web client program to download a web page using TCP sockets.
PROCEDURE:
 TCP connection with the web server using a Socket. We then use the socket's input and
output streams to send an HTTP GET request and receive the server's response.
 Replace "example.com" with the actual domain name or IP address of the web page you want
to download. You can also modify the port and path variables as needed.
 Keep in mind that this is a basic example, and it assumes that the web server is listening on
the standard HTTP port (port 80).
 In a real-world scenario, you might need to handle redirects, handle different response
codes, handle chunked encoding, and so on.

PROGRAM:
import java.io.BufferedReader;
import java.io.IOException;
import
java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class WebPageDownloader
{
public static void main(String[] args)
{
String host = "example.com"; int port = 80;
String path = "/";
try (Socket socket = new Socket(host, port);
PrintWriter requestWriter = new PrintWriter(socket.getOutputStream());
BufferedReader responseReader = new BufferedReader(new
InputStreamReader(socket.getInputStream)))
// Send HTTP GET request requestWriter.println("GET " + path + "
HTTP/1.1"); requestWriter.println("Host: " + host);
requestWriter.println("Connection: close");
requestWriter.println();
requestWriter.flush();
// Read and print the response
String line;
while ((line = responseReader.readLine()) != null)
{ System.out.println(line);

}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

OUT PUT:
Successfully Downloaded.

RESULT:
Thus the above program HTTP web client program to download a web page using TCP sockets
has been executed successfully.
EX NO 3 (a) Applications using Tcp Sockets

DATE: Echo client and echo server

AIM:
Write a program for Echo Client and Echo server using TCP sockets.

PROCEDURE:

 Compile both EchoServer.java and EchoClient.java using javac.


 Start the server by running java EchoServer in one terminal or command prompt window.
 Start the client by running java EchoClient in another terminal or command
prompt window.
 Type messages in the client terminal and press Enter to send them to the server.
 The server will echo the messages back to the client, and the client will display
the server's response.
 Type "exit" in the client terminal to quit the program.
The Echo server listens for incoming client connections and echoes back any
messages received from the client. The Echo client connects to the server and allows the user
to input messages, which are then sent to the server. The server echoes the messages back to
the client, which displays the server's response.
PROGRAM:

Echo client program:


import java.io.*;
import
java.net.*;
import
java.util.*;
public class
echoclient
{
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());
}
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
echoserver
{
public static void main(String args[])throws Exception
{
Server Socket m=null;Socket c=null;
DataInputStream usr_inp=null;
DataInputStream din=new
DataInputStream(System.in);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)
{
String unip;while(true)
{
System.out.println("\nMessage from
Client...");String
m1=(usr_inp.readLine());
System.out.println(m1);
dout.writeBytes(""+m1);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();
c.close();

}
}

OUTPUT
Client:
C:\Program Files\Java\jdk1.6.0\bin>java
echoclienthello
The echoed
messagehello
Enter your
message
Server:
C:\Program Files\Java\jdk1.6.0\bin>java
echoserverMessage from Client...
hello

RESULT:

Thus the program for implementing TCP Echo client and server is successfully executed using
java program.
EXP NO: 3 b) Implementation Of TCP chat program
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
responsemessage back to client socket.
Step 6:Client socket in term reads message from server socket and write reply message
back toserver 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.*;
public class
talkclient
{
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)
{}
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 talkserver
{
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:");
unip=din.readLine(); dout.writeBytes(""+unip);
dout.writeBytes("\n");
}
}
dout.close();
usr_inp.close();

c.close();
}
}

OUTPUT
Client:
C:\Program Files\Java\jdk1.6.0\bin>java talkclient
Enter your message:
hai reply hello
enter your message:
Server:
C:\Program Files\Java\jdk1.6.0\bin>java
talkservermessage from client:
hai
enter your message:
hello
message from client:

RESULT:

Thus the socket program for implementation of TCP talk is successfully executed .
EXP NO: 4 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
Serverimport
java.io.*;
import
java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str)) return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com",
"facebook.com"}; String[] ip = {"68.180.206.184",
"209.85.148.19","80.168.92.140", "69.63.189.16"};
System.out.println("Press Ctrl + C to
Quit");while (true)
{
DatagramSocket serversocket=new
DatagramSocket(1362);byte[] senddata = new
byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new DatagramPacket(receivedata,
receivedata.length);serversocket.receive(recvpack);
String sen = new
String(recvpack.getData()); InetAddress
ipaddress = recvpack.getAddress();int
port = recvpack.getPort();
String capsent;
System.out.println("Request for host "
+ sen);if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts,
sen)];else capsent = "Host
Not Found";
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}}}

//UDP DNS Client


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

Server

javacudpdnsserver.javajava
udpdnsserver
Press Ctrl + C to Quit Request for host yahoo.com
Request for host
cricinfo.com
Request for host
youtube.com

Client

javac udp dnsclient. Java


java udp dns client

Enter the hostname :


yahoo.comIP
Address:
68.180.206.184
java udpdnsclient
Enter the hostname :
cricinfo.comIP
Address:
80.168.92.140
java udpdnsclient
Enter the hostname :
youtube.comIP
Address: Host Not
Found

RESULT
Thus the Domain Name Server program to convert domain name to IP address is successfully
executed.
EXP NO: 5 Wireshark to capture packets and examine the packets
DATE:

AIM:

Use a tool wire shark to capture a packets and examine the packets.

PROCEDURE:
Wireshark is a powerful network protocol analyzer that allows you to capture and
analyze network packets. Here's how you can use Wireshark to capture packets and examine them:
1. Start Wireshark on your machine.
2. Select the network interface that you want to capture packets from. For example, if you're
using Wi-Fi, select the Wi-Fi interface. If you're using Ethernet, select the Ethernet
interface.
3. Click on the "Start" button to begin capturing packets.
4. Run your DNS server program (as described in the previous response) or any other
network program that generates network traffic.
5. Perform the actions or execute the program that generates the network traffic you want to
capture and examine. For example, if you're using the DNS server program, you can use
the nslookup command or any other DNS client program to perform DNS queries.
6. Once you're done generating the network traffic, go back to Wireshark and click on the
"Stop" button to stop capturing packets.
7. Wireshark will display a list of captured packets in its main window. You can scroll
through the list to view individual packets.
8. You can select a packet from the list to examine its details in the packet details pane.
Wireshark provides detailed information about each packet, including source and
destination IP addresses, port numbers, protocols, and packet payload.
9. To filter the captured packets based on specific criteria, you can use the filter box at the
top of the Wireshark window. For example, you can filter packets by protocol, source or
destination IP address, port number, or any other field.
10. You can right-click on a packet in the list to perform various actions, such as following a
TCP stream, analyzing the packet in more detail, or exporting the packet data for further
analysis.
Wireshark provides a wide range of features and capabilities for packet analysis,
including the ability to dissect and decode various protocols, perform statistical analysis, apply
filters, and much more. It's a valuable tool for examining network packets and understanding the
communication between different network entities.

RESULT

Thus the tool wire shark to capture a packets and examine the packets was successfully
executed.
EX NO:6 Simulating ARP/RARP
protocol
DATE:

AIM:
To write a program to simulate ARP/RARP protocol.
PROCEDURE:
In this simulation, we have a simple ARPTable class that stores IP-MAC address
mappings. The ARPProtocolSimulator class demonstrates the usage of this table to simulate ARP
and RARP lookups.
To run the simulation, simply compile and execute the ARPProtocolSimulator.java file. It
will perform an ARP lookup by querying the ARP table for a given IP address and display the
corresponding MAC address if found. It will also perform a RARP lookup by searching the ARP
table for a given MAC address and display the corresponding IP address if found.
Note that this is a basic simulation for educational purposes and doesn't involve actual
network communication. In real-world scenarios, ARP and RARP involve communication
between devices on a network to resolve IP and MAC addresses.
In this simulation, we have a simple RARP Table class that stores MAC-IP address
mappings.
The RARP Protocol-simulator class demonstrates the usage of this table to simulate a RARP lookup.
To run the simulation, simply compile and execute the RARP Protocol-simulator.java file.
It will perform a RARP lookup by querying the RARP table for a given MAC address and
display the corresponding IP address if found.
PROGRAM:
a) ARP PROTOCOL
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); clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}

b) RARP PROTOCOL:
import
java.util.HashMap;
import
java.util.Map;
class RARPTable
{
private Map<String, String>
table; public RARPTable()
{
this.table = new HashMap<>();
}
public void addEntry(String macAddress, String ipAddress)

{
table.put(macAddress, ipAddress);
}
public String lookup(String macAddress)
{
return table.get(macAddress);
}
}
class RARPProtocolSimulator
{
public static void main(String[] args)
{
RARPTable rarpTable = new RARPTable();
rarpTable.addEntry("00:11:22:33:44:55", "192.168.0.1");
rarpTable.addEntry("AA:BB:CC:DD:EE:FF", "192.168.0.2");
// Simulate RARP lookup
String macAddress = "00:11:22:33:44:55";
String ipAddress =
rarpTable.lookup(macAddress); if
(ipAddress != null)
{
System.out.println("RARP Lookup - MAC: " + macAddress + ", IP: " + ipAddress);
}
else
{
}

System.out.println("RARP Lookup - MAC: " + macAddress + ", IP not found");}


}

OUT PUT:

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

RESULT:

Thus the above program to simulate ARP/RARP protocol has been executed successfully.
EX NO: 7 Study of Network simulator
(NS)
DATE:

AIM:
Study of Network simulator (NS) and Simulation of Congestion Control Algorithms
using NS.
PROCEDURE:
Network Simulator (NS) is a discrete event network simulation tool used for simulating
and evaluating the performance of computer networks. It allows researchers and network
engineers to simulate various network scenarios, protocols, and algorithms to understand their
behaviour and performance under different conditions.
NS is widely used for academic and research purposes to explore network concepts, test
new protocols, study network behaviour, and evaluate network performance. It provides a
flexible and extensible environment for designing network topologies, defining network
parameters, and running simulations.
Some key features of NS include:
 Network Topology: NS allows users to create complex network topologies with nodes,
links, and routers. It supports various network types, including wired and wireless
networks.
 Protocol Simulation: NS provides a library of network protocols that can be simulated,
such as TCP/IP, UDP, routing protocols (e.g., OSPF, BGP), and congestion control
algorithms.
 Traffic Generation: NS allows users to generate traffic patterns and flows to simulate
realistic network traffic scenarios. This enables the evaluation of network performance
and congestion control algorithms under different traffic conditions.
 Event-driven Simulation: NS operates on an event-driven model, where events (such as
packet arrivals, link failures, or timer expirations) are scheduled and processed based on
simulation time. This allows for fine-grained control and synchronization of network
events.
 Performance Metrics: NS provides built-in tools for collecting and analysing performance
metrics during simulations. These metrics can include throughput, latency, packet loss,
congestion indicators, and more.
Now, let's discuss simulating Congestion Control Algorithms using NS. Congestion control
algorithms aim to manage network congestion and optimize network performance by regulating
the rate at which data is transmitted. NS enables researchers to simulate and evaluate different
congestion control algorithms and compare their performance in various network scenarios.
To simulate congestion control algorithms using NS, you would typically follow these
steps: Design the network topology:
Define the network topology you want to simulate, including nodes, links, and their properties.
Implement the congestion control algorithm:
Write the code or configure the congestion control algorithm within NS. NS provides a
programming interface to implement custom congestion control algorithms or use existing ones
available in the library.
Define traffic patterns:
Specify the traffic patterns and flows that will be generated in the network. This can
include different types of traffic, such as bulk data transfers, real-time traffic, or background
traffic.
Run the simulation: Start the simulation and let NS simulate the network behaviour over
time. NS will handle events, process packets, and simulate the congestion control algorithm's
actions based on the defined network conditions and traffic patterns.
Collect and analyse results:
Monitor and collect performance metrics during the simulation, such as throughput,
delay, packet loss, and congestion indicators. Analyse the results to evaluate the effectiveness and
efficiency of the congestion control algorithm under different scenarios.
Iterate and refine:
Based on the simulation results, refine the congestion control algorithm or experiment with different
parameter settings to optimize network performance.
NS provides extensive documentation, tutorials, and examples to help users get started
with simulating congestion control algorithms and exploring network behaviour. You can refer to
the official NS documentation and resources for detailed guidance on using NS for congestion
control simulations.
Keep in mind that simulating congestion control algorithms in NS provides a controlled
environment for evaluation and comparison. Real-world network deployments may introduce
additional complexities and factors that can impact the algorithm's performance. Therefore, it's
essential to validate the simulation results with real-world experiments when possible.

RESULT:

Thus the above study of Network Stimulator has been studied and understood properly.
EX NO: 8 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:


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 behaviour of TCP and UDP based on the configured parameters and network
conditions. Packets will be sent, routed, and received by the simulated 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 for analysis.
Analysis and Comparison:
Analyse the collected data to assess the performance of TCP and UDP. Compare their
behavior 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 strengths, 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.

RESULT:
Thus the above study of TCP/UDP protocol has been studied and understood properly.
EX NO: 9(a) Simulation of Distance Vector
Algorithm
DATE:

AIM:
To simulate the Distance Vector routing algorithm
PROCEDURE:
To simulate the Distance Vector routing algorithm, you can use network simulation tools
like Network Simulator (NS), ns-3, or OMNeT++. Here's a step-by-step guide on simulating the
Distance Vector algorithm:
Network Topology Design:
Design the network topology you want to simulate. Define the nodes and links in the
network, including their properties such as bandwidth, delay, and reliability. Consider the size
and complexity of the network to reflect the scenario you want to study.

Node Configuration:
Configure each node in the network to use the Distance Vector routing algorithm. Each
node should maintain its routing table and exchange routing updates with its neighboring nodes.

Routing Table Initialization:


Initialize the routing tables of each node in the network. Set the initial costs to
neighboring nodes (directly connected links) and infinity for all other nodes.

Routing Update Exchange:


Implement the routing update exchange process. Each node should periodically send its
routing table to its neighboring nodes and receive routing updates from them. The updates
contain information about the costs to reach different destinations.

Distance Vector Calculation:


Implement the distance vector calculation mechanism. Each node should calculate the
shortest path to each destination based on the received routing updates and update its routing
table accordingly.

Routing Table Updates:


Whenever a node's routing table is updated, it should inform its neighboring nodes about
the changes by sending routing updates.
Simulation Execution:
Run the simulation using the selected simulation tool. The simulation will execute the
Distance Vector algorithm, update the routing tables, and forward packets based on the calculated
paths.Traffic Generation:

Define the traffic patterns and flows to be used in the simulation. Generate traffic
between nodes to simulate realistic network conditions. Specify the type, volume, and source-
destination pairs of the traffic flows based on your study objectives.
Performance Metrics Collection:
Monitor and collect performance metrics during the simulation to evaluate the Distance
Vector algorithm's performance. Common metrics include routing convergence time, packet
delivery ratio, end- to-end delay, routing table size, and network utilization. The simulation tool
should provide mechanisms to collect these metrics for analysis.
Analysis and Comparison:
Analyze the collected data to assess the performance of the Distance Vector algorithm.
Compare its behavior under different scenarios, network sizes, and traffic patterns. Evaluate its
convergence time, routing stability, scalability, and ability to handle network changes.
Validation and Verification:
Validate the simulation results by comparing them with theoretical expectations or known
behaviors of the Distance Vector algorithm. If possible, validate the results against real-world
measurements or experiments to ensure the simulation accurately represents the algorithm's
performance.
Simulation tools like NS, ns-3, or OMNeT++ provide libraries, modules, and example
scenarios to facilitate the simulation of the Distance Vector algorithm. You can refer to their
documentation and resources for specific guidance on using these tools for Distance Vector
simulations.
Remember that simulations provide insights into the behavior of routing algorithms but
may not fully capture the complexity of real-world networks. Therefore, it's important to
complement simulation results with real-world experiments whenever possible to validate and
verify the findings.

RESULT:

Thus the above simulation program has been executed successfully.


EX NO: 9(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 thatroute.

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 cumulativecost.
6. Repeat steps 3 to 5 until every router becomes permanent. DescriptionTo 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.
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 thestudents)


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.
EX NO: 10 Simulation of an error correction code
(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:
/*Cyclic Redundancy check*/
#include<stdio.h> #include<string.h>
// length of the generator polynomial#define N
strlen(gen_poly)
// data to be transmitted and receivedchar
data[28];
// CRC value
char check_value[28];
// generator polynomialchar
gen_poly[10];
// variables
int data_length,i,j;void
CRC(void);
// function that performs XOR operationvoid XOR( )
{
// if both bits are the same, the output is 0
// if the bits are different the output is 1for(j = 1;j <
N; j++)
check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');
}
// Function to check for errors on the receiver sidevoid
receiver()
{
// get the received data printf("Enter the
received data: ");scanf("%s", data);
printf("\n \n");printf("Data
received: %s", data);
// Cyclic Redundancy Checkcrc( );
// 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 ");
// print the data with padded zeros
printf("\n Data padded with n-1 zeros : %s",data);printf("\n
");
// Cyclic Redundancy Checkcrc();
// 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 errorsreceiver();
return 0;
}

OUTPUT
Enter data to be transmitted: 1001101 Enter the
Generating polynomial: 1011

Data padded with n-1 zeros : 1001101000


CRC or Check value is : 101
Final data to be sent : 1001101101
Enter the received data: 1001101101

Data received: 1001101101No error detected

RESULT:
Thus the c program to implement the concept of Cyclic Redundancy Check(CRC) was
successfully executed and output was verified.

You might also like