12. routing algorithm for mobile agent

79
12. Routing Algorithm for Mobile Agent Jean-Raymond Abrial 2009

Upload: others

Post on 27-Oct-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 12. Routing Algorithm for Mobile Agent

12. Routing Algorithm for Mobile Agent

Jean-Raymond Abrial

2009

Page 2: 12. Routing Algorithm for Mobile Agent

Purpose of this Lecture 1

- No more learning about refinement and abstraction (practicing)

- No more learning about modeling conventions (practicing)

- Re-using dynamically the small tree theory we already developed

- Study a practical problem in distributed computing communication

- The example comes from the following paper:

L. Moreau. Distributed Directory Service and Message Routing for

Mobile Agent. Science of Computer Programming 2001.

1

Page 3: 12. Routing Algorithm for Mobile Agent

The Abstract Communication Situation with a Mobile Agent 2

- A mobile agentM is supposed to travel between sites

- Some fixed agents at sites want to send messages toM

- In an abstract world:

- the moves ofM are instantaneous

- the traveling of messages between sites takes no time

- the knowledge of the moves ofM is also instantaneous

- Thus fixed agents always send messages whereM is

2

Page 4: 12. Routing Algorithm for Mobile Agent

Initial Situation 3

ba

d c

3

Page 5: 12. Routing Algorithm for Mobile Agent

M moves from c to d 4

ba

d c

b

c

a

d

4

Page 6: 12. Routing Algorithm for Mobile Agent

M moves from d to a 5

ba

d c

bb

cc

a

d

a

d

5

Page 7: 12. Routing Algorithm for Mobile Agent

M moves from a to c 6

ba

d c

bb

cc

a

d

d

a b

a

d

c

6

Page 8: 12. Routing Algorithm for Mobile Agent

M moves from c to b 7

d

a b

c

ba

d c

bb

cc

a

d

a

d

d

a b

c

7

Page 9: 12. Routing Algorithm for Mobile Agent

A More Concrete Situation 8

- The moves ofM are still instantaneous

- The traveling of messages between sites still takes no time

- The knowledge of the moves ofM is not instantaneous any more

8

Page 10: 12. Routing Algorithm for Mobile Agent

A More Concrete Situation (cont’d) 9

- WhenM moves from site x to site y then

- Agents of x and y knows it immediately

- Agents of other sites are not aware of the move

- They still sent their messages where they believeM is

- A message arriving at a site whichM has left can be forwarded

9

Page 11: 12. Routing Algorithm for Mobile Agent

Initial Situation 10

ba

d c

10

Page 12: 12. Routing Algorithm for Mobile Agent

M moves from c to d 11

ba

d c c

ba

d

11

Page 13: 12. Routing Algorithm for Mobile Agent

M moves from d to a 12

ba

d c

b

cc

b a

d

a

d

12

Page 14: 12. Routing Algorithm for Mobile Agent

M moves from a to c 13

ba

d c

b

cc

b a

d

a

d

d

a b

c

13

Page 15: 12. Routing Algorithm for Mobile Agent

M moves from c to b 14

ba

d c

b

cc

b a

d

a

d

d

a b

c

b

cd

a

14

Page 16: 12. Routing Algorithm for Mobile Agent

Showing the Structural Modifications 15

ba ba

d cd

a b

cd c

a

d

b

c

a

d

b

c

15

Page 17: 12. Routing Algorithm for Mobile Agent

Showing the Tree Structure 16

d

c

ba

d

c

a b

a

d

c

b

c

a b

b

c

a

d

d

16

Page 18: 12. Routing Algorithm for Mobile Agent

A Tree of Communications 17

- The mobileM is at the root of a tree

17

Page 19: 12. Routing Algorithm for Mobile Agent

Modification of the Tree 18

18

Page 20: 12. Routing Algorithm for Mobile Agent

Comparing the two Situations 19

m

n

p

n

m

p

n

m

p

qq q

The mobileM remains at the root of a tree (to be proved however)

19

Page 21: 12. Routing Algorithm for Mobile Agent

Initial Model: the Constants 20

- S denotes the set of sites

- M denotes the set of messages

carrier sets: SM

constant: il

axm0 1: il ∈ S

axm0 2: finite(S)

- Constant il denotes the initial location of the mobile

20

Page 22: 12. Routing Algorithm for Mobile Agent

Initial Model: the Variables (1) 21

variables: lcp

inv0 1: l ∈ S

inv0 2: c ∈ S \ {l} → S

inv0 3: p ∈ M 7→ S

- Variable l denotes the actual location of the mobile

