0% found this document useful (0 votes)
18 views47 pages

CN Lab Manual

The document is a lab manual for the CS3591 Computer Networks course at Mount Zion College of Engineering & Technology, detailing experiments and practical applications in networking. It covers various topics including TCP socket programming, HTTP web client creation, and network command usage, along with algorithms for routing and error correction. The manual is prepared for B.Tech (IT) students in their fifth semester for the academic year 2024-2025.

Uploaded by

M. Aarthie
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)
18 views47 pages

CN Lab Manual

The document is a lab manual for the CS3591 Computer Networks course at Mount Zion College of Engineering & Technology, detailing experiments and practical applications in networking. It covers various topics including TCP socket programming, HTTP web client creation, and network command usage, along with algorithms for routing and error correction. The manual is prepared for B.Tech (IT) students in their fifth semester for the academic year 2024-2025.

Uploaded by

M. Aarthie
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/ 47

Mount Zion College of Engineering & Technology

To Make Man Whole!!

DEPARTMENT OF INFORMATION
TECHNOLOGY

LAB MANUAL

CS3591 – COMPUTER NETWORKS


LABORATORY

B.TECH (IT)
(REG 2021)

SEMESTER : V

ACADEMIC YEAR : 2024 -2025

PREPARED BY
MS. M. AARTHIE
ASSISTANT PROFESSOR
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DAT SCIENCE

TABLE OF CONTENTS

S.NO. DATE EXPERIMENT TITLE MARKS SIGN.

Leam to use commands like tcpdump, netstat,


ifconfig, nslookup and traceroute. Capture
1
ping and trace route PDUs using a network
protocol analyzer and examine.
Write a HTTP web client program to download a
2
web page using TCP sockets.
Applications using TCP sockets like Echo client
3a
and echo server
3b Applications using TCP sockets like Chat
4 Simulation of DNS using UDP sockets
Use a tool like Wireshark to capture packets and
5
examine the packets
6a Write a code simulating ARP protocols
6b Write a code simulating RARP protocols

Study of Network simulator (NS) and Simulation


7
of Congestion Control Algorithms using NS

Study of TCP/UDP performance using


8
Simulation tool

9a Simulation of Distance Vector Routing algorithm

9b Simulation of Link State Routing algorithm


10 Simulation of error correction code (like CRC)

2
PREREQUISTING KNOWLEDGE

Java

• Java is a high-level, object-oriented, and platform-independent programming language.


• Developed by Sun Microsystems (now Oracle).
• Known for its WORA (Write Once, Run Anywhere) feature.
• Runs on the Java Virtual Machine (JVM).

Networking Basics

Java provides the java.net package for handling network communication.

• OSI and TCP/IP models

• IP addressing (IPv4/IPv6), subnetting

• Protocols: TCP, UDP, ICMP, ARP, DNS, HTTP, etc.


1. Use of Commands like tcpdump, netstat, ifconfig, nslookup, traceroute
• Linux CLI basics
• Network interface configuration
• Packet capturing and filtering concepts
• DNS resolution process
• ICMP, IP routing
2. HTTP Web Client using TCP sockets
• TCP client/server model
• HTTP protocol (request/response format)
• Socket programming in Python or C
• DNS resolution and connection establishment
3. TCP Socket Applications
• TCP connection setup (3-way handshake)
• Writing simple echo server/client (send/receive loop)
• Handling multiple clients (optional: threading or select)
• Message framing and buffering
4. DNS Simulation using UDP sockets
• DNS protocol basics (query/response format)
• UDP socket communication

3
• Parsing domain names and constructing DNS packets manually
5. Packet Capture and Analysis using Wireshark
• Using Wireshark filters and interfaces
• Interpreting headers: Ethernet, IP, TCP/UDP, ICMP, etc.
• Protocol layering and encapsulation
6. ARP/RARP Protocol Simulation
• ARP protocol (request/response format)
• IP-to-MAC resolution logic
• Low-level network programming (optional: raw sockets)
• Understanding of Ethernet frame format
7. Network Simulator (NS2/NS3) and Congestion Control
• Installation and basic usage of NS2 or NS3
• Writing simple simulation scripts (TCL for NS2, C++/Python for NS3)
• TCP congestion control algorithms (Tahoe, Reno, etc.)
8. TCP/UDP Performance Analysis via Simulation
• Differences between TCP and UDP
• Throughput, latency, packet loss metrics
• Creating test scenarios and collecting data using simulation tools
9. Distance Vector / Link State Routing Simulation
• Routing algorithms:

• Distance Vector (Bellman-Ford)

• Link State (Dijkstra)


• Graph theory basics
• Data structures for routing tables
• Message exchange simulation between routers
10. Error Correction Code Simulation (e.g., CRC)
• Error detection and correction theory
• Polynomial division method for CRC
• Bitwise operations in programming
• Binary arithmetic

4
DATE: 1. Leam to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute
Capture ping and trace route PDUs using a network protocol analyzer
and examine

AIM:
To study the basic networking commands.

NETWORKING COMMANDS:

