Alternating Bit Protocol m[2],0 m[1],1 m[0],0 m[0],0 R S ack, 0 ABP is a link layer protocol. Works on FIFO channels only. Guarantees reliable message delivery with a 1-bit sequence number (this is the traditional version with window size = 1). Study how this works. Alternating Bit Protocol

program ABP; {program for process S} define sent, b : 0 or 1; next : integer; initially next = 0, sent = 1, b = 0, and channels are empty; do sent b send (m[next], b); next := next+1; sent := b [] (ack, j) is received if j = b b := 1- b [] j b skip fi [] timeout (R,S) send (m[next-1], b) od {program for process R} define j : 0 or 1; {initially j = 0}; do (m[ ], b) is received if j = b accept the message; send (ack, j); j:= 1 - j [] j b send (ack, 1-j) fi

od S m[1],1 a,0 m[0],0 m[0],0 R How TCP works Supports end-to-end logical connection between any two computers on the Internet. Basic idea is the same as those of sliding window protocols. But TCP uses bounded sequence numbers! It is safe to re-use a sequence number when it is unique. With a high probability, a random 32 or 64-bit number is unique during the lifetime of the application. Also, current sequence numbers are flushed out of the system after a time = 2d, where d is the round

trip delay. It is even more unlikely that the same sequence number is generated within a time interval of of 2d. How TCP works Sender Receiver SYN SYN seq = x , seq=y, ack = x+1 ACK, ack=y+1 send (m, y+1)

ack (y+2) How TCP works Three-way handshake. Sequence numbers are unique w.h.p. Why is the knowledge of roundtrip delay important? -Timeout can be correctly chosen What if the timeout period is too small / too large? What if the window is too small / too large? Adaptive retransmission: receiver can throttle sender and control the window size to save its buffer space. Distributed Consensus Reaching agreement is a fundamental problem in distributed computing. Some examples are Leader election / Mutual Exclusion Commit or Abort in distributed transactions Reaching agreement about which process has failed Clock phase synchronization Air traffic control system: all aircrafts must have the same view

Problem Specification Termination. Every non-faulty process must eventually decide. Agreement. The final decision of every non-faulty process must be identical. Validity. If every non-faulty process begins with the same initial value v, then their final decision must be v. Problem Specification input output

p0 u0 v p1 v p2 u1 u2 p3 u3 v

v Here, v must be equal to the value at some input line. Finally, all outputs must be identical, even if one or more processes fail. Observation If there is no failure, then reaching consensus is trivial. All-to-all broadcast followed by a applying a choice function Consensus in presence of failures can however be complex. The complexity depends on the system model and the type of failures Asynchronous Consensus Seven members of a busy household decided to hire a cook, since they do not have time to prepare their own food. Each member separately interviewed every applicant for the cooks position. Depending on how it went, each member voted "yes" (means hire) or "no" (means don't hire).

These members will now have to communicate with one another to reach a uniform final decision about whether the applicant will be hired. The process will be repeated with the next applicant, until someone is hired. Consider various modes of communication like shared memory or message passing. Also assume that one process (i.e. a member) may crash at any time. Asynchronous Consensus Theorem. In a purely asynchronous distributed system, the consensus problem is impossible to solve if even a single process crashes Result due to Fischer, Lynch, Patterson (commonly known as FLP 85). Received the most influential paper award of ACM PODC in 2001 Proof Bivalent and Univalent states A decision state is bivalent, if starting from that state, there exist two distinct executions leading to two distinct decision values 0 or 1. Otherwise it is univalent.

A univalent state may be either 0-valent or 1-valent. Proof (continued) Lemma. No execution can lead from a 0-valent to a 1-valent state or vice versa. Proof. Follows from the definition of 0-valent and 1-valent states. Proof Lemma. Every consensus protocol must have a bivalent initial state. Proof by contradiction. Suppose not. Then consider the following input patterns: s[0] s[n-1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1

1 1 1 1 1 1 1 1 1 {0-valent) {1-valent} there must ne a j: s[j] is 0-valent s[j+1] is 1-valent (differ in jth position) What if process (j+1) crashes at the first step? Proof of FLP (continued) Lemma. bivalent

In a consensus protocol, starting from Q any initial bivalent state I, there must exist a reachable bivalent state T, such that every action taken by some process p in state T leads to either a bivalent bivalent S bivalent R action 0

bivalent U action 1 T action 0 action 1 0 valent or a 1-valent state. R0 Note that bivalent states should not form a cycle, since it affects termination. o-valent

R1 1-valent T0 o-valent T1 1-valent Actions 0 and 1 from T must be taken by the same process p. Why? Proof of FLP (continued) Assume shared memory communication. Also assume that p q. Various cases are possible 1-valent

Case 1. q writes e1 Decision =1 T1 ? T p reads T0 0-valent Decision = 0 e0

Such a computation must exist since p can crash at any time Starting from T, let e1 be a computation that excludes any step by p. Let p crash after reading. Then e1 is a valid computation from T0 too. To all non-faulty processes, these two computations are identical, but the outcomes are different! This is not possible! But then, starting from a 0-valent state, a computation reaches decision = 1 which is not feasible Proof (continued) Case 2. 1-valent T1 q writes e1 Decision =1

T p writes T0 0-valent Decision = 0 e0 Both write on the same variable, and p writes first. From T, let e1 be a computation that excludes any step by p. Let p crash after writing. Then e1 is a valid computation from T0 too. To all non-faulty processes, these two computations are identical, (q overwrites the value written by p) but the outcomes are different!

Proof (continued) Case 3 1-valent q writes T1 p writes Decision =1 Z T p writes T0 0-valent

Let both p and q write, but q writes Decision = 0 on different variables. Then regardless of the order of these writes, both computations lead to the same intermediate global state Z, which must be univalent. Is Z 1-valent or 0-valent? Both are absurd. Proof (continued) Similar arguments can be made for communication using the message passing model too (See Nancy Lynchs book). These lead to the fact that p, q cannot be distinct processes, and p = q. Call p the decider process. What if p crashes in state T? No consensus is reached! Conclusion

In a purely asynchronous system, there is no solution to the consensus problem if a single process crashes.. Note that this is true for deterministic algorithms only. Solutions do exist for the consensus problem using randomized algorithm, or using the synchronous model.