using contexts to define transitions

53 views
Skip to first unread message

Imran Akbar

unread,
Apr 24, 2014, 9:06:58 PM4/24/14
to squirrel-st...@googlegroups.com
Hi everyone,
    Thanks for the great work on the library so far.  I'm trying to build a state machine for a TCP stack.

There are some states which can transition to two other states depending on the data that was passed to it.  In my example code below, I can go from the 'SynRcvd' state to either the 'Established' or 'Listen' states depending on the content of the packet that was received.  But I'm not sure how to represent that in the state machine.  Do I need to parse the packets outside the state machine and turn my single 'PacketReceived' event into more fine-grained events?

enum FSMEvent
{
        PacketReceived, PacketSent, Timeout2MSL, Timeout, Close
}

public class TCPStack extends AbstractUntypedStateMachine
{
     protected void transitFromSynRcvdToEstablishedOnPacketReceived(String from, String to, FSMEvent event, TCPPacket packet) {}
     protected void transitFromSynRcvdToListenOnPacketReceived(String from, String to, FSMEvent event, TCPPacket packet) {}
}
        
Also, when I use the 'convention over configuration'-style transitions like above, does the FSM automatically generate the list of states, or do I need to define those somewhere?

thanks,
imran

He Henry

unread,
Apr 25, 2014, 2:01:35 AM4/25/14
to squirrel-st...@googlegroups.com
Hi Imran,

Please see my answers below.

Thanks,
Henry


在 2014年4月25日星期五UTC+8上午9时06分58秒,Imran Akbar写道:
Hi everyone,
    Thanks for the great work on the library so far.  I'm trying to build a state machine for a TCP stack.

There are some states which can transition to two other states depending on the data that was passed to it.  In my example code below, I can go from the 'SynRcvd' state to either the 'Established' or 'Listen' states depending on the content of the packet that was received.  But I'm not sure how to represent that in the state machine.  
[Henry] Basically you can define a conditional transition which will add a Condition object to the transition. Condition object takes Context object as parameter to decide whether condition is satisfied or not. You can choose whatever type of object to be the state machine context. Thus, whether to parse the packets inside Condition object or outside is really your decision. 
Do I need to parse the packets outside the state machine and turn my single 'PacketReceived' event into more fine-grained events?
[Henry] You need to consider whether the context object you choose(or you made) can represent the context during state machine transitions(all transitions not the specific transition). It is really your decision. State machine allows any type of context. 

enum FSMEvent
{
        PacketReceived, PacketSent, Timeout2MSL, Timeout, Close
}

public class TCPStack extends AbstractUntypedStateMachine
{
     protected void transitFromSynRcvdToEstablishedOnPacketReceived(String from, String to, FSMEvent event, TCPPacket packet) {}
     protected void transitFromSynRcvdToListenOnPacketReceived(String from, String to, FSMEvent event, TCPPacket packet) {}
}
        
Also, when I use the 'convention over configuration'-style transitions like above, does the FSM automatically generate the list of states, or do I need to define those somewhere?
[Henry] Simple answer is no. You need to define your state either through API or annotations. For more information, you can read the document and play sample code. 
 

thanks,
imran
Reply all
Reply to author
Forward
0 new messages