1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
44 #include <anna/core/core.hpp>
45 #include <anna/xml/xml.hpp>
46 #include <anna/diameter/stack/Engine.hpp>
47 #include <anna/time/functions.hpp>
48 #include <anna/time/Date.hpp>
50 #include <anna/diameter/codec/tme/Engine.hpp>
51 #include <anna/diameter/codec/tme/Message.hpp>
54 typedef anna::diameter::codec::tme::Message tmeMessage;
55 typedef anna::diameter::codec::tme::Avp tmeAvp;
58 void _exit(const std::string & msg) {
59 std::cout << std::endl << msg << std::endl;
64 std::string exec_cmd(const char* cmd) {
65 FILE* pipe = popen(cmd, "r");
68 std::string result = "";
70 if(fgets(buffer, 128, pipe) != NULL)
77 int main(int argc, char** argv) {
78 Logger::setLevel(Logger::Debug);
79 Logger::initialize("tme", new TraceWriter("file.trace", 2048000));
80 anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
81 anna::time::functions::setControlPoint(); // start control point (application lifetime)
82 anna::diameter::stack::Engine & stackEngine = anna::diameter::stack::Engine::instantiate();
83 anna::diameter::stack::Dictionary *dictionary;
84 anna::diameter::codec::tme::Engine *codecEngine = new anna::diameter::codec::tme::Engine();
85 std::string exec = argv[0];
86 std::string param = argv[1] ? argv[1] : "";
89 std::string msg = "Use: "; msg += exec; msg += " <xml directory>";
90 msg += "\n xml directory: contains the xml files needed, which are:";
92 msg += "\n avps_ietf.xml";
93 msg += "\n avps_etsi.xml";
94 msg += "\n avps_tgpp.xml";
95 msg += "\n avps_tme.xml";
96 msg += "\n commands_dccaOCS-CS_HuaweiNGIN_de-es.xml";
98 msg += "\n For example: "; msg += exec; msg += " ";
99 std::string projectRoot = exec_cmd("git rev-parse --show-toplevel");
100 if (projectRoot != "") {
101 //projectRoot.resize(projectRoot.size()-1);
102 projectRoot.erase(projectRoot.size()-1);
107 msg += "source/diameter/stack/setups";
113 dictionary = stackEngine.createDictionary(0 /* general unique stack id */);
114 dictionary->allowUpdates();
115 dictionary->load(param + "/avps_ietf.xml");
116 dictionary->load(param + "/avps_etsi.xml");
117 dictionary->load(param + "/avps_tgpp.xml");
118 dictionary->load(param + "/avps_tme.xml");
119 dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml");
120 codecEngine->setDictionary(dictionary);
123 LOGINFORMATION(Logger::information(stackEngine.asString(), ANNA_FILE_LOCATION));
124 LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION));
125 LOGDEBUG(Logger::debug(codecEngine->asString(), ANNA_FILE_LOCATION));
127 } catch (anna::RuntimeException &ex) {
129 std::cout << ex.getText() << std::endl;
134 cca.setId("Credit-Control-Answer");
136 tmeAvp *sid = (tmeAvp*)cca.addAvp("Session-Id");
137 tmeAvp *ohst = (tmeAvp*)cca.addAvp("Origin-Host");
138 tmeAvp *orlm = (tmeAvp*)cca.addAvp("Origin-Realm");
140 sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81");
141 ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se");
142 orlm->getDiameterIdentity()->setValue("vepc.ericsson.se");
144 int outRange = inRange + 1;
145 //((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(inRange);
146 ((tmeAvp*)cca.addAvp("CS-Result-Code"))->getUnsigned16()->setValue(outRange); // WILL BE 0 !!
149 <command name="Credit-Control-Answer" code="272" type="Answer">
150 <avprule id="Session-Id" type="Fixed"/>
151 <avprule id="Result-Code" type="Mandatory"/>
152 <avprule id="CS-Result-Code" type="Optional"/>
153 <avprule id="CS-Dialogue-Handling" type="Optional"/>
154 <avprule id="Origin-Host" type="Mandatory"/>
155 <avprule id="Origin-Realm" type="Mandatory"/>
156 <avprule id="Auth-Application-Id" type="Mandatory"/>
157 <avprule id="CC-Request-Type" type="Mandatory"/>
158 <avprule id="CC-Request-Number" type="Mandatory"/>
159 <avprule id="Granted-Service-Unit" type="Optional"/>
160 <avprule id="Cost-Information" type="Optional"/>
161 <avprule id="Low-Balance-Indication" type="Optional"/>
162 <avprule id="Remaining-Balance" type="Optional"/>
163 <avprule id="Credit-Control-Failure-Handling" type="Optional"/>
164 <avprule id="CC-Correlation-Id" type="Optional"/>
165 <avprule id="Redirect-Host" type="Optional" qual="*"/>
166 <avprule id="Redirect-Host-Usage" type="Optional"/>
167 <avprule id="Redirect-Max-Cache-Time" type="Optional"/>
168 <avprule id="Proxy-Info" type="Optional" qual="*"/>
169 <avprule id="Route-Record" type="Optional" qual="*"/>
170 <avprule id="Failed-AVP" type="Optional" qual="*"/>
171 <avprule id="Service-Information" type="Optional"/>
172 <avprule id="AVP" type="Optional" qual="*"/>
175 LOGDEBUG(Logger::debug(cca.asXMLString(), ANNA_FILE_LOCATION));
177 _exit("Open 'file.trace' in order to see traces");