Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Assignment 2 - Computer Networks

Atanu Nayak (A3 - 002110501081)

Flow of Program :
There are three distinct directories, each dedicated to a specific aspect of the
problem: Go-Back-N, Stop-and-Wait, and Selective-Repeat. Within each directory, we
create three Python files: server.py, client.py, and inject_error.py. In this setup, the
server.py file is responsible for reading binary data from a file and performing various
operations to calculate the checksum and CRC. Following this, we execute the
inject_error.py file, which introduces errors into the sender's data, affecting both the
message and the checksum or CRC. The potentially corrupted data is then
transmitted to the client, where the client.py file attempts to identify the presence of
errors. Importantly, each of these methods employs distinct retransmission
strategies.

Input and Output format :


File has the content in binary string format, and the output is in boolean format, later
on we process and we then return the text for better understanding.

Functions in each file :


Explaining Functions :
● server.py
1. calculate_checksum : Basically this function divides the message into
size 16 codewords, and then complements the added together value -
just the basic way of finding the checksum. Now it adds that checksum
value with the original message, and returns that value.
2. All calculate_crc functions : We are already given the respective CRC
polynomials and we find the CRC for each of the messages. And return
the clubbed together message and CRC.
3. run_injectError : This function runs the function from injectError.py file,
which inserts error inside the sender’s message.

● client.py
1. Receiving the modified binary string from the server.
2. Verifying the correctness of the received data using the checksum
method.
3. Dividing the binary string into several 16-bit substrings using the
divide_into_substrings method.
4. Adding CRC to the data using the calculate_CRC method. Checking the
final data for any errors using CRC.

● injectError.py
1. The inject_error.py module contains a function that randomly injects
errors into the binary data. This random error injection simulates
real-world network scenarios where data corruption may occur during
transmission.
2. First, we evaluate the permissible error count. Afterward, we iterate to
identify that specific number of indexes, randomly setting them to
either 0 or 1. This approach allows us to simulate various types of errors,
including: no errors, single errors, multiple errors, and burst errors.
3. We get no error in two different scenarios here, either we get the
number of permissible errors to be zero or the places where we were
supposed to have the errors we are having the values already that we
get after changing.

1. Stop and Wait ARQ – The sender sends the packet and waits for the
acknowledgement of the packet. Once the acknowledgement reaches the sender, it
transmits the next packet in a row. If the acknowledgement does not reach the
sender before the specified time, known as the timeout, the sender sends the same
packet again.

Stop-and-Wait ARQ working:


1. Sender A initiates the process by sending a data frame or packet labeled with
sequence number 0.
2. Upon receiving the data frame, Receiver B responds with an
acknowledgement that carries sequence number 1. This sequence number
signifies the next expected data frame or packet.

In this protocol, both the sender and receiver maintain a buffer capable of holding
just a single frame or packet at any given time.
2. Go Back N ARQ – The sender sends N packets which are equal to the window size.
Once the entire window is sent, the sender then waits for a cumulative
acknowledgement to send more packets. On the receiver end, it receives only
in-order packets and discards out-of-order packets. As in case of packet loss, the
entire window would be re-transmitted.

Go-Back-N ARQ working :


Go-Back-N ARQ allows the sender to transmit multiple frames without waiting for
individual acknowledgments. It relies on sequence numbers to keep track of which
frames have been successfully received. In the event of a timeout or error, it
retransmits a window of frames, including those that have already been
acknowledged but may have been lost or corrupted, ensuring reliable data
transmission.

3. Selective Repeat ARQ– The sender sends packets of window size N and the receiver
acknowledges all packets whether they were received in order or not. In this case,
the receiver maintains a buffer to contain out-of-order packets and sorts them. The
sender selectively re-transmits the lost packet and moves the window forward.
Selective Repeat ARQ, implemented across server.py, client.py, and injectError.py,
facilitates reliable data transmission. Server.py handles checksum and CRC
calculations, while client.py receives, verifies, and processes data. InjectError.py
simulates error scenarios. This system ensures data integrity through checksums and
CRC, along with error simulation for testing purposes.

You might also like