0% found this document useful (0 votes)
4 views34 pages

Hardware & Networking Lab (ALL PRACTICAL)

The document outlines the study of OSI and TCP/IP layers, detailing the functions and responsibilities of each layer in both models. It also discusses practical applications of searching and sorting techniques in networking, including algorithms like linear search, binary search, and sorting methods such as merge sort. Additionally, it presents a Python program simulating packet management, demonstrating the sorting and searching of network packets.

Uploaded by

manthankapse5
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)
4 views34 pages

Hardware & Networking Lab (ALL PRACTICAL)

The document outlines the study of OSI and TCP/IP layers, detailing the functions and responsibilities of each layer in both models. It also discusses practical applications of searching and sorting techniques in networking, including algorithms like linear search, binary search, and sorting methods such as merge sort. Additionally, it presents a Python program simulating packet management, demonstrating the sorting and searching of network packets.

Uploaded by

manthankapse5
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

PRACTICAL-1

AIM: Study of OSI and TCP/IP Layers with their comparison.


Solution:

➔There are two important network architectures, the OSI reference model and the

TCP/IP reference model.

❖OSI REFERENCE MODEL :

➔The OSI model is based on a proposal developed by the International Standards


Organization (ISO) as a first step toward international standardization of the protocols used in the
various [Link] model is called the ISO OSI (Open Systems Interconnection) Reference Model
because it deals with connecting open systems—that is, systems that are open for communication with
other systems and they arrive at the destination irrespective of the route they take.
OSI MODEL

The OSI model has seven layers. The principles that were applied to arrive at the seven
layers can be briefly summarized as follows:
1. A layer should be created where a different abstraction is needed.
2. Each layer should perform a well-defined function.
3. The function of each layer should be chosen with an eye toward defining internationally
standardized protocols.
4. The layer boundaries should be chosen to minimize the information flow across the
interfaces.
5. The number of layers should be large enough that distinct functions need not be thrown
together in the same layer out of necessity and small enough that the architecture does
not become unwieldy.

FIG : ISO/OSI REFERENCE MODEL

LAYER 1 : The PHYSICAL LAYER deals with transmission of individual bits from one node to another
over a physical medium.
The main functions of the physical layer are as follows:-
●It defines the physical characteristics and functions of the physical devices and interfaces so that
transmission can occur. It states the number of pins in each of the Z devices as well as the purpose of
each pin.
●It lays out the transmission medium and type of signal for transmitting the bits, i.e., electrical pulses,
optical pulses or radio signals.
LAYER 2
The DATA LINK LAYER converts the raw transmission facilit provided by the physical layer to a
reliable and error-free link.
The main functions of the data link layer are as follows
It breaks up the stream of bits into data frames having sizes from a few hundred to a few thousand bytes.
It ensures distribution of the frames to the different systems. For this, it adds a head to the frame
containing the address of the sender and the [Link] case of reliable connection, this layer ensures
that the receiver sends an retransmission is done. It also has mechanisms to identify duplicate frames.
The data link layer ensures flow control of transmission so that a fast sender does not drown a slow
receiver.
In the case of broadcast networks, this layer also controls access to the shared channel.

LAYER 3: The NETWORK LAYER controls the source to destination delivery of data packets across
multiple hops (nodes). It controls the operation of the subnet.
The main functions of the network layer are as follows
It is responsible for routing packets from the source host to the destination host. The routes can be based
upon static tables that are rarely changed, or they can be

➔LAYER 6 : The PRESENTATION LAYER ensures that the message is presented to

