coloured petri nets modelling and validation of concurrent systems

61
Kurt Jensen Lars M. Kristensen 1 Coloured Petri Nets Department of Computer Science Coloured Petri Nets Modelling and Validation of Concurrent Systems Chapter 5: Hierarchical Coloured Petri Nets Kurt Jensen & Lars Michael Kristensen {kjensen,lmkristensen} @cs.au.dk Receiver Network Sender Packets To Send NOxDATA C NO D NO A NOxDATA Data Received "" DATA B NOxDATA Sender Network Receiver 6 1`(1,"COL")++ 1`(2,"OUR")++ 1`(3,"ED ")++ 1`(4,"PET")++ 1`(5,"RI ")++ 1`(6,"NET") 1 1`(1,"COL") 1 1`""

Upload: maya-lamb

Post on 02-Jan-2016

34 views

Category:

Documents


2 download

DESCRIPTION

Chapter 5: Hierarchical Coloured Petri Nets. Coloured Petri Nets Modelling and Validation of Concurrent Systems. Kurt Jensen & Lars Michael Kristensen {kjensen,lmkristensen} @cs.au.dk. CPN models can be divided into modules. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

1

Coloured Petri NetsDepartment of Computer Science

Coloured Petri NetsModelling and Validation of Concurrent Systems

Chapter 5: Hierarchical Coloured Petri Nets

Kurt Jensen &Lars Michael Kristensen

{kjensen,lmkristensen}@cs.au.dk

Receiver

Receiver

Network

Network

Sender

Sender

PacketsTo Send

AllPackets

NOxDATA

C

NO

D

NO

A

NOxDATA

DataReceived

""

DATA

B

NOxDATA

Sender Network Receiver

6

1`(1,"COL")++1`(2,"OUR")++1`(3,"ED ")++1`(4,"PET")++1`(5,"RI ")++1`(6,"NET")

1 1`(1,"COL")

11`""

Page 2: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

2

Coloured Petri NetsDepartment of Computer Science

CPN models can be divided into modules

CPN modules play a similar role as modules in ordinary programming languages.

They allow the model to be split intomanageable parts with well-defined interfaces.

CPN nets with modules are also calledhierarchical Coloured Petri Nets.

Page 3: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

3

Coloured Petri NetsDepartment of Computer Science

Why do we need modules?

There are often system components that are used repeatedly. Inefficient to model these components several times. Instead we define a module, and use the module repeatedly. In this way there is only one description to read, and one

description to modify when changes are necessary.

Impractical to draw a CPN model of a large system as a single net. Would become very large and unhandy. Could be printed on separate sheets and glued together,

but it would be difficult to get an overview and make a nice layout.

The human modeller needs abstractions that make it possible toconcentrate on only a few details at a time. CPN modules can be seen as black-boxes, where the modeller

(when desired) can forget about the details within the modules. This makes it possible to work at different abstraction levels.

Page 4: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

4

Coloured Petri NetsDepartment of Computer Science

Simple protocol

data

n if successthen 1`nelse empty

n

if n=kthen k+1else k

(n,d)(n,d)

nif n=k then data^delse data

(n,d)

if successthen 1`(n,d)else empty

(n,d)

ReceiveAck

TransmitAck

ReceivePacket

TransmitPacket

SendPacket

1`1

NO

CD

NO

A

NOxDATA

NextSend

1`1

NO

DataReceived

1`""

DATA

B

NOxDATA

PacketsTo Send

AllPackets

NOxDATA

k n

NextRec

k

if n=kthen k+1else k

NO

1 1`1

11`""6

1`(1,"COL")++1`(2,"OUR")++1`(3,"ED ")++1`(4,"PET")++1`(5,"RI ")++1`(6,"NET")

11`1

Sender Network Receiver

The protocol model can be divided into three modules: Sender. Network. Receiver.

We “cut” the model into three parts: Using the buffer

places as interfaces between the modules.

Page 5: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

5

Coloured Petri NetsDepartment of Computer Science

Sender module

(n,d)

n

(n,d)

n

SendPacket

A Out

NOxDATA

D In

NO

NextSend

1`1

NO

AllPackets

NOxDATA

In

Out

PacketsTo Send

I/OI/O

ReceiveAck

k n

Input portUsed to import tokens from the environment

Output portUsed to export tokens to the environment

Input/output portUsed to import and export tokens

Internal placeLocal to themodule

The module interacts with other modules via three port places.

Page 6: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

6

Coloured Petri NetsDepartment of Computer Science

Receiver module

(n,d)

if n=k then data^delse data

k

data

ReceivePacket

COut

NO

BIn

NOxDATA

""

DATA

1`1

NO

In

Out

if n=kthen k+1else k

NextRec

