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

diameter_mip4_ha_client_session.hxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* OpenDiameter: Open-source software for the Diameter protocol           */
00004 /*                                                                        */
00005 /* Copyright (C) 2004  Open Diameter Project.                             */
00006 /*                                                                        */
00007 /* This library is free software; you can redistribute it and/or modify   */
00008 /* it under the terms of the GNU Lesser General Public License as         */
00009 /* published by the Free Software Foundation; either version 2.1 of the   */
00010 /* License, or (at your option) any later version.                        */
00011 /*                                                                        */
00012 /* This library is distributed in the hope that it will be useful,        */
00013 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00014 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00015 /* Lesser General Public License for more details.                        */
00016 /*                                                                        */
00017 /* You should have received a copy of the GNU Lesser General Public       */
00018 /* License along with this library; if not, write to the Free Software    */
00019 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00020 /* USA.                                                                   */
00021 /*                                                                        */
00022 /* In addition, when you copy and redistribute some or the entire part of */
00023 /* the source code of this software with or without modification, you     */
00024 /* MUST include this copyright notice in each copy.                       */
00025 /*                                                                        */
00026 /* If you make any changes that are appeared to be useful, please send    */
00027 /* sources that include the changed part to                               */
00028 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00029 /* changes to one unified version of this software.                       */
00030 /*                                                                        */
00031 /* END_COPYRIGHT                                                          */
00032 /* 
00033    diameter_mip4_ha_client_session.hxx
00034    Ha Client Session definition for Diameter MIP 4 Application 
00035    Written by Miriam Tauil
00036    Created June 30, 2004.
00037 */
00038 
00039 #ifndef __MIP4_HA_CLIENT_SESSION_H__
00040 #define __MIP4_HA_CLIENT_SESSION_H__
00041 
00042 #include <string>
00043 #include <list>
00044 #include "ace/Synch.h"
00045 #include "diameter_api.h"
00046 #include "diameter_mip4_ha_client_fsm.hxx"
00047 #include "diameter_mip4_parser.hxx"
00048 #include "mip4_diameter_ha_client_interface.hxx"
00049 
00050 
00055 template<class SpecificHaClientSession > 
00056 class DIAMETER_MIP4_HA_CLIENT_EXPORTS DiameterMip4HaClientSession : 
00057   public AAAClientSession, public DiameterMip4HaClientStateMachine, 
00058   public Mip4DiameterHaClientInterface
00059 {
00060  public:
00061 
00062   class DIAMETER_MIP4_HA_CLIENT_EXPORTS AMA_Handler : 
00063     public AAASessionMessageHandler
00064   {
00065   public:
00066     AMA_Handler(AAAApplicationCore &appCore,
00067                 DiameterMip4HaClientSession<SpecificHaClientSession>  &s) 
00068       : AAASessionMessageHandler(appCore, MipAmrCommandCode),
00069         session(s)
00070     {}
00071 
00072   private:  
00073     DiameterMip4HaClientSession<SpecificHaClientSession> &session;
00074 
00075   
00076     AAAReturnCode HandleMessage (AAAMessage &msg)
00077     {
00078     // Header flag check.
00079       if (msg.hdr.flags.r)
00080         {
00081           AAA_LOG(LM_ERROR, "[%N] Received AMR instead of AMA.\n");
00082           return AAA_ERR_UNKNOWN_CMD;
00083         }
00084 
00085       // Parse the received message.
00086       AMA_Parser parser;
00087       parser.setAppData(&session.amaData);
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 
00099       session.Notify(DiameterMip4HaClientStateMachine::EvRxAMA);
00100       return AAA_ERR_SUCCESS;
00101     }
00102 
00103   };
00104 
00106   DiameterMip4HaClientSession(AAAApplicationCore &appCore): 
00107     AAAClientSession(appCore, Mip4ApplicationId),  
00108     DiameterMip4HaClientStateMachine(*this, appCore.GetTask().JobHandle()),
00109     specificHaClientSession(*new SpecificHaClientSession(*this)) 
00110   {
00111 
00112     answerHandler = (new AMA_Handler(appCore, *this));
00113     
00114     // Register the AMA message handler
00115     if (RegisterMessageHandler( answerHandler) != AAA_ERR_SUCCESS)
00116     {
00117       AAA_LOG(LM_ERROR, "[%N] AMA_Handler registration failed.\n");
00118       throw -1; 
00119     }
00120 
00121     Start();
00122     // test if SpecificHaClientSession is an HaClientSession
00123 #ifdef THIS_SHOULD_WORK_BUT_IT_DOESNT
00124     try {
00125      HaClientSession &haClientSession = 
00126        dynamic_cast<HaClientSession&>(specificHaClientSession);
00127      assert (haClientSession != NULL);
00128 
00129      }
00130      catch (bad_cast) {    
00131        DIAMETER_LOG(LM_ERROR, "[%N] AMA_Handler registration failed.\n");
00132        throw -1;
00133      }    
00134 #endif
00135 }
00136 
00138   virtual ~DiameterMip4HaClientSession() 
00139   {
00140     delete (&specificHaClientSession);
00141     delete answerHandler;
00142   }
00143 
00144 
00145   // this is a virtual fn in the parent interface, that must be implemented 
00146   // here. 
00147   void RxMipRegReq( diameter_octetstring_t &mipRegReq) 
00148   {
00149      amrData.MipRegRequest.Set( mipRegReq); 
00150      Notify(  DiameterMip4HaClientStateMachine::EvRxMipRegReq); 
00151   }
00152 
00153   DiameterMip4HaClientSession* Self() { return this; }
00154 
00161   AAAReturnCode HandleMessage(AAAMessage &msg)
00162   {
00163     AAA_LOG(LM_ERROR, "[%N] Unknown command.\n");
00164     return AAA_ERR_UNKNOWN_CMD;
00165   }
00166 
00173   AAAReturnCode HandleDisconnect()
00174   { 
00175     AAA_LOG(LM_ERROR, "[%N] Session termination event received.\n");
00176     Notify(DiameterMip4HaClientStateMachine::EvSgDisconnect);
00177     return AAA_ERR_SUCCESS; 
00178   }
00180   AAAReturnCode HandleSessionTimeout()
00181   { 
00182     AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n");
00183     Notify(DiameterMip4HaClientStateMachine::EvSgSessionTimeout);
00184     return AAA_ERR_SUCCESS; 
00185   }
00186                                      
00188   AAAReturnCode HandleAuthLifetimeTimeout()
00189   { 
00190     AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00191     Notify(DiameterMip4HaClientStateMachine::EvSgAuthLifetimeTimeout);
00192     return AAA_ERR_SUCCESS; 
00193   }
00194 
00196   AAAReturnCode HandleAuthGracePeriodTimeout()
00197   { 
00198     AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00199     Notify(DiameterMip4HaClientStateMachine::EvSgAuthGracePeriodTimeout);
00200     return AAA_ERR_SUCCESS; 
00201   }
00202 
00208   AAAReturnCode HandleTimeout()
00209   { 
00210     AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n");
00211     Notify(DiameterMip4HaClientStateMachine::EvSgTimeout);
00212     return AAA_ERR_SUCCESS; 
00213   }
00219   AAAReturnCode HandleAbort() { return AAA_ERR_SUCCESS; }
00220 
00221   void Start() throw (AAA_Error)
00222   {
00223     DiameterMip4HaClientStateMachine::Start();
00224     AAAClientSession::Start();
00225   }
00226 
00227   AAAReturnCode Reset() throw (AAA_Error)
00228   {    
00229     AAAClientSession::Start();
00230     amrData.Clear(); 
00231     amaData.Clear();
00232     //sets the session state to StInitialize
00233     DiameterMip4HaClientStateMachine::Restart();
00234    
00235     specificHaClientSession.Reset();
00236 
00237     return AAA_ERR_SUCCESS;
00238   }
00239 
00240   // The implementation of this function in a child class is optional.
00241   // The function's purpose is to provide an interface for memory deallocation
00242   // of the DiameterMip4HaClientSession, when it is allocated using the "new"
00243   // operator. More documentation in the sample application file.
00244   virtual void Abort(){}
00245 
00246  void SetUserName(AAA_ScholarAttribute<diameter_utf8string_t> &userName)
00247   {
00248     diameter_utf8string_t _userName;
00249     specificHaClientSession.SetUserName( _userName);
00250     userName.Set( _userName);
00251   }
00252 
00255   // This function is used to setup the Destination Realm, of the AAAH
00256   // by the user application. This is called currently from the main program 
00257   void SetDestinationRealm( diameter_utf8string_t _destinationRealm)
00258   {
00259      amrData.DestinationRealm.Set( _destinationRealm);
00260   }
00261 #ifdef XXX
00262    void SetDestinationRealm
00263   (AAA_ScholarAttribute<diameter_utf8string_t> &destinationRealm)
00264   {
00265     diameter_utf8string_t _destinationRealm;
00266     specificHaClientSession.SetDestinationRealm( _destinationRealm);
00267     destinationRealm.Set( _destinationRealm);
00268   }
00269 #endif
00270   // OriginHost & OriginRealm --> this will be populated from the config file
00271   //  MipRegRequest will be set by the fn RxMipregReq()
00272 
00273   void SetMipMnAaaAuth
00274     (AAA_ScholarAttribute<mip_mn_aaa_auth_info_t> &mipMnAaaAuth)
00275   {
00276 
00277     AAA_ScholarAttribute<mip_mn_aaa_auth_info_t> _mipMnAaaAuth; 
00278     
00279     specificHaClientSession.SetMipMnAaaSpi( 
00280                          &( _mipMnAaaAuth().MipMnAaaSpi() ));
00281     specificHaClientSession.SetMipAuthInputDataLength( 
00282                         &(_mipMnAaaAuth().MipAuthInputDataLength() ));
00283     specificHaClientSession.SetMipAuthenticatorLength( 
00284                         &( _mipMnAaaAuth().MipAuthenticatorLength() ));
00285     specificHaClientSession.SetMipAuthenticatorOffset( 
00286                         &( _mipMnAaaAuth().MipAuthenticatorOffset() ));
00287 
00288 
00289     mipMnAaaAuth.Set(  _mipMnAaaAuth());
00290 
00291     mipMnAaaAuth().MipMnAaaSpi = _mipMnAaaAuth().MipMnAaaSpi();
00292 
00293     mipMnAaaAuth().MipAuthInputDataLength =
00294                                      _mipMnAaaAuth().MipAuthInputDataLength();
00295     mipMnAaaAuth().MipAuthenticatorLength =
00296                                      _mipMnAaaAuth().MipAuthenticatorLength();
00297     mipMnAaaAuth().MipAuthenticatorOffset =
00298                                      _mipMnAaaAuth().MipAuthenticatorOffset();
00299 
00300   }
00301 
00302   //optional AVPs
00303 
00306   void SetDestinationHost( diameter_utf8string_t  _destinationHost)
00307   {
00308     amrData.DestinationHost.Set(_destinationHost);
00309   }
00310 
00311   void SetMipMobileNodeAddress
00312   (AAA_ScholarAttribute<diameter_address_t> &mipMobileNodeAddress)
00313   {
00314     diameter_address_t _mipMobileNodeAddress;
00315     specificHaClientSession.SetMipMobileNodeAddress(_mipMobileNodeAddress);
00316     mipMobileNodeAddress.Set(_mipMobileNodeAddress);
00317   }
00318 
00319   void SetMipHomeAgentAddress
00320   (AAA_ScholarAttribute<diameter_address_t> &mipHomeAgentAddress)
00321   {
00322     diameter_address_t _mipHomeAgentAddress;
00323     specificHaClientSession.SetMipHomeAgentAddress(_mipHomeAgentAddress);
00324     mipHomeAgentAddress.Set(_mipHomeAgentAddress);
00325   }
00326 
00327   void SetAuthorizationLifetime
00328   (AAA_ScholarAttribute<diameter_unsigned32_t> &authorizationLifetime)
00329   {
00330     diameter_unsigned32_t _authorizationLifetime;
00331     if ( specificHaClientSession.SetAuthorizationLifetime(
00332                                           &_authorizationLifetime) == 0 )
00333         authorizationLifetime.Set(0);
00334     else
00335         authorizationLifetime.Set(_authorizationLifetime);
00336   }
00337 
00338 // fn not needed=> static info
00339 // void SetAuthSessionState
00340 //  (AAA_ScholarAttribute<diameter_enumerated_t> &authSessionState) {}
00341 
00342   //int 
00343   void SetMipHomeAgentHost
00344   (AAA_ScholarAttribute<mip_home_agent_host_info_t> &mipHomeAgentHost)
00345   {
00346     //mip_home_agent_host_info_t 
00347     diameter_identity_t _mipHomeAgentHost;
00348     if (specificHaClientSession.SetMipHomeAgentHost(_mipHomeAgentHost)==1)
00349       {
00350         // convert ip address from string to unsigned32 ???
00351         //mipHomeAgentHost.DestinationHost.Set(_mipHomeAgentHost);
00352       //return 1;
00353       }
00354     //else
00355     //return 0;
00356   }
00357 
00358   void SendMipRegReply(diameter_unsigned32_t &amaResultCode)
00359   {
00360     specificHaClientSession.SendMipRegReply( amaResultCode);
00361   }
00362 
00363   int IsMnHaKeyRequested()
00364   {
00365     return ( specificHaClientSession.IsMnHaKeyRequested() );
00366   }
00367 
00368   void EnforceMipMnToFaMsa(const mip_mn_to_fa_msa_info_t &mipMnToFaMsa)
00369   {
00370     specificHaClientSession.EnforceMipMnToFaMsa( mipMnToFaMsa);
00371   }
00372   
00373   void EnforceMipMnToHaMsa( const mip_mn_to_ha_msa_info_t &mipMnToHaMsa)
00374   {
00375     specificHaClientSession.EnforceMipMnToHaMsa( mipMnToHaMsa);
00376   }
00377 
00378 
00379   void EnforceMipFaToMnMsa( const mip_fa_to_mn_msa_info_t &mipFaToMnMsa)
00380   {
00381     specificHaClientSession.EnforceMipFaToMnMsa( mipFaToMnMsa);
00382   }
00383 
00384   void EnforceMipFaToHaMsa( const mip_fa_to_ha_msa_info_t &mipFaToHaMsa)
00385   {
00386     specificHaClientSession.EnforceMipFaToHaMsa( mipFaToHaMsa);
00387   }
00388 
00389   void EnforceMipHaToMnMsa( const mip_ha_to_mn_msa_info_t &mipHaToMnMsa)
00390   {
00391     specificHaClientSession.EnforceMipHaToMnMsa( mipHaToMnMsa);
00392   }
00393 
00394   void EnforceMipMsaLifetime( const diameter_unsigned32_t &mipMsaLifetime)
00395   {
00396     specificHaClientSession.EnforceMipMsaLifetime( mipMsaLifetime);
00397   }
00398 
00399   void EnforceErrorMessage( const diameter_utf8string_t &errorMessage)
00400   {
00401     specificHaClientSession.EnforceErrorMessage( errorMessage);
00402   }
00403 
00404   AMR_Data& AMR() { return amrData; }
00405   AMA_Data& AMA() { return amaData; }
00406 
00407   SpecificHaClientSession &specificHaClientSession;
00408 
00409  protected:
00410  private:
00411   
00412   AMR_Data amrData;
00413   AMA_Data amaData;
00414   AMA_Handler *answerHandler;
00415  
00416 };
00417 
00418 
00419 #endif  // __MIP4_HA_CLIENT_SESSION_H__

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