the upper layer in a standardized format. It deals with the syntax and the semantics of
the messages.
The main functions of the presentation layer are as follows:-
●It encodes the messages from the user dependent format to the common format and
vice versa, for communication among dissimilar systems.
●It is responsible for data encryption and decryption of sensitive data before they are
transmitted over common channels.
●It is also responsible for data compression. Data compression is done at the source to
reduce the number of bits to be transmitted. It reduces the storage space and increases
the file transfer rate. It is particularly useful for transmission of large multimedia files.
It is responsible for routing packets from the source host to the destination host. The routes can be
based upon static tables that are rarely changed, or they can be automatically updated depending upon
network conditions.
The data link layer assigns the physical address locally. When the data packets are routed to remote
locations, a logical addressing scheme is required to differentiate between the source system and the
destination system.
→ LAYER 4: The TRANSPORT LAYFR is responsible for delivery of an entire message from an
application program on the source device to a similar application program on the destination device.
The main functions of the transport layer are as follows:-
It delivers a message from a specific process of one computer to a specific process in another computer.
The transport layer adds a port address to the header of the data packet.
It divides a message into smaller segments such that each segment contains a sequence number along
with the port address. It ensures that the segments arrive correctly at the receiver's end and then
reassembles [Link] provides an error-free point-to-point channel for both connectionless and
connection-oriented services.
→ LAYER 5: The SESSION LAYER is responsible for establishing, managing, synchronizing and
terminating sessions between end-user application processes.
The main functions of the session layer are as follows:-
It works as a dialog controller. It allows the systems to communicate in either half-duplex or full-duplex
mode of communication.
It is responsible for token management. Through this, it prevents the two users to simultaneously
attempt the same critical operation.
It synchronizes communication. It adds synchronization points or checkpoints in data streams for long
communications.

➔LAYER 6 : The PRESENTATION LAYER ensures that the message is presented to

the upper layer in a standardized format. It deals with the syntax and the semantics of the messages.
The main functions of the presentation layer are as follows:-
●It encodes the messages from the user dependent format to the common format and vice versa, for
communication among dissimilar systems.
●It is responsible for data encryption and decryption of sensitive data before they are transmitted over
common channels.
●It is also responsible for data compression. Data compression is done at the source to
reduce the number of bits to be transmitted. It reduces the storage space and increases
the file transfer rate. It is particularly useful for transmission of large multimedia files.
topmost layer of the OSI model. It specifies the interfaces and supports services to the end users for
network access.

➔LAYER 7 : The APPLICATION LAYER is checkpoints are successfully received and acknowledged.
In case of any failures, only the streams after the checkpoints have to be re-transmitted.
The main functions of the application layer are as follows:-
●It provides a virtual network terminal through which a user can log on to the remote
host on the network.
●It provides facilities so that a user can access and retrieve files in a remote computer
for local usage, as well as manage and store files on a remote computer from the local
computer.
●It provides email services.
●It helps to retrieve global information and services by providing access to distributed
database resources.

❖TCP/IP REFERENCE MODEL :

➔TCP/IP means Transmission Control Protocol and Internet Protocol. It is the network

model used in the current Internet architecture as we Protocols are a set of rules which
govern every possible communication over a network. These protocols describe the
movement of data between the source and destination or the internet. They also offer
simple naming and addressing schemes.
FIG : PROTOCOLS AND NETWORKS IN THE TCP/IP MODEL INITIALLY
Network Access Layer/Host -to -Network Layer :

➔A network layer is the lowest layer of the TCP/IP model.

➔A network layer is the combination of the Physical layer and Data Link layer defined
in the OSI reference model.

➔It defines how the data should be sent physically through the network.

➔This layer is mainly responsible for the transmission of the data between two devices

on the same network.

➔The functions carried out by this layer are encapsulating the IP datagram into frames

transmitted by the network and mapping of IP addresses into physical addresses.

➔The protocols used by this layer are ethernet, token ring, FDDI, X.25, frame relay.

Transport Layer :

➔The transport layer is responsible for error-free, end-to-end delivery of data from the
source host to the destination host. It corresponds to the transport layer of the OSI model.

➔The functions of the transport layer are :

●It facilitates the communicating hosts to carry on a conversation.


●It provides an interface for the users to the underlying network.
●It can provide for a reliable connection. It can also carry out error checking, flow control, and
verification.

➔The protocols used in this layer are :-

