From e3f60b6b4a178c63ebd6f8915431bfa485a2e601 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Tue, 8 Sep 2015 02:19:21 +0200 Subject: [PATCH] Fixes and improvs. Basic DRA feature. --- example/diameter/launcher/Launcher.cpp | 11 ++++++ .../launcher/testing/TestCondition.cpp | 2 +- .../diameter/launcher/testing/TestManager.cpp | 2 + .../diameter/launcher/testing/TestManager.hpp | 3 ++ .../diameter/launcher/testing/TestStep.cpp | 39 +++++++++++++------ .../diameter/launcher/testing/TestStep.hpp | 2 +- source/diameter/codec/functions.cpp | 6 +-- 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index a6c5bee..041e7a9 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -1227,6 +1227,8 @@ std::string Launcher::help() const throw() { result += "\n and test case reports will be written depending on this report option. Anyway, you could"; result += "\n use the 'look' operation to see the report."; 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|reset|[|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."; @@ -1610,6 +1612,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons // test|ip-limit[|amount] In-progress limit of test cases. No new test cases will be launched over this value ... // test|repeat[|[yes]|no] Restarts the programmed test cases when finished. Disabled by default: the testing ... // 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|reset|[|id] Reset the test case for id provided, all the tests when missing ... @@ -1665,6 +1668,14 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons testManager.setDumpReports((param2 == "yes")); opt_response_content += (testManager.getDumpReports() ? "report enabled" : "report disabled"); } + else if(param1 == "report-hex") { + 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 == "") param2 = "yes"; + testManager.setDumpHex((param2 == "yes")); + opt_response_content += (testManager.getDumpHex() ? "report includes hexadecimal messages" : "report excludes hexadecimal messages"); + } else if(param1 == "goto") { if (numParams > 2) throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION); diff --git a/example/diameter/launcher/testing/TestCondition.cpp b/example/diameter/launcher/testing/TestCondition.cpp index a772ab0..7f535d5 100644 --- a/example/diameter/launcher/testing/TestCondition.cpp +++ b/example/diameter/launcher/testing/TestCondition.cpp @@ -90,7 +90,7 @@ bool TestCondition::comply(const anna::DataBlock &message/*, bool matchSessionId } if (a_bitR != "") { - compare = (cid.first ? "1":"0"); + compare = (cid.second ? "1":"0"); if (a_bitR != compare) return false; } diff --git a/example/diameter/launcher/testing/TestManager.cpp b/example/diameter/launcher/testing/TestManager.cpp index 97a0d4f..da90107 100644 --- a/example/diameter/launcher/testing/TestManager.cpp +++ b/example/diameter/launcher/testing/TestManager.cpp @@ -34,6 +34,7 @@ TestManager::TestManager() : a_timeController = NULL; a_reportsDirectory = "./"; a_dumpReports = false; + a_dumpHexMessages = false; a_synchronousAmount = 1; a_poolRepeat = false; a_inProgressCount = 0; @@ -384,6 +385,7 @@ throw() { else result->createAttribute("InProgressLimit", a_inProgressLimit); result->createAttribute("DumpReports", (a_dumpReports ? "yes":"no")); + result->createAttribute("DumpHexMessages", (a_dumpHexMessages ? "yes":"no")); result->createAttribute("ReportsDirectory", a_reportsDirectory); if (a_clock) { result->createAttribute("AsynchronousSendings", a_synchronousAmount); diff --git a/example/diameter/launcher/testing/TestManager.hpp b/example/diameter/launcher/testing/TestManager.hpp index 614cb1e..1756315 100644 --- a/example/diameter/launcher/testing/TestManager.hpp +++ b/example/diameter/launcher/testing/TestManager.hpp @@ -56,6 +56,7 @@ class TestManager : public anna::timex::TimeEventObserver, public anna::Singleto // reports std::string a_reportsDirectory; bool a_dumpReports; + bool a_dumpHexMessages; // Pool of test cases test_pool_t a_testPool; @@ -95,6 +96,8 @@ class TestManager : public anna::timex::TimeEventObserver, public anna::Singleto void setReportsDirectory(const std::string &rd) throw() { a_reportsDirectory = rd; } const std::string &getReportsDirectory() const throw() { return a_reportsDirectory; } + void setDumpHex(bool dh) throw() { a_dumpHexMessages = dh; } + bool getDumpHex() const throw() { return a_dumpHexMessages; } void setDumpReports(bool dr) throw() { a_dumpReports = dr; } bool getDumpReports() const throw() { return a_dumpReports; } diff --git a/example/diameter/launcher/testing/TestStep.cpp b/example/diameter/launcher/testing/TestStep.cpp index c4ec2e5..e53ae9a 100644 --- a/example/diameter/launcher/testing/TestStep.cpp +++ b/example/diameter/launcher/testing/TestStep.cpp @@ -161,15 +161,19 @@ anna::xml::Node* TestStepSendxml::asXML(anna::xml::Node* parent) const throw() { anna::xml::Node* result = TestStep::asXML(parent); //parent->createChild("TestStepSendxml"); + std::string msg = "", xmlmsg = ""; // Message - std::string msg = "", xmlmsg = ""; - if (a_message.isEmpty()) { - msg = ""; + if (TestManager::instantiate().getDumpHex()) { + if (a_message.isEmpty()) { + msg = ""; + } + else { + msg = "\n"; msg += a_message.asString(); msg += "\n"; + } } - else { - msg = "\n"; msg += a_message.asString(); msg += "\n"; - // Helper + + if (!a_message.isEmpty()) { try { Launcher& my_app = static_cast (anna::app::functions::getApp()); static anna::diameter::codec::Message codecMsg(my_app.getCodecEngine()); @@ -181,9 +185,11 @@ throw() { } } - result->createAttribute("Message", msg); + if (msg != "") result->createAttribute("Message", msg); if (xmlmsg != "") result->createAttribute("XMLMessage", xmlmsg); result->createAttribute("Expired", (a_expired ? "yes":"no")); + if (a_waitForRequestStepNumber != -1) + result->createAttribute("WaitForRequestStepNumber", a_waitForRequestStepNumber); return result; } @@ -334,25 +340,36 @@ anna::xml::Node* TestStepWait::asXML(anna::xml::Node* parent) const throw() { anna::xml::Node* result = TestStep::asXML(parent); //parent->createChild("TestStepWait"); + std::string msg = "", xmlmsg = ""; // Condition a_condition.asXML(result); + // Message + if (TestManager::instantiate().getDumpHex()) { + if (a_message.isEmpty()) { + msg = ""; + } + else { + msg = "\n"; msg += a_message.asString(); msg += "\n"; + } + } + if (!a_message.isEmpty()) { - // Message - result->createAttribute("MatchedMessage", a_message.asString()); - // Helper try { Launcher& my_app = static_cast (anna::app::functions::getApp()); static anna::diameter::codec::Message codecMsg(my_app.getCodecEngine()); codecMsg.decode(a_message); - result->createAttribute("MatchedXMLMessage", codecMsg.asXMLString()); + xmlmsg = "\n"; xmlmsg += codecMsg.asXMLString(); xmlmsg += "\n"; } catch (anna::RuntimeException &ex) { ex.trace(); } } + if (msg != "") result->createAttribute("MatchedMessage", msg); + if (xmlmsg != "") result->createAttribute("XMLMessage", xmlmsg); + return result; } diff --git a/example/diameter/launcher/testing/TestStep.hpp b/example/diameter/launcher/testing/TestStep.hpp index 3473c54..b63c147 100644 --- a/example/diameter/launcher/testing/TestStep.hpp +++ b/example/diameter/launcher/testing/TestStep.hpp @@ -175,7 +175,7 @@ class TestStepWait : public TestStep { anna::diameter::comm::ServerSession *a_serverSession; public: - TestStepWait(TestCase *testCase) : TestStep(testCase) { a_type = Type::Wait; a_clientSession = NULL; a_serverSession = NULL; } + TestStepWait(TestCase *testCase) : TestStep(testCase), a_message(true) { a_type = Type::Wait; a_clientSession = NULL; a_serverSession = NULL; } ~TestStepWait() {;} // setter & getters diff --git a/source/diameter/codec/functions.cpp b/source/diameter/codec/functions.cpp index 767d960..8c5d350 100644 --- a/source/diameter/codec/functions.cpp +++ b/source/diameter/codec/functions.cpp @@ -285,7 +285,7 @@ void functions::setHopByHop(anna::DataBlock & db, diameter::HopByHop hbh) throw( throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION); } - static char source[4]; + char source[4]; source[0] = (char)(hbh >> 24); source[1] = (char)(hbh >> 16); source[2] = (char)(hbh >> 8); @@ -299,7 +299,7 @@ void functions::setEndToEnd(anna::DataBlock & db, diameter::EndToEnd ete) throw( throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION); } - static char source[4]; + char source[4]; source[0] = (char)(ete >> 24); source[1] = (char)(ete >> 16); source[2] = (char)(ete >> 8); @@ -312,7 +312,7 @@ void functions::setPotentiallyReTransmittedMessageBit(const anna::DataBlock & db throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION); } - static char flags[1]; + char flags[1]; flags[0] = *(db.getData() + 4); if(activate) flags[0] |= Message::TBitMask; else flags[0] &= (~Message::TBitMask); memcpy((char *)(db.getData() + 4), flags, 1); -- 2.20.1