• C:\> arp -a
o ARP is short for Address Resolution Protocol.
o It will show the IP address of your computer along with the IP address and MAC address
of your router.
• C:\> hostname
o This is the simplest of all TCP/IP commands.
o It simply displays the name of your computer.
• C:\> ipconfig
o The ipconfig command displays information about the host (the computer you are using)
and its TCP/IP configuration.
• C:\> ipconfig /all
o This command displays detailed configuration information about your TCP/IP connection,
including Router, Gateway, DNS, DHCP, and the type of Ethernet adapter in your system.
• C:\> ipconfig /renew
o Using this command will renew all your IP addresses that you are currently leasing from
the DHCP server.
o This is a quick problem solver for connection issues, but it does not work if your system
has been configured with a static IP address.
• C:\> ipconfig /release
o This command allows you to drop the IP lease from the DHCP server.
• C:\> ipconfig /flushdns
o This command is used when you are experiencing DNS-related issues.
o It clears out the DNS resolver cache and is often used as a troubleshooting step.
• C:\> nbtstat -a
o This command helps solve problems with NetBIOS name resolution.
o (Nbt stands for NetBIOS over TCP/IP).
• C:\> netdiag
o Netdiag is a network testing utility that performs various diagnostic tests to identify
network issues.
o It is not installed by default but can be installed from the Windows XP CD.
o Navigate to the CD-ROM drive letter → Support\Tools folder → setup.exe.
• C:\> netstat
o Netstat displays various statistics about a computer's active TCP/IP connections.
o It is helpful when troubleshooting issues with TCP/IP applications like HTTP and FTP.
• C:\> nslookup
o Nslookup is used to diagnose DNS problems.
o If you can access a resource using its IP address but not by its DNS name, this command
will help identify DNS issues.
• C:\> pathping
5
o Pathping is unique to Windows and is a combination of the Ping and Tracert commands.
o It traces the route to the destination address and then performs a 25-second test of each
router along the route, gathering statistics on data loss.
• C:\> ping
o Ping is the most basic TCP/IP command.
o It works like a phone call, sending a request to another computer on the network and
waiting for a response.
o You can use the Ping command with a computer’s name or IP address to check
connectivity.
• C:\> route
o The Route command displays the computer’s routing table.
o If you are facing network access issues, this command can help ensure the routing table
has correct entries.
• C:\> tracert
o Tracert (Trace Route) displays a list of all the routers a packet passes through to reach its
destination.
o It is useful for diagnosing network routing issues.

RESULT:

Thus the above list of primitive has been studied.

6
DATE: 2.Write a HTTP webclient program to download a
Webpage using TCPsockets
AIM:

To Write a HTTP web client program to download a webpage using TCPsockets.

ALGORITHM:

1. Start the program.


2. Create a TCP socket using socket() function.
3. Establish a connection to the web server using the connect() function, specifying the server’s IP
address and port number (typically port 80 for HTTP).
4. Form an HTTP GET request in the correct format:

vbnet
CopyEdit
GET /path/to/resource HTTP/1.1
Host: www.example.com

5. Send the HTTP request to the server using send() function.


6. Receive the server’s response using the recv() function.
7. Display the downloaded web page content.
8. Close the socket using close() function.
9. End the program.

PROGRAM
import java.io.*;
import javax.net.ssl.*;

public class HttpClient {


public static void main(String[] args) {
String host = "wordpress.org"; // Change to your desired HTTPS website
String path = "/"; // Root path

try {
// Create an SSL socket to establish a secure connection on port 443
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) factory.createSocket(host, 443);

// Get the input and output streams


PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

7
// Send HTTPS GET request
out.println("GET " + path + " HTTP/1.1");
out.println("Host: " + host);
out.println("Connection: close");
out.println(); // Empty line to signal end of headers

// Read the response


StringBuilder response = new StringBuilder();
String line;
boolean isBody = false;

while ((line = in.readLine()) != null) {


if (line.isEmpty()) { // Headers and body are separated by an empty line
isBody = true;
continue;
}
if (isBody) {
response.append(line).append("\n");
}
}

// Close the socket


socket.close();

// Save the webpage content to a file


try (BufferedWriter writer = new BufferedWriter(new FileWriter("downloaded_page.html"))) {
writer.write(response.toString());
}

System.out.println("Web page downloaded and saved as 'downloaded_page.html'.");

} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
}

8
WEBSITE:

OUTPUT:

9
RESULT:
The webpage is successfully downloaded and the contents are displayed and verified.

10
3.a. SOCKET PROGRAM FOR ECHO
DATE:
AIM:

To write a socket program for the implementation of echo.

ALGORITHM:
Client Side:

1. Start the program.


2. Create a socket that binds the IP address of the server and the port address to acquire service.
3. After establishing a connection, send data to the server.
4. Receive and print the same data from the server.
5. Close the socket.
6. End the program.

Server Side:

1. Start the program.


2. Create a server socket to activate the port address.
3. Create a socket for the server socket to accept the connection.
4. After establishing a connection, receive the data from the client.
5. Print and send the same data back to the client.
6. Close the socket.
7. End the program.

