1.
INTRODUCTION TO COMPUTER NETWORKS
A Computer Network is a collection of interconnected computing devices that can
communicate with each other and share resources such as data, software, hardware, and
internet connectivity. These devices may include computers, servers, routers, switches,
mobile devices, and embedded systems. Communication between devices is achieved
using standard networking protocols that ensure reliable and secure data transmission.
Computer Networks form the backbone of modern digital communication. From sending
emails and browsing websites to cloud computing and online banking, almost every
digital service depends on computer networks. With the rapid growth of the internet,
networking has become a fundamental subject in computer science and engineering.
Diagram Description:
The diagram shows multiple computers connected through a switch/router forming a network.
Each computer acts as a node and communicates using network links.
1.1 Need for Computer Networks
The primary reasons for using computer networks are:
● Resource Sharing: Hardware (printers, storage), software, and data can be shared among
multiple users.
● Communication: Enables fast communication through emails, video calls, messaging, and
file transfer.
● Reliability: Data can be stored on multiple machines, improving fault tolerance.
● Scalability: Networks can be expanded easily by adding more devices.
● Cost Efficiency: Shared resources reduce overall operational cost.
1.2 Applications of Computer Networks
Computer Networks are widely used in almost every field. Some major applications are:
1 Business Applications
● Online transactions and digital payments
● Cloud-based services
● Video conferencing and remote collaboration
● Data sharing between departments
2 Educational Applications
● Online learning platforms and virtual classrooms
● Digital libraries and research databases
● Student information systems
● Remote access to lab resources
3 Communication Applications
● Email services
● Instant messaging
● Voice over IP (VoIP)
● Social networking platforms
4 Healthcare Applications
● Electronic health records
● Telemedicine
● Medical data sharing
● Remote patient monitoring
5 Industrial and Scientific Applications
● Process automation
● Distributed computing
● IoT-based monitoring systems
● Data analysis and research collaboration
1.3 Types of Computer Networks
● LAN (Local Area Network): Covers a small area like a lab, office, or building.
● MAN (Metropolitan Area Network): Covers a city or large campus.
● WAN (Wide Area Network): Covers large geographical areas; the Internet is the best
example.
2. STUDY OF NETWORKING DEVICES
1. Bridge
Definition:
A Bridge is a network device that operates at the Data Link Layer (Layer 2) of the OSI
model. It is used to connect and filter traffic between two or more LAN segments.
Diagram Description:
The diagram shows two LAN segments connected using a bridge.
Working:
A bridge examines the MAC address of incoming data frames and forwards them only to
the relevant segment. This reduces unnecessary traffic and improves network
performance.
Advantages:
● Reduces network congestion
● Improves performance by filtering traffic
● Simple to install and
configure Limitations:
● Slower compared to switches
● Limited scalability
● Cannot handle complex routing
2. Router
Definition:
A Router is a networking device that operates at the Network Layer (Layer 3) of the OSI model.
It is used to connect different networks and route data packets between them.
Diagram Description:
The diagram shows multiple networks connected through a router, each network having a
different IP address range.
Working:
Routers use IP addresses and routing tables to determine the best path for data packets. They can
connect LANs to WANs and provide internet access.
Advantages:
● Connects different networks
● Provides security using firewalls and access control
● Supports multiple routing
protocols Applications:
● Internet connectivity
● Enterprise networks
● Home and office networks
3. Gateway
Definition:
A Gateway is a network device that connects networks using different protocols or
architectures. It can operate across multiple layers of the OSI model.
Diagram Description:
The diagram shows two different networks using different protocols connected through a
gateway.
Working:
Gateways perform protocol conversion, data translation, and communication
management between incompatible networks.
Examples:
● Email gateways
● VoIP gateways
● Internet
gateways
Advantages:
● Enables communication between different network systems
● Supports protocol conversion
● Highly flexible
4. Switch
Diagram Description:
The diagram shows multiple computers connected to a central switch within a LAN.
Definition:
A Switch is a network device that operates mainly at the Data Link Layer (Layer 2)
and sometimes at Layer 3. It connects multiple devices within a LAN.
Working:
A switch uses a MAC address table to forward data frames only to the destination
device, reducing collisions and improving efficiency.
Advantages:
● High-speed data transfer
● Reduces network collisions
● Better performance than hubs and
bridges Applications:
● Local area networks
● Office and campus networks
● Data centers
3. CISCO PACKET TRACER
Definition:
Cisco Packet Tracer is a network simulation software developed by Cisco that allows
users to design, configure, and test computer networks virtually.
It helps students and beginners:
● build network topologies,
● configure routers and switches,
● understand how data packets move in a network,
● practice networking concepts without real hardware.
It is mainly used for learning networking and CCNA preparation.
Explanation of the Given Cisco Packet Tracer Interface:
1 Menu Bar
This is the menu bar at the top.
● Contains options like File, Edit, View, Tools, Extensions, Help.
● Used to create new files, save projects, change settings, and access help.
2 Main Toolbar
This toolbar provides quick access icons for:
● New file, Open, Save
● Undo / Redo
● Zoom in / Zoom out
● Show or hide panels
3 Common Tools Bar
This section contains editing and drawing tools, such as:
● Select tool
● Delete tool
● Draw line, rectangle, ellipse
● Add notes or labels
4 Logical / Physical Workspace Selector
This bar lets you switch between:
● Logical View → shows how devices are logically connected.
● Physical View → shows physical layout like rooms, racks, buildings.
5 Workspace (Main Working Area)
This is the main design area.
● All routers, switches, PCs, and connections are placed here.
● You build the actual network topology in this area.
6 Device-Type Selection Bar
This bar shows categories of devices, such as:
● Network Devices
● End Devices
● Connections
● IoT Devices
7 (Implicit – Mode Control Area)
Near this area you control how the network runs:
● Realtime Mode → normal operation
● Simulation Mode → packet-by-packet analysis
8 Device Category Icons
This section shows device categories, like:
● Routers
● Switches
● End devices (PC, Laptop, Server)
● Wireless devices
9 Device Model Selection Area
Here you see specific models, for example:
● Router 1941, 2901
● Switch 2960
● PT-Router, PT-Cloud
10 Simulation / Event List Panel
This panel is used in Simulation Mode.
● Shows packet details like source, destination, type, status.
● Helps analyze how data moves through the network.
Output:-
Enter IP Address:
[Link] IP Class: C
Program 1:
Find class of an IP
import [Link];
public class IPClassFinder {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter IP Address: ");
String ip = [Link]();
int first = 0;
int i = 0;
// Extract first octet
while (i < [Link]() && [Link](i) != '.') {
first = first * 10 + ([Link](i) - '0');
i++;
}
// Determine class
if (first >= 1 && first <= 126) {
[Link]("IP Class: A");
} else if (first >= 128 && first <= 191) {
[Link]("IP Class: B");
} else if (first >= 192 && first <= 223) {
[Link]("IP Class: C");
} else if (first >= 224 && first <= 239) {
[Link]("IP Class: D");
} else {
[Link]("IP Class: E");
}
[Link]();
}
}
Output:-
Enter IP Address:
[Link] Net ID:
192.168.1
Host ID: 10
Range: [Link] to
[Link]
Program 2:
Find Net ID, Host ID and Range of IP Address
import [Link].*;
public class IPDetails {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter IP Address: ");
String ip = [Link]();
String[] parts = [Link]("\\.");
if ([Link] != 4) {
[Link]("Invalid IP format");
return;
}
int a = [Link](parts[0]);
int b = [Link](parts[1]);
int c = [Link](parts[2]);
int d = [Link](parts[3]);
if (a >= 1 && a <= 126) {
[Link]("Net ID: " + a);
[Link]("Host ID: " + b + "." + c + "." + d);
[Link]("Range: " + a + ".0.0.0 to " + a + ".255.255.255");
}
else if (a >= 128 && a <= 191) {
[Link]("Net ID: " + a + "." + b);
[Link]("Host ID: " + c + "." + d);
[Link]("Range: " + a + "." + b + ".0.0 to " + a + "." + b + ".255.255");
}
else if (a >= 192 && a <= 223) {
[Link]("Net ID: " + a + "." + b + "." + c);
[Link]("Host ID: " + d);
[Link]("Range: " + a + "." + b + "." + c + ".0 to " + a + "." + b + "." +
c + ".255");
}
else {
[Link]("Invalid or unsupported class");
}
[Link]();
}
}
Output:
Enter the first string :
10110
Enter second string :
10001
Hamming distance is :3
XOR = 00111
Program 3:
Find Hamming Distance Between Two Binary Strings
import [Link].*;
public class hamming {
public static void main(String[] args) {
{
try (Scanner sc = new Scanner([Link])) {
[Link]("Enter the first string :");
String s1 = [Link]();
[Link]("Enter second string :");
String s2 = [Link]();
if ([Link]() != [Link]()) {
[Link]("Hamming distance not possible.");
}
String xor = "";
int distance = 0;
for (int i = 0; i < [Link](); i++) {
if ([Link](i) != [Link](i)) {
distance++;
xor+=1;
}
else{
xor+=0;
}
}
[Link]("Hamming distance is :" + distance);
[Link]("XOR = " +xor);
}
}
}
}
Output
Program 4:
Write a program for Implementation of Stop-and-Wait Protocol.
import [Link];
public class stop_and_wait {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of frames: ");
int n = [Link]();
for (int i = 1; i <= n; i++) {
[Link]("Sending Frame " + i);
[Link]("Did receiver receive frame " + i + "? (yes/no): ");
String ack = [Link]();
if ([Link]("yes")) {
[Link]("ACK received for Frame " + i);
} else {
[Link]("Resending Frame " + i);
i--; // resend same frame
}
}
[Link]("All frames sent successfully!");
}
}
Output:
Enter total number of frames: 5
Enter window size: 2
Sending frames:
Frame 1 sent
Frame 2 sent
Enter last successfully received frame: 2
Sending frames:
Frame 3 sent
Frame 4 sent
Enter last successfully received frame: 3
Sending frames:
Frame 4 sent
Frame 5 sent
Enter last successfully received frame: 5
All frames transmitted successfully!
PS C:\Users\LENOVO\java\practice>
Program 5:
Write a program for Implementation of Go-Back-N Protocol.
import [Link];
public class GoBackN {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter total number of frames: ");
int total = [Link]();
[Link]("Enter window size: ");
int window = [Link]();
int i = 1;
while (i <= total) {
[Link]("\nSending frames:");
for (int j = 0; j < window && (i + j) <= total; j++) {
[Link]("Frame " + (i + j) + " sent");
}
[Link]("Enter last successfully received frame: ");
int ack = [Link]();
if (ack < i) {
[Link]("Error! Resending from Frame " + i);
} else {
i = ack + 1;
}
}
[Link]("All frames transmitted successfully!");
}
}
Output:
Enter number of frames: 3
Was Frame 1 received? (true/false): true
Was Frame 2 received? (true/false): false
Was Frame 3 received? (true/false): true
Retransmitting lost frames:
Resending Frame 2
Transmission complete!
Program 6:
Write a program for Implementation of Selective repeat Protocol.
import [Link];
public class SelectiveRepeat {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of frames: ");
int n = [Link]();
boolean[] received = new boolean[n];
for (int i = 0; i < n; i++) {
[Link]("Was Frame " + (i + 1) + " received? (true/false): ");
received[i] = [Link]();
}
[Link]("\nRetransmitting lost frames:");
for (int i = 0; i < n; i++) {
if (!received[i]) {
[Link]("Resending Frame " + (i + 1));
}
}
[Link]("Transmission complete!");
}
}
Fig 1:
Fig 2:
Program 7:
Implement Mesh Topology.
In the mesh topology of networking, each and every device sends its own signal to the
other devices that are present in the arrangement of the network.
Steps to Configure and Setup Ring Topology in Cisco Packet Tracer:
Step 1: First, open the Cisco packet tracer desktop and select the devices given below:
[Link] Device Model name
1. PC PC
2. Switch PT-switch
IP Addressing Table:
[Link] Device IPv4 Address Subnet Mask
1. Pc11 [Link] [Link]
2. pc12 [Link] [Link]
3. Pc13 [Link] [Link]
4. Pc14 [Link] [Link]
Then, create a network topology as shown below the image.
Use an Automatic connecting cable to connect the devices with others.
Fig 1: Mesh Topology.
Step 2: Configure the PCs (hosts) with IPv4 address and Subnet Mask according to the
IP addressing table given above.
To assign an IP address in PC11, click on PC11.
Then, go to desktop and then IP configuration and there you will IPv4
configuration.
Fill IPv4 address and subnet mask.
Fig 2:
Fig 3:
Fig 4:
Assigning IP address using the ipconfig command.
Also, we can also assign an IP address with the help of a command.
Go to the command terminal of the PC.
Then, type ipconfig <IPv4 address><subnet mask><default gateway>(if needed)
Example: ipconfig [Link] [Link]
Fig 3:
Repeat the same procedure with other PCs to configure them thoroughly.
Step 3: Verify the connection by pinging the IP address of any host in PC11.
Use the ping command to verify the connection.
We will check if we are getting any replies or not.
Here we get replies from a targeted node on both PCs.
Hence the connection is verified.
A simulation of the experiment is given below we have sent two PDU packets
targeted from PC11 to PC14 Fig 4:
Fig 5:
Fig 6:
Program 8:
Implement Bus Topology.
A bus topology is a network in which nodes are directly linked with a common half-
duplex link. A host on a bus topology is called a station. In a bus network, every station
will accept all network packets, and these packets generated by each station have equal
information priority. A bus network includes a single network segment and collision
domain.
Steps to Configure and Setup Bus Topology in Cisco Packet Tracer :
Step 1: First, open the cisco packet tracer desktop and select the devices given below:
Devic
[Link] e Model-Name
1. PC PC
2. Switch PT-Switch
IP Addressing Table
[Link] Device IPv4 Address Subnet Mask
Pc15 [Link] [Link]
pc16 [Link] [Link]
Pc17 [Link] [Link]
Pc18 [Link] [Link]
Then, create a network topology as shown below image:
Use an Automatic connecting cable to connect the devices with others.
Fig 5: Bus Topology
Step 2: Configure the PCs (hosts) with IPv4 address and Subnet Mask according to the
IP addressing table given above.
To assign an IP address in PC15, click on PC15.
Then, go to desktop and then IP configuration and there you will IPv4
configuration.
Fill IPv4 address and subnet mask.
Fig 6:
Fig 7:
Fig 8:
Assigning an IP address using the ipconfig command, or we can also assign an IP
address with the help of a command.
Go to the command terminal of the PC.
Then, type ipconfig <IPv4 address><subnet mask><default gateway>(if needed)
Example: ipconfig [Link] [Link]
Repeat the same procedure with other PCs to configure them thoroughly.
Step 3: Verify the connection by pinging the IP address of any host in PC15.
Use the ping command to verify the connection.
As we can see we are getting replies from a targeted node on both PCs.
Hence the connection is verified.
Fig 7:
A simulation of the experiment is given below we have sent two PDU packets
one targeted from PC15 to PC18 Fig 8:
Fig :9
Fig :10
Program 9:
Implement Star Topology.
A star topology for a Local Area Network (LAN) is one in which each node is
connected to a central connection point, such as a hub or switch. Whenever a
node tries to connect with another node then the transmission of the message
must be happening with the help of the central node. The best part of star
topology is the addition and removal of the node in the network but too many
nodes can cause suffering to the network.
Steps Implementing Star Topology using Cisco Packet Tracer:
Step 1: We have taken a switch and linked it to six end devices.
Step 2: Link every device with the switch. Fig 9:
Step 3: Provide the IP address to each device.
Step 4: Transfer message from one device to another and check the Table for
Validation. Fig 10:
[Link] Device Model-Name
1. PC PC
2. Switch PT-Switch
IP Addressing Table
S.N
O Device IPv4 Address Subnet Mask
pc0 [Link] [Link]
pc1 [Link] [Link]
pc2 [Link] [Link]
pc3 [Link] [Link]
Fig :11
Fig :12
Now to check whether the connections are correct or not try to ping any
device and the image below is doing the same.
To do ping one terminal of one device and run the following command:
Command:
"ping ip_address_of _any_device"
Example:
ping [Link]
Note:If the connections are correct
then you will receive the response. Fig :11
A simulation of the experiment is given below we have sent two PDU packets
one targeted from PC0 to PC5 Fig 12:
Fig :13
Fig :14
Program 10:
Implement ARP Protocol.
1. Aim
To implement and observe the working of the Address Resolution Protocol (ARP) in a
Bus Topology using Cisco Packet Tracer.
2. Theory
The Address Resolution Protocol (ARP) is used to map an IP address to a MAC address
in a local network. In a bus topology, all devices share a common communication
medium. When a device sends an ARP request, it is broadcast to all devices, and only the
device with the matching IP address responds with its MAC address.
3. Network Topology (As per given diagram)
PC6 → [Link]
PC8 → [Link]
PC7 → [Link]
All devices connected through a switch (logical bus communication)
Label:
Fig 13:
4. Requirements
[Link] Device Model
1 PC PC-PT
2 Switch PT-Switch
5. IP Addressing Table
Device IPv4 Address Subnet Mask
PC6 [Link] [Link]
PC8 [Link] [Link]
PC7 [Link] [Link]
6. Procedure
Step 1: Create Topology
Open Cisco Packet Tracer
Add 3 PCs and 1 Switch
Connect all PCs to the switch using automatic cables
This forms a logical bus network
Step 2: Configure IP Addresses
Click on each PC
Fig :15
Fig: 16
Fig :17
Go to Desktop → IP Configuration
Assign IP and Subnet Mask as per table
OR using command:
ipconfig [Link] [Link]
(Repeat for all PCs with respective IPs)
Fig :14
Step 3: Check ARP Table (Before Communication)
On PC6:
arp -a Fig :15
Initially, no entries will be present
Step 4: Generate ARP Request using Ping
From PC6:
ping [Link] Fig:16
What happens:
PC6 broadcasts ARP request:
“Who has [Link]?”
All PCs receive it
Only PC8 replies with its MAC address
Step 5: Verify ARP Table (After Ping)
arp -a Fig :17
Now you will see:
[Link] → MAC Address
Step 6: Simulation Mode (Important)
Switch to Simulation Mode
Filter → Select ARP
Click Capture/Forward
You will observe:
ARP Request (Broadcast to all PCs)
ARP Reply (Unicast to sender)
Output:
Enter a string to send: HELLO_JAVA!
Encoded frame: 11|HELLO_JAVA!
Decoded string: HELLO_JAVA!
Program 11:
Write a program for Implementation of Character Count Framing.
import [Link].*;
public class CharCountFraming {
// Sender side: add count
public static String charCountEncode(String data) {
int count = [Link]();
return count + "|" + data;
}
// Receiver side: extract data
public static String charCountDecode(String frame) {
int pos = [Link]('|');
int count = [Link]([Link](0, pos));
String data = [Link](pos + 1, pos + 1 + count);
return data;
}
public static void main(String[] args) {
try(Scanner sc = new Scanner([Link])){
[Link]("Enter a string to send: ");
String input = [Link]();
String encoded = charCountEncode(input);
[Link]("Encoded frame: " + encoded);
String decoded = charCountDecode(encoded);
[Link]("Decoded string: " + decoded);
}
}
}
Output:
Stuffed Frame: DLESTXABCDLEDLEFGDLEETX
Original Data: ABCDLEFG
Program 12:
Write a program for Implementation of Character (Byte) Stuffing and
Destuffing.
public class ByteStuffing {
// Sender side: stuffing
public static String stuffData(String data) {
String DLE = "DLE";
String STX = "STX";
String ETX = "ETX";
String result = DLE + STX; // start frame
for (int i = 0; i < [Link](); i++) {
// Check if substring "DLE" appears
if (i + 2 < [Link]() && [Link](i, i + 3).equals(DLE)) {
result += DLE; // extra DLE (stuffing)
}
result += [Link](i);
}
result += DLE + ETX; // end frame
return result;
}
// Receiver side: destuffing
public static String destuffData(String frame) {
String DLE = "DLE";
String data = [Link](6, [Link]() - 6);
String result = "";
for (int i = 0; i < [Link](); i++) {
if (i + 5 < [Link]() && [Link](i, i + 6).equals("DLEDLE")) {
result += DLE;
i += 5; // skip both DLEs
} else {
result += [Link](i);
}
}
return result;
}
public static void main(String[] args) {
String data = "ABCDLEFG";
String stuffed = stuffData(data);
[Link]("Stuffed Frame: " + stuffed);
String destuffed = destuffData(stuffed);
[Link]("Original Data: " + destuffed);
}
}
Output:
Original Data: 01111110111110
Stuffed Data: 0111110101111100
Destuffed Data: 01111110111110
Program 13:
Write a program for Implementation of Bit Stuffing and Destuffing.
public class BitStuffing {
public static String bitStuffing(String data) {
String result = "";
int count = 0;
for (int i = 0; i < [Link](); i++) {
char bit = [Link](i);
result += bit;
if (bit == '1') {
count++;
if (count == 5) {
result += '0'; // stuff 0
count = 0;
}
} else {
count = 0;
}
}
return result;
}
public static String bitDestuffing(String data) {
String result = "";
int count = 0;
for (int i = 0; i < [Link](); i++) {
char bit = [Link](i);
result += bit;
if (bit == '1') {
count++;
if (count == 5) {
i++; // skip stuffed 0
count = 0;
}
} else {
count = 0;
}
}
return result;
}
public static void main(String[] args) {
String data = "01111110111110";
[Link]("Original Data: " + data);
String stuffed = bitStuffing(data);
[Link]("Stuffed Data: " + stuffed);
String destuffed = bitDestuffing(stuffed);
[Link]("Destuffed Data: " + destuffed);
}
}