#include <math.h> // ceil
#include <climits>
#include <unistd.h> // chdir
-#include <regex>
+//#include <regex> TODO: use this from gcc4.9.0: http://stackoverflow.com/questions/8060025/is-this-c11-regex-error-me-or-the-compiler
+#include <stdio.h>
// Project
#include <anna/timex/Engine.hpp>
#include <anna/diameter.comm/ApplicationMessageOamModule.hpp>
#include <anna/testing/defines.hpp>
#include <anna/xml/xml.hpp>
+#include <anna/diameter.comm/OriginHost.hpp>
+#include <anna/diameter.comm/OriginHostManager.hpp>
#include <Procedure.hpp>
// Process
#include <Launcher.hpp>
#include <MyDiameterEngine.hpp>
-#include <anna/diameter.comm/OriginHost.hpp>
#include <anna/testing/TestManager.hpp>
#include <anna/testing/TestCase.hpp>
//a_admlMinResolution = (anna::Millisecond)100;
a_counterRecorderClock = NULL;
- // a_originHosts.clear();
a_workingNode = NULL;
a_httpServerSocket = NULL;
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);
}
if (eventOperation) commEngine->lazyInitialize();
// Node and Codec Engine registration ///////////////////////////////////////////////////////
- a_originHosts[originHost->getValue()] = a_workingNode;
+ ohm.registerOriginHost(originHost->getValue(), a_workingNode);
/////////////////////////////////////////////////////////////////////////////////////////////
}
}
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<anna::diameter::comm::OriginHost*>(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<anna::diameter::comm::OriginHost*>(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) {
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);
// 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 = ".";
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();
// 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();
}
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();
}
}
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";
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|<soft|hard> 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,";
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();
// 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|<soft|hard> 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 ...
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 ";
}
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 {
}
}
}
+ 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);
// optional 'full':
if(param4 != "strict") {
+
+ // TODO: use this from gcc4.9.0: http://stackoverflow.com/questions/8060025/is-this-c11-regex-error-me-or-the-compiler
+/*
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, pos_1, pos_2;
+
+ pos = regexp.find("hop-by-hop-id=", 0u);
+ pos = regexp.find("\"", pos);
+ pos_1 = pos;
+ pos = regexp.find("\"", pos+1);
+ pos_2 = pos;
+ regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+
+ pos = regexp.find("end-to-end-id=", 0u);
+ pos = regexp.find("\"", pos);
+ pos_1 = pos;
+ pos = regexp.find("\"", pos+1);
+ pos_2 = pos;
+ regexp.replace(pos_1 + 1, pos_2 - pos_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 += "$";
}
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);
}