Signaling and Network Control

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
Amr Talaat
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
Amr Talaat
Example: EFTPOS System (STD of an
FSM)
Initial
1 digit
d1
1 digit
d2
1 digit
d3
1 digit
d4
OK
OK
OK
OK
Rejected
Initial state
OK
OK
pressed
Reject
Approved
Final state
3/47
Amr Talaat
Example: EFTPOS System (A Petri net)
1 digit
Initial
1 digit
d1
1 digit
d2
1 digit
d4
d3
OK
OK
OK
OK
OK
OK
pressed
Rejected!
Reject
approve
approved
4/47
Amr Talaat
Petri Net Example
Arc
Arc with w=1
Transition 0
Place
Place 0
Place 1
Token
Transition
Transition 1


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
Amr Talaat
EFTPOS System


Scenario 1: Normal
 Enters all 4 digits and press OK.
Scenario 2: Exceptional
 Enters only 3 digits and press OK.
6/47
Amr Talaat
Example: EFTPOS System (Token Games)
1 digit
Initial
1 digit
d1
1 digit
d2
1 digit
d4
d3
OK
OK
OK
OK
OK
pressed
Rejected!
Reject
approve
approved
7/47
Amr Talaat
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
Amr Talaat
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
Amr Talaat
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
Amr Talaat
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
Amr Talaat
Example: Vending Machine (STD of an FSM)
Take 15c snack bar
5 cents
Deposit 10c
15 cents
0 cent
10 cents
Deposit 10c
20 cents
Take 20c snack bar
12/47
Amr Talaat
Modeling FSMs
vend 15¢ candy
5
10
5
5
0
10
10
15
5
5
10
20
vend 20¢ candy
13/47
Amr Talaat
Modeling FSMs
vend 15¢ candy
10
5
5
5
10
state machines:
each transition
5 has exactly
one input and
one output
10
vend 20¢ candy
14/47
Amr Talaat
Example: Vending Machine (A Petri net)
Take 15c bar
Deposit 10c
5c
15c
Deposit 5c
0c
Deposit
5c
Deposit
5c
Deposit 10c
10c
Deposit
5c
20c
Deposit 10c
Take 20c bar
15/47
Amr Talaat
Example: Vending Machine (3 Scenarios)



Scenario 1:
 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
Amr Talaat
Example: Vending Machine (Token Games)
Take 15c bar
Deposit 10c
5c
15c
Deposit 5c
0c
Deposit
5c
Deposit
5c
Deposit 10c
10c
Deposit
5c
20c
Deposit 10c
Take 20c bar
17/47
Amr Talaat
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
Amr Talaat
Example: In a Restaurant (A Petri Net)
Waiter
free
Customer 1
Customer 2
Take
order
Take
order
wait
Order
taken
wait
eating
eating
Serve food
Tell
kitchen
Serve food
19/47
Amr Talaat
Example: In a Restaurant (Two Scenarios)


Scenario 1:
 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
Amr Talaat
Example: In a Restaurant (Scenario 1)
Waiter
free
Customer 1
Customer 2
Take
order
Take
order
wait
Order
taken
wait
eating
eating
Serve food
Tell
kitchen
Serve food
21/47
Amr Talaat
Example: In a Restaurant (Scenario 2)
Waiter
free
Customer 1
Customer 2
Take
order
Take
order
wait
Order
taken
wait
eating
eating
Serve food
Tell
kitchen
Serve food
22/47
Amr Talaat
Net Structures

A sequence of events/actions:
e1

e2
e3
e2
e3
e4
e5
Concurrent executions:
e1
23/47
Amr Talaat
Net Structures

Non-deterministic events - conflict, choice or decision: A choice of
either e1, e2 … or e3, e4 ...
e1
e2
e3
e4
24/47
Amr Talaat
Net Structures

Synchronization
e1
25/47
Amr Talaat
Net Structures

Synchronization and Concurrency
e1
26/47
Amr Talaat
Modeling communication
protocols
ready
to send
ready
to receive
buffer
full
send
msg.
wait
for ack.
proc.1
receive
ack.
receive
msg.
send
ack.
buffer
full
ack.
received
proc.2
msg.
received
ack.
sent
28/47
Amr Talaat
Modeling Protocols Using Petri
Nets (Stop and Wait Protocol)

Transmitter
Receiver
Timer

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

