Advanced Network Security 2. Distributed Algorithms: Leader Election Jaap-Henk Hoepman Digital Security (DS) Radboud University Nijmegen, the Netherlands @xotoxot // * jhh@cs.ru.nl // 8 www.cs.ru.nl/~jhh
Leader election: motivation n IBM token ring (1970) ● For local area network ● Single token traversing ring ● Station with token was allowed to send n How to ● Start the network? « 0 tokens ● Recover from an error? « >1 tokens Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 2
Leader election (1) n Given a graph ! = ($, &) of nodes, design a protocol that will elect a single node as leader n Output stored in local variable ( ) . +,-.,/ ● There is one node ) with ( ) . +,-.,/ = 0/1, ● For all 2 ∈ $, 2 ≠ ) we have ( ) . +,-.,/ = 5-+6, n Assumptions ● ! is connected, i.e. nodes can reach each other; we assume a bidirectional ring network here ● Nodes have unique identifiers ( ) . ). « E.g. a MAC address « Note that nodes do NOT know V (i.e. the set of identities in the graph) ● All nodes simultaneously start the protocol Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 3
Leader election (2) " Safety n Requirements " ● Correctness: at most one leader is elected (and once elected stays elected). " livenest " ● Progress: eventually a leader is elected. n Leader election used, for example to ● Recover from errors (the leader coordinates the repair) ● Initiate another higher-level distributed algorithm Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 4
_ pint - to pint How would/could you solve this? message - ) 4. ni passing - " i - t ' H ij s → s n FIFO :# ( k f ij n ^ KK ✓ ← n km ) Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 5
Jaap-Henk Hoepman // Radboud University Nijmegen //
Some non-solutions n Node ) with ( ) . ). = 0 becomes leader ● May not exist. E.g. if identifiers are based on MAC addresses n Consider the following protocol for node ) Send clockwise (right) ( ) . ). Receive counterclockwise (left) ). ( ) . +,-.,/ = (( ) . ). < ). ) ● This protocol assumes that ( ) . ). = ) , i.e. assigned increasing along the ring, this is not necessarily the case Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 6
LeLann’s protocol: leader election on a ring n Assumption ● FIFO message passing and unique identifiers ● Note: nodes do not know the size of the ring ● Unidirectional communication (clockwise only) n Protocol for node ) 9 : = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 : do receive left ). 9 : = 9 : ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min 2 ∈ 9 : ) Election point C Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 7
⇒ 9 = ∅ LeLann ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). n Why does this work? 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min 2 ∈ 9) C n What is the message / round complexity? - 0 ( log N ) - single message size has constant . 01N ) for message complexit a single node total - # messages : 0 ( N ' ) is n What if message passing is not FIFO? Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 8
9 = ∅ Le Lann ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). n Why does this work? 9 = 9 ∪ {).} i send right ). FIFO ! , → ( ) . +,-.,/ = (( ) . ). = min 2 ∈ 9) C also 40k r ij ker / Identificeer : \ s - - Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 9
9 = ∅ Le Lann ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). n What is the message / round complexity? 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min 2 ∈ 9) C Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 10
9 = ∅ LeLann ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). n Why does this work? 9 = 9 ∪ {).} send right ). ● See proof further on ( ) . +,-.,/ = (( ) . ). = min 2 ∈ 9) C n What is the message / round complexity? ● Every node forwards messages until it receives it’s own id back. ● If the size of the ring is n, each node sends D + 1 messages ● Total number of messages sent it D D + 1 ● Round complexity is D n What if message passing is not FIFO? ● Homework ;-) Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 11
9 = ∅ Le Lann: proof ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). NY n Proof obligations 9 = 9 ∪ {).} send right ). ● Correctness ( ) . +,-.,/ = (( ) . ). = min 2 ∈ 9) election ⇒ C ● Progress pour ⑧ Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 12
LeLann proof of correctness (1) n Correctness: at most one leader is elected (and once elected stays elected). ● We need to prove that for all nodes ), 2 that reach the election point, we have 9 : = 9 C . Then the result follows as nodes have unique identifiers. ● In fact we will show that we have 9 : = 9 C = ( G . ). G ∈ 0, D − 1 (nodes are numbered clockwise around the ring, and D is the number of nodes – which is unknown to the number of nodes!) ● In what follows, let 9 : be the list of values, in the order in which they were received (instead of a set). Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 13
LeLann proof of correctness (1) n [correctness proof continued] ● We prove this using induction on the / -th message node ) receives; in fact we show that when node ) receives the / -th message, it actually received 9 : = (( ) − 1 mod D . )., … , ( ) − / mod D . ).) in that order. ● For round / = 0 (i.e. initially) the statement holds trivially: no messages have been received so far and 9 : = () Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 14
LeLann proof of correctness (2) n [correctness proof continued] ● For round / L = / + 1 observe « All message received by node ) by round / L = / + 1 must have been sent by its left hand neighbour 2 = ) − 1 mod D in or before round / . « At the end of round / node 2 has sent all values in 9 C to ) , in the same order, but first sent out ( 2 . ). « Because of the FIFO property node ) receives these in the same order « Using the induction hypothesis 9 C = ( 2 − 1 mod D . )., … , ([2 − / mod D] in that order. « Then ) receives ( 2 . )., … , ( 2 − r mod D = ( ) − 1 mod D . )., … , ( ) − / L . ). in that order as required. Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 15
LeLann proof of correctness (3) n [correctness proof continued] ● If node ) reaches the election point then ( ) . ). ∈ 9 : ● This happens when the / -th message node ) receives (so / > 0 ), i.e.the message ( G . ). with G = ) − / mod D , equals ( ) . ). . ● As identities on the ring are unique, this implies G = ) and so / = D and hence, 9 : = (( ) − 1 mod D . )., … , ( ) − D mod D . ).) ● In other words 9 : = ( G . ). G ∈ 0, D − 1] as required. Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 16
LeLann proof of correctness (3) n Progress: eventually a leader is elected. ● Let node ) have the smallest ( ) . ). ● Initially node ) sends ( ) . ). to its right-hand neighbour ● This means a message ( ) . ). is either in transit on a link (meaning the next node will eventually receive it) or received by the node (meaning it will be sent out to the right by that node) ● Whenever this message is sent, it moves one step closer back to node ) ● Eventually node ) receives ( ) . ). (and sends it once more the right) and then stops ● It determines that (( ) . ). = min ) ∈ 9) and hence becomes leader as required : Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 17
What if nodes do not have unique identifiers? oid → are µ ¥ ( leider % ! i 0 ÷ # Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 18
What if nodes do not have unique identifiers? n Then there exists a symmetric configuration ( ● where all nodes have the same state, and all edges have the same state ● I.e. either all nodes are leaders, or no node is leader n Starting in ( let all nodes take a step (the same) in turn, then ● all steps are local steps (changing the local state to a new state, the same for all nodes) ● all steps are receive actions (receiving the same message), or ● all steps are send actions (sending the same message) n Therefore the resulting configuration ( L is again symmetric n We can repeat this forever, never reaching a state where there is exactly one leader n This is called a symmetry argument Jaap-Henk Hoepman // Radboud University Nijmegen // 02-03-2020 // Distributed algorithms - Leader Election 19
Recommend
More recommend