Remove core-comm dependency through CounterManager/timex in core/oam subsystem. Basic...
[anna.git] / example / diameter / tme / main.cpp
1 // Standard
2 #include <iostream>
3 #include <fstream>
4
5 // STL
6 #include <string>
7
8 #include <anna/core/core.hpp>
9 #include <anna/xml/xml.hpp>
10 #include <anna/diameter/stack/Engine.hpp>
11 #include <anna/diameter/codec/Engine.hpp>
12 #include <anna/time/functions.hpp>
13 #include <anna/time/Date.hpp>
14
15
16 void _exit(const std::string & msg) {
17    std::cout << std::endl << msg << std::endl;
18    exit(-1);
19 }
20
21
22 std::string exec_cmd(const char* cmd) {
23   FILE* pipe = popen(cmd, "r");
24   if (!pipe) return "";
25   char buffer[128];
26   std::string result = "";
27   while(!feof(pipe)) {
28     if(fgets(buffer, 128, pipe) != NULL)
29       result += buffer;
30   }
31   pclose(pipe);
32   return result;
33 }
34
35 int main(int argc, char** argv) {
36   Logger::setLevel(Logger::Debug);
37   Logger::initialize("tme", new TraceWriter("file.trace", 2048000));
38   anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
39   anna::time::functions::setControlPoint(); // start control point (application lifetime)
40   anna::diameter::stack::Engine & engine = anna::diameter::stack::Engine::instantiate();
41   anna::diameter::stack::Dictionary *dictionary;
42   std::string exec = argv[0];
43   std::string param = argv[1] ? argv[1] : "";
44
45   if (param == "") {
46     std::string msg = "Use: "; msg += exec; msg += " <xml directory>";
47     msg += "\n     xml directory: contains the xml files needed, which are:";
48     msg += "\n";
49     msg += "\n                       avps_ietf.xml";
50     msg += "\n                       avps_etsi.xml";
51     msg += "\n                       avps_tgpp.xml";
52     msg += "\n                       avps_tme.xml";
53     msg += "\n                       commands_dccaOCS-CS_HuaweiNGIN_de-es.xml";
54     msg += "\n";
55     msg += "\n     For example:   "; msg += exec; msg += " ";
56     std::string projectRoot = exec_cmd("git rev-parse --show-toplevel");
57     if (projectRoot != "") {
58       //projectRoot.resize(projectRoot.size()-1);
59       projectRoot.erase(projectRoot.size()-1);
60       msg += projectRoot;
61       msg += "/";
62     }
63
64     msg += "source/diameter/stack/setups";
65
66     _exit(msg);
67   }
68
69   try {
70     dictionary = engine.createDictionary(0 /* general unique stack id */);
71     dictionary->allowUpdates();
72     dictionary->load(param + "/avps_ietf.xml");
73     dictionary->load(param + "/avps_etsi.xml");
74     dictionary->load(param + "/avps_tgpp.xml");
75     dictionary->load(param + "/avps_tme.xml");
76     dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml");
77
78     // Trace:
79     LOGINFORMATION(Logger::information(engine.asString(), ANNA_FILE_LOCATION));
80     LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION));
81
82   } catch (anna::RuntimeException &ex) {
83     ex.trace();
84     std::cout << ex.getText() << std::endl;
85   }
86
87
88   anna::diameter::codec::Message ccr;
89   ccr.setId("Credit-Control-Request");
90
91   //LOGDEBUG(Logger::debug(ccr.asXMLString(), ANNA_FILE_LOCATION));
92 /*
93
94   tmeAvp *sid = (tmeAvp*)ccr.addAvp("Session-Id");
95   tmeAvp *ohst = (tmeAvp*)ccr.addAvp("Origin-Host");
96   tmeAvp *orlm = (tmeAvp*)ccr.addAvp("Origin-Realm");
97
98   sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81");  
99   ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se");
100   orlm->getDiameterIdentity()->setValue("vepc.ericsson.se");
101 */ 
102 /*
103    <command name="Credit-Control-Request" code="272" type="Request">
104       <avprule id="Session-Id" type="Fixed"/>
105       <avprule id="Origin-Host" type="Mandatory"/>
106       <avprule id="Origin-Realm" type="Mandatory"/>
107       <avprule id="Destination-Realm" type="Mandatory"/>
108       <avprule id="Auth-Application-Id" type="Mandatory"/>
109       <avprule id="Service-Context-Id" type="Mandatory"/>
110       <avprule id="CC-Request-Type" type="Mandatory"/>
111       <avprule id="CC-Request-Number" type="Mandatory"/>
112       <avprule id="Event-Timestamp" type="Optional"/>
113       <avprule id="Subscription-Id" type="Mandatory" qual="*"/>
114       <avprule id="Termination-Cause" type="Optional"/>
115       <avprule id="Requested-Service-Unit" type="Optional"/>
116       <avprule id="Requested-Action" type="Optional"/>
117       <avprule id="Used-Service-Unit" type="Optional"/>
118       <avprule id="CC-Correlation-Id" type="Optional"/>
119       <avprule id="User-Equipment-Info" type="Optional"/>
120       <avprule id="Proxy-Info" type="Optional" qual="*"/>
121       <avprule id="Route-Record" type="Optional" qual="*"/>
122       <avprule id="Service-Information" type="Optional"/>
123       <avprule id="AVP" type="Optional" qual="*"/>
124    </command>
125
126    <command name="Credit-Control-Answer" code="272" type="Answer">
127       <avprule id="Session-Id" type="Fixed"/>
128       <avprule id="Result-Code" type="Mandatory"/>
129       <avprule id="CS-Result-Code" type="Optional"/>
130       <avprule id="CS-Dialogue-Handling" type="Optional"/>
131       <avprule id="Origin-Host" type="Mandatory"/>
132       <avprule id="Origin-Realm" type="Mandatory"/>
133       <avprule id="Auth-Application-Id" type="Mandatory"/>
134       <avprule id="CC-Request-Type" type="Mandatory"/>
135       <avprule id="CC-Request-Number" type="Mandatory"/>
136       <avprule id="Granted-Service-Unit" type="Optional"/>
137       <avprule id="Cost-Information" type="Optional"/>
138       <avprule id="Low-Balance-Indication" type="Optional"/>
139       <avprule id="Remaining-Balance" type="Optional"/>
140       <avprule id="Credit-Control-Failure-Handling" type="Optional"/>
141       <avprule id="CC-Correlation-Id" type="Optional"/>
142       <avprule id="Redirect-Host" type="Optional" qual="*"/>
143       <avprule id="Redirect-Host-Usage" type="Optional"/>
144       <avprule id="Redirect-Max-Cache-Time" type="Optional"/>
145       <avprule id="Proxy-Info" type="Optional" qual="*"/>
146       <avprule id="Route-Record" type="Optional" qual="*"/>
147       <avprule id="Failed-AVP" type="Optional" qual="*"/>
148       <avprule id="Service-Information" type="Optional"/>
149       <avprule id="AVP" type="Optional" qual="*"/>
150    </command>
151 */
152
153    _exit("Open 'file.trace' in order to see the stacks loaded");
154 }
155