●Transmission Control Protocol, TCP − It is a reliable connection-oriented protocol that transmits data
from the source to the destination machine without any error. A connection is established between the
peer entities prior to transmission. At the sending host, TCP divides an incoming byte stream into
segments and assigns a separate sequence number to each segment. At the receiving host, TCP reorders
the segments and sends an acknowledgment to the sender for correct receipt of segments. TCP also
manages flow control so that a fast sender does not overwhelm a slow receiver.
●User Datagram Protocol, UDP−
It is a message-oriented protocol that provides a simple unreliable, connectionless, unacknowledged
service. It is suitable for applications that do not require TCP’s sequencing, error control or flow control.
It is used for transmitting a small amount of data where the speed of delivery is more important than
the accuracy of delivery.
●Stream Control Transmission Protocol, SCTP
It combines the features of both TCP and UDP. It is message oriented like the UDP, which provides a
reliable, connection-oriented service like TCP. It is used for telephony over the Internet.

Application Layer :
1. This is the top most layer of TCP/IP model.
2. It is used for interaction between user and application.
3. There are several protocols used by the application layer for user interaction such as:
HTTP, SNMP, SMTP, DNS, TELNET, FTP etc.

➔HTTP: HTTP stands for Hypertext transfer protocol, it allows the user to interact with

world wide web through the browser application. HTTP can be used to transfer
various types of data such as plain text, audio, video etc.
➔FTP: FTP stands for File Transfer Protocol. This protocol is used for transmitting files

from one system to another system.


Comparison between OSI vs TCP/IP
Practical No.2

Aim: Apply appropriate searching and sorting techniques for a given


problem statement
Applying Searching Techniques to Networking
Searching algorithms are used for efficient data retrieval in network monitoring
tools and router tables.
1. Linear Search (Unsorted Data)
• Problem: Scan a raw log file for a specific IP address that recently
connected.
• Technique: Linear Search – Checks each IP one by one.
• Complexity:
2. Binary Search (Sorted Data)
• Problem: Find a specific network flow ID within a sorted list of thousands
of active connections.
• Technique: Binary Search – Efficiently finds items in a sorted structure by
dividing in half.
• Complexity:
3. Hashing/Map Searching
• Problem: Quickly look up a MAC address corresponding to an IP address
in an ARP table.
• Technique: Hash Map/Table – Provides near-instant lookups.

Part 3: Applying Sorting Techniques to Networking


Sorting techniques are crucial for prioritizing traffic, managing routing tables, or
analyzing logs.
1. Sort by Frequency (Heap Sort / Hash Map)
• Problem: Identify the top 10 IP addresses consuming the most bandwidth.
• Technique: Counting Sort or Heap Sort to rank IP frequencies.
Sort by IP/Time (Quick Sort/Merge Sort)
• Problem: Organize raw security log files chronologically or by destination
IP address.
• Technique: Merge Sort or Quick Sort – Effective for sorting large datasets
of log entries.
3. Priority Sorting
• Problem: Sort incoming packets to prioritize VoIP packets (high priority)
over file transfer packets (low priority).
• Technique: Insertion Sort – Efficient for nearly sorted data.
This practical lab applies TCP/IP modeling to network data, sorting captured
packets by sequence number (Merge Sort for large data) and searching for
specific IP addresses using Binary Search. The program simulates capturing
network traffic, sorting for organized processing, and searching for a specific
node, bridging network layers.
Practical Problem Statement
Objective: Simulate a packet analyzer that receives raw packets from a network
(Physical Layer) and sorts them based on sequence numbers
(Transport/Application layer) for reassembly, followed by a search for a specific
packet ID.
Approach:
1. Sorting: Use Merge Sort to order packets based on sequence numbers
(efficient for potential large-scale, unordered data).
2. Searching: Use Binary Search on the sorted packets to find a specific
packet ID efficiently (logarithmic time).
Program:
Python Program: Network Packet Management
python
# Packet Structure representing data from Network Access/Internet Layers
class Packet:
def __init__(self, seq_no, data):
self.seq_no = seq_no
[Link] = data
def __repr__(self):
return f"[Seq: {self.seq_no}, Data: {[Link]}]"

# --- SORTING TECHNIQUE: MERGE SORT ---


# Chosen because network packets might arrive out of order and in large
numbers.
def merge_sort_packets(packets):
if len(packets) > 1:
mid = len(packets) // 2
left_half = packets[:mid]
right_half = packets[mid:]

merge_sort_packets(left_half)
merge_sort_packets(right_half)