PROGRAM:
Echo Client
import java.io.*;
import java.net.*;

public class EClient {


public static void main(String args[]) {
Socket c = null;
String line;
DataInputStream is, is1;
PrintStream os;

try {
c = new Socket("localhost", 8080);

11
} catch (IOException e) {
System.out.println(e);
}

try {
os = new PrintStream(c.getOutputStream());
is = new DataInputStream(System.in);
is1 = new DataInputStream(c.getInputStream());

do {
System.out.println("Client: ");
line = is.readLine();
os.println(line);

if (!line.equals("exit")) {
System.out.println("Server: " + is1.readLine());
}
} while (!line.equals("exit"));
} catch (IOException e) {
System.out.println("Socket closed");
}
}
}
Echo Server:
import java.io.*;
import java.net.*;

public class EServer {


public static void main(String args[]) throws IOException {
ServerSocket s = null;
String line;
DataInputStream is;
PrintStream ps;
Socket c = null;

try {
s = new ServerSocket(8080);
12
} catch (IOException e) {
System.out.println(e);
}

try {
c = s.accept();
is = new DataInputStream(c.getInputStream());
ps = new PrintStream(c.getOutputStream());

while (true) {
line = is.readLine();
System.out.println("Message received and sent back to client");
ps.println(line);
}
} catch (IOException e) {
System.out.println(e);
}
}
}

OUTPUT:
CLIENT

Enter the IP address 127.0.0.1


CONNECTIONESTABLISHED
Enter the data CSE
ClientreceivedCSE
SERVER
CONNECTIONACCEPTED
ServerreceivedCSE

RESULT:

Thus the program for simulation of echo server and Client was written & executed.

13
DATE: 3.B.CLIENT-SERVER APPLICATION FOR CHAT

AIM:

To write a client-server application for chat using TCP.


ALGORITHM:

Client:

1. Start the program.


2. Include necessary packages in Java.
3. Create a socket in the client to connect to the server.
4. Establish a connection to the server.
5. The client sends data to the server.
6. Communicate with the server until the end of the message is sent using the keyword "quit".
7. Stop the program.

Server:

1. Start the program.


2. Include necessary packages in Java.
3. Create a server socket to listen for client connections.
4. Establish a connection when the client requests.
5. The server sends and receives data from the client.
6. Communicate with the client until the end of the message is sent using the keyword "quit".
7. Stop the program.

PROGRAM:
TCP Server (TCPserver1.java)
import java.net.*;
import java.io.*;

public class TCPserver1 {


public static void main(String arg[]) {
ServerSocket s = null;
String line;
DataInputStream is = null, is1 = null;
PrintStream os = null;
Socket c = null;

try {
s = new ServerSocket(9999);
} catch (IOException e) {
System.out.println(e);
}

14
try {
c = s.accept();
is = new DataInputStream(c.getInputStream());
is1 = new DataInputStream(System.in);
os = new PrintStream(c.getOutputStream());

do {
line = is.readLine();
System.out.println("Client: " + line);
System.out.println("Server: ");
line = is1.readLine();
os.println(line);
} while (!line.equalsIgnoreCase("quit"));

is.close();
os.close();
} catch (IOException e) {
System.out.println(e);
}
}
}

TCP Client (TCPclient1.java)


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

public class TCPclient1 {


public static void main(String arg[]) {
Socket c = null;
String line;
DataInputStream is, is1;
PrintStream os;

try {
c = new Socket("10.0.200.36", 9999);
} catch (IOException e) {
System.out.println(e);
}

try {
os = new PrintStream(c.getOutputStream());
is = new DataInputStream(System.in);
is1 = new DataInputStream(c.getInputStream());

do {
System.out.println("Client: ");
line = is.readLine();
os.println(line);

15
System.out.println("Server: " + is1.readLine());
} while (!line.equalsIgnoreCase("quit"));

is1.close();
os.close();
} catch (IOException e) {
System.out.println("Socket Closed! Message Passing is Over");
}
}
}

OUTPUT:
Server:
C:\Program Files\Java\jdk1.5.0\bin> javac TCPserver1.java
Note: TCPserver1.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin> java TCPserver1
Client: Hai Server
Server: Hai Client
Client: How are you
Server: Fine
Client: quit

Client:
C:\Program Files\Java\jdk1.5.0\bin> javac TCPclient1.java
Note: TCPclient1.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin> java TCPclient1
Client: Hai
Server: Hai
Client: How are you
Server: Fine
Client: quit
Server: quit

RESULT:

Thus, the above program a client-server application for chat using TCP/IP was executed successfully

16
DATE: 4.Simulation of DNS using UDP sockets.

AIM:

To write a program to simulate DNS using UDP sockets.

ALGORITHM:

1. Start the program.


2. Get the hostname from the user.
3. Create a frame based on the user's request.
4. Send frames to the server from the client side using UDP sockets.
5. The server checks for the hostname:
o If the hostname exists, it sends the corresponding IP address as an acknowledgment
(ACK).
o If the hostname is not found, it sends a "Host Not Found" message as a negative
acknowledgment (NACK).
6. Stop the program.

