Algorithms
Algorithms
1. Take the input message (in binary) and copy it to an output message
buffer.
2. If the CRC mode is enabled, append zeroes to the output message buffer
such that its length is equal to the length of the generator polynomial.
3. Perform XOR operation between the output message buffer and the
generator polynomial.
4. Iterate over each bit of the input message and perform the following
steps:
If the current bit of the output message buffer is 1, perform another XOR
operation between the output message buffer and the generator
polynomial shifted left by the number of bits already processed.
If the current bit of the output message buffer is 0, simply skip to the
next bit.
5. Check for errors by looking for any 1's in the output message buffer. If
there are any, return 0 to indicate that an error occurred during
transmission.
6. If there are no errors, return 1 to indicate successful transmission.
Experiment 2: Bit Stuffing and Destuffing
1. Take the input data (in binary) and count the number of consecutive 1's.
2. Append the current bit to the output buffer and increment the output
buffer index.
3. If the count of consecutive 1's reaches 5 and the next bit is also 1,
append a 0 to the output buffer to stuff the bit and reset the count of
consecutive 1's to 0.
4. Repeat steps 2-3 for all bits in the input data.
5. Prepend and append the stuffed data with a special flag sequence of
"01111110" to indicate the start and end of the data frame.
6. To destuff the data, scan through the stuffed data and remove any "0"
that immediately follows 5 consecutive 1's.
7. Return the destuffed data.
Experiment 3: Sliding Window Go Back N :
1. Set winsize to 8 and initialize temp1, temp2, temp3, temp4, and i to 0.
2. Generate a random integer value for noframes.
3. While moreframes is greater than or equal to 0, do the following: a.
Simulate the sliding window protocol by calling the simulate function
with winsize as the argument. Set the value returned by simulate to
temp1. b. Update temp4 by adding the value of temp1. c. For each
frame from temp3 + 1 to temp4, print "Sending frame X", where X is the
frame number. d. Call the receiver function with temp1 as the argument.
Set the value returned by receiver to temp2. e. Update temp3 by adding
the value of temp2. f. Print "Acknowledgement for the frames up to X",
where X is the value of temp3. g. Subtract temp2 from moreframes. h.
Set temp4 to temp3. i. If winsize is less than or equal to 0, set winsize to
8.
4. Print "End of sliding window protocol" and exit the program.
The simulate function:
1. Generate a random integer value for temp1.
2. If temp1 is equal to 0, repeat step 1 until temp1 is not equal to 0.
3. Return temp1 modulo winsize.
The receiver function:
1. Generate a random integer value for i.
2. Return 1.
Experiment 4: Selective Repeat Algorithm
1. Prompt the user to enter the number of packets to be sent.
2. Initialize an array of frames, where each frame contains a data field and
an acknowledgment field (initialized to 'y').
3. Send the packets to the receiver.
4. Randomly select a packet to simulate a lost packet, and mark its
acknowledgment field as 'n'.
5. Check each frame's acknowledgment field, and for any frames with an
'n' acknowledgment, resend the packet and wait for acknowledgment.
6. When an acknowledgment for a packet is received, mark its
acknowledgment field as 'y'.
7. Repeat steps 5-6 until all packets have been acknowledged.
8. Print a message indicating that all packets have been sent successfully.
Experiment 5: Distance Vector Routing algorithm using the Bellman-Ford
algorithm.
1. User inputs the number of nodes in the network, and the cost of each
route between nodes.
2. The algorithm initializes the "via" array to indicate that each node is
reached directly from itself.
3. For each pair of nodes that are directly connected, the algorithm
initializes the distance array to 1 to indicate a direct connection.
4. The Bellman-Ford algorithm is applied to find the shortest path between
each pair of nodes. For each node pair (i,j), the algorithm checks
whether going through a third node (k) results in a shorter path than the
current best path. If it does, then the path through k is updated as the
best path.
5. The algorithm outputs the cost of each route and the intermediate
nodes (via which the route passes) to reach each node in the network.