Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

IU2041050070

Practical-4

AIM: To compare OSI and TCP/IP protocol Model.

Comparison of OSI and TCP/IP Models:


1. OSI Model:
 Layers: The OSI model consists of seven layers: Physical, Data Link,
Network, Transport, Session, Presentation, and Application.
 Standardization: Developed by the International Organization for
Standardization (ISO).
 Modular Approach: Each layer has a specific function, and changes to
one layer do not necessarily affect the other layers.
 Theoretical: The OSI model is more of a theoretical framework and is not
directly implemented in networking protocols.
2. TCP/IP Model:
 Layers: The TCP/IP model has four layers: Network Interface, Internet,
Transport, and Application.
 Real-World Implementation: The TCP/IP model closely reflects the
actual operation of the Internet and is used as the basis for the Internet
protocol suite.
 Interoperability: TCP/IP protocols are widely used and have high
interoperability.
 Simpler: TCP/IP is often considered simpler and more practical for real-
world implementation.

|Page
IU2041050070

Practical-5

AIM: To demonstrate Networking and Internetworking devices (NIC,


Switch, Hub, Router, Gateway, Repeater, Bridges, Cables)

Networking and Internetworking Devices:


1. NIC (Network Interface Card): Hardware component that allows a
computer to connect to a network. It provides the physical interface
between the computer and the network medium.
2. Switch: A data-link layer device that connects multiple devices in a local
area network (LAN) and forwards data only to the specific device it is
intended for, reducing network congestion.
3. Hub: A basic networking device that connects multiple devices in a
LAN, but unlike a switch, it sends data to all devices connected to it,
leading to more network congestion.
4. Router: A network layer device that connects different networks and
forwards data packets between them. Routers make decisions based on IP
addresses.
5. Gateway: A device that connects two different networks using different
protocols, facilitating communication between them. It operates at
different layers depending on the protocols being used.
6. Repeater: A device used to extend the range of a network by
regenerating and retransmitting signals. It operates at the physical layer.
7. Bridges: A device that connects two LANs and filters traffic between
them based on MAC addresses. It operates at the data-link layer.
Cables:
1. Coaxial Cable: Used for cable television and broadband internet
connections.
2. Twisted Pair Cable: Commonly used for Ethernet connections. Comes
in two types: unshielded (UTP) and shielded (STP).
3. Fiber Optic Cable: Transmits data using light signals, offering high data
rates and immunity to electromagnetic interference.
These devices play crucial roles in establishing and maintaining network
connections, facilitating data communication, and managing traffic within
networks.

|Page
IU2041050070

Practical-6

AIM: Write a program which demonstrates the concept of bit stuffing.

Bit Stuffing:
#include <stdio.h>
#include <string.h>

void bit_stuffing(char *input, char *output) {


int count = 0;
int len = strlen(input);

for (int i = 0, j = 0; i < len; i++) {


output[j++] = input[i];

if (input[i] == '1') {
count++;
if (count == 5) {
output[j++] = '0';
count = 0;
}
} else {
count = 0;
}
}
output[strlen(input) + count] = '\0';
}
|Page
IU2041050070

int main() {
char input[] = "0111110101101111101";
char output[100];

bit_stuffing(input, output);

printf("Original Data: %s\n", input);


printf("Stuffed Data: %s\n", output);

return 0;
}

|Page
IU2041050070

Practical-7

AIM: Write a program which demonstrates the concept of byte stuffing.

Byte Stuffing:

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

void byte_stuffing(char *input, char *output, char byte) {


int len = strlen(input);
int j = 0;

for (int i = 0; i < len; i++) {


if (input[i] == byte) {
output[j++] = byte;
output[j++] = byte;
} else {
output[j++] = input[i];
}
}
output[j] = '\0';
}

int main() {
char input[] = "\x7E\xA0\xA1\x7E";
char output[100];

|Page
IU2041050070

char byte = '\x7E'; // Byte for byte stuffing

byte_stuffing(input, output, byte);

printf("Original Data: %s\n", input);


printf("Stuffed Data: %s\n", output);

return 0;
}

|Page
IU2041050070

Practical-8

AIM: Write a program to demonstrate the concept of PARITY


CHECKING.

Parity Checking:

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

int calculate_parity(char *data, int length) {


int parity = 0;

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


if (data[i] == '1') {
parity ^= 1;
}
}

return parity;
}

