Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_client_fsm.h

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 #ifndef __PANA_CLIENT_FSM_H__
00035 #define __PANA_CLIENT_FSM_H__
00036 
00037 #include "framework.h"
00038 #include "pana_fsm.h"
00039 #include "pana_client.h"
00040 
00041 class PANA_EXPORT PANA_ClientStateTable : public AAA_StateTable<PANA_Client>
00042 {
00043    public:
00044       class PacSendDiscover : public AAA_Action<PANA_Client> {
00045         virtual void operator()(PANA_Client &c) { c.SendDiscover(); }
00046       };
00047 
00048       class PacReceiveStartRequest : public AAA_Action<PANA_Client> {
00049         virtual void operator()(PANA_Client &c) { c.ReceiveStartRequest(); }
00050       };
00051 
00052       class PacReceiveBindRequest : public AAA_Action<PANA_Client> {
00053         virtual void operator()(PANA_Client &c) { c.ReceiveBindRequest(); }
00054       };
00055 
00056       class PacReceiveAuthRequest : public AAA_Action<PANA_Client> {
00057         virtual void operator()(PANA_Client &c) { c.ReceiveEapRequest(); }
00058       };
00059 
00060       class PacReceiveEapReAuthRequest : public AAA_Action<PANA_Client> {
00061         virtual void operator()(PANA_Client &c) { c.ReceiveEapReAuthRequest(); }
00062       };
00063 
00064       class PacSendReAuthRequest : public AAA_Action<PANA_Client> {
00065         virtual void operator()(PANA_Client &c) { c.SendReAuthenticateRequest(); }
00066       };
00067 
00068       class PacReceiveReAuthRequest : public AAA_Action<PANA_Client> {
00069         virtual void operator()(PANA_Client &c) { c.ReceiveReAuthenticateRequest(); }
00070       };
00071 
00072       class PacReceiveReAuthAnswer : public AAA_Action<PANA_Client> {
00073         virtual void operator()(PANA_Client &c) { c.ReceiveReAuthenticateAnswer(); }
00074       };
00075 
00076       class PacSendTermRequest : public AAA_Action<PANA_Client> {
00077         virtual void operator()(PANA_Client &c) { c.SendTerminationRequest(); }
00078       };
00079 
00080       class PacReceiveTermRequest : public AAA_Action<PANA_Client> {
00081         virtual void operator()(PANA_Client &c) { c.ReceiveTerminationRequest(); }
00082       };
00083 
00084       class PacReceiveTermAnswer : public AAA_Action<PANA_Client> {
00085         virtual void operator()(PANA_Client &c) { c.ReceiveTerminationAnswer(); }
00086       };
00087 
00088       class PacDiscoverTimeout : public AAA_Action<PANA_Client> {
00089         virtual void operator()(PANA_Client &c) { c.RetryDiscover(); }
00090       };
00091 
00092       class PacStartAnswerTimeout : public AAA_Action<PANA_Client> {
00093         virtual void operator()(PANA_Client &c) { c.RetryStartAnswer(); }
00094       };
00095 
00096       class PacSessionTimeout : public AAA_Action<PANA_Client> {
00097         virtual void operator()(PANA_Client &c) { c.Disconnect(PANA_SESSION_TIMEOUT); }
00098       };
00099 
00100       class PacReAuthRequestTimeout : public AAA_Action<PANA_Client> {
00101         virtual void operator()(PANA_Client &c) { c.RetryReAuthenticateRequest(); }
00102       };
00103 
00104       class PacTermRequestTimeout : public AAA_Action<PANA_Client> {
00105         virtual void operator()(PANA_Client &c) { c.RetryTerminationRequest(); }
00106       };
00107     
00108       class PacRetryTimeout : public AAA_Action<PANA_Client> {
00109         virtual void operator()(PANA_Client &c) { c.Disconnect(PANA_RETRY_TIMEOUT); }
00110       };
00111 
00112       typedef AAA_NullAction<PANA_Client> PacNullAction;
00113 
00114       PANA_ClientStateTable() {
00115 
00116         AddStateTableEntry(PANA_ST_OFFLINE, PANA_SIG_AUTH_USER,
00117                            PANA_ST_DISCOVER, m_acSendDiscover);
00118 
00119         AddStateTableEntry(PANA_ST_OFFLINE, PANA_RX_START_REQUEST,
00120                            PANA_ST_WAIT_PAA, m_acReceiveStartRequest);
00121 
00122         AddWildcardStateTableEntry(PANA_ST_OFFLINE, PANA_ST_OFFLINE);
00123         
00124         AddStateTableEntry(PANA_ST_DISCOVER, PANA_RX_START_REQUEST,
00125                            PANA_ST_WAIT_PAA, m_acReceiveStartRequest);
00126 
00127         AddStateTableEntry(PANA_ST_DISCOVER, PANA_TM_DISCOVER_TIMEOUT,
00128                            PANA_ST_DISCOVER, m_acDiscoverTimeout);
00129 
00130         AddStateTableEntry(PANA_ST_DISCOVER, PANA_TM_DISCONNECT,
00131                            PANA_ST_OFFLINE, m_acRetryTimeout);
00132 
00133         AddWildcardStateTableEntry(PANA_ST_DISCOVER, PANA_ST_DISCOVER);
00134         
00135         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_RX_AUTH_REQUEST,
00136                            PANA_ST_WAIT_PAA, m_acReceiveAuthRequest);
00137 
00138         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_TM_DISCOVER_TIMEOUT,
00139                            PANA_ST_WAIT_PAA, m_acDiscoverTimeout);
00140 
00141         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_TM_STARTANSR_TIMEOUT,
00142                            PANA_ST_WAIT_PAA, m_acStartAnswerTimeout);
00143 
00144         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_TM_DISCONNECT,
00145                            PANA_ST_OFFLINE, m_acRetryTimeout);
00146 
00147         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_RX_BIND_FAILURE,
00148                            PANA_ST_OFFLINE, m_acReceiveBindRequest);
00149 
00150         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_RX_BIND_FIRST,
00151                            PANA_ST_SECOND_EAP, m_acReceiveBindRequest);
00152 
00153         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_RX_BIND_FINAL,
00154                            PANA_ST_OPEN, m_acReceiveBindRequest);
00155 
00156         AddStateTableEntry(PANA_ST_WAIT_PAA, PANA_RX_REAUTH_REQUEST,
00157                            PANA_ST_OPEN, m_acReceiveReAuthRequest);
00158 
00159         AddWildcardStateTableEntry(PANA_ST_WAIT_PAA, PANA_ST_WAIT_PAA);
00160         
00161         AddStateTableEntry(PANA_ST_SECOND_EAP, PANA_RX_AUTH_REQUEST,
00162                            PANA_ST_WAIT_PAA, m_acReceiveAuthRequest);
00163 
00164         AddWildcardStateTableEntry(PANA_ST_SECOND_EAP, PANA_ST_SECOND_EAP);
00165         
00166         AddStateTableEntry(PANA_ST_OPEN, PANA_RX_AUTH_REQUEST,
00167                            PANA_ST_WAIT_PAA, m_acReceiveEapReAuthRequest);
00168 
00169         AddStateTableEntry(PANA_ST_OPEN, PANA_RX_REAUTH_REQUEST,
00170                            PANA_ST_OPEN, m_acReceiveReAuthRequest);
00171 
00172         AddStateTableEntry(PANA_ST_OPEN, PANA_SIG_REAUTH_PAA,
00173                            PANA_ST_WAIT_REAUTH_ANSWER, m_acSendReAuthRequest);
00174 
00175         AddStateTableEntry(PANA_ST_OPEN, PANA_SIG_TERMINATE_SESSION,
00176                            PANA_ST_SESSION_TERMINATION, m_acSendTermRequest);
00177 
00178         AddStateTableEntry(PANA_ST_OPEN, PANA_RX_TERM_REQUEST,
00179                            PANA_ST_OFFLINE, m_acReceiveTermRequest);
00180 
00181         AddStateTableEntry(PANA_ST_OPEN, PANA_TM_SESSION_TIMEOUT,
00182                            PANA_ST_OFFLINE, m_acSessionTimeout);
00183 
00184         AddStateTableEntry(PANA_ST_OPEN, PANA_SIG_EAP_REAUTH,
00185                            PANA_ST_WAIT_PAA, m_acSendDiscover);
00186 
00187         AddWildcardStateTableEntry(PANA_ST_OPEN, PANA_ST_OPEN);
00188         
00189         AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_RX_REAUTH_ANSWER,
00190                            PANA_ST_OPEN, m_acReceiveReAuthAnswer);
00191 
00192         AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_TM_REAUTHREQ_TIMEOUT,
00193                            PANA_ST_WAIT_REAUTH_ANSWER, m_acReAuthRequestTimeout);
00194 
00195         AddStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_TM_DISCONNECT,
00196                            PANA_ST_OFFLINE, m_acRetryTimeout);
00197 
00198         AddWildcardStateTableEntry(PANA_ST_WAIT_REAUTH_ANSWER, PANA_ST_WAIT_REAUTH_ANSWER);
00199         
00200         AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_RX_TERM_ANSWER,
00201                            PANA_ST_OFFLINE, m_acReceiveTermAnswer);
00202 
00203         AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_TM_SESSION_TIMEOUT,
00204                            PANA_ST_OFFLINE, m_acSessionTimeout);
00205 
00206         AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_TM_TERMREQ_TIMEOUT,
00207                            PANA_ST_SESSION_TERMINATION, m_acTermRequestTimeout);
00208 
00209         AddStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_TM_DISCONNECT,
00210                            PANA_ST_OFFLINE, m_acRetryTimeout);
00211 
00212         AddWildcardStateTableEntry(PANA_ST_SESSION_TERMINATION, PANA_ST_SESSION_TERMINATION);
00213         
00214         InitialState(PANA_ST_OFFLINE);
00215       }
00216 
00217    private:
00218       PacSendDiscover             m_acSendDiscover;
00219       PacReceiveStartRequest      m_acReceiveStartRequest;
00220       PacReceiveBindRequest       m_acReceiveBindRequest;
00221       PacReceiveAuthRequest       m_acReceiveAuthRequest;
00222       PacReceiveEapReAuthRequest  m_acReceiveEapReAuthRequest;
00223       PacSendReAuthRequest        m_acSendReAuthRequest;
00224       PacReceiveReAuthRequest     m_acReceiveReAuthRequest;
00225       PacReceiveReAuthAnswer      m_acReceiveReAuthAnswer;
00226       PacSendTermRequest          m_acSendTermRequest;
00227       PacReceiveTermRequest       m_acReceiveTermRequest;
00228       PacReceiveTermAnswer        m_acReceiveTermAnswer;
00229       PacDiscoverTimeout          m_acDiscoverTimeout;
00230       PacStartAnswerTimeout       m_acStartAnswerTimeout;
00231       PacReAuthRequestTimeout     m_acReAuthRequestTimeout;
00232       PacSessionTimeout           m_acSessionTimeout;
00233       PacTermRequestTimeout       m_acTermRequestTimeout;
00234       PacRetryTimeout             m_acRetryTimeout;
00235       PacNullAction               m_acNullAction;
00236 };
00237 
00238 class PANA_EXPORT PANA_PacSession : public PANA_StateMachine<PANA_Client>
00239 {
00240    public:
00241       PANA_PacSession(PANA_Node &n, PANA_ClientEventInterface &eif) :
00242          PANA_StateMachine<PANA_Client>(m_Client, m_StateTable, n, m_Udp),
00243          m_Client(m_TxChannel, m_Timer, eif),
00244          m_Node(n),
00245          m_Udp(n.Job(), "Pac UDP Channel") {
00246           
00247          AAA_SCSIAdapter1<PANA_PacSession, 
00248                            void(PANA_PacSession::*)(PANA_Message&),
00249                            PANA_Message&> 
00250                      msgHandler(*this, &PANA_PacSession::Receive);
00251          AAA_SCSIAdapter1<PANA_PacSession, 
00252                            void(PANA_PacSession::*)(int), 
00253                            int> 
00254                      errHandler(*this, &PANA_PacSession::Error);
00255          
00256          ACE_INET_Addr addr((u_short)PANA_CONFIG_GENERAL().listen_port_);
00257          m_Udp.Open(addr);
00258          m_Udp.RegisterHandler(msgHandler);
00259          m_Udp.RegisterHandler(errHandler);
00260          
00261          InitializeMsgMaps();
00262          PANA_StateMachine<PANA_Client>::Start(); 
00263       }
00264       virtual ~PANA_PacSession() { 
00265          PANA_StateMachine<PANA_Client>::Stop(); 
00266          FlushMsgMaps(); 
00267          m_Udp.Close();
00268          m_Udp.RemoveHandler();
00269       }
00270       virtual void Start() throw (AAA_Error) { 
00271          Notify(PANA_SIG_AUTH_USER);
00272       }
00273       virtual void SendEapResponse(AAAMessageBlock *response) {
00274          m_Client.SendEapMessage(response);
00275       }
00276       virtual void EapReAuthenticate() {
00277          Notify(PANA_SIG_EAP_REAUTH);
00278       }
00279       virtual void ReAuthenticate() {
00280          Notify(PANA_SIG_REAUTH_PAA);
00281       }
00282       virtual void Bind() {
00283          m_Client.SendBindAnswer();
00284       }
00285       virtual void Bind(diameter_octetstring_t &msk) {
00286          m_Client.MSK(msk);
00287          Bind();
00288       }
00289       PANA_CfgProviderInfo &PreferedISP() {
00290           return m_Client.PreferedISP();
00291       }
00292       PANA_CfgProviderInfo &PreferedNAP() {
00293           return m_Client.PreferedNAP();
00294       }
00295       virtual void Stop() { 
00296          m_Client.m_TerminationCause = PANA_TC_LOGOUT;
00297          Notify(PANA_SIG_TERMINATE_SESSION); 
00298       }
00299       virtual bool IsSessionResumption() {
00300           switch (state) {
00301               case PANA_ST_WAIT_PAA:
00302                   return (PANA_CONFIG_GENERAL().mobility_ > 0) ?
00303                       true : false;
00304               case PANA_ST_OPEN: return true;
00305               default: return false;
00306           }
00307       }
00308       virtual PANA_DeviceId *PeerDeviceId() {
00309           return m_Client.PeerDeviceId();
00310       }
00311       virtual std::string &CurrentInterface() {
00312           return PANA_CONFIG_GENERAL().iface_name_;
00313       }
00314 
00315    private:
00316       virtual void InitializeMsgMaps();
00317       virtual void FlushMsgMaps();
00318 
00319       static PANA_ClientStateTable m_StateTable;
00320       PANA_Client m_Client;
00321       PANA_Node &m_Node;
00322       PANA_UdpChannel m_Udp;
00323 };
00324 
00325 #endif // __PANA_CLIENT_FSM_H__

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5