๐ŸŒ
B.TECH III YEAR โ€ข I SEMESTER โ€ข R22

Computer Networks - Lab Manual

Computer Networks Laboratory โ€ข Program Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ III Year ๐Ÿ“š I Semester ๐ŸŒ Computer Networks ๐Ÿงช Lab Program
Selected Program

Develop a simple data link layer that performs the flow control using the sliding window protocol, and loss recovery using the Go-Back-N mechanism.

โ† All Computer Networks Programs

Flow control using the Sliding Window Protocol:


Source Code:

File Name: gobackN.c

#include<stdio.h>

int main() {
    int windowSize, totalFrames, i;
    int frames[50];

    // Prompt the user for the sliding window size
    printf("Enter window size: ");
    scanf("%d", &windowSize);

    // Prompt the user for the number of frames to transmit
    printf("\nEnter number of frames to transmit: ");
    scanf("%d", &totalFrames);

    // Prompt the user to enter all the frames
    printf("\nEnter %d frames: ", totalFrames);
    for(i = 1; i <= totalFrames; i++) {
        scanf("%d", &frames[i]);
    }

    // Display the transmission process
    printf("\nSliding Window Protocol Simulation (Assuming No Frame Loss/Corruption)\n");
    printf("Sender sends %d frames at a time and waits for acknowledgement.\n\n", windowSize);

    for(i = 1; i <= totalFrames; i++) {
        // Send frame
        printf("%d ", frames[i]);

        // Check if the window is full
        if(i % windowSize == 0) {
            printf("\nAcknowledgement of above frames is received by sender\n\n");
        }
    }

    // If remaining frames are less than window size
    if(totalFrames % windowSize != 0) {
        printf("\nAcknowledgement of above frames is received by sender\n");
    }

    return 0;
}


Output:


$ gcc gobackN.c
$ ./a.out
Enter window size: 3

Enter number of frames to transmit: 7

Enter 7 frames: 10 20 30 40 50 60 70

Sliding Window Protocol Simulation (Assuming No Frame Loss/Corruption)
Sender sends 3 frames at a time and waits for acknowledgement.

10 20 30
Acknowledgement of above frames is received by sender

40 50 60
Acknowledgement of above frames is received by sender

70
Acknowledgement of above frames is received by sender



๐Ÿ’ป Run This C Program

Develop a simple data link layer that performs the flow control using the sliding window protocol, and loss recovery using the Go-Back-N mechanism.
The selected C program is loaded automatically into the editor. Edit the program, provide input through STDIN if required and click Run.

The compiler is embedded using OneCompiler. Your C program runs inside the embedded C environment; Study Glance does not execute C code directly on your web server. Enter the input values of the program in the STDIN box before clicking Run.
โ† Back to Computer Networks Lab Programs ๐Ÿ“š All Lab Manuals