X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=dynamic%2Flauncher%2Fgx%2F00001%2FProcedure.cpp;h=03e02eb57b3fafeee4237d1eae4d946160c2268a;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=63b4ef1e27c1b6fac8f16075eb44cedf533263d9;hpb=d723d5bf571eb48c641b092058eaa38bb6c4fcc8;p=anna.git diff --git a/dynamic/launcher/gx/00001/Procedure.cpp b/dynamic/launcher/gx/00001/Procedure.cpp index 63b4ef1..03e02eb 100644 --- a/dynamic/launcher/gx/00001/Procedure.cpp +++ b/dynamic/launcher/gx/00001/Procedure.cpp @@ -18,6 +18,7 @@ #include #include #include +#include // Local #include "Procedure.hpp" @@ -27,7 +28,18 @@ namespace { void usage (std::string &response) { response += "\n\nInvalid arguments. Provide these ones:"; response += "\n"; - response += "\n|||[|CCR-T xml file]"; + response += "\nSIGUSR2 Interface:"; + response += "\n||||[|CCR-T xml file]"; + response += "\n"; + response += "\nREST Interface:"; + response += "\n{"; + response += "\n \"seqI\":\"\""; + response += "\n ,\"seqF\":\"\""; + response += "\n ,\"msecsTimeout\":\"\""; + response += "\n ,\"digits\":\"\""; + response += "\n ,\"ccrI\":\"\""; + response += "\n [,\"ccrT\":\"\"]"; + response += "\n}"; response += "\n"; response += "\nSequences are parsed when needed, over AVPs or internal values:"; response += "\n"; @@ -42,12 +54,12 @@ namespace { response += "\nThe same will be done in MSISDN and IMSI (Subscription-Data AVPs)."; response += "\nFramed-IP-Address will be sequenced with a direct correspondence to hex value."; response += "\n"; - response += "\nThen, you could provide these arguments: \"5000|2000000|9000000|7|CCR-I.xml|CCR-T.xml\""; + response += "\nThen, you could provide these arguments: \"2000000|9000000|5000|7|CCR-I.xml|CCR-T.xml\""; response += "\n"; } } -void Procedure::execute(const std::string &args, std::string &response, anna::diameter::comm::OriginHost *originHost) throw(anna::RuntimeException) { +void Procedure::execute(const std::string &args, std::string &response) noexcept(false) { response = "Dynamic procedure failed to process '"; response += args; response += "': "; @@ -92,58 +104,55 @@ void Procedure::execute(const std::string &args, std::string &response, anna::di // Load xml messages: anna::diameter::codec::Message ccri, ccrt; anna::diameter::codec::Avp *ccri_sessionId, *ccrt_sessionId, *ccri_framedIPAddress, *ccrt_framedIPAddress, *ccri_msisdn, *ccri_imsi; - anna::diameter::codec::Avp *si1, *si2, *sidata1, *sidata2, *sitype1, *sitype2; - - try { + anna::diameter::codec::Avp *si1, *si2, *sidata1, *sidata2, *sitype1; + anna::diameter::codec::Avp *ccri_originHost; - ///////// CCR-Initial: - ccri.loadXML(ccr_i); + ///////// CCR-Initial: + ccri.loadXMLFile(ccr_i); - // Session-Id & Framed-Ip-Address AVPs - ccri_sessionId = ccri.getAvp("Session-Id"); - ccri_framedIPAddress = ccri.getAvp("Framed-IP-Address"); + // Session-Id & Framed-Ip-Address AVPs + ccri_sessionId = ccri.getAvp("Session-Id"); + ccri_framedIPAddress = ccri.getAvp("Framed-IP-Address"); + ccri_originHost = ccri.getAvp("Origin-Host"); - // Subscription-Id AVPs - if (ccri.countAvp("Subscription-Id") != 2) { - response += "Both Subscription-Id MSISDN & IMSI Avps must be present in the CCR-Initial provided !"; - return; - } + // Subscription-Id AVPs + if (ccri.countAvp("Subscription-Id") != 2) { + response += "Both Subscription-Id MSISDN & IMSI Avps must be present in the CCR-Initial provided !"; + return; + } - si1 = ccri.getAvp("Subscription-Id", 1, anna::Exception::Mode::Ignore); - si2 = ccri.getAvp("Subscription-Id", 2, anna::Exception::Mode::Ignore); + si1 = ccri.getAvp("Subscription-Id", 1, anna::Exception::Mode::Ignore); + si2 = ccri.getAvp("Subscription-Id", 2, anna::Exception::Mode::Ignore); - if (!si1 || !si2) { - response += "Cannot found Subscription-Id MSISDN & IMSI Avps !" ; - return; - } + if (!si1 || !si2) { + response += "Cannot found Subscription-Id MSISDN & IMSI Avps !" ; + return; + } - sidata1 = si1->getAvp("Subscription-Id-Data"); - sidata2 = si2->getAvp("Subscription-Id-Data"); - sitype1 = si1->getAvp("Subscription-Id-Type"); - //sitype2 = si2->getAvp("Subscription-Id-Type"); + sidata1 = si1->getAvp("Subscription-Id-Data"); + sidata2 = si2->getAvp("Subscription-Id-Data"); + sitype1 = si1->getAvp("Subscription-Id-Type"); + //sitype2 = si2->getAvp("Subscription-Id-Type"); - if (sitype1->getEnumerated()->getValue() == anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164) { - ccri_msisdn = sidata1; - ccri_imsi = sidata2; - } - else { - ccri_msisdn = sidata2; - ccri_imsi = sidata1; - } + if (sitype1->getEnumerated()->getValue() == anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164) { + ccri_msisdn = sidata1; + ccri_imsi = sidata2; + } + else { + ccri_msisdn = sidata2; + ccri_imsi = sidata1; + } - ///////// CCR-Termination: - if (haveTermination) { - ccrt.loadXML(ccr_t); + ///////// CCR-Termination: + if (haveTermination) { + ccrt.loadXMLFile(ccr_t); - // Session-Id & Framed-Ip-Address AVPs - ccrt_sessionId = ccrt.getAvp("Session-Id"); - ccrt_framedIPAddress = ccrt.getAvp("Framed-IP-Address"); - } - } - catch(anna::RuntimeException &ex) { - ex.trace(); + // Session-Id & Framed-Ip-Address AVPs + ccrt_sessionId = ccrt.getAvp("Session-Id"); + ccrt_framedIPAddress = ccrt.getAvp("Framed-IP-Address"); } + // Prepare session-id string: std::string sessionId = ccri_sessionId->getUTF8String()->getValue(); std::size_t last_semicolon = sessionId.rfind(";"); @@ -211,6 +220,12 @@ void Procedure::execute(const std::string &args, std::string &response, anna::di char cad_framed[16]; anna::testing::TestCase *tc; + // Origin host manager: + anna::diameter::comm::OriginHostManager &ohm = anna::diameter::comm::OriginHostManager::instantiate(); + // Assume the oh name from CCR-I (same as CCR-T): + std::string originHostName = ccri_originHost->getDiameterIdentity()->getValue(); + anna::diameter::comm::OriginHost *originHost = ohm.getOriginHost(originHostName); + for (ll_index = 0; ll_index < ll_seq_size; ll_index++) { // Calculate next values //////////////////////////////////////////////////////////// @@ -258,24 +273,46 @@ void Procedure::execute(const std::string &args, std::string &response, anna::di } // Step 2: sendxml2e: CCR-Initial - tc->addSendxml2e(ccri.code(), originHost, -1 /* 'wait for request' step number for answers */); + tc->addSendDiameterXml2e(ccri.code(), originHost, -1 /* 'wait for request' step number for answers */); // Step 3: waitfe: CCA with same session id // PARAM: 1 2 3 4 5 6 7 8 9 10 11 // wait|[code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId] - tc->addWait(true /* from entity */, "272", "0", "", "", sessionId, "2001", "", "", ""); + tc->addWaitDiameter(true /* from entity */, "272", "0", "", "", sessionId, "2001", "", "", ""); if (haveTermination) { // Step 4: sendxml2e: CCR-Termination - tc->addSendxml2e(ccrt.code(), originHost, -1 /* 'wait for request' step number for answers */); + tc->addSendDiameterXml2e(ccrt.code(), originHost, -1 /* 'wait for request' step number for answers */); // Step 5: waitfe: CCA with same session id - tc->addWait(true /* from entity */, "272", "0", "", "", sessionId, "2001", "", "", ""); + tc->addWaitDiameter(true /* from entity */, "272", "0", "", "", sessionId, "2001", "", "", ""); } } // loop - response = "Completed provision for pid "; response += anna::functions::asString(a_app->getPid()); response += "; range ["; + response = "Completed provision: range ["; response += seq_i; response += ", "; response += seq_f; response += "]; scenary: "; response += "CCR-Initial"; if (haveTermination) response += " + CCR-Termination"; } +void Procedure::execute(const nlohmann::json &args, std::string &response) noexcept(false) { + + // Build the arguments string and call the previous centralized logic procedure execution: + // ||||[|CCR-T xml file] + const char *arg_names[6] = { "seqI", "seqF", "msecsTimeout", "digits", "ccrI", "ccrT" }; + std::string args_string, arg, pipe("|"); + + for (int i = 0; i < 6; i++) + { + auto it = args.find(arg_names[i]); + arg = (it != args.end() && it->is_string()) ? *it : ""; + if (arg != "") args_string += arg + pipe; + } + + // Remove last 'pipe': + if (args_string != "") + args_string = args_string.substr(0, args_string.size()-1); + + execute(args_string, response); +} + +