Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Eng Amr T. Abdel-Hamid

Similar presentations


Presentation on theme: "Dr. Eng Amr T. Abdel-Hamid"— Presentation transcript:

1 Dr. Eng Amr T. Abdel-Hamid
NETW 703 Network Protocols Petri Nets Dr. Eng Amr T. Abdel-Hamid Spring 2008 Based on lectures from: * Dr Chris Ling, School of Computer Science & Software Engineering Monash University * Claus Reinke, Computing Lab, UKC

2 Introduction First introduced by Carl Adam Petri in 1962.
A diagrammatic tool to model concurrency and synchronization in distributed systems. Very similar to FSMs. Used as a visual communication aid to model the system behaviour. Based on strong mathematical foundation. 2/47

3 Example: EFTPOS System (STD of an FSM)
Initial 1 digit d1 d2 d3 d4 OK pressed approve Approved Rejected Initial state Final state Reject 3/47

4 Example: EFTPOS System (A Petri net)
Initial 1 digit d1 d2 d3 d4 OK pressed approve approved Reject Rejected! 4/47

5 Petri Net Example Arc with w=1 Arc Place Token Transition
I(tj) = {pi P : (pi, tj) A} O(tj) = {pi P : (tj, pi) A} I(pi) ={tj T : (tj, pi) A} O(pi) ={tj T : (pi, tj) A} 5/47

6 EFTPOS System Scenario 1: Normal Enters all 4 digits and press OK.
Scenario 2: Exceptional Enters only 3 digits and press OK. 6/47

7 Example: EFTPOS System (Token Games)
Initial 1 digit d1 d2 d3 d4 OK pressed approve approved Reject Rejected! 7/47

8 A Petri Net Specification ...
consists of three types of components: places (circles), transitions (rectangles) and arcs (arrows): Places represent possible states of the system. Transitions are events or actions which cause the change of state. Every arc simply connects a place with a transition or a transition with a place. 8/47

9 A Change of State … is denoted by a movement of token(s) (black dots) from place(s) to place(s); and is caused by the firing of a transition. The firing represents an occurrence of the event or an action taken. The firing is subject to the input conditions, denoted by token availability. 9/47

10 A Change of State A transition is firable or enabled when there are sufficient tokens in its input places. After firing, tokens will be transferred from the input places (old state) to the output places, denoting the new state. Note that the EFTPOS example is a Petri net representation of a finite state machine (FSM). 10/47

11 Example: Vending Machine
The machine dispenses two kinds of snack bars – 20c and 15c. Only two types of coins can be used – 10c coins and 5c coins. The machine does not return any change. 11/47

12 Example: Vending Machine (STD of an FSM)
0 cent 5 cents 10 cents 15 cents 20 cents Deposit 5c Deposit 10c Take 20c snack bar Take 15c snack bar 12/47

13 Modeling FSMs vend 15¢ candy 10 15 5 5 5 5 5 10 10 20 10
5 10 10 20 10 vend 20¢ candy 13/47

14 Modeling FSMs state machines: each transition has exactly
vend 15¢ candy 10 5 state machines: each transition has exactly one input and one output 5 5 5 10 10 vend 20¢ candy 14/47

15 Example: Vending Machine (A Petri net)
Take 15c bar Deposit 5c 0c Deposit 10c Deposit c 10c Deposit 20c 15c Take 20c bar 15/47

16 Example: Vending Machine (3 Scenarios)
Deposit 5c, deposit 5c, deposit 5c, deposit 5c, take 20c snack bar. Scenario 2: Deposit 10c, deposit 5c, take 15c snack bar. Scenario 3: Deposit 5c, deposit 10c, deposit 5c, take 20c snack bar. 16/47

17 Example: Vending Machine (Token Games)
Take 15c bar Deposit 5c 0c Deposit 10c Deposit c 10c Deposit 20c 15c Take 20c bar 17/47

