#include <anna/diameter/helpers/base/functions.hpp>
#include <anna/time/functions.hpp>
#include <anna/diameter.comm/ApplicationMessageOamModule.hpp>
+#include <anna/testing/defines.hpp>
#include <anna/xml/xml.hpp>
#include <Procedure.hpp>
// Process
#include <Launcher.hpp>
-#include <OriginHost.hpp>
#include <MyDiameterEngine.hpp>
-#include <TestManager.hpp>
-#include <TestCase.hpp>
+#include <anna/diameter.comm/OriginHost.hpp>
+#include <anna/testing/TestManager.hpp>
+#include <anna/testing/TestCase.hpp>
#define SIGUSR2_TASKS_INPUT_FILENAME "sigusr2.in"
// 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;
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) {
// Register one entity for this engine:
a_workingNode->createEntity(entity->getValue(), ceaTimeoutMs, answersTimeoutMs);
- 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();
}
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);
);
}
else {
- a_workingNode = const_cast<OriginHost*>(nodeIt->second);
+ a_workingNode = const_cast<anna::diameter::comm::OriginHost*>(nodeIt->second);
result = true;
}
return result;
}
-OriginHost *Launcher::getOriginHost(const std::string &oh) const throw(anna::RuntimeException) {
+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);
}
-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));
}
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);
}
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()
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";
// 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"))
// Start client connections //////////////////////////////////////////////////////////////////////////////////
MyDiameterEntity *entity;
for (origin_hosts_it it = a_originHosts.begin(); it != a_originHosts.end(); it++) {
- entity = it->second->getEntity();
+ entity = (MyDiameterEntity *)(it->second->getEntity());
if (entity) entity->bind();
}
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();
+ it->second->getCommEngine()->resetStatistics();
}
}
}
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();
///////////////////////////////////////////////////////////////////
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);
- p.execute(args, response_content);
+ try {
+ p.execute(args, response_content, getWorkingNode());
+ }
+ catch(anna::RuntimeException &ex) {
+ ex.trace();
+ response_content = ex.asString();
+ return;
+ }
return;
}
try { if(getOperatedHost()->logEnabled()) codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); }
}
- bool success = getOperatedEntity()->send(msg, cl.exists("balance"));
+ bool success = getOperatedEntity()->send(msg);
getOperatedHost()->releaseCommMessage(msg);
// Detailed log:
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();
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);
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);
} else if (param1 == "clear") {
getOperatedServer()->getReactingAnswers()->clear();
} else if (param1 == "dump") {
- getOperatedServer()->getReactingAnswers()->dump();
+ getOperatedServer()->getReactingAnswers()->dump("programmed_answer");
} else {
codecMsg.loadXML(param1);
updateOperatedOriginHostWithMessage(codecMsg);
} else if (param1 == "clear") {
getOperatedEntity()->getReactingAnswers()->clear();
} else if (param1 == "dump") {
- getOperatedEntity()->getReactingAnswers()->dump();
+ getOperatedEntity()->getReactingAnswers()->dump("programmed_answer");
} else {
codecMsg.loadXML(param1);
updateOperatedOriginHostWithMessage(codecMsg);
statsAsXML(result);
// Testing: could be heavy if test case reports are enabled
- TestManager::instantiate().asXML(result);
+ anna::testing::TestManager::instantiate().asXML(result);
return result;
}