DataReceived

I/OI/O

if n=kthen k+1else k

Input portUsed to import tokens from the environment

Output portUsed to export tokens to the environment

Input/output portUsed to import andexport tokens

Internal placeLocal to the module

Page 7: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

7

Coloured Petri NetsDepartment of Computer Science

Network module

n

if successthen 1`(n,d)else empty(n,d)

TransmitAck

TransmitPacket

C In

NO

B Out

NOxDATA

DOut

NO

AIn

NOxDATA

In

Out

Out

Inif successthen 1`nelse empty

Input port

Input port

Output port

Output port

Interaction with the sender

Interaction with the receiver

Page 8: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

8

Coloured Petri NetsDepartment of Computer Science

Receiver

Receiver

Network

Network

Sender

Sender

PacketsTo Send

AllPackets

NOxDATA

C

NO

D

NO

A

NOxDATA

DataReceived

""

DATA

B

NOxDATA

Sender Network Receiver

Protocol module Provides a more abstract view of the protocol system. “Glues” the three other modules together.

Three substitution transitions referring to three different modules.

Name of substitution transition

Name of submodule

Page 9: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

9

Coloured Petri NetsDepartment of Computer Science

Protocol module

Receiver

Receiver

Network

Network

Sender

Sender

AllPackets

NOxDATA

C

NO

D

NO

A

NOxDATA

DataReceived

""

B

NOxDATA

Sender Network Receiver

DATA

PacketsTo Send

Sender

(n,d)

n

(n,d)

n

SendPacket A Out

NOxDATA

D In

NO

NextSend

1`1

NO

AllPackets

NOxDATA

In

Out

PacketsTo SendI/OI/O

ReceiveAck

k n

(n,d)

if n=k then data^delse data

k

data

ReceivePacket

COut

NO

BIn

NOxDATA

""

DATA

1`1

NO

In

Out

if n=kthen k+1else k

NextRec

DataReceived

I/OI/O

if n=kthen k+1else k

n

if successthen 1`(n,d)else empty(n,d)

TransmitAck

TransmitPacket

C In

NO

B Out

NOxDATA

DOut

NO

AIn

NOxDATA

In

Out

Out

Inif successthen 1`nelse empty

Network Receiver

Page 10: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

10

Coloured Petri NetsDepartment of Computer Science

Receiver

Receiver

Network

Network

Sender

Sender

PacketsTo Send

AllPackets

NOxDATA

C

NO

D

NO

A

NOxDATA

DataReceived

""

DATA

B

NOxDATA

Sender Network Receiver

Protocol module

Input socket for Network substitution transitionOutput socket for Sender substitution transition

The places surrounding substitution transitions are socket places. They constitute the interface for the substitution transition.

Input/output socketfor Sender substitutiontransition

Page 11: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

11

Coloured Petri NetsDepartment of Computer Science

Port-socket relation The interfaces must be related to each other.

Each port place of a submodule is related to a socket place of its substitution transition: input port input socket. output port output socket. input/output port input/output socket.

Ports and sockets that are related to each other constitute different views of a single compound place. They have the same marking. When a token is added/removed at one of them it is also

added/removed at the other. Also the colour sets and initial markings are identical.

For the protocol system ports and sockets have identical names, but this is not required in general.

Page 12: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

12

Coloured Petri NetsDepartment of Computer Science

Receiver

Receiver

Network

Network

Sender

Sender

AllPackets

NOxDATA

C

NO

D

NO

A

NOxDATA

DataReceived

""

B

NOxDATA

Sender Network Receiver

DATA

PacketsTo Send

Sender

(n,d)

n

(n,d)

n

SendPacket A Out

NOxDATA

D In

NO

NextSend

1`1

NO

AllPackets

NOxDATA

In

Out

PacketsTo SendI/OI/O

ReceiveAck

k n

(n,d)

if n=k then data^delse data

k

data

ReceivePacket

COut

NO

BIn

NOxDATA

""

DATA

1`1

NO

In

Out

if n=kthen k+1else k

NextRec

DataReceived

I/OI/O

if n=kthen k+1else k

n

if successthen 1`(n,d)else empty(n,d)

TransmitAck

TransmitPacket

C In

NO

B Out

NOxDATA

DOut

NO

AIn

NOxDATA

In

Out

Out

Inif successthen 1`nelse empty

Network Receiver

Port-socket relation

Page 13: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

13

Coloured Petri NetsDepartment of Computer Science

Substitution transitions Substitution transitions do not have arc expressions and guards. They do not become enabled and they do not occur. Instead they represent the compound behaviour of their

submodules.

Receiver

Receiver

Network

Network

Sender

Sender

PacketsTo Send

AllPackets

NOxDATA

