Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
307 views3 pages

CNS Practical

Uploaded by

Rishu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
307 views3 pages

CNS Practical

Uploaded by

Rishu Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NAME: RISHU SINGH

CLASS: TE/C
ROLL NO: T213050
PRACTICAL NO: 08

Write a program to simulate Go back N and Selective Repeat Modes of Sliding


Window Protocol in Peer-to-Peer mode
------------------------------------------------------------------------------------------------
PROGRAM:

#include<bits/stdc++.h>

#include<ctime>

#define ll long long int


using namespace std;

void transmission(ll & i, ll & N, ll & tf, ll & tt) {


while (i <= tf) {
int z = 0;
for (int k = i; k < i + N && k <= tf; k++) {
cout << "Sending Frame " << k << "..." << endl;
tt++;
}
for (int k = i; k < i + N && k <= tf; k++) {
int f = rand() % 2;
if (!f) {
cout << "Acknowledgment for Frame " << k << "..." << endl;
z++;
} else {
cout << "Timeout!! Frame Number : " << k << " Not Received" << endl;
cout << "Retransmitting Window..." << endl;
break;
}
}
cout << "\n";
i = i + z;
}
}

int main() {
ll tf, N, tt = 0;
srand(time(NULL));
cout << "Enter the Total number of frames : ";
cin >> tf;
cout << "Enter the Window Size : ";
cin >> N;
ll i = 1;
transmission(i, N, tf, tt);
cout << "Total number of frames which were sent and resent are : " << tt <<
endl;
return 0;
}
OUTPUT:

Enter the Total number of frames : 12

Enter the Window Size : 4

Sending Frame 1...

Sending Frame 2...

Sending Frame 3...

Sending Frame 4...

Acknowledgment for Frame 1...

Acknowledgment for Frame 2...

Acknowledgment for Frame 3...

Acknowledgment for Frame 4...

Sending Frame 5...

Sending Frame 6...

Sending Frame 7...

Sending Frame 8...

Timeout!! Frame Number : 5 Not Received

Retransmitting Window...

Sending Frame 5...

Sending Frame 6...

Sending Frame 7...

Sending Frame 8...

Acknowledgment for Frame 5...

Acknowledgment for Frame 6...


Acknowledgment for Frame 7...

Acknowledgment for Frame 8...

Sending Frame 9...

Sending Frame 10...

Sending Frame 11...

Sending Frame 12...

Acknowledgment for Frame 9...

Timeout!! Frame Number : 10 Not Received

Retransmitting Window...

Sending Frame 10...

Sending Frame 11...

Sending Frame 12...

Timeout!! Frame Number : 10 Not Received

Retransmitting Window...

Sending Frame 10...

Sending Frame 11...

Sending Frame 12...

Acknowledgment for Frame 10...

Acknowledgment for Frame 11...

Acknowledgment for Frame 12...

Total number of frames which were sent and resent are : 22

You might also like