X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FLauncher.cpp;h=94d8f66f52e5c12e52c4c4f9d0694b0f3e8102ee;hb=5406b19bdbfe101b264f8c4d878392e2916b8f9d;hp=5ae6f8771e1de6d566ba3a4b0735ada958472394;hpb=4e2e5e6df510cfba2a716b5ee9b745a157d4d0fb;p=anna.git diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 5ae6f87..94d8f66 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -28,12 +28,13 @@ #include #include #include +#include +#include #include // Process #include #include -#include #include #include @@ -141,7 +142,6 @@ Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", " //a_admlMinResolution = (anna::Millisecond)100; a_counterRecorderClock = NULL; - // a_originHosts.clear(); a_workingNode = NULL; a_httpServerSocket = NULL; @@ -302,8 +302,9 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp burstLog = (*it)->getAttribute("burstLog", false /* no exception */); // (yes | no) // Basic checkings: - origin_hosts_it nodeIt = a_originHosts.find(originHost->getValue()); - if (nodeIt != a_originHosts.end()) { + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + anna::diameter::comm::OriginHost *oh = ohm.getOriginHost(originHost->getValue()); + if (oh) { std::string msg = "Already registered such Origin-Host: "; msg += originHost->getValue(); throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); } @@ -416,7 +417,7 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp if (eventOperation) commEngine->lazyInitialize(); // Node and Codec Engine registration /////////////////////////////////////////////////////// - a_originHosts[originHost->getValue()] = a_workingNode; + ohm.registerOriginHost(originHost->getValue(), a_workingNode); ///////////////////////////////////////////////////////////////////////////////////////////// } } @@ -515,25 +516,25 @@ anna::Millisecond Launcher::checkTimeMeasure(const std::string ¶meter, const bool Launcher::setWorkingNode(const std::string &name) throw() { bool result = false; - origin_hosts_it nodeIt = a_originHosts.find(name); - if (nodeIt == a_originHosts.end()) { - LOGWARNING( - std::string msg = "Unknown node with name '"; msg += name; msg += "'. Ignoring ..."; - anna::Logger::warning(msg, ANNA_FILE_LOCATION); - ); - } - else { - a_workingNode = const_cast(nodeIt->second); + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + anna::diameter::comm::OriginHost *oh = ohm.getOriginHost(name); + + if (oh) { + a_workingNode = const_cast(oh); result = true; } return result; } -anna::diameter::comm::OriginHost *Launcher::getOriginHost(const std::string &oh) const throw(anna::RuntimeException) { - origin_hosts_it it = a_originHosts.find(oh); - if (it != a_originHosts.end()) return it->second; - throw anna::RuntimeException(anna::functions::asString("There is no origin host registered as '%s' (set Origin-Host avp correctly or force a specific host with 'node' operation)", oh.c_str()), ANNA_FILE_LOCATION); +anna::diameter::comm::OriginHost *Launcher::getOriginHost(const std::string &name) const throw(anna::RuntimeException) { + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + anna::diameter::comm::OriginHost *result = ohm.getOriginHost(name); + + if (!result) + throw anna::RuntimeException(anna::functions::asString("There is no origin host registered as '%s' (set Origin-Host avp correctly or force a specific host with 'node' operation)", name.c_str()), ANNA_FILE_LOCATION); + + return result; } anna::diameter::comm::OriginHost *Launcher::getOriginHost(const anna::diameter::codec::Message &message) const throw(anna::RuntimeException) { @@ -541,6 +542,12 @@ anna::diameter::comm::OriginHost *Launcher::getOriginHost(const anna::diameter:: return (getOriginHost(originHost)); } +bool Launcher::uniqueOriginHost() const throw() { + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + return (ohm.size() == 1); +} + + void Launcher::updateOperatedOriginHostWithMessage(const anna::diameter::codec::Message &message) throw(anna::RuntimeException) { if (!a_operatedHost) // priority for working node by mean 'node' operation a_operatedHost = getOriginHost(message); @@ -589,7 +596,14 @@ throw(anna::RuntimeException) { // Counters record procedure: const char *varname = "cntRecordPeriod"; - anna::Millisecond cntRecordPeriod = (cl.exists(varname)) ? checkTimeMeasure(varname, cl.getValue(varname)) : (anna::Millisecond)300000; + anna::Millisecond cntRecordPeriod; + try { + cntRecordPeriod = (cl.exists(varname)) ? checkTimeMeasure(varname, cl.getValue(varname)) : (anna::Millisecond)300000; + } + catch(anna::RuntimeException &ex) { + if (cntRecordPeriod != 0) throw ex; + } + if(cntRecordPeriod != 0) { a_counterRecorderClock = new MyCounterRecorderClock("Counters record procedure clock", cntRecordPeriod); // clock std::string cntDir = "."; @@ -614,7 +628,7 @@ void Launcher::run() throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("Launcher", "run", ANNA_FILE_LOCATION)); CommandLine& cl(anna::CommandLine::instantiate()); - anna::diameter::stack::Engine &stackEngine = anna::diameter::stack::Engine::instantiate(); + anna::diameter::stack::Engine::instantiate(); // Start time: a_start_time.setNow(); @@ -779,7 +793,8 @@ throw(anna::RuntimeException) { // Start client connections ////////////////////////////////////////////////////////////////////////////////// MyDiameterEntity *entity; - for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + for (diameter::comm::origin_hosts_it it = ohm.begin(); it != ohm.end(); it++) { entity = (MyDiameterEntity *)(it->second->getEntity()); if (entity) entity->bind(); } @@ -839,7 +854,8 @@ void Launcher::resetStatistics() throw() { a_workingNode->getCommEngine()->resetStatistics(); } else { - for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + for (diameter::comm::origin_hosts_it it = ohm.begin(); it != ohm.end(); it++) { it->second->getCommEngine()->resetStatistics(); } } @@ -1272,7 +1288,8 @@ std::string Launcher::help() const throw() { result += "\n source file (xml representation). Fix mode must be enabled to avoid"; result += "\n unexpected matching behaviour. If you need a strict matching you"; result += "\n must add parameter 'strict', if not, regexp is built ignoring sequence"; - result += "\n information (hop-by-hop-id=\"[0-9]+\" end-to-end-id=\"[0-9]+\")."; + result += "\n information (hop-by-hop-id=\"[0-9]+\" end-to-end-id=\"[0-9]+\") and"; + result += "\n Origin-State-Id value."; result += "\n All LF codes will be internally removed when comparison is executed"; result += "\n in order to ease xml content configuration."; result += "\n"; @@ -1447,6 +1464,10 @@ std::string Launcher::help() const throw() { result += "\n been done before. Test cases state & data will be reset (when achieved again), but general"; result += "\n statistics and counters will continue measuring until reset with 'collect' operation."; result += "\n"; + result += "\n test|auto-reset| When cycling, current test cases can be soft (default) or hard reset. If no timeout has"; + result += "\n been configured for the test case, hard reset could prevent stuck on the next cycle for"; + result += "\n those test cases still in progress."; + result += "\n"; result += "\n test|clear Clears all the programmed test cases and stop testing (if in progress)."; result += "\n"; result += "\n test|summary Test manager general report (number of test cases, counts by state, global configuration,"; @@ -1592,7 +1613,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if (args == "" && op_size != 7) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); try { - p.execute(args, response_content, getWorkingNode()); + p.execute(args, response_content); } catch(anna::RuntimeException &ex) { ex.trace(); @@ -1968,6 +1989,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons // test|look[|id] Show programmed test case for id provided, current when missing ... // test|interact|amount|id Makes interactive a specific test case id. The amount is the margin of execution steps ... // test|reset|<[soft]/hard>[|id] Reset the test case for id provided, all the tests when missing ... + // test|auto-reset| When cycling, current test cases can be soft (default) or hard reset ... // test|clear Clears all the programmed test cases. // test|summary Test manager general report (number of test cases, counts by state ... @@ -2152,7 +2174,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons anna::testing::TestCase *testCase = ((id != -1) ? testManager.findTestCase(id) : NULL); if (testCase) { - bool done = testCase->reset((param2 == "hard") ? true:false); + bool done = testCase->reset(param2 == "hard"); opt_response_content = "test "; opt_response_content += param2; opt_response_content += " reset for id "; @@ -2161,7 +2183,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else { if (id == -1) { - bool anyReset = testManager.resetPool((param2 == "hard") ? true:false); + bool anyReset = testManager.resetPool(param2 == "hard"); opt_response_content = param2; opt_response_content += " reset have been sent to all programmed tests: "; opt_response_content += anyReset ? "some/all have been reset" : "nothing was reset"; } else { @@ -2171,6 +2193,16 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } } } + else if(param1 == "auto-reset") { + if (numParams != 2) + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + if (param2 != "soft" && param2 != "hard") + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + testManager.setAutoResetHard(param2 == "hard"); + opt_response_content += anna::functions::asString("Auto-reset configured to '%s'", param2.c_str()); + } else if(param1 == "clear") { if (numParams > 1) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); @@ -2289,35 +2321,41 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons /* std::string s_from = "hop-by-hop-id=\"[0-9]+\" end-to-end-id=\"[0-9]+\""; std::string s_to = s_from; + std::string s_from2 = "avp name=\"Origin-State-Id\" data=\"[0-9]+\""; + std::string s_to2 = s_from2; try { regexp = std::regex_replace (regexp, std::regex(s_from), s_to); + regexp = std::regex_replace (regexp, std::regex(s_from2), s_to2); } catch (const std::regex_error& e) { throw anna::RuntimeException(e.what(), ANNA_FILE_LOCATION); } + */ - std::string::size_type pos = 0u; - std::string::size_type pos_hbh_1, pos_hbh_2; - std::string::size_type pos_ete_1, pos_ete_2; + std::string::size_type pos, pos_1, pos_2; - pos = regexp.find("hop-by-hop-id=", pos); + pos = regexp.find("hop-by-hop-id=", 0u); pos = regexp.find("\"", pos); - pos_hbh_1 = pos; + pos_1 = pos; pos = regexp.find("\"", pos+1); - pos_hbh_2 = pos; + pos_2 = pos; + regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); - pos = regexp.find("end-to-end-id=", pos); + pos = regexp.find("end-to-end-id=", 0u); pos = regexp.find("\"", pos); - pos_ete_1 = pos; + pos_1 = pos; pos = regexp.find("\"", pos+1); - pos_ete_2 = pos; + pos_2 = pos; + regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); - std::string hbh = regexp.substr(pos_hbh_1 + 1, pos_hbh_2 - pos_hbh_1 - 1); - std::string ete = regexp.substr(pos_ete_1 + 1, pos_ete_2 - pos_ete_1 - 1); - - regexp.replace(pos_hbh_1 + 1, pos_hbh_2 - pos_hbh_1 - 1, "[0-9]+"); - regexp.replace(pos_ete_1 + 1, pos_ete_2 - pos_ete_1 - 1, "[0-9]+"); + pos = regexp.find("Origin-State-Id", 0u); + pos = regexp.find("\"", pos); + pos = regexp.find("\"", pos+1); + pos_1 = pos; + pos = regexp.find("\"", pos+1); + pos_2 = pos; + regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+"); //regexp.insert(0, "^"); //regexp += "$"; @@ -2448,7 +2486,8 @@ throw() { result->createAttribute("InitialWorkingDirectory", a_initialWorkingDirectory); result->createAttribute("SecondsLifeTime", anna::time::functions::lapsedMilliseconds() / 1000); // Diameter: - for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + for (diameter::comm::origin_hosts_it it = ohm.begin(); it != ohm.end(); it++) { it->second->asXML(result); }