Advanced Network Security 2. Distributed Algorithms: Leader - - PowerPoint PPT Presentation

advanced network security
SMART_READER_LITE
LIVE PREVIEW

Advanced Network Security 2. Distributed Algorithms: Leader - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Jaap-Henk Hoepman

Digital Security (DS) Radboud University Nijmegen, the Netherlands

@xotoxot // * jhh@cs.ru.nl // 8 www.cs.ru.nl/~jhh

Advanced Network Security

  • 2. Distributed Algorithms:

Leader Election

slide-2
SLIDE 2

Jaap-Henk Hoepman // Radboud University Nijmegen //

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

02-03-2020 // Distributed algorithms - Leader Election 2

slide-3
SLIDE 3

Jaap-Henk Hoepman // Radboud University Nijmegen //

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

02-03-2020 // Distributed algorithms - Leader Election 3

slide-4
SLIDE 4

Jaap-Henk Hoepman // Radboud University Nijmegen //

Leader election (2)

n Requirements

  • Correctness: at most one leader is elected (and once elected stays

elected).

  • 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

02-03-2020 // Distributed algorithms - Leader Election 4

" Safety

" " livenest

"

slide-5
SLIDE 5

Jaap-Henk Hoepman // Radboud University Nijmegen //

How would/could you solve this?

02-03-2020 // Distributed algorithms - Leader Election 5

pint

  • to
_ pint

message

  • 4. ni
  • )

passing

"

i

  • n

t

'

s

(

FIFO :#

Hijs

k

^

KK

fijn

n

km )

slide-6
SLIDE 6

Jaap-Henk Hoepman // Radboud University Nijmegen //

slide-7
SLIDE 7

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 )

  • This protocol assumes that ( ) . ). = ), i.e. assigned increasing along

the ring, this is not necessarily the case

02-03-2020 // Distributed algorithms - Leader Election 6

Send clockwise (right) ( ) . ). Receive counterclockwise (left) ). ( ) . +,-.,/ = (( ) . ). < ).)

slide-8
SLIDE 8

Jaap-Henk Hoepman // Radboud University Nijmegen //

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 )

02-03-2020 // Distributed algorithms - Leader Election 7

9: = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9: do receive left ). 9: = 9: ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min

C

2 ∈ 9:) Election point

slide-9
SLIDE 9

Jaap-Henk Hoepman // Radboud University Nijmegen //

LeLann

n Why does this work? n What is the message / round complexity? n What if message passing is not FIFO?

02-03-2020 // Distributed algorithms - Leader Election 8

9 = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min

C

2 ∈ 9)

  • single message

has constant

size

.
  • 0 ( log N)
  • # messages :

01N) for

a single node

total

message complexit

is

0 ( N')

slide-10
SLIDE 10

Jaap-Henk Hoepman // Radboud University Nijmegen //

Le Lann

n Why does this work?

02-03-2020 // Distributed algorithms - Leader Election 9

9 = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min

C

2 ∈ 9)

i

FIFO !

, →

40k

also

/

rijker

Identificeer

:

\

  • s
slide-11
SLIDE 11

Jaap-Henk Hoepman // Radboud University Nijmegen //

Le Lann

n What is the message / round complexity?

02-03-2020 // Distributed algorithms - Leader Election 10

9 = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min

C

2 ∈ 9)

slide-12
SLIDE 12

Jaap-Henk Hoepman // Radboud University Nijmegen //

LeLann

n Why does this work?

  • See proof further on

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 ;-)

02-03-2020 // Distributed algorithms - Leader Election 11

9 = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min

C

2 ∈ 9)

slide-13
SLIDE 13

Jaap-Henk Hoepman // Radboud University Nijmegen //

Le Lann: proof

n Proof obligations

  • Correctness
  • Progress

02-03-2020 // Distributed algorithms - Leader Election 12

9 = ∅ ( ) . +,-.,/ = 5-+6, send right ( ) . ). while ( ) . ). ∉ 9 do receive left ). 9 = 9 ∪ {).} send right ). ( ) . +,-.,/ = (( ) . ). = min

C

2 ∈ 9)

NY

election ⇒

pour

slide-14
SLIDE 14

Jaap-Henk Hoepman // Radboud University Nijmegen //

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).

02-03-2020 // Distributed algorithms - Leader Election 13

slide-15
SLIDE 15

Jaap-Henk Hoepman // Radboud University Nijmegen //

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: = ()

02-03-2020 // Distributed algorithms - Leader Election 14

slide-16
SLIDE 16

Jaap-Henk Hoepman // Radboud University Nijmegen //

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

  • rder.

«Then ) receives ( 2 . )., … , ( 2 − r mod D = ( ) − 1 mod D . )., … , ( ) − /L . ). in that order as required.

02-03-2020 // Distributed algorithms - Leader Election 15

slide-17
SLIDE 17

Jaap-Henk Hoepman // Radboud University Nijmegen //

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.

02-03-2020 // Distributed algorithms - Leader Election 16

slide-18
SLIDE 18

Jaap-Henk Hoepman // Radboud University Nijmegen //

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

02-03-2020 // Distributed algorithms - Leader Election 17

slide-19
SLIDE 19

Jaap-Henk Hoepman // Radboud University Nijmegen //

What if nodes do not have unique identifiers?

02-03-2020 // Distributed algorithms - Leader Election 18

→ are

  • id

µ

