-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12.Go_Back_N.c
More file actions
176 lines (166 loc) · 5.6 KB
/
12.Go_Back_N.c
File metadata and controls
176 lines (166 loc) · 5.6 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <stdio.h>
#include <windows.h>
int main()
{
int n, exit_flag = 1, timeout = 10000;
char data[5][10];
while (exit_flag)
{
puts("\n1) Damaged Frame");
puts("2) Lost Frame");
puts("3) Lost Acknowledgement");
puts("4) Exit");
printf("\nEnter your choice: ");
scanf("%d", &n);
switch (n)
{
case 1:
puts("\nDamaged Frame:");
printf("\nEnter the value of Frame-0: ");
scanf("%s", &data[0]);
printf("Enter the value of Frame-1: ");
scanf("%s", &data[1]);
printf("Enter the value of Frame-2: ");
scanf("%s", &data[2]);
puts("ACK-3: Frame-0, Frame-1, Frame-2 received successfully");
printf("Enter the value of Frame-3: ");
scanf("%s", &data[3]);
puts("NAK-4: Error in Frame-3");
printf("Enter the value of Frame-4: ");
scanf("%s", &data[4]);
puts("Frame-4 discarded by the receiver.");
printf("Enter the value of Frame-5: ");
scanf("%s", &data[5]);
puts("Frame-5 discarded by the receiver.");
printf("Re-enter the value of Frame-3: ");
scanf("%s", &data[3]);
printf("Re-enter the value of Frame-4: ");
scanf("%s", &data[4]);
printf("Re-enter the value of Frame-5: ");
scanf("%s", &data[5]);
puts("Frame-0, Frame-1, Frame-2, Frame-3, Frame-4, Frame-5 received successfully");
break;
case 2:
puts("\nLost Frame:");
printf("\nEnter the value of Frame-0: ");
scanf("%s", &data[0]);
printf("Enter the value of Frame-1: ");
scanf("%s", &data[1]);
printf("Enter the value of Frame-2: ");
scanf("%[^\n]", &data[2]);
printf("\nEnter the value of Frame-3: ");
scanf("%s", &data[3]);
puts("Frame-3 discarded at the receiver");
puts("NAK-2: Frame-2 didn't received properly");
printf("Enter the value of Frame-4: ");
scanf("%s", &data[4]);
puts("Frame-4 discarded by the receiver.");
printf("Re-enter the value of Frame-2: ");
scanf("%s", &data[2]);
printf("Re-enter the value of Frame-3: ");
scanf("%s", &data[3]);
printf("Re-enter the value of Frame-4: ");
scanf("%s", &data[4]);
puts("Frame-0, Frame-1, Frame-2, Frame-3, Frame-4 received successfully");
break;
case 3:
puts("\nLost Acknowledgement:");
printf("\nEnter the value of Frame-0: ");
scanf("%s", &data[0]);
printf("Enter the value of Frame-1: ");
scanf("%s", &data[1]);
printf("Enter the value of Frame-2: ");
scanf("%s", &data[2]);
puts("ACK-3: generated after receiving 3 frames got lost.");
Sleep(timeout);
puts("Sender node Waiting Time has expired: Time-Out !!!...");
printf("Re-enter the value of Frame-0: ");
scanf("%s", &data[0]);
printf("Re-enter the value of Frame-1: ");
scanf("%s", &data[1]);
printf("Re-enter the value of Frame-2: ");
scanf("%s", &data[2]);
puts("Frame-0, Frame-1, Frame-2 received successfully");
break;
case 4:
exit_flag = 0;
break;
default:
puts("\nInvalid choice !!!... Enter a valid choice.");
getchar();
}
}
return 0;
}
// Input/Output:-
// ------------
// 1) Damaged Frame
// 2) Lost Frame
// 3) Lost Acknowledgement
// 4) Exit
//
// Enter your choice: 1
//
// Damaged Frame:
//
// Enter the value of Frame-0: 10101010
// Enter the value of Frame-1: 10101011
// Enter the value of Frame-2: 11101101
// ACK-3: Frame-0, Frame-1, Frame-2 received successfully
// Enter the value of Frame-3: 123458sc
// NAK-4: Error in Frame-3
// Enter the value of Frame-4: 10110010
// Frame-4 discarded by the receiver.
// Enter the value of Frame-5: 10110100
// Frame-5 discarded by the receiver.
// Re-enter the value of Frame-3: 10111101
// Re-enter the value of Frame-4: 10110010
// Re-enter the value of Frame-5: 10110100
// Frame-0, Frame-1, Frame-2, Frame-3, Frame-4, Frame-5 received successfully
//
// 1) Damaged Frame
// 2) Lost Frame
// 3) Lost Acknowledgement
// 4) Exit
//
// Enter your choice: 2
//
// Lost Frame:
//
// Enter the value of Frame-0: 10110010
// Enter the value of Frame-1: 01001101
// Enter the value of Frame-2: Enter the value of Frame-3: 11010110
// Frame-3 discarded at the receiver
// NAK-2: Frame-2 didn't received properly
// Enter the value of Frame-4: 10010101
// Frame-4 discarded by the receiver.
// Re-enter the value of Frame-2: 11001010
// Re-enter the value of Frame-3: 11010110
// Re-enter the value of Frame-4: 10010101
// Frame-0, Frame-1, Frame-2, Frame-3, Frame-4 received successfully
//
// 1) Damaged Frame
// 2) Lost Frame
// 3) Lost Acknowledgement
// 4) Exit
//
// Enter your choice: 3
//
// Lost Acknowledgement
//
// Enter the value of Frame-0: 11011011
// Enter the value of Frame-1: 01101001
// Enter the value of Frame-2: 10110101
// ACK-3: generated after receiving 3 frames got lost.
// Sender node Waiting Time has expired: Time-Out !!!...
// Re-enter the value of Frame-0: 11011011
// Re-enter the value of Frame-1: 01101001
// Re-enter the value of Frame-2: 10110101
// Frame-0, Frame-1, Frame-2 received successfully
//
// 1) Damaged Frame
// 2) Lost Frame
// 3) Lost Acknowledgement
// 4) Exit
//
// Enter your choice: 4