C

NO

D

NO

A

NOxDATA

DataReceived

""

DATA

B

NOxDATA

Sender Network Receiver

6

1`(1,"COL")++1`(2,"OUR")++1`(3,"ED ")++1`(4,"PET")++1`(5,"RI ")++1`(6,"NET")

1 1`(1,"COL")

11`""

Page 14: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

14

Coloured Petri NetsDepartment of Computer Science

Abstraction levels

In the protocol system we only have two different levels of abstraction. Highest: Protocol module. Lowest: Sender, Network and Receiver modules.

CPN models of larger systems typically have up to10 abstraction levels.

Page 15: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

15

Coloured Petri NetsDepartment of Computer Science

Second version of hierarchical protocol

n

if successthen 1`(n,d)else empty(n,d)

TransmitAck

TransmitPacket

C In

NO

B Out

NOxDATA

DOut

NO

AIn

NOxDATA

In

Out

Out

Inif successthen 1`nelse empty

We would like to define a single Transmit module and use this twice. To do this we need to make the colours sets identical.

The two transitions in the Network module have a similar behaviour. The upper transition transmits packets. The lower transition transmits acknowledgements.

Page 16: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

16

Coloured Petri NetsDepartment of Computer Science

Packets and acknowledgements

colset NO = int;colset DATA = string;colset NOxDATA = product NO * DATA;

colset PACKET = union Data : NoxDATA + Ack : NO;

Data(1,"COL") Ack(2)

One colour set for acknowledgement packets

Another colour set for data packets

AcknowledgementData

Instead we define a common colour set which can be used for both data packets and acknowledgement packets:

Until now:

Page 17: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

17

Coloured Petri NetsDepartment of Computer Science

Network

Network

Receiver

Receiver

Sender

Sender

PacketsTo Send

AllPackets

PACKET

C

PACKET

D

PACKET

A

PACKET

DataReceived

B

PACKET

Sender ReceiverNetwork

DATA

""

Modified Protocol module Uses the new type. Otherwise there are no changes.

Page 18: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

18

Coloured Petri NetsDepartment of Computer Science

Modified Sender Module

Ack(n)

Data(n,d)

n

SendPacket

A Out

PACKET

D In

PACKET

NextSend

1`1

NO

AllPackets

PACKET

In

Out

n

ReceiveAck

k

PacketsTo Send

I/OI/O

Data(n,d)

Uses the new type.

Arc expressions have been modified to match the new type.

Page 19: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

19

Coloured Petri NetsDepartment of Computer Science

Modified Receiver module

if n=kthen Ack(k+1)else Ack(k)

Data(n,d)

if n=k then data^delse data

data

Receive Packet

COut

PACKET

BIn

PACKET

DataReceived

I/O

""

DATA

NextRec

1`1

NO

In

Out

if n=kthen k+1else k

k

I/O Uses the new type. Arc expressions have

been modified to match the new type.

Page 20: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

20

Coloured Petri NetsDepartment of Computer Science

Modified Network module

TransmitAck

Transmit

C Out

PACKET

DIn

PACKET

B Out

PACKET

AIn

PACKET

In

In

Transmit

TransmitData

TransmitTransmit

Out

Out

The two substitution transitions refer to the same submodule.

Substitution transitions (refers to same module)

Uses the new type. Contains two substitution transitions.

Page 21: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

21

Coloured Petri NetsDepartment of Computer Science

Transmit module

pTransmit

PACKET

INIn

PACKET

if successthen 1`pelse empty

OUT OutIn Out

The variable p can be bound to a data packetsuch as Data(1,"COL").

It can also be bound to an acknowledgement packetsuch as Ack(2).

Both kinds of packets are handled in the same way.

colset PACKET = union Data : NoxDATA + Ack : NO;var p : PACKET;

The Transmit module can handle both data packets and acknowledgement packets.

Page 22: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

22

Coloured Petri NetsDepartment of Computer Science

Marking of Protocol module after some steps

Network

Network

Receiver

Receiver

Sender

Sender

PacketsTo Send

AllPackets

PACKET

C

PACKET

D

PACKET

A

PACKET

DataReceived

B

PACKET

Sender ReceiverNetwork

DATA

""6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

33`Ack(3)

2

2`Ack(3)

3

1`Data((2,"OUR"))++2`Data((3,"ED "))

11`"COLOUR"

1

1`Data((2,"OUR"))

Page 23: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

23

Coloured Petri NetsDepartment of Computer Science

Marking of Transmit module There are two instances of the transmit module. One instance for each substitution transition that uses to the module.

if successthen 1`pelse emptyp

Transmit OUT Out

PACKET

INIn

PACKET

In Out

1

