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 //
16 #include <anna/core/core.hpp>
17 #include <anna/xml/xml.hpp>
18 #include <anna/diameter/stack/Engine.hpp>
19 #include <anna/time/functions.hpp>
20 #include <anna/time/Date.hpp>
22 #include <anna/diameter/codec/Engine.hpp>
23 #include <anna/diameter/codec/tme/Message.hpp>
26 typedef anna::diameter::codec::tme::Message tmeMessage;
27 typedef anna::diameter::codec::tme::Avp tmeAvp;
30 void _exit(const std::string & msg) {
31 std::cout << std::endl << msg << std::endl;
36 std::string exec_cmd(const char* cmd) {
37 FILE* pipe = popen(cmd, "r");
42 std::string result = "";
45 if(fgets(buffer, 128, pipe) != NULL)
53 int main(int argc, char** argv) {
54 Logger::setLevel(Logger::Debug);
55 Logger::initialize("tme", new TraceWriter("file.trace", 2048000));
56 anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
57 anna::time::functions::setControlPoint(); // start control point (application lifetime)
58 anna::diameter::stack::Engine & stackEngine = anna::diameter::stack::Engine::instantiate();
59 anna::diameter::stack::Dictionary *dictionary;
60 std::string exec = argv[0];
61 std::string param = argv[1] ? argv[1] : "";
64 std::string msg = "Usage: "; msg += exec; msg += " <xml directory>";
65 msg += "\n xml directory: contains the xml files needed, which are:";
67 msg += "\n avps_ietf.xml";
68 msg += "\n avps_etsi.xml";
69 msg += "\n avps_tgpp.xml";
70 msg += "\n avps_tme.xml";
71 msg += "\n commands_dccaOCS-CS_HuaweiNGIN_de-es.xml";
73 msg += "\n For example: "; msg += exec; msg += " ";
74 std::string projectRoot = exec_cmd("git rev-parse --show-toplevel");
76 if(projectRoot != "") {
77 //projectRoot.resize(projectRoot.size()-1);
78 projectRoot.erase(projectRoot.size() - 1);
83 msg += "source/diameter/stack/setups";
88 dictionary = stackEngine.createDictionary(0 /* general unique stack id */);
89 dictionary->allowUpdates();
90 dictionary->load(param + "/avps_ietf.xml");
91 dictionary->load(param + "/avps_etsi.xml");
92 dictionary->load(param + "/avps_tgpp.xml");
93 dictionary->load(param + "/avps_tme.xml");
94 dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml");
96 LOGINFORMATION(Logger::information(stackEngine.asString(), ANNA_FILE_LOCATION));
97 LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION));
98 } catch(anna::RuntimeException &ex) {
100 std::cout << ex.getText() << std::endl;
104 anna::diameter::codec::Engine *codecEngine = new anna::diameter::codec::Engine("TME Engine", dictionary);
105 LOGDEBUG(Logger::debug(codecEngine->asString(), ANNA_FILE_LOCATION));
106 tmeMessage cca(codecEngine);
107 cca.setId("Credit-Control-Answer");
108 tmeAvp *sid = (tmeAvp*)cca.addAvp("Session-Id");
109 tmeAvp *ohst = (tmeAvp*)cca.addAvp("Origin-Host");
110 tmeAvp *orlm = (tmeAvp*)cca.addAvp("Origin-Realm");
111 sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81");
112 ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se");
113 orlm->getDiameterIdentity()->setValue("vepc.ericsson.se");
115 int outRange = inRange + 1;
116 //((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(inRange);
117 ((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(outRange); // WILL BE 0 !!
119 <command name="Credit-Control-Answer" code="272" type="Answer">
120 <avprule id="Session-Id" type="Fixed"/>
121 <avprule id="Result-Code" type="Mandatory"/>
122 <avprule id="CS-Result-Code" type="Optional"/>
123 <avprule id="CS-Dialogue-Handling" type="Optional"/>
124 <avprule id="Origin-Host" type="Mandatory"/>
125 <avprule id="Origin-Realm" type="Mandatory"/>
126 <avprule id="Auth-Application-Id" type="Mandatory"/>
127 <avprule id="CC-Request-Type" type="Mandatory"/>
128 <avprule id="CC-Request-Number" type="Mandatory"/>
129 <avprule id="Granted-Service-Unit" type="Optional"/>
130 <avprule id="Cost-Information" type="Optional"/>
131 <avprule id="Low-Balance-Indication" type="Optional"/>
132 <avprule id="Remaining-Balance" type="Optional"/>
133 <avprule id="Credit-Control-Failure-Handling" type="Optional"/>
134 <avprule id="CC-Correlation-Id" type="Optional"/>
135 <avprule id="Redirect-Host" type="Optional" qual="*"/>
136 <avprule id="Redirect-Host-Usage" type="Optional"/>
137 <avprule id="Redirect-Max-Cache-Time" type="Optional"/>
138 <avprule id="Proxy-Info" type="Optional" qual="*"/>
139 <avprule id="Route-Record" type="Optional" qual="*"/>
140 <avprule id="Failed-AVP" type="Optional" qual="*"/>
141 <avprule id="Service-Information" type="Optional"/>
142 <avprule id="AVP" type="Optional" qual="*"/>
145 LOGDEBUG(Logger::debug(cca.asXMLString(), ANNA_FILE_LOCATION));
146 _exit("Open 'file.trace' in order to see traces");