hsmCommunicator

This machine manages communications using a "stop and wait" protocol. Only one message is allowed to be outstanding.

Before any message can be exchanged, however, a session must be established with the peer. Establishing a connection requires several exchanges to authenticate. The session will remain active as long as messages continue to be exchanged with a minimum frequency.

The user of this machine calls run_hsmCommunicator, passing the SEND_MESSAGE event. For the first message, the machine will be IDLE, and thus needs to queue the message, start the establishSession machine, and transition to the ESTABLISHING_SESSION state. Requests to send messages received in this state will simply be queued.

While the top level machine is in the ESTABLISHING_SESSION state, the establishSession machine does the establishment work.

When the establishSession machine receives the STEP1_RESPONSE event, it reports to the top level machine that the session is established by returning the parent's SESSION_ESTABLISHED event. This will move the top level machine to its IN_SESSION state and cause it to send the message(s) which are enqueued.

Number of events4
Events not handled0
Events handled in one state2
At least one event handled the same in all states?no
Number of states3
Number of states with entry functions0
Number of states with exit functions0
States handling no events0
States handling exactly one event1
States with no way in0
States with no way out0
  SEND_MESSAGE SESSION_ESTABLISHED SESSION_TIMEOUT MESSAGE_RECEIVED
IDLE startSessionEstablishment
shares event with:
  • sendMessage

transition : ESTABLISHING_SESSION

Start the session establishment process by activating the establishSession machine.


transition : none

transition : none

transition : none
ESTABLISHING_SESSION queueMessage
shares event with:
  • sendMessage

transition : none

Extend the session timer and queue the message

completeSessionStart
returns:
  • noEvent

transition : IN_SESSION

Start the session timer and notify the sendMessage machine that the session is established.


transition : none
passMessageReceived
shares event with:
  • establishSession
  • sendMessage

transition : none

Pass the MESSAGE_RECEIVED event along.

IN_SESSION requestMessageTransmission
shares event with:
  • sendMessage

transition : none

Extend the session timer and pass the message to be sent to the sendMessage machine.


transition : none
noAction
transition : IDLE
passMessageReceived
shares event with:
  • establishSession
  • sendMessage

transition : none

Pass the MESSAGE_RECEIVED event along.

Events
Total number of events:4
Events with no handlers:0
Events with one handler:2
Average event state density:58%
SEND_MESSAGE This event comes from our client code, asking us to send a message.

This event is shared with:

  • sendMessage

Handled In 3 of 3 (100 %) States:

  • IDLE
  • ESTABLISHING_SESSION
  • IN_SESSION

Causes these actions to be taken:

  • startSessionEstablishment
  • queueMessage
  • requestMessageTransmission
SESSION_ESTABLISHED This event comes from our establishSession submachine, indicating that it has successfully completed its work. We then forward it to our sendMessage submachine to indicate that it may now begin to send messages.

Handled In 1 of 3 (33 %) States:

  • ESTABLISHING_SESSION

Causes these actions to be taken:

  • completeSessionStart
SESSION_TIMEOUT This event comes from our external timer, indicating that we've not tickled it in a while, and thus should close down our session.

Handled In 1 of 3 (33 %) States:

  • IN_SESSION
MESSAGE_RECEIVED This event comes from our lower comm layers, indicating that a peer message has arrived. While we're in the ESTABLISHING_SESSION state, we forward this event to the establishSession submachine; while in the IN_SESSION state, we forward it to the sendMessage submachine.

This event is shared with:

  • establishSession
  • sendMessage

Handled In 2 of 3 (66 %) States:

  • ESTABLISHING_SESSION
  • IN_SESSION

Causes these actions to be taken:

  • passMessageReceived
States
Total number of states:3
States with no events:0
States with one event:1
States with no way in:0
States with no way out:0
Average state event density:58%
IDLE

The wakeup state. Also, this is the state to which the machine returns when a session times out.

Inbound Transitions:

  • IN_SESSION

Outbound Transitions:

  • ESTABLISHING_SESSION

Events Handled (1 of 4 for 25%):

  • SEND_MESSAGE

Actions Taken:

  • startSessionEstablishment
ESTABLISHING_SESSION

The machine is establishing a session. The actual work is being done by the establishSession submachine. While in this state, the MESSAGE_RECEIVED event is forwarded to that submachine.

Inbound Transitions:

  • IDLE

Outbound Transitions:

  • IN_SESSION

Events Handled (3 of 4 for 75%):

  • SESSION_ESTABLISHED
  • MESSAGE_RECEIVED
  • SEND_MESSAGE

Actions Taken:

  • completeSessionStart
  • passMessageReceived
  • queueMessage
IN_SESSION

A session has been established, and messages are being exchanged with the peer. While in this state, the MESSAGE_RECEIVED event is forwarded to the sendMessage submachine.

Inbound Transitions:

  • ESTABLISHING_SESSION

Outbound Transitions:

  • IDLE

Events Handled (3 of 4 for 75%):

  • MESSAGE_RECEIVED
  • SEND_MESSAGE
  • SESSION_TIMEOUT

Actions Taken:

  • passMessageReceived
  • requestMessageTransmission
Actions
startSessionEstablishment

Shares event to:
  • sendMessage

Matrices:

  • SEND_MESSAGE, IDLE transitions to state ESTABLISHING_SESSION
completeSessionStart

Returns:
  • noEvent

Matrices:

  • SESSION_ESTABLISHED, ESTABLISHING_SESSION transitions to state IN_SESSION
passMessageReceived

Shares event to:
  • establishSession
  • sendMessage

Matrices:

  • MESSAGE_RECEIVED, (ESTABLISHING_SESSION, IN_SESSION)
queueMessage

Shares event to:
  • sendMessage

Matrices:

  • SEND_MESSAGE, ESTABLISHING_SESSION
requestMessageTransmission

Shares event to:
  • sendMessage

Matrices:

  • SEND_MESSAGE, IN_SESSION
transition

Matrices:

  • SESSION_TIMEOUT, IN_SESSION transitions to state IDLE
Sub Machines
establishSession

Establish a connection with the peer.

Two messages must be exchanged with the peer to successfully establish the session. The machine needs only two states, IDLE and AWAITING_RESPONSE since the top level machine tracks whether or not it is in a session. The AWAITING_RESPONSE state serves for both required messages, since the receipt of each message produces a unique event.

When the STEP1_RESPONSE event is received, the session is considered established. This machine will then return the parent's SESSION_ESTABLISHED message and move to its IDLE state.

sendMessage

Send a message to the peer.

Since the protocol allows only one message to be outsanding, the machine dequeues and transmits a message only from the IDLE state, transitioning to the AWAITING_ACK state immediately thereafter.

In the AWAITNG_ACK state, incomming messages are parsed and, when an ACK is found, the machine checks the queue and transitions to the IDLE state. Checking the queue can return the SEND_MESSAGE event, which will be handled from the IDLE state, thus resulting in a transmission and return to the AWAITING_ACK state.