1`Data((2,"OUR"))

3

1`Data((2,"OUR"))++2`Data((3,"ED "))

if successthen 1`pelse emptyp

Transmit OUT Out

PACKET

INIn

PACKET

In Out

2

2`Ack(3)

3

3`Ack(3)

Instance related to Transmit Data

Instance related to Transmit Ack

Each instance has its own marking which is independent of themarking of the other instance.

Page 24: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

24

Coloured Petri NetsDepartment of Computer Science

Module hierarchy Represents the relationship between modules. Each node represents a module. Each arc is labelled by a substitution transition.

The Protocol module contains a substitution transition Receiver which refers to the Receiver module

Page 25: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

25

Coloured Petri NetsDepartment of Computer Science

Module hierarchy The roots are called prime modules. Each module has as many

instances as there are pathsfrom a prime module.

1

1 1 1

2

Prime module

The module hierarchy must be an acyclic graph.

This guarantees that each module has a finite number of instances.

Path of length 0

Page 26: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

26

Coloured Petri NetsDepartment of Computer Science

Instance hierarchy Similar to the module hierarchy, but now the two instances of

the Transmit module are drawn as two separate nodes. The instance hierarchy is an unfolded version of the module

hierarchy. It is a directed tree.

Page 27: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

27

Coloured Petri NetsDepartment of Computer Science

Network

Network

Receiver1

Receiver

Receiver2

Receiver

Sender

Sender

PacketsTo Send

AllPackets

PACKETA1

PACKET

D1

PACKET

DataReceived1

""

DATA

C1

PACKET

B1

PACKET

C2

PACKET

D2

PACKET

A2

PACKET

Data Received2

""

DATA

B2

PACKET

Sender Receiver ReceiverNetwork

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

1

1`""

2 2`Data((1,"COL"))

11`Ack(2)

22`Ack(2)

1

1`"COL"

1 1`Data((1,"COL"))

Protocol with multiple receiversData and acknowledgments to/from the first receiver

Data and acknowledgments to/from the second receiver

Two different receivers

Page 28: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

28

Coloured Petri NetsDepartment of Computer Science

Sender module

Identical data packets are broadcasted to the two receivers (via A1 and A2).

ReceiveAck can only occur when there are identical acknowledgements from the two receivers (on D1 and D2).Ack(n)

Data(n,d)

Data(n,d)

Ack(n)

Data(n,d)

n

nk

ReceiveAck

SendPacket

D1 In

PACKET

A2 Out

PACKET

A1 Out

PACKET

D2 In

PACKET

NextSend

1`1

NO

PacketsTo Send

I/O

AllPackets

PACKET

I/O

In

Out

Out

In

2 2`Ack(2)

1 1`1

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

Page 29: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

29

Coloured Petri NetsDepartment of Computer Science

Network module

Data to the first receiver

Data to the second receiver

Acknowledgements from first receiver

Acknowledgements from second receiver

TransmitAck1

Transmit

TransmitAck2

Transmit

TransmitData2

Transmit

TransmitData1

Transmit

A2In

PACKET

D1Out

PACKET

A1In

PACKET

B2 Out

PACKET

D2Out

PACKET

B1 Out

PACKET

C2 In

PACKET

C1 In

PACKET

In

In

Out

Out

Out

In

Out

In

Transmit

Transmit

Transmit

Transmit

1 1`Data((1,"COL"))

2 2`Ack(2)

2 2`Data((1,"COL"))

1 1`Ack(2)

Page 30: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

30

Coloured Petri NetsDepartment of Computer Science

if n=kthen Ack(k+1)else Ack(k)

Data(n,d)

if n=k then data^delse data

k

data

if n=kthen k+1else k

ReceivePacket

COut

PACKET

BIn

PACKET

DataReceived

I/O

""

DATA

NextRec

1`1

NO

I/O

In

Out

2

2`Data((1,"COL"))

11`""

11`1

if n=kthen Ack(k+1)else Ack(k)

Data(n,d)

if n=k then data^delse data

k

data

if n=kthen k+1else k

ReceivePacket

COut

PACKET

BIn

PACKET

DataReceived

I/O

""

DATA

NextRec

1`1

NO

In

Out

I/O

1

1`Ack(2)

1

1`Data((1,"COL"))

11`"COL"

11`2

Receiver module (2 instances) Each instance has its own marking.

Receiver 1 Receiver 2

Waiting for packet no. 1 Waiting for packet no. 2

Page 31: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

31

Coloured Petri NetsDepartment of Computer Science

Network

Network

Receiver1

Receiver

Receiver2

Receiver

Sender

Sender

PacketsTo Send

AllPackets

PACKET

DataReceived1

(Recv(1),"")

RECVxDATA

C

RECVxPACKET

D

