descriptionHLA macros to make executable FSM language
ownerchris.brody@gmail.com
last changeWed, 16 Apr 2008 22:13:11 +0000 (17 00:13 +0200)
content tags
add:
readme
[SMTP FSM image]

This is currently a pre-alpha, experimental project to use the macro facility of the High Level Assember (HLA) to make an easy-to-use Finite State Machine (FSM) language.

License: Public domain. Other licenses are under consideration for countries that do not recognize the meaning of "public domain".

Note:If you find this project useful, and especially if you have any suggestions for improvement, I would appreciate a note with your feedback to: chris.brody@gmail.com

Rationale: The FSM is one of the hardest constructs to support in traditional, existing programming languages. A better solution is to use some form of an extensible programming language that allows such a construct to be defined at a higher level. The HLA provides a sufficient macro facility to support the extensible language required for the FSM construct.

WARNING: This is currently at an experimental stage-the design is subject to change without guarantee of backwards compatibility. Preservation of backwards compatibility will come when this project reaches a stable release stage.

Example:


fsm_start ( fsm, smtpfsm_advance, "smtpfsm_advance" )

        init_state ( STATE_INIT )
        state ( STATE_HELO )
        state ( STATE_MAIL )
        state ( STATE_RCPT )
        state ( STATE_DATA )
        state ( STATE_QUIT )

        event ( EVENT_HELO )
        event ( EVENT_MAIL )
        event ( EVENT_QUIT )
        event ( EVENT_RCPT )
        event ( EVENT_DATA )
        event ( EVENT_END_DATA )

        fsm_advance

                tr ( STATE_INIT, EVENT_HELO, STATE_HELO, helo_enter )

                tr ( STATE_HELO, EVENT_MAIL, STATE_MAIL, mail_enter )
                tr2( STATE_HELO, EVENT_QUIT, STATE_QUIT, quit_callback )

                tr ( STATE_MAIL, EVENT_RCPT, STATE_RCPT, rcpt_enter )
                tr2( STATE_MAIL, EVENT_QUIT, STATE_QUIT, quit_callback )

                tr ( STATE_RCPT, EVENT_DATA, STATE_DATA, data_enter )
                tr2( STATE_RCPT, EVENT_QUIT, STATE_QUIT, quit_callback )

                tr ( STATE_DATA, EVENT_END_DATA, STATE_MAIL, mail_enter )

end_fsm;

Design:

The design of the HLA FSM macro system is based on the CFSM project [2], though currently missing the error construct. There are two parts for the FSM:
* Header files defining C structure with init, free, and accessor macros
* FSM macros (fsm.hhf) to define the FSM advance function in HLA

Note: Knowledge of HLA, eventxx, and libevent are assumed for those interested in building and running the SMTP test.

SMTP test:

The SMTP test program requires the headers from a fork of eventxx at: http://repo.or.cz/w/eventxx/ioevent.git
To build and run the SMTP FSM test, please make sure the following is installed and in your build path:
* libevent 1.4.2 (http://www.monkey.org/~provos/libevent/) or later with the following patch applied: http://repo.or.cz/w/eventxx/ioevent.git?a=blob_plain;f=libevent-1.4.2-rc.patch;hb=HEAD
* headers from eventxx/ioevent.git: http://repo.or.cz/w/eventxx/ioevent.git
* Recommended but untested: libev (http://cvs.schmorp.de/libev/import_libevent?view=markup)
* Recommended command-line SMTP test client: http://www.logix.cz/michal/devel/smtp/

Please note that a very limited subset of SMTP is supported, i.e. no SSL or security checking, no special EHLO features, etc. In addition, the SMTP test is listening to port 5525, not 25.

Alternatives:

* Seed7 - higher-level extensible language (under LGPL and GPL licenses)
* LLVM - a more portable machine language than HLA, which currently only targets x86

Future work:

* Handling of error and exceptional conditions
* Support for tracing
* Clean up the FSM specification macro, with a goal that the same FSM specification can be assembled into both an executable engine and a graph output program
* Targeting more executable environments, such as LLVM, Python, JavaScript, etc.
* Bring the macro extensible language to a higher level and integrate with an interpreter such as CINT
* Embedded design environments such as Contiki and MyHDL
* Better documentation, examples, and tutorials, as always
* Start a mailing list if there is enough interest

References:

[1] High Level Assembler - http://webster.cs.ucr.edu/AsmTools/HLA/ - public domain
[2] CFSM - http://www.mindrot.org/projects/cfsm/ - BSD license
[3] eventxx (original version) - http://www.llucax.com.ar/~luca/eventxx/ - public domain
[4] libevent - http://www.monkey.org/~provos/libevent/ - BSD license
[5] libev - http://software.schmorp.de/pkg/libev.html - 2-clause BSD license
[6] Command-line SMTP test client - http://www.logix.cz/michal/devel/smtp/
[7] Seed7 - http://seed7.sourceforge.net/ - LGPL and GPL
[8] CINT - http://root.cern.ch/twiki/bin/view/ROOT/CINT - BSD license
[9] LLVM - http://llvm.org/ - BSD license
[10] MyHDL - http://myhdl.jandecaluwe.com/ - LGPL
[11] Contiki - http://www.sics.se/contiki/ - BSD
shortlog
2008-04-16 Chris BrodyGraphviz presentation of SMTP test FSMmaster
2008-04-16 Chris BrodyModify HLA FSM to generate graphviz output
2008-04-16 Chris BrodyPrepare hlafsm for graphviz generation
2008-04-16 Chris BrodyUpdate smtp test program for repo.or.cz/w/ioevent.git
2008-04-07 Chris BrodyInitial version of HLA FSM from hla-test in git://repo...
heads
16 years ago master