- Variable c denotes the dynamic channel structure

- Variable p denotes the position of each message

21

Page 23: 12. Routing Algorithm for Mobile Agent

Initial Model: the State (2) 22

This invariant states that the channel structure is a tree with:

- root: l

- parent function: c

inv0 4: ∀T · T ⊆ S ∧ T ⊆ c−1[T ] ⇒ T = ∅

22

Page 24: 12. Routing Algorithm for Mobile Agent

Initial Model: the Events (1) 23

initl := ilc := (S \ {il}) × {il}p := ∅

rcv agtany s where

s 6= lthen

l := sc := ({s} �− c) ∪ {l 7→ s}

end

- This event describes the move of the mobile from l to s

- The move of the mobile from l to s is supposed to be instantaneous

23

Page 25: 12. Routing Algorithm for Mobile Agent

Initial Model: the Events (2) 24

- Node s sends a message to the Mobile

- This message is stored locally

snd msgany s, m where

s ∈ Sm ∈ M \ dom(p)

thenp(m) := s

end

24

Page 26: 12. Routing Algorithm for Mobile Agent

Initial Model: the Events (3) 25

- Messages are either delivered or forwarded

dlv msgany m where

m ∈ dom(p)p(m) = l

thenp := {m} �− p

end

fwd msgany m where

m ∈ dom(p)p(m) 6= l

thenp(m) := c(p(m))

end

- When delivered, a message is removed

25

Page 27: 12. Routing Algorithm for Mobile Agent

Initial Model: Proof of invariant inv0 4 by event rcv agt 26

rcv agtany s where

s ∈ S \ {l}then

l := sc := ({s} �− c) ∪ {l 7→ s}

end

. . .

Invariant inv0 4

Guard of rcv agt`

Modified Invariant inv0 4

. . .

∀T ·

T ⊆ ST ⊆ c−1[T ]

⇒T = ∅

s ∈ S \ {l}

`

∀T ·

T ⊆ ST ⊆ ({s} �− c) ∪ {l 7→ s})−1[T ]

⇒T = ∅

26

Page 28: 12. Routing Algorithm for Mobile Agent

Proof 27

. . .

∀T ·

T ⊆ ST ⊆ c−1[T ]

⇒T = ∅

s ∈ S \ {l}T ⊆ ST ⊆ ({s} �− c) ∪ {l 7→ s})−1[T ]

`T = ∅

ALL L

. . . T ⊆ ST ⊆ c−1[T ]

⇒T = ∅

s ∈ S \ {l}T ⊆ ST ⊆ ({s} �− c) ∪ {l 7→ s})−1[T ]

`T = ∅

SET . . .

. . .

. . . T ⊆ ST ⊆ c−1[T ]

⇒T = ∅

s ∈ S \ {l}T ⊆ ST ⊆ ({s} �− c) ∪ {l 7→ s})−1[T ]T ⊆ c−1[T ]

`T = ∅

IMP L

. . .T = ∅s ∈ S \ {l}T ⊆ ST ⊆ ({s} �− c) ∪ {l 7→ s})−1[T ]T ⊆ c−1[T ]

`T = ∅

HYP

27

Page 29: 12. Routing Algorithm for Mobile Agent

Proof (cont’d) 28

- The key to this proof is the following lemma:

· · ·s ∈ S \ {l}T ⊆ ({s} �− c) ∪ {l 7→ s})−1[T ]

