X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;ds=sidebyside;f=example%2Fdiameter%2Flauncher%2FMyLocalServer.cpp;h=f18653fcb0c57718adc8afebf1307201ee2c91a1;hb=e782294456d0877aa8fc05aa931291ac79808eb3;hp=8127d84598d559787027741ea416fba614bc8252;hpb=4c3f0a4d7e4db76996404d80c6f939548fca656f;p=anna.git diff --git a/example/diameter/launcher/MyLocalServer.cpp b/example/diameter/launcher/MyLocalServer.cpp index 8127d84..f18653f 100644 --- a/example/diameter/launcher/MyLocalServer.cpp +++ b/example/diameter/launcher/MyLocalServer.cpp @@ -14,14 +14,14 @@ #include #include #include +#include // Process #include #include #include #include -#include -#include +#include void MyLocalServer::eventRequest(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) @@ -29,10 +29,8 @@ throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("launcher::MyLocalServer", "eventRequest", ANNA_FILE_LOCATION)); // Performance stats: Launcher& my_app = static_cast (anna::app::functions::getApp()); - RealmNode * my_node = my_app.getRealmNode(getEngine()->getRealm()); - - // Testing: - TestManager::instantiate().receiveMessage(message, serverSession); + anna::diameter::comm::OriginHost *my_node = my_app.getOriginHost(getEngine()->getOriginHostName()); + anna::diameter::codec::Engine *codecEngine = my_node->getCodecEngine(); // CommandId: anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); @@ -61,24 +59,28 @@ throw(anna::RuntimeException) { msg->forwardEndToEnd(); // end-to-end will be kept msg->setBody(message); msg->setRequestServerSessionKey(serverSession->getKey()); - bool success = entity->send(msg, my_node->getEntity()->getBalance()); + bool success = entity->send(msg); // Detailed log: if(my_node->logEnabled()) { anna::diameter::comm::Server *usedServer = entity->getLastUsedResource(); anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL; - std::string detail = usedClientSession ? usedClientSession->asString() : ""; // esto no deberia ocurrir + std::string detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // esto no deberia ocurrir my_node->writeLogFile(message, (success ? "fwd2e" : "fwd2eError"), detail); // forwarded } + + // Testing: + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); + return; } // Error analisys: bool analysisOK = true; // by default anna::diameter::codec::Message *answer_message = NULL; - anna::diameter::codec::Message codecMsg(a_codecEngine); - anna::diameter::codec::Message codecAnsMsg(a_codecEngine); + anna::diameter::codec::Message codecMsg; + anna::diameter::codec::Message codecAnsMsg; CommandLine& cl(anna::CommandLine::instantiate()); if(!cl.exists("ignoreErrors")) { // Error analysis @@ -88,7 +90,7 @@ throw(anna::RuntimeException) { // Decode try { codecMsg.decode(message, answer_message); } catch(anna::RuntimeException &ex) { ex.trace(); } - answer_message->setStandardToAnswer(codecMsg, my_node->getMyDiameterEngine()->getHost(), my_node->getMyDiameterEngine()->getRealm()); + answer_message->setStandardToAnswer(codecMsg, my_node->getCommEngine()->getOriginHostName(), my_node->getCommEngine()->getOriginRealmName()); analysisOK = (answer_message->getResultCode() == anna::diameter::helpers::base::AVPVALUES__Result_Code::DIAMETER_SUCCESS); } @@ -98,13 +100,19 @@ throw(anna::RuntimeException) { answer_message = programmed_answer; // Prepare answer: my_app.getCommunicator()->prepareAnswer(answer_message, message); - } else return; // nothing done + } else { + + // Testing: + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); + + return; // nothing done + } } - anna::diameter::codec::Engine::ValidationMode::_v backupVM = a_codecEngine->getValidationMode(); + anna::diameter::codec::Engine::ValidationMode::_v backupVM = codecEngine->getValidationMode(); if(!analysisOK) - a_codecEngine->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Never); + codecEngine->setValidationMode(anna::diameter::codec::Engine::ValidationMode::Never); anna::diameter::comm::Message *msg; try { @@ -122,31 +130,29 @@ throw(anna::RuntimeException) { my_node->releaseCommMessage(msg); // Restore validation mode - a_codecEngine->setValidationMode(backupVM); + codecEngine->setValidationMode(backupVM); // Pop front the reacting answer: if(analysisOK && programmed) a_reactingAnswers.nextMessage(code); + + // Testing: + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); } void MyLocalServer::eventResponse(const anna::diameter::comm::Response &response) throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("launcher::MyLocalServer", "eventResponse", ANNA_FILE_LOCATION)); Launcher& my_app = static_cast (anna::app::functions::getApp()); - RealmNode * my_node = my_app.getRealmNode(getEngine()->getRealm()); + anna::diameter::comm::OriginHost * my_node = my_app.getOriginHost(getEngine()->getOriginHostName()); anna::diameter::comm::ClassCode::_v code = response.getClassCode(); anna::diameter::comm::Response::ResultCode::_v result = response.getResultCode(); anna::diameter::comm::Message* request = const_cast(response.getRequest()); const anna::DataBlock* message = response.getMessage(); const anna::diameter::comm::ServerSession *serverSession = static_cast(response.getSession()); - bool isBindResponse = (code == anna::diameter::comm::ClassCode::Bind); - bool isApplicationMessage = (code == anna::diameter::comm::ClassCode::ApplicationMessage); bool contextExpired = (result == anna::diameter::comm::Response::ResultCode::Timeout); bool isUnavailable = (result == anna::diameter::comm::Response::ResultCode::DiameterUnavailable); bool isOK = (result == anna::diameter::comm::Response::ResultCode::Success); - // Testing: - TestManager::instantiate().receiveMessage(*message, serverSession); - // CommandId: anna::diameter::CommandId request_cid = request->getCommandId(); LOGDEBUG @@ -190,10 +196,10 @@ throw(anna::RuntimeException) { anna::diameter::comm::Entity *entity = my_node->getEntity(); if(entity) { - anna::diameter::comm::ClientSession *usedClientSession = my_node->getMyDiameterEngine()->findClientSession(request->getRequestClientSessionKey()); + anna::diameter::comm::ClientSession *usedClientSession = my_node->getCommEngine()->findClientSession(request->getRequestClientSessionKey()); std::string detail; - if(my_node->logEnabled()) detail = usedClientSession ? usedClientSession->asString() : ""; // this should not happen + if(my_node->logEnabled()) detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // this should not happen anna::diameter::comm::Message *msg; try { @@ -219,6 +225,9 @@ throw(anna::RuntimeException) { my_node->releaseCommMessage(request); } } + + // Testing: + if(isOK) anna::testing::TestManager::instantiate().receiveDiameterMessage(*message, serverSession); } void MyLocalServer::eventUnknownResponse(anna::diameter::comm::ServerSession *serverSession, const anna::DataBlock &message) @@ -226,7 +235,7 @@ throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("launcher::MyLocalServer", "eventUnknownResponse", ANNA_FILE_LOCATION)); // Performance stats: Launcher& my_app = static_cast (anna::app::functions::getApp()); - RealmNode * my_node = my_app.getRealmNode(getEngine()->getRealm()); + anna::diameter::comm::OriginHost *my_node = my_app.getOriginHost(getEngine()->getOriginHostName()); // CommandId: anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); LOGDEBUG @@ -248,7 +257,7 @@ throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("launcher::MyLocalServer", "eventDPA", ANNA_FILE_LOCATION)); // Performance stats: Launcher& my_app = static_cast (anna::app::functions::getApp()); - RealmNode * my_node = my_app.getRealmNode(getEngine()->getRealm()); + anna::diameter::comm::OriginHost *my_node = my_app.getOriginHost(getEngine()->getOriginHostName()); // CommandId: anna::diameter::CommandId cid = anna::diameter::codec::functions::getCommandId(message); LOGDEBUG @@ -262,5 +271,9 @@ throw(anna::RuntimeException) { anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); + // Write reception if(my_node->logEnabled()) my_node->writeLogFile(message, "recvfc", serverSession->asString()); + + // Testing: + anna::testing::TestManager::instantiate().receiveDiameterMessage(message, serverSession); }