PROGRAM:
UDP DNS Server (udpdnsserver.java)

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

public class udpdnsserver {

private static int indexOf(String[] array, String str) {


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

DatagramSocket serverSocket = new DatagramSocket(1362);

while (true) {
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
17
DatagramPacket recvPacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(recvPacket);

String receivedHost = new String(recvPacket.getData()).trim();


InetAddress ipAddress = recvPacket.getAddress();
int port = recvPacket.getPort();

System.out.println("Request for host: " + receivedHost);

String response;
int index = indexOf(hosts, receivedHost);

if (index != -1) {
response = ip[index];
} else {
response = "Host Not Found";
}

sendData = response.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, port);
serverSocket.send(sendPacket);
}
}
}

UDP DNS Client (udpdnsclient.java)

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

public class udpdnsclient {

public static void main(String args[]) throws IOException {


BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress ipAddress;

if (args.length == 0) {
ipAddress = InetAddress.getLocalHost();
} else {
ipAddress = InetAddress.getByName(args[0]);
}

byte[] sendData = new byte[1024];


byte[] receiveData = new byte[1024];
int portAddr = 1362;

18
System.out.print("Enter the hostname: ");
String sentence = br.readLine();
sendData = sentence.getBytes();

DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress,


portAddr);
clientSocket.send(sendPacket);

DatagramPacket recvPacket = new DatagramPacket(receiveData, receiveData.length);


clientSocket.receive(recvPacket);

String modified = new String(recvPacket.getData()).trim();


System.out.println("IP Address: " + modified);

clientSocket.close();
}
}

OUTPUT:
Server Output:

C:\Program Files\Java\jdk1.6.0\bin> javac udpdnsserver.java


C:\Program Files\Java\jdk1.6.0\bin> java udpdnsserver
Press Ctrl+C to Quit
Request for host yahoo.com
Request for host cricinfo.com
Request for host youtube.com

Client Output:
C:\Program Files\Java\jdk1.6.0\bin> javac udpdnsclient.java
C:\Program Files\Java\jdk1.6.0\bin> java udpdnsclient
Enter the hostname: yahoo.com
IP Address: 68.180.206.184

C:\Program Files\Java\jdk1.6.0\bin> java udpdnsclient


Enter the hostname: cricinfo.com
IP Address: 80.168.92.140

C:\Program Files\Java\jdk1.6.0\bin> java udpdnsclient


Enter the hostname: youtube.com
IP Address: Host Not Found

RESULT:
Thus, the above program for a client-server application for chat using UDP was executed
successfully.

19
DATE: 5. Use a tool like Wireshark to capture packets and examine the packets

AIM

To use Wireshark to capture network packets and analyze them to understand the behavior of protocols
like TCP, UDP, and ICMP.

APPARATUS REQUIRED

• Wireshark software
• Personal Computer with Internet connection

THEORY

Wireshark is a network protocol analyzer that captures packets in real-time and displays detailed
information about them. It is widely used for network troubleshooting, analysis, and communication
protocol development.

Key Features of Wireshark:

• Capture live network traffic


• Filter packets for analysis
• Decode and display packet data
• Support for various protocols like TCP, UDP, ICMP, HTTP, FTP, etc.

PROCEDURE
Step 1: Install Wireshark

1. Download Wireshark from the official website https://www.wireshark.org/.


2. Follow the installation instructions for your operating system.
3. Ensure that you install Npcap for packet capturing.

Step 2: Capture Packets

1. Launch Wireshark.
2. Select the appropriate network interface (e.g., Ethernet or Wi-Fi).
3. Click on the Start Capture button.
4. Perform activities like opening websites, downloading files, or pinging servers to generate
network traffic.
5. Click on Stop once you have sufficient packets captured.

Step 3: Apply Filters

• Use filters to narrow down the packet view. Examples:


o tcp - Display only TCP packets.
o udp - Display only UDP packets.
o icmp - Display ICMP packets.
o ip.src == 192.168.1.5 - Show packets from a specific source IP.
20
Step 4: Analyze Packets

• Click on a packet to view detailed information.


• Inspect the packet headers (e.g., Ethernet, IP, TCP/UDP).
• Analyze fields like source and destination IP addresses, ports, sequence numbers, and
acknowledgments.

Step 5: Export and Save Data

• Go to File -> Save As to save the capture in .pcapng format.


• Use this file for further analysis or sharing.

21
RESULTS AND OBSERVATIONS

• Successfully captured and analyzed packets using Wireshark.


• Observed the behavior of TCP three-way handshake, UDP data transfer, and ICMP echo requests.
• Applied filters to inspect specific packets.

CONCLUSION

Wireshark is a powerful tool for capturing and analyzing network traffic. By examining packet details,
users can troubleshoot network issues, understand communication patterns, and gain insights into
protocol behavior.

22
RESULT

Thus,the packet capture and analysis using Wireshark were successfully completed. Various packets
were captured and filtered using specific criteria.

23
DATE: 6.a.Write a code simulating ARP protocols.

AIM:

