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
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
00052
00056
00057 template<class SpecificHaServerSession >
00058 class DIAMETER_MIP4_HA_SERVER_EXPORTS DiameterMip4HaServerSession :
00059 public AAAServerSession, public DiameterMip4HaServerStateMachine
00060 {
00061 public:
00062
00064
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
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
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
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();
00201
00202
00203 DiameterMip4HaServerStateMachine::Restart();
00204
00205 return ( specificHaServerSession.Reset() );
00206
00207 }
00208
00209
00210
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
00229
00230
00231
00232
00233
00234
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
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
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