Main Page | Class List | Directories | File List | Class Members

diameter_mip4_ha_server_session.hxx

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 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 /* 
00036    diameter_mip4_ha_server_session.hxx
00037    HA Server Session definition for Diameter MIP4 Application 
00038    Written by Miriam Tauil
00039    Created December 20th, 2004.
00040 */
00041 
00042 #ifndef __MIP4_HA_SERVER_SESSION_H__
00043 #define __MIP4_HA_SERVER_SESSION_H__
00044 
00045 #include <string>
00046 #include <list>
00047 #include "ace/Synch.h"
00048 #include "diameter_api.h"
00049 #include "diameter_mip4_parser.hxx"
00050 #include "diameter_mip4_ha_server_fsm.hxx"
00051 //#include "diameter_mip4_ha_server_interface.hxx"
00052 
00056 
00057 template<class SpecificHaServerSession > 
00058 class DIAMETER_MIP4_HA_SERVER_EXPORTS DiameterMip4HaServerSession : 
00059   public AAAServerSession, public DiameterMip4HaServerStateMachine
00060 {
00061  public:
00062 
00064   //class DIAMETER_MIP4_HA_SERVER_EXPORTS HAR_Handler:public AAASessionMessageHandler
00065 class HAR_Handler:public AAASessionMessageHandler
00066   {
00067   public:
00068     HAR_Handler(AAAApplicationCore &appCore, 
00069                 DiameterMip4HaServerSession<SpecificHaServerSession >  &s) 
00070       : AAASessionMessageHandler(appCore, MipHarCommandCode),
00071         session(s)
00072     {}
00073   private:
00074     DiameterMip4HaServerSession<SpecificHaServerSession >  &session;
00075     AAAReturnCode HandleMessage (AAAMessage &msg)
00076     {
00077 
00078       // Header flag check.
00079       if (!msg.hdr.flags.r)
00080         {
00081           AAA_LOG(LM_ERROR, "[%N] Received HAA instead of HAR.\n");
00082           return AAA_ERR_UNKNOWN_CMD;
00083         }
00084 
00085       // Parse the received message.
00086       HAR_Parser parser;
00087       parser.setAppData(&session.harData);
00088       parser.setRawData(&msg);
00089 
00090       try {
00091         parser.parseRawToApp();
00092       }
00093       catch ( DiameterParserError ) 
00094         {
00095           AAA_LOG(LM_ERROR, "[%N] Payload error.\n");
00096           return AAA_ERR_PARSING_ERROR;
00097         }
00098 #ifdef PRINT_MSG_CONTENT
00099   printf("HAR:\nAuthorization Lifetime: %d\nMip-Reg-Request: %s\nUser Name: %s\nDestination Realm: %s\nDestination Host: %s\n\n", 
00100          session.harData.AuthorizationLifetime(), 
00101          session.harData.MipRegRequest().data(), 
00102          session.harData.UserName().data(),
00103          session.harData.DestinationRealm().data(),
00104          session.harData.DestinationHost().data() );
00105 #endif
00106        session.Notify(DiameterMip4HaServerStateMachine::EvRxHAR);
00107       
00108       return AAA_ERR_SUCCESS;
00109    
00110     }
00111   };
00112 
00114   DiameterMip4HaServerSession( AAAApplicationCore &appCore, 
00115                          diameter_unsigned32_t appId=Mip4ApplicationId):
00116     AAAServerSession(appCore, Mip4ApplicationId),  
00117     DiameterMip4HaServerStateMachine(*this, appCore.GetTask().JobHandle()),
00118     specificHaServerSession(*new SpecificHaServerSession())
00119   {
00120 
00121     requestHandler = (new HAR_Handler(appCore, *this));
00122     
00123     // Register the HAR message handler
00124     if (RegisterMessageHandler( requestHandler) != AAA_ERR_SUCCESS)
00125     {
00126       AAA_LOG(LM_ERROR, "[%N] HAR_Handler registration failed.\n");
00127       throw -1; 
00128     }
00129 
00130   }
00131 
00133   virtual ~DiameterMip4HaServerSession() 
00134   {
00135     delete (&specificHaServerSession);
00136     delete requestHandler;
00137   }
00138   
00140   DiameterMip4HaServerSession* Self() { return this; }
00141 
00143   AAAReturnCode HandleMessage(AAAMessage &msg)
00144   {
00145     AAA_LOG(LM_ERROR, "[%N] Unknown command.\n");
00146     return AAA_ERR_UNKNOWN_CMD;
00147   }
00148 
00150   AAAReturnCode HandleDisconnect()
00151   {
00152     AAA_LOG(LM_ERROR, "[%N] Session termination event received.\n");
00153     Notify(DiameterMip4HaServerStateMachine::EvSgDisconnect);
00154     return AAA_ERR_SUCCESS; 
00155   }
00156 
00158   AAAReturnCode HandleSessionTimeout()
00159   { 
00160     AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n");
00161     Notify(DiameterMip4HaServerStateMachine::EvSgSessionTimeout);
00162     return AAA_ERR_SUCCESS; 
00163   }
00164           
00166   AAAReturnCode HandleAuthLifetimeTimeout()
00167   { 
00168     AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00169     Notify(DiameterMip4HaServerStateMachine::EvSgAuthLifetimeTimeout);
00170     return AAA_ERR_SUCCESS; 
00171   }
00172                                                                                
00174   AAAReturnCode HandleAuthGracePeriodTimeout()
00175   { 
00176     AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00177     Notify(DiameterMip4HaServerStateMachine::EvSgAuthGracePeriodTimeout);
00178     return AAA_ERR_SUCCESS; 
00179   }
00180 
00182   AAAReturnCode HandleAbort() { return AAA_ERR_SUCCESS; }
00183 
00186   AAAReturnCode HandleTimeout()
00187   { 
00188     AAA_LOG(LM_ERROR, "[%N] General timeout received.\n");
00189     Notify(DiameterMip4HaServerStateMachine::EvSgTimeout);
00190     return AAA_ERR_SUCCESS; 
00191   }
00192 
00193   void Start() throw (AAA_Error)
00194   {
00195     DiameterMip4HaServerStateMachine::Start();
00196   }
00197 
00198   AAAReturnCode Reset() throw (AAA_Error)
00199   {    
00200     AAAServerSession::Reset();  //Start();
00201 
00202     //sets the session state to StInitialize
00203     DiameterMip4HaServerStateMachine::Restart();
00204    
00205     return ( specificHaServerSession.Reset() );
00206     
00207   }
00208 
00209   // implementation of the virtual functions defined in ha_session_fsm
00210   // by calling the functions of the SpecificHaServer
00211 
00212   int ProcessMipRegRequest( diameter_octetstring_t &MipRegReq )
00213   {
00214     return specificHaServerSession.ProcessMipRegRequest( MipRegReq );
00215   }
00216 
00217   int SetMipFaToHaSpi(diameter_unsigned32_t &faHaSpi)
00218   {
00219     return specificHaServerSession.SetMipFaToHaSpi( faHaSpi);
00220   }
00221 
00222   int SetMipFaToMnSpi(diameter_unsigned32_t &faMnSpi)
00223   {
00224     return specificHaServerSession.SetMipFaToMnSpi( faMnSpi);
00225   }
00226 
00227   /****
00228   int SetHaMnKey(  AAA_ScholarAttribute<diameter_octetstring_t> &mipSessionKey)
00229   {
00230     diameter_octetstring_t _mipSessionKey;
00231     int rc = specificAaaSServerSession.SetHaMnKey( _mipSessionKey);
00232     if (rc)
00233       mipSessionKey.Set( _mipSessionKey);
00234     return rc;
00235   }
00236   ********/
00237   int SetErrorMessage(AAA_ScholarAttribute<diameter_utf8string_t> &errorMessage)
00238   {
00239     diameter_utf8string_t _errorMessage;
00240     int rc;
00241     if (rc = specificHaServerSession.SetErrorMessage( _errorMessage))
00242       errorMessage.Set( _errorMessage);
00243     return rc;
00244   }
00245 
00246   int SetMipRegReply(AAA_ScholarAttribute<diameter_octetstring_t> &reply)
00247   {
00248     diameter_octetstring_t _reply="";
00249     int rc=0;
00250     if ( rc = specificHaServerSession.SetMipRegReply( _reply ))
00251       reply.Set( _reply);
00252     return rc;
00253   }
00254 
00255   // is called if MN address does not appear in HAR
00256   int SetMipMnAddress(AAA_ScholarAttribute<diameter_address_t> &address)
00257   {
00258     diameter_address_t _address;
00259     int rc;
00260     if ( rc = specificHaServerSession.SetMipMnAddress( _address) )
00261       address.Set(_address);
00262     return rc;
00263   }
00264 
00265   // Must be populated by HA
00266   int SetAcctMultiSessionId( AAA_ScholarAttribute<diameter_utf8string_t> &acctMultiSessionId)
00267   {
00268     diameter_utf8string_t _acctMultiSessionId;
00269     int rc;
00270     if ( rc =
00271          specificHaServerSession.SetAcctMultiSessionId( _acctMultiSessionId))
00272       acctMultiSessionId.Set( _acctMultiSessionId);
00273     return rc;
00274   }
00275 
00276   HAR_Data harData;
00277   HAA_Data haaData;
00278 
00279   HAR_Data& HAR() { return harData; }
00280   HAA_Data& HAA() { return haaData; }
00281 
00282  protected:
00283  private:
00284 
00285   SpecificHaServerSession &specificHaServerSession;
00286 
00287   HAR_Handler *requestHandler;
00288 
00289 };
00290 
00291 #endif

Generated on Thu Apr 7 09:08:51 2005 for Diameter Mobile IP v4 C++ API by  doxygen 1.4.2