X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FLauncher.cpp;h=871fcb3878ffc525ce5a788957151dcccccc13f4;hb=7ee10b64f4c116460ffef5784eb9ef87d3f2339c;hp=116c325e75285a49a5e0e2f3e7d6be04091e2256;hpb=0c533bf948a63d134c8001e16b15194b197cb99a;p=anna.git diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 116c325..871fcb3 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,16 @@ #include #include #include +#include #include +#include // Process #include -#include #include -#include -#include +#include +#include +#include #define SIGUSR2_TASKS_INPUT_FILENAME "sigusr2.in" @@ -325,11 +329,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; @@ -337,19 +354,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) { @@ -366,7 +385,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->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 +397,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); @@ -504,20 +523,20 @@ bool Launcher::setWorkingNode(const std::string &name) throw() { ); } else { - a_workingNode = const_cast(nodeIt->second); + a_workingNode = const_cast(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)); } @@ -527,7 +546,14 @@ void Launcher::updateOperatedOriginHostWithMessage(const anna::diameter::codec:: 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 +561,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,7 +585,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"; @@ -574,7 +600,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 +614,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(); @@ -754,7 +780,7 @@ throw(anna::RuntimeException) { // 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(); } @@ -768,8 +794,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); @@ -784,7 +809,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; @@ -793,13 +819,28 @@ 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(); + it->second->getCommEngine()->resetStatistics(); } } } @@ -1198,16 +1239,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|