Revision 9b0d959aea55e085083652864435023cc39f0785 (click the page title to view the current version)
Behavioral Modeling - WebSocket Protocol
Simplified Web Socket Protocol
Note: this is a contrived example, not the actual protocol.
First, we’d like to express the states of the websocket and the
transitions among them. When a websocket is created it starts in the
state ready, which we model as the initial
state. Upon entering each state initially, the websocket is not
accepting any requests. Furthermore, in the states closed
and failed, the websocket is not accepting any requests
permanently.
The request, if exists, points to either open or
close. The children of the request indicate
success or failure of the request.
Example scenarios
The example scenarios serve as test cases, whereby we can state the
intended behavior of the websocket. In each case, the constraint must be
consistent with the behavior specified above; however, it can be
underspecified. A chain of transitions is a sequence, read from left to
right, and initially anchors it to the start of the trace.
Without initially, the chain would have to hold in every
state of the trace, which contradicts the behavior above. For example,
the socket can remain in the state opened for an arbitrary
number of snapshots until the request to close is received. We express
that using the transition -->>. In the other cases,
state changes must occur in the next snapshot as required by
-->.
Web socket successfully opened and closed
We call such a temporal constraint a trace specification.
Trace 1
Since, the trace specification and the behavior of the websocket are
consistent, a trace generator can produce the following trace. After the
last state, the trace loops back to that state: the websocket remains
closed forever.
|
|
|
|
|
Web socket successfully opened but failed to be closed
All the Clafer code on a page forms one model, and all its concrete clafers exist at the same time. Therefore, this scenario and the next one are not part of the model of this page. To try one, open the model in the IDE and use it to replace the scenario above.
webSocketOpenedFailed : WebSocket
[ initially (ready --> request=open && request.success --> opened -->> request=close && request.failure --> failed --> failed) ]
Trace 2
|
|
|
|
|
Web socket failed to be opened
webSocketFailed : WebSocket
[ initially (ready --> request=open && request.failure --> failed --> failed) ]
Trace 3
|
|
|
