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

pana_session.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 
00035 #ifndef __PANA_SESSION_H__
00036 #define __PANA_SESSION_H__
00037 
00038 #include <string>
00039 #include "ace/Atomic_Op.h"
00040 #include "pana_exports.h"
00041 #include "pana_exceptions.h"
00042 #include "pana_device_id.h"
00043 #include "pana_security_assoc.h"
00044 #include "pana_config_manager.h"
00045 #include "pana_retransmission.h"
00046 
00050 class PANA_SessionAttribute {
00051 
00052     public:
00053        PANA_SessionAttribute();
00054 
00055        virtual ~PANA_SessionAttribute();
00056 
00057        virtual void Reset();
00058 
00059        std::string m_SessionId;                
00061        PANA_DeviceIdContainer m_PeerDeviceId;  
00063        PANA_DeviceId::TYPE m_ReqDeviceId;      
00065        ACE_UINT32 m_InitialPacTsec;            
00067        ACE_UINT32 m_InitialPaaTsec;            
00069        ACE_UINT32 m_LastTransmittedTsec;       
00071        ACE_UINT32 m_LastReceivedTsec;          
00073        ACE_UINT32 m_LastReceivedRsec;          
00075        ACE_UINT32 m_SessionLifetime;           
00077        ACE_UINT32 m_PeerPort;                  
00079        ACE_UINT32 m_BindCount;                 
00081        ACE_UINT32 m_BindResult[PANA_BIND_COUNT_MAX]; 
00083        ACE_UINT32 m_TerminationCause;          
00085        AAAMessageBlock *m_LastPayload;         
00087        PANA_CfgProviderInfo m_PreferedISP;     
00089        PANA_CfgProviderInfo m_PreferedNAP;     
00091        bool m_SeparateAuth;                    
00093        std::list<PANA_Message*> m_RxMessageQueue; 
00094 };
00095 
00096 typedef enum {
00097   PANA_TIMER_TYPE_SESSION = 0,
00098   PANA_TIMER_TYPE_RETRY
00099 } PANA_TIMER_TYPE;
00100 
00101 typedef enum {
00102   PANA_TC_INVALID = 0,
00103   PANA_TC_LOGOUT = 1,
00104   PANA_TC_ADMINISTRATIVE = 4,
00105   PANA_TC_SESSION_TIMEOUT = 8
00106 } PANA_TERMINATION_CAUSE;
00107 
00108 typedef enum {
00109   PANA_BIND_INVALID = 0,
00110   PANA_BIND_SUCCESS_INITIAL,
00111   PANA_BIND_SUCCESS_FINAL,
00112   PANA_BIND_INTERIM,
00113   PANA_BIND_FAILED,
00114 } PANA_BIND_RESULT;
00115 
00116 typedef enum {
00117   PANA_TID_SESSION = 1,
00118   PANA_TID_DISC_RETRY,
00119   PANA_TID_PSA_RETRY,
00120   PANA_TID_PBR_RETRY,
00121   PANA_TID_PRAR_RETRY,
00122   PANA_TID_PTR_RETRY,
00123   PANA_TID_DISCONNECT
00124 } PANA_TID;
00125 
00126 typedef enum {
00127   PANA_REAUTH_EAP,
00128   PANA_REAUTH_PANA
00129 } PANA_REAUTH;
00130 
00131 template<class ARG>
00132 class PANA_EXPORT PANA_SessionRxInterface
00133 {
00134    public:
00135       PANA_SessionRxInterface(ARG &arg) : m_arg(arg) { }
00136       virtual void operator()(PANA_Message &msg) = 0;
00137       virtual PANA_SessionRxInterface<ARG> *clone() = 0;
00138    protected:
00139       ARG &m_arg;
00140 };
00141 
00142 template<class ARG>
00143 class PANA_EXPORT PANA_SessionRxInterfaceTable : public AAA_Job
00144 {
00145    public:
00146       PANA_SessionRxInterfaceTable(AAA_GroupedJob &jobQ) :
00147          m_GroupedJob(jobQ) { }
00148       virtual ~PANA_SessionRxInterfaceTable() { }
00149 
00150       virtual void Register(int mtype, PANA_SessionRxInterface<ARG> &i) {
00151          m_map.insert(std::pair<int, PANA_SessionRxInterface<ARG>*>
00152                       (mtype, i.clone()));
00153       }
00154       virtual void Remove(int type) { 
00155          typename std::map<int, PANA_SessionRxInterface<ARG>*>::iterator i =
00156              m_map.find(type); 
00157          if (i != m_map.end()) {
00158             delete static_cast<PANA_SessionRxInterface<ARG>*>
00159                 (i->second);
00160             m_map.erase(i);
00161          }
00162       }
00163       void Receive(PANA_Message &msg) {
00164          m_rxSchedulingQueue.push_back(&msg);
00165          Schedule(this);
00166       }
00167 
00168    protected:
00169       std::map<int, PANA_SessionRxInterface<ARG>*> m_map;
00170       std::list<PANA_Message*> m_rxSchedulingQueue;
00171       AAA_GroupedJob &m_GroupedJob;
00172 
00173    private:
00174       virtual int Serve() {
00175          PANA_Message &msg = (*m_rxSchedulingQueue.front()); 
00176          m_rxSchedulingQueue.pop_front();
00177 
00178          typename std::map<int, PANA_SessionRxInterface<ARG>*>::iterator i =
00179              m_map.find(msg.type());
00180          if (i != m_map.end()) {
00181             PANA_SessionRxInterface<ARG> *h = i->second;
00182             try {
00183                (*h)(msg);
00184             }
00185             catch (PANA_Exception &e) {
00186                delete &msg;
00187                ACE_DEBUG((LM_INFO, "(%P|%t) ERROR: code = %d, desc = %s\n",
00188                         e.code(), e.description().data()));
00189             }
00190             catch (...) {
00191                delete &msg;
00192                ACE_DEBUG((LM_INFO, "(%P|%t) ERROR: Unknown exception\n"));
00193             }
00194          }
00195          return (0);
00196       }
00197       virtual int Schedule(AAA_Job* job, size_t backlogSize = 1) {
00198          return m_GroupedJob.Schedule(job, backlogSize);
00199       }
00200 };
00201 
00202 class PANA_Session;
00203 class PANA_EXPORT PANA_SessionTxInterface
00204 {
00205    public:
00206       PANA_SessionTxInterface() { }
00207       virtual void Send(PANA_Session &s, PANA_Message &msg) = 0;
00208       virtual void GetLocalAddress(PANA_DeviceIdContainer &srcDevices) = 0;
00209 };
00210 
00211 class PANA_EXPORT PANA_SessionTimerInterface
00212 {
00213    public:
00214       virtual void Schedule(PANA_TID id, ACE_UINT32 sec) = 0;
00215       virtual void Cancel(PANA_TID id) = 0;
00216 };
00217 
00218 class PANA_EXPORT PANA_SessionEventInterface
00219 {
00220    public:
00221       virtual void AuthorizePeer(PANA_DeviceId &peer, bool reAuth) = 0;
00222       virtual void ReAuthentication(PANA_REAUTH cause) = 0;
00223       virtual void Disconnect(ACE_UINT32 cause = 0) = 0;
00224       virtual void Error(ACE_UINT32 resultCode) = 0;
00225 };
00226 
00227 class PANA_EXPORT PANA_Session : public PANA_SessionAttribute
00228 {
00229    public:
00230       virtual void ValidateMessage(PANA_Message &msg);
00231       virtual void DestinationAddressFormatting(PANA_Message &msg,
00232                               AAAMessageBlock *eapPayload = NULL);
00233 
00234       virtual void SendReAuthenticateRequest();
00235       virtual void RetryReAuthenticateRequest();
00236       virtual void ReceiveReAuthenticateRequest();
00237 
00238       virtual void SendReAuthenticateAnswer();
00239       virtual void ReceiveReAuthenticateAnswer();
00240 
00241       virtual void SendTerminationRequest();
00242       virtual void RetryTerminationRequest();
00243       virtual void ReceiveTerminationRequest();
00244 
00245       virtual void SendTerminationAnswer();
00246       virtual void ReceiveTerminationAnswer();
00247 
00248       virtual void SendErrorMessage(ACE_UINT32 rcode,
00249                                     AAAAvpContainer *failedAvp);
00250       virtual void ReceiveErrorMessage(PANA_Message &msg);
00251 
00252       virtual void ReAuthenticate(PANA_REAUTH cause);
00253       virtual void Disconnect(ACE_UINT32 cause = 0);
00254 
00255       virtual PANA_BIND_RESULT BindResult();
00256       virtual PANA_BIND_RESULT BindResult(int rcode);
00257       virtual void BindResultReset();
00258     
00259       virtual PANA_DeviceId *PeerDeviceId() {
00260           return m_PeerDeviceId.search(m_ReqDeviceId);
00261       }
00262       PANA_CfgProviderInfo &PreferedISP() {
00263           return m_PreferedISP;
00264       }
00265       PANA_CfgProviderInfo &PreferedNAP() {
00266           return m_PreferedNAP;
00267       }
00268       PANA_SecurityAssociation &SA() { 
00269           return m_SA; 
00270       }
00271 
00272       virtual void Reset();
00273 
00274    protected:
00275       PANA_Session(PANA_SessionTxInterface &tp,
00276                    PANA_SessionTimerInterface &tm,
00277                    PANA_SessionEventInterface &ev) :
00278          PANA_SessionAttribute(), m_TxChannel(tp),
00279          m_Timer(tm), m_Event(ev),
00280          m_InStatefulDiscovery(false) { }
00281       virtual ~PANA_Session() { }
00282 
00283       PANA_SecurityAssociation m_SA;
00284       PANA_SessionTxInterface &m_TxChannel;
00285       PANA_SessionTimerInterface &m_Timer;
00286       PANA_SessionEventInterface &m_Event;
00287       PANA_RtQueue m_RtQueue;
00288       bool m_InStatefulDiscovery;
00289 };
00290 
00291 #endif /* __PANA_SESSION_H__ */
00292 

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