i=j=k=0
while i < len(left_half) and j < len(right_half):
if left_half[i].seq_no < right_half[j].seq_no:
packets[k] = left_half[i]
i += 1
else:
packets[k] = right_half[j]
j += 1
k += 1

while i < len(left_half):


packets[k] = left_half[i]
i += 1
k += 1

while j < len(right_half):


packets[k] = right_half[j]
j += 1
k += 1
return packets

# --- SEARCHING TECHNIQUE: BINARY SEARCH ---


# Chosen for efficiency on already sorted packet data.
def binary_search_packet(packets, target_seq):
low = 0
high = len(packets) - 1

while low <= high:


mid = (low + high) // 2
if packets[mid].seq_no == target_seq:
return packets[mid]
elif packets[mid].seq_no < target_seq:
low = mid + 1
else:
high = mid - 1
return None

# --- MAIN EXECUTION (Simulation of OSI Application Layer Handling) ---


if __name__ == "__main__":
# 1. Simulating unordered packets received at the Transport/Network Layer
received_packets = [
Packet(105, "Payload_E"),
Packet(101, "Payload_A"),
Packet(104, "Payload_D"),
Packet(102, "Payload_B"),
Packet(103, "Payload_C")
]
print("Unordered Packets (Network Access Layer):")
print(received_packets)

# 2. Applying Sorting (Merge Sort) for Reassembly


sorted_packets = merge_sort_packets(received_packets)
print("\nSorted Packets (Transport Layer - Reassembly):")
print(sorted_packets)
# 3. Searching for a specific packet
target = 104
found = binary_search_packet(sorted_packets, target)
print(f"\nSearching for Sequence Number {target}...")
if found:
print(f"Packet Found: {found}")
else:
print("Packet not found.")

OUTPUT:-
Unordered Packets (Network Access Layer):
[[Seq: 105, Data: Payload_E], [Seq: 101, Data: Payload_A], [Seq: 104, Data:
Payload_D], [Seq: 102, Data: Payload_B], [Seq: 103, Data: Payload_C]]
Sorted Packets (Transport Layer - Reassembly):
[[Seq: 101, Data: Payload_A], [Seq: 102, Data: Payload_B], [Seq: 103, Data:
Payload_C], [Seq: 104, Data: Payload_D], [Seq: 105, Data: Payload_E]]

Searching for Sequence Number 104...


Packet Found: [Seq: 104, Data: Payload_D]

** Process exited - Return Code: 0 **


^C

Conclusion: Hence we have executed successfully implement this program.


Practical No.3

Aim: Create: Design applications using linear and nonlinear data


structures to solve engineering problems.

Introduction:
data structures are primarily categorized into two types based on how the data
elements are organized and accessed: Linear and Non-Linear data structures.

1. Linear Data Structures


In a linear data structure, data elements are arranged in a sequential order, where
each element is connected to its previous and next adjacent elements. This structure
forms a single level (linear) hierarchy.
• Traversal: Can be traversed in a single run.
• Complexity: Generally easier to implement, but memory allocation can be
inefficient.
• Examples: Arrays, Linked Lists, Stacks, Queues.
Example: Stack (LIFO - Last In First Out)
A Stack is a linear data structure where elements are added and removed from the
same end (the top).
Python Program (Using a List):
stack = []

# Push elements
[Link]('A')
[Link]('B')
[Link]('C')

print("Stack after pushes:", stack)

# Pop element
removed = [Link]()
print("Popped element:", removed)
print("Stack after pop:", stack)
Output:
Stack after pushes: ['A', 'B', 'C']
Popped element: C
Stack after pop: ['A', 'B']

Applications:
✓ Undo/Redo functions in word processors.
✓ Expression Evaluation (converting infix to postfix).
✓ Function Call Management (Recursion stack).

2. Non-Linear Data Structures


In non-linear data structures, data elements are not arranged sequentially.
Elements are attached to one or more other elements, creating a hierarchical or
interconnected relationship.
• Traversal: Cannot be traversed in a single run; requires multiple passes or
recursion.
• Complexity: More complex to implement but highly efficient for
searching and representing complex relationships.
• Examples: Trees, Graphs.
Example: Binary Tree
A Tree is a hierarchical structure where a "root" node points to "child" nodes.
Python Program (Simple Tree Structure):
class Node:
def _init_(self, key):
[Link] = None
[Link] = None
[Link] = key