`T ⊆ c−1[T ]

Hint: Consider two cases successively, s ∈ T and s /∈ T .

28

Page 30: 12. Routing Algorithm for Mobile Agent

A More Concrete Situation 29

- The moves ofM are not completely instantaneous any more

- The traveling of messages between sites still takes no time

- The knowledge of the moves ofM is not instantaneous any more

29

Page 31: 12. Routing Algorithm for Mobile Agent

WhenM Departs from Site l 30

- Agents of l do not know whereM is going

- Agents of other sites are not aware of the move

- Messages at l cannot be forwarded until l knows whereM is

- Messages at other sites can be forwarded (in general)

30

Page 32: 12. Routing Algorithm for Mobile Agent

WhenM Arrives at its destination s (coming from l) 31

- It sends a “service message” to l to inform it about its new position

- Once l has received the “service message” it can forward

again communication messages which were pending

- From now on, we have to distinguish:

- communication messages (still instantaneous)

- service messages (which take some time)

31

Page 33: 12. Routing Algorithm for Mobile Agent

Initial Situation 32

ba

d c

32

Page 34: 12. Routing Algorithm for Mobile Agent

M moves from c to d 33

ba

d c

b

cd

a

M sends a service message to c: "I am now in d"

Site c suspend sending com. msg. until it knows whereM is

33

Page 35: 12. Routing Algorithm for Mobile Agent

M moves from d to a 34

ba

d c

b

c

b

c

a

dd

a

M sends a service message to d: "I am now in a"

Site d suspend sending com. msg. until it knows whereM is

34

Page 36: 12. Routing Algorithm for Mobile Agent

M moves from a to c 35

ba

d c

b

c

b

c

a

dd

a

d

a b

c

M sends a service message to a: "I am now in c"

Site a suspend sending com. msg. until it knows whereM is

35

Page 37: 12. Routing Algorithm for Mobile Agent

M moves from c to b 36

ba

d c

b

c

b

c

a

dd

a

d

a b b

c c

a

d

M sends a service message to c: "I am now in b"

Site c suspend sending com. msg. until it knows whereM is

36

Page 38: 12. Routing Algorithm for Mobile Agent

No Service Message has Arrived yet 37

ba

d c

37

Page 39: 12. Routing Algorithm for Mobile Agent

Service Message from a to d Arrives 38

b

cd

a

c

ba

d

Site d believesM is in a. It now forwards pending com. msg. to a

38

Page 40: 12. Routing Algorithm for Mobile Agent

Service Message from c to a Arrives 39

b

c

b

c

a

dd

a

c

ba

d

Site a believesM is in c. It now forwards pending com. msg. to c

39

Page 41: 12. Routing Algorithm for Mobile Agent

Service Message from b to c Arrives 40

b

c

b

c

a

dd

a

a

d

b

c

ba

d

c

Site c believesM is in b. It now forwards pending com. msg. to b

40

Page 42: 12. Routing Algorithm for Mobile Agent

Service Message from d to c Arrives. FAILURE 41

b

c

b

c

a

dd

a

a

d

b

c

b

a

d

a

d

b

cc

Site c believesM is in d. It now forwards pending com. msg. to d

The tree structure is destroyed: we have a CYCLE.

41

Page 43: 12. Routing Algorithm for Mobile Agent

Analysis of Failure and “magic” Solution 42

- The failure comes from the two srv. msg. arriving in the same place

- We must preclude this to happen

- We shall suppose that we have the following “magic” behavior

- WhenM sends a service message to site x

- It is able to remove all other pending service messages

whose destination is also x

42

Page 44: 12. Routing Algorithm for Mobile Agent

Initial Situation 43

ba

d c

43

Page 45: 12. Routing Algorithm for Mobile Agent

M moves from c to d 44

ba

d c

b

cd

a

M sends a service message to c: "I am now in d"

Site c suspend forwarding com. msg. until it believes whereM is

44

Page 46: 12. Routing Algorithm for Mobile Agent

M moves from d to a 45

ba

d c

b

c

b

c

a

dd

a

M sends a service message to d: "I am now in a"

Site d suspend forwarding com. msg. until it believes whereM is

45

Page 47: 12. Routing Algorithm for Mobile Agent

M moves from a to c 46

ba

d c

b

c

b

c

a

dd

a

d

a b

c

M sends a service message to a: "I am now in c"

Site a suspend forwarding com. msg. until it believes whereM is

46

Page 48: 12. Routing Algorithm for Mobile Agent

M moves from c to b 47

ba

d c

b

c

b

c

a

dd

a

d

a b b

c c

a

d

M sends a service message to c: "I am now in b"

M “magically” removes the other service message arriving to c

47

Page 49: 12. Routing Algorithm for Mobile Agent

First Refinement: the State (1) 48

variables: l, p, d, a, da

inv1 1: d ∈ S \ {l} 7→ S

inv1 2: a ∈ S \ {l} 7→ S

inv1 3: c = d �− a

- Variable d denotes the new dynamic tree structure

- Variable a denotes the service message channel.

- inv1 3 denotes the link between c and the concrete d and a

48

Page 50: 12. Routing Algorithm for Mobile Agent

More about the Service Channel a 49

inv1 2: a \ {l} ∈ S 7→ S

- s1 7→ s2 in a means a message from s2 (new site) to s1 (old site)

- Notice that the new site cannot be l

- At most one service message is in transit to site s1 (a is a function)

- This magic behavior is fundamental

49

Page 51: 12. Routing Algorithm for Mobile Agent

First Refinement: the State (2) 50

inv1 4: da ⊆ S

inv1 5: dom(a) = da \ {l}

- Variable da denotes the set of sites expecting a service message

- Such nodes cannot forward a message

50

Page 52: 12. Routing Algorithm for Mobile Agent

First Refinement: the Events (1) 51

dlv msgany m where

m ∈ dom(p)p(m) /∈ dap(m) = l

thenp := {m} �− p

end

fwd msgany m where

m ∈ dom(p)p(m) /∈ dap(m) 6= l

thenp(m) := d(p(m))

end

- The guards are now local

- We can later data-refine da with a local boolean variable

51

Page 53: 12. Routing Algorithm for Mobile Agent

First Refinement: the Events (3) 52

leave agtwhen

l /∈ dathen

da := da ∪ {l}end

rcv agtany s where

s ∈ S \ {l}l ∈ da

thenl := sa := (s �− a) �− (l 7→ s)d := {s} �− dda := da \ {s}

end

- Event leave agt is a new event where the set da is extended

- In event rcv agt, the new site location s is removed from da

- A previous service message to l is removed.

52

Page 54: 12. Routing Algorithm for Mobile Agent

First Refinement: the Events (2) 53

rcv srvany s where

s ∈ dom(a)s 6= l

thend(s) := a(s)a := {s} �− ada := da \ {s}

end

- This is a new event

- It corresponds to the arrival of the service message

53

Page 55: 12. Routing Algorithm for Mobile Agent

Second Refinement: Implementing the “magic” srv. channel 54

- Magic behavior when sending a new service message to x:

- Pending service messages to x are removed

- The mobileM travels with a logical clock

- Each site has a last time counter

- This counter records the “time” of the last visit ofM

54

Page 56: 12. Routing Algorithm for Mobile Agent

Implementing the “magic” service channel (cont’d) 55

- WhenM arrives at a site y

- it increments its logical clock

- it stores its incremented clock in the last time counter of y

- it sends a new service message to its previous location x

- The srv. msg. from y to x is stamped with the new clock value

- When a service message arrives at a site x, it is accepted

- only if its stamp value is greater than the time counter of x

- the last time counter takes the value of the stamp

55

Page 57: 12. Routing Algorithm for Mobile Agent

Initial Situation 56

00

0 1

56

Page 58: 12. Routing Algorithm for Mobile Agent

M moves from c to d 57

00

0 1 12

0 00

2

57

Page 59: 12. Routing Algorithm for Mobile Agent

M moves from d to a 58

00

0 1 12

0 00 3

1

0

22

3

2

58

Page 60: 12. Routing Algorithm for Mobile Agent

M moves from a to c 59

00

0 1 12

0 00 3

1

0

4

2

2

3 0

2

3

2

3

2

4

59

Page 61: 12. Routing Algorithm for Mobile Agent

M moves from c to b 60

00

0 1 12

0 00 3

1

0

4

2

2

3 0 5

42

3

2

3

2

3

2

4 3 4 5

2

60

Page 62: 12. Routing Algorithm for Mobile Agent

No Service Message has yet Arrived 61

53

2 42

3 4 5

61

Page 63: 12. Routing Algorithm for Mobile Agent

Service Message from a to d Arrives 62

53

2 42

3 4 5

2

4 5

53

3 4

- It is accepted

62

Page 64: 12. Routing Algorithm for Mobile Agent

Service Message from c to a Arrives 63

53

2 42

3 4 5

2

4 5

53

3 4

54

3 42

5

- It is accepted

63

Page 65: 12. Routing Algorithm for Mobile Agent

Service Message from b to c Arrives 64

53

2 42

3 4 5

2

4 5

53

3 4

54

3 42

5

5

52

3

4

- It is accepted

64

Page 66: 12. Routing Algorithm for Mobile Agent

Service Message from d to c Arrives. NO FAILURE 65

53

2 42

3 4 5

2

4 5

53

3 4

54

3 42

5

5

52

3

4 5

5

4

3

- It is rejected

65

Page 67: 12. Routing Algorithm for Mobile Agent

Structure of the New Service Channel 66

- Suppose:

- s1 has emitted a service msg. to s at time 3

- s2 has emitted a service msg. to s at time 5

- s3 has emitted a service msg. to s at time 9

- This will be “recorded” in the refined service channel as follows:

s 7→ {3 7→ s1, 5 7→ s2, 9 7→ s3}

- In the abstract service channel we had: s 7→ s3

66

Page 68: 12. Routing Algorithm for Mobile Agent

Second Refinement: the State 67

variables: l, p, d, da,k, t, b

inv2 1: k ∈ N

inv2 2: t ∈ S → N

inv2 3: b ∈ S → (N 7→ S)

- Variable k is the clock taken by the Mobile when it travels

- Variable t denotes the time of the last visit of the Mobile to a site

- Variable b is the new service channel, it data-refines variable a

67

Page 69: 12. Routing Algorithm for Mobile Agent

Connecting the Abstract a and the Concrete b (1) 68

- An abstract service message is the most recent concrete one

inv2 4: ∀s ·

s ∈ dom(a)

⇒dom(b(s)) 6= ∅a(s) = b(s)(max(dom(b(s))))

68

Page 70: 12. Routing Algorithm for Mobile Agent

Connecting the Abstract a and the Concrete b (2) 69

inv2 5: ∀s ·

s ∈ Sdom(b(s)) 6= ∅t(s) < max(dom(b(s)))

⇒s ∈ dom(a)

- This technical invariant will help us proving guard strengthening

for event rcv srv

69

Page 71: 12. Routing Algorithm for Mobile Agent

More Invariants Between k and t 70

inv2 6: ∀s · s ∈ S ⇒ dom(b(s)) ⊆ 0 .. k

inv2 7: t(l) = k

inv2 8: ∀s · s ∈ S \ {l} ⇒ t(s) ≤ k

70

Page 72: 12. Routing Algorithm for Mobile Agent

The Key Invariant 71

- The only service message stamp to a site s which is strictly greater

than the time of last visit to that site s is the maximum one.

inv2 9: ∀ s, n ·

s ∈ Sn ∈ dom(b(s))t(s) < n

⇒n = max(dom(b(s)))

71

Page 73: 12. Routing Algorithm for Mobile Agent

Second Refinement: the Events (1) 72

- Sending the service message with the time stamp k + 1

(abstract-)rcv agtany s where

s ∈ S \ {l}l ∈ da

thenl := sa := (s �− a) �− (l 7→ s)d := {s} �− dda := da \ {s}

end

(concrete-)rcv agtany s where

s ∈ S \ {l}l ∈ da

thenl := st(s) := k + 1k := k + 1b(l) := b(l) �− {k + 1 7→ s}d := {s} �− dda := da \ {s}

end

72

Page 74: 12. Routing Algorithm for Mobile Agent

Second Refinement: the Events (2) 73

(abstract-)rcv srvany s where

s ∈ dom(a)s 6= l

thend(s) := a(s)a := {s} �− ada := da \ {s}

end

(concrete-)rcv srvany s, n where

s ∈ Sn ∈ dom(b(s))t(s) < n

thend(s) := b(s)(n)t(s) := nda := da \ {s}b(s) := {n} �− b(s)

end

∀s ·s ∈ Sdom(b(s)) 6= ∅t(s) < max(dom(b(s)))

⇒s ∈ dom(a)

∀ s, n ·

s ∈ Sn ∈ dom(b(s))t(s) < n

⇒n = max(dom(b(s)))

73

Page 75: 12. Routing Algorithm for Mobile Agent

Third Refinement: Data-refinement of Variables da 74

variables: l, p, d, b,dab, k, t

inv3 1: dab ∈ S → BOOL

inv3 3: ∀x · x ∈ S ⇒ (x ∈ da ⇔ dab(x) = TRUE)

74

Page 76: 12. Routing Algorithm for Mobile Agent

Third Refinement: The Events (1) 75

initl := ilp := ∅d := (S \ {il}) × {il}b := S × {∅}dab := S × {FALSE}k := 1t := S × {0} �− {il 7→ 1}

leave agtwhen

dab(l) = FALSEthen

dab(l) := TRUEend

75

Page 77: 12. Routing Algorithm for Mobile Agent

Third Refinement: The Events (2) 76

rcv agtany s where

s ∈ S \ {l}dab(l) = TRUE

thenl := st(s) := k + 1k := k + 1b(l) := b(l) �− {k + 1 7→ s}d := {s} �− ddab(s) := FALSE

end

rcv srvany s, n where

s ∈ Sn ∈ dom(b(s))t(s) < n

thend(s) := b(s)(n)t(s) := ndab(s) := FALSE

end

76

Page 78: 12. Routing Algorithm for Mobile Agent

Third Refinement: The Events (3) 77

dlv msgany m where

m ∈ dom(p)dab(p(m)) = FALSEp(m) = l

thenp := {m} �− p

end

fwd msgany m where

m ∈ dom(p)dab(p(m)) = FALSEp(m) 6= l

thenp(m) := d(p(m))

end

77

Page 79: 12. Routing Algorithm for Mobile Agent

Summary of Proofs 78

Initial Model 11 0

1st Reft. 23 2

2nd Reft. 70 14

3rd Reft. 25 0

Total 129 16

78