00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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
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
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
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
00146
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
00233 DiameterMip4HaClientStateMachine::Restart();
00234
00235 specificHaClientSession.Reset();
00236
00237 return AAA_ERR_SUCCESS;
00238 }
00239
00240
00241
00242
00243
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
00256
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
00271
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
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
00339
00340
00341
00342
00343 void SetMipHomeAgentHost
00344 (AAA_ScholarAttribute<mip_home_agent_host_info_t> &mipHomeAgentHost)
00345 {
00346
00347 diameter_identity_t _mipHomeAgentHost;
00348 if (specificHaClientSession.SetMipHomeAgentHost(_mipHomeAgentHost)==1)
00349 {
00350
00351
00352
00353 }
00354
00355
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__