# Creating a simple tree


# 1
# /\
# 2 3
root = Node(1)
[Link] = Node(2)
[Link] = Node(3)

print("Root:", [Link])
print("Left Child:", [Link])
print("Right Child:", [Link])

Output:
Root: 1
Left Child: 2
Right Child: 3

Applications:
✓ Trees: Used in File Systems (folders/subfolders), Organization Charts,
and HTML DOM (Document Object Model).
✓ Graphs: Used in Social Networks (Facebook/LinkedIn connections),
Google Maps (finding shortest paths), and Recommendation Engines.

Conclusion: hence,. Successfully creating the linear and non linear data
stractures with its example.
Practical No.4

Aim: Evaluate to Choose appropriate data structures to solve given


problems (Sorted Array) efficiently.

Introduction:
Sorted Array with Binary Search
A sorted array is a data structure where elements are stored in a particular order
(ascending or descending).
Binary Search is a fast searching technique that works only on sorted arrays.
Instead of scanning every element, it repeatedly divides the array into two parts
and searches efficiently.
Working Principle:
Binary search uses the middle index:
o If key == arr[mid] → element found
o If key < arr[mid] → search in left half
o If key > arr[mid] → search in right half
Advantages:
o Faster than linear search
o Reduces search space by half each time
o Efficient for large datasets
Time Complexity:
o Best Case: O(1)
o Worst Case: O(log n)

Program:
#include <stdio.h>

int binarySearch(int arr[], int n, int key) {


int low = 0, high = n - 1, mid;

while (low <= high) {


mid = (low + high) / 2;
if (arr[mid] == key)
return mid; // element found
else if (arr[mid] < key)
low = mid + 1; // search right half
else
high = mid - 1; // search left half
}

return -1; // element not found


}

int main() {
int arr[] = {1, 3, 5, 7, 9, 11, 13}; // sorted array
int n = sizeof(arr) / sizeof(arr[0]);
int key = 7;

int result = binarySearch(arr, n, key);

if (result != -1)
printf("Element found at index: %d", result);
else
printf("Element not found");

return 0;
}

Output:
Element found at index: 3
Conclusion: Hence,. Choose the appropriate data structures to solve given
problem successfully.
Practical No.5

Aim: To study the various physical layer components and different


topologies of networking.

Physical Layer in Networking:


The Physical Layer is the first layer of the OSI Model. It is responsible for
transmitting raw bits (0s and 1s) over a communication medium.

Main Functions:
-Transmits data in the form of electrical, optical, or radio signals
-Defines hardware elements and transmission media
-Controls data rate and synchronization
-Specifies voltage levels and physical connections.

Physical Layer Components:


[Link] Media
Guided Media: Twisted pair cable, coaxial cable, fiber optic cable
Unguided Media: Radio waves, microwaves, infrared
[Link] Devices
Hub: Connects multiple devices and broadcasts data
Repeater: Amplifies weak signals
Modem: Converts digital to analog signals and vice versa
[Link] & Interfaces
RJ45 connectors, ports, cables

Network Topologies
Network topology refers to the layout or arrangement of devices in a network.
Types of Network Topologies:
1. Bus Topology
-All devices connected to a single backbone cable
-Simple and low cost
-If the main cable fails, entire network stops
2. Star Topology
-All devices connected to a central hub/switch
-Easy to manage and troubleshoot
-Failure of central device affects the whole network
3. Ring Topology
-Devices connected in a circular manner
-Data travels in one direction
-Break in the ring can stop communication
4. Mesh Topology
-Every device is connected to every other device
-Highly reliable and secure
-Expensive and complex
5. Tree Topology
-Combination of star and bus topology
-Hierarchical structure
-Easy to expand
6. Hybrid Topology
-Combination of two or more topologies
-Flexible and scalable

Conclusion: Hence,. Studied the various physical layer components and different
topologies of networking.
Practical No.6

Aim: To study OSI reference model and TCP/IP reference model with
respect to protocol suite.

