Node class, command line redesign. New xml template for process configuration.
[anna.git] / example / diameter / launcher / RealmNode.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #ifndef example_diameter_launcher_RealmNode_hpp
10 #define example_diameter_launcher_RealmNode_hpp
11
12 // Standard
13 #include <string>
14 #include <fstream>
15
16 // Project
17 #include <anna/core/util/Millisecond.hpp>
18 #include <anna/core/util/Recycler.hpp>
19 #include <anna/core/DataBlock.hpp>
20 #include <anna/diameter/codec/Message.hpp>
21
22
23 namespace anna {
24   namespace diameter {
25     namespace codec {
26       class Engine;
27     }
28     namespace comm {
29       class Message;
30     }
31   }
32 }
33
34
35 class MyDiameterEntity;
36 class MyDiameterEngine;
37 class MyLocalServer;
38
39
40 class RealmNode {
41
42   MyDiameterEngine *a_commEngine;
43   MyDiameterEntity *a_entity; // we could get it finding the unique instante within comm engine, but it is more comfortable assign here.
44   MyLocalServer* a_diameterServer; // idem
45   anna::diameter::codec::Engine *a_codecEngine;
46
47   // resources
48   int a_requestRetransmissions;
49   anna::Recycler<anna::diameter::comm::Message> a_commMessages;
50
51   // main
52   std::string a_originRealm;
53   unsigned int a_applicationId;
54
55   // Timming
56   anna::Millisecond a_allowedInactivityTime;
57   anna::Millisecond a_tcpConnectDelay;
58   anna::Millisecond a_answersTimeout;
59   anna::Millisecond a_ceaTimeout;
60   anna::Millisecond a_watchdogPeriod;
61
62   // Logs & burst
63   std::string a_logFile;
64   bool a_splitLog, a_detailedLog, a_dumpLog;
65   std::string a_burstLogFile;
66   std::ofstream a_burstLogStream;
67   int a_burstCycle;
68   bool a_burstRepeat;
69   bool a_burstActive;
70   std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
71   int a_burstLoadIndx;
72   std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
73   int a_otaRequest;
74   int a_burstPopCounter;
75
76 public:
77   RealmNode(const std::string &originRealm, unsigned int applicationId, anna::diameter::codec::Engine *codecEngine);
78   ~RealmNode() {;}
79
80   std::string asString() const throw();
81
82   // Core resources:
83   MyDiameterEngine* getMyDiameterEngine() const throw() { return a_commEngine; }
84   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
85   void createEntity(const std::string &entityRepresentation, const anna::Millisecond &bindTimeout, const anna::Millisecond &applicationTimeout) throw();
86   MyDiameterEntity *getEntity() const throw() { return a_entity; }
87   void startDiameterServer(const std::string &serverRepresentation, int sessions, const anna::Millisecond &inactivityTimeout) throw(anna::RuntimeException);
88   MyLocalServer* getDiameterServer() throw() { return a_diameterServer; }
89   void setRequestRetransmissions(int r) throw() { if (r >= 0) a_requestRetransmissions = r; }
90
91   // Messages factory:
92   anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException);
93   void releaseCommMessage(anna::diameter::comm::Message*) throw();
94
95   // Traffic logs & burst:
96   void setLogs(const std::string &log, bool splitLog, bool detailedLog, bool dumpLog, const std::string &burstLog) throw() {
97     a_logFile = log;
98     a_splitLog = splitLog;
99     a_detailedLog = detailedLog;
100     a_dumpLog = dumpLog;
101     a_burstLogFile = burstLog;
102   }
103
104   bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
105   void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw();
106   void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw();
107   void writeBurstLogFile(const std::string &buffer) throw();
108   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
109   int clearBurst() throw(); // returns removed
110   int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
111   void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
112   int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
113   int pushBurst(int loadAmount) throw(); // returns pushed (perhaps is less than provided because of no repeat mode and burst list exhausted), or -1 if burst list is empty, -2 if invalid load (0 or negative)
114   int sendBurst(int loadAmount) throw(); // returns sent (burst always cycled using send), returns -1 if burst list is empty, -2 if invalid load (0 or negative)
115   int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
116   int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
117   bool burstActive() const throw() { return a_burstActive; }
118   bool sendBurstMessage(bool anyway = false) throw();
119   std::string lookBurst(int order) const throw();
120   std::string gotoBurst(int order) throw();
121
122   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
123   std::string asXMLString() const throw();
124 };
125
126 #endif