RECVxPACKET

A

RECVxPACKET

Data Received2

(Recv(2),"")

RECVxDATA

B

RECVxPACKET

Sender Receiver ReceiverNetwork

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

1

1`(Recv(1),"")

1

1`(Recv(2),Ack(2))

2

2`(Recv(2),Ack(2))

1

1`(Recv(2),"COL")

3

2`(Recv(1),Data((1,"COL")))++1`(Recv(2),Data((1,"COL")))

Second version with multiple receivers

Two different receivers

A1 and A2 have been folded into a single place A. Analogously, for B1 and B2, C1 and C2, D1 and D2.

Page 32: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

32

Coloured Petri NetsDepartment of Computer Science

Packets and acknowledgements

colset RECV = index Recv with 1..2;

colset RECVxPACKET = product RECV * PACKET;

Recv(1)Two different values

Recv(2)

To be able to make the folding we define an index colour set:

Instead of using two different places such as A1 and A2 we use the token colour to tell which receiver the data goes to / acknowledgements comes from.

(Recv(1),Data(2,"OUR")) Data packet for the first receiver

(Recv(2),Ack(3)) Acknowledgement from the second receiver

Page 33: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

33

Coloured Petri NetsDepartment of Computer Science

PacketsTo Send

I/O

PACKET

AllPackets

I/O

NextSend

NO

1`1

D In

RECVxPACKET

In

A Out

RECVxPACKET

SendPacket

ReceiveAck

k n

n

Data(n,d)

1`(Recv(1),Ack(n)) ++ 1`(Recv(2),Ack(n))

1`(Recv(1),Data(n,d))++1`(Recv(2),Data(n,d))

Out

61`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

1 1`1

22`(Recv(2),Ack(2))

Sender module Uses the new type. Arc expressions have been modified to match the new type.

Similar changes in the other three modules

Page 34: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

34

Coloured Petri NetsDepartment of Computer Science

TransmitAck

Transmit

TransmitData

Transmit

AIn

RECVxPACKET

B Out

RECVxPACKET

DOut

RECVxPACKET

C In

RECVxPACKET

InOut

OutIn

Transmit

Transmit

3

2`(Recv(1),Data((1,"COL")))++1`(Recv(2),Data((1,"COL")))

2

2`(Recv(2),Ack(2))

1

1`(Recv(2),Ack(2))

Network module

Data to both receivers

Acknowledgements from both receivers

Uses the new type. Now we only need two instances of the Transmit module.

Page 35: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

35

Coloured Petri NetsDepartment of Computer Science

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

Transmit module

var recv : RECV;

Uses the new type. Arc expressions have been modified to match the new type. A new variable has been introduced.

Page 36: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

36

Coloured Petri NetsDepartment of Computer Science

if n=kthen (recv,Ack(k+1))else (recv,Ack(k))

(recv,Data(n,d))

if n=k then (recv,data^d)else (recv,data)

k

(recv,data)

if n=kthen k+1else k

Receive Packet

COut

RECVxPACKET

BIn

RECVxPACKET

DataReceived

I/O

RECVxDATA

NextRec

1`1

NO

In

Out

I/O

1

1`(Recv(2),Ack(2))

3

2`(Recv(1),Data((1,"COL")))++1`(Recv(2),Data((1,"COL")))

11`(Recv(1),"")

11`1

Receiver moduleReceiver no 1

The first receiver has not yet received any data

Two data packets for Receiver1

The first receiver is waiting for data packet no. 1

Page 37: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

37

Coloured Petri NetsDepartment of Computer Science

if n=kthen (recv,Ack(k+1))else (recv,Ack(k))

(recv,Data(n,d))

if n=k then (recv,data^d)else (recv,data)

k

(recv,data)

if n=kthen k+1else k

Receive Packet

COut

RECVxPACKET

BIn

RECVxPACKET

DataReceived

I/O

RECVxDATA

NextRec

1`1

NO

I/O

In

Out1

1`(Recv(2),Ack(2))

3

2`(Recv(1),Data((1,"COL")))++1`(Recv(2),Data((1,"COL")))

11`(Recv(2),"COL")

11`2

The second receiver has received the first data packet

The second receiver is waiting for data packet no. 2

A data packet for Receiver2

An acknowledgement from Receiver2

Receiver moduleReceiver no 2

Page 38: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

38

Coloured Petri NetsDepartment of Computer Science

Network

Network

Receiver

Receiver

Sender

Sender

PacketsTo Send

PACKET

C

RECVxPACKET

D

RECVxPACKET

A

RECVxPACKET

Data Received

AllRecvs ""

RECVxDATA

B

RECVxPACKET

Sender ReceiverNetwork

AllPackets

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

3

