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/tme/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 anna::diameter::codec::tme::Engine *codecEngine = new anna::diameter::codec::tme::Engine();
61 std::string exec = argv[0];
62 std::string param = argv[1] ? argv[1] : "";
65 std::string msg = "Usage: "; msg += exec; msg += " <xml directory>";
66 msg += "\n xml directory: contains the xml files needed, which are:";
68 msg += "\n avps_ietf.xml";
69 msg += "\n avps_etsi.xml";
70 msg += "\n avps_tgpp.xml";
71 msg += "\n avps_tme.xml";
72 msg += "\n commands_dccaOCS-CS_HuaweiNGIN_de-es.xml";
74 msg += "\n For example: "; msg += exec; msg += " ";
75 std::string projectRoot = exec_cmd("git rev-parse --show-toplevel");
77 if(projectRoot != "") {
78 //projectRoot.resize(projectRoot.size()-1);
79 projectRoot.erase(projectRoot.size() - 1);
84 msg += "source/diameter/stack/setups";
89 dictionary = stackEngine.createDictionary(0 /* general unique stack id */);
90 dictionary->allowUpdates();
91 dictionary->load(param + "/avps_ietf.xml");
92 dictionary->load(param + "/avps_etsi.xml");
93 dictionary->load(param + "/avps_tgpp.xml");
94 dictionary->load(param + "/avps_tme.xml");
95 dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml");
96 codecEngine->setDictionary(dictionary);
98 LOGINFORMATION(Logger::information(stackEngine.asString(), ANNA_FILE_LOCATION));
99 LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION));
100 LOGDEBUG(Logger::debug(codecEngine->asString(), ANNA_FILE_LOCATION));
101 } catch(anna::RuntimeException &ex) {
103 std::cout << ex.getText() << std::endl;
108 cca.setId("Credit-Control-Answer");
109 tmeAvp *sid = (tmeAvp*)cca.addAvp("Session-Id");
110 tmeAvp *ohst = (tmeAvp*)cca.addAvp("Origin-Host");
111 tmeAvp *orlm = (tmeAvp*)cca.addAvp("Origin-Realm");
112 sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81");
113 ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se");
114 orlm->getDiameterIdentity()->setValue("vepc.ericsson.se");
116 int outRange = inRange + 1;
117 //((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(inRange);
118 ((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(outRange); // WILL BE 0 !!
120 <command name="Credit-Control-Answer" code="272" type="Answer">
121 <avprule id="Session-Id" type="Fixed"/>
122 <avprule id="Result-Code" type="Mandatory"/>
123 <avprule id="CS-Result-Code" type="Optional"/>
124 <avprule id="CS-Dialogue-Handling" type="Optional"/>
125 <avprule id="Origin-Host" type="Mandatory"/>
126 <avprule id="Origin-Realm" type="Mandatory"/>
127 <avprule id="Auth-Application-Id" type="Mandatory"/>
128 <avprule id="CC-Request-Type" type="Mandatory"/>
129 <avprule id="CC-Request-Number" type="Mandatory"/>
130 <avprule id="Granted-Service-Unit" type="Optional"/>
131 <avprule id="Cost-Information" type="Optional"/>
132 <avprule id="Low-Balance-Indication" type="Optional"/>
133 <avprule id="Remaining-Balance" type="Optional"/>
134 <avprule id="Credit-Control-Failure-Handling" type="Optional"/>
135 <avprule id="CC-Correlation-Id" type="Optional"/>
136 <avprule id="Redirect-Host" type="Optional" qual="*"/>
137 <avprule id="Redirect-Host-Usage" type="Optional"/>
138 <avprule id="Redirect-Max-Cache-Time" type="Optional"/>
139 <avprule id="Proxy-Info" type="Optional" qual="*"/>
140 <avprule id="Route-Record" type="Optional" qual="*"/>
141 <avprule id="Failed-AVP" type="Optional" qual="*"/>
142 <avprule id="Service-Information" type="Optional"/>
143 <avprule id="AVP" type="Optional" qual="*"/>
146 LOGDEBUG(Logger::debug(cca.asXMLString(), ANNA_FILE_LOCATION));
147 _exit("Open 'file.trace' in order to see traces");