(

leider

¥

i

% !

÷ #

slide-20
SLIDE 20

Jaap-Henk Hoepman // Radboud University Nijmegen //

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

02-03-2020 // Distributed algorithms - Leader Election 19

slide-21
SLIDE 21

Jaap-Henk Hoepman // Radboud University Nijmegen //

Peterson’s protocol: leader election on a ring

n Bidirectional communication

  • Nodes can send messages clockwise and anticlockwise

n Idea: algorithm proceeds in rounds

  • First round all D nodes are active and participate
  • If a round starts with G participants, at least G/2 and at most G − 1 will

be eliminated (and become passive)

  • If a round start with 1 participant, it will declare itself leader at the

end of the round

02-03-2020 // Distributed algorithms - Leader Election 20

start with

N

modes :

Yom are garant eed

to

find

a

leader in

log ( N)

rounds

slide-22
SLIDE 22

Jaap-Henk Hoepman // Radboud University Nijmegen //

Peterson’s protocol: leader election on a ring

n The protocol for node )

02-03-2020 // Distributed algorithms - Leader Election 21

( ) . -S0)T, = 0/1, ( ) . +,-.,/ = 5-+6, while 0/1, /* new round */ do if ( ) . -S0)T, == 0/1, ∧ ( ) . +,-.,/ == 5-+6, send left ( ) . ). send right ( ) . ). receive right /)Vℎ0). receive left +,50). if (( ) . ). == +,50).) ∧ (( ) . ). == /)Vℎ0).) ( ) . +,-.,/ = 0/1, else if (( ) . ). < +,50).) ∨ (( ) . ). < /)Vℎ0).) ( ) . -S0)T, = 5-+6, else /* passive or leader */ receive right ). ; send left ). receive left ). ; send right ).

slide-23
SLIDE 23

Jaap-Henk Hoepman // Radboud University Nijmegen //

Peterson’s protocol

n Why does it work? n What is the message / round complexity? n What if message passing is not FIFO?

02-03-2020 // Distributed algorithms - Leader Election 22

( ) . -S0)T, = 0/1, ( ) . +,-.,/ = 5-+6, while 0/1, /* new round */ do if ( ) . -S0)T, == 0/1, ∧ ( ) . +,-.,/ == 5-+6, send left ( ) . ). send right ( ) . ). receive right /)Vℎ0). receive left +,50). if (( ) . ). == +,50).) ∧ (( ) . ). == /)Vℎ0).) ( ) . +,-.,/ = 0/1, else if (( ) . ). < +,50).) ∨ (( ) . ). < /)Vℎ0).) ( ) . -S0)T, = 5-+6, else /* passive or leader */ receive right ). ; send left ). receive left ). ; send right ).

slide-24
SLIDE 24

Jaap-Henk Hoepman // Radboud University Nijmegen //

Peterson

02-03-2020 // Distributed algorithms - Leader Election 23

( ) . -S0)T, = 0/1, ( ) . +,-.,/ = 5-+6, while 0/1, /* new round */ do if ( ) . -S0)T, == 0/1, ∧ ( ) . +,-.,/ == 5-+6, send left ( ) . ). send right ( ) . ). receive right /)Vℎ0). receive left +,50). if (( ) . ). == +,50).) ∧ (( ) . ). == /)Vℎ0).) ( ) . +,-.,/ = 0/1, else if (( ) . ). < +,50).) ∨ (( ) . ). < /)Vℎ0).) ( ) . -S0)T, = 5-+6, else /* passive or leader */ receive right ). ; send left ). receive left ). ; send right ).

etel

  • "
slide-25
SLIDE 25

Jaap-Henk Hoepman // Radboud University Nijmegen //

Peterson’s protocol: leader election on a ring

n There are at most log D rounds

  • Node can only survive (remain active) if

both its left and right active neighbour are smaller

  • Therefore at most half of the nodes can

survive

n In every round 2D messages are sent

  • An active or passive node sends exactly 2

messages in each round

n So: message complexity is at most 2D log D

02-03-2020 // Distributed algorithms - Leader Election 24

( ) . -S0)T, = 0/1, ( ) . +,-.,/ = 5-+6, while 0/1, /* new round */ do if ( ) . -S0)T, == 0/1, ∧ ( ) . +,-.,/ == 5-+6, send left ( ) . ). send right ( ) . ). receive right /)Vℎ0). receive left +,50). if (( ) . ). == +,50).) ∧ (( ) . ). == /)Vℎ0).) ( ) . +,-.,/ = 0/1, else if (( ) . ). < +,50).) ∨ (( ) . ). < /)Vℎ0).) ( ) . -S0)T, = 5-+6, else /* passive or leader */ receive right ). ; send left ). receive left ). ; send right ).

slide-26
SLIDE 26

Jaap-Henk Hoepman // Radboud University Nijmegen //

i

Öre

:

¥

slide-27
SLIDE 27

Jaap-Henk Hoepman // Radboud University Nijmegen //

Peterson’s protocol: leader election on a ring

n There are at most log D rounds

  • Node can only survive (remain active) if

both its left and right active neighbour are smaller

  • Therefore at most half of the nodes can

survive

n In every round 2D messages are sent

  • An active or passive node sends exactly 2

messages in each round

n So: message complexity is at most 2D log D

02-03-2020 // Distributed algorithms - Leader Election 24

( ) . -S0)T, = 0/1, ( ) . +,-.,/ = 5-+6, while 0/1, /* new round */ do if ( ) . -S0)T, == 0/1, ∧ ( ) . +,-.,/ == 5-+6, send left ( ) . ). send right ( ) . ). receive right /)Vℎ0). receive left +,50). if (( ) . ). == +,50).) ∧ (( ) . ). == /)Vℎ0).) ( ) . +,-.,/ = 0/1, else if (( ) . ). < +,50).) ∨ (( ) . ). < /)Vℎ0).) ( ) . -S0)T, = 5-+6, else /* passive or leader */ receive right ). ; send left ). receive left ). ; send right ).