Shanshak CN
Shanshak CN
AIM
THEORY
1. Bit Stuffing
Sender Side:
Before transmitting the data, the sender scans the bit stream for predefined patterns (e.g., 0111110)
that could be misinterpreted as control characters. To avoid this, the sender inserts an extra bit—
usually a 0—after every five consecutive 1 bits. This insertion disrupts the pattern, preventing any
misinterpretation.
Receiver Side:
The receiver, while reading the incoming bit stream, monitors it for these stuffed bits. Whenever five
consecutive 1s are followed by a 0, it identifies the 0 as a stuffed bit and removes it. This process
restores the original data stream, which is then processed normally.
Sender Side:
The sender inspects the byte stream for any occurrence of
control characters or delimiters. If such a byte is found, an
additional byte known as an escape character is inserted
before it. This escape character signals that the next byte
should be interpreted as data, not as a control character.
Receiver Side:
While reading the byte stream, the receiver looks for escape characters. Upon encountering one, it
understands that the following byte is actual data—even if it resembles a control character—and
processes it accordingly. The escape character itself is removed during this process.
CODE
#include <bits/stdc++.h>
cout << "Input string data: \t" << data << endl;
flag += "1";
flag += "0";
string stuffedData;
int consecutiveOnes = 0;
stuffedData += bit;
if (bit == '1') {
consecutiveOnes++;
if (consecutiveOnes == threshold) {
stuffedData += '0';
consecutiveOnes = 0;
} else {
consecutiveOnes = 0;
return stuffedData;
cout << "Input string data: \t" << data << endl;
string stuffedData;
stuffedData += escape;
stuffedData += character;
return stuffedData;
}
RESULT
Input:
Output:
• Framed data according to the selected technique (e.g., bit stuffed, byte stuffed, or character
stuffed).
EXPERIMENT 2
AIM
THEORY
Cyclic Redundancy Check (CRC) is a method used for detecting errors in data transmission. It
involves appending a check code generated by a special algorithm to the data being sent. At
the receiver's end, the same algorithm is applied to verify the integrity of the received data.
CRC works by detecting changes in bits due to transmission faults, ensuring data accuracy. It
is widely used in digital networks and storage devices to enhance data reliability.
CODE
#include <bits/stdc++.h>
while (num) {
num >>= 1;
return bin;
lli num = 0;
if (bin[i] == '1')
return num;
}
int n = generator.length();
dividend = (dividend & ((1LL << shft) - 1)) | (rem << shft);
int n = generator.length();
dividend = (dividend & ((1LL << shft) - 1)) | (rem << shft);
cout << "Transmitted Codeword : " << toBin(codeword) << endl << endl;
}
CRCSender(dataword, generator);
CRCCheck(codeword, generator);
CRCCheck(codeword, generator);
int main() {
CRC(dataword, generator);
return 0;
}
RESULT
Input:
• Verification Result:
o If error detected: Display "Invalid" along with the original codeword and the
corrupted codeword.
EXPERIMENT 3
AIM
THEORY
Stop-and-Wait Automatic Repeat reQuest (ARQ) protocol
is a type of error-control protocol used in data
transmission over unreliable communication channels,
typically in computer networks. It ensures reliable
delivery of data by employing a simple mechanism of
sending a frame and waiting for an acknowledgment
(ACK) from the receiver before sending the next frame.
3. ACK Lost: Sender sends frame, receiver receives but ACK is lost, sender retransmits due to
timeout.
4. Late ACK: Sender sends frame, receiver acknowledges late, sender retransmits assuming
frame loss.
CODE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int i, j, packet[30];
int fsize = 5;
while (j == 0 || rand() % 2 == 0) {
sleep(1);
printf("\t1 ");
sleep(1);
sleep(1);
if (j == 4)
else
break;
if (j == 0) {
sleep(1);
printf("\t0 ");
RESULT
Handle three cases: when the frame and acknowledgement are delivered successfully, when the
frame is lost, and when the acknowledgement is lost. Show the role of the timeout timer in the
protocol.
Input:
Output:
• Timeout message
EXPERIMENT 4
AIM
Study and implement Go Back N ARQ.
THEORY
Go Back N Automatic Repeat Request (ARQ) is a sliding window protocol used in the data
link layer for flow control purposes. It allows for the transmission of multiple frames from
the sender to the receiver before receiving acknowledgments, enabling efficient pipelining
of data. Its components are:
• Sender Window: Maintains a fixed-sized window (N) for consecutive frame transmission.
• Receiver Window: Accepts one frame at a time.
• Operation: Frames sent without waiting for acknowledgments; sender slides window upon
acknowledgment reception.
• Retransmission: If acknowledgment not received or frames arrive out of order, sender
retransmits from corrupted frame.
• Pipelining: Allows transmission before acknowledgment reception, enhancing efficiency.
CODE
#include<bits/stdc++.h>
#include<ctime>
#define ll long long int
using namespace std;
cout << "Acknowledgment for Frame " << k << "..." << endl;
z++;
} else {
cout << "Timeout!! Frame Number : " << k << " Not Received" << endl;
int main() {
ll tf, N, tt = 0;
srand(time(NULL));
cout << "Enter the Total number of frames: ";
• Window size.
• Timeout period for the timer.
Output:
• Success message for successful transmission.
5. Timer: Set by the sender for each transmitted frame to detect timeouts and trigger
retransmissions.
6. Sequence Numbers: Assigned to each frame to enable identification of lost frames
and facilitate sorting at the receiver's end.
7. Buffer: Used by the receiver to store received frames for sorting and eventual
processing.
CODE
#include<iostream>
int receiver(int);
int simulate(int);
int negack(int);
int main() {
rand();
morePacket = noofPacket;
tmp1 = simulate(windowsize);
windowsize -= tmp1;
tmp4 += tmp1;
tmp4 = noofPacket;
tmp2 = receiver(tmp1);
tmp3 += tmp2;
tmp3 = noofPacket;
tmp2 = negack(tmp1);
tmp5 += tmp2;
if (tmp5 != 0) {
cout << "\nNo acknowledgement for the frame " << tmp5;
morePacket -= tmp1;
if (windowsize <= 0)
windowsize = 4;
cout << "\n Selective Repeat Protocol Ends. All packets are successfully transmitted.";
}
int receiver(int tmp1) {
int i;
rand();
i = rand() % tmp1;
return i;
int i;
rand();
i = rand() % tmp1;
return i;
int tmp1, i;
tmp1 = rand();
if (tmp1 == 0)
tmp1 = simulate(windowsize);
i = tmp1 % windowsize;
if (i == 0)
return windowsize;
else
}
RESULT
Input:
• Data frames to be transmitted.
• Window size.
• Timeout period for the timer.
Output:
• Success message for successful
transmission.
• Resend the message if the frame is lost.
• Timeout message if acknowledgement is
lost.