int main() {
char data[] = "1101010";
int received_parity = 1; // Replace with the received parity bit
int calculated_parity = calculate_parity(data, strlen(data));

if (received_parity == calculated_parity) {

|Page
IU2041050070

printf("Data: %s\n", data);


printf("Received Parity: %d\n", received_parity);
printf("Calculated Parity: %d\n", calculated_parity);
printf("Parity Check: Passed\n");
} else {
printf("Parity Check: Failed\n");
}

return 0;
}

Practical-9

|Page
IU2041050070

AIM: Write a program to demonstrate the concept of error detection


methods using LRC and VRC.

Error Detection Methods using LRC and VRC:


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

int calculate_lrc(char *data, int length) {


int lrc = 0;

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


lrc ^= data[i];
}

return lrc;
}

int verify_lrc(char *data, int length, int received_lrc) {


int calculated_lrc = calculate_lrc(data, length);
return received_lrc == calculated_lrc;
}

int calculate_vrc(char *data, int length) {


int vrc[8] = {0};

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

|Page
IU2041050070

for (int j = 0; j < 8; j++) {


vrc[j] ^= (data[i] >> j) & 1;
}
}

return vrc;
}

int verify_vrc(char *data, int length, int *received_vrc) {


int calculated_vrc[8];
int *calculated_vrc_ptr = calculate_vrc(data, length);

for (int i = 0; i < 8; i++) {


calculated_vrc[i] = *(calculated_vrc_ptr + i);
}

int is_correct = 1;
for (int i = 0; i < 8; i++) {
if (received_vrc[i] != calculated_vrc[i]) {
is_correct = 0;
break;
}
}

return is_correct;
}

|Page
IU2041050070

int main() {
char data[] = {0b10101010, 0b11001100, 0b11110000};
int received_lrc = 0b01010101;
int received_vrc[] = {0, 1, 0, 1, 0, 1, 0, 1};

int is_lrc_correct = verify_lrc(data, sizeof(data), received_lrc);


int is_vrc_correct = verify_vrc(data, sizeof(data), received_vrc);

printf("Data: ");
for (int i = 0; i < sizeof(data); i++) {
printf("%02X ", data[i]);
}
printf("\nReceived LRC: %02X\n", received_lrc);
printf("Is LRC Correct: %s\n", is_lrc_correct ? "Yes" : "No");
printf("Received VRC: ");
for (int i = 0; i < 8; i++) {
printf("%d ", received_vrc[i]);
}
printf("\nIs VRC Correct: %s\n", is_vrc_correct ? "Yes" : "No");

return 0;
}

|Page
IU2041050070

Practical-10

AIM: Write a program to demonstrate the concept of Error Detection


Method CRC

Error Detection Method using CRC:

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

void crc_remainder(int *data, int data_len, int *divisor, int divisor_len, int
*remainder) {
int crc[data_len + divisor_len - 1];

for (int i = 0; i < data_len; i++) {


crc[i] = data[i];
}

for (int i = 0; i < data_len - divisor_len + 1; i++) {


if (crc[i] == 1) {
for (int j = 0; j < divisor_len; j++) {
crc[i + j] ^= divisor[j];
}
}
}

for (int i = data_len; i < data_len + divisor_len - 1; i++) {


remainder[i - data_len] = crc[i];

|Page
IU2041050070

}
}

int verify_crc(int *data_with_crc, int data_with_crc_len, int *divisor, int


divisor_len) {
int remainder[divisor_len - 1];
crc_remainder(data_with_crc, data_with_crc_len - divisor_len + 1, divisor,
divisor_len, remainder);

for (int i = 0; i < divisor_len - 1; i++) {


if (remainder[i] != 0) {
return 0;
}
}

return 1;
}

int main() {
int data[] = {1, 0, 1, 0, 1, 1, 0};
int divisor[] = {1, 0, 0, 1}; // CRC-4 divisor
int data_with_crc[11];
int divisor_len = sizeof(divisor) / sizeof(divisor[0]);
int data_len = sizeof(data) / sizeof(data[0]);

for (int i = 0; i < data_len; i++) {


data_with_crc[i] = data[i];

|Page
IU2041050070

crc_remainder(data_with_crc, data_len, divisor, divisor_len, data_with_crc +


data_len);

int is_crc_correct = verify_crc(data_with_crc, data_len + divisor_len - 1,


divisor, divisor_len);

printf("Data: ");
for (int i = 0; i < data_len; i++) {
printf("%d ", data[i]);
}
printf("\nGenerated CRC: ");
for (int i = data_len; i < data_len + divisor_len - 1; i++) {
printf("%d ", data_with_crc[i]);
}
printf("\nIs CRC Correct: %s\n", is_crc_correct ? "Yes" : "No");

return 0;
}

|Page

You might also like