To implement Address Resolution Protocol (ARP).

ALGORITHM:
Client Side:

1. Establish a connection between the Client and Server using a socket.

Socket ss = new Socket(InetAddress.getLocalHost(), 1100);

2. Create an instance of OutputStreamWriter.

PrintWriter ps = new PrintWriter(ss.getOutputStream(), true);

3. Get the IP Address from the user to resolve its physical (MAC) address.
4. Send the IP Address to the server using the output stream.

ps.println(ip);

5. Receive and print the Physical Address sent by the server.

Server Side:

1. Accept the connection request from the client using a ServerSocket.

ServerSocket ss = new ServerSocket(1100);


Socket s = ss.accept();

2. Receive the IP address from the client using the input stream.

BufferedReader br1 = new BufferedReader(new InputStreamReader(s.getInputStream()));


ip = br1.readLine();

3. Execute the arp command using Runtime.getRuntime().

Runtime r = Runtime.getRuntime();
Process p = r.exec("arp -a " + ip);

4. Send the Physical Address (MAC address) to the client.

24
PROGRAM:
ARP Client (ArpClient.java)
import java.io.*;
import java.net.*;

class ArpClient {
public static void main(String args[]) throws IOException {
try {
Socket ss = new Socket(InetAddress.getLocalHost(), 1100);
PrintStream ps = new PrintStream(ss.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the IP ADDRESS:");


String ip = br.readLine();
ps.println(ip);

BufferedReader br2 = new BufferedReader(new InputStreamReader(ss.getInputStream()));


System.out.println("ARP From Server:");
String str;

while (!(str = br2.readLine()).equalsIgnoreCase("end")) {


System.out.println(str);
}
} catch (IOException e) {
System.out.println("Error: " + e);
}
}
}

ARP Server (ArpServer.java)

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

class ArpServer {
public static void main(String args[]) throws IOException {
try {
ServerSocket ss = new ServerSocket(1100);
Socket s = ss.accept();
PrintStream ps = new PrintStream(s.getOutputStream());
BufferedReader br1 = new BufferedReader(new InputStreamReader(s.getInputStream()));

String ip = br1.readLine();
Runtime r = Runtime.getRuntime();
Process p = r.exec("arp -a " + ip);

BufferedReader br2 = new BufferedReader(new InputStreamReader(p.getInputStream()));

25
String str;

while ((str = br2.readLine()) != null) {


ps.println(str);
}
ps.println("end");
} catch (IOException e) {
System.out.println("Error: " + e);
}
}
}

OUTPUT:
Server Output:
C:\NetworkingPrograms>java ArpServer
Client Output:
C:\NetworkingPrograms>java ArpClient
Enter the IP ADDRESS:
192.168.11.58
ARP From Server:
Interface: 192.168.11.57 on Interface 0x1000003
Internet Address Physical Address Type
192.168.11.58 00-14-85-67-11-84 dynamic

RESULT:

Thus, the implementation of ARP is done and executed successfully.

26
DATE: 6.b.Write a code simulating RARP protocols.

AIM:
To write a Java program for simulating RARP protocols.

ALGORITHM:

CLIENT

1. Start the program.


2. Using datagram sockets, UDP function is established.
3. Get the MAC address to be converted into an IP address.
4. Send this MAC address to the server.
5. The server returns the IP address to the client.

SERVER

1. Start the program.


2. The server maintains the table in which IP and corresponding MAC addresses are stored.
3. Read the MAC address which is sent by the client.
4. Map the IP address with its MAC address and return the IP address to the client.

CLIENT PROGRAM
import java.io.*;
import java.net.*;

class ClientRarp12 {
public static void main(String args[]) {
try {
DatagramSocket client = new DatagramSocket();
InetAddress addr = InetAddress.getByName("127.0.0.1");

byte[] sendbyte = new byte[1024];


byte[] receivebyte = new byte[1024];

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));


System.out.println("Enter the Physical address (MAC): ");
String str = in.readLine();
sendbyte = str.getBytes();

DatagramPacket sender = new DatagramPacket(sendbyte, sendbyte.length, addr, 1309);


client.send(sender);

27
DatagramPacket receiver = new DatagramPacket(receivebyte, receivebyte.length);
client.receive(receiver);

String s = new String(receiver.getData());


System.out.println("The Logical Address is (IP): " + s.trim());
client.close();
} catch (Exception e) {
System.out.println(e);
}
}
}

SERVER PROGRAM
import java.io.*;
import java.net.*;

class ServerRarp12 {
public static void main(String args[]) {
try {
DatagramSocket server = new DatagramSocket(1309);

while (true) {
byte[] sendbyte = new byte[1024];
byte[] receivebyte = new byte[1024];

DatagramPacket receiver = new DatagramPacket(receivebyte, receivebyte.length);


server.receive(receiver);

String str = new String(receiver.getData());


String s = str.trim();
InetAddress addr = receiver.getAddress();
int port = receiver.getPort();

String ip[] = { "165.165.80.80", "165.165.79.1" };


String mac[] = { "6A:08:AA:C2", "8A:BC:E3:FA" };

for (int i = 0; i < ip.length; i++) {


if (s.equals(mac[i])) {
sendbyte = ip[i].getBytes();
DatagramPacket sender = new DatagramPacket(sendbyte, sendbyte.length, addr, port);
server.send(sender);
break;
}
}
break;
}
} catch (Exception e) {
System.out.println(e);

28
}
}
}

