1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
13 #include <EventOperation.hpp>
14 #include <Launcher.hpp>
15 #include <Procedure.hpp>
16 #include <MyDiameterEngine.hpp>
17 #include <MyLocalServer.hpp>
18 #include <anna/testing/TestManager.hpp>
22 #include <unistd.h> // chdir
25 #include <anna/diameter.comm/OriginHost.hpp>
26 #include <anna/json/functions.hpp>
27 #include <anna/diameter/codec/Message.hpp>
28 #include <anna/diameter/helpers/base/functions.hpp>
29 #include <anna/time/functions.hpp>
30 #include <anna/core/functions.hpp>
31 #include <anna/xml/xml.hpp>
32 #include <anna/diameter.comm/Message.hpp>
38 bool EventOperation::node(std::string &response, const std::string & name) {
40 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
42 anna::diameter::comm::OriginHost *workingNode;
43 try { workingNode = my_app.getWorkingNode(); } catch(anna::RuntimeException &ex) { ex.trace(); }
46 if (my_app.setWorkingNode(name)) {
47 response = anna::functions::asString("Forced node is now '%s'", name.c_str());
48 my_app.setOperatedHost(my_app.getWorkingNode()); // now is the new one
51 response = anna::functions::asString("Node '%s' invalid. Nothing done", name.c_str());
57 response = anna::functions::encodeBase64(workingNode->asXMLString());
60 response = workingNode->asXMLString();
64 response = "Working node is automatic";
70 bool EventOperation::node_auto(std::string &response) {
72 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
75 response = "Working node has been set to automatic";
80 ////////////////////////
81 // Parsing operations //
82 ////////////////////////
83 bool EventOperation::code(std::string &response, const std::string & diameterJson) {
86 std::string diameterXml = anna::json::functions::json2xml(diameterJson, success);
88 response += "json to xml failed, unable to encode !";
91 anna::diameter::codec::Message codecMsg; // auxiliary codec message
92 codecMsg.loadXMLString(diameterXml);
93 response = anna::functions::asHexString(codecMsg.code());
98 bool EventOperation::decode(std::string &response, const std::string & diameterHex) {
100 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
102 anna::DataBlock db_aux(true);
103 anna::functions::fromHexString(diameterHex, db_aux);
104 anna::diameter::codec::Message codecMsg; // auxiliary codec message
106 codecMsg.decode(db_aux);
107 std::string xmlString = codecMsg.asXMLString();
108 response = anna::functions::encodeBase64(xmlString);
110 catch(anna::RuntimeException &ex) { ex.trace(); }
115 bool EventOperation::loadmsg(std::string &response, const std::string & diameterJson) {
118 std::string diameterXml = anna::json::functions::json2xml(diameterJson, success);
120 response += "json to xml failed, unable to load message !";
123 anna::diameter::codec::Message codecMsg; // auxiliary codec message
124 codecMsg.loadXMLString(diameterXml);
125 response = anna::functions::encodeBase64(codecMsg.asXMLString());
133 bool EventOperation::services(std::string &response, const std::string & servicesJson) {
135 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
138 std::string servicesXml = anna::json::functions::json2xml(servicesJson, success);
140 response += "json to xml failed, unable to load services !";
145 my_app.loadServicesFromXMLString(servicesXml, true /* bind entities */);
147 catch(anna::RuntimeException &ex) {
149 response += "loaded services with errors";
152 response = "loaded services correctly";
157 bool EventOperation::diameterServerSessions(std::string &response, int sessions) {
159 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
162 my_app.getOperatedServer()->setMaxConnections(sessions);
164 catch(anna::RuntimeException &ex) {
166 response += "fail to operate the server";
169 response = "new sessions successfully established on operated diameter server";
174 bool EventOperation::change_dir(std::string &response, const std::string & directory) {
176 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
178 std::string dir = directory;
179 if (dir == "") dir = my_app.getInitialWorkingDirectory();
180 bool result = (chdir(dir.c_str()) == 0);
183 response = "New execution directory configured: ";
185 response = "Cannot assign provided execution directory: ";
191 ////////////////////////////////
192 // Client sessions visibility //
193 ////////////////////////////////
194 bool EventOperation::visibility(std::string &response, const std::string & action, const std::string &addressPort, int socket) {
196 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
200 if(addressPort != "") {
202 std::string key = addressPort;
204 key += anna::functions::asString(socket);
206 if(action == "hide") my_app.getOperatedEngine()->findClientSession(key)->hide();
207 if(action == "show") my_app.getOperatedEngine()->findClientSession(key)->show();
208 if(action == "hidden") response = my_app.getOperatedEngine()->findClientSession(key)->hidden() ? "true" : "false";
209 if(action == "shown") response = my_app.getOperatedEngine()->findClientSession(key)->shown() ? "true" : "false";
213 anna::functions::getAddressAndPortFromSocketLiteral(addressPort, address, port);
215 if(action == "hide") my_app.getOperatedEngine()->findServer(address, port)->hide();
216 if(action == "show") my_app.getOperatedEngine()->findServer(address, port)->show();
217 if(action == "hidden") response = my_app.getOperatedEngine()->findServer(address, port)->hidden() ? "true" : "false";
218 if(action == "shown") response = my_app.getOperatedEngine()->findServer(address, port)->shown() ? "true" : "false";
221 if(action == "hide") my_app.getOperatedEntity()->hide();
222 if(action == "show") my_app.getOperatedEntity()->show();
223 if(action == "hidden") response = my_app.getOperatedEntity()->hidden() ? "true" : "false";
224 if(action == "shown") response = my_app.getOperatedEntity()->shown() ? "true" : "false";
234 bool EventOperation::collect(std::string &response) {
236 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
238 my_app.resetCounters();
239 my_app.resetStatistics();
240 response = "All process counters & statistic information have been reset";
245 bool EventOperation::context(std::string &response, const std::string & targetFile) {
247 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
249 std::string contextFile = (targetFile != "") ? targetFile : anna::functions::asString("/var/tmp/anna.context.%05d", my_app.getPid());
250 my_app.writeContext(contextFile);
251 response = anna::functions::asString("Context dumped on file '%s'", contextFile.c_str());
256 bool EventOperation::forceCountersRecord(std::string &response) {
258 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
260 my_app.forceCountersRecord();
261 response = "Current counters have been dump to disk";
266 bool EventOperation::log_statistics_samples(std::string &response, const std::string & list) {
268 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
270 my_app.logStatisticsSamples(list);
271 response = anna::functions::asString("Log statistics samples for '%s' concepts", list.c_str());
276 bool EventOperation::show_oam(std::string &response) {
278 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
280 anna::xml::Node root("root");
281 response = anna::xml::Compiler().apply(my_app.oamAsXML(&root));
283 response = anna::functions::encodeBase64(response);
288 bool EventOperation::show_stats(std::string &response) {
290 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
292 anna::xml::Node root("root");
293 response = anna::xml::Compiler().apply(my_app.statsAsXML(&root));
295 response = anna::functions::encodeBase64(response);
300 /////////////////////
301 // Flow operations //
302 /////////////////////
303 bool EventOperation::sendmsg_hex_2e(std::string &response, const std::string & diameterJson_or_Hex, bool msg_or_hex) {
305 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
306 anna::diameter::codec::Message codecMsg; // auxiliary codec message
308 anna::diameter::comm::Message *msg;
311 std::string diameterXml = anna::json::functions::json2xml(diameterJson_or_Hex, success);
313 response += "json to xml failed, unable to send message !";
316 codecMsg.loadXMLString(diameterXml);
318 my_app.updateOperatedOriginHostWithMessage(codecMsg);
319 msg = my_app.getOperatedHost()->createCommMessage();
322 catch(anna::RuntimeException &ex) {
324 response += "invalid operated host";
327 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)
328 msg->setBody(codecMsg.code());
330 // Get DataBlock from hex content:
331 anna::DataBlock db_aux(true);
332 std::string hexString = diameterJson_or_Hex;
333 hexString.erase(std::remove(hexString.begin(), hexString.end(), ':'), hexString.end());
335 std::string msg = "Hex string (remove colons if exists): ";
337 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
339 anna::functions::fromHexString(hexString, db_aux); // could launch exception
341 my_app.updateOperatedOriginHostWithMessage(db_aux);
342 msg = my_app.getOperatedHost()->createCommMessage();
344 catch(anna::RuntimeException &ex) {
346 response += "invalid operated host";
349 msg->setBody(db_aux);
350 try { if(my_app.getOperatedHost()->logEnabled()) codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); }
353 success = my_app.getOperatedEntity()->send(msg);
354 my_app.getOperatedHost()->releaseCommMessage(msg);
357 if(my_app.getOperatedHost()->logEnabled()) {
358 anna::diameter::comm::Server *usedServer = my_app.getOperatedEntity()->getLastUsedResource();
359 anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL;
360 std::string detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // shouldn't happen
361 my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail);
365 response = "Operation processed"; // could be failed
369 bool EventOperation::sendmsg_hex_2c(std::string &response, const std::string & diameterJson_or_Hex, bool msg_or_hex) {
371 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
372 anna::diameter::codec::Message codecMsg; // auxiliary codec message
374 anna::diameter::comm::Message *msg;
377 std::string diameterXml = anna::json::functions::json2xml(diameterJson_or_Hex, success);
379 response += "json to xml failed, unable to send message !";
382 codecMsg.loadXMLString(diameterXml);
384 my_app.updateOperatedOriginHostWithMessage(codecMsg);
385 msg = my_app.getOperatedHost()->createCommMessage();
388 catch(anna::RuntimeException &ex) {
390 response += "invalid operated host";
393 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)
394 msg->setBody(codecMsg.code());
396 // Get DataBlock from hex content:
397 anna::DataBlock db_aux(true);
398 std::string hexString = diameterJson_or_Hex;
399 hexString.erase(std::remove(hexString.begin(), hexString.end(), ':'), hexString.end());
401 std::string msg = "Hex string (remove colons if exists): ";
403 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
405 anna::functions::fromHexString(hexString, db_aux); // could launch exception
407 my_app.updateOperatedOriginHostWithMessage(db_aux);
408 msg = my_app.getOperatedHost()->createCommMessage();
410 catch(anna::RuntimeException &ex) {
412 response += "invalid operated host";
415 msg->setBody(db_aux);
416 try { if(my_app.getOperatedHost()->logEnabled()) codecMsg.decode(db_aux); } catch(anna::RuntimeException &ex) { ex.trace(); }
419 success = my_app.getOperatedServer()->send(msg);
420 my_app.getOperatedHost()->releaseCommMessage(msg);
423 if(my_app.getOperatedHost()->logEnabled()) {
424 anna::diameter::comm::ServerSession *usedServerSession = my_app.getOperatedServer()->getLastUsedResource();
425 std::string detail = usedServerSession ? usedServerSession->asString() : "[null server session]"; // shouldn't happen
426 my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail);
430 response = "Operation processed"; // could be failed
434 bool EventOperation::answermsg_action_2e(std::string &response, const std::string & diameterJson_or_action, bool msg_or_action) {
436 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
437 anna::diameter::codec::Message codecMsg; // auxiliary codec message
438 anna::diameter::codec::Message *message;
443 std::string diameterXml = anna::json::functions::json2xml(diameterJson_or_action, success);
445 response += "json to xml failed, unable to send message !";
448 codecMsg.loadXMLString(diameterXml);
450 my_app.updateOperatedOriginHostWithMessage(codecMsg);
451 message = my_app.getOperatedHost()->getCodecEngine()->createMessage(diameterXml, false /* is xml string */); // loads xml again, lesser of two evils
452 LOGDEBUG(anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION));
454 catch(anna::RuntimeException &ex) {
456 response += "invalid operated host";
460 if(message->isRequest()) {
461 response += "cannot program diameter requests. Answer type must be provided";
465 int code = message->getId().first;
466 LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to entity' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION));
467 response = "Added 'answer to entity' to the FIFO queue corresponding to its message code";
468 my_app.getOperatedEntity()->getReactingAnswers()->addMessage(code, message);
472 if(diameterJson_or_action == "list") { // programmed answers FIFO's to stdout
473 response = anna::functions::encodeBase64(my_app.getOperatedEntity()->getReactingAnswers()->asString("ANSWERS TO ENTITY"));
474 } else if (diameterJson_or_action == "rotate") {
475 my_app.getOperatedEntity()->getReactingAnswers()->rotate(true);
477 } else if (diameterJson_or_action == "exhaust") {
478 my_app.getOperatedEntity()->getReactingAnswers()->rotate(false);
479 response = "exhaust";
480 } else if (diameterJson_or_action == "clear") {
481 my_app.getOperatedEntity()->getReactingAnswers()->clear();
483 } else if (diameterJson_or_action == "dump") {
484 my_app.getOperatedEntity()->getReactingAnswers()->dump("programmed_answer");
493 bool EventOperation::answermsg_action_2c(std::string &response, const std::string & diameterJson_or_action, bool msg_or_action) {
495 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
496 anna::diameter::codec::Message codecMsg; // auxiliary codec message
497 anna::diameter::codec::Message *message;
502 std::string diameterXml = anna::json::functions::json2xml(diameterJson_or_action, success);
504 response += "json to xml failed, unable to send message !";
507 codecMsg.loadXMLString(diameterXml);
509 my_app.updateOperatedOriginHostWithMessage(codecMsg);
510 message = my_app.getOperatedHost()->getCodecEngine()->createMessage(diameterXml, false /* is xml string */); // loads xml again, lesser of two evils
511 LOGDEBUG(anna::Logger::debug(message->asXMLString(), ANNA_FILE_LOCATION));
513 catch(anna::RuntimeException &ex) {
515 response += "invalid operated host";
519 if(message->isRequest()) {
520 response += "cannot program diameter requests. Answer type must be provided";
524 int code = message->getId().first;
525 LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to client' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION));
526 my_app.getOperatedServer()->getReactingAnswers()->addMessage(code, message);
527 response = "Added 'answer to client' to the FIFO queue corresponding to its message code";
531 if(diameterJson_or_action == "list") { // programmed answers FIFO's to stdout
532 response = anna::functions::encodeBase64(my_app.getOperatedServer()->getReactingAnswers()->asString("ANSWERS TO CLIENT"));
533 } else if (diameterJson_or_action == "rotate") {
534 my_app.getOperatedServer()->getReactingAnswers()->rotate(true);
536 } else if (diameterJson_or_action == "exhaust") {
537 my_app.getOperatedServer()->getReactingAnswers()->rotate(false);
538 response = "exhaust";
539 } else if (diameterJson_or_action == "clear") {
540 my_app.getOperatedServer()->getReactingAnswers()->clear();
542 } else if (diameterJson_or_action == "dump") {
543 my_app.getOperatedServer()->getReactingAnswers()->dump("programmed_answer");
555 bool EventOperation::test_id__description(std::string &response, unsigned int id, const std::string & description) {
557 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
558 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
561 testManager.getTestCase(id)->setDescription(description); // creates / reuses
564 catch(anna::RuntimeException &ex) {
566 response += "invalid ip-limit";
573 bool EventOperation::test_id__ip_limit(std::string &response, unsigned int id, int amount) {
575 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
576 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
579 testManager.getTestCase(id)->addIpLimit(amount); // creates / reuses
582 catch(anna::RuntimeException &ex) {
584 response += "invalid ip-limit";
591 bool EventOperation::test_id__timeout(std::string &response, unsigned int id, int msecs) {
593 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
594 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
597 anna::Millisecond timeout = my_app.checkTimeMeasure("Test case timeout", anna::functions::asString(msecs));
598 testManager.getTestCase(id)->addTimeout(timeout); // creates / reuses
601 catch(anna::RuntimeException &ex) {
603 response += "invalid timeout";
610 bool EventOperation::test_id__sendmsg2e_2c(std::string &response, unsigned int id, bool _2e_or_2c, const std::string & diameterJson, int stepNumber) {
612 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
613 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
616 std::string diameterXml = anna::json::functions::json2xml(diameterJson, success);
618 response += "json to xml failed, unable to load message !";
621 anna::diameter::codec::Message codecMsg; // auxiliary codec message
622 codecMsg.loadXMLString(diameterXml);
625 if (!codecMsg.isRequest() && (stepNumber == -1))
626 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);
630 my_app.updateOperatedOriginHostWithMessage(codecMsg);
632 testManager.getTestCase(id)->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses
634 testManager.getTestCase(id)->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses
638 catch(anna::RuntimeException &ex) {
640 response += "failed";
647 bool EventOperation::test_id__delay(std::string &response, unsigned int id, int msecs) {
649 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
650 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
653 anna::Millisecond delay = ((msecs == 0 /* special case */) ? (anna::Millisecond)0 : my_app.checkTimeMeasure("Test case delay step", anna::functions::asString(msecs)));
654 testManager.getTestCase(id)->addDelay(delay); // creates / reuses
657 catch(anna::RuntimeException &ex) {
659 response += "invalid delay";
666 bool EventOperation::test_id__sh_command(std::string &response, unsigned int id, const std::string & script) {
668 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
669 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
672 testManager.getTestCase(id)->addCommand(script); // creates / reuses
675 catch(anna::RuntimeException &ex) {
677 response += "failed";
684 bool EventOperation::test_id__waitfefc_hex(std::string &response, unsigned int id, bool fe_or_fc, const std::string & hex, bool strict) {
686 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
687 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
689 // Get DataBlock from hex content:
690 anna::DataBlock db_aux(true);
691 std::string hexString = hex;
692 hexString.erase(std::remove(hexString.begin(), hexString.end(), ':'), hexString.end());
694 std::string msg = "Hex string (remove colons if exists): ";
696 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
701 anna::functions::fromHexString(hexString, db_aux); // could launch exception
702 regexp = anna::functions::asHexString(db_aux);
704 catch(anna::RuntimeException &ex) {
706 response += "failed";
712 //// If request, we will ignore sequence data:
713 //if (anna::diameter::codec::functions::requestBit(db_aux))
714 regexp.replace (24, 16, "[0-9A-Fa-f]{16}");
716 regexp.insert(0, "^");
721 testManager.getTestCase(id)->addWaitDiameterRegexpHex(fe_or_fc, regexp);
724 catch(anna::RuntimeException &ex) {
726 response += "failed";
733 bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int id, bool fe_or_fc, const std::string & diameterJson, bool strict) {
735 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
736 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
739 std::string diameterXml = anna::json::functions::json2xml(diameterJson, success);
741 response += "json to xml failed, unable to load message !";
746 anna::diameter::codec::Message codecMsg; // auxiliary codec message
747 codecMsg.loadXMLString(diameterXml);
748 std::string regexp = codecMsg.asXMLString(true /* normalization */);
750 // Now we must insert regular expressions in hop-by-hop, end-to-end and Origin-State-Id:
754 std::string::size_type pos, pos_1, pos_2;
756 pos = regexp.find("end-to-end-id=", 0u);
757 pos = regexp.find("\"", pos);
759 pos = regexp.find("\"", pos+1);
761 regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
763 pos = regexp.find("hop-by-hop-id=", 0u);
764 pos = regexp.find("\"", pos);
766 pos = regexp.find("\"", pos+1);
768 regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
770 // For this representation: <avp name="Origin-State-Id" data="1428633668"/>
771 //pos = regexp.find("Origin-State-Id", 0u);
772 //pos = regexp.find("\"", pos);
773 //pos = regexp.find("\"", pos+1);
775 //pos = regexp.find("\"", pos+1);
777 //regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
778 // But we have this one: <avp data="1428633668" name="Origin-State-Id"/>
779 pos = regexp.find("Origin-State-Id", 0u);
780 pos = regexp.rfind("\"", pos);
781 pos = regexp.rfind("\"", pos-1);
782 pos = regexp.rfind("\"", pos-1);
784 pos = regexp.find("\"", pos+1);
786 regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
788 //regexp.insert(0, "^");
792 testManager.getTestCase(id)->addWaitDiameterRegexpXml(fe_or_fc, regexp);
795 catch(anna::RuntimeException &ex) {
797 response += "failed";
804 bool EventOperation::test_id__waitfefc(std::string &response, unsigned int id, bool fe_or_fc,
805 const std::string & code,
806 const std::string & bitR,
807 const std::string & hopByHop,
808 const std::string & applicationId,
809 const std::string & sessionId,
810 const std::string & resultCode,
811 const std::string & msisdn,
812 const std::string & imsi,
813 const std::string & serviceContextId) {
815 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
816 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
818 try { // [code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId]
819 testManager.getTestCase(id)->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId);
822 catch(anna::RuntimeException &ex) {
824 response += "failed";
831 /////////////////////////
832 // Testcases execution //
833 /////////////////////////
834 bool EventOperation::test__ttps(std::string &response, int amount) {
836 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
837 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
839 bool success = testManager.configureTTPS(amount);
841 response = "Assigned new test launch rate to ";
842 response += anna::functions::asString(amount);
843 response += " events per second";
846 response += "unable to configure the test rate provided";
849 return success; // OK
852 bool EventOperation::test__next(std::string &response, int syncAmount) {
854 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
855 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
857 if (syncAmount < 1) {
858 response += "the parameter 'sync-amount' must be a positive integer value";
862 bool success = testManager.execTestCases(syncAmount);
864 response = (success ? "P" : "Not completely p" /* completed cycle and no repeats, rare case */);
865 response += "rocessed ";
866 response += anna::functions::asString(syncAmount);
867 response += ((syncAmount > 1) ? " test cases synchronously" : " test case");
872 bool EventOperation::test__ip_limit(std::string &response, int amount) {
874 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
875 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
878 testManager.setInProgressLimit(amount);
879 response = "New in-progress limit: ";
880 response += (amount != -1) ? anna::functions::asString(amount) : "[no limit]";
883 response = "In-progress limit amount: ";
884 int limit = testManager.getInProgressLimit();
885 response += (limit != -1) ? anna::functions::asString(limit) : "[no limit]";
886 response += "; currently there are ";
887 response += anna::functions::asString(testManager.getInProgressCount());
888 response += " test cases running";
894 bool EventOperation::test__goto(std::string &response, int id) {
896 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
897 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
899 bool success = testManager.gotoTestCase(id);
902 response = "Position updated for id provided (";
905 response += "cannot found test id (";
907 response += anna::functions::asString(id);
913 bool EventOperation::test__run(std::string &response, int id) {
915 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
916 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
918 bool success = testManager.runTestCase(id);
921 response = "Test executed for id provided (";
924 response += "cannot found test id (";
926 response += anna::functions::asString(id);
932 bool EventOperation::test__look(std::string &response, int id) {
934 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
935 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
937 anna::testing::TestCase *testCase = testManager.findTestCase(id);
940 response += "no current test case detected (testing started ?)";
943 response += "cannot found test id (";
944 response += anna::functions::asString(id);
952 response = anna::functions::encodeBase64(testCase->asXMLString());
954 response = testCase->asXMLString();
959 bool EventOperation::test__state(std::string &response, int id) {
961 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
962 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
964 anna::testing::TestCase *testCase = testManager.findTestCase(id);
967 response += "no current test case detected (testing started ?)";
970 response += "cannot found test id (";
971 response += anna::functions::asString(id);
978 response = anna::testing::TestCase::asText(testCase->getState());
979 return testCase->isSuccess();
982 bool EventOperation::test__interact(std::string &response, int amount, unsigned int id) {
984 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
985 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
988 response += "interactive amount must be -1 (to disable interactive mode) or a positive number.";
992 anna::testing::TestCase *testCase = testManager.findTestCase(id);
995 testCase->makeInteractive(false);
996 response = "Interactive mode disabled";
999 testCase->addInteractiveAmount(amount);
1000 response = "Added interactive amount of ";
1001 response += anna::functions::asString(amount);
1002 response += " units";
1003 if (amount == 0) response += " (0: freezing a non-interactive testcase, no effect on already interactive)";
1005 response += " for test case id ";
1006 response += anna::functions::asString(id);
1009 response += "cannot found test id (";
1010 response += anna::functions::asString(id);
1018 bool EventOperation::test__reset(std::string &response, bool soft_hard, int id) {
1020 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1021 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1023 anna::testing::TestCase *testCase = ((id != -1) ? testManager.findTestCase(id) : NULL);
1025 bool done = testCase->reset(!soft_hard);
1027 response += (soft_hard ? "soft":"hard");
1028 response += " reset for id ";
1029 response += anna::functions::asString(id);
1030 response += done ? ": done": ": not done";
1034 bool anyReset = testManager.resetPool(!soft_hard);
1035 response = (soft_hard ? "Soft":"Hard");
1036 response += " reset have been sent to all programmed tests: "; response += anyReset ? "some/all have been reset" : "nothing was reset";
1039 response += "cannot found test id (";
1040 response += anna::functions::asString(id);
1049 bool EventOperation::test__repeats(std::string &response, int amount) {
1051 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1052 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1054 if (amount < 0) amount = -1;
1055 testManager.setPoolRepeats(amount);
1056 std::string nolimit = (amount != -1) ? "":" [no limit]";
1057 response = anna::functions::asString("Pool repeats: %d%s (current cycle: %d)", amount, nolimit.c_str(), testManager.getPoolCycle());
1062 bool EventOperation::test__auto_reset(std::string &response, bool soft_hard) {
1064 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1065 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1067 testManager.setAutoResetHard(!soft_hard);
1068 response = anna::functions::asString("Auto-reset configured to '%s'", (soft_hard ? "soft":"hard"));
1073 bool EventOperation::test__initialized(std::string &response) {
1075 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1076 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1078 response = anna::functions::asString("%lu", testManager.getInitializedCount());
1083 bool EventOperation::test__finished(std::string &response) {
1085 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1086 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1088 response = anna::functions::asString("%lu", testManager.getFinishedCount());
1093 bool EventOperation::test__clear(std::string &response) {
1095 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1096 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1098 return testManager.clearPool(response);
1101 bool EventOperation::test__junit(std::string &response, const std::string & targetFile) {
1103 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1104 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1107 out.open(targetFile.c_str());
1109 if(out.is_open() == false) {
1110 response += "error opening '";
1111 response += targetFile;
1116 out << testManager.junitAsXMLString() << std::endl;
1119 response = "Junit report written on '";
1120 response += targetFile;
1126 bool EventOperation::test__summary_counts(std::string &response) {
1128 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1129 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1131 response = anna::functions::encodeBase64(testManager.summaryCounts());
1136 bool EventOperation::test__summary_states(std::string &response) {
1138 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1139 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1141 response = anna::functions::encodeBase64(testManager.summaryStates());
1146 bool EventOperation::test__summary(std::string &response) {
1148 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1149 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1151 response = anna::functions::encodeBase64(testManager.asXMLString());
1156 bool EventOperation::test__report(std::string &response, const std::string & state, bool enable) {
1158 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1159 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1161 std::string _state = state;
1163 if(_state == "initialized")
1164 testManager.setDumpInitializedReports(enable);
1165 else if(_state == "in-progress")
1166 testManager.setDumpInProgressReports(enable);
1167 else if(_state == "failed")
1168 testManager.setDumpFailedReports(enable);
1169 else if(_state == "success")
1170 testManager.setDumpSuccessReports(enable);
1171 else if(_state == "all") {
1173 testManager.setDumpAllReports(enable);
1175 else if(_state == "none") {
1178 testManager.setDumpAllReports(enable);
1181 response += "invalid state (allowed: initialized|in-progress|failed|success|[all]|none)";
1185 response = (enable ? "Report enabled " : "Report disabled ");
1186 response += "for tests in '";
1188 response += "' state";
1193 bool EventOperation::test__report_hex(std::string &response, bool enable) {
1195 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1196 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1198 testManager.setDumpHex(enable);
1199 response = (testManager.getDumpHex() ? "Report includes hexadecimal messages" : "Report excludes hexadecimal messages");
1204 bool EventOperation::test__dump_stdout(std::string &response, bool enable) {
1206 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1207 anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
1209 testManager.setDumpStdout(enable);
1210 response = (testManager.getDumpStdout() ? "Test manager dumps progress into stdout" : "Test manager does not dump progress into stdout");
1215 bool EventOperation::test__dynamic(std::string &response, const nlohmann::json &arguments) {
1217 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
1219 Procedure p(&my_app);
1221 p.execute(arguments, response);
1223 catch(anna::RuntimeException &ex) {
1225 response += ex.asString();