29/47
Amr Talaat
Stop and Wait Protocol: Normal
Operation
pkt 0
Get Pkt 0
Send Pkt 0
Ack 0
Wait Ptk 1
Wait Ack 0
pkt 1
Get Pkt 1
Ack 1
Wait Pkt 0
Send Pkt 1
Wait Ack 1
Transmitter State
Channel State
Receiver State
30/47
Amr Talaat
Stop and Wait Protocol: Normal
Operation
pkt 0
Get Pkt 0
Send Pkt 0
Ack 0
Wait Ptk 1
Wait Ack 0
pkt 1
Get Pkt 1
Ack 1
Wait Pkt 0
Send Pkt 1
Wait Ack 1
Transmitter State
Channel State
Receiver State
31/47
Amr Talaat
Stop and Wait Protocol:
Deadlock
pkt 0
Get Pkt 0
Send Pkt 0
loss
Ack 0
Wait Ptk 1
Wait Ack 0
loss
pkt 1
Get Pkt 1
Ack 1
Wait Pkt 0
Send Pkt 1
Wait Ack 1
loss
loss
Transmitter State
Channel State
Receiver State
32/47
Stop and Wait Protocol:
Deadlock Avoidance Using
pkt 0
Timers
Amr Talaat
Get Pkt 0
Send Pkt 0
loss
Wait Ack 0
Ack 0
Wait Ptk 1
timer
loss
pkt 1
Get Pkt 1
Ack 1
Wait Pkt 0
Send Pkt 1
timer
Wait Ack 1
loss
loss
Transmitter State
Channel State
Receiver State
33/47
Amr Talaat
Stop and Wait Protocol: Loss of
Acknowledgements
pkt 0
Get Pkt 0
Send Pkt 0
loss
Wait Ack 0
Ack 0
Reject 0
Wait Ptk 1
timer
loss
pkt 1
Get Pkt 1
Send Pkt 1
timer
Wait Ack 1
loss
Ack 1
Reject 1
Wait Pkt 0
loss
Transmitter State
Channel State
Receiver State
34/47
Amr Talaat
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
Amr Talaat
Recalling the Vending Machine (Token Game)
Take 15c bar
Deposit 10c
5c
15c
Deposit 5c
0c
Deposit
5c
Deposit
5c
Deposit 10c
10c
Deposit
5c
20c
Deposit 10c
Take 20c bar
36/47
Amr Talaat
A marking is a state ...
t8
p4
t4
p2
t1
p1
t3
t5
t7
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)
Initial marking:M0
t6
t2
p5
p3
t9
37/47
Amr Talaat
Reachability
t8
p4
t4
M0 = (1,0,0,0,0)
p2
M1 = (0,1,0,0,0)
t1
M2 = (0,0,1,0,0)
p1
t3
t7
t5
p3
M4 = (0,0,0,0,1)
t6
t2
M3 = (0,0,0,1,0)
p5
Initial marking:M0
t9
M0
t1
M1
t3
M2
t5
M3
t8
M0
t2
M2
t6
M4
38/47
Amr Talaat
Reachability
A firing or occurrence sequence:
M0
•
•
t1
M1
t3
M2
t5
M3
t8
M0
t2
M2
t6
M4
“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
Amr Talaat
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
Amr Talaat
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
Amr Talaat
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
Amr Talaat
An Example
t1
p3
p2
p1
t2
t3
t4
p4
M0 = (1,0,0,1)
M1 = (0,1,0,1)
M2 = (0,0,1,0)
M3 = (0,0,0,1)
A bounded but non-live Petri net
43/47
Amr Talaat
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
Amr Talaat
Coverability tree example
M0=(100)
t3
p2
t2
p1
t1
t0
p3
45/47
Amr Talaat
Coverability tree example
M0=(100)
t1
t3
p2
t2
p1
t1
M1=(001)
“dead end”
t0
p3
46/47
Amr Talaat
Coverability tree example
M0=(100)
t1
t3
p2
t2
p1
t1
M1=(001)
“dead end”
t3
M3=(10)
t0
p3
47/47
Amr Talaat
Coverability tree example
M0=(100)
t1
t3
p2
p1
t1
M1=(001)
“dead end”
t0
t3
M3=(10)
t1
M4=(01)
t2
p3
48/47
Amr Talaat
Coverability tree example
M0=(100)
t1
t3
p2
p1
t1
M1=(001)
“dead end”
t0
t3
M3=(10)
t1
M4=(01)
t2
p3
t3
M3=(10)
“old”
49/47
Amr Talaat
Coverability tree example
M0=(100)
t1
t3
p2
p1
t1
t3
M1=(001)
“dead end”
t0
M3=(10)
t1
M4=(01)
t2
p3
t2
t3
M6=(10)
“old”
M5=(01)
“old”
50/47
Amr Talaat
Coverability tree example
M0=(100)
100
t1
t1
t3
001
M1=(001)
“dead end”
10
t1
t2
t3
01
t3
M3=(10)
t1
M4=(01)
t2
t3
M6=(10)
“old”
M5=(01)
“old”
coverability graph
coverability tree
51/47
Amr Talaat

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
Amr Talaat
-2 1 1 0
1 -1 0 -2
1 0 -1 2
1 -1 0 -2
0 1 -1 4
0000
55/47