X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FLauncher.cpp;h=07c2e1be73dfe176cb13b7acf221d19f417adef7;hb=8b8309d46e9ccc968d3a315e86e70c5a806706d0;hp=95173728c972b1880fff22d0bc7f3436dae85a3b;hpb=b024e74e517f6f2da26722bc258ec48532a2b15e;p=anna.git diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 9517372..07c2e1b 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -12,6 +12,8 @@ #include // ceil #include #include // chdir +//#include TODO: use this from gcc4.9.0: http://stackoverflow.com/questions/8060025/is-this-c11-regex-error-me-or-the-compiler +#include // Project #include @@ -24,14 +26,18 @@ #include #include #include +#include #include +#include +#include // Process #include -#include +#include +#include #include -#include -#include +#include +#include #define SIGUSR2_TASKS_INPUT_FILENAME "sigusr2.in" @@ -137,7 +143,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; @@ -298,8 +303,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); } @@ -325,11 +331,24 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp // Checking command line parameters std::string sessionBasedModelsType; + anna::diameter::comm::Entity::SessionBasedModelsType::_v sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::SessionIdLowPart; if(sessionBasedModelsClientSocketSelection) { sessionBasedModelsType = sessionBasedModelsClientSocketSelection->getValue(); - if((sessionBasedModelsType != "SessionIdHighPart") && (sessionBasedModelsType != "SessionIdOptionalPart") && (sessionBasedModelsType != "RoundRobin")) { - throw anna::RuntimeException("Parameter 'sessionBasedModelsClientSocketSelection' only accepts 'SessionIdHighPart'/'SessionIdOptionalPart'/'RoundRobin' as parameter values", ANNA_FILE_LOCATION); - } + if (sessionBasedModelsType == "RoundRobin") { + sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::RoundRobin; + } + else if (sessionBasedModelsType == "SessionIdOptionalPart") { + sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::SessionIdOptionalPart; + } + else if (sessionBasedModelsType == "SessionIdHighPart") { + sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::SessionIdHighPart; + } + else if (sessionBasedModelsType == "SessionIdLowPart") { + sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::SessionIdLowPart; + } + else { + throw anna::RuntimeException("Parameter 'sessionBasedModelsClientSocketSelection' only accepts 'SessionIdLowPart'/'SessionIdHighPart'/'SessionIdOptionalPart'/'RoundRobin' as parameter values", ANNA_FILE_LOCATION); + } } int retransmissions = retries ? retries->getIntegerValue() : 0; @@ -337,18 +356,21 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp throw anna::RuntimeException("Parameter 'retries' must be non-negative", ANNA_FILE_LOCATION); } - // Create new Node instance ///////////////////////////////////////////////////////////////// - a_workingNode = new OriginHost(originHost->getValue(), applicationId, bpd); - MyDiameterEngine *commEngine = a_workingNode->getMyDiameterEngine(); ///////////////////////////////////////////////////////////////////////////////////////////// - - // Assignments: + // Diameter communication engine: + std::string commEngineName = originHost->getValue() + "_DiameterCommEngine"; + MyDiameterEngine *commEngine = new MyDiameterEngine(commEngineName.c_str(), bpd); + commEngine->setAutoBind(false); // allow to create client-sessions without binding them, in order to set timeouts. commEngine->setMaxConnectionDelay(tcpConnectDelayMs); commEngine->setWatchdogPeriod(watchdogPeriodMs); + commEngine->setOriginHostName(originHost->getValue()); + if (originRealm) commEngine->setOriginRealmName(originRealm->getValue()); + + // Origin host node: + a_workingNode = new anna::diameter::comm::OriginHost((anna::diameter::comm::Engine*)commEngine, applicationId); + a_workingNode->setRequestRetransmissions(retransmissions); + ///////////////////////////////////////////////////////////////////////////////////////////// - // Realm information: - commEngine->setOriginHost(originHost->getValue()); - if (originRealm) commEngine->setOriginRealm(originRealm->getValue()); // Diameter entity: if(entity) { @@ -365,8 +387,7 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp // Register one entity for this engine: a_workingNode->createEntity(entity->getValue(), ceaTimeoutMs, answersTimeoutMs); - a_workingNode->setRequestRetransmissions(retransmissions); - a_workingNode->getEntity()->setSessionBasedModelsType(sessionBasedModelsType); + a_workingNode->getEntity()->setSessionBasedModelsType(sessionBasedModelsTypeEnum); a_workingNode->getEntity()->setBalance(balance ? (balance->getValue() == "yes") : false); // for sendings if (eventOperation) a_workingNode->getEntity()->bind(); } @@ -378,12 +399,12 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp std::string ceaPathfile = cea ? cea->getValue() : ""; int sessions = diameterServerSessions ? diameterServerSessions->getIntegerValue() : 1; - a_workingNode->startDiameterServer(diameterServer->getValue(), sessions, allowedInactivityTimeMs, answersTimeoutMs, ceaPathfile); + a_workingNode->createDiameterServer(diameterServer->getValue(), sessions, allowedInactivityTimeMs, answersTimeoutMs, ceaPathfile); } // Logs: if (!allLogsDisabled) { - std::string host = commEngine->getOriginHost(); + std::string host = commEngine->getOriginHostName(); std::string s_log = host + ".launcher.log"; if (log) s_log = log->getValue(); bool b_splitLog = (splitLog ? (splitLog->getValue() == "yes") : false); bool b_detailedLog = (detailedLog ? (detailedLog->getValue() == "yes") : false); @@ -397,7 +418,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); ///////////////////////////////////////////////////////////////////////////////////////////// } } @@ -496,38 +517,51 @@ 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; } -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; } -OriginHost *Launcher::getOriginHost(const anna::diameter::codec::Message &message) const throw(anna::RuntimeException) { +anna::diameter::comm::OriginHost *Launcher::getOriginHost(const anna::diameter::codec::Message &message) const throw(anna::RuntimeException) { std::string originHost = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Host)->getDiameterIdentity()->getValue(); 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); } -OriginHost *Launcher::getOperatedHost() const throw(anna::RuntimeException) { +anna::diameter::comm::OriginHost *Launcher::getWorkingNode() const throw(anna::RuntimeException) { + if(!a_workingNode) + throw anna::RuntimeException("Working node not identified (try to load services)", ANNA_FILE_LOCATION); + + return a_workingNode; +} + +anna::diameter::comm::OriginHost *Launcher::getOperatedHost() const throw(anna::RuntimeException) { if(!a_operatedHost) throw anna::RuntimeException("Node not identified (try to force a specific Origin-Host with 'node' operation)", ANNA_FILE_LOCATION); @@ -535,21 +569,21 @@ OriginHost *Launcher::getOperatedHost() const throw(anna::RuntimeException) { } MyDiameterEntity *Launcher::getOperatedEntity() const throw(anna::RuntimeException) { - MyDiameterEntity *result = getOperatedHost()->getEntity(); + MyDiameterEntity *result = (MyDiameterEntity *)(getOperatedHost()->getEntity()); if (!result) throw anna::RuntimeException("No entity configured for the operated node", ANNA_FILE_LOCATION); return result; } MyLocalServer *Launcher::getOperatedServer() const throw(anna::RuntimeException) { - MyLocalServer *result = getOperatedHost()->getDiameterServer(); + MyLocalServer *result = (MyLocalServer *)(getOperatedHost()->getDiameterServer()); if (!result) throw anna::RuntimeException("No local server configured for the operated node", ANNA_FILE_LOCATION); return result; } MyDiameterEngine *Launcher::getOperatedEngine() const throw(anna::RuntimeException) { - return getOperatedHost()->getMyDiameterEngine(); // never will be NULL + return (MyDiameterEngine *)getOperatedHost()->getCommEngine(); // never will be NULL } void Launcher::initialize() @@ -559,11 +593,18 @@ throw(anna::RuntimeException) { anna::comm::Communicator::WorkMode::_v workMode(anna::comm::Communicator::WorkMode::Single); a_communicator = new MyCommunicator(workMode); a_timeEngine = new anna::timex::Engine((anna::Millisecond)600000, a_admlMinResolution); - TestManager::instantiate().setTimerController(a_timeEngine); + anna::testing::TestManager::instantiate().setTimerController(a_timeEngine); // 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 = "."; @@ -574,7 +615,7 @@ throw(anna::RuntimeException) { // Testing framework: std::string tmDir = "."; if(cl.exists("tmDir")) tmDir = cl.getValue("tmDir"); - TestManager::instantiate().setReportsDirectory(tmDir); + anna::testing::TestManager::instantiate().setReportsDirectory(tmDir); // Tracing: if(cl.exists("trace")) @@ -588,7 +629,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(); @@ -745,39 +786,17 @@ throw(anna::RuntimeException) { a_timeEngine->activate(a_counterRecorderClock); // start clock } - // Log statistics concepts - if(cl.exists("logStatisticSamples")) { - std::string list = cl.getValue("logStatisticSamples"); - anna::statistics::Engine &statEngine = anna::statistics::Engine::instantiate(); - - if(list == "all") { - if(statEngine.enableSampleLog(/* -1: all concepts */)) - LOGDEBUG(anna::Logger::debug("Sample log activation for all statistic concepts", ANNA_FILE_LOCATION)); - } else { - anna::Tokenizer lst; - lst.apply(cl.getValue("logStatisticSamples"), ","); - - if(lst.size() >= 1) { - anna::Tokenizer::const_iterator tok_min(lst.begin()); - anna::Tokenizer::const_iterator tok_max(lst.end()); - anna::Tokenizer::const_iterator tok_iter; - int conceptId; - - for(tok_iter = tok_min; tok_iter != tok_max; tok_iter++) { - conceptId = atoi(anna::Tokenizer::data(tok_iter)); - - if(statEngine.enableSampleLog(conceptId)) - LOGDEBUG(anna::Logger::debug(anna::functions::asString("Sample log activation for statistic concept id = %d", conceptId), ANNA_FILE_LOCATION)); - } - } - } - } - + ///////////////////////////// + // Log statistics concepts // + ///////////////////////////// + if(cl.exists("logStatisticSamples")) + logStatisticsSamples(cl.getValue("logStatisticSamples")); // Start client connections ////////////////////////////////////////////////////////////////////////////////// MyDiameterEntity *entity; - for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { - entity = it->second->getEntity(); + 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(); } @@ -791,8 +810,7 @@ throw(anna::RuntimeException) { a_communicator->accept(); } - -bool Launcher::getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw() { +bool Launcher::getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw(anna::RuntimeException) { // Get hex string static char buffer[8192]; std::ifstream infile(pathfile.c_str(), std::ifstream::in); @@ -807,7 +825,8 @@ bool Launcher::getDataBlockFromHexFile(const std::string &pathfile, anna::DataBl msg += hexString; anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); - anna::functions::fromHexString(hexString, db); + + anna::functions::fromHexString(hexString, db); // could launch exception // Close file infile.close(); return true; @@ -816,13 +835,29 @@ bool Launcher::getDataBlockFromHexFile(const std::string &pathfile, anna::DataBl return false; } +bool Launcher::getContentFromFile(const std::string &pathfile, std::string &content) const throw(anna::RuntimeException) { + + std::ifstream inFile(pathfile.c_str(), std::ifstream::in); + if(!inFile.good()) { + throw RuntimeException(anna::functions::asString("Unable to open file '%s'", pathfile.c_str()), ANNA_FILE_LOCATION); + } + + std::stringstream strStream; + strStream << inFile.rdbuf(); //read the file + content = strStream.str(); // holds the content of the file + inFile.close(); + + return true; +} + void Launcher::resetStatistics() throw() { if (a_workingNode) { - a_workingNode->getMyDiameterEngine()->resetStatistics(); + a_workingNode->getCommEngine()->resetStatistics(); } else { - for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { - it->second->getMyDiameterEngine()->resetStatistics(); + 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(); } } } @@ -833,6 +868,15 @@ void Launcher::resetCounters() throw() { anna::diameter::codec::OamModule::instantiate().resetCounters(); } +void Launcher::signalTerminate() throw(anna::RuntimeException) { + LOGMETHOD(anna::TraceMethod tm("Launcher", "signalTerminate", ANNA_FILE_LOCATION)); + + forceCountersRecord(); + + a_communicator->terminate (); + comm::Application::signalTerminate (); +} + void Launcher::signalUSR2() throw(anna::RuntimeException) { std::string inputFile = getSignalUSR2InputFile(); @@ -1036,6 +1080,11 @@ std::string Launcher::help() const throw() { result += "\n This operation applies over all the registered host nodes"; result += "\n except if one specific working node has been set."; result += "\nforceCountersRecord Forces dump to file the current counters of the process."; + result += "\nlog-statistics-samples| Log statistics samples for the provided comma-separated concept id"; + result += "\n list, over './sample..csv' files. For example: \"1,2\""; + result += "\n will log concepts 1 and 2. Reserved words \"all\"/\"none\" activates/"; + result += "\n deactivates all registered statistics concept identifiers. That ids"; + result += "\n are shown at context dump."; result += "\nchange-dir[|directory] Changes the execution point which could be fine to ease some"; result += "\n file system interaction tasks. Be care about some requirements"; result += "\n (for example if you have a user defined counters directory as"; @@ -1181,7 +1230,17 @@ std::string Launcher::help() const throw() { result += "\n values (Session-Id, Subscriber-Id, etc.)."; result += "\n"; result += "\n : commands to be executed for the test id provided. Each command programmed"; - result += "\n constitutes a test case 'step', numbered from 1 to N."; + result += "\n constitutes a test case 'step', numbered from 1 to N, with an exception for"; + result += "\n 'description' which is used to describe the test case:"; + result += "\n"; + result += "\n description| Sets a test case description. Test cases by default are"; + result += "\n constructed with description 'Testcase_'."; + result += "\n"; + result += "\n ip-limit[|amount] In-progress limit of test cases controlled from this test."; + result += "\n No new test cases will be launched over this value (test"; + result += "\n manager tick work will be ignored). Zero-value is equivalent"; + result += "\n to stop the clock tick, -1 is used to specify 'no limit' which"; + result += "\n is the default. For missing amount, value of 1 is applied."; result += "\n"; result += "\n timeout| Sets an asynchronous timer to restrict the maximum timeout"; result += "\n until last test step. Normally, this command is invoked"; @@ -1216,16 +1275,6 @@ std::string Launcher::help() const throw() { result += "\n delay| Blocking step until the time lapse expires. Useful to give "; result += "\n some cadence control and time schedule for a specific case."; result += "\n A value of 0 could be used as a dummy step."; - result += "\n wait| Blocking step until condition is fulfilled. The message could"; - result += "\n received from entity (waitfe) or from client (waitfc)."; - result += "\n"; - result += "\n wait-regexp|"; - result += "\n Wait condition, from entity (waitfe-regexp) or client (waitfc-regexp)"; - result += "\n to match the serialized xml content for received messages. CPU cost"; - result += "\n is bigger than the former ones because the whole message must be"; - result += "\n decoded and converted to xml instead of doing a direct hexadecimal"; - result += "\n buffer search. The main advantage is the great flexibility to identify"; - result += "\n any content with a regular expression."; result += "\n"; result += "\n sh-command|