1`(Recv(1),"")++1`(Recv(2),"")++1`(Recv(3),"")

We only have a single Receiver module. The Receiver module represents an arbitrary number of receivers. We will use token colours to distinguish the receiver tokens from each other.

Third version with multiple receivers

One token for each receiver

Page 39: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

39

Coloured Petri NetsDepartment of Computer Science

Packets and acknowledgements

colset RECV = index Recv with 1..NoRecv;

colset RECVxPACKET = product RECV * PACKET;

We define the number of receivers by means of a constant. Can easily be changed without modifying the other definitions.

val NoRecv = 3;

colset RECVxNO = product RECV * NO;

colset RECVxDATA = product RECV * DATA;

As before we add a RECV component to DATA tokens and PACKET tokens:

We do the same for NO tokens:

Page 40: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

40

Coloured Petri NetsDepartment of Computer Science

Initial marking for DataReceived

For three receivers we want the initial marking to be:

The initial marking should change automatically when the number of receivers changes.

To obtain this, we define the initial marking by means of a function called AllRecvs.

1`(Recv(1),"") ++ 1`(Recv(2),"") ++ 1`(Recv(3),"")

For six receivers we want the initial marking to be:

1`(Recv(1),"") ++ 1`(Recv(2),"") ++ 1`(Recv(3),"") ++1`(Recv(4),"") ++ 1`(Recv(5),"") ++ 1`(Recv(6),"")

Page 41: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

41

Coloured Petri NetsDepartment of Computer Science

Definition of function AllRecvs

fun AllRecvs v = List.map (fn recv => (recv,v))(RECV.all());

All receivers

1`Recv(1) ++ 1`Recv(2) ++ 1`Recv(3)

[(Recv(1),v),(Recv(2),v),(Recv(3),v)]

1`(Recv(1),v) ++ 1`(Recv(2),v) ++ 1`(Recv(3),v)

Anonymous functionCurried library function:Applies a function(given as first argument)on all elements in a list(given as second argument) [Recv(1),Recv(2),Recv(3)]

CPN tools represents multisets as lists

AllRecvs "" 1`(Recv(1),"") ++ 1`(Recv(2),"") ++ 1`(Recv(3),"")

Page 42: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

42

Coloured Petri NetsDepartment of Computer Science

if n=kthen (recv,Ack(k+1))else (recv,Ack(k))

(recv,Data(n,d))

if n=k then (recv,data^d)else (recv,data)

(recv,k)

(recv,data)

if n=kthen (recv,k+1)else (recv,k)

ReceivePacket

COut

RECVxPACKET

BIn

RECVxPACKET

DataReceived

I/O

RECVxDATA

NextRec

RECVxNO

In

Out

AllRecvs 1

I/O

31`(Recv(1),"")++1`(Recv(2),"")++1`(Recv(3),"")

3

1`(Recv(1),1)++1`(Recv(2),1)++1`(Recv(3),1)

Receiver moduleOne token for each receiver

One token for each receiver

Initialisation expression

Page 43: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

43

Coloured Petri NetsDepartment of Computer Science

Ack(n)

AllRecvs (Data(n,d))

AllRecvs (Ack(n))

Data(n,d)

n

ReceiveAck

SendPacket

AllAcks

PACKET

A Out

RECVxPACKET

D In

RECVxPACKET

NextSend

1`1

NO

PacketsTo SendI/O AllPackets

PACKET

I/O

In

Out

Acks

k n

1 1`1

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

6

1`Ack(2)++1`Ack(3)++1`Ack(4)++1`Ack(5)++1`Ack(6)++1`Ack(7)

Sender module

AllRecvs

This implies that the CPN simulator cannot find a binding for the variable n.

To solve this problem we add a new place Acks.

AllRecvs (Ack(n))is not a pattern– because it involves a function call.

Page 44: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

44

Coloured Petri NetsDepartment of Computer Science

Ack(n)

AllRecvs (Data(n,d))

AllRecvs (Ack(n))

Data(n,d)

n

ReceiveAck

SendPacket

AllAcks

PACKET

A Out

RECVxPACKET

D In

RECVxPACKET

NextSend

1`1

NO

PacketsTo SendI/O AllPackets

PACKET

I/O

In

Out

Acks

k n