OUTPUT:
Server Side:
I:\ex> java ServerRarp12
Waiting for clients...
Connection established
Received MAC Address: 6A:08:AA:C2
Sending IP Address: 165.165.80.80
Client Side:
I:\ex> java ClientRarp12
Enter the Physical address (MAC): 6A:08:AA:C2
The Logical Address is (IP): 165.165.80.80

RESULT:

Thus, the implementation of RARP is done and executed successfully.

29
DATE: 7.Study of Network simulator(NS) and Simulation of
Congestion Control Algorithms using NS.

OBJECTIVE: To study network simulator (ns) and simulate congestion control algorithms using ns.

SYSTEM REQUIREMENTS:

• PC: Pentium or higher


• One LAN card onboard or on PCI slot with 10/100 Mbps speed
• 128 MB RAM
• 500 MB free space on the Hard Drive
• CD ROM drive
• Serial port, LPT port & USB port installed on the system
• Operating System: Windows 2000 or higher

THEORY:

LTS-01 Local Area Network / Wireless Local Area Network Trainer System

The LTS-01 system is designed to help students understand the basic concepts, modes of operation, and
protocols involved in networking. It offers hands-on experience in working with LAN and WLAN
topologies using hardware and software.

Features:

• Integrated hardware flow control on panel board for LAN topology simulations.
• Windows-based user-friendly software.
• Protocol analysis and network layer understanding.
• Error rate and throughput measurement.
• Option to introduce errors in packets for analysis.
• Graph plotting of throughput vs. packet size.

Students can establish networks using LAN or WLAN, select server and clients, and apply desired
protocols for communication. The network allows server-to-client communication, but not client-to-client
communication.

For LAN networks, ensure LAN cards are installed. For WLAN networks, USB wireless access cards and
an access point are required.

L-SIM LAN Protocol Simulator & Analyzer Software

L-SIM software is developed to teach the following networking concepts:

• Various network topologies and protocols.


• Protocol analysis and network error measurements.
30
• Introduction of packet errors and their effect analysis.
• Throughput analysis using graphs.

The software has a comprehensive instruction manual and offers online help for easy understanding.

MODEL WINDOW DIAGRAM FOR L-SIM

N-SIM Network Simulation Software

N-SIM is designed to provide an advanced understanding of network concepts using simulations and
animations.

Capabilities:

• LAN and WAN protocol simulations.


• Network devices, routers, and protocol analysis.
• Encryption and decryption demonstrations.
• Error insertion and effect analysis.
• Visualization of network communication.

31
MODEL WINDOW DIAGRAM FOR N-SIM

Categories of Integrated Systems:

The integrated systems used in networking are categorized as follows:

1. Data Communication:
o Transmission and media
o Signal decoding and interfacing
o Data link control and multiplexing
2. Networking:
o Technology and network architecture
3. Communication Protocols:
o Protocol architecture and analysis
o Layer-wise communication understanding

Network Laboratory

The network laboratory is designed as per Anna University’s curriculum. It consists of:

• DCT-03 Data Communication Trainer Kit: For understanding serial and parallel
communication.
• LTS-01 LAN/WLAN Trainer System: For studying LAN and WLAN network protocols.
• L-SIM Software: For protocol simulation and analysis.
• N-SIM Software: For network simulations and animations.

32
DCT-03 Data Communication Trainer Kit

The kit is used to conduct theoretical and practical experiments in serial and parallel communication. It
consists of functional blocks representing:

• Serial and parallel communication systems.


• Sender and receiver models.
• Data transmission medium.
• Communication protocols.

The system requires two computers with communication ports and an oscilloscope for practical
experiments. It demonstrates real-time data communication concepts and offers hands-on experience in:

• Information source and receiver communication.


• Proper data transmission using protocols.

With the shift from analog to digital communication, data communication using computers is a primary
method for information exchange in the modern communication sector.

RESULT:

The study of the network simulator (NS) and the simulation of congestion control algorithms
using NS have been successfully executed and verified.

33
DATE: 8.Study of TCP/UDP performance using Simulationtool.

AIM:

To study the performance of TCP/UDP using a simulation tool.

TOOLS USED:

Opnet Simulator

INTRODUCTION:

The transport layer protocols provide connection-oriented sessions and reliable data delivery services.
This paper reflects a comparative analysis between the two transport layer protocols, TCP/IP and UDP/IP,
to observe their effects in a client-server network. The similarities and differences between TCP and UDP
over the Internet are also presented. A network structure is implemented using Opnet Modeler, and based
on practical results, conclusions are drawn to show how these protocols work.

The transport layer provides reliable, cost-effective data transport from the source machine to the
destination machine, independently of the physical network or networks in use. TCP and UDP are key
components of this layer, providing the connection points through which applications access network
services. TCP and UDP use IP for lower-layer delivery.

