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_FA_CLIENT_SESSION_H__
00040 #define __MIP4_FA_CLIENT_SESSION_H__
00041
00042
00043 #include <list>
00044 #include "ace/Synch.h"
00045 #include "diameter_api.h"
00046 #include "diameter_mip4_fa_client_fsm.hxx"
00047 #include "diameter_mip4_parser.hxx"
00048 #include "mip4_diameter_fa_client_interface.hxx"
00049
00050
00055 template<class SpecificFaClientSession >
00056 class DIAMETER_MIP4_FA_CLIENT_EXPORTS DiameterMip4FaClientSession :
00057 public AAAClientSession, public DiameterMip4FaClientStateMachine,
00058 public Mip4DiameterFaClientInterface
00059 {
00060 public:
00061
00062 class DIAMETER_MIP4_FA_CLIENT_EXPORTS AMA_Handler :
00063 public AAASessionMessageHandler
00064 {
00065 public:
00066 AMA_Handler(AAAApplicationCore &appCore,
00067 DiameterMip4FaClientSession<SpecificFaClientSession> &s)
00068 : AAASessionMessageHandler(appCore, MipAmrCommandCode),
00069 session(s)
00070 {}
00071
00072 private:
00073 DiameterMip4FaClientSession<SpecificFaClientSession> &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(DiameterMip4FaClientStateMachine::EvRxAMA);
00100 return AAA_ERR_SUCCESS;
00101 }
00102
00103 };
00104
00106 DiameterMip4FaClientSession(AAAApplicationCore &appCore):
00107 AAAClientSession(appCore, Mip4ApplicationId),
00108 DiameterMip4FaClientStateMachine(*this, appCore.GetTask().JobHandle()),
00109 specificFaClientSession(*new SpecificFaClientSession(*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
00122 #ifdef THIS_SHOULD_WORK_BUT_IT_DOESNT
00123 try {
00124 FaClientSession &faClientSession =
00125 dynamic_cast<FaClientSession&>(specificFaClientSession);
00126 assert (faClientSession != NULL);
00127
00128 }
00129 catch (bad_cast) {
00130 DIAMETER_LOG(LM_ERROR, "[%N] AMA_Handler registration failed.\n");
00131 throw -1;
00132 }
00133 #endif
00134 }
00135
00137 virtual ~DiameterMip4FaClientSession()
00138 {
00139 delete (&specificFaClientSession);
00140 delete answerHandler;
00141 }
00142
00143
00144
00145
00146 void RxMipRegReq( diameter_octetstring_t &mipRegReq)
00147 {
00148 amrData.MipRegRequest.Set( mipRegReq);
00149 Notify( DiameterMip4FaClientStateMachine::EvRxMipRegReq);
00150 }
00151
00152 DiameterMip4FaClientSession* Self() { return this; }
00153
00160 AAAReturnCode HandleMessage(AAAMessage &msg)
00161 {
00162 AAA_LOG(LM_ERROR, "[%N] Unknown command.\n");
00163 return AAA_ERR_UNKNOWN_CMD;
00164 }
00165
00172 AAAReturnCode HandleDisconnect()
00173 {
00174 AAA_LOG(LM_ERROR, "[%N] Session termination event received.\n");
00175 Notify(DiameterMip4FaClientStateMachine::EvSgDisconnect);
00176 return AAA_ERR_SUCCESS;
00177 }
00179 AAAReturnCode HandleSessionTimeout()
00180 {
00181 AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n");
00182 Notify(DiameterMip4FaClientStateMachine::EvSgSessionTimeout);
00183 return AAA_ERR_SUCCESS;
00184 }
00185
00187 AAAReturnCode HandleAuthLifetimeTimeout()
00188 {
00189 AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00190 Notify(DiameterMip4FaClientStateMachine::EvSgAuthLifetimeTimeout);
00191 return AAA_ERR_SUCCESS;
00192 }
00193
00195 AAAReturnCode HandleAuthGracePeriodTimeout()
00196 {
00197 AAA_LOG(LM_ERROR, "[%N] Timeout received.\n");
00198 Notify(DiameterMip4FaClientStateMachine::EvSgAuthGracePeriodTimeout);
00199 return AAA_ERR_SUCCESS;
00200 }
00201
00207 AAAReturnCode HandleTimeout()
00208 {
00209 AAA_LOG(LM_ERROR, "[%N] Session timeout received.\n");
00210 Notify(DiameterMip4FaClientStateMachine::EvSgTimeout);
00211 return AAA_ERR_SUCCESS;
00212 }
00218 AAAReturnCode HandleAbort() { return AAA_ERR_SUCCESS; }
00219
00220 void Start() throw (AAA_Error)
00221 {
00222 DiameterMip4FaClientStateMachine::Start();
00223 AAAClientSession::Start();
00224 }
00225
00226 AAAReturnCode Reset() throw (AAA_Error)
00227 {
00228 AAAClientSession::Start();
00229 amrData.Clear();
00230 amaData.Clear();
00231
00232 DiameterMip4FaClientStateMachine::Restart();
00233
00234 specificFaClientSession.Reset();
00235
00236 return AAA_ERR_SUCCESS;
00237 }
00238
00239
00240
00241
00242
00243 virtual void Abort(){}
00244
00245 void SetUserName(AAA_ScholarAttribute<diameter_utf8string_t> &userName)
00246 {
00247 diameter_utf8string_t _userName;
00248 specificFaClientSession.SetUserName( _userName);
00249 userName.Set( _userName);
00250 }
00251
00254 virtual void SetDestinationRealm
00255 (AAA_ScholarAttribute<diameter_utf8string_t> &destinationRealm)
00256 {
00257 diameter_utf8string_t _destinationRealm;
00258 specificFaClientSession.SetDestinationRealm( _destinationRealm);
00259 destinationRealm.Set( _destinationRealm);
00260 }
00261
00262
00263
00264 void SetMipMnAaaAuth
00265 (AAA_ScholarAttribute<mip_mn_aaa_auth_info_t> &mipMnAaaAuth)
00266 {
00267
00268 AAA_ScholarAttribute<mip_mn_aaa_auth_info_t> _mipMnAaaAuth;
00269
00270 specificFaClientSession.SetMipMnAaaSpi(
00271 &( _mipMnAaaAuth().MipMnAaaSpi() ));
00272 specificFaClientSession.SetMipAuthInputDataLength(
00273 &(_mipMnAaaAuth().MipAuthInputDataLength() ));
00274 specificFaClientSession.SetMipAuthenticatorLength(
00275 &( _mipMnAaaAuth().MipAuthenticatorLength() ));
00276 specificFaClientSession.SetMipAuthenticatorOffset(
00277 &( _mipMnAaaAuth().MipAuthenticatorOffset() ));
00278
00279
00280 mipMnAaaAuth.Set( _mipMnAaaAuth());
00281
00282 mipMnAaaAuth().MipMnAaaSpi = _mipMnAaaAuth().MipMnAaaSpi();
00283
00284 mipMnAaaAuth().MipAuthInputDataLength =
00285 _mipMnAaaAuth().MipAuthInputDataLength();
00286 mipMnAaaAuth().MipAuthenticatorLength =
00287 _mipMnAaaAuth().MipAuthenticatorLength();
00288 mipMnAaaAuth().MipAuthenticatorOffset =
00289 _mipMnAaaAuth().MipAuthenticatorOffset();
00290
00291 }
00292
00293
00294
00297 void SetDestinationHost
00298 (AAA_ScholarAttribute<diameter_utf8string_t> &destinationHost)
00299 {
00300 diameter_utf8string_t _destinationHost;
00301 specificFaClientSession.SetDestinationHost( _destinationHost);
00302 destinationHost.Set(_destinationHost);
00303 }
00304
00305 void SetMipMobileNodeAddress
00306 (AAA_ScholarAttribute<diameter_address_t> &mipMobileNodeAddress)
00307 {
00308 diameter_address_t _mipMobileNodeAddress;
00309 specificFaClientSession.SetMipMobileNodeAddress(_mipMobileNodeAddress);
00310 mipMobileNodeAddress.Set(_mipMobileNodeAddress);
00311 }
00312
00313 void SetMipHomeAgentAddress
00314 (AAA_ScholarAttribute<diameter_address_t> &mipHomeAgentAddress)
00315 {
00316 diameter_address_t _mipHomeAgentAddress;
00317 specificFaClientSession.SetMipHomeAgentAddress(_mipHomeAgentAddress);
00318 mipHomeAgentAddress.Set(_mipHomeAgentAddress);
00319 }
00320
00321 int IsMnHaKeyRequested()
00322 {
00323 return ( specificFaClientSession.IsMnHaKeyRequested() );
00324 }
00325
00326 int IsMnFaKeyRequested()
00327 {
00328 return ( specificFaClientSession.IsMnFaKeyRequested() );
00329 }
00330 int IsFaHaKeyRequested()
00331 {
00332 return ( specificFaClientSession.IsFaHaKeyRequested() );
00333 }
00334 int IsMnHomeAddrRequested()
00335 {
00336 return ( specificFaClientSession.IsMnHomeAddrRequested() );
00337 }
00338 int IsMnHomeAgentRequested()
00339 {
00340 return ( specificFaClientSession.IsMnHomeAgentRequested() );
00341 }
00342
00343 void SetAuthorizationLifetime
00344 (AAA_ScholarAttribute<diameter_unsigned32_t> &authorizationLifetime)
00345 {
00346 diameter_unsigned32_t _authorizationLifetime;
00347 if ( specificFaClientSession.SetAuthorizationLifetime(
00348 &_authorizationLifetime) == 0 )
00349 authorizationLifetime.Set(0);
00350 else
00351 authorizationLifetime.Set(_authorizationLifetime);
00352 }
00353
00354
00355
00356
00357
00358
00359 void SetMipHomeAgentHost
00360 (AAA_ScholarAttribute<mip_home_agent_host_info_t> &mipHomeAgentHost)
00361 {
00362
00363 diameter_identity_t _mipHomeAgentHost;
00364 if (specificFaClientSession.SetMipHomeAgentHost(_mipHomeAgentHost)==1)
00365 {
00366
00367
00368
00369 }
00370
00371
00372 }
00373
00374 virtual int SetMipFaChallenge
00375 (AAA_ScholarAttribute<diameter_octetstring_t> &mipFaChallenge)
00376 {
00377 diameter_octetstring_t _mipFaChallenge;
00378
00379 int rc = specificFaClientSession.SetMipFaChallenge( _mipFaChallenge);
00380 mipFaChallenge.Set(_mipFaChallenge);
00381 return rc;
00382 }
00383
00384 virtual void SetMipCandidateHomeAgentHost
00385 (AAA_ScholarAttribute<diameter_identity_t> &mipCandidateHomeAgentHost)
00386 {}
00387
00388 virtual int SetMipHaToFaSpi
00389 (AAA_ScholarAttribute<diameter_unsigned32_t> &mipHaToFaSpi)
00390 {
00391 diameter_unsigned32_t _mipHaToFaSpi;
00392 if ( specificFaClientSession.SetMipHaToFaSpi( &_mipHaToFaSpi) == 0)
00393 {
00394 mipHaToFaSpi.Set(0);
00395 return 0;
00396 }
00397 else
00398 {
00399 mipHaToFaSpi.Set( _mipHaToFaSpi);
00400 return 1;
00401 }
00402 }
00403
00404 void EnforceAuthorizationLifetime
00405 (const diameter_unsigned32_t &authorizationLifetime)
00406 {
00407 specificFaClientSession.EnforceAuthorizationLifetime(authorizationLifetime);
00408 }
00409
00410 void EnforceAuthSessionState( const diameter_enumerated_t &authSessionState)
00411 {
00412 specificFaClientSession.EnforceAuthSessionState( authSessionState);
00413 }
00414
00415 void EnforceReAuthRequestType( const diameter_enumerated_t &reAuthReqType)
00416 {
00417 specificFaClientSession.EnforceReAuthRequestType( reAuthReqType);
00418 }
00419
00420 void EnforceMipMnToFaMsa(const mip_mn_to_fa_msa_info_t &mipMnToFaMsa)
00421 {
00422 specificFaClientSession.EnforceMipMnToFaMsa( mipMnToFaMsa);
00423 }
00424
00425 void EnforceMipMnToHaMsa( const mip_mn_to_ha_msa_info_t &mipMnToHaMsa)
00426 {
00427 specificFaClientSession.EnforceMipMnToHaMsa( mipMnToHaMsa);
00428 }
00429
00430 void EnforceMipFaToMnMsa( const mip_fa_to_mn_msa_info_t &mipFaToMnMsa)
00431 {
00432 specificFaClientSession.EnforceMipFaToMnMsa( mipFaToMnMsa);
00433 }
00434
00435 void EnforceMipFaToHaMsa( const mip_fa_to_ha_msa_info_t &mipFaToHaMsa)
00436 {
00437 specificFaClientSession.EnforceMipFaToHaMsa( mipFaToHaMsa);
00438 }
00439
00440 void EnforceMipHaToMnMsa( const mip_ha_to_mn_msa_info_t &mipHaToMnMsa)
00441 {
00442 specificFaClientSession.EnforceMipHaToMnMsa( mipHaToMnMsa);
00443 }
00444
00445 void EnforceMipMsaLifetime( const diameter_unsigned32_t &mipMsaLifetime)
00446 {
00447 specificFaClientSession.EnforceMipMsaLifetime( mipMsaLifetime);
00448 }
00449
00450 void EnforceErrorMessage( const diameter_utf8string_t &errorMessage)
00451 {
00452 specificFaClientSession.EnforceErrorMessage( errorMessage);
00453 }
00454
00455 void EnforceMipFilterRule (
00456 const AAA_VectorAttribute<diameter_ipfilter_rule_t> &mipFilterRule)
00457
00458 {
00459 specificFaClientSession.EnforceMipFilterRule( mipFilterRule);
00460 }
00461
00462 void SendMipRegReply(diameter_unsigned32_t &amaResultCode)
00463 {
00464 specificFaClientSession.SendMipRegReply( amaResultCode);
00465 }
00466
00467
00468 void SendMipRegReply( diameter_unsigned32_t &amaResultCode,
00469 diameter_octetstring_t &mipRegReply)
00470 {
00471 specificFaClientSession.SendMipRegReply( amaResultCode, mipRegReply);
00472 }
00473
00474
00475 AMR_Data& AMR() { return amrData; }
00476 AMA_Data& AMA() { return amaData; }
00477
00478 SpecificFaClientSession &specificFaClientSession;
00479
00480 protected:
00481 private:
00482
00483 AMR_Data amrData;
00484 AMA_Data amaData;
00485 AMA_Handler *answerHandler;
00486
00487 };
00488
00489
00490 #endif // __MIP4_FA_CLIENT_SESSION_H__