1 1`1

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

6

1`Ack(2)++1`Ack(3)++1`Ack(4)++1`Ack(5)++1`Ack(6)++1`Ack(7)

Modified Sender module

All possible acknowledgements

Ack(n) is a pattern.

Ack is a data constructor – not a function call.

Hence the CPN simulator can find a binding for the variable n.

The initial marking of Acks is defined by means of the symbolic constant AllAcks.

Page 45: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

45

Coloured Petri NetsDepartment of Computer Science

val AllAcks = List.map (fn Data(n,_) => Ack(n+1)) AllPackets;

Definition of AllAcks

All packets

1‘Data((1,"COL")) ++ 1‘Data((2,"OUR")) ++1‘Data((3,"ED ")) ++ 1‘Data((4,"PET")) ++1‘Data((5,"RI ")) ++ 1‘Data((6,"NET"))

[Data((1,"COL")),Data((2,"OUR")), Data((3,"ED ")),Data((4,"PET")), Data((5,"RI ")),Data((6,"NET"))]

[Ack(2),Ack(3),Ack(4),Ack(5),Ack(6),Ack(7)]

Curried library function:Applies a function(given as first argument)on all elements in a list(given as second argument)

CPN tools represents multisets as lists

1`Ack(2) ++ 1`Ack(3) ++ 1`Ack(4) ++ 1`Ack(5) ++ 1`Ack(6) ++ 1`Ack(7)

Anonymous function

Page 46: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

46

Coloured Petri NetsDepartment of Computer Science

Fusion sets

Modules can exchange tokens via: Port and socket places. Fusion sets.

Fusion sets allow places in different modules to be “glued” to one compound place ― across the hierarchical structure of the model.

Fusion sets are in some sense similar to global variables known from many programming languages and should therefore be used with care.

Page 47: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

47

Coloured Petri NetsDepartment of Computer Science

Collecting lost packets

We collect a copy of the lost packets on place PacketsLost. Each instance of the Transmit module collects separately.

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

PacketsLost

RECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

Page 48: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

48

Coloured Petri NetsDepartment of Computer Science

Collecting at a single place

All instances of the place PacketsLost are “glued together” to become a single compound place – sharing the same marking.

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

PacketsLost

LostRECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

LostMember of fusion set

Page 49: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

49

Coloured Petri NetsDepartment of Computer Science

Marking

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

PacketsLost

LostRECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

Lost

9

3`(Recv(1),Data((1,"COL")))++1`(Recv(2),Data((1,"COL")))++3`(Recv(3),Data((1,"COL")))++2`(Recv(3),Ack(2))

1

1`(Recv(1),Data((1,"COL")))

43

13`(Recv(1),Data((1,"COL")))++18`(Recv(2),Data((1,"COL")))++12`(Recv(3),Data((1,"COL")))

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

PacketsLost

LostRECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

Lost

9

3`(Recv(1),Data((1,"COL")))++1`(Recv(2),Data((1,"COL")))++3`(Recv(3),Data((1,"COL")))++2`(Recv(3),Ack(2))

2

1`(Recv(1),Ack(2))++1`(Recv(2),Ack(2))

5

2`(Recv(1),Ack(2))++3`(Recv(3),Ack(2))

Local

Local

Shared

Shared

TransmitData

TransmitAck

Local

Local

Page 50: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

50

Coloured Petri NetsDepartment of Computer Science

Booleans(trans)trans

data

InitialiseModel

Ack Packets

AcksPACKET

Success

Success BOOL

Data Packets

DataPacketsPACKET

Network

unreliable

TRANSMISSION

DataTo Send

"COLOURED PETRI NET"

DATA

DataPackets

Success

Acks

AllDataPackets(data)

AllAckPackets(data)

1 1`unreliable

1 1`"COLOURED PETRI NET"

Initialisation module Initialisation of the CPN model is done in a specific module. Tokens are distributed to the other modules via fusion sets.

Fusion set

Fusion set

Fusion set

Data to be transmitted

Network properties

Page 51: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

51

Coloured Petri NetsDepartment of Computer Science

Booleans(trans)trans

data

InitialiseModel

Ack Packets

AcksPACKET

Success

Success BOOL

Data Packets

DataPacketsPACKET

Network

unreliable

TRANSMISSION

DataTo Send

"COLOURED PETRI NET"

DATA

DataPackets

Success

Acks

AllDataPackets(data)

AllAckPackets(data) 6

1`Ack(2)++1`Ack(3)++1`Ack(4)++1`Ack(5)++1`Ack(6)++1`Ack(7)

2

1`false++1`true

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

Marking after initialisation

Tokens to Sender module

Tokens to Transmit module

Page 52: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

52

Coloured Petri NetsDepartment of Computer Science

SplitData

fun SplitData (data) = let val pl = PacketLength;

fun splitdata (n,data) = let val dl = String.size (data) in if dl <= pl then [(n,data)] else (n,substring (data,0,pl)):: splitdata (n+1,substring (data,pl,dl-pl)) end;

in splitdata (1,data) end;

Local symbolic constant:Max length of each packet

Local auxiliary function

val PacketLength = 3; Symbolic constant: max length of each packet

Page 53: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

53

Coloured Petri NetsDepartment of Computer Science

AllDataPackets and AllAckPackets

fun AllDataPackets (data) = (List.map (fn (n,d) => Data(n,d)) (SplitData (data)));

Function to initialise place PacketsToSend in the Sender module:

fun AllAckPackets (data) = (List.map (fn (n,_) => Ack(n+1)) (SplitData (data)));

Function to initialise place Acks in the Sender module:

[(1,"COL"),(2,"OUR"),(3,"ED "),(4,"PET"),(5,"RI "),(6,"NET")]

Page 54: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

54

Coloured Petri NetsDepartment of Computer Science

AllRecvs (Data(n,d))

Data(n,d)

n

nk

ReceiveAck

SendPacket

PACKET

A Out

RECVxPACKET

D In

RECVxPACKET

NextSend

1`1

