CN Lab Manual
CN Lab Manual
DEPARTMENT OF INFORMATION
TECHNOLOGY
LAB MANUAL
B.TECH (IT)
(REG 2021)
SEMESTER : V
PREPARED BY
MS. M. AARTHIE
ASSISTANT PROFESSOR
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DAT SCIENCE
TABLE OF CONTENTS
2
PREREQUISTING KNOWLEDGE
Java
Networking Basics
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:
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:
6
DATE: 2.Write a HTTP webclient program to download a
Webpage using TCPsockets
AIM:
ALGORITHM:
vbnet
CopyEdit
GET /path/to/resource HTTP/1.1
Host: www.example.com
PROGRAM
import java.io.*;
import javax.net.ssl.*;
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);
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
} 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:
ALGORITHM:
Client Side:
Server Side:
PROGRAM:
Echo Client
import java.io.*;
import java.net.*;
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.*;
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
RESULT:
Thus the program for simulation of echo server and Client was written & executed.
13
DATE: 3.B.CLIENT-SERVER APPLICATION FOR CHAT
AIM:
Client:
Server:
PROGRAM:
TCP Server (TCPserver1.java)
import java.net.*;
import java.io.*;
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);
}
}
}
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:
ALGORITHM:
PROGRAM:
UDP DNS Server (udpdnsserver.java)
import java.io.*;
import java.net.*;
while (true) {
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
17
DatagramPacket recvPacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(recvPacket);
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);
}
}
}
import java.io.*;
import java.net.*;
if (args.length == 0) {
ipAddress = InetAddress.getLocalHost();
} else {
ipAddress = InetAddress.getByName(args[0]);
}
18
System.out.print("Enter the hostname: ");
String sentence = br.readLine();
sendData = sentence.getBytes();
clientSocket.close();
}
}
OUTPUT:
Server Output:
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
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.
PROCEDURE
Step 1: Install Wireshark
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.
21
RESULTS AND OBSERVATIONS
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:
ALGORITHM:
Client Side:
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);
Server Side:
2. Receive the IP address from the client using the input stream.
Runtime r = Runtime.getRuntime();
Process p = r.exec("arp -a " + ip);
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));
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);
25
String str;
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:
26
DATE: 6.b.Write a code simulating RARP protocols.
AIM:
To write a Java program for simulating RARP protocols.
ALGORITHM:
CLIENT
SERVER
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");
27
DatagramPacket receiver = new DatagramPacket(receivebyte, receivebyte.length);
client.receive(receiver);
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];
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:
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:
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.
The software has a comprehensive instruction manual and offers online help for easy understanding.
N-SIM is designed to provide an advanced understanding of network concepts using simulations and
animations.
Capabilities:
31
MODEL WINDOW DIAGRAM FOR N-SIM
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:
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:
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:
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.
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
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:
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
• Each router shares its knowledge about the entire network by sending all collected information to
its neighbors.
• Each router periodically sends its network knowledge only to its directly connected neighbors.
• Every 30 seconds, each router sends its information about the whole network to its neighbors.
Sharing Information:
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:
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:
APPARATUS REQUIRED:
1. VI-RTSIM software.
2. Personal computer.
THEORY:
• In Link State Routing, each router shares its information about its neighbors with every other
router in the internetwork.
• 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.
• 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.
• 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:
• 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:
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:
THEORY:
Error Detection:
Transmission Errors:
Error Detection:
• Basic idea: Add redundant information to a frame to determine if errors have occurred.
• 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:
#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];
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:
RESULT:
Thus, error detection and correction techniques using a C program have been implemented and
verified successfully.
47