X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestManager.cpp;h=cf768ab61ce9935c390c164a6e9a63fd33511d50;hb=61f1340da3cae5159d2e3bc14fc47c6d4bf9453e;hp=bd9bbfcca2487a538442ea6b9dc4139ec65cd414;hpb=983eaadca6cfae987be3453853d75bb9bce04487;p=anna.git diff --git a/example/diameter/launcher/testing/TestManager.cpp b/example/diameter/launcher/testing/TestManager.cpp index bd9bbfc..cf768ab 100644 --- a/example/diameter/launcher/testing/TestManager.cpp +++ b/example/diameter/launcher/testing/TestManager.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -23,7 +24,7 @@ #include #include #include -#include +#include class TestTimer; @@ -82,7 +83,12 @@ TestManager::TestManager() : anna::timex::TimeEventObserver("TestManager") { a_timeController = NULL; a_reportsDirectory = "./"; - a_dumpReports = false; + + a_dumpInProgressReports = false; + a_dumpInitializedReports = false; + a_dumpFailedReports = false; + a_dumpSuccessReports = false; + a_dumpHexMessages = false; a_synchronousAmount = 1; a_poolRepeats = 0; // repeat disabled by default @@ -90,6 +96,7 @@ TestManager::TestManager() : a_inProgressLimit = UINT_MAX; // no limit a_clock = NULL; //a_testPool.clear(); + //a_statSummary.clear(); a_currentTestIt = a_testPool.end(); } @@ -104,6 +111,22 @@ void TestManager::registerSessionId(const std::string &sessionId, const TestCase } else { a_sessionIdTestCaseMap[sessionId] = const_cast(testCase); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager::registerSessionId for test case (id = %llu): %s)", testCase->getId(), sessionId.c_str()), ANNA_FILE_LOCATION)); + } +} + +void TestManager::registerSubscriberId(const std::string &subscriberId, const TestCase *testCase) throw(anna::RuntimeException) { + + std::map::const_iterator it = a_subscriberIdTestCaseMap.find(subscriberId); + if (it != a_subscriberIdTestCaseMap.end()) { // found + unsigned int id = it->second->getId(); + if (id != testCase->getId()) { + throw anna::RuntimeException(anna::functions::asString("There is another test case (id = %llu) which registered such subscriberId: %s", id, subscriberId.c_str()), ANNA_FILE_LOCATION); + } + } + else { + a_subscriberIdTestCaseMap[subscriberId] = const_cast(testCase); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("TestManager::registerSubscriberId for test case (id = %llu): %s)", testCase->getId(), subscriberId.c_str()), ANNA_FILE_LOCATION)); } } @@ -259,6 +282,7 @@ bool TestManager::clearPool() throw() { a_testPool.clear(); a_sessionIdTestCaseMap.clear(); + a_subscriberIdTestCaseMap.clear(); a_currentTestIt = a_testPool.end(); a_poolCycle = 1; configureTTPS(0); // stop @@ -275,6 +299,7 @@ bool TestManager::resetPool(bool hard) throw() { result = true; } //a_sessionIdTestCaseMap.clear(); + //a_subscriberIdTestCaseMap.clear(); return result; } @@ -355,26 +380,51 @@ TestCase *TestManager::getTestCaseFromSessionId(const anna::DataBlock &message, } catch (anna::RuntimeException &ex) { //ex.trace(); - LOGWARNING(anna::Logger::warning("Cannot get the Session-Id from received DataBlock in order to identify the Test Case", ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug("Cannot get the Session-Id from received DataBlock in order to identify the Test Case", ANNA_FILE_LOCATION)); return NULL; } std::map::const_iterator sessionIdIt = a_sessionIdTestCaseMap.find(sessionId); if (sessionIdIt != a_sessionIdTestCaseMap.end()) return sessionIdIt->second; - LOGWARNING(anna::Logger::warning(anna::functions::asString("Cannot identify the Test Case for received Session-Id: %s", sessionId.c_str()), ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("Cannot identify the Test Case for received Session-Id: %s", sessionId.c_str()), ANNA_FILE_LOCATION)); return NULL; } -void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *realm, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException) { +TestCase *TestManager::getTestCaseFromSubscriberId(const anna::DataBlock &message, std::string &subscriberId) throw() { + try { + subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(message, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164); + if (subscriberId == "") // try with IMSI + subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(message, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI); + } + catch (anna::RuntimeException &ex) { + //ex.trace(); + LOGDEBUG(anna::Logger::debug("Cannot get the Subscriber-Id from received DataBlock in order to identify the Test Case", ANNA_FILE_LOCATION)); + return NULL; + } + std::map::const_iterator subscriberIdIt = a_subscriberIdTestCaseMap.find(subscriberId); + if (subscriberIdIt != a_subscriberIdTestCaseMap.end()) + return subscriberIdIt->second; + + LOGDEBUG(anna::Logger::debug(anna::functions::asString("Cannot identify the Test Case for received Subscriber-Id: %s", subscriberId.c_str()), ANNA_FILE_LOCATION)); + return NULL; +} + +void TestManager::receiveMessage(const anna::DataBlock &message, OriginHost *host, const anna::diameter::comm::ClientSession *clientSession) throw(anna::RuntimeException) { // Testing disabled: if (!tests()) return; // Identify the test case: - std::string sessionId; - TestCase *tc = getTestCaseFromSessionId(message, sessionId); - if (!tc) return; + std::string sessionId, subscriberId; + TestCase *tc; + tc = getTestCaseFromSessionId(message, sessionId); + if (!tc) + tc = getTestCaseFromSubscriberId(message, subscriberId); + if (!tc) { + LOGWARNING(anna::Logger::warning(anna::comm::functions::asText("Cannot identify the Test Case for the message received from server: ", message), ANNA_FILE_LOCATION)); // this should not appear + return; + } // Work with Test case: TestStepWait *tsw = tc->searchNextWaitConditionFulfilled(message, true /* comes from entity */); @@ -386,10 +436,10 @@ void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *real codecMsg.decode(message); hint += "\n"; hint += codecMsg.asXMLString(); - // // Realm checking: - // std::string messageOR = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->getValue(); - // if (messageOR != realm->getName()) { - // LOGWARNING(anna::Logger::warning(anna::functions::asString("Received message from realm '%s', with different Origin-Realm: %s", realm->getName().c_str(), messageOR.c_str()), ANNA_FILE_LOCATION)); + // // Host checking: + // std::string messageOH = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->getValue(); + // if (messageOH != host->getName()) { + // LOGWARNING(anna::Logger::warning(anna::functions::asString("Received message from host '%s', with different Origin-Host: %s", host->getName().c_str(), messageOH.c_str()), ANNA_FILE_LOCATION)); // } } catch (anna::RuntimeException &ex) { @@ -406,15 +456,21 @@ void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *real } } -void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *realm, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException) { +void TestManager::receiveMessage(const anna::DataBlock &message, OriginHost *host, const anna::diameter::comm::ServerSession *serverSession) throw(anna::RuntimeException) { // Testing disabled: if (!tests()) return; // Identify the test case: - std::string sessionId; - TestCase *tc = getTestCaseFromSessionId(message, sessionId); - if (!tc) return; + std::string sessionId, subscriberId; + TestCase *tc; + tc = getTestCaseFromSessionId(message, sessionId); + if (!tc) + tc = getTestCaseFromSubscriberId(message, subscriberId); + if (!tc) { + LOGWARNING(anna::Logger::warning(anna::comm::functions::asText("Cannot identify the Test Case for the message received from client: ", message), ANNA_FILE_LOCATION)); // this should not appear + return; + } // Work with Test case: TestStepWait *tsw = tc->searchNextWaitConditionFulfilled(message, false /* comes from client */); @@ -426,10 +482,10 @@ void TestManager::receiveMessage(const anna::DataBlock &message, RealmNode *real codecMsg.decode(message); hint += "\n"; hint += codecMsg.asXMLString(); - // // Realm checking: - // std::string messageOR = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->getValue(); - // if (messageOR != realm->getName()) { - // LOGWARNING(anna::Logger::warning(anna::functions::asString("Received message from realm '%s', with different Origin-Realm: %s", realm->getName().c_str(), messageOR.c_str()), ANNA_FILE_LOCATION)); + // // Host checking: + // std::string messageOH = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->getValue(); + // if (messageOH != host->getName()) { + // LOGWARNING(anna::Logger::warning(anna::functions::asString("Received message from host '%s', with different Origin-Host: %s", host->getName().c_str(), messageOH.c_str()), ANNA_FILE_LOCATION)); // } } catch (anna::RuntimeException &ex) { @@ -460,7 +516,10 @@ throw() { result->createAttribute("InProgressLimit", ""); else result->createAttribute("InProgressLimit", a_inProgressLimit); - result->createAttribute("DumpReports", (a_dumpReports ? "yes":"no")); + result->createAttribute("DumpInitializedReports", (a_dumpInitializedReports ? "yes":"no")); + result->createAttribute("DumpInProgressReports", (a_dumpInProgressReports ? "yes":"no")); + result->createAttribute("DumpFailedReports", (a_dumpFailedReports ? "yes":"no")); + result->createAttribute("DumpSuccessReports", (a_dumpSuccessReports ? "yes":"no")); result->createAttribute("DumpHexMessages", (a_dumpHexMessages ? "yes":"no")); result->createAttribute("ReportsDirectory", a_reportsDirectory); if (a_clock) { @@ -471,9 +530,13 @@ throw() { if (a_currentTestIt != a_testPool.end()) { result->createAttribute("CurrentTestCaseId", (*a_currentTestIt).first); } - if (a_dumpReports && poolSize != 0) { + if (poolSize != 0) { anna::xml::Node* testCases = result->createChild("TestCases"); for (test_pool_it it = a_testPool.begin(); it != a_testPool.end(); it++) { + if (((*it).second->getState() == TestCase::State::Initialized) && (!getDumpInitializedReports())) continue; + if (((*it).second->getState() == TestCase::State::InProgress) && (!getDumpInProgressReports())) continue; + if (((*it).second->getState() == TestCase::State::Failed) && (!getDumpFailedReports())) continue; + if (((*it).second->getState() == TestCase::State::Success) && (!getDumpSuccessReports())) continue; (*it).second->asXML(testCases); } }