NO

PacketsTo SendDataPackets

PACKET

DataPackets

InAcksAcksAcksAllRecvs (Ack(n))Ack(n)

Out

1 1`1

6

1`Data((1,"COL"))++1`Data((2,"OUR"))++1`Data((3,"ED "))++1`Data((4,"PET"))++1`Data((5,"RI "))++1`Data((6,"NET"))

6

1`Ack(2)++1`Ack(3)++1`Ack(4)++1`Ack(5)++1`Ack(6)++1`Ack(7)

Marking of Sender module after initialisation

AllDataPackets (data)

data = "COLOURED PETRI NET"

AllAckPackets (data)

Page 55: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

55

Coloured Petri NetsDepartment of Computer Science

Reliable/unreliable transmission

(* Produces the boolean values to which the variable success can be bound *)

fun Booleans reliable = 1`true | Booleans unreliable = 1`true ++ 1`false;

New colour set:

colset TRANSMISSION = with reliable | unreliable;

No packets are lost:success can only be bound to true

Packets may be lost:success can be bound to either true or false

Function to initialise place Success in the Transmit module:

Page 56: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

56

Coloured Petri NetsDepartment of Computer Science

success

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

BOOL

PacketsLost

Lost RECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

Out

Lost

In

Success

SuccessSuccess

21`false++1`true

Marking of Transmit module after initialisation

Booleans (unreliable)

Page 57: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

57

Coloured Petri NetsDepartment of Computer Science

Unfolding hierarchical CPN models

A hierarchical CPN model can always be unfolded to an equivalent non-hierarchical CPN model

Three steps:

Replace each substitution transition with the content of its submodule (related port and socket places are merged into a single place).

Collect the contents of all prime modules in a single module.

Merge places which belong to the same fusion set.

Page 58: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

58

Coloured Petri NetsDepartment of Computer Science

Example of folding

TransmitAck

Transmit

TransmitData

Transmit

AIn

RECVxPACKET

B Out

RECVxPACKET

DOut

RECVxPACKET

C In

RECVxPACKET

InOut

OutIn

Transmit

Transmit

success

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

Success

Success BOOL

PacketsLost

Lost RECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

Lost

Success

success

if successthen emptyelse 1`(recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack) Transmit

Packet

Success

Success BOOL

PacketsLost

Lost RECVxPACKET

OUT Out

RECVxPACKET

INIn

RECVxPACKET

In Out

Lost

Success

Replace

Replace

Merge

Merge

Merge

Merge

Page 59: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

59

Coloured Petri NetsDepartment of Computer Science

Non-hierarchical CPN model

if successthen 1`(recv,pack)else empty (recv,pack)

if successthen 1`(recv,pack)else empty(recv,pack)

TransmitPacket

BOOLRECVxPACKET

AIn

RECVxPACKET

B Out

RECVxPACKET

DOut

RECVxPACKET

C In

RECVxPACKET

TransmitPacket

PacketsLostLostLost

if successthen emptyelse 1`(recv,pack)

Success SuccessSuccess

if successthen emptyelse 1`(recv,pack)

In

OutIn

Out

success

success

TransmitData

TransmitAck

Page 60: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

60

Coloured Petri NetsDepartment of Computer Science

Hierarchical versus non-hierarchical nets

In theory, this implies that the hierarchy constructs of CP-nets do not add expressive power to the modelling language.

Any system that can be modelled with a hierarchical CPN model can also be modelled with a non-hierarchical CPN model.

In practice, the hierarchy constructs are very important.

They make it possible to structure large models and thereby cope with the complexity of large systems.

Hence they add modelling power.

A hierarchical CPN model can always be transformed into an equivalent non-hierarchical CPN model.

Page 61: Coloured Petri Nets Modelling and Validation of Concurrent Systems

Kurt Jensen Lars M. Kristensen

61

Coloured Petri NetsDepartment of Computer Science

Questions