84 #include <boost/asio/ip/tcp.hpp>
85 #include <boost/ptr_container/ptr_map.hpp>
86 #include <boost/enable_shared_from_this.hpp>
87 #include <boost/tuple/tuple.hpp>
93 #include <sandesh/sandesh_util.h>
94 #include <sandesh/sandesh_types.h>
95 #include <sandesh/protocol/TProtocol.h>
96 #include <sandesh/transport/TBufferTransports.h>
97 #include <sandesh/sandesh_trace.h>
98 #include <sandesh/sandesh_options.h>
120 class SandeshMessageTypeStats;
121 class SandeshMessageStats;
122 class SandeshMessageTypeBasicStats;
123 class SandeshMessageBasicStats;
135 boost::shared_ptr<contrail::sandesh::transport::TMemoryBuffer> >
148 typedef std::map<std::string, std::map<std::string,std::string> >
DerivedStats;
152 const std::string &
source,
157 const std::vector<std::string> &collectors,
162 const std::string &source,
163 const std::string &node_type,
164 const std::string &instance_id,
166 unsigned short http_port,
170 static void RecordPort(
const std::string& name,
const std::string& module,
171 unsigned short port);
174 const std::string &source,
175 const std::string &node_type,
176 const std::string &instance_id,
178 const std::string &collector_ip,
int collector_port,
179 unsigned short http_port,
184 const std::string &source,
185 const std::string &node_type,
186 const std::string &instance_id,
188 unsigned short http_port,
192 int collector_port,
bool periodicuve =
false);
214 std::string
level,
bool enable_trace_print =
false,
215 bool enable_flow_log =
false,
bool enable_session_syslog =
false);
218 bool enable_flow_log =
false);
235 virtual size_t GetSize()
const = 0;
259 std::vector<SandeshMessageTypeStats> *mtype_stats,
260 SandeshMessageStats *magg_stats);
262 boost::ptr_map<std::string, SandeshMessageTypeStats> *mtype_stats,
263 SandeshMessageStats *magg_stats);
267 virtual void Log()
const = 0;
269 virtual std::string
ToString()
const = 0;
271 virtual int32_t
Read(
272 boost::shared_ptr<contrail::sandesh::protocol::TProtocol> iprot) = 0;
273 virtual int32_t
Write(
274 boost::shared_ptr<contrail::sandesh::protocol::TProtocol> oprot)
const = 0;
277 virtual const char *
Name()
const {
return name_.c_str(); }
279 virtual int32_t
WriteBinary(u_int8_t *buf, u_int32_t buf_len,
int *error);
280 virtual int32_t
ReadBinary(u_int8_t *buf, u_int32_t buf_len,
int *error);
328 int max_backup_index,
329 const std::string &syslog_facility,
330 const std::vector<std::string> &destn,
331 const std::string &ident,
332 bool is_sampled_logger);
334 const std::vector<std::string> &sampled_destination,
335 const std::vector<std::string> &slo_destination);
394 const std::vector<std::string> &collectors,
398 const std::string &source,
399 const std::string &node_type,
400 const std::string &instance_id,
402 unsigned short http_port,
474 #define SANDESH_LOG(_Level, _Msg) \
476 if (LoggingDisabled()) break; \
477 LOG4CPLUS_##_Level(Sandesh::logger(), _Msg); \
481 public boost::enable_shared_from_this<SandeshRequest> {
485 const std::string& snh_query) = 0;
487 boost::shared_ptr<const SandeshRequest>
SharedPtr()
const {
return shared_from_this(); }
491 Sandesh(SandeshType::REQUEST, name, seqno),
self_(this) {}
493 template <
typename T>
494 friend void boost::checked_delete(T *x);
495 boost::shared_ptr<SandeshRequest>
self_;
500 virtual const bool get_more()
const = 0;
501 virtual void set_more(
const bool val) = 0;
505 Sandesh(SandeshType::RESPONSE, name, seqno) {}
525 Sandesh(SandeshType::BUFFER, name, seqno, true) {}
548 Sandesh(SandeshType::SYSTEM, name, seqno) {}
554 Sandesh(SandeshType::OBJECT, name, seqno) {}
560 Sandesh(SandeshType::FLOW, name, seqno) {}
566 Sandesh(SandeshType::SESSION, name, seqno) {}
578 virtual std::string
DataLog(
void) {
return std::string(); }
593 SandeshUVE(name, seqno, SandeshType::ALARM) {}
598 template <
typename QueueT>
601 while (q.try_pop(element)) {
610 template <
typename QueueT>
613 while (q.try_pop(rsandesh)) {
624 map_type::iterator it =
GetMap()->find(s);
625 if (it ==
GetMap()->end()) {
631 typedef std::map<std::string, Sandesh*(*)()>
map_type;
634 map_type::const_iterator m_iter = map.begin();
635 for (; m_iter != map.end(); m_iter++) {
636 map_type::iterator b_iter =
GetMap()->find((*m_iter).first);
637 if (b_iter !=
End()) {
640 GetMap()->insert(*m_iter);
643 static map_type::const_iterator
Begin() {
return GetMap()->begin(); }
644 static map_type::const_iterator
End() {
return GetMap()->end(); }
657 GetMap()->insert(std::make_pair(s, &createT<T>));
667 #define SANDESH_REGISTER_DEC_TYPE(NAME) \
668 static SandeshDerivedRegister<NAME> reg
670 #define SANDESH_REGISTER_DEF_TYPE(NAME) \
671 SandeshDerivedRegister<NAME> NAME::reg(#NAME)
679 template <
typename T>
681 static bool get(
const T& s) {
return false; }
683 template <
typename T>
685 static std::string
get(
const T& s) {
return std::string(
""); }
687 #endif // __SANDESH_H__
SandeshAlarm(const std::string &name, uint32_t seqno)
SandeshFlow(const std::string &name, uint32_t seqno)
SandeshTrace(const std::string &name, uint32_t seqno)
SandeshLevel::type level() const
boost::asio::ip::tcp::endpoint Endpoint
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
SandeshLevel::type level_
static void InitClient(EventManager *evm, Endpoint server, const SandeshConfig &config, bool periodicuve)
static bool IsTracePrintEnabled()
static SandeshContext * module_context(const std::string &module_name)
static bool disable_sending_object_logs_
static std::string instance_id_
virtual void SendTrace(const std::string &context, bool more)=0
SandeshUVE(const std::string &name, uint32_t seqno, SandeshType::type t=SandeshType::UVE)
static bool sampled_to_collector_
static map_type::const_iterator Begin()
static SandeshRole::type role_
static SandeshLevel::type StringToLevel(std::string level)
bool Dispatch(SandeshConnection *sconn=NULL)
static void InitReceive(int recv_task_inst=-1)
std::string scope() const
static SandeshLevel::type SendingLevel()
WorkQueue< SandeshRequest * > SandeshRxQueue
virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
virtual void HandleRequest() const =0
SandeshFlowSession(const std::string &name, uint32_t seqno)
static void ReConfigCollectors(const std::vector< std::string > &collector_list)
static Sandesh * CreateInstance(std::string const &s)
static bool SendReady(SandeshConnection *sconn=NULL)
static void SetLoggingParams(bool enable_local_log, std::string category, std::string level, bool enable_trace_print=false, bool enable_flow_log=false, bool enable_session_syslog=false)
const bool get_more() const
virtual std::string ModuleName() const =0
static void set_response_callback(SandeshCallback response_cb)
static bool HandleTest(SandeshLevel::type level, const std::string &category)
virtual size_t GetSize() const =0
static bool is_send_sampled_to_logger_enabled()
static void set_instance_id(std::string &instance_id)
static void SetSendQueue(bool enable)
SandeshRequest(const std::string &name, uint32_t seqno)
static void set_send_rate_limit(int rate_limit)
static bool enable_trace_print_
Sandesh(SandeshType::type type, const std::string &name, uint32_t seqno)
static std::unique_ptr< SandeshRxQueue > recv_queue_
virtual void Log() const =0
std::map< std::string, SandeshContext * > ModuleContextMap
virtual int32_t ReadBinaryFromFile(const std::string &path, int *error)
static const char * SandeshRoleToString(SandeshRole::type role)
static SandeshLevel::type LoggingLevel()
static void SetDscpValue(uint8_t value)
virtual const char * Name() const
SandeshObject(const std::string &name, uint32_t seqno)
static log4cplus::Logger sampled_logger_
static log4cplus::Logger & sampled_logger()
std::map< std::string, std::map< std::string, std::string > > DerivedStats
static bool is_send_slo_to_collector_enabled()
static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes)
static void SetLoggingCategory(std::string category)
static SandeshCallback response_callback()
boost::shared_ptr< const SandeshRequest > SharedPtr() const
static bool ProcessRecv(SandeshRequest *)
static bool ConnectToCollector(const std::string &collector_ip, int collector_port, bool periodicuve=false)
static void DisableSendingObjectLogs(bool disable)
static tbb::mutex stats_mutex_
static void UpdateRxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshRxDropReason::type dreason)
static log4cplus::Logger & slo_logger()
static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes)
static std::string node_type()
void set_category(std::string category)
boost::function< void(Sandesh *)> SandeshCallback
static SandeshLevel::type logging_ut_level_
SandeshDerivedRegister(std::string const &s)
bool Enqueue(SandeshRxQueue *queue)
static void SetLocalLogging(bool enable)
static tbb::atomic< uint32_t > sandesh_send_ratelimit_
static bool InitCollector(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, const std::string &collector_ip, int collector_port, unsigned short http_port, SandeshContext *client_context=NULL, const SandeshConfig &config=SandeshConfig())
static bool IsFlowLoggingEnabled()
static bool disable_sending_flows_
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
static bool IsSendingObjectLogsDisabled()
static bool disable_flow_collection_
void set_seqnum(const uint32_t seqnum)
static const char * LevelToString(SandeshLevel::type level)
static void SetSessionSyslogging(bool enable_session_syslog)
static void SetLoggingLevel(std::string level)
static std::string node_type_
static SandeshRole::type role()
static std::string module()
virtual int32_t Read(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > iprot)=0
static SandeshLevel::type logging_level_
void set_level(SandeshLevel::type level)
SandeshType::type type() const
std::map< std::string, Sandesh *(*)()> map_type
bool Dispatch(SandeshConnection *sconn=NULL)
static bool enable_flow_log_
std::string category() const
static std::string module_
SandeshResponse(const std::string &name, uint32_t seqno)
static bool enable_session_syslog_
std::string context() const
static bool send_queue_enabled_
virtual std::string DataLog(void)
static log4cplus::Logger slo_logger_
static bool IsFlowCollectionDisabled()
bool IsLoggingAllowed() const
static map_type::const_iterator End()
bool DoDropSandeshMessage(const SandeshHeader &header, const SandeshLevel::type drop_level)
static SandeshClient * client_
static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
static SandeshConfig config_
static SandeshClient * client()
virtual bool SendEnqueue()
virtual const int32_t versionsig() const =0
static std::string logging_category_
void set_name(const char *name)
void operator()(QueueT &q, bool delete_entry)
static log4cplus::Logger logger_
static int32_t ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
static bool IsSendingSystemLogsDisabled()
void set_scope(std::string scope)
static void set_module_context(const std::string &module_name, SandeshContext *context)
static bool connect_to_collector_
static bool is_send_slo_to_logger_enabled()
const bool get_more() const
static bool InitGeneratorTest(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, SandeshContext *client_context=NULL, const SandeshConfig &config=SandeshConfig())
static void set_source(std::string &source)
virtual const bool get_more() const =0
virtual const uint32_t seqnum()
void set_hints(int32_t hints)
size_t AtomicIncrementQueueCount(QueueEntryT *entry)
static bool IsSendingAllMessagesDisabled()
static bool InitGenerator(const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, const std::vector< std::string > &collectors, SandeshContext *client_context=NULL, DerivedStats ds=DerivedStats(), const SandeshConfig &config=SandeshConfig())
SandeshElement(Sandesh *snh)
size_t AtomicDecrementQueueCount(QueueEntryT *entry)
WorkQueue< boost::shared_ptr< contrail::sandesh::transport::TMemoryBuffer > > SandeshBufferQueue
~SandeshDerivedRegister()
void set_type(SandeshType::type type)
virtual int32_t ReadBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
static uint64_t UTCTimestampUsec()
static bool enable_local_log_
static std::string LoggingCategory()
static bool IsConnectToCollectorEnabled()
virtual void ForcedLog() const =0
void set_context(std::string context)
void operator()(QueueT &q, bool delete_entry)
void set_timestamp(time_t timestamp)
static uint32_t get_send_rate_limit()
static map_type * GetMap()
static SandeshRxQueue * recv_queue()
Sandesh(SandeshType::type type, const std::string &name, uint32_t seqno, bool no_time_stamp)
bool Dispatch(SandeshConnection *sconn=NULL)
WorkQueue< SandeshElement > SandeshQueue
static bool IsLoggingDroppedAllowed(SandeshType::type)
static bool disable_sending_all_
static bool IsLocalLoggingEnabled()
static SandeshCallback response_callback_
boost::shared_ptr< SandeshRequest > self_
static bool IsLevelUT(SandeshLevel::type level)
virtual std::string ToString() const =0
static void DisableFlowCollection(bool disable)
static void set_client_context(SandeshContext *context)
virtual int32_t Write(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > oprot) const =0
static void SetFlowLogging(bool enable)
static void set_logger_appender(const std::string &file_name, long max_file_size, int max_backup_index, const std::string &syslog_facility, const std::vector< std::string > &destn, const std::string &ident, bool is_sampled_logger)
SandeshBuffer & operator=(const SandeshBuffer &r)
static SandeshMessageStatistics msg_stats_
static log4cplus::Logger & logger()
SandeshSystem(const std::string &name, uint32_t seqno)
static bool Initialize(SandeshRole::type role, const std::string &module, const std::string &source, const std::string &node_type, const std::string &instance_id, EventManager *evm, unsigned short http_port, SandeshContext *client_context=NULL, const SandeshConfig &config=SandeshConfig())
static std::string source()
virtual bool Dispatch(SandeshConnection *sconn=NULL)
static void RecordPort(const std::string &name, const std::string &module, unsigned short port)
static bool sampled_to_logger_
static bool slo_to_collector_
friend class SandeshTracePerfTest
static bool is_send_sampled_to_collector_enabled()
static SandeshLevel::type LoggingUtLevel()
static void Update(map_type &map)
static std::string source_
static void set_node_type(std::string &node_type)
boost::tuple< size_t, SandeshLevel::type, bool, bool > QueueWaterMarkInfo
SandeshBuffer(const std::string &name, uint32_t seqno)
static void DisableSendingAllMessages(bool disable)
static EventManager * event_manager_
static void GetMsgStats(std::vector< SandeshMessageTypeStats > *mtype_stats, SandeshMessageStats *magg_stats)
void set_more(const bool val)
static SandeshContext * client_context_
static bool IsSendingFlowsDisabled()
static bool slo_to_logger_
static bool IsLevelCategoryLoggingAllowed(SandeshType::type type, SandeshLevel::type level, const std::string &category)
static void DisableSendingFlows(bool disable)
virtual bool RequestFromHttp(const std::string &ctx, const std::string &snh_query)=0
static void set_send_to_collector_flags(const std::vector< std::string > &sampled_destination, const std::vector< std::string > &slo_destination)
virtual void set_more(const bool val)=0
static void SetTracePrint(bool enable)
static bool IsSendQueueEnabled()
static SandeshContext * client_context()
static bool IsSloSyslogEnabled()
static ModuleContextMap module_context_
static std::string instance_id()
virtual int32_t WriteBinaryToFile(const std::string &path, int *error)
static void set_module(std::string &module)
virtual void Process(SandeshContext *context)=0
static SandeshConfig & config()
bool Enqueue(SandeshQueue *queue)
virtual ~SandeshContext()