Cs3591-Computer-Networks-Lab DEC 2024

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

INDEX

S.NO DATE LIST OF EXPERIMENTS PAGE NO MARKS SIGN


1 Basic Commands
2 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 Simulating ARP /RARP
protocols
7 Study of Network simulator (NS)
and Simulation of Congestion
Control Algorithms using NS
8 Study of TCP/UDP performance
using Simulation tool
9 Simulation of Distance Vector/
Link State Routing algorithm
10 Simulation of an error correction
code (like CRC)
EX NO: 1 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. TCPDUMP:

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. Determining the status of the
network and various foreign hosts. The ping command is usually used as a simple way to
verify that a computer can communicate over the network with another computer or
network device. 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.getInputStrea
m())))
{

// 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:

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:
a) Echo Server.java:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class EchoServer
{
public static void main(String[] args)
{
int port = 12345;
try (ServerSocket serverSocket = new ServerSocket(port))
{
System.out.println("EchoServer is listening on port " + port);
while (true)
{
Socket clientSocket = serverSocket.accept();
System.out.println("Client connected: " + clientSocket.getInetAddress().
getHostAddress());
// Start a new thread to handle the client
Thread clientThread = new Thread(() ->
{
try (BufferedReader reader = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
PrintWriter writer = new PrintWriter(clientSocket.getOutputStream(),
true))
{
String line;
while ((line = reader.readLine()) != null) {
System.out.println("Received from client: " + line);
writer.println("Echo: " + line);
}
}
catch (IOException e)
{
e.printStackTrace();
}
System.out.println("Client disconnected: " +

clientSocket.getInetAddress().getHostAddress());
}
clientThread.start();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

OUTPUT
Server
C:\Program Files\Java\jdk1.5.0\bin>javac EServer.java
C:\Program Files\Java\jdk1.5.0\bin>java EServer
C:\Program Files\Java\jdk1.5.0\bin>
Client
C:\Program Files\Java\jdk1.5.0\bin>javac EClient.java
C:\Program Files\Java\jdk1.5.0\bin>java EClient
Client: Hai Server
Server:Hai Server
Client: Hello
Server:Hello
Client:end
Server:end
Client:ds
Socket Closed!
b) Echo Client.java:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class EchoClient
{
public static void main(String[] args)
{
String serverAddress = "localhost";
int port = 12345;
try (Socket socket = new Socket(serverAddress, port);
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
Scanner scanner = new Scanner(System.in));
{
System.out.println("Connected to EchoServer at " + serverAddress + ":" + port);
System.out.println("Type a message and press Enter to send, or type 'exit' to
quit.");
// Read input from the user and send it to the server String input;
do
{
input = scanner.nextLine();
writer.println(input);
String response = reader.readLine();
System.out.println("Server response: " + response);
}
while (!input.equalsIgnoreCase("exit"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

OUTPUT:
Server
C:\Program Files\Java\jdk1.5.0\bin>javac UDPserver.java
C:\Program Files\Java\jdk1.5.0\bin>java UDPserver
press ctrl+c to quit the program
Client:Hai Server
Server:Hello Client
Client:How are You
Server:I am Fine
Client
Downloaded from: annauniversityedu.blogspot.com
25
C:\Program Files\Java\jdk1.5.0\bin>javac UDPclient.java
C:\Program Files\Java\jdk1.5.0\bin>java UDPclient
server waiting
Client:Hai Server
Server:Hello Clie
Client:How are You
Server:I am Fine
Client:end

Result:
Thus the above program for Echo Client and Echo server using TCP sockets has been
executed successfully.
EX NO 3 (b) Applications using TCP sockets
DATE: Chat

AIM:
To write a program for the Chat Applications using TCP sockets.
PROCEDURE:
 Compile both ChatServer.java and ChatClient.java using javac.
 Start the server by running java ChatServer in one terminal or command prompt
window.
 Start multiple clients by running java ChatClient in separate terminal or command
prompt windows.
 Each client can type messages, and they will be broadcasted to all
connected clients.
PROGRAMS:
A) ChatServer.java
import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer
{
private static final int PORT = 12345;
private static Set<Socket> clientSockets = new HashSet<>();
private static final Object lock = new Object();
public static void main(String[] args)
{
try (ServerSocket serverSocket = new ServerSocket(PORT))
{
System.out.println("ChatServer is listening on port " + PORT);
while (true)
{
Socket clientSocket = serverSocket.accept();
System.out.println("Client connected: " + clientSocket.getInetAddress().
getHostAddress());
synchronized (lock)
{

clientSockets.add(clientSocket);
}
Thread clientThread = new Thread(() -> handleClient(clientSocket));
clientThread.start();
}
} catch (IOException e)
{
e.printStackTrace();
}
}

private static void handleClient(Socket clientSocket)


{
try (BufferedReader reader = new BufferedReader(new InputStreamReader

(clientSocket.getInputStream()));
PrintWriter writer = new PrintWriter(clientSocket.getOutputStream(), true))
{
String clientMessage;
while ((clientMessage = reader.readLine()) != null)
{
System.out.println("Received from client: " + clientMessage);
// Broadcast the message to all connected clients
synchronized (lock) {
for (Socket socket : clientSockets) {
PrintWriter clientWriter = new PrintWriter(socket.getOutputStream(), true);
clientWriter.println(clientMessage);
}
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
synchronized (lock)
{
clientSockets.remove(clientSocket);
}
System.out.println("Client disconnected: " + clientSocket.getInetAddress().
getHostAddress());
}
}

B) ChatClient.java

import java.io.*;

import java.net.*;

import java.util.Scanner;

public class ChatClient

private static final String SERVER_ADDRESS = "localhost";

private static final int PORT = 12345;

public static void main(String[] args)

try (Socket socket = new Socket(SERVER_ADDRESS, PORT);

BufferedReader reader = new BufferedReader(new

InputStreamReader(socket.getInputStream()));

PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);


Scanner scanner = new Scanner(System.in))

System.out.println("Connected to ChatServer at " + SERVER_ADDRESS + ":" +


PORT);

System.out.println("Type your messages and press Enter to send, or type 'exit' to


quit.");

// Create a separate thread to receive messages from the server

Thread receiveThread = new Thread(() ->

String serverMessage;

try

while ((serverMessage = reader.readLine()) != null)

System.out.println("Server says: " + serverMessage);

} catch (IOException e)

e.printStackTrace();

});

receiveThread.start();

// Read input from the user and send messages to the server

String input;

Do

input = scanner.nextLine();

writer.println(input);
}

while (!input.equalsIgnoreCase("exit"));

catch (IOException e)

e.printStackTrace();

OUT PUT:
server
E:\nwlab>java FileServer
Sending file ... 9% complete!
Sending file ... 19% complete!
Sending file ... 28% complete!
Sending file ... 38% complete!
Sending file ... 47% complete!
Sending file ... 57% complete!
Sending file ... 66% complete!
Sending file ... 76% complete!
Sending file ... 86% complete!
Sending file ... 95% complete!
Sending file ... 100% complete!
File sent successfully!
E:\nwlab>client
E:\nwlab>java FileClient

File saved successfully!

RESULT:
Thus the above a program for the Chat Applications using TCP sockets has been executed
succesfully.
EX NO: 4 Simulation of DNS using UDP sockets
DATE:

AIM:
To write a program for Simulation of DNS using UDP sockets

PROCEDURE:
The DNS server listens on port 53, which is the standard DNS port. It receives DNS
queries from clients, processes them, and sends back the corresponding IP address. The process
DNSQuery() method is a placeholder where you can implement your own logic to map domain
names to IP addresses.
To test the DNS server, you can use a DNS client program or a tool like nslookup. Here's
an example using the nslookup command:
 Compile and run the DNS server program using javac DNSServer.java and java DNSServer.
 Open a new terminal or command prompt window.
 Type nslookup example.com localhost to query the DNS server for the IP address of
example.com. Replace localhost with the IP address or hostname of the machine running the
DNS server.
 You should see the DNS server responding with the IP address for example.com.
Note that this is a basic example and does not cover all the complexities of a full-fledged
DNS server. It's intended to demonstrate the concept of simulating DNS using UDP sockets.

PROGRAM:

import java.net.*;

public class DNSServer

private static final int PORT = 53;

public static void main(String[] args)

try (DatagramSocket socket = new DatagramSocket(PORT))

System.out.println("DNS Server is listening on port " + PORT);

byte[] receiveBuffer = new byte[1024];


while (true)

DatagramPacket requestPacket = new DatagramPacket(receiveBuffer,


receiveBuffer.length);

socket.receive(requestPacket);

InetAddress clientAddress = requestPacket.getAddress();

int clientPort = requestPacket.getPort();

String query = new String(requestPacket.getData()).trim();

System.out.println("Received DNS query from client: " + query);

// Process the DNS query and obtain the corresponding IP address

String ipAddress = processDNSQuery(query);

byte[] responseBytes = ipAddress.getBytes();

DatagramPacket responsePacket = new DatagramPacket(responseBytes,

responseBytes.length, clientAddress,
clientPort);

socket.send(responsePacket);

System.out.println("Sent DNS response to client: " + ipAddress);

catch (Exception e)

e.printStackTrace();

private static String processDNSQuery(String query)

// Perform DNS query processing and return the appropriate IP address based on the
query

// For simplicity, we'll use a hardcoded mapping here


switch (query)

case "example.com":

return "192.0.2.1";

case "google.com":

return "8.8.8.8";

default:

return "Unknown host";

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

IP Address: Host Not Found

RESULT:
Thus the above program for Simulation of DNS using UDP sockets has been executed
successfully.
EX NO: 5 Capturing Packets using WireShark
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 capturing of packets and examining the packets using Wireshark has been
completed successfully.
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 RARPTable class that stores MAC-IP address
mappings. The RARPProtocolSimulator class demonstrates the usage of this table to simulate a
RARP lookup.
To run the simulation, simply compile and execute the RARPProtocolSimulator.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.util.HashMap;
import java.util.Map;
class ARPTable
{
private Map<String, String> table;
public ARPTable()
{
this.table = new HashMap<>();
}
public void addEntry(String ipAddress, String macAddress) {
table.put(ipAddress, macAddress);
}
public String lookup(String ipAddress)
{
return table.get(ipAddress);
}
}
class ARPProtocolSimulator
{
public static void main(String[] args)
{
ARPTable arpTable = new ARPTable();
arpTable.addEntry("192.168.0.1", "00:11:22:33:44:55");
arpTable.addEntry("192.168.0.2", "AA:BB:CC:DD:EE:FF");
// Simulate ARP lookup
String ipAddress = "192.168.0.1";
String macAddress = arpTable.lookup(ipAddress);
if (macAddress != null)
{
System.out.println("ARP Lookup - IP: " + ipAddress + ", MAC: " +
macAddress);
}
else
{
System.out.println("ARP Lookup - IP: " + ipAddress + ", MAC not found");
}
// Simulate RARP lookup
String targetMacAddress = "00:11:22:33:44:55";
String targetIpAddress = null;
for (Map.Entry<String, String> entry : arpTable.getTable().entrySet())
{
if (entry.getValue().equals(targetMacAddress))
{
targetIpAddress = entry.getKey();
break;
}
}
if (targetIpAddress != null)
{
System.out.println("RARP Lookup - MAC: " + targetMacAddress + ", IP: " +
targetIpAddress);
}
else
{
System.out.println("RARP Lookup - MAC: " + targetMacAddress + ", IP not
found");
}
}}
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.
Local Area Network / Wireless Local Area Network Trainer System.
It is designed to help students understand the basic concepts, modes of operation and
protocols involved in networking. The trainer has integrated hardware flow control on panel
board for better understanding of different types of LAN topologies involved in networking.
The trainer system is provided with windows-based user friendly software with analysis of
protocols, different layers, network and measurement of error rate and throughput.
Students can easily do connections in different topologies and can learn actual data
transfer either through hardware or through simulated network concept. Facility is provided
into system software to introduce errors into packets being sent and analyze the effect of
error on different protocols and hence find the effect on through put graph as well.
Trainer and its various types of experimentation using this system. This system works
into server-client base. For any topology user has to select one server and select the network
type whether it is LAN or WLAN. To understand the topology concept user can connect
two or more clients to hardware. Depending on the topology selected user will have option
to select protocols for the selected topology. Upon selection of protocol user can then create
network of connected computers.
In any network which is created by user server can send or can communicate with
any of the clients however clients can communicate only with server, no client to client
communication is possible. Transmitter port protocol & network analysis can be done after
communication is over between server and clients. Throughput v/s Packet size graph can be
plotted for which at least two file transfers should be carried out. This plot can be printed to
attach in the lab exercise sheet.
For the LAN network LAN cards must be installed prior to start work on this trainer.
For wireless LAN USB ports should be available on the computers which are to be used for
experimentation. In WLAN wireless access cards gets connected to computer USB ports and
access point gets connected to hardware device.
L-SIM LAN Protocol Simulator & Analyzer Software:
It is designed to teach the basic concepts, topologies & various protocols involved in
networking. The software is provided with analysis of protocols, different layers, network
and measurement of error rate and throughput. Facility is provided to introduce errors into
packets being sent and analyze the effect of error on different protocols and hence find the
effect on throughput graph as well. Software is supported with neat operating instruction
manual and online help.
Model Window Diagram for L-SIM:

N-SIM Network Simulation Software:


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

Rapid advances in computer & communication technologies have resulted in the


increasing merger of these two fields. The lines have blurred among computing, switching &
digital transmission equipment; and the same digital techniques are being used for data, audio &
video transmission. Merging & evolving technologies, coupled with increasing demands for
efficient & timely collection, processing & dissemination of information, have led to the
development of integrated systems that transmit & process all types of data.
These intgrated systems are broadly divided as follows:
- Data Communication dealing with transmission, transmission media, signal decoding,
interfacing, data link control & multiplexing
- Networking deals with the technology & architecture of communication network.
- Communication Protocols which covers the architecture as well as analysis of
individual protocols at various layers depending on the hardware & software Network
laboratory is designed & developed considering the curriculum offered by Anna
University. Trainers offered under network laboratory are designed for students at all
level to study and understand all the concepts of data communication, data transfer
using serial and parallel ports, Ethernet and wireless LAN with complete protocol
understanding and actual hands on with hardware & software with ease.
Network laboratory consists of DCT-03 Data communication trainer kit, LTS- 01 LAN /
Wireless LAN training system, L-SIM LAN / WLAN protocol simulator and analyzer software
& N-SIM Network simulation software.
The DCT-03: Data communication trainer is a unique trainer kit for the development of
exercises and theoretical-experimental courses to understand the basic concept and working of
modes and protocols in serial and parallel communication.
The trainer kit consists of functional blocks for serial and parallel communication system.
The trainer kit is highly innovative from a technological as well as an educational point
of view. The trainer kit is used as “basic unit” to examine all the peculiar operating standards of
serial and parallel communication system. The only external equipments required are two
Computers with serial and parallel communication ports and an Oscilloscope. Utmost care has
been laid in the design and quality control of all circuits, to ensure the repeatability of the results
of the experiments.
Data communication is a term referred when the sender and receiver are digital devices,
which communicate with each other by means of binary information. The objective of this
trainer kit is to clear the various aspects of the data communications which comprise of
• The information source or sender.
• The medium for carrying information.
• The information receiver.
• The communication protocols, which ensure proper transfer of data.
With an increasing demand in information exchange the field of data communication
technique is emerging as the only solution, to satisfy the various needs of today’s
communication sector and to achieve very high bandwidth along with highest accuracy. The
communication media is shifting from analog signal transfer towards digital communication.

With PC becoming the biggest storage devices in digital form, it becomes the main
source and destination for information exchange. With rapid growth in both the communication
technologies as well as computer hardware and software technologies, these two fields are
merged to form a data communication network. Now the digital data is used for data, voice and
image transmission.

Depending upon the application the communication link can be of point to point
communication between two devices or a multipoint communication between at least 3 devices
and data transfer can be serial or in parallel form.

RESULT:

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.

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.
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:
Simulation of Link State Routing algorithm.
PROCEDURE:
To simulate the Link State 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
Link State 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 Link State routing algorithm. Each node
should have a Link State Database (LSDB) that stores information about the network's topology.

Link State Information Exchange:


Implement the link state information exchange process. Each node should flood its link
state information to all other nodes in the network. This involves creating Link State Packets
(LSPs) that contain information about the node's links and flooding them throughout the
network.

Link State Database Update:


When a node receives an LSP from another node, it should update its LSDB with the
received information. Each node's LSDB should represent the complete network topology based
on the received LSPs.

Shortest Path Calculation:


Implement the shortest path calculation mechanism. Each node should run a shortest
path algorithm, such as Dijkstra's algorithm, using the information in its LSDB to determine the
shortest paths to each destination node.
Routing Table Construction:
Based on the shortest paths calculated, each node should construct its routing table. The
routing table should specify the next hop for each destination node.

Packet Forwarding:
During the simulation, when a packet needs to be forwarded, the source node consults its
routing table to determine the next hop and forwards the packet accordingly.
Simulation Execution:
Run the simulation using the selected simulation tool. The simulation will execute the
Link State algorithm, update the LSDBs, calculate shortest paths, and forward packets based on
the routing tables.
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 Link State
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 Link State 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 Link State 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 Link State algorithm. You can refer to their
documentation and resources for specific guidance on using these tools for Link State
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: 10 Simulation of an error correction code (CRC)
DATE:

AIM:
Simulation of an error correction code (CRC).
PROCEDURE:
To simulate an error correction code like CRC (Cyclic Redundancy Check), you can use
programming languages like Python to create a simulation program. Here's a step-by-step guide
on simulating CRC:
Select CRC Parameters:
Determine the parameters of the CRC code you want to simulate, such as the polynomial
and its degree, generator polynomial, and the number of bits for the checksum. These
parameters define the characteristics of the CRC code.
Generate Test Data:
Create test data that represents the message to be encoded and transmitted. This can be a
string of bits or bytes, or you can generate random data. Make sure the data contains errors or
introduce errors intentionally to simulate the error correction process.
CRC Encoding:
Implement the CRC encoding process. This involves dividing the message by the
generator polynomial using modulo-2 division and appending the resulting CRC checksum to
the original message. This generates the encoded message.
Error Introduction:
Introduce errors into the encoded message to simulate transmission errors. You can flip
bits randomly or intentionally introduce specific error patterns.
CRC Decoding:
Implement the CRC decoding process. Receive the transmitted message and perform the
same modulo-2 division with the generator polynomial. If the remainder is zero, the message is
assumed to be error-free. If the remainder is non-zero, it indicates the presence of errors.
Error Detection and Correction:
Analyze the remainder obtained in the decoding process. If the remainder is non-zero,
errors are detected. Use the CRC algorithm to correct the errors, if possible. You can attempt to
fix the errors by manipulating the received message or requesting retransmission.
Performance Analysis:
Collect performance metrics to evaluate the effectiveness of the CRC code. Measure the
error detection rate, error correction rate, and false positive rate. Calculate the overall accuracy
of the CRC code in detecting and correcting errors.
Repeat and Compare:
Repeat the simulation with different test data, error patterns, or CRC parameters to
analyze the performance under various conditions. Compare the results to assess the impact of
different factors on the CRC's effectiveness.
By implementing the CRC algorithm in a programming language, you can simulate the
error detection and correction process. You can modify the simulation program to test different
CRC parameters, error patterns, or even combine CRC with other error correction techniques.
Remember that this simulation represents a simplified version of real-world scenarios,
and CRC is just one type of error correction code. More complex error correction codes, such as
Reed-Solomon codes, may require additional considerations and calculations.
Error Detection:
• Bit errors occur in frames due to electrical interference or thermal noise.
• Detecting errors is one part of the problem; correcting errors is the other.
• What happens when an error is detected?
• Two basic approaches:
– Notify the sender that message is corrupt so the sender can retransmit it; (
most often used in every day applications)
– Use an error-correcting code to reconstruct the correct message
Transmission Errors:
 External electromagnetic signals can cause incorrect delivery of data
 Data can be received incorrectly
 Data can be lost
 Unwanted data can be generated
Any of these problems are called transmission errors
Error Detection:
Detecting Transmission Errors: basic idea is to add redundant information to a frame that
can determine if errors have been introduced.
Error Correction or Error Detection:
• When error is detected, frame is discarded and resent, using bandwidth and
causing latency, waiting for its arrival.
• Error correction requires additional bit to be sent with every frame.
• Correction is useful when
• 1) errors are probable or
• 2) the cost of retransmission is too high
Cyclic Redundancy Check (CRC):
CRC is a different approach to detect if the received frame contains valid data. This
technique involves binary division of the data bits being sent. The divisor is generated using
polynomials. The sender performs a division operation on the bits being sent and calculates the
remainder. Before sending the actual bits, the sender adds the remainder at the end of the actual
bits. Actual data bits plus the remainder is called a code word. The sender transmits data bits as
code words.

At the other end, the receiver performs division operation on code words using the same
CRC divisor. If the remainder contains all zeros the data bits are accepted, otherwise it is
considered as there some data corruption occurred in transit.
Procedure:
• Start the process.
• Give the data which is the message.
• Compile and run the program.
• Enter the received hamming code.
• The error is corrected codeword.

Program for Code Generation for Error Detection and Correction:

#include
<stdio.h> #include
<math.h> #include
<stdlib.h> int main()
{
int i,j,k,count,err- pos=0,flag=0; char dw[20],cw[20],data[20];
printf(“enter data as binary bit stream(7 bits):\n”); scanf(“%s”,data);
for(i=1,j=0,k=0;i<12;i++)
{
if(i==(int)pow(2,j))
{ dw[i]=’?’; j++;
}
else

{
dw[i]=data[k];

k++;
}
}
for(i=0;j<4;i++)
{
count=0; for(j=(int)pow(2,i);j<12;j<12;j+=(int)pow(2,i))
{
for (k=0;k<(int)pow(2,i);k++)
{
if(dw[j]==’1’)count++;j++;
}
}
if(count%2==0) dw[(int)pow(2,i)]=’0’; else dw[(int)pow(2,i)]=’1’;
}
printf(“in code word is\n\n”); for(i=1;i<12;i++) printf(“%c”,dw[i]);
printf(“\n\n enter the received hamming code\n\n”); scanf(“%s”,cw);
for(i=12;i>0;i--)
cw[i]=cw[i-1]; for(i=0;i<4;i++)
{
count=0; for(j=(int)pow(2,i);j<12;j+=(int)pow(2,i))
{
for(k=0;k<(int)pow(2,i);k++)
{
if(cw[j]==’1’)count++;j++;
}
}
if (count%2!=0)
err-pos=err-post+(int)pow(2,i);
}
if(err-pos==0)
printf(“\n\n there is no error in received code word
\n”); else
{
if(cw[err-pos]==dw[err-pos])
{
printf(“\n\n there are 2 or more errors in received code……\n\n”); printf(“sorry…!
hamming code cannot correct 2 or more errors….\n”); flag=1;
}
else
printf(“in there is an error in bit position %d of received code word \n”,err-pos);
if(flag==0)
{
cw[err-pos]=(cw[err-pos]==’1’)?’0’:’1’;

printf(“\n\n corrected code word is


\n\n”); for(i=1;i<12;i++) printf(“%c”,cw[i]);
}
}
printf(“\n\n”);
}
OUTPUT:
Enter data as binary bit stream(7 bits):
1110110
Code word is 11101100110
Enter the received hamming code 10101100110
There is an error in bit position 2 of received code word corrected code word is
11101100110
Enter data as binary bit stream(7 bits) 11101110
Code word is 11101100110
Enter the received hamming code 00101100110
There are 2 or more error in received code… Sorry…!

RESULT:
Thus the above simulation program has been executed successfully.

You might also like