Remove core-comm dependency through CounterManager/timex in core/oam subsystem. Basic...
[anna.git] / example / diameter / tme / main.cpp
diff --git a/example/diameter/tme/main.cpp b/example/diameter/tme/main.cpp
new file mode 100644 (file)
index 0000000..567cf8a
--- /dev/null
@@ -0,0 +1,155 @@
+// Standard
+#include <iostream>
+#include <fstream>
+
+// STL
+#include <string>
+
+#include <anna/core/core.hpp>
+#include <anna/xml/xml.hpp>
+#include <anna/diameter/stack/Engine.hpp>
+#include <anna/diameter/codec/Engine.hpp>
+#include <anna/time/functions.hpp>
+#include <anna/time/Date.hpp>
+
+
+void _exit(const std::string & msg) {
+   std::cout << std::endl << msg << std::endl;
+   exit(-1);
+}
+
+
+std::string exec_cmd(const char* cmd) {
+  FILE* pipe = popen(cmd, "r");
+  if (!pipe) return "";
+  char buffer[128];
+  std::string result = "";
+  while(!feof(pipe)) {
+    if(fgets(buffer, 128, pipe) != NULL)
+      result += buffer;
+  }
+  pclose(pipe);
+  return result;
+}
+
+int main(int argc, char** argv) {
+  Logger::setLevel(Logger::Debug);
+  Logger::initialize("tme", new TraceWriter("file.trace", 2048000));
+  anna::time::functions::initialize(); // before application instantiation (it have a anna::time object)
+  anna::time::functions::setControlPoint(); // start control point (application lifetime)
+  anna::diameter::stack::Engine & engine = anna::diameter::stack::Engine::instantiate();
+  anna::diameter::stack::Dictionary *dictionary;
+  std::string exec = argv[0];
+  std::string param = argv[1] ? argv[1] : "";
+
+  if (param == "") {
+    std::string msg = "Use: "; msg += exec; msg += " <xml directory>";
+    msg += "\n     xml directory: contains the xml files needed, which are:";
+    msg += "\n";
+    msg += "\n                       avps_ietf.xml";
+    msg += "\n                       avps_etsi.xml";
+    msg += "\n                       avps_tgpp.xml";
+    msg += "\n                       avps_tme.xml";
+    msg += "\n                       commands_dccaOCS-CS_HuaweiNGIN_de-es.xml";
+    msg += "\n";
+    msg += "\n     For example:   "; msg += exec; msg += " ";
+    std::string projectRoot = exec_cmd("git rev-parse --show-toplevel");
+    if (projectRoot != "") {
+      //projectRoot.resize(projectRoot.size()-1);
+      projectRoot.erase(projectRoot.size()-1);
+      msg += projectRoot;
+      msg += "/";
+    }
+
+    msg += "source/diameter/stack/setups";
+
+    _exit(msg);
+  }
+
+  try {
+    dictionary = engine.createDictionary(0 /* general unique stack id */);
+    dictionary->allowUpdates();
+    dictionary->load(param + "/avps_ietf.xml");
+    dictionary->load(param + "/avps_etsi.xml");
+    dictionary->load(param + "/avps_tgpp.xml");
+    dictionary->load(param + "/avps_tme.xml");
+    dictionary->load(param + "/commands_dccaOCS-CS_HuaweiNGIN_de-es.xml");
+
+    // Trace:
+    LOGINFORMATION(Logger::information(engine.asString(), ANNA_FILE_LOCATION));
+    LOGDEBUG(Logger::debug(dictionary->asString(), ANNA_FILE_LOCATION));
+
+  } catch (anna::RuntimeException &ex) {
+    ex.trace();
+    std::cout << ex.getText() << std::endl;
+  }
+
+
+  anna::diameter::codec::Message ccr;
+  ccr.setId("Credit-Control-Request");
+
+  //LOGDEBUG(Logger::debug(ccr.asXMLString(), ANNA_FILE_LOCATION));
+/*
+
+  tmeAvp *sid = (tmeAvp*)ccr.addAvp("Session-Id");
+  tmeAvp *ohst = (tmeAvp*)ccr.addAvp("Origin-Host");
+  tmeAvp *orlm = (tmeAvp*)ccr.addAvp("Origin-Realm");
+
+  sid->getUTF8String()->setValue("grump.example.com:33041;23432;893;0AF3B81");  
+  ohst->getDiameterIdentity()->setValue("c0-10-70-238-74-w5p1vepg1.vepc.ericsson.se");
+  orlm->getDiameterIdentity()->setValue("vepc.ericsson.se");
+*/ 
+/*
+   <command name="Credit-Control-Request" code="272" type="Request">
+      <avprule id="Session-Id" type="Fixed"/>
+      <avprule id="Origin-Host" type="Mandatory"/>
+      <avprule id="Origin-Realm" type="Mandatory"/>
+      <avprule id="Destination-Realm" type="Mandatory"/>
+      <avprule id="Auth-Application-Id" type="Mandatory"/>
+      <avprule id="Service-Context-Id" type="Mandatory"/>
+      <avprule id="CC-Request-Type" type="Mandatory"/>
+      <avprule id="CC-Request-Number" type="Mandatory"/>
+      <avprule id="Event-Timestamp" type="Optional"/>
+      <avprule id="Subscription-Id" type="Mandatory" qual="*"/>
+      <avprule id="Termination-Cause" type="Optional"/>
+      <avprule id="Requested-Service-Unit" type="Optional"/>
+      <avprule id="Requested-Action" type="Optional"/>
+      <avprule id="Used-Service-Unit" type="Optional"/>
+      <avprule id="CC-Correlation-Id" type="Optional"/>
+      <avprule id="User-Equipment-Info" type="Optional"/>
+      <avprule id="Proxy-Info" type="Optional" qual="*"/>
+      <avprule id="Route-Record" type="Optional" qual="*"/>
+      <avprule id="Service-Information" type="Optional"/>
+      <avprule id="AVP" type="Optional" qual="*"/>
+   </command>
+
+   <command name="Credit-Control-Answer" code="272" type="Answer">
+      <avprule id="Session-Id" type="Fixed"/>
+      <avprule id="Result-Code" type="Mandatory"/>
+      <avprule id="CS-Result-Code" type="Optional"/>
+      <avprule id="CS-Dialogue-Handling" type="Optional"/>
+      <avprule id="Origin-Host" type="Mandatory"/>
+      <avprule id="Origin-Realm" type="Mandatory"/>
+      <avprule id="Auth-Application-Id" type="Mandatory"/>
+      <avprule id="CC-Request-Type" type="Mandatory"/>
+      <avprule id="CC-Request-Number" type="Mandatory"/>
+      <avprule id="Granted-Service-Unit" type="Optional"/>
+      <avprule id="Cost-Information" type="Optional"/>
+      <avprule id="Low-Balance-Indication" type="Optional"/>
+      <avprule id="Remaining-Balance" type="Optional"/>
+      <avprule id="Credit-Control-Failure-Handling" type="Optional"/>
+      <avprule id="CC-Correlation-Id" type="Optional"/>
+      <avprule id="Redirect-Host" type="Optional" qual="*"/>
+      <avprule id="Redirect-Host-Usage" type="Optional"/>
+      <avprule id="Redirect-Max-Cache-Time" type="Optional"/>
+      <avprule id="Proxy-Info" type="Optional" qual="*"/>
+      <avprule id="Route-Record" type="Optional" qual="*"/>
+      <avprule id="Failed-AVP" type="Optional" qual="*"/>
+      <avprule id="Service-Information" type="Optional"/>
+      <avprule id="AVP" type="Optional" qual="*"/>
+   </command>
+*/
+
+   _exit("Open 'file.trace' in order to see the stacks loaded");
+}
+