18 Multiple Local States In the real world, events happen at the same time. A system may have many local states to form a global state. There is a need to model concurrency and synchronization. 18/47

19 Example: In a Restaurant (A Petri Net)
Waiter free Customer 1 Customer 2 Take order Take order wait Order taken wait eating eating Tell kitchen Serve food Serve food 19/47

20 Example: In a Restaurant (Two Scenarios)
Waiter takes order from customer 1; serves customer 1; takes order from customer 2; serves customer 2. Scenario 2: Waiter takes order from customer 1; takes order from customer 2; serves customer 2; serves customer 1. 20/47

21 Example: In a Restaurant (Scenario 1)
Waiter free Customer 1 Customer 2 Take order Take order wait Order taken wait eating eating Tell kitchen Serve food Serve food 21/47

22 Example: In a Restaurant (Scenario 2)
Waiter free Customer 1 Customer 2 Take order Order taken Tell kitchen wait Serve food eating 22/47

23 Net Structures A sequence of events/actions: Concurrent executions: e1
23/47

24 Net Structures Non-deterministic events - conflict, choice or decision: A choice of either e1, e2 … or e3, e4 ... e1 e2 e3 e4 24/47

25 Net Structures Synchronization e1 25/47

26 Net Structures Synchronization and Concurrency e1 26/47

27 Modeling communication protocols
ready to send ready to receive buffer full send msg. receive msg. wait for ack. proc.2 proc.1 msg. received receive ack. send ack. buffer full ack. received ack. sent 28/47

28 Modeling Protocols Using Petri Nets (Stop and Wait Protocol)
The transmitter sends a frame and stops waiting for an acknowledgement from the receiver (ACK) Once the receiver correctly receives the expected packet, it sends an acknowledgement to let the transmitter send the next frame. When the transmitter does not receive an ACK within a specified period of time (timer) then it retransmits the packet. Timer Transmitter Receiver Frame 0 Frame 1 ACK 0 ACK 1 29/47

29 Stop and Wait Protocol: Normal Operation
Ack 1 pkt 0 Ack 0 pkt 1 Get Pkt 0 Get Pkt 1 Send Pkt 0 Send Pkt 1 Wait Ptk 1 Wait Pkt 0 Wait Ack 0 Wait Ack 1 Transmitter State Receiver State 30/47 Channel State

30 Stop and Wait Protocol: Normal Operation
Ack 1 pkt 0 Ack 0 pkt 1 Get Pkt 0 Get Pkt 1 Send Pkt 0 Send Pkt 1 Wait Ptk 1 Wait Pkt 0 Wait Ack 0 Wait Ack 1 Transmitter State Receiver State 31/47 Channel State

31 Stop and Wait Protocol: Deadlock
Ack 1 pkt 0 Ack 0 pkt 1 Get Pkt 0 Get Pkt 1 Send Pkt 0 Send Pkt 1 loss Wait Ptk 1 Wait Pkt 0 Wait Ack 0 Wait Ack 1 Transmitter State Receiver State 32/47 Channel State

32 Stop and Wait Protocol: Deadlock Avoidance Using Timers
Ack 1 pkt 0 Ack 0 pkt 1 Get Pkt 0 Get Pkt 1 Send Pkt 0 Send Pkt 1 loss timer Wait Ptk 1 Wait Pkt 0 Wait Ack 0 Wait Ack 1 timer Transmitter State Receiver State 33/47 Channel State

33 Stop and Wait Protocol: Loss of Acknowledgements
pkt 0 Ack 0 pkt 1 Get Pkt 0 Get Pkt 1 Send Pkt 0 Send Pkt 1 loss Reject 0 timer Wait Ptk 1 Wait Pkt 0 Wait Ack 0 Wait Ack 1 timer Reject 1 Transmitter State Receiver State 34/47 Channel State

34 Behavioural Properties
Reachability “Can we reach one particular state from another?” Boundedness “Will a storage place overflow?” Liveness “Will the system die in a particular state?” 35/47

