-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGoBack-N.c
59 lines (54 loc) · 1.84 KB
/
GoBack-N.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
int main() {
int frame_size;
int N = 10; /* Window size */
int Rn = 0; /* Request number `Rn = Ack + 1` */
int Sn = 0; /* `[Sb:Sm)` Sequence number [0 1 2 3 4 5] 6 */
int Sb = 0; /* `Sb = 0`Sequence base (0)1 2 3 4 5 */
int Sm = 11; /* `Sm = N + 1` Sequence max 0 1 2 3 4 5 (6) */
unsigned int count = 0,n = -1;
printf("Enter size of frame: ");
scanf("%d",&frame_size);
printf("Enter sliding window size: ");
scanf("%d",&N);
Sm = N;
printf("Enter which nth frame is courrupted: ");
scanf("%d",&n);
if(N <= 0 || frame_size < N || n < 1) {
printf("Invalied inputs.");
return 1;
} printf("\nGoBack-%d ARQ:",N);
for (int ack = -1; ack < frame_size - 1; printf(" //timeout"))
{
for ( Sn = Sb; Sn < Sm ; Sn++) {
count++; /*frame sent*/
ack = (count%n == 0)? ack : (Sn == Sb)? Sn : ack;
printf("\n%2d. Frame %2d is send. Ack:%2d",count,Sn+1,ack+1);
Sm = (ack + (Sm - Sb + 1) >= frame_size)? frame_size : ack + (Sm - Sb + 1);
Sb = ack + 1;
if (count%n == 0)
{ printf(" (courrupted!)"); }
}
}printf("\n");
return 0;
}
/*
frame_size = 6
N = 5 (window size)
n = 3
count frame ack = Rn - 1
1. frame 1 sent | 1
2. frame 2 sent | 2
3. frame 3 sent (courrupted) | 2
4. frame 4 sent | 2
5. frame 5 sent | 2
6. frame 6 sent (courrupted) | 2
7. frame 3 sent //timeout | 3
8. frame 4 sent | 4
9. frame 5 sent (courrupted) | 4
10. frame 6 sent | 4
11. frame 5 sent | 5
12. frame 6 sent (courrupted) | 5
13. frame 6 sent | 6
*/