An FSM description of a simple data link protocol

More about protocols
(with an example)
Consider a network system:
User A
The task: Using a network and
Network
network services, user A and B
services
want to exchange data, by blocks
of variable size.
User B
Network
services
Network
The requirements:
1. Users A and B may send data blocks to each other.
2. At any moment, only one data block may be transmitted
(AB or BA).
3. If both A and B want to transmit exactly at the same
time, then the transmission should be permitted to only
one user.
4. To resolve the collision, A and B should have different
priority.
5. All network services must be separated into two layers:
data link and network access.
Data link: provides reliable transmission of data blocks and
collision resolution.
Network access: provides the electro-mechanical interface
with the network and sending/ receiving raw data
(series of bytes).
Note: Two computers connected via RS-232 through “null”
modem may be used for this system…
1
More detailed scheme
User A
1
2
send
buffer
User B
4
3
recv
buff
SAP
Data
link
SAP
Network access
Network access
Data block
Length Data bytes CRC CRC
NAK/error
ACK/OK
Neutral,
0
Transmitting,
3
Timeout/error
req/ENQ
Timeout/reset
All bytes/ACK
Error/NAK
ENQ/EOT
Receiving,
2
Up to
254
EOT/length
ENQ&priority/
Waiting,
1
ENQ&not priority/EOT
byte/store in buffer
2
User A transmits to user B (no collision)
User A (prior.)
User B (not prior.)
Timeout
data block
EOT
length
Timeout
ENQ
req
(to send a data
block)
CRC
CRC
data block received
ACK
OK
Time
Both users want transmit at the same time
User A (prior.)
ENQ
req
User B (not prior.)
req
ENQ
Response
time for A
EOT
CRC
CRC
ACK
ENQ
data
received from B
data
received from A
CRC
CRC
Time
Response
time for B
EOT
data block
OK
to user A
length
OK to user B
3
Description of a protocol as
a finite state machine (FSM)
General form:
Outputs
Inputs
FSM
Input
events S0
E0
E2
...
Em
States
S1 . . .
Sn
Operation,
next state
Sj
Let
Ei
Sj – current state,
Ei – current input event.
Then Opij – operation,
Opij ,
Sij
or
Sij
Sj
Ei/Opij
Sij {S0, . . ., Sn} – next state.
4
An example:
An FSM description of a simple data link protocol
Events
req
ENQ
EOT
States
0
Send ENQ,
1
Send EOT,
2
1
2
Send EOT (if
not prior.), 2
Send length,
3
OK to user,
0
Error to
user, 0
ACK
NAK
Time-out
ACK
received
Byte
received
(not last)
Receive
error
New byte
to send
3
Error to user,
0
Reset,
0
Send
ACK, 0
Store
byte, 2
Send
NAK, 0
Send byte,
3
5
Possible data structure to represent a protocol
(using our example)
Header
Linked list of states
0
State=0
EOT
Procedure
P(req)
P(EOT)
Next
state=1
Next
state=3
ENQ
P(ENQ)
ENQ
P(ENQ)
2
2
0
0
State=0
For the state 3
Inp.
event= req
State=0
Linked list of arcs for the state 2
State=0
For the state 1
Linked list of outgoing arcs
for the state 0
Curr.
state
0
0
6
An algorithm of the FSM engine
Input event E,
current state S.
Start
Moving along the list of states,
find the element containing the
value of S.
Moving along the list of arcs of the
state S, try to find an element
containing the value of event E.
Found?
No
Yes
Using the procedure, the name of
which is in the element, perform an
operation.
Ignore the
event E
End
Using the field “next state” in the
element, set new current state in
the header.
End
7
Definition of a Petri net:
Petri net
PN = (P, T, In, Out),
Where
P = {P1, P2, …, Pn} is a finite set of places (n>=0),
T = {t1, t2, …, tm} is a finite set of transitions (m>=0),
PT = ,
In : T  P is the input function (mapping from transitions to
bags of places),
Out : T  P is the output function (mapping from transitions
to bags of places).
P = PPP. . . Descartes product of set.
An example:
P2
Here:
t1
t2
t4
P1
P4
P={ P1, P2, …, P5},
T = {t1, t2, t3, t4},
P5
In(t1) = {P1}
In(t2) = {P2, P3, P5}
P3
In(t3) = {P3}
t3
In(t4) = {P4}
Out(t1) = { P2, P3, P5}
Out(t2) = {P5}
Out(t3) = {P4}
Out(t4) = { P2, P3}
Transition firing
In(t)={P1, P2, P2, P3}
t
P1
P4
P2
P5
P3
Before firing
t
P1
P4
P2
P5
P3
After firing
8
Petri net model of a simple data link protocol
(a fragment).
User
Req
Sender
Channel
ENQ
Receiver
EOT
Idle
Waiting
Idle
Next byte
Transm
itting
All bytes
Receiving
Absorbing
ACK
OK
NAK
Error to
user
 Some transitions are named by the corresponding
operations.
 Some places show the current state (at sender or
receiver).
9
Petri net model of a protocol, with sender
window size of 3
data
send
ready
msg sent
receive
data
prepare
data
ACK sent
send ACK
receiver
idle
using
data
Get ACK
10