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 //
9 #ifndef anna_diameter_comm_OriginHost_hpp
10 #define anna_diameter_comm_OriginHost_hpp
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 #include <anna/diameter.comm/Message.hpp>
22 #include <anna/diameter/codec/MessagesDeque.hpp>
36 * OriginHost with single access point for client and server
37 * That is to say: only one communication engine, then:
38 * - For client: one CER, then one application Id
39 * - For server: no app id control, and multiple serverSession overwrites tsw server session (TestManager), no way to distinguish with single port ...
43 anna::diameter::comm::Engine *a_commEngine;
44 anna::diameter::comm::Entity *a_entity; // we could get it finding the unique instante within comm engine, but it is more comfortable assign here.
45 anna::diameter::comm::LocalServer* a_diameterServer; // idem
46 anna::diameter::codec::Engine *a_codecEngine;
49 int a_requestRetransmissions;
50 anna::Recycler<anna::diameter::comm::Message> a_commMessages;
53 unsigned int a_applicationId;
56 std::string a_logFile;
57 bool a_splitLog, a_detailedLog, a_dumpLog;
58 std::string a_burstLogFile;
59 std::ofstream a_burstLogStream;
63 std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
65 std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
67 int a_burstPopCounter;
69 anna::diameter::codec::MessagesDeque a_reactingAnswers;
72 OriginHost(anna::diameter::comm::Engine* commEngine, unsigned int applicationId);
76 const std::string &getName() const ;
79 anna::diameter::comm::Engine* getCommEngine() const { return a_commEngine; }
80 unsigned int getApplicationId() const { return a_applicationId; }
81 anna::diameter::codec::Engine *getCodecEngine() const { return a_codecEngine; }
83 void createEntity(const std::string &entityRepresentation, const anna::Millisecond &bindTimeout, const anna::Millisecond &applicationTimeout) noexcept(false);
84 anna::diameter::comm::Entity *getEntity() const { return a_entity; }
86 void createDiameterServer(const std::string &serverRepresentation, int sessions, const anna::Millisecond &inactivityTimeout, const anna::Millisecond &applicationTimeout, const std::string &ceaPathfile) noexcept(false);
87 anna::diameter::comm::LocalServer* getDiameterServer() { return a_diameterServer; }
88 void setRequestRetransmissions(int r) { if (r >= 0) a_requestRetransmissions = r; }
91 anna::diameter::comm::Message *createCommMessage() noexcept(false);
92 void releaseCommMessage(anna::diameter::comm::Message*) ;
94 // Traffic logs & burst:
95 void setLogs(const std::string &log, bool splitLog, bool detailedLog, bool dumpLog, const std::string &burstLog) {
97 a_splitLog = splitLog;
98 a_detailedLog = detailedLog;
100 a_burstLogFile = burstLog;
103 bool logEnabled() const { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
104 void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const ;
105 void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const ;
106 void writeBurstLogFile(const std::string &buffer) ;
107 bool burstLogEnabled() const { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
108 int clearBurst() ; // returns removed
109 int loadBurstMessage(const anna::DataBlock & db) noexcept(false);
110 void repeatBurst(bool repeat) { a_burstRepeat = repeat; }
111 int startBurst(int initialLoad) ; // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
112 int pushBurst(int loadAmount) ; // 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)
113 int sendBurst(int loadAmount) ; // returns sent (burst always cycled using send), returns -1 if burst list is empty, -2 if invalid load (0 or negative)
114 int popBurst(int releaseAmount) ; // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
115 int stopBurst() ; // returns remaining on cycle, or -1 if burst already stopped
116 bool burstActive() const { return a_burstActive; }
117 bool sendBurstMessage(bool anyway = false) ;
118 std::string lookBurst(int order = -1) const ;
119 std::string gotoBurst(int order) ;
121 anna::xml::Node* asXML(anna::xml::Node* parent) const ;
122 std::string asXMLString() const ;
124 anna::diameter::codec::MessagesDeque *getReactingAnswers() { return (anna::diameter::codec::MessagesDeque*)&a_reactingAnswers; }