INTRODUCTION:
OSI Model: It has 7 layers Physical layer, Data Link layer, Network layer,
Transport layer, Session layer, Presentation layer, and Application layer. Each
layer performs its task independently.
TCP/IP Model: It has 5 layers named as Physical layer, Data Link Layer,
Network layer, Transport layer, and Application layer. It can also be used as a
communications protocol in a private computer network.

OSI Model
The OSI (Open Systems Interconnection) Model is a 7-layer conceptual
framework used to understand and design network communication. Each layer
has a clearly defined function and works independently of the others.

1. Physical Layer
Transmits raw bits over physical media.
• Deals with cables, connectors, voltages, signals
• Converts digital data into electrical/optical signals
o Defines hardware specifications (NICs, hubs, repeaters)
o Handles data rate, modulation, and physical topology
2. Data Link Layer
Provides reliable node-to-node data transfer.
• Uses MAC addresses for device identification
• Performs error detection and correction (Frame Check Sequence)
• Breaks data into frames
• Manages access to the physical medium (Ethernet, switches)
3. Network Layer
Handles logical addressing and routing of packets.
• Uses IP addresses for routing decisions
• Determines the best path to the destination
• Manages packet forwarding and routing tables
• Supports routers and Layer 3 protocols (IP, ICMP)
4. Transport Layer
Ensures reliable or fast delivery of data.
• Uses TCP (reliable) and UDP (fast, connectionless)
• Handles segmentation and reassembly of data
• Provides flow control (sliding window)
• Ensures error recovery and end-to-end communication
5. Session Layer
Establishes, manages, and terminates sessions.
• Controls dialog between devices (duplex/half-duplex)
• Maintains session checkpoints and recovery
• Handles session authentication and reconnection
• Used in RPC, SQL sessions, NetBIOS
6. Presentation Layer
Translates, encrypts, and formats data.
• Converts data formats (encoding/decoding)
• Applies encryption and decryption (SSL/TLS)
• Handles compression for efficient transmission
• Makes data readable for the application layer
7. Application Layer
Provides services to end-user applications.
• Supports protocols like HTTP, FTP, SMTP, DNS
• Provides network services such as email, web access, file transfer
• Interacts directly with user applications
• Identifies communication partners and resource availability

TCP/IP Model
The TCP/IP (Transmission Control Protocol/Internet Protocol) Model is a 5-
layer practical networking framework used for real-world communication,
especially on the Internet. It defines how data is packaged, addressed,
transmitted, routed, and received across networks.

1. Physical Layer
Transmits raw bits over physical media.
• Deals with physical hardware: cables, signals, connectors
• Converts digital data into electrical/optical/radio signals
• Defines data transmission rate and physical topologies
• Supported devices include hubs, repeaters, and NICs
2. Data Link Layer
Provides node-to-node communication and framing.
• Uses MAC addresses for device identification
• Responsible for framing, error detection (FCS), and flow control
• Handles access to the transmission medium (Ethernet, Wi-Fi)
• Switches operate at this layer
3. Network (Internet) Layer
Handles logical addressing and packet routing.
• Uses IP addressing (IPv4/IPv6)
• Determines the best path to destination
• Performs packet routing and fragmentation
• Includes protocols: IP, ICMP, ARP, RARP
4. Transport Layer
Provides end-to-end communication and reliability.
• Uses TCP for reliable, connection-oriented communication
• Uses UDP for fast, connectionless, low-overhead delivery
• Handles segmentation, sequencing, and reassembly
• Provides error detection, correction, and flow control
5. Application Layer
Provides network services to end-user applications.
• Supports protocols like HTTP, FTP, SMTP, DNS, DHCP, SNMP
• Responsible for data formatting and communication services
• Directly interacts with user applications
• Handles resource sharing, remote file access, email, web browsing

Conclusion: Hence,. Studied OSI and TCP/IP reference model with respect to
protocol suite.
Practical No.7

Aim: Write a program for Hamming code generation for error detection
and correction.

Introduction (Hamming Code)


Hamming Code is an error detection and correction technique used in data
communication to ensure reliable transmission of data. It was developed by
Richard Hamming. This method adds extra bits, called parity bits, to the original
data bits so that errors occurring during transmission can be detected and
corrected at the receiver side. Hamming Code is capable of detecting up to two-
bit errors and correcting one-bit error, making it widely used in computer
networks and memory systems.