The transport layer meets several functions:

• Enabling applications to communicate over the network using a single device.


• Ensuring all data is received by the correct application.
• Handling fragmentation and reassembly.
• Managing error control mechanisms.

Comparison Between TCP and UDP


Service TCP UDP
The receiver can signal the sender to slow ACKs are not returned, making flow
Flow Control
down. control absent.
Requires a connection setup, ensuring
Connection Setup No connection is required.
reliability.
Guaranteed Message Returns acknowledgments to ensure UDP does not return ACKs, leading
Delivery message delivery. to possible data loss.
Network devices can use TCP ACKs for Lacks congestion control
Congestion Control
congestion control. mechanisms.

A significant difference between TCP and UDP is the congestion control algorithm. TCP prevents
senders from overrunning the network capacity and adapts to network conditions to avoid congestion. In
contrast, UDP provides a connectionless delivery service using IP without error recovery or flow control.
Applications using UDP must implement their own error detection mechanisms.

34
SIMULATION RESULTS:

The simulation was set for two hours, with data transfer between a LAN network and the server. No
packet latency or packet discard was observed with a 0% packet discard ratio while packets traversed the
WAN.

1. ResponsetimeforTCPand UDP

2. Trafficreceived(packets/sec)fortheserver

35
3. Traffic/Linkutilization from theWANtothe server

Link utilization with a 0.5% packets discard ratio

Observations:

1. Response Time for TCP and UDP: TCP took longer to complete the task due to its three-way
handshake and acknowledgment process, while UDP completed tasks faster without these
processes.
2. Traffic Received (Packets/sec): The server recorded higher throughput with UDP compared to
TCP.
3. Traffic/Link Utilization: With a 0.5% packet discard ratio, link utilization was observed to be
better with UDP due to its simplicity and lack of congestion control.

36
Conclusion:

The main difference between TCP and UDP lies in reliability and performance. TCP provides reliability
and congestion control, while UDP focuses on improving speed and performance. UDP is ideal for
applications that prioritize performance over reliability. TCP is preferable for scenarios where data
integrity and reliable delivery are critical.

RESULT:

Thus, the performance of TCP and UDP has been successfully simulated using OPNET.

37
DATE: 9.aSimulation of DistanceVectorRouting algorithm.

AIM:

To implement the Distance–Vector Routing Algorithm

APPARATUS REQUIRED:

1. VI-RTSIM software.
2. Personal computer.

THEORY:
Distance Vector Algorithm:

• Distance vector routing involves each router periodically sharing its knowledge about the entire
network with its neighbors.
• The three key principles to understand this algorithm are:
1. Knowledge about the whole network
2. Routing only to neighbors
3. Information sharing at regular intervals

Knowledge about the Whole Network:

• Each router shares its knowledge about the entire network by sending all collected information to
its neighbors.

Routing Only to Neighbors:

• Each router periodically sends its network knowledge only to its directly connected neighbors.

Information Sharing at Regular Intervals:

• Every 30 seconds, each router sends its information about the whole network to its neighbors.

Sharing Information:

• LANs are connected by routers, represented by nodes such as A, B, C, D, E, and F.


• Distance vector routing simplifies the routing process by assuming a cost of one unit per link.
• The transmission efficiency depends on the number of links required to reach a destination.

Routing Table:

• Each router maintains an initial routing table with knowledge of the internetwork and updates it
using shared information.
• The routing table consists of three columns:
o Destination Network: The final destination of the packet.
o Hop Count: Number of hops to reach the destination.

38
o Next Router: The router to which the packet should be forwarded.

Updating Algorithm:

1. Each router increments the hop count field for each advertised router.
2. The router applies the following rules to update the table:
o If the advertised destination is not in the routing table, it adds the entry.
o If the next hop field matches the current entry, it replaces the entry with the advertised one.
o If the next hop field is different but the advertised hop count is smaller, it updates the entry
with the new information.
o If the advertised hop count is not smaller, no update is made.

PROCEDURE:

1. Open the VI-RTSIM software from the desktop.


2. Click on the Simulation menu.
3. Select the Distance-Vector Routing Algorithm from the routing algorithm menu.
4. Draw the network with routers connected through links using options like:
o Add router
o Join link
o Delete router
o Delete link
o Add caption to link
o Add caption to router
5. Select any two nodes to find the shortest distance between them.
6. Click on the Find Path button to run the program.
7. The shortest paths between the two nodes are displayed.

39
RESULT:

Thus, the Distance Vector Routing Algorithm has been implemented, and the shortest path has been
calculated and displayed.

40
DATE: 9.b Simulation of Link State Routing Algorithm.

AIM:

To implement the Link State Routing Algorithm.

APPARATUS REQUIRED:

1. VI-RTSIM software.
2. Personal computer.

THEORY:

Link State Routing Algorithm:

• In Link State Routing, each router shares its information about its neighbors with every other
router in the internetwork.

Knowledge About the Neighborhood:

• Instead of sending its entire routing table, a router sends information only about its neighbors.

