X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FLauncher.cpp;h=b1418654368644fab76f8daf572dfb3b45b686a4;hb=d723d5bf571eb48c641b092058eaa38bb6c4fcc8;hp=45f51a9630d5feeaf2f1d9d9f6ca881010fcc7d3;hpb=983eaadca6cfae987be3453853d75bb9bce04487;p=anna.git diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 45f51a9..b141865 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -11,6 +11,7 @@ #include // std::cout #include // ceil #include +#include // chdir // Project #include @@ -23,18 +24,20 @@ #include #include #include +#include #include +#include // Process #include -#include #include -#include -#include +#include +#include +#include -#define SIGUSR2_TASKS_INPUT_FILENAME "./sigusr2.in" -#define SIGUSR2_TASKS_OUTPUT_FILENAME "./sigusr2.out" +#define SIGUSR2_TASKS_INPUT_FILENAME "sigusr2.in" +#define SIGUSR2_TASKS_OUTPUT_FILENAME "sigusr2.out" const char *ServicesDTD = "\ @@ -59,56 +62,70 @@ const char *ServicesDTD = "\ -->\n\ \n\ \n\ -\n\ +\n\ \n\ \n\ @@ -122,13 +139,20 @@ Launcher::Launcher() : anna::comm::Application("launcher", "DiameterLauncher", " //a_admlMinResolution = (anna::Millisecond)100; a_counterRecorderClock = NULL; - // a_nodes.clear(); + // a_originHosts.clear(); a_workingNode = NULL; a_httpServerSocket = NULL; } +std::string Launcher::getSignalUSR2InputFile() const throw() { + return (a_initialWorkingDirectory + "/" + SIGUSR2_TASKS_INPUT_FILENAME); +} + +std::string Launcher::getSignalUSR2OutputFile() const throw() { + return (a_initialWorkingDirectory + "/" + SIGUSR2_TASKS_OUTPUT_FILENAME); +} void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOperation) throw(anna::RuntimeException) { @@ -139,8 +163,8 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp // const anna::xml::Attribute *id, *dictionary; - // - const anna::xml::Attribute *originRealm, *appId, *originHost, *cer, *dwr, *allowedInactivityTime, *tcpConnectDelay, + // + const anna::xml::Attribute *originHost, *appId, *originRealm, *cer, *dwr, *cea, *allowedInactivityTime, *tcpConnectDelay, *answersTimeout, *ceaTimeout, *watchdogPeriod, *entity, *entityServerSessions, *diameterServer, *diameterServerSessions, *balance, *sessionBasedModelsClientSocketSelection, *retries, *log, *splitLog, *detailedLog, *dumpLog, *burstLog; @@ -203,7 +227,7 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp const anna::xml::Attribute *vm_attr = (*it)->getAttribute("validationMode", false /* no exception */); const anna::xml::Attribute *vd_attr = (*it)->getAttribute("validationDepth", false /* no exception */); const anna::xml::Attribute *fm_attr = (*it)->getAttribute("fixMode", false /* no exception */); - const anna::xml::Attribute *if_attr = (*it)->getAttribute("ignoreFlags", false /* no exception */); + const anna::xml::Attribute *if_attr = (*it)->getAttribute("ignoreFlagsOnValidation", false /* no exception */); std::string vm_value = vm_attr ? vm_attr->getValue() : "AfterDecoding"; std::string vd_value = vd_attr ? vd_attr->getValue() : "FirstError"; @@ -251,11 +275,12 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp if(nodeName == "node") { // Input data: - originRealm = (*it)->getAttribute("originRealm"); + originHost = (*it)->getAttribute("originHost"); appId = (*it)->getAttribute("applicationId"); - originHost = (*it)->getAttribute("originHost", false /* no exception */); + originRealm = (*it)->getAttribute("originRealm", false /* no exception */); cer = (*it)->getAttribute("cer", false /* no exception */); dwr = (*it)->getAttribute("dwr", false /* no exception */); + cea = (*it)->getAttribute("cea", false /* no exception */); allowedInactivityTime = (*it)->getAttribute("allowedInactivityTime", false /* no exception */); tcpConnectDelay = (*it)->getAttribute("tcpConnectDelay", false /* no exception */); answersTimeout = (*it)->getAttribute("answersTimeout", false /* no exception */); @@ -275,9 +300,9 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp burstLog = (*it)->getAttribute("burstLog", false /* no exception */); // (yes | no) // Basic checkings: - realm_nodes_it nodeIt = a_nodes.find(originRealm->getValue()); - if (nodeIt != a_nodes.end()) { - std::string msg = "Already registered node name (Origin-Realm): "; msg += originRealm->getValue(); + origin_hosts_it nodeIt = a_originHosts.find(originHost->getValue()); + if (nodeIt != a_originHosts.end()) { + std::string msg = "Already registered such Origin-Host: "; msg += originHost->getValue(); throw anna::RuntimeException(msg, ANNA_FILE_LOCATION); } @@ -302,11 +327,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; 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; @@ -314,18 +352,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 RealmNode(originRealm->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: - if (originHost) commEngine->setHost(originHost->getValue()); - commEngine->setRealm(originRealm->getValue()); // Diameter entity: if(entity) { @@ -342,8 +383,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(); } @@ -351,18 +391,21 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp // Diameter Server: if(diameterServer) { + // Server CEA + std::string ceaPathfile = cea ? cea->getValue() : ""; + int sessions = diameterServerSessions ? diameterServerSessions->getIntegerValue() : 1; - a_workingNode->startDiameterServer(diameterServer->getValue(), sessions, allowedInactivityTimeMs); + a_workingNode->createDiameterServer(diameterServer->getValue(), sessions, allowedInactivityTimeMs, answersTimeoutMs, ceaPathfile); } // Logs: if (!allLogsDisabled) { - std::string realm = commEngine->getRealm(); - std::string s_log = realm + ".launcher.log"; if (log) s_log = log->getValue(); + 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); bool b_dumpLog = (dumpLog ? (dumpLog->getValue() == "yes") : false); - std::string s_burstLog = realm + ".launcher.burst"; if (burstLog) s_burstLog = burstLog->getValue(); + std::string s_burstLog = host + ".launcher.burst"; if (burstLog) s_burstLog = burstLog->getValue(); a_workingNode->setLogs(s_log, b_splitLog, b_detailedLog, b_dumpLog, s_burstLog); } @@ -371,12 +414,12 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp if (eventOperation) commEngine->lazyInitialize(); // Node and Codec Engine registration /////////////////////////////////////////////////////// - a_nodes[originRealm->getValue()] = a_workingNode; + a_originHosts[originHost->getValue()] = a_workingNode; ///////////////////////////////////////////////////////////////////////////////////////////// } } - if (!uniqueRealm()) + if (!uniqueOriginHost()) a_workingNode = NULL; // by default, mode auto // Diameter comm engines which are loaded after application start (via management operation 'services') are not really started, @@ -470,60 +513,67 @@ anna::Millisecond Launcher::checkTimeMeasure(const std::string ¶meter, const bool Launcher::setWorkingNode(const std::string &name) throw() { bool result = false; - realm_nodes_it nodeIt = a_nodes.find(name); - if (nodeIt == a_nodes.end()) { + 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); + a_workingNode = const_cast(nodeIt->second); result = true; } return result; } -RealmNode *Launcher::getRealmNode(const std::string &realmName) const throw(anna::RuntimeException) { - realm_nodes_it it = a_nodes.find(realmName); - if (it != a_nodes.end()) return it->second; - throw anna::RuntimeException(anna::functions::asString("There is no realm node registered as '%s' (set Origin-Realm avp correctly or force a specific realm with 'node' operation)", realmName.c_str()), ANNA_FILE_LOCATION); +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); } -RealmNode *Launcher::getRealmNode(const anna::diameter::codec::Message &message) const throw(anna::RuntimeException) { - std::string originRealm = message.getAvp(anna::diameter::helpers::base::AVPID__Origin_Realm)->getDiameterIdentity()->getValue(); - return (getRealmNode(originRealm)); +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)); } -void Launcher::updateOperatedRealmNodeWithMessage(const anna::diameter::codec::Message &message) throw(anna::RuntimeException) { - if (!a_operatedRealm) // priority for working node by mean 'node' operation - a_operatedRealm = getRealmNode(message); +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); } -RealmNode *Launcher::getOperatedRealm() const throw(anna::RuntimeException) { - if(!a_operatedRealm) - throw anna::RuntimeException("Realm Node not identified (try to force a specific realm with 'node' operation)", ANNA_FILE_LOCATION); +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_operatedRealm; + 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); + + return a_operatedHost; } MyDiameterEntity *Launcher::getOperatedEntity() const throw(anna::RuntimeException) { - MyDiameterEntity *result = getOperatedRealm()->getEntity(); + MyDiameterEntity *result = (MyDiameterEntity *)(getOperatedHost()->getEntity()); if (!result) - throw anna::RuntimeException("No entity configured for the operated Realm Node", ANNA_FILE_LOCATION); + throw anna::RuntimeException("No entity configured for the operated node", ANNA_FILE_LOCATION); return result; } MyLocalServer *Launcher::getOperatedServer() const throw(anna::RuntimeException) { - MyLocalServer *result = getOperatedRealm()->getDiameterServer(); + MyLocalServer *result = (MyLocalServer *)(getOperatedHost()->getDiameterServer()); if (!result) - throw anna::RuntimeException("No local server configured for the operated Realm Node", ANNA_FILE_LOCATION); + throw anna::RuntimeException("No local server configured for the operated node", ANNA_FILE_LOCATION); return result; } MyDiameterEngine *Launcher::getOperatedEngine() const throw(anna::RuntimeException) { - return getOperatedRealm()->getMyDiameterEngine(); // never will be NULL + return (MyDiameterEngine *)getOperatedHost()->getCommEngine(); // never will be NULL } void Launcher::initialize() @@ -533,7 +583,7 @@ 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"; @@ -548,7 +598,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")) @@ -566,6 +616,13 @@ throw(anna::RuntimeException) { // Start time: a_start_time.setNow(); + + // Initial working directory: + char cwd[1024]; + if (getcwd(cwd, sizeof(cwd)) == NULL) + throw anna::RuntimeException("Cannot retrieve initial working directory !!", ANNA_FILE_LOCATION); + a_initialWorkingDirectory = cwd; + // Statistics: anna::statistics::Engine::instantiate().enable(); @@ -712,39 +769,16 @@ 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 (realm_nodes_it it = a_nodes.begin(); it != a_nodes.end(); it++) { - entity = it->second->getEntity(); + for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { + entity = (MyDiameterEntity *)(it->second->getEntity()); if (entity) entity->bind(); } @@ -785,11 +819,11 @@ bool Launcher::getDataBlockFromHexFile(const std::string &pathfile, anna::DataBl void Launcher::resetStatistics() throw() { if (a_workingNode) { - a_workingNode->getMyDiameterEngine()->resetStatistics(); + a_workingNode->getCommEngine()->resetStatistics(); } else { - for (realm_nodes_it it = a_nodes.begin(); it != a_nodes.end(); it++) { - it->second->getMyDiameterEngine()->resetStatistics(); + for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { + it->second->getCommEngine()->resetStatistics(); } } } @@ -801,11 +835,15 @@ void Launcher::resetCounters() throw() { } void Launcher::signalUSR2() throw(anna::RuntimeException) { + + std::string inputFile = getSignalUSR2InputFile(); + std::string outputFile = getSignalUSR2OutputFile(); + LOGNOTICE( std::string msg = "Captured signal SIGUSR2. Reading tasks at '"; - msg += SIGUSR2_TASKS_INPUT_FILENAME; + msg += inputFile; msg += "' (results will be written at '"; - msg += SIGUSR2_TASKS_OUTPUT_FILENAME; + msg += outputFile; msg += "')"; anna::Logger::notice(msg, ANNA_FILE_LOCATION); ); @@ -813,13 +851,18 @@ void Launcher::signalUSR2() throw(anna::RuntimeException) { // Operation: std::string line; std::string response_content; - std::ifstream in_file(SIGUSR2_TASKS_INPUT_FILENAME); - std::ofstream out_file(SIGUSR2_TASKS_OUTPUT_FILENAME); + std::ifstream in_file(inputFile); + std::ofstream out_file(outputFile); if(!in_file.is_open()) throw RuntimeException("Unable to read tasks", ANNA_FILE_LOCATION); if(!out_file.is_open()) throw RuntimeException("Unable to write tasks", ANNA_FILE_LOCATION); while(getline(in_file, line)) { + + // Ignore comments and blank lines: + if (line[0] == '#') continue; + if (std::string::npos == line.find_first_not_of(" \t")) continue; + LOGDEBUG( std::string msg = "Processing line: "; msg += line; @@ -847,7 +890,7 @@ std::string Launcher::help() const throw() { result += "\nOVERVIEW"; result += "\n--------"; result += "\n"; - result += "\nThe ADML (ANNA Diameter Multirealm Launcher) process is a multi-realm node with client and server"; + result += "\nThe ADML (ANNA Diameter MultiHost Launcher) process is a multi-host node with client and server"; result += "\n capabilities as well as balancer (proxy) features. It could be used as diameter server (i.e. to"; result += "\n simulate PCRF nodes, OCS systems, etc.), as diameter client (GGSNs, DPIs, etc.), and balancer"; result += "\n systems to provide failover to external round-robin launchers. Also, auxiliary encoder/decoder/loader"; @@ -858,7 +901,7 @@ std::string Launcher::help() const throw() { result += "\n establish as minimum), separate statistics analyzer per each resource, automatic CER/CEA and DWR/DWA"; result += "\n generation, expiration control and many more features."; result += "\n"; - result += "\nThe ADML process can easily configure a many realm nodes as needed, which will have own endpoints."; + result += "\nThe ADML process can easily configure a many origin-host nodes as needed, which will have own endpoints."; result += "\nYou should avoid loop configurations (client and server for that client) because automatic forwarding,"; result += "\n is implemented and this would get in a never ending cycle when a request is sent."; result += "\n"; @@ -897,7 +940,7 @@ std::string Launcher::help() const throw() { result += "\n "; result += "\n"; result += "\n "; - result += "\n "; + result += "\n "; result += "\n"; result += "\n"; result += "\nServer configuration:"; @@ -907,13 +950,13 @@ std::string Launcher::help() const throw() { result += "\n "; result += "\n"; result += "\n "; - result += "\n "; + result += "\n "; result += "\n"; result += "\n"; result += "\nIf you act as a proxy or a translation agent, you need to combine both former setups, and probably"; result += "\n will need to program the answers to be replied through the operations interface. To balance the"; result += "\n traffic at your client side you shall use '--balance' and '--sessionBasedModelsClientSocketSelection'"; - result += "\n arguments in order to define the balancing behaviour. To make hybrid setups you only must mix the realms:"; + result += "\n arguments in order to define the balancing behaviour. To make hybrid setups you only must mix the nodes:"; result += "\n"; result += "\nClient and server configuration:"; result += "\n"; @@ -924,8 +967,8 @@ std::string Launcher::help() const throw() { result += "\n "; result += "\n"; result += "\n "; - result += "\n "; - result += "\n "; + result += "\n "; + result += "\n "; result += "\n"; result += "\n"; result += "\n"; @@ -947,7 +990,7 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\n--------------------------------------------------------------------------------------- Node management"; result += "\n"; - result += "\nnode[|] Selects a context working node by mean a registered name."; + result += "\nnode[|] Selects a context working node by mean a registered name (origin-host)."; result += "\n All the subsequent operations will be forced to work with"; result += "\n this node, which makes possible some rare scenarios like"; result += "\n sending unexpected messages on remote peers. This is also"; @@ -957,12 +1000,12 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\nnode_auto Returns to the default behaviour (smart node selection)."; result += "\n Depending on the operation, this could imply a global"; - result += "\n action scope, affecting to all the registered realms."; + result += "\n action scope, affecting to all the registered hosts."; result += "\n This should be the normal configuration. Take into"; result += "\n account that if you fix the working node, this could"; result += "\n affect to things like test programming: communication"; result += "\n resources will override those which would be inferred"; - result += "\n from programmed messages Origin-Realm avps."; + result += "\n from programmed messages Origin-Host avps."; result += "\n"; result += "\n------------------------------------------------------------------------------------ Parsing operations"; result += "\n"; @@ -978,7 +1021,7 @@ std::string Launcher::help() const throw() { result += "\n line '--services' parameter was used or not. Those services which"; result += "\n are not correctly loaded will be ignored to keep the process alive."; result += "\n If you need to load services as deltas, you must firstly load the"; - result += "\n diameter base dictionary with stack id 0, because all the realms"; + result += "\n diameter base dictionary with stack id 0, because all the nodes"; result += "\n will use this dictionary to encode/decode base protocol messages"; result += "\n managed by the communication engine."; result += "\n"; @@ -991,9 +1034,19 @@ std::string Launcher::help() const throw() { result += "\n performance measurement. Context data can be written at"; result += "\n '/var/tmp/anna.context.' by mean 'kill -10 '."; result += "\n or sending operation 'context|[target file]'."; - result += "\n This operation applies over all the registered realm nodes"; + 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"; + result += "\n relative path this must exists from the new execution directory)."; + result += "\n If nothing provided, initial working directory will be restored."; result += "\nshow-oam Dumps current counters of the process. This is also done at"; result += "\n process context dump."; result += "\nshow-stats Dumps statistics of the process. This is also done at process"; @@ -1080,10 +1133,10 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\n------------------------------------------------------------------------------------------- Burst tests"; result += "\n"; - result += "\nIn order to simplify user experience, burst category operations are only allowed in single realm node"; - result += "\n configuration. Indeed, you could send messages with incorrect Origin-Realm, and no warning is shown."; - result += "\nAll the operations are performed through the unique realm: if you need to use more interfaces, you may"; - result += "\n launch different ADML instances. Is nonsense to allow burst in a multi-realm configured ADML, because"; + result += "\nIn order to simplify user experience, burst category operations are only allowed in single host node"; + result += "\n configuration. Indeed, you could send messages with unmatched Origin-Host, and no warning is shown."; + result += "\nAll the operations are performed through the unique host: if you need to use more interfaces, you may"; + result += "\n launch different ADML instances. Is nonsense to allow burst in a multi-host configured ADML, because"; result += "\n this feature is not able to coordinate the messages."; result += "\n"; result += "\nburst|[|parameter] Used for performance testing, we first program diameter requests"; @@ -1116,7 +1169,7 @@ std::string Launcher::help() const throw() { result += "\n-------------------------------------------------------------------------------------- Advanced testing"; result += "\n"; result += "\n Burst mode only allows single interface interaction. For multiple interface"; - result += "\n (realm) coordination, you could use the advanced test cases programming:"; + result += "\n (origin-host) coordination, you could use the advanced test cases programming:"; result += "\n"; result += "\n"; result += "\n test||[|parameters]"; @@ -1148,6 +1201,9 @@ std::string Launcher::help() const throw() { result += "\n sendxml2e|[|]"; result += "\n Sends xml source file (pathfile) to entity (it would be a"; result += "\n 'forward' event if it came through local server endpoint)."; + result += "\n Take into account that the xml message is encoded just on"; + result += "\n call. The xml file is not longer needed neither interpreted"; + result += "\n in case of modification, after calling this command."; result += "\n The step number should be provided for answers to indicate"; result += "\n the 'wait for request' corresponding step. If you miss this"; result += "\n reference, the sequence information (hop-by-hop, end-to-end)"; @@ -1155,6 +1211,8 @@ std::string Launcher::help() const throw() { result += "\n the difficulty of predicting these information). Be sure to"; result += "\n refer to a 'wait for request' step. Conditions like 'regexp'"; result += "\n (as we will see later) are not verified."; + result += "\n In the case of requests, the step number is used to force the"; + result += "\n copy of Session-Id value from the referred step."; result += "\n"; result += "\n sendxml2c|[|]"; result += "\n Sends xml source file (pathfile) to client (it would be a"; @@ -1214,7 +1272,7 @@ std::string Launcher::help() const throw() { result += "\n which fulfills that condition. This message is useful together with the peer"; result += "\n connection source in a further send step configured with the corresponding"; result += "\n response. You could also insert a delay between wait and send steps to be"; - result += "\n more realistic (processing time simulation in a specific ADML realm node)."; + result += "\n more realistic (processing time simulation in a specific ADML host node)."; result += "\n Always, a response send step will get the needed information from the most"; result += "\n recent wait step finding in reverse order (note that some race conditions"; result += "\n could happen if your condition is not specific enough)."; @@ -1252,7 +1310,7 @@ std::string Launcher::help() const throw() { result += "\n RFC says that a hop by hop must be unique for a specific connection, something that"; result += "\n could be difficult to manage if we have multiple available connections from client"; result += "\n side endpoint (entity or local server), even if we would have only one connection but"; - result += "\n several realm interfaces. It is enough to configure different hop-by-hop values within"; + result += "\n several host interfaces. It is enough to configure different hop-by-hop values within"; result += "\n each test case, because on reception, the Session-Id is used to identify that test case."; result += "\n"; result += "\n"; @@ -1339,15 +1397,6 @@ std::string Launcher::help() const throw() { result += "\n Test cases reports are not dumped on process context (too many information in general)."; result += "\n The report contains context information in every moment: this operation acts as a snapshot."; result += "\n"; - result += "\n test|report[|[yes]|no] Every time a test case is finished, its xml representation will be dump on a file under"; - result += "\n the execution directory (or the one configured in process command-line 'tmDir') with"; - result += "\n the name 'cycle-.testcase-.xml'. This option is disabled by"; - result += "\n default reducing IO. ADML process context won't show test manager whole information"; - result += "\n because it could be a huge amount of data to write. Anyway, you could use the 'look'"; - result += "\n operation to see the desired report(s)."; - result += "\n"; - result += "\n test|report-hex[|[yes]|no] Reports could include the diameter messages in hexadecimal format. Disabled by default."; - result += "\n"; result += "\n test|interact|amount|id Makes interactive a specific test case id. The amount is the margin of execution steps"; result += "\n to be done. Normally, we will execute 'test|interact|0|', which means that"; result += "\n the test case is selected to be interactive, but no step is executed. Then you have to"; @@ -1356,7 +1405,7 @@ std::string Launcher::help() const throw() { result += "\n steps margin, which could be useful to 'freeze' a test in the middle of its execution."; result += "\n You could also provide -1 to make it non-interactive resuming it from the current step."; result += "\n"; - result += "\n test|reset|[|id] Reset the test case for id provided, all the tests when missing. It could be hard/soft:"; + result += "\n test|reset|<[soft]/hard>[|id] Reset the test case for id provided, all the tests when missing. It could be hard/soft:"; result += "\n - hard: you probably may need to stop the load rate before. This operation initializes"; result += "\n all test cases regardless their states."; result += "\n - soft: only for finished cases (those with 'Success' or 'Failed' states). It does not"; @@ -1372,7 +1421,46 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\n test|summary Test manager general report (number of test cases, counts by state, global configuration,"; result += "\n forced in-progress limitation, reports visibility, etc.). Be careful when you have reports"; - result += "\n dumps enabled because all the programmed test cases will be dump and that could be heavy."; + result += "\n enabled because the programmed test cases dumps could be heavy (anyway you could enable the"; + result += "\n dumps separately, for any of the possible states: Initialized, InProgress, Failed, Success)."; + result += "\n"; + result += "\n test|report|[|[yes]|no]"; + result += "\n"; + result += "\n Enables/disables report generation for a certain test case state: initialized, in-progress,"; + result += "\n failed or success (also 'all' and 'none' reserved words could be used). This applies to report"; + result += "\n summary (former described operation) and automatic dumps during testing where only failed or"; + result += "\n successful states will appear: every time a test case is finished its xml representation will"; + result += "\n be dump on a file under the execution directory (or the one configured in process command-line"; + result += "\n 'tmDir') with the name:"; + result += "\n"; + result += "\n 'cycle-.testcase-.xml'."; + result += "\n"; + result += "\n By default, all the states are disabled to avoid IO overload. In most of cases not all the"; + result += "\n tests are going to fail then you could enable only such failed dumps. Anyway you could set"; + result += "\n the reports visibility to fit your needs in a given situation."; + result += "\n"; + result += "\n test|report-hex[|[yes]|no] Reports could include the diameter messages in hexadecimal format. Disabled by default."; + result += "\n"; + result += "\n"; + result += "\n------------------------------------------------------------------------------------- Dynamic procedure"; + result += "\n"; + result += "\ndynamic[|args] This launch an internal operation implemented in 'Procedure' class."; + result += "\n Its default implementation does nothing, but you could create a dynamic"; + result += "\n library 'libanna_launcherDynamic.so' and replace the one in this project."; + result += "\n One interesting application consists in the use of the diameter API and"; + result += "\n event operation to create a set of libraries as the testing framework."; + result += "\n To execute each test case, the ADML process would be executed with a"; + result += "\n specific library path. But the main use would be the stress programming"; + result += "\n to achieve a great amount of cloned (even mixed) tests without using"; + result += "\n the management operation interface by mean http or signals: a single"; + result += "\n call to 'dynamic' would be enough to start a cascade of internally"; + result += "\n implemented operations."; + result += "\n This operation accepts a generic string argument (piped or not, as you"; + result += "\n desire and depending on your procedure implementation)."; + result += "\n"; + result += "\n This operation requires advanced programming and knowlegde of ANNA Diameter"; + result += "\n stack and testing framework, to take advantage of all the possibilities."; + result += "\n"; result += "\n"; result += "\n"; result += "\nUSING OPERATIONS INTERFACE"; @@ -1395,13 +1483,13 @@ std::string Launcher::help() const throw() { result += "\n"; result += "\nThe alternative using SIGUSR2 signal requires the creation of the task(s) file which will be read at"; result += "\n signal event:"; - result += "\n echo \"<\" > "; result += SIGUSR2_TASKS_INPUT_FILENAME; + result += "\n echo \"<\" > "; result += getSignalUSR2InputFile(); result += "\n then"; result += "\n kill -12 "; result += "\n or"; result += "\n kill -s SIGUSR2 "; result += "\n and then see the results:"; - result += "\n cat "; result += SIGUSR2_TASKS_OUTPUT_FILENAME; + result += "\n cat "; result += getSignalUSR2OutputFile(); result += "\n"; result += "\n (this file is ended with EOF final line, useful managing huge batch files to ensure the job completion)"; result += "\n"; @@ -1415,26 +1503,75 @@ std::string Launcher::help() const throw() { return result; } + +void Launcher::logStatisticsSamples(const std::string &conceptsList) throw() { + anna::statistics::Engine &statEngine = anna::statistics::Engine::instantiate(); + + if(conceptsList == "all") { + if(statEngine.enableSampleLog(/* -1: all concepts */)) + LOGDEBUG(anna::Logger::debug("Sample log activation for all statistic concepts", ANNA_FILE_LOCATION)); + } + else if(conceptsList == "none") { + if(statEngine.disableSampleLog(/* -1: all concepts */)) + LOGDEBUG(anna::Logger::debug("Sample log deactivation for all statistic concepts", ANNA_FILE_LOCATION)); + } else { + anna::Tokenizer lst; + lst.apply(conceptsList, ","); + + 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)); + } + } + } +} + + void Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("Launcher", "eventOperation", ANNA_FILE_LOCATION)); if (operation == "") return; // ignore - LOGDEBUG(anna::Logger::debug(operation, ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("Operation: %s", operation.c_str()), ANNA_FILE_LOCATION)); // Default response: - response_content = "Operation processed with exception (see traces): "; + response_content = "Operation processed with exception: "; response_content += operation; std::string opt_response_content = ""; // aditional response content anna::DataBlock db_aux(true); anna::diameter::codec::Message codecMsg; // auxiliary codec message // Singletons: - CommandLine& cl(anna::CommandLine::instantiate()); - TestManager &testManager = TestManager::instantiate(); + anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate(); /////////////////////////////////////////////////////////////////// // Simple operations without arguments: + // Dynamic operation: + if(operation.find("dynamic") == 0) { + Procedure p(this); + int op_size = operation.size(); + std::string args = ((operation.find("dynamic|") == 0) && (op_size > 8)) ? operation.substr(8) : ""; + 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()); + } + catch(anna::RuntimeException &ex) { + ex.trace(); + response_content = ex.asString(); + return; + } + return; + } + // Help: if(operation == "help") { response_content = help(); @@ -1511,7 +1648,10 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons // Check the number of parameters: bool wrongBody = false; + if((opType == "change-dir") && (numParams > 1)) wrongBody = true; + if((opType == "log-statistics-samples") && (numParams != 1)) wrongBody = true; if((opType == "node") && (numParams > 1)) wrongBody = true; + if((opType == "node_auto") && (numParams > 0)) wrongBody = true; if(((opType == "code") || (opType == "decode")) && (numParams != 2)) wrongBody = true; @@ -1540,6 +1680,24 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons return; } + if(opType == "log-statistics-samples") { + logStatisticsSamples(param1); + response_content = anna::functions::asString("Log statistics samples for '%s' concepts", param1.c_str()); + return; + } + + // Change execution directory: + if(opType == "change-dir") { + if (param1 == "") param1 = a_initialWorkingDirectory; + if (chdir(param1.c_str()) == 0) + response_content = "New execution directory configured: "; + else + response_content = "Cannot assign provided execution directory: "; + + response_content += param1; + return; + } + if(opType == "services") { std::string servicesFile = ((numParams == 1) ? param1 : "services.xml"); try { @@ -1554,7 +1712,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons return; } - // Realm switch: + // Host switch: if(opType == "node") { if (param1 != "") { if (setWorkingNode(param1)) response_content = anna::functions::asString("Forced node is now '%s'", param1.c_str()); @@ -1576,12 +1734,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons return; } - // Operated realm from possible forced-working node: - a_operatedRealm = a_workingNode ? a_workingNode /* priority */: NULL /* auto */; + // Operated host from possible forced-working node: + a_operatedHost = a_workingNode ? a_workingNode /* priority */: NULL /* auto */; // Use later: - // If any message is managed: updateOperatedRealmNodeWithMessage(codecMessage) + // If any message is managed: updateOperatedOriginHostWithMessage(codecMessage) // To operate, use the exception-protected methods which never will return NULL: - // getOperatedRealm(), getOperatedEntity(), getOperatedServer(), getOperatedEngine() + // getOperatedHost(), getOperatedEntity(), getOperatedServer(), getOperatedEngine() if(opType == "code") { @@ -1646,8 +1804,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(opType == "sendxml2e") { codecMsg.loadXML(param1); - updateOperatedRealmNodeWithMessage(codecMsg); - msg = getOperatedRealm()->createCommMessage(); + updateOperatedOriginHostWithMessage(codecMsg); + msg = getOperatedHost()->createCommMessage(); msg->clearBody(); try { codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue sending (see validation mode configured in launcher) msg->setBody(codecMsg.code()); @@ -1655,25 +1813,25 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons // Get DataBlock from file with hex content: if(!getDataBlockFromHexFile(param1, db_aux)) throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION); - msg = getOperatedRealm()->createCommMessage(); + msg = getOperatedHost()->createCommMessage(); msg->setBody(db_aux); - try { if(getOperatedRealm()->logEnabled()) codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); } + try { if(getOperatedHost()->logEnabled()) codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); } } - bool success = getOperatedEntity()->send(msg, cl.exists("balance")); - getOperatedRealm()->releaseCommMessage(msg); + bool success = getOperatedEntity()->send(msg); + getOperatedHost()->releaseCommMessage(msg); // Detailed log: - if(getOperatedRealm()->logEnabled()) { + if(getOperatedHost()->logEnabled()) { anna::diameter::comm::Server *usedServer = getOperatedEntity()->getLastUsedResource(); anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL; std::string detail = usedClientSession ? usedClientSession->asString() : ""; // shouldn't happen - getOperatedRealm()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail); + getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail); } } else if((opType == "burst")) { - if (!uniqueRealm()) - throw anna::RuntimeException("Burst category operations are only allowed in single realm node configuration. This is only to simplify user experience.", ANNA_FILE_LOCATION); + if (!uniqueOriginHost()) + throw anna::RuntimeException("Burst category operations are only allowed in single host node configuration. This is only to simplify user experience.", ANNA_FILE_LOCATION); // burst|clear clears all loaded burst messages. // burst|load| loads the next diameter message into launcher burst. @@ -1690,7 +1848,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(param1 == "clear") { opt_response_content = "removed "; - opt_response_content += anna::functions::asString(getOperatedRealm()->clearBurst()); + opt_response_content += anna::functions::asString(getOperatedHost()->clearBurst()); opt_response_content += " elements"; } else if(param1 == "load") { if(param2 == "") throw anna::RuntimeException("Missing xml path file for burst load operation", ANNA_FILE_LOCATION); @@ -1699,7 +1857,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(codecMsg.isAnswer()) throw anna::RuntimeException("Cannot load diameter answers for burst feature", ANNA_FILE_LOCATION); try { codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue loading (see validation mode configured in launcher) - int position = getOperatedRealm()->loadBurstMessage(codecMsg.code()); + int position = getOperatedHost()->loadBurstMessage(codecMsg.code()); opt_response_content = "loaded '"; opt_response_content += param2; opt_response_content += "' file into burst list position "; @@ -1708,7 +1866,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(param2 == "") throw anna::RuntimeException("Missing initial load for burst start operation", ANNA_FILE_LOCATION); int initialLoad = atoi(param2.c_str()); - int processed = getOperatedRealm()->startBurst(initialLoad); + int processed = getOperatedHost()->startBurst(initialLoad); if(processed > 0) { opt_response_content = "initial load completed for "; @@ -1717,7 +1875,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if(param1 == "push") { if(param2 == "") throw anna::RuntimeException("Missing load amount for burst push operation", ANNA_FILE_LOCATION); - int pushed = getOperatedRealm()->pushBurst(atoi(param2.c_str())); + int pushed = getOperatedHost()->pushBurst(atoi(param2.c_str())); if(pushed > 0) { opt_response_content = "pushed "; @@ -1727,14 +1885,14 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(param2 == "") throw anna::RuntimeException("Missing amount for burst pop operation", ANNA_FILE_LOCATION); int releaseLoad = atoi(param2.c_str()); - int popped = getOperatedRealm()->popBurst(releaseLoad); + int popped = getOperatedHost()->popBurst(releaseLoad); if(popped > 0) { opt_response_content = "burst popped for "; opt_response_content += anna::functions::entriesAsString(popped, "message"); } } else if(param1 == "stop") { - int left = getOperatedRealm()->stopBurst(); + int left = getOperatedHost()->stopBurst(); if(left != -1) { opt_response_content += anna::functions::entriesAsString(left, "message"); @@ -1744,12 +1902,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(param2 == "") param2 = "yes"; bool repeat = (param2 == "yes"); - getOperatedRealm()->repeatBurst(repeat); + getOperatedHost()->repeatBurst(repeat); opt_response_content += (repeat ? "repeat enabled" : "repeat disabled"); } else if(param1 == "send") { if(param2 == "") throw anna::RuntimeException("Missing amount for burst send operation", ANNA_FILE_LOCATION); - int sent = getOperatedRealm()->sendBurst(atoi(param2.c_str())); + int sent = getOperatedHost()->sendBurst(atoi(param2.c_str())); if(sent > 0) { opt_response_content = "sent "; @@ -1758,29 +1916,30 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if(param1 == "goto") { if(param2 == "") throw anna::RuntimeException("Missing order position for burst goto operation", ANNA_FILE_LOCATION); - opt_response_content = getOperatedRealm()->gotoBurst(atoi(param2.c_str())); + opt_response_content = getOperatedHost()->gotoBurst(atoi(param2.c_str())); } else if(param1 == "look") { int order = ((param2 != "") ? atoi(param2.c_str()) : -1); opt_response_content = "\n\n"; - opt_response_content += getOperatedRealm()->lookBurst(order); + opt_response_content += getOperatedHost()->lookBurst(order); } else { throw anna::RuntimeException("Wrong body content format on HTTP Request for 'burst' operation (unexpected action parameter). See help", ANNA_FILE_LOCATION); } } else if((opType == "test")) { - // test||[|parameters] Add a new step to the test case ... - // test|ttps| Starts/resume the provided number of time ticks per second (ttps). The ADML starts ... - // test|next[|] Forces the execution of the next test case(s) without waiting for test manager tick ... - // test|ip-limit[|amount] In-progress limit of test cases. No new test cases will be launched over this value ... - // test|repeats| Restarts the whole programmed test list when finished the amount number of times ... - // test|report[|[yes]|no] Every time a test case is finished a report file in xml format will be created under ... - // test|report-hex[|[yes]|no] Reports could include the diameter messages in hexadecimal format. Disabled by default. - // test|goto| Updates current test pointer position. - // 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|[|id] Reset the test case for id provided, all the tests when missing ... - // test|clear Clears all the programmed test cases. - // test|summary Test manager general report (number of test cases, counts by state ... + // test||[|parameters] Add a new step to the test case ... + // test|ttps| Starts/resume the provided number of time ticks per second (ttps). The ADML starts ... + // test|next[|] Forces the execution of the next test case(s) without waiting for test manager tick ... + // test|ip-limit[|amount] In-progress limit of test cases. No new test cases will be launched over this value ... + // test|repeats| Restarts the whole programmed test list when finished the amount number of times ... + // test|report|[|[yes]|no] + // Enables/disables report generation for a certain test case state: initialized, in-progress ... + // test|report-hex[|[yes]|no] Reports could include the diameter messages in hexadecimal format. Disabled by default. + // test|goto| Updates current test pointer position. + // 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|clear Clears all the programmed test cases. + // test|summary Test manager general report (number of test cases, counts by state ... if(param1 == "ttps") { @@ -1843,12 +2002,37 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons opt_response_content += anna::functions::asString("Pool repeats: %d%s (current cycle: %d)", repeats, nolimit.c_str(), testManager.getPoolCycle()); } else if(param1 == "report") { - if (numParams > 2) + if (numParams > 3) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); - if(param2 == "") param2 = "yes"; - testManager.setDumpReports((param2 == "yes")); - opt_response_content += (testManager.getDumpReports() ? "report enabled" : "report disabled"); + if(param2 == "") param2 = "all"; + if(param3 == "") param3 = "yes"; + bool enable = (param3 == "yes"); + + if(param2 == "initialized") + testManager.setDumpInitializedReports(enable); + else if(param2 == "in-progress") + testManager.setDumpInProgressReports(enable); + else if(param2 == "failed") + testManager.setDumpFailedReports(enable); + else if(param2 == "success") + testManager.setDumpSuccessReports(enable); + else if(param2 == "all") { + param2 = "any"; + testManager.setDumpAllReports(enable); + } + else if(param2 == "none") { + enable = !enable; + param2 = "any"; + testManager.setDumpAllReports(enable); + } + else + throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + + opt_response_content += (enable ? "report enabled " : "report disabled "); + opt_response_content += "for tests in '"; + opt_response_content += param2; + opt_response_content += "' state"; } else if(param1 == "report-hex") { if (numParams > 2) @@ -1878,7 +2062,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); int id = ((param2 != "") ? atoi(param2.c_str()) : -1); - TestCase *testCase = testManager.findTestCase(id); + anna::testing::TestCase *testCase = testManager.findTestCase(id); if (testCase) { response_content = testCase->asXMLString(); @@ -1904,7 +2088,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Interactive amount must be -1 (to disable interactive mode) or a positive number.", ANNA_FILE_LOCATION); int id = atoi(param3.c_str()); - TestCase *testCase = testManager.findTestCase(id); + anna::testing::TestCase *testCase = testManager.findTestCase(id); if (testCase) { if (amount == -1) { testCase->makeInteractive(false); @@ -1930,11 +2114,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if (numParams > 3) 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") + if(param2 == "") param2 = "soft"; + 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); int id = ((param3 != "") ? atoi(param3.c_str()) : -1); - TestCase *testCase = ((id != -1) ? testManager.findTestCase(id) : NULL); + anna::testing::TestCase *testCase = ((id != -1) ? testManager.findTestCase(id) : NULL); if (testCase) { bool done = testCase->reset((param2 == "hard") ? true:false); @@ -1947,7 +2132,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons else { if (id == -1) { bool anyReset = testManager.resetPool((param2 == "hard") ? true:false); - opt_response_content = "reset have been sent to all programmed tests: "; opt_response_content += anyReset ? "some/all have been reset" : "nothing was reset"; + 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 { opt_response_content = "cannot found test id ("; @@ -2000,20 +2185,18 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); if(param3 == "") throw anna::RuntimeException(anna::functions::asString("Missing xml file for '%s' command in test id operation", param2.c_str()), ANNA_FILE_LOCATION); codecMsg.loadXML(param3); - if (codecMsg.isRequest()) { - if (param4 != "") - throw anna::RuntimeException("Step number is provided with answers (to resolve the corresponding 'wait for request' step), but NOT with requests", ANNA_FILE_LOCATION); - } - else { - if (param4 == "") LOGWARNING(anna::Logger::warning("Step number has not been provided. Take into account that this answer message will be sent 'as is' and sequence information could be wrong at the remote peer", ANNA_FILE_LOCATION)); - } - updateOperatedRealmNodeWithMessage(codecMsg); + LOGWARNING( + if (!codecMsg.isRequest() && (param4 == "")) + anna::Logger::warning("Step number has not been provided. Take into account that this answer message will be sent 'as is' and sequence information could be wrong at the remote peer", ANNA_FILE_LOCATION); + ); + + updateOperatedOriginHostWithMessage(codecMsg); int stepNumber = ((param4 != "") ? atoi(param4.c_str()):-1); if (param2 == "sendxml2e") - testManager.getTestCase(id)->addSendxml2e(codecMsg.code(), getOperatedRealm(), stepNumber); // creates / reuses + testManager.getTestCase(id)->addSendxml2e(codecMsg.code(), getOperatedHost(), stepNumber); // creates / reuses else - testManager.getTestCase(id)->addSendxml2c(codecMsg.code(), getOperatedRealm(), stepNumber); // creates / reuses + testManager.getTestCase(id)->addSendxml2c(codecMsg.code(), getOperatedHost(), stepNumber); // creates / reuses } else if (param2 == "delay") { if (numParams > 3) @@ -2045,10 +2228,13 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } } else if (param2 == "sh-command") { - if (numParams > 4) - throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); + // Allow pipes in command: + //if (numParams > 4) + // throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); if(param3 == "") throw anna::RuntimeException("Missing script/executable command-line for 'sh-command' in test id operation", ANNA_FILE_LOCATION); - testManager.getTestCase(id)->addCommand(param3); // creates / reuses + std::string token = "|sh-command|"; + std::string command = operation.substr(operation.find(token) + token.size()); + testManager.getTestCase(id)->addCommand(command); // creates / reuses } else { throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); @@ -2060,8 +2246,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(opType == "sendxml2c") { codecMsg.loadXML(param1); - updateOperatedRealmNodeWithMessage(codecMsg); - msg = getOperatedRealm()->createCommMessage(); + updateOperatedOriginHostWithMessage(codecMsg); + msg = getOperatedHost()->createCommMessage(); msg->clearBody(); try { codecMsg.valid(); } catch(anna::RuntimeException &ex) { ex.trace(); } // at least we need to see validation errors although it will continue sending (see validation mode configured in launcher) @@ -2070,18 +2256,18 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons // Get DataBlock from file with hex content: if(!getDataBlockFromHexFile(param1, db_aux)) throw anna::RuntimeException("Error reading hex file provided", ANNA_FILE_LOCATION); - msg = getOperatedRealm()->createCommMessage(); + msg = getOperatedHost()->createCommMessage(); msg->setBody(db_aux); } bool success = getOperatedServer()->send(msg); - getOperatedRealm()->releaseCommMessage(msg); + getOperatedHost()->releaseCommMessage(msg); // Detailed log: - if(getOperatedRealm()->logEnabled()) { + if(getOperatedHost()->logEnabled()) { anna::diameter::comm::ServerSession *usedServerSession = getOperatedServer()->getLastUsedResource(); std::string detail = usedServerSession ? usedServerSession->asString() : ""; // shouldn't happen - getOperatedRealm()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail); + getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail); } } else if(opType == "loadxml") { codecMsg.loadXML(param1); @@ -2102,11 +2288,11 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if (param1 == "clear") { getOperatedServer()->getReactingAnswers()->clear(); } else if (param1 == "dump") { - getOperatedServer()->getReactingAnswers()->dump(); + getOperatedServer()->getReactingAnswers()->dump("programmed_answer"); } else { codecMsg.loadXML(param1); - updateOperatedRealmNodeWithMessage(codecMsg); - anna::diameter::codec::Message *message = getOperatedRealm()->getCodecEngine()->createMessage(param1); // loads xml again, lesser of two evils + updateOperatedOriginHostWithMessage(codecMsg); + anna::diameter::codec::Message *message = getOperatedHost()->getCodecEngine()->createMessage(param1); // loads xml again, lesser of two evils LOGDEBUG(anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION)); if(message->isRequest()) @@ -2128,11 +2314,11 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons } else if (param1 == "clear") { getOperatedEntity()->getReactingAnswers()->clear(); } else if (param1 == "dump") { - getOperatedEntity()->getReactingAnswers()->dump(); + getOperatedEntity()->getReactingAnswers()->dump("programmed_answer"); } else { codecMsg.loadXML(param1); - updateOperatedRealmNodeWithMessage(codecMsg); - anna::diameter::codec::Message *message = getOperatedRealm()->getCodecEngine()->createMessage(param1); // loads xml again, lesser of two evils + updateOperatedOriginHostWithMessage(codecMsg); + anna::diameter::codec::Message *message = getOperatedHost()->getCodecEngine()->createMessage(param1); // loads xml again, lesser of two evils LOGDEBUG(anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION)); if(message->isRequest()) @@ -2160,18 +2346,23 @@ throw() { anna::comm::Application::asXML(result); // Timming: result->createAttribute("StartTime", a_start_time.asString()); + result->createAttribute("InitialWorkingDirectory", a_initialWorkingDirectory); result->createAttribute("SecondsLifeTime", anna::time::functions::lapsedMilliseconds() / 1000); // Diameter: - for (realm_nodes_it it = a_nodes.begin(); it != a_nodes.end(); it++) { + for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) { it->second->asXML(result); } + // Registered codec engines: + anna::diameter::codec::EngineManager &em = anna::diameter::codec::EngineManager::instantiate(); + em.asXML(result); + // OAM & statistics: oamAsXML(result); statsAsXML(result); // Testing: could be heavy if test case reports are enabled - TestManager::instantiate().asXML(result); + anna::testing::TestManager::instantiate().asXML(result); return result; }