CN Lab Manual
CN Lab Manual
Regulation : NR23
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
M2: Develop an innovative ecosystem with strong involvement and participation of students
and faculty members.
M3: Impart National development spirit among the students to utilize their knowledge and
skills for societal benefits with ethical values.
M1: To impart quality technical education in design and implementation of IT applications through
innovative teaching - learning practices
M2:To in culcate Professional behavior, with strong ethical values, and research capabilities.
M3:To educate students to be effective problem solvers with social sensitivity for the betterment of
the society and humanity as a whole.
PEO-I:To provide students with a solid foundation in mathematics, engineering, basic science
fundamentals required to solve computing problems and also to pursue higher studies and
research.
PEO-II: To train students with good Computer Science and Engineering breadth so as to
comprehend, analyze, design and create innovative computing products and solutions for real
lifeproblems.
Course Objectives
• To understand the working principle of various communication protocols.
• To understand the network simulator environment and visualize a network
topology and observe its performance
• To analyze the traffic flow and the contents of protocol frames
Course Outcomes
• Implement data link layer farming methods
• Analyze error detection and error correction codes.
• Implement and analyze routing and congestion issues in network design.
• Implement Encoding and Decoding techniques used in presentation layer
• To be able to work with different network tools
List of Experiments
1. Implement the data link layer framing methods such as character, character-
stuffing and bit stuffing.
2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC
CCIP
3. Develop a simple data link layer that performs the flow control using the
sliding window protocol, and loss recovery using the Go-Back-N
mechanism.
4. Implement Dijsktra’s algorithm to compute the shortest path through a network
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
6. Implement distance vector routing algorithm for obtaining routing tables at each node.
7. Implement data encryption and data decryption
8. Write a program for congestion control using Leaky bucket algorithm.
9. Write a program for frame sorting techniques used in buffers.
10. Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics &
Filters. How to run Nmap scan
Operating System Detection using
NR23 B.Tech. CSE Syllabus NRCM
Nmap Do the following using NS2
Simulator
i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate & Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to Transmission of Packets
TEXT BOOK:
1. Computer Networks, Andrew S Tanenbaum, David. j. Wetherall, 5th
Edition. Pearson Education/PHI.
REFERENCE BOOKS:
1. An Engineering Approach to Computer Networks, S. Keshav, 2nd Edition, Pearson
Education.
2. Data Communications and Networking – Behrouz A. Forouzan. 3rd Edition, TMH.
NR23 [COMPUTER NETWORKS LAB]
1. Implement the data link layer framing methods such as character, characterstuffing and bit
stuffing.
1. AIM: To implement the Data Link Layer Framing methods such as Character Count,
Character Stuffing, and Bit Stuffing.
2. ALGORITHM / DESCRIPTION
Character Count Method:
1. Count the number of characters in the frame.
2. Prefix the count at the beginning of the frame.
3. Send the frame with the count byte.
Character Stuffing:
1. Define a special flag character (e.g., #) to mark frame boundaries.
2. Insert an escape character (e.g., \) before each occurrence of the flag or escape character in the
data.
3. Transmit the data with start and end flag.
Bit Stuffing:
1. Monitor the bit stream continuously.
2. After 5 consecutive 1s in the data, insert a 0.
3. At the receiver, after seeing 5 1s followed by 0, remove the stuffed 0.
3. PROGRAM
#include <stdio.h>
#include <string.h>
void characterStuffing() {
char input[50], stuffed[100] = "";
printf("Enter the input string: ");
scanf("%s", input);
strcat(stuffed, "#");
for (int i = 0; i < strlen(input); i++) {
if (input[i] == '#' || input[i] == '\\')
strcat(stuffed, "\\");
M.SHRAVANI,CSE | 1
NR23 [COMPUTER NETWORKS LAB]
void bitStuffing() {
int data[50], stuffed[100], n, i, j = 0, count = 0;
printf("Enter the number of bits: ");
scanf("%d", &n);
printf("Enter the bits: ");
for (i = 0; i < n; i++) scanf("%d", &data[i]);
int main() {
int choice;
printf("1. Character Stuffing\n2. Bit Stuffing\nEnter your choice: ");
scanf("%d", &choice);
M.SHRAVANI,CSE | 2
NR23 [COMPUTER NETWORKS LAB]
if (choice == 1)
characterStuffing();
else
bitStuffing();
return 0;
}
4. OUTPUT
Output 1: Character Stuffing
Enter the input string: hello#net
Stuffed Data: #hello\#net#
Answer: To ensure correct data boundaries and allow the receiver to identify the start and end
of each frame.
Answer: Character stuffing adds escape characters before special bytes, whereas bit stuffing
inserts bits after a sequence of bits.
Answer: It is a special character (e.g., '#') that marks the start and end of a frame.
M.SHRAVANI,CSE | 3
NR23 [COMPUTER NETWORKS LAB]
Answer: To differentiate between data and control characters like frame delimiters.
Answer: Synchronous uses a clock signal to sync transmission; asynchronous uses start/stop
bits.
Answer: By detecting the special pattern and removing inserted bits after five 1s.
Answer: If the count field is corrupted, the entire frame may be misread.
Answer: Bit stuffing is often more reliable for binary streams; character stuffing is easier for
text-based protocols.
M.SHRAVANI,CSE | 4
NR23 [COMPUTER NETWORKS LAB]
2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP
1. AIM: To write a program to compute CRC code for the polynomials CRC-12, CRC-16,
and CRC-CCIP.
2. ALGORITHM / DESCRIPTION
1. Accept input data bits and a divisor polynomial (e.g., CRC-12, CRC-16, or CRC-CCIP).
2. Append zeros (length of divisor - 1) to the input data.
3. Perform binary division (XOR) of the input with the divisor.
4. The remainder is the CRC.
5. Append the CRC to the original data to form the transmitted frame.
3. C PROGRAM
#include <stdio.h>
#include <string.h>
strcpy(temp, data);
for (int i = 0; i < divisorLen - 1; i++)
strcat(temp, "0");
char current[100];
strncpy(current, temp, divisorLen);
M.SHRAVANI,CSE | 5
NR23 [COMPUTER NETWORKS LAB]
current[divisorLen] = '\0';
int main() {
char data[50], crc12[] = "1100000001111", crc16[] =
"11000000000000101", ccip[] =
"100000100110000010001110110110111";
int choice;
switch (choice) {
case 1: computeCRC(data, crc12); break;
case 2: computeCRC(data, crc16); break;
case 3: computeCRC(data, ccip); break;
default: printf("Invalid choice!\n");
M.SHRAVANI,CSE | 6
NR23 [COMPUTER NETWORKS LAB]
}
return 0;
}
4. OUTPUT
Sample Input:
Enter data bits: 1101011011
Choose CRC type:
1. CRC-12
2. CRC-16
3. CRC-CCIP
Enter choice: 1
Output:
CRC: 100000111111
Transmitted Frame: 1101011011100000111111
Answer: CRC detects more complex errors than parity, which can only detect odd numbers of
bit errors.
M.SHRAVANI,CSE | 7
NR23 [COMPUTER NETWORKS LAB]
Answer: It can detect most common errors, but not all possible errors.
Answer: 12 bits.
Answer: Yes, CRC is used in Ethernet, HDLC, USB, and other communication standards.
Answer: Only specific, standardized polynomials are used to ensure effective error detection.
M.SHRAVANI,CSE | 8
NR23 [COMPUTER NETWORKS LAB]
3. Develop a simple data link layer that performs the flow control using the sliding window
protocol, and loss recovery using the Go-Back-N mechanism.
1. AIM
To develop a simple data link layer that performs the flow control using the sliding window
protocol and loss recovery using the Go-Back-N mechanism.
2. ALGORITHM / DESCRIPTION
1. Set sender window size (N).
2. Send N frames initially.
3. Wait for acknowledgments (ACKs) from the receiver.
4. If ACK received, slide the window and send next frame.
5. If ACK not received within timeout, resend all frames from last ACK.
6. Repeat until all frames are acknowledged.
3. C PROGRAM
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 10
int main() {
int frames[MAX], i, windowSize, sent = 0, ack;
M.SHRAVANI,CSE | 9
NR23 [COMPUTER NETWORKS LAB]
srand(time(NULL));
ack = sent + (rand() % windowSize); // simulate random ACK loss
4. OUTPUT
Sample Output:
Enter number of frames to send: 5
Enter window size: 3
M.SHRAVANI,CSE | 10
NR23 [COMPUTER NETWORKS LAB]
Sending frames: 0 1 2
Acknowledgment received for frame: 1
Sending frames: 2 3 4
Acknowledgment received for frame: 4
Answer: It is a flow control method that allows multiple frames to be sent before needing an
acknowledgment.
Answer: An error control protocol that resends all frames from the last unacknowledged frame
after a timeout.
Answer: Go-Back-N resends all frames after a lost one, while Selective Repeat resends only
the lost frames.
Answer: It is the maximum number of frames the sender can send without waiting for an
acknowledgment.
Answer: To prevent overwhelming the receiver with too many frames at once.
Answer: The sender assumes loss and resends all unacknowledged frames.
M.SHRAVANI,CSE | 11
NR23 [COMPUTER NETWORKS LAB]
Answer: It discards the frame and does not send an ACK, prompting retransmission.
Answer: ACK for a frame implies that all previous frames have been received correctly.
M.SHRAVANI,CSE | 12
NR23 [COMPUTER NETWORKS LAB]
1. AIM:To implement Dijkstra’s algorithm to compute the shortest path through a network.
2. ALGORITHM / DESCRIPTION
3. C PROGRAM
#include <stdio.h>
#define INF 9999
#define MAX 10
M.SHRAVANI,CSE | 13
NR23 [COMPUTER NETWORKS LAB]
}
}
visited[nextNode] = 1;
for (j = 0; j < n; j++) {
if (!visited[j] && distance[nextNode] + graph[nextNode][j] < distance[j]) {
distance[j] = distance[nextNode] + graph[nextNode][j];
}
}
}
int main() {
int graph[MAX][MAX], n, i, j, start;
printf("Enter number of nodes: ");
scanf("%d", &n);
dijkstra(graph, n, start);
return 0;
}
M.SHRAVANI,CSE | 14
NR23 [COMPUTER NETWORKS LAB]
4. OUTPUT
Enter number of nodes: 4
Enter the adjacency matrix (9999 for no path):
0 3 9999 7
3 0 1 9999
9999 1 0 2
7 9999 2 0
Enter the starting node (0 to 3): 0
M.SHRAVANI,CSE | 15
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 16
NR23 [COMPUTER NETWORKS LAB]
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
1. AIM: To take an example subnet of hosts and obtain a broadcast tree for the subnet.
2. ALGORITHM / DESCRIPTION
1. Represent the subnet as a weighted undirected graph where nodes are hosts and edges are
connections with cost.
2. Use Prim’s algorithm to find the Minimum Spanning Tree (MST).
3. Start with an arbitrary node as the root of the tree.
4. Add the nearest node not in the tree by selecting the minimum weight edge.
5. Repeat until all nodes are included.
6. The resulting MST represents the broadcast tree.
3. C PROGRAM
#include <stdio.h>
#define INF 9999
#define MAX 20
int main() {
int cost[MAX][MAX], visited[MAX] = {0}, i, j, n, no_edges = 0;
int min, a, b, total_cost = 0;
M.SHRAVANI,CSE | 17
NR23 [COMPUTER NETWORKS LAB]
visited[0] = 1;
printf("Edges in the broadcast tree:\n");
4. OUTPUT
yaml
CopyEdit
Enter number of nodes (hosts): 4
M.SHRAVANI,CSE | 18
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 19
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 20
NR23 [COMPUTER NETWORKS LAB]
6. Implement distance vector routing algorithm for obtaining routing tables at each node.
1. AIM:To implement the Distance Vector Routing Algorithm for obtaining routing tables at
each node in a subnet.
2. ALGORITHM / DESCRIPTION
1. Initialize the routing table of each node with direct link costs to neighbors.
2. Set the cost to self as 0 and to unreachable nodes as ∞.
3. Exchange routing tables periodically with immediate neighbors.
4. Update each node's table using the Bellman-Ford equation:
3. C PROGRAM
#include <stdio.h>
#define INFINITY 9999
#define MAX 10
int main() {
int cost[MAX][MAX], dist[MAX][MAX], via[MAX][MAX];
int n, i, j, k;
M.SHRAVANI,CSE | 21
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 22
NR23 [COMPUTER NETWORKS LAB]
}
}
return 0;
}
4. OUTPUT
Enter number of nodes: 3
Enter the cost matrix:
027
201
710
M.SHRAVANI,CSE | 23
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 24
NR23 [COMPUTER NETWORKS LAB]
Experiment -7
7. Implement data encryption and data decryption
1. AIM
2. ALGORITHM / DESCRIPTION
3. C PROGRAM
#include <stdio.h>
#include <string.h>
M.SHRAVANI,CSE | 25
NR23 [COMPUTER NETWORKS LAB]
int main() {
char message[100];
int key;
encrypt(message, key);
printf("Encrypted message: %s\n", message);
decrypt(message, key);
printf("Decrypted message: %s\n", message);
return 0;
}
4. OUTPUT
pgsql
CopyEdit
Enter message to encrypt: hello
Enter encryption key (integer): 3
Encrypted message: khoor
Decrypted message: hello
M.SHRAVANI,CSE | 26
NR23 [COMPUTER NETWORKS LAB]
1. What is encryption?
It is the process of converting plaintext into unreadable ciphertext.
2. What is decryption?
It is the process of converting ciphertext back into readable plaintext.
3. What is a cipher?
It is an algorithm used to perform encryption or decryption.
4. What is a key in encryption?
A value used in the algorithm to transform data during encryption or decryption.
5. What type of encryption is used here?
Simple symmetric encryption (Caesar cipher style).
6. What is symmetric encryption?
Encryption where the same key is used for both encryption and decryption.
7. What is ASCII value manipulation in encryption?
It uses arithmetic on ASCII values to alter characters.
8. Can this method protect sensitive data?
No, it's too simple and not secure for real-world use.
9. What is the advantage of symmetric encryption?
It is fast and easy to implement.
10. What is one disadvantage of symmetric encryption?
Key distribution must be secure; otherwise, data is compromised.
M.SHRAVANI,CSE | 27
NR23 [COMPUTER NETWORKS LAB]
Experiment- 8
1. AIM:To write a program for congestion control using the Leaky Bucket algorithm.
2. ALGORITHM / DESCRIPTION
3. C PROGRAM
#include <stdio.h>
int main() {
int bucket_size, output_rate, n, i;
int input[20], storage = 0, dropped;
M.SHRAVANI,CSE | 28
NR23 [COMPUTER NETWORKS LAB]
return 0;
}
4. OUTPUT
yaml
CopyEdit
Enter bucket size: 10
Enter output rate: 4
Enter number of input time slots: 4
Enter incoming packet size at each time slot:
Time 1: 6
M.SHRAVANI,CSE | 29
NR23 [COMPUTER NETWORKS LAB]
Time 2: 5
Time 3: 2
Time 4: 8
Time 1:
Incoming packet size: 6
Bucket status: 6/10
Packets sent: 4
Packets dropped: 0
Time 2:
Incoming packet size: 5
Bucket status: 7/10
Packets sent: 4
Packets dropped: 0
Time 3:
Incoming packet size: 2
Bucket status: 5/10
Packets sent: 4
Packets dropped: 0
Time 4:
Incoming packet size: 8
Bucket status: 9/10
Packets sent: 4
Packets dropped: 3
M.SHRAVANI,CSE | 30
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 31
NR23 [COMPUTER NETWORKS LAB]
1. AIM
To write a program for sorting out-of-order frames in a buffer using sequence numbers.
2. ALGORITHM / DESCRIPTION
3. C PROGRAM
c
CopyEdit
#include <stdio.h>
M.SHRAVANI,CSE | 32
NR23 [COMPUTER NETWORKS LAB]
int main() {
int frames[20], n, i;
sort(frames, n);
return 0;
}
4. OUTPUT
Enter number of frames: 5
Enter frame sequence numbers (out-of-order):
41352
Frames in sorted order:
12345
M.SHRAVANI,CSE | 33
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 34
NR23 [COMPUTER NETWORKS LAB]
i. NS2 Simulator-Introduction
ii. ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate & Throughput. vi. Simulate to Plot Congestion for Different
Source/Destination vii. Simulate to Determine the Performance with respect to
Transmission of Packets
1. AIM
To analyze network traffic using Wireshark and simulate network behavior using NS2 to study
packet drops, throughput, and congestion control.
2. ALGORITHM / DESCRIPTION
A. Wireshark
1. Packet Capture:
o Launch Wireshark and select a network interface.
o Click “Start Capturing Packets” to begin live capture.
M.SHRAVANI,CSE | 35
NR23 [COMPUTER NETWORKS LAB]
2. Starting Wireshark:
o Open the application from the start menu or terminal (wireshark).
3. Viewing Captured Traffic:
o Use the middle pane to examine individual packets.
o Apply filters like ip, tcp, udp, icmp for specific analysis.
4. Analysis and Statistics:
o Use “Statistics” → “Protocol Hierarchy”, “Conversations”, “IO Graphs” to
interpret results.
5. Running Nmap:
o Run nmap -sS <target IP> to perform a SYN scan.
o Use nmap -O <target IP> for OS detection.
B. NS2 Simulator
1. Introduction:
o NS2 is a discrete event simulator used to simulate routing, congestion, and
protocols.
2. Packet Drop Analysis:
o Write a Tcl script with dropping logic using DropTail or RED.
o Analyze using trace file and tools like awk.
3. TCP/UDP Drop Detection:
o Filter trace file for lines with tcp or udp and event d.
4. Congestion Simulation:
o Create two flows to one destination with limited bandwidth and buffer.
5. Data Rate & Throughput Comparison:
o Analyze received packet count and timestamps.
6. Plot Congestion:
o Use Xgraph to visualize congestion points.
7. Performance Evaluation:
o Calculate metrics like throughput, drop ratio, delay using trace files.
M.SHRAVANI,CSE | 36
NR23 [COMPUTER NETWORKS LAB]
M.SHRAVANI,CSE | 37
NR23 [COMPUTER NETWORKS LAB]
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam out.nam &
exit 0
}
$ns run
4. OUTPUT
Wireshark:
Nmap:
nginx
CopyEdit
nmap -sS 192.168.1.1
nmap -O 192.168.1.1
M.SHRAVANI,CSE | 38
NR23 [COMPUTER NETWORKS LAB]
1. What is Wireshark?
It is a network protocol analyzer used to capture and inspect data packets.
2. What is NS2 used for?
NS2 is a simulator used to model computer networks and analyze their behavior.
3. How do you filter TCP traffic in Wireshark?
Use filter tcp or tcp.port == <port number>.
4. What does nmap -O do?
It performs OS detection on a target host.
5. What is the .tr file in NS2?
It is the trace file containing simulation events for analysis.
6. What does the d event in trace file mean?
It indicates a dropped packet.
7. How do you simulate congestion in NS2?
By creating multiple flows to a bottleneck link.
8. What tools are used to analyze NS2 trace files?
awk, perl, or custom scripts.
9. What is throughput?
The rate of successful data delivery over a network channel.
10. What is a NAM file?
NAM is the Network Animator that visually simulates the NS2 network topology.
M.SHRAVANI,CSE | 39