-
Notifications
You must be signed in to change notification settings - Fork 1
/
Polling.cpp
53 lines (49 loc) · 2.12 KB
/
Polling.cpp
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
/*Polling: This code is contributed by Sourajita Dewasi.This is Time Division Multiplexing means equal
division of time reserved for each station in
Round Robin Technique but after conducting a poll on which station has the requirement to transmit
data packets to avoid wastage of efficiency in reservation for stations which don't have data packets
to transmit. Since there is only one packet at a time in channel there can be no collision. */
#include <iostream>
using namespace std;
int Sum=0;
int i=0;
int MaxPacket=2;
//This is the maximum number of packets that can be transmitted by aStation in the given time slot.
//We are also assuming equal packet size of data or considering the max packet nos transmission as on the largest packet size.
int main() {
int Stations[5]={0,1,2,3,4};
/*Let in Station 0 no of packets to be transfered are 6.
in Station 1 no of packets to be transfered are 0.
in Station 2 no of packets to be transfeered are 2.
in Station 3 no of packets to be transfeered are 1.
in Station 4 no of packets to be transfeered are 0. */
int Check[5]={6,0,2,1,0};
//run to check if there is any data packet to transmit in any station initially
for( i=0; i<5; i++){
Sum=Check[i]+Sum;
}
//running the Polling function
while(Sum!= 0){
for( i=0; i<5; i++){
cout<<"\n\n Polling Time for Station "<<i;
if(Check[i] == 0){
cout<<"\n No time alloted for transmission because 0 packets present";
}
else{ cout<<" +Transmission Time";
if(Check[i]<MaxPacket){
cout<<"\n Time alloted for transmission of "<<Check[i]<<"th packet from station "<<i;
cout<<"\n "<<Check[i]<<" packet Transmitted";
Check[i]--; Sum--;
}
else{
cout<<"\nTime alloted for transmission of "<<Check[i]<<"th packet from station "<<i;
cout<<"\n "<<Check[i]<<"th packet Transmitted";
cout<<"\n Time alloted for transmission of "<<Check[i]-1<<"th packet from station "<<i;
cout<<"\n "<<Check[i]-1<<"th packet Transmitted";
Check[i]= Check[i]-MaxPacket;Sum=Sum-MaxPacket;
}
}
}
}
return 0;
}