35 Recalling the Vending Machine (Token Game)
Take 15c bar Deposit 5c 0c Deposit 10c Deposit c 10c Deposit 20c 15c Take 20c bar 36/47

36 A marking is a state ... M0 = (1,0,0,0,0) M1 = (0,1,0,0,0)
p4 M0 = (1,0,0,0,0) t4 M1 = (0,1,0,0,0) p2 t1 M2 = (0,0,1,0,0) M3 = (0,0,0,1,0) p1 M4 = (0,0,0,0,1) t3 t7 t5 Initial marking:M0 t6 p5 t2 p3 t9 37/47

37 Reachability p1 t8 t1 t2 p2 t3 p3 t4 t5 t6 p5 t7 p4 t9
Initial marking:M0 M0 = (1,0,0,0,0) M1 = (0,1,0,0,0) M2 = (0,0,1,0,0) M3 = (0,0,0,1,0) M4 = (0,0,0,0,1) M0 M1 M2 M3 M4 t3 t1 t5 t8 t2 t6 38/47

38 Reachability A firing or occurrence sequence:
M0 M1 M2 M3 M4 t3 t1 t5 t8 t2 t6 A firing or occurrence sequence: “M2 is reachable from M1 and M4 is reachable from M0.” In fact, in the vending machine example, all markings are reachable from every marking. 39/47

39 Boundedness A Petri net is said to be k-bounded or simply bounded if the number of tokens in each place does not exceed a finite number k for any marking reachable from M0. The Petri net for vending machine is 1-bounded. A 1-bounded Petri net is safe. 40/47

40 Liveness A Petri net with initial marking M0 is live if, no matter what marking has been reached from M0, it is possible to ultimately fire any transition by progressing through some further firing sequence. A live Petri net guarantees deadlock-free operation, no matter what firing sequence is chosen. 41/47

41 Liveness The vending machine is live and the producer-consumer system is also live. A transition is dead if it can never be fired in any firing sequence. 42/47

42 An Example A bounded but non-live Petri net t1 p3 t3 t4 p1 p2 p4 t2
43/47

43 Analysis methods (1) Coverability tree
tree representation of all possible markings root = M0 nodes = markings reachable from M0 arcs = transition firings if net is unbounded, then tree is kept finite by introducing the symbol  Properties a PN is bounded iff  doesn’t appear in any node a PN is safe iff only 0’s and 1’s appear in nodes a transition is dead iff it doesn’t appear in any arc if M is reachable form M0, then exists a node M’ that covers M 44/47

44 Coverability tree example
45/47

45 Coverability tree example
“dead end” p2 t1 t0 t2 p3 46/47

46 Coverability tree example
“dead end” M3=(10) p2 t1 t0 t2 p3 47/47

47 Coverability tree example
“dead end” M3=(10) t1 p2 t1 t0 M4=(01) t2 p3 48/47

48 Coverability tree example
“dead end” M3=(10) t1 t3 p2 t1 t0 M4=(01) M3=(10) “old” t2 p3 49/47

49 Coverability tree example
“dead end” M3=(10) t1 t3 p2 t1 t0 M4=(01) M6=(10) “old” t2 t2 p3 M5=(01) “old” 50/47

50 Coverability tree example
100 t1 t3 t1 t3 M1=(001) “dead end” M3=(10) 001 10 t1 t3 t1 t3 M4=(01) M6=(10) “old” 01 t2 t2 M5=(01) “old” coverability graph coverability tree 51/47

51 For a petrinet to be Rechable (Cr = m) r is the rank of C
x is n x 1 column vector of nonnegative integers and is called the firing count vector For a petrinet to be Rechable (Cr = m) r is the rank of C 54/47

52 55/47


Download ppt "Dr. Eng Amr T. Abdel-Hamid"

Similar presentations


Ads by Google