Key Points:
• Developed by Richard Hamming
• Uses parity bits for error detection and correction
• Detects up to 2-bit errors
• Corrects 1-bit error
• Parity bits placed at positions 1, 2, 4, 8...
• Widely used in networking and memory systems

Program:
#include <stdio.h>
#include <math.h>

// Function to calculate redundant bits


int calculateParityBits(int m) {
int r = 0;
while (pow(2, r) < (m + r + 1)) {
r++;
}
return r;
}
int main() {
int data[20], hamming[30];
int m, r, i, j, k = 1;

printf("Enter number of data bits: ");


scanf("%d", &m);

printf("Enter data bits (one by one):\n");


for (i = 1; i <= m; i++) {
scanf("%d", &data[i]);
}

r = calculateParityBits(m);

int total = m + r;

// Place data and parity bits


j = 1;
for (i = 1; i <= total; i++) {
if (i == pow(2, k - 1)) {
hamming[i] = 0; // parity bit placeholder
k++;
} else {
hamming[i] = data[j];
j++;
}
}

// Calculate parity bits


for (i = 0; i < r; i++) {
int pos = pow(2, i);
int parity = 0;

for (j = pos; j <= total; j++) {


if (j & pos) {
parity ^= hamming[j];
}
}
hamming[pos] = parity;
}

printf("\nGenerated Hamming Code:\n");


for (i = 1; i <= total; i++) {
printf("%d ", hamming[i]);
}

// Error detection
int received[30];
printf("\n\nEnter received code:\n");
for (i = 1; i <= total; i++) {
scanf("%d", &received[i]);
}

int errorPos = 0;

for (i = 0; i < r; i++) {


int pos = pow(2, i);
int parity = 0;

for (j = pos; j <= total; j++) {


if (j & pos) {
parity ^= received[j];
}
}

if (parity != 0) {
errorPos += pos;
}
}

if (errorPos == 0) {
printf("\nNo error detected.\n");
} else {
printf("\nError detected at position: %d\n", errorPos);
received[errorPos] ^= 1; // correct the error

printf("Corrected Code:\n");
for (i = 1; i <= total; i++) {
printf("%d ", received[i]);
}
}

return 0;
}

Output:
Enter number of data bits: 4
Enter data bits:
1011

Generated Hamming Code:


1010011
Enter received code:
1010111

Error detected at position: 5


Corrected Code:
1010011

Conclusion: Hence,. Successfully execute the program for hamming code


generation.
Practical No.8

Aim: Write a program for error detecting code using CRC CCIT (16 bits).

Introduction (CRC–CCITT)
Cyclic Redundancy Check (CRC) is a popular error detection technique used in
data communication to detect accidental changes in transmitted data. CRC works by
treating data as a binary polynomial and dividing it by a fixed generator
polynomial. The remainder obtained is appended to the data before transmission.
One common standard is CRC-CCITT (16-bit), which uses the polynomial 0x1021
(x¹⁶ + x¹² + x⁵ + 1). It is widely used in protocols like X.25 and HDLC.

Key Points:
▪ CRC stands for Cyclic Redundancy Check
▪ CRC-CCITT uses 16-bit polynomial (0x1021)
▪ Detects burst errors efficiently
▪ Used in protocols like HDLC
▪ More reliable than parity and checksum methods

Program:
#include <stdio.h>
#include <string.h>

#define POLY 0x1021 // CRC-CCITT polynomial

unsigned short crc_ccitt(char *data) {


unsigned short crc = 0xFFFF; // initial value

while (*data) {
crc ^= (*data << 8);
for (int i = 0; i < 8; i++) {
if (crc & 0x8000)
crc = (crc << 1) ^ POLY;
else
crc <<= 1;
}
data++;
}
return crc;
}

int main() {
char data[100];

printf("Enter data string: ");


scanf("%s", data);

unsigned short crc = crc_ccitt(data);

printf("CRC-CCITT (16-bit) value: %X\n", crc);

// Simulate receiver check


unsigned short verify = crc_ccitt(data);

if (verify == crc)
printf("No error detected.\n");
else
printf("Error detected in data.\n");

return 0;
}

