Full version of the algorithm.
This is the general version of the one-on-group communication algorithm as presented in my graduation thesis. The packages used in this algorithm have the following form:
Ksource(destination,checksum,group,position,window_size,data)
An explanation of the fields:
source |
source port where this package is sent from [S,Ri]; |
Ksource |
the source who sends this package knows this package; |
destination |
destination port of package [S,Ri]; |
checksum |
digital arithmatic representation of the package |
group |
group receivers to which the message is sent [RG, - ]("-" means that the sender communicates only to the destination (one-on-one communication)) |
position |
position of the data from the input tape; |
window_size |
size of the sending/sliding window; |
data |
data that has to be transmitted. |
Sender (incoming packages)
1 for (i = 1 to n)
{For all agents who sender is sending to, ... }
2 high_cons_ack_Ri = 0
{... initialize the highest consecutive acknowledge number.}
3 end
{High_cons_ack_Ri's initialized}
4 high_cons_ack_RG = 0
{Initialize the overall highest consecutive acknowledgement.}
5 while true do
{Get ready for receiving acknowledgements from the receivers you're sending to, ... [19]}
6 when received K_Ri(S,checksum,-,ack_Ri,window_size,-) do
{You have received a package. Prepare for processing, ... [18]}
7 if (checksum = calculateChecksum(KRi(S,-,-,ack_Ri,window_size,-)))
{Check if the checksum of the package is correct, delete package if not. [17]}
8 latest_advert_Ri = window_size
{The last advertisement you have received from Ri is this one.}
9 latest_advert_RG = min(latest_advert_Ri (for i = 1 to n))
{The last RG advertisement is the lowest latest advertisement from all Ri's.}
10 if (ack_Ri > high_cons_ack_Ri) do
{If this acknowledgement from Ri is higher than the highest
consecutive acknowledgement received so far from Ri, ... [16]}
11 high_cons_ack_Ri = ack_Ri
{This is the new highest consecutive acknowledgement from Ri.}
12 forall ack_Ri with (ack_Ri ≤ high_cons_ack_Ri) do}
{For all the packages up to the highest acknowledgment, ...}
13 store KSKRi(-,-,-,ack_Ri,-,-)
{... store the fact that you know that Ri knows it.}
14 end
{Acknowledgement from Ri updated.}
15 high_cons_ack_RG = min(high_cons_ack_Ri (for i = 1 to n))
{The new high_cons_ack_RG is equal to the lowest high_cons_ack_Ri
for all i's.}
16 end
{[10] ... high_cons_ack_Ri and high_cons_ack_RG updated with
acknowledgement from Ri.}
17 end
{... [7].}
18 end
{[6] ... finished processing of incoming package.}
19 end
{... [5].}
Sender (outgoing packages)
1 window_size = 4
{Set initial window-size.}
2 time_out = 20
{Retransmission Time-Out (RTO). Common value is 20 ms.}
3 offset = 0
{Reading of a tape starts at position 0.}
4 while true do
{Start reading and sending an infinite tape, ... [24]}
5 forall seq with (offset ≤ seq < offset+window_size) do
{For all the packages in the current window, ...}
6 read(seq,alpha)
{... read the values from the tape, ...}
7 store KS(-,-,-,seq,-,alpha)
{... and store this information in your knowledge base.}
8 end
{Tape within window has been read. Facts stored.}
9 while (high_cons_ack_RG ≠ offset+window_size-1) do
{While not all the packages in the window have been acknowledged from RG
(all agents), ... [21]}
10 forall seq with (offset ≤ seq < offset+window_size) do
{For all the packages in the current window, ...}
11 for (i = 1 to n) do
{... and for all receiving agents, ...}
12 if not KSKRi(-,-,-,seq,-,-) do
{... check if package `seq' has not been acknowledged yet by Ri, ...}
13 if (timer\tiny (seq,Ri) \scriptsize ≥ time_out) do
{... and its retransmission time has expired, ...}
14 checksum = calculateChecksum(KS(Ri,-,group,seq,window_size,alpha))
{... calculate the checksum of the package to be sent ...}
15 send KS(Ri,checksum,group,seq,window_size,alpha)
{... (re)send the package to Ri.}
16 timer\tiny (seq,Ri) \scriptsize = 0
{Reset the timer.}
17 end
{A package for which the retransmission time was expired, ...}
18 end
{... and that was unacknowledged by Ri, has been resent.}
19 end
{A package has been resent to all agents that didn't acknowledge it.}
20 end
{All packages from the sending window have been resent to all the receiving agents
that didn't acknowledge these packages.}
21 end
{[9] ... all the packages in the window have been acknowledged by all
receiving agents Ri.}
22 offset = offset + window-size
{Move offset with the size of the current window.}
23 window_size = latest_advert_Rg
{Set the window-size to the latest group advertisement.}
24 end
{... [4].}
Receiver (incoming packages)
1 while true do
{Get ready for receiving an infinite tape, ... [7]}
2 when received KS(Ri,group,checksum,seq,window_size,alpha) do
{You have received a package (from S). Prepare for processing, ... [6]}
3 if(checksum = calculateChecksum(KS(Ri,-,group,seq,window_size,alpha)))
{Check if the checksum of the package is correct, delete package if not.[5]}
4 store KRiKS(-,-,group,seq,window_size,alpha)
{Store the received package.}
5 end
{... [3]}
6 end
{[2] ... finished processing incoming package.}
7 end
{... [1].}
Receiver (outgoing packages)
1 when KRiKS(-,-,-,0,-,-)
{Wait until the first message is received.}
2 high_cons_seq = 0
{Initiate the highest consecutive sequence at 0.}
3 time_out = 20
{Set the retransmission Time-Out (RTO). Common value is 20 ms.}
4 timer = 0
{Reset timer.}
5 while true do
{Get ready to acknowledge incoming packages, ... [15]}
6 while not KRi(-,-,-,high_cons_seq+1,-,-) do
{Still not received package with sequence number 'high_cons_seq+1', ...}
7 if (timer ≥ time_out)
{... and it is time to (re)transmit acknowledgement, Prepare for
(re)transmitting, ...[12]}
8 window_size = estimateOptimalWindowSizeRi()
{Estimate the best window-size for the state the buffer of Ri is in.}
9 checksum = calculateChecksum(KRi(S,-,-,high_cons_seq,window_size,-))
{Calculate the checksum of the package to be sent.}
10 send KRi(S,checksum,-,high_cons_seq,window_size,-)
{Send acknowledgement.}
12 timer = 0
{Reset the timer.}
13 end
{[7] ... you've just (re)transmitted an acknowledgement package.}
14 end
{You've received message high_cons_seq+1.}
15 high_cons_seq = high_cons_seq +1
{You now know the next message. Increment high_cons_seq.}
16 end
{... [5].}