To All Routers:

• Each router sends this information to every other router in the internetwork, not just to its
neighbors.
• It uses a process called "flooding", meaning that a router sends its information to all routers.

Information Sharing When There Is a Change:

• Each router sends out information about its neighbors whenever there is a change in the network.

Information Sharing:

• Link State Routing uses the same internetwork as the Distance Vector Algorithm.
• Here, each router sends its knowledge about its neighbors to every other router in the network.
• Cost is applied only by routers and not by other stations in the network. If cost was applied by all
stations, it would accumulate unpredictably.
• Cost is applied as a packet leaves the router rather than when it enters.
• Most networks are broadcast networks, and packets can be picked up by every station, so cost
assignment is done only by routers.

Link State Packet (LSP):

• When a router floods the network with information about its neighborhood, it is said to be
advertising.
• The basis of this advertising is a short packet called a Link State Packet (LSP).
41
LSP Example:

Advertiser Network Cost Neighbor

Getting Information About Neighbors:

• A router gathers information about its neighbors by periodically sending a short greeting packet.
• If the neighbor responds as expected, it is assumed to be alive and functioning.

Initialization:

• Assume that all routers in the network come up at the same time.
• Each router sends a greeting packet to its neighbors to determine the state of each link.

Link-State Database:

• Every router collects all LSPs and stores the information in a Link-State Database.
• Since every router receives the same LSPs, they build an identical database.
• The database is stored on disk and used to calculate routing tables.
• If a router is added or removed, the entire database is shared for quick updates.

PROCEDURE:

1. Open VI-RTSIM software from the desktop.


2. Click on the Simulation menu bar.
3. Select the Link State Routing Algorithm option from the Routing Algorithm menu bar.
4. Draw the network with routers connected through links using the options in the editor (Add
Router, Join Link, Delete Router, Delete Link, Add Caption to Link, Add Caption to Router).
5. Select any two nodes to find the shortest distance between them.
6. Click on the Find Path button to run the program.
7. The shortest path between the two nodes using the Link State Routing Algorithm will be
calculated.

42
RESULT:

Thus, the Link-State Routing Algorithm has been implemented and the shortest path has been determined
successfully.

43
DATE: 10.Simulation of error correctioncode(like CRC)

AIM:

To implement and check the error detection/error correction techniques in networks using a C program.

APPARATUS REQUIRED:

1. PC with operating system


2. C/C++ compiler

THEORY:

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.
• Two basic approaches to handle errors:
o Notify the sender that the message is corrupt so the sender can retransmit it (used in most
everyday applications).
o 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, lost, or unwanted data can be generated.
• These problems are referred to as transmission errors.

Error Detection:

• Basic idea: Add redundant information to a frame to determine if errors have occurred.

Error Correction vs. Error Detection:

• Error detection requires retransmission using bandwidth and adds latency.


• Error correction requires additional bits to be sent with every frame.
• Correction is useful when:
1. Errors are probable
2. The cost of retransmission is too high

Cyclic Redundancy Check (CRC):

• CRC detects if the received frame contains valid data using binary division.
• The sender calculates a remainder by dividing data bits using a divisor.
• The remainder is appended to the data bits to form a codeword.
• At the receiver's end, a division operation is performed using the same divisor.
44
• If the remainder is all zeros, the data is accepted; otherwise, it is considered corrupted.

PROCEDURE:

1. Start the process.


2. Enter the data as a binary bitstream (7 bits).
3. Compile and run the program.
4. Enter the received Hamming code.
5. The error position is detected, and the corrected codeword is displayed.

PROGRAM 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 bitstream (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++;
45
}
}

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 (dw[j] == '1') count++;
j++;
}
}
dw[(int)pow(2, i)] = (count % 2 == 0) ? '0' : '1';
}

printf("Codeword is: ");


for (i = 1; i < 12; i++) printf("%c", dw[i]);

printf("\n\nEnter the received Hamming code: ");


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_pos + (int)pow(2, i);
}

if (err_pos == 0) {
printf("\nNo error detected in the received codeword.\n");
} else {
if (cw[err_pos] == dw[err_pos]) {
printf("\nThere are 2 or more errors in the received code. Hamming code cannot correct 2 or more
errors.\n");
flag = 1;
} else {
printf("\nThere is an error in bit position %d of the received codeword.\n", err_pos);
cw[err_pos] = (cw[err_pos] == '1') ? '0' : '1';
printf("\nCorrected codeword is: ");
for (i = 1; i < 12; i++) printf("%c", cw[i]);
}
}
printf("\n");

46
return 0;
}

OUTPUT:

Enter data as binary bitstream (7 bits):


1110110
Codeword is 11101100110
Enter the received Hamming code: 10101100110
There is an error in bit position 2 of the received codeword
Corrected codeword is 11101100110

Enter data as binary bitstream (7 bits):


11101110
Codeword is 11101100110
Enter the received Hamming code: 00101100110
There are 2 or more errors in the received code. Sorry!

RESULT:

Thus, error detection and correction techniques using a C program have been implemented and
verified successfully.

47

You might also like