Output:
Enter data string: HELLO
CRC-CCITT (16-bit) value: 34D2
No error detected.

Conclusion: Hence,. Successfully implemented the program for error detection


code
Practical No.9

Aim: To study Network IP, network command and network configuration


commands.

Introduction:
To study network IP and configuration commands, use tools like ipconfig
(Windows) or ifconfig/ip (Linux) to display IP addresses, subnet masks, and
default gateways. Essential commands include ping for connectivity,
tracert/traceroute to trace paths, and netstat for active connections. These
utilities diagnose, configure, and monitor network health, crucial for
troubleshooting TCP/IP networks.

Core Network Commands & Analysis


• ipconfig (Windows) / ifconfig (Linux): Displays active TCP/IP network
configuration, including IP address, subnet mask, and default gateway.
• ipconfig /all: Provides detailed configuration information, including
physical address (MAC), DHCP server, and DNS settings.
• ping [IP/Domain]: Tests connectivity between your device and a target
host by sending ICMP Echo Request packets.
• tracert / traceroute: Traces the path packets take to a destination,
identifying latency and intermediate hops.
• netstat: Displays active TCP/IP connections, statistics, and routing tables,
useful for identifying network traffic issues.
• nslookup: Queries DNS servers to find IP addresses or map domains.
• arp -a: Displays the Address Resolution Protocol (ARP) table, showing
mappings of IP addresses to physical MAC addresses.

Network Configuration Commands


• ipconfig /release & ipconfig /renew: Releases current DHCP IP address
and requests a new one, troubleshooting connectivity issues.
• ipconfig /flushdns: Clears the DNS resolver cache to resolve domain
resolution issues.
• route: Used to view or modify the local IP routing table.
• hostname: Displays the name of the host computer.

Practical Application & Troubleshooting


• Check IP: Open Command Prompt/Terminal and type ipconfig
(Windows) or ifconfig (Linux) to view network settings.
• Test Connectivity: Type ping [Link] to test internet connectivity, or
ping your default gateway to check local connection.
• Find Path: Use tracert [Link] to identify where a network connection
fails.
• View Connections: Run netstat -an to see all active ports and connections.

Conclusion: Hence,. Studied the network IP, command and command


configuration.
Practical No.10

Aim: To study Packet Tracer & to perform.

Introduction:
Cisco Packet Tracer is a free, powerful network simulation tool used to design,
configure, and troubleshoot networks. To study, download it via the Cisco
Networking Academy. Perform labs by dragging devices (routers, switches,
PCs) onto the workspace, connecting them, and using Simulation Mode to
visualize packet flow.

Steps to Study and Perform in Packet Tracer


[Link] & Install:
Create a free account at NetAcad to download the software for Windows, Linux,
or macOS.
[Link] the Interface:
• Logical Workspace: Where you build network topology.
• Physical Workspace: Provides a 3D view of cities, buildings, and wiring
closets.
• Device Box: Bottom-left corner, contains routers, switches, end devices
(PCs, laptops), and cables.

[Link] a Simple Lab (Perform):


• Add a switch and two PCs.
• Use the Connections (lightning bolt icon) to select a copper straight-
through cable and connect PCs to the switch.
• Configure IP Addresses: Click on each PC, go to the "Desktop" tab, and
select "IP Configuration".
• Verify Connectivity: Open the Command Prompt on a PC and type ping
<IP_of_other_PC>.
[Link] Simulation Mode:
Toggle from "Realtime" to "Simulation" mode in the bottom-right to watch
packets (PDUs) move step-by-step between devices.
[Link] CLI:
Click on routers or switches to access the Command Line Interface (CLI) to
configure devices using Cisco IOS commands.
Key Concepts to Practice
• VLANs and Trunking: Segmenting networks.
• Routing Protocols: Configuring RIP, OSPF, or Static Routes.
• DHCP/DNS: Setting up automatic IP assignment and name resolution.
• IoT & Python: Integrating Smart Home devices and scripting.

Conclusion: Hence,. Studied the packet tracer and to be performing with there
steps.

You might also like