Requirements Techniques, cont.

24
CSC 402 Requirements Engineering 1 Requirements Techniques, cont. Formal requirements analysis techniques include: DFD (covered) ERD (covered) Finite State Machines Petri Nets

description

Requirements Techniques, cont. Formal requirements analysis techniques include: DFD (covered) ERD (covered) Finite State Machines Petri Nets. Finite State Machines. A requirements technique for modeling the states and transitions of a software system - PowerPoint PPT Presentation

Transcript of Requirements Techniques, cont.

Page 1: Requirements Techniques, cont.

CSC 402 Requirements Engineering

1

Requirements Techniques, cont.

• Formal requirements analysis techniques include:– DFD (covered)– ERD (covered)– Finite State Machines– Petri Nets

Page 2: Requirements Techniques, cont.

CSC 402 Requirements Engineering

2

Finite State Machines

• A requirements technique for modeling the states and transitions of a software system

• Finite state machines are used in other contexts– automata theory and compilers, for example

• More precise than data-flow diagrams– data-flow diagrams specify only the nature of a

system’s data flow (e.g. the what and the where)– finite state machines provide information on how a

system progresses from state to state¤ what is “state”

Page 3: Requirements Techniques, cont.

CSC 402 Requirements Engineering

3

Formal Definition

• The definition of a finite state machine (FSM) consists of five parts– a set of states– a set of inputs– a transition function– the initial state– a set of final states

Page 4: Requirements Techniques, cont.

CSC 402 Requirements Engineering

4

Simple Example

• States of a combination lock for a safe– Safe has a dial with three positions (1, 2, & 3)– The dial can be turned in two possible directions

¤ At any point six possible motions• Turn left to 1 (1L)• Turn right to 1 (1R)• etc...

– Combination is 1L, 3R, 2L– The possible states include the safe being locked

and unlocked, sounding the alarm, and the steps along the combination (e.g. 1L and 3R)

Page 5: Requirements Techniques, cont.

CSC 402 Requirements Engineering

5

Example, cont.

• Set of States (Locked, A, B, Unlocked, Alarm)• Set of Inputs (1L, 1R, 2L, 2R, 3L, 3R)• Transition Function (next two slides)• Initial State (Locked)• Final States (Unlocked, Alarm)

Page 6: Requirements Techniques, cont.

CSC 402 Requirements Engineering

6

Example, cont.

alarm

locked a b unlocked1L 3R 2L

X X X

any other input

initial state

final state

X

Page 7: Requirements Techniques, cont.

CSC 402 Requirements Engineering

7

Transition Table

Input

1L

1R

2L

2R

3L

3R

Locked

A

Alarm

Alarm

Alarm

Alarm

Alarm

A

Alarm

Alarm

Alarm

Alarm

Alarm

B

B

Alarm

Alarm

Alarm

Alarm

Alarm

Unlocked

Page 8: Requirements Techniques, cont.

CSC 402 Requirements Engineering

8

Finite State Machine Wrap-Up

• More advanced examples in other textbooks – The infamous “Elevator Example” is a good one

(Schach)

• Demonstrates– The specification power of FSMs

• Typical Problem– The number of states and transitions grows rapidly in

large systems– Approach: decompose problem into smaller subsystems

• Tool support exists for this and related techniques (e.g. statecharts)

Page 9: Requirements Techniques, cont.

CSC 402 Requirements Engineering

9

Petri Nets

• A formal technique suited for specifying the properties of concurrent or multithreaded systems

• Typical concurrency problems– race conditions

¤ X accesses Y before Z updates it

– deadlock¤ X is waiting on Y which is waiting on X

• Petri nets can be used to help avoid ambiguity in specifications that can lead to this class of problems in multithreaded systems

Page 10: Requirements Techniques, cont.

CSC 402 Requirements Engineering

10

Formal Definition of Petri Nets

• A Petri net consists of four parts– A set of places– A set of transitions– An input function– An output function

• In the subsequent diagrams, the input and output functions are represented by arrows

Page 11: Requirements Techniques, cont.

CSC 402 Requirements Engineering

11

Petri Net Parts

Place

Transition

Token

Page 12: Requirements Techniques, cont.

CSC 402 Requirements Engineering

12

Firing a transition

A transition fires when it has a token at each input place; as a result a token is placed at each output place.

Page 13: Requirements Techniques, cont.

CSC 402 Requirements Engineering

13

Simple Example

• A server cannot send an event to a client until the client has indicated that it is ready to receive one

• Approach– Map states into places– Map events into

transitions

• States– Event waiting– Event received– Event processed– Client Ready

• Events– Generate Event– Send Event– Process Event– Notify server

Page 14: Requirements Techniques, cont.

CSC 402 Requirements Engineering

14

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

Three events; one being received

Page 15: Requirements Techniques, cont.

CSC 402 Requirements Engineering

15

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

An event gets generated

Page 16: Requirements Techniques, cont.

CSC 402 Requirements Engineering

16

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

An event gets processed; waiting eventmust wait since “Send Event” cannot fire.

Page 17: Requirements Techniques, cont.

CSC 402 Requirements Engineering

17

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

Another event gets generated

Page 18: Requirements Techniques, cont.

CSC 402 Requirements Engineering

18

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

The client notifies the server

Page 19: Requirements Techniques, cont.

CSC 402 Requirements Engineering

19

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

An event is sent...

Page 20: Requirements Techniques, cont.

CSC 402 Requirements Engineering

20

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

Second event is processed...

Page 21: Requirements Techniques, cont.

CSC 402 Requirements Engineering

21

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

The client notifies the server

Page 22: Requirements Techniques, cont.

CSC 402 Requirements Engineering

22

Example, cont.

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

Final event is sent...andeventually processed (ghost token)

Page 23: Requirements Techniques, cont.

CSC 402 Requirements Engineering

23

Final State

Event Generator Event Waiting Event Received Event Processed

Client Ready

Generate Event

Send EventProcess Event

Notify Server

Client is ready for next event

Page 24: Requirements Techniques, cont.

CSC 402 Requirements Engineering

24

Petri Net Wrap-Up

• Clean notation for specifying concurrent properties

• Graphical notation hides underlying formalism– Makes it easier to understand

• Tool support and execution engines exists for this technique– The latter can help in testing how well a Petri net

specifies a property by running it on test cases