OpenSDN source code
cpp/sandesh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // sandesh.h
7 //
8 // Sandesh means message in Hindi. Sandeshs are used to store
9 // structured information from various software modules of the
10 // Virtual Network System (VNS) into the analytics database.
11 // Sandeshs are also used to exchange information for the purpose of
12 // debugging the VNS.
13 // The different types of Sandeshs are:
14 // 1. Async - Used to send event-triggered messages to the analytics
15 // database
16 // 2. Request and Response - Used for debugging and displaying
17 // information from various software modules of the VNS like
18 // vnswa and bgpd.
19 // 3. Trace - Used for triggering internal trace messages
20 //
21 // Sandesh module consists of 2 parts:
22 // 1. The first part is a code generator tool that reads in .sandesh files
23 // and generates appropriate C++ code for encoding the Sandeshs using
24 // XML.
25 // 2. The second part is a library that software modules like vnswa and
26 // bgpd will link with and use to:
27 // a. Send Sandeshs to the analytics database
28 // b. Provide operational command implementation
29 // c. Enable/disable tracing
30 //
31 // For example, vnswa developer wants to generate a structured error message to
32 // report some error condition. The developer will add an async sandesh to the
33 // file VNSwitch.sandesh as below:
34 //
35 // struct VNSRoute {
36 // 1: i32 prefix;
37 // }
38 //
39 // async sandesh VNSwitchError {
40 // 1: "VNSwitchId = ";
41 // 2: i32 vnSwitchId;
42 // 3: "VNetworkId = ";
43 // 4: i32 vnId;
44 // 5: list<VNSRoute> vnRoutes;
45 // 6: VNSRoute vnMarkerRoute;
46 // }
47 //
48 // To use Sandesh, the following needs to be added to the module SConscript:
50 // # Generate the source files
51 // SandeshGenFiles = env.SandeshGenCpp('VNS.sandesh')
52 // SandeshGenFiles += env.SandeshGenCpp('VNSwitch.sandesh')
53 //
54 // # The above returns VNS_types.h, VNS_types.cpp, VNS_constants.h
55 // # VNS_constants.cpp, VNSwitch_types.h, VNSwitch_types.cpp,
56 // # VNSwitch_constants.h, VNSwitch_constants.cpp
57 //
58 // # To include the header files above from your module's sources
59 // env.Append(CPPPATH = env['TOP'])
60 //
61 // # Extract the .cpp files to be used as sources
62 // SandeshGenSrcs = env.ExtractCpp(SandeshGenFiles)
63 //
64 // Add SandeshGenSrcs to the module source files
65 //
66 // Add libsandesh, and libbase to the module libraries.
67 //
68 // The code to send the Sandesh to the analytics database will be:
69 //
70 // VNSwitchError::Send(int32_t vnSwitchId, int32_t vnId, std::vector<VNSRoute> vnRoutes,
71 // VNSRoute vnMarkerRoute)
72 //
73 // The developer will have to call Sandesh::InitGenerator from the module's
74 // initialization before calling the above function.
75 //
76 
77 #ifndef __SANDESH_H__
78 #define __SANDESH_H__
79 
80 #include <time.h>
81 
82 #include <atomic>
83 #include <map>
84 #include <mutex>
85 
86 #include <boost/asio/ip/tcp.hpp>
87 #include <boost/ptr_container/ptr_map.hpp>
88 #include <boost/enable_shared_from_this.hpp>
89 #include <boost/tuple/tuple.hpp>
90 #include <base/contrail_ports.h>
91 #include <base/logging.h>
92 #include <base/queue_task.h>
93 #include <base/string_util.h>
94 #include <base/time_util.h>
95 #include <sandesh/sandesh_util.h>
96 #include <sandesh/sandesh_types.h>
97 #include <sandesh/protocol/TProtocol.h>
98 #include <sandesh/transport/TBufferTransports.h>
99 #include <sandesh/sandesh_trace.h>
100 #include <sandesh/sandesh_options.h>
101 
102 // Forward declaration
103 class EventManager;
104 class SandeshClient;
105 class SandeshSession;
106 
107 // Sandesh Context
109  // Abstract base class for users of sandesh library to
110  // pass in information to used when handling sandesh
111  // request and response
112 protected:
114 public:
115  virtual ~SandeshContext() { }
116 };
117 
118 //
119 // Sandesh
120 //
122 class SandeshMessageTypeStats;
123 class SandeshMessageStats;
124 class SandeshMessageTypeBasicStats;
125 class SandeshMessageBasicStats;
126 class SandeshConnection;
127 class SandeshRequest;
128 
129 
130 struct SandeshElement;
131 
132 class Sandesh {
133 public:
136  typedef WorkQueue<
137  boost::shared_ptr<contrail::sandesh::transport::TMemoryBuffer> >
139  typedef boost::asio::ip::tcp::endpoint Endpoint;
140  typedef boost::function<void (Sandesh *)> SandeshCallback;
141  struct SandeshRole {
142  enum type {
147  };
148  };
149  typedef boost::tuple<size_t, SandeshLevel::type, bool, bool> QueueWaterMarkInfo;
150  typedef std::map<std::string, std::map<std::string,std::string> > DerivedStats;
151 
152  // Initialization APIs
153  static bool InitGenerator(const std::string &module,
154  const std::string &source,
155  const std::string &node_type,
156  const std::string &instance_id,
157  EventManager *evm,
158  unsigned short http_port,
159  const std::vector<std::string> &collectors,
161  DerivedStats ds = DerivedStats(),
162  const SandeshConfig &config = SandeshConfig());
163  static bool InitGenerator(const std::string &module,
164  const std::string &source,
165  const std::string &node_type,
166  const std::string &instance_id,
167  EventManager *evm,
168  unsigned short http_port,
170  DerivedStats ds = DerivedStats(),
171  const SandeshConfig &config = SandeshConfig());
172  static void RecordPort(const std::string& name, const std::string& module,
173  unsigned short port);
174  // Collector
175  static bool InitCollector(const std::string &module,
176  const std::string &source,
177  const std::string &node_type,
178  const std::string &instance_id,
179  EventManager *evm,
180  const std::string &collector_ip, int collector_port,
181  unsigned short http_port,
183  const SandeshConfig &config = SandeshConfig());
184  // Test
185  static bool InitGeneratorTest(const std::string &module,
186  const std::string &source,
187  const std::string &node_type,
188  const std::string &instance_id,
189  EventManager *evm,
190  unsigned short http_port,
192  const SandeshConfig &config = SandeshConfig());
193  static bool ConnectToCollector(const std::string &collector_ip,
194  int collector_port, bool periodicuve = false);
195  static void ReConfigCollectors(const std::vector<std::string>& collector_list);
196  static void Uninit();
197  static void SetDscpValue(uint8_t value);
198 
199  // Disable flow collection
200  static void DisableFlowCollection(bool disable);
202 
203  // Flags to control sending of sandesh from generators
204  static void DisableSendingAllMessages(bool disable);
205  static bool IsSendingAllMessagesDisabled();
206  static void DisableSendingObjectLogs(bool disable);
207  static bool IsSendingObjectLogsDisabled();
208  static bool IsSendingSystemLogsDisabled();
209  static void DisableSendingFlows(bool disable);
210  static bool IsSendingFlowsDisabled();
211  static void set_send_rate_limit(int rate_limit);
212  static uint32_t get_send_rate_limit();
213 
214  // Logging and category APIs
215  static void SetLoggingParams(bool enable_local_log, std::string category,
216  std::string level, bool enable_trace_print = false,
217  bool enable_flow_log = false, bool enable_session_syslog = false);
218  static void SetLoggingParams(bool enable_local_log, std::string category,
219  SandeshLevel::type level, bool enable_trace_print = false,
220  bool enable_flow_log = false);
221  static void SetLoggingLevel(std::string level);
225  static bool IsLocalLoggingEnabled() { return enable_local_log_; }
226  static void SetLocalLogging(bool enable);
227  static bool IsFlowLoggingEnabled() { return enable_flow_log_; }
228  static bool IsSloSyslogEnabled() { return enable_session_syslog_; }
229  static void SetFlowLogging(bool enable);
230  static void SetSessionSyslogging(bool enable_session_syslog);
231  static bool IsTracePrintEnabled() { return enable_trace_print_; }
232  static void SetTracePrint(bool enable);
233  static void SetLoggingCategory(std::string category);
234  static std::string LoggingCategory() { return logging_category_; }
235 
236  //GetSize method to report the size
237  virtual size_t GetSize() const = 0;
238 
239  // Send queue processing
240  static void SetSendQueue(bool enable);
241  static inline bool IsSendQueueEnabled() {
242  return send_queue_enabled_;
243  }
244  static inline bool IsConnectToCollectorEnabled() {
245  return connect_to_collector_;
246  }
248 
249  static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len,
250  int *error, SandeshContext *client_context);
251  static int32_t ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len,
252  int *error, SandeshContext *client_context);
253  static bool SendReady(SandeshConnection * sconn = NULL);
254  static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes);
255  static void UpdateRxMsgFailStats(const std::string &msg_name,
256  uint64_t bytes, SandeshRxDropReason::type dreason);
257  static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes);
258  static void UpdateTxMsgFailStats(const std::string &msg_name,
259  uint64_t bytes, SandeshTxDropReason::type dreason);
260  static void GetMsgStats(
261  std::vector<SandeshMessageTypeStats> *mtype_stats,
262  SandeshMessageStats *magg_stats);
263  static void GetMsgStats(
264  boost::ptr_map<std::string, SandeshMessageTypeStats> *mtype_stats,
265  SandeshMessageStats *magg_stats);
266  static const char * SandeshRoleToString(SandeshRole::type role);
267 
268  virtual void Release() { delete this; }
269  virtual void Log() const = 0;
270  virtual void ForcedLog() const = 0;
271  virtual std::string ToString() const = 0;
272  virtual std::string ModuleName() const = 0;
273  virtual int32_t Read(
274  boost::shared_ptr<contrail::sandesh::protocol::TProtocol> iprot) = 0;
275  virtual int32_t Write(
276  boost::shared_ptr<contrail::sandesh::protocol::TProtocol> oprot) const = 0;
277  virtual const uint32_t seqnum() { return seqnum_; }
278  virtual const int32_t versionsig() const = 0;
279  virtual const char *Name() const { return name_.c_str(); }
280  bool Enqueue(SandeshQueue* queue);
281  virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error);
282  virtual int32_t ReadBinary(u_int8_t *buf, u_int32_t buf_len, int *error);
283  virtual int32_t WriteBinaryToFile(const std::string& path, int *error);
284  virtual int32_t ReadBinaryFromFile(const std::string& path, int *error);
285 
286  bool IsLoggingAllowed() const;
288 
289  // Accessors
290  static void set_source(std::string &source) { source_ = source; }
291  static std::string source() { return source_; }
292  static void set_module(std::string &module) { module_ = module; }
293  static std::string module() { return module_; }
294  static void set_instance_id(std::string &instance_id) { instance_id_ = instance_id; }
295  static std::string instance_id() { return instance_id_; }
296  static void set_node_type(std::string &node_type) { node_type_ = node_type; }
297  static std::string node_type() { return node_type_; }
298  static SandeshRole::type role() { return role_; }
299  static int http_port() { return http_port_; }
300  static SandeshRxQueue* recv_queue() { return recv_queue_.get(); }
303  static SandeshContext *module_context(const std::string &module_name);
304  static void set_module_context(const std::string &module_name,
306  static void set_response_callback(SandeshCallback response_cb) { response_callback_ = response_cb; }
308  static SandeshClient* client() { return client_; }
309  static SandeshConfig& config() { return config_; }
310 
311  time_t timestamp() const { return timestamp_; }
312  void set_context(std::string context) { context_ = context; }
313  std::string context() const { return context_; }
314  void set_scope(std::string scope) { scope_ = scope; }
315  std::string scope() const { return scope_; }
316  SandeshType::type type() const { return type_; }
317  void set_hints(int32_t hints) { hints_ = hints; }
318  int32_t hints() const { return hints_; }
320  SandeshLevel::type level() const { return level_; }
321  void set_category(std::string category) { category_ = category; }
322  std::string category() const { return category_; }
323  static const char* LevelToString(SandeshLevel::type level);
324  static SandeshLevel::type StringToLevel(std::string level);
325  static log4cplus::Logger& logger() { return logger_; }
326  static log4cplus::Logger& slo_logger() { return slo_logger_; }
327  static log4cplus::Logger& sampled_logger() { return sampled_logger_; }
328  static void set_logger_appender(const std::string &file_name,
329  long max_file_size,
330  int max_backup_index,
331  const std::string &syslog_facility,
332  const std::vector<std::string> &destn,
333  const std::string &ident,
334  bool is_sampled_logger);
335  static void set_send_to_collector_flags(
336  const std::vector<std::string> &sampled_destination,
337  const std::vector<std::string> &slo_destination);
342 
343 protected:
346  void set_name(const char *name) { name_ = name; }
347 
348  Sandesh(SandeshType::type type, const std::string& name, uint32_t seqno) :
349  seqnum_(seqno),
350  context_(""),
352  scope_(""),
353  type_(type),
354  hints_(0),
355  level_(SandeshLevel::INVALID),
356  category_(""),
357  name_(name) {
358  }
359  Sandesh(SandeshType::type type, const std::string& name, uint32_t seqno, bool no_time_stamp) :
360  seqnum_(seqno),
361  context_(""),
362  scope_(""),
363  type_(type),
364  hints_(0),
365  level_(SandeshLevel::INVALID),
366  category_(""),
367  name_(name) {
368  timestamp_ = no_time_stamp ? 0 : UTCTimestampUsec();
369  }
370  virtual ~Sandesh() {}
371  virtual bool Dispatch(SandeshConnection * sconn = NULL);
372  virtual bool SendEnqueue();
373 
374  static bool HandleTest(SandeshLevel::type level, const
375  std::string& category);
376 
377  static bool IsUnitTest() {
379  }
382  static bool IsLevelUT(SandeshLevel::type level);
385  const std::string& category);
386 
387 private:
388  friend class SandeshTracePerfTest;
389 
390  typedef std::map<std::string, SandeshContext *> ModuleContextMap;
391 
392  static void InitReceive(int recv_task_inst = -1);
393  static void InitClient(EventManager *evm, Endpoint server,
394  const SandeshConfig &config, bool periodicuve);
395  static bool InitClient(EventManager *evm,
396  const std::vector<std::string> &collectors,
397  const SandeshConfig &config);
398  static bool ProcessRecv(SandeshRequest *);
399  static bool Initialize(SandeshRole::type role, const std::string &module,
400  const std::string &source,
401  const std::string &node_type,
402  const std::string &instance_id,
403  EventManager *evm,
404  unsigned short http_port,
406  const SandeshConfig &config = SandeshConfig());
407 
409  static std::string module_;
410  static std::string source_;
411  static std::string node_type_;
412  static std::string instance_id_;
413  static int http_port_;
414  static std::unique_ptr<SandeshRxQueue> recv_queue_;
415  static int recv_task_id_;
418  static bool enable_local_log_; // whether to just enable local logging
419  static bool enable_flow_log_; // whether to enable flow sandesh message logging
420  static bool enable_session_syslog_; // whether to enable syslog for SLO session messages
421  static SandeshLevel::type logging_level_; // current logging level
422  static SandeshLevel::type logging_ut_level_; // ut_debug logging level
423  static std::string logging_category_; // current logging category
424  static bool enable_trace_print_; // whether to print traces locally
425  static bool connect_to_collector_; // whether to connect to collector
427  static bool send_queue_enabled_;
429  static std::mutex stats_mutex_;
430  static log4cplus::Logger logger_;
431  static log4cplus::Logger slo_logger_;
432  static log4cplus::Logger sampled_logger_;
433  static bool disable_flow_collection_; // disable flow collection
435  static bool disable_sending_all_;
438 
439  const uint32_t seqnum_;
440  std::string context_;
441  time_t timestamp_;
442  std::string scope_;
444  int32_t hints_;
446  std::string category_;
447  std::string name_;
448  static std::atomic<uint32_t> sandesh_send_ratelimit_;
449  static bool slo_to_collector_;
451  static bool slo_to_logger_;
452  static bool sampled_to_logger_;
453 };
454 
457  //Explicit constructor creating only if Sandesh is passed as arg
458  explicit SandeshElement(Sandesh *snh):snh_(snh),size_(snh->GetSize()) {
459  }
461  size_t GetSize() const {
462  return size_;
463  }
464  private:
465  size_t size_;
466 };
467 
468 template<>
470  SandeshElement *element);
471 
472 template<>
474  SandeshElement *element);
475 
476 #define SANDESH_LOG(_Level, _Msg) \
477  do { \
478  if (LoggingDisabled()) break; \
479  LOG4CPLUS_##_Level(Sandesh::logger(), _Msg); \
480  } while (0)
481 
482 class SandeshRequest : public Sandesh,
483  public boost::enable_shared_from_this<SandeshRequest> {
484 public:
485  virtual void HandleRequest() const = 0;
486  virtual bool RequestFromHttp(const std::string& ctx,
487  const std::string& snh_query) = 0;
488  void Release();
489  boost::shared_ptr<const SandeshRequest> SharedPtr() const { return shared_from_this(); }
490  bool Enqueue(SandeshRxQueue* queue);
491 protected:
492  SandeshRequest(const std::string& name, uint32_t seqno) :
493  Sandesh(SandeshType::REQUEST, name, seqno), self_(this) {}
494 
495  template <typename T>
496  friend void boost::checked_delete(T *x);
497  boost::shared_ptr<SandeshRequest> self_;
498 };
499 
500 class SandeshResponse : public Sandesh {
501 public:
502  virtual const bool get_more() const = 0;
503  virtual void set_more(const bool val) = 0;
504  virtual void Response() {}
505 protected:
506  SandeshResponse(const std::string& name, uint32_t seqno) :
507  Sandesh(SandeshType::RESPONSE, name, seqno) {}
508  bool Dispatch(SandeshConnection * sconn = NULL);
509 };
510 
511 class SandeshBuffer : public Sandesh {
512 public:
513  virtual void Process(SandeshContext *context) = 0;
515  set_context(r.context());
517  set_scope(r.scope());
518  set_hints(r.hints());
519  set_type(r.type());
520  set_level(r.level());
521  set_category(r.category());
522  set_name(r.Name());
523  return(*this);
524  }
525 protected:
526  SandeshBuffer(const std::string& name, uint32_t seqno) :
527  Sandesh(SandeshType::BUFFER, name, seqno, true) {}
528 };
529 
530 class SandeshTrace : public Sandesh {
531 public:
532  const uint32_t seqnum() { return xseqnum_; }
533  virtual void SendTrace(const std::string& context, bool more) = 0;
534  const bool get_more() const { return more_; }
535  virtual ~SandeshTrace() {}
536 protected:
537  SandeshTrace(const std::string& name, uint32_t seqno) :
538  Sandesh(SandeshType::TRACE, name, 0), xseqnum_(0), more_(true) {}
539  bool Dispatch(SandeshConnection * sconn = NULL);
540  void set_seqnum(const uint32_t seqnum) { xseqnum_= seqnum; }
541  void set_more(bool more) { more_ = more; }
542 private:
543  uint32_t xseqnum_;
544  bool more_;
545 };
546 
547 class SandeshSystem : public Sandesh {
548 protected:
549  SandeshSystem(const std::string& name, uint32_t seqno) :
550  Sandesh(SandeshType::SYSTEM, name, seqno) {}
551 };
552 
553 class SandeshObject : public Sandesh {
554 protected:
555  SandeshObject(const std::string& name, uint32_t seqno) :
556  Sandesh(SandeshType::OBJECT, name, seqno) {}
557 };
558 
559 class SandeshFlow : public Sandesh {
560 protected:
561  SandeshFlow(const std::string& name, uint32_t seqno) :
562  Sandesh(SandeshType::FLOW, name, seqno) {}
563 };
564 
565 class SandeshFlowSession : public Sandesh {
566 protected:
567  SandeshFlowSession(const std::string& name, uint32_t seqno) :
568  Sandesh(SandeshType::SESSION, name, seqno) {}
569 };
570 
571 class SandeshUVE : public Sandesh {
572 public:
573  const bool get_more() const { return more_; }
574  typedef enum {
575  ST_SYNC = 0,
578  ST_MAX = 3
580  virtual std::string DataLog(void) { return std::string(); }
581 protected:
582  SandeshUVE(const std::string& name, uint32_t seqno,
583  SandeshType::type t = SandeshType::UVE) :
584  Sandesh(t, name, seqno), more_(false) {}
585  bool Dispatch(SandeshConnection * sconn = NULL);
586  void set_more(const bool val) { more_=val; }
587 
588  private:
589  bool more_;
590 };
591 
592 class SandeshAlarm : public SandeshUVE {
593 protected:
594  SandeshAlarm(const std::string& name, uint32_t seqno) :
595  SandeshUVE(name, seqno, SandeshType::ALARM) {}
596 };
597 
598 template<>
600  template <typename QueueT>
601  void operator()(QueueT &q, bool delete_entry) {
602  SandeshElement element;
603  while (q.try_pop(element)) {
604  Sandesh *sandesh(element.snh_);
605  sandesh->Release();
606  }
607  }
608 };
609 
610 template<>
612  template <typename QueueT>
613  void operator()(QueueT &q, bool delete_entry) {
614  SandeshRequest *rsandesh;
615  while (q.try_pop(rsandesh)) {
616  rsandesh->Release();
617  }
618  }
619 };
620 
621 template<typename T> Sandesh* createT() { return new T; }
622 
624 public:
625  static Sandesh* CreateInstance(std::string const& s) {
626  map_type::iterator it = GetMap()->find(s);
627  if (it == GetMap()->end()) {
628  return 0;
629  }
630  return it->second();
631  }
632 
633  typedef std::map<std::string, Sandesh*(*)()> map_type;
634 
635  static void Update(map_type &map) {
636  map_type::const_iterator m_iter = map.begin();
637  for (; m_iter != map.end(); m_iter++) {
638  map_type::iterator b_iter = GetMap()->find((*m_iter).first);
639  if (b_iter != End()) {
640  GetMap()->erase(b_iter);
641  }
642  GetMap()->insert(*m_iter);
643  }
644  }
645  static map_type::const_iterator Begin() { return GetMap()->begin(); }
646  static map_type::const_iterator End() { return GetMap()->end(); }
647 
648 protected:
649  static map_type* GetMap() {
650  static map_type map_;
651  return &map_;
652  }
653 };
654 
655 template<typename T>
657  SandeshDerivedRegister(std::string const& s) :
658  name_(s) {
659  GetMap()->insert(std::make_pair(s, &createT<T>));
660  }
662  map_type::iterator iter = GetMap()->find(name_);
663  GetMap()->erase(iter);
664  }
665 private:
666  std::string name_;
667 };
668 
669 #define SANDESH_REGISTER_DEC_TYPE(NAME) \
670  static SandeshDerivedRegister<NAME> reg
671 
672 #define SANDESH_REGISTER_DEF_TYPE(NAME) \
673  SandeshDerivedRegister<NAME> NAME::reg(#NAME)
674 
675 bool DoDropSandeshMessage(const SandeshHeader &header,
676  SandeshLevel::type drop_level);
677 
678 log4cplus::LogLevel SandeshLevelTolog4Level(
679  SandeshLevel::type slevel);
680 
681 template <typename T>
683  static bool get(const T& s) { return false; }
684 };
685 template <typename T>
687  static std::string get(const T& s) { return std::string(""); }
688 };
689 #endif // __SANDESH_H__
SandeshAlarm(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:594
static void Update(map_type &map)
Definition: cpp/sandesh.h:635
static map_type::const_iterator End()
Definition: cpp/sandesh.h:646
static map_type * GetMap()
Definition: cpp/sandesh.h:649
static map_type::const_iterator Begin()
Definition: cpp/sandesh.h:645
static Sandesh * CreateInstance(std::string const &s)
Definition: cpp/sandesh.h:625
std::map< std::string, Sandesh *(*)()> map_type
Definition: cpp/sandesh.h:633
virtual void Process(SandeshContext *context)=0
SandeshBuffer(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:526
SandeshBuffer & operator=(const SandeshBuffer &r)
Definition: cpp/sandesh.h:514
virtual ~SandeshContext()
Definition: cpp/sandesh.h:115
SandeshFlowSession(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:567
SandeshFlow(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:561
SandeshObject(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:555
virtual bool RequestFromHttp(const std::string &ctx, const std::string &snh_query)=0
boost::shared_ptr< const SandeshRequest > SharedPtr() const
Definition: cpp/sandesh.h:489
friend void boost::checked_delete(T *x)
void Release()
Definition: sandesh.cc:570
virtual void HandleRequest() const =0
boost::shared_ptr< SandeshRequest > self_
Definition: cpp/sandesh.h:497
SandeshRequest(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:492
bool Enqueue(SandeshRxQueue *queue)
Definition: sandesh.cc:803
virtual void Response()
Definition: cpp/sandesh.h:504
virtual void set_more(const bool val)=0
virtual const bool get_more() const =0
SandeshResponse(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:506
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:737
SandeshSystem(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:549
const uint32_t seqnum()
Definition: cpp/sandesh.h:532
SandeshTrace(const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:537
void set_seqnum(const uint32_t seqnum)
Definition: cpp/sandesh.h:540
uint32_t xseqnum_
Definition: cpp/sandesh.h:543
virtual ~SandeshTrace()
Definition: cpp/sandesh.h:535
virtual void SendTrace(const std::string &context, bool more)=0
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:750
void set_more(bool more)
Definition: cpp/sandesh.h:541
const bool get_more() const
Definition: cpp/sandesh.h:534
virtual std::string DataLog(void)
Definition: cpp/sandesh.h:580
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:760
void set_more(const bool val)
Definition: cpp/sandesh.h:586
const bool get_more() const
Definition: cpp/sandesh.h:573
SandeshUVE(const std::string &name, uint32_t seqno, SandeshType::type t=SandeshType::UVE)
Definition: cpp/sandesh.h:582
virtual ~Sandesh()
Definition: cpp/sandesh.h:370
static bool ConnectToCollector(const std::string &collector_ip, int collector_port, bool periodicuve=false)
Definition: sandesh.cc:213
time_t timestamp_
Definition: cpp/sandesh.h:441
static void SetLoggingLevel(std::string level)
Definition: sandesh.cc:391
static bool IsSendingSystemLogsDisabled()
Definition: sandesh.cc:529
static void set_response_callback(SandeshCallback response_cb)
Definition: cpp/sandesh.h:306
void set_hints(int32_t hints)
Definition: cpp/sandesh.h:317
static log4cplus::Logger & logger()
Definition: cpp/sandesh.h:325
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
Definition: sandesh.cc:891
static log4cplus::Logger logger_
Definition: cpp/sandesh.h:430
static void set_module_context(const std::string &module_name, SandeshContext *context)
Definition: sandesh.cc:958
static bool disable_sending_all_
Definition: cpp/sandesh.h:435
static bool SendReady(SandeshConnection *sconn=NULL)
boost::asio::ip::tcp::endpoint Endpoint
Definition: cpp/sandesh.h:139
virtual int32_t Write(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > oprot) const =0
static SandeshLevel::type SendingLevel()
Definition: sandesh.cc:976
static bool disable_sending_object_logs_
Definition: cpp/sandesh.h:436
void set_scope(std::string scope)
Definition: cpp/sandesh.h:314
static void InitClient(EventManager *evm, Endpoint server, const SandeshConfig &config, bool periodicuve)
Definition: sandesh.cc:124
static SandeshLevel::type LoggingLevel()
Definition: cpp/sandesh.h:223
void set_name(const char *name)
Definition: cpp/sandesh.h:346
SandeshLevel::type level_
Definition: cpp/sandesh.h:445
static SandeshRole::type role()
Definition: cpp/sandesh.h:298
static bool is_send_slo_to_logger_enabled()
Definition: cpp/sandesh.h:340
static bool slo_to_logger_
Definition: cpp/sandesh.h:451
static SandeshLevel::type logging_ut_level_
Definition: cpp/sandesh.h:422
static int http_port()
Definition: cpp/sandesh.h:299
static bool enable_session_syslog_
Definition: cpp/sandesh.h:420
static std::unique_ptr< SandeshRxQueue > recv_queue_
Definition: cpp/sandesh.h:414
virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:572
static bool enable_flow_log_
Definition: cpp/sandesh.h:419
static log4cplus::Logger & sampled_logger()
Definition: cpp/sandesh.h:327
boost::tuple< size_t, SandeshLevel::type, bool, bool > QueueWaterMarkInfo
Definition: cpp/sandesh.h:149
std::string name_
Definition: cpp/sandesh.h:447
static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:643
static EventManager * event_manager_
Definition: cpp/sandesh.h:426
static void DisableSendingFlows(bool disable)
Definition: sandesh.cc:517
virtual const int32_t versionsig() const =0
SandeshLevel::type level() const
Definition: cpp/sandesh.h:320
static std::mutex stats_mutex_
Definition: cpp/sandesh.h:429
static void ReConfigCollectors(const std::vector< std::string > &collector_list)
Definition: sandesh.cc:231
static SandeshConfig & config()
Definition: cpp/sandesh.h:309
static void UpdateRxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshRxDropReason::type dreason)
Definition: sandesh.cc:879
static SandeshLevel::type LoggingUtLevel()
Definition: cpp/sandesh.h:224
static std::string LoggingCategory()
Definition: cpp/sandesh.h:234
static void set_instance_id(std::string &instance_id)
Definition: cpp/sandesh.h:294
static void set_send_to_collector_flags(const std::vector< std::string > &sampled_destination, const std::vector< std::string > &slo_destination)
Definition: sandesh.cc:1057
std::string context() const
Definition: cpp/sandesh.h:313
static void GetMsgStats(std::vector< SandeshMessageTypeStats > *mtype_stats, SandeshMessageStats *magg_stats)
Definition: sandesh.cc:897
void set_type(SandeshType::type type)
Definition: cpp/sandesh.h:345
static void set_client_context(SandeshContext *context)
Definition: cpp/sandesh.h:302
static bool IsTracePrintEnabled()
Definition: cpp/sandesh.h:231
time_t timestamp() const
Definition: cpp/sandesh.h:311
static bool IsLevelCategoryLoggingAllowed(SandeshType::type type, SandeshLevel::type level, const std::string &category)
Definition: sandesh.cc:822
virtual void Release()
Definition: cpp/sandesh.h:268
virtual void Log() const =0
static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:885
static bool IsLocalLoggingEnabled()
Definition: cpp/sandesh.h:225
static void SetLocalLogging(bool enable)
Definition: sandesh.cc:448
static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:873
const uint32_t seqnum_
Definition: cpp/sandesh.h:439
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())
Definition: sandesh.cc:272
static bool IsSendQueueEnabled()
Definition: cpp/sandesh.h:241
static ModuleContextMap module_context_
Definition: cpp/sandesh.h:417
static bool connect_to_collector_
Definition: cpp/sandesh.h:425
bool Enqueue(SandeshQueue *queue)
Definition: sandesh.cc:545
static std::string node_type_
Definition: cpp/sandesh.h:411
static void SetSendQueue(bool enable)
Definition: sandesh.cc:911
static bool IsFlowLoggingEnabled()
Definition: cpp/sandesh.h:227
static bool IsFlowCollectionDisabled()
Definition: cpp/sandesh.h:201
std::map< std::string, std::map< std::string, std::string > > DerivedStats
Definition: cpp/sandesh.h:150
std::string context_
Definition: cpp/sandesh.h:440
friend class SandeshTracePerfTest
Definition: cpp/sandesh.h:388
static bool disable_sending_flows_
Definition: cpp/sandesh.h:437
static SandeshClient * client()
Definition: cpp/sandesh.h:308
static SandeshContext * client_context_
Definition: cpp/sandesh.h:416
static std::string source()
Definition: cpp/sandesh.h:291
virtual size_t GetSize() const =0
static void SetLoggingCategory(std::string category)
Definition: sandesh.cc:439
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)
Definition: sandesh.cc:1004
static const char * SandeshRoleToString(SandeshRole::type role)
Definition: sandesh.cc:101
virtual const char * Name() const
Definition: cpp/sandesh.h:279
static SandeshConfig config_
Definition: cpp/sandesh.h:434
static bool IsSendingObjectLogsDisabled()
Definition: sandesh.cc:513
int32_t hints() const
Definition: cpp/sandesh.h:318
static int recv_task_id_
Definition: cpp/sandesh.h:415
static bool IsSendingAllMessagesDisabled()
Definition: sandesh.cc:501
std::string category_
Definition: cpp/sandesh.h:446
static int http_port_
Definition: cpp/sandesh.h:413
virtual const uint32_t seqnum()
Definition: cpp/sandesh.h:277
virtual int32_t ReadBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:591
void set_level(SandeshLevel::type level)
Definition: cpp/sandesh.h:319
static const char * LevelToString(SandeshLevel::type level)
Definition: sandesh.cc:853
static bool send_queue_enabled_
Definition: cpp/sandesh.h:427
static bool is_send_slo_to_collector_enabled()
Definition: cpp/sandesh.h:338
static void set_send_rate_limit(int rate_limit)
Definition: sandesh.cc:533
static uint32_t get_send_rate_limit()
Definition: sandesh.cc:541
static void DisableFlowCollection(bool disable)
Definition: sandesh.cc:485
std::string scope_
Definition: cpp/sandesh.h:442
WorkQueue< SandeshRequest * > SandeshRxQueue
Definition: cpp/sandesh.h:134
static log4cplus::Logger slo_logger_
Definition: cpp/sandesh.h:431
static bool HandleTest(SandeshLevel::type level, const std::string &category)
Definition: sandesh.cc:967
WorkQueue< SandeshElement > SandeshQueue
Definition: cpp/sandesh.h:135
static SandeshContext * client_context()
Definition: cpp/sandesh.h:301
std::string category() const
Definition: cpp/sandesh.h:322
static bool ProcessRecv(SandeshRequest *)
Definition: sandesh.cc:564
static bool slo_to_collector_
Definition: cpp/sandesh.h:449
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())
Definition: sandesh.cc:293
static void RecordPort(const std::string &name, const std::string &module, unsigned short port)
Definition: sandesh.cc:192
static bool sampled_to_logger_
Definition: cpp/sandesh.h:452
SandeshType::type type() const
Definition: cpp/sandesh.h:316
static void SetDscpValue(uint8_t value)
Definition: sandesh.cc:335
static SandeshMessageStatistics msg_stats_
Definition: cpp/sandesh.h:428
static bool IsUnitTest()
Definition: cpp/sandesh.h:377
static bool IsLoggingDroppedAllowed(SandeshType::type)
Definition: sandesh.cc:845
static bool is_send_sampled_to_collector_enabled()
Definition: cpp/sandesh.h:339
static void Uninit()
Definition: sandesh.cc:342
std::string scope() const
Definition: cpp/sandesh.h:315
static std::string module()
Definition: cpp/sandesh.h:293
bool IsLoggingAllowed() const
Definition: sandesh.cc:836
void set_context(std::string context)
Definition: cpp/sandesh.h:312
static void SetSessionSyslogging(bool enable_session_syslog)
Definition: sandesh.cc:475
boost::function< void(Sandesh *)> SandeshCallback
Definition: cpp/sandesh.h:140
static void DisableSendingAllMessages(bool disable)
Definition: sandesh.cc:493
static SandeshRxQueue * recv_queue()
Definition: cpp/sandesh.h:300
void set_category(std::string category)
Definition: cpp/sandesh.h:321
static SandeshRole::type role_
Definition: cpp/sandesh.h:408
static SandeshContext * module_context(const std::string &module_name)
Definition: sandesh.cc:950
static void set_source(std::string &source)
Definition: cpp/sandesh.h:290
static std::string instance_id_
Definition: cpp/sandesh.h:412
static SandeshCallback response_callback_
Definition: cpp/sandesh.h:380
static std::atomic< uint32_t > sandesh_send_ratelimit_
Definition: cpp/sandesh.h:448
static int32_t ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:685
static SandeshLevel::type logging_level_
Definition: cpp/sandesh.h:421
static SandeshClient * client_
Definition: cpp/sandesh.h:381
static log4cplus::Logger & slo_logger()
Definition: cpp/sandesh.h:326
static bool enable_trace_print_
Definition: cpp/sandesh.h:424
void set_timestamp(time_t timestamp)
Definition: cpp/sandesh.h:344
virtual int32_t WriteBinaryToFile(const std::string &path, int *error)
Definition: sandesh.cc:609
virtual int32_t ReadBinaryFromFile(const std::string &path, int *error)
Definition: sandesh.cc:626
int32_t hints_
Definition: cpp/sandesh.h:444
static void SetFlowLogging(bool enable)
Definition: sandesh.cc:466
static std::string instance_id()
Definition: cpp/sandesh.h:295
SandeshType::type type_
Definition: cpp/sandesh.h:443
static bool IsSendingFlowsDisabled()
Definition: sandesh.cc:525
static void SetTracePrint(bool enable)
Definition: sandesh.cc:457
static void InitReceive(int recv_task_inst=-1)
Definition: sandesh.cc:116
static bool IsConnectToCollectorEnabled()
Definition: cpp/sandesh.h:244
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())
Definition: sandesh.cc:145
std::map< std::string, SandeshContext * > ModuleContextMap
Definition: cpp/sandesh.h:390
virtual bool SendEnqueue()
Definition: sandesh.cc:703
static std::string node_type()
Definition: cpp/sandesh.h:297
static std::string source_
Definition: cpp/sandesh.h:410
static std::string logging_category_
Definition: cpp/sandesh.h:423
virtual void ForcedLog() const =0
static bool IsLevelUT(SandeshLevel::type level)
Definition: sandesh.cc:817
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())
Definition: sandesh.cc:311
static bool enable_local_log_
Definition: cpp/sandesh.h:418
static bool disable_flow_collection_
Definition: cpp/sandesh.h:433
static bool is_send_sampled_to_logger_enabled()
Definition: cpp/sandesh.h:341
virtual int32_t Read(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > iprot)=0
static bool IsSloSyslogEnabled()
Definition: cpp/sandesh.h:228
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)
Definition: sandesh.cc:370
static log4cplus::Logger sampled_logger_
Definition: cpp/sandesh.h:432
Sandesh(SandeshType::type type, const std::string &name, uint32_t seqno, bool no_time_stamp)
Definition: cpp/sandesh.h:359
Sandesh(SandeshType::type type, const std::string &name, uint32_t seqno)
Definition: cpp/sandesh.h:348
static std::string module_
Definition: cpp/sandesh.h:409
static void DisableSendingObjectLogs(bool disable)
Definition: sandesh.cc:505
static void set_node_type(std::string &node_type)
Definition: cpp/sandesh.h:296
virtual std::string ToString() const =0
static void set_module(std::string &module)
Definition: cpp/sandesh.h:292
WorkQueue< boost::shared_ptr< contrail::sandesh::transport::TMemoryBuffer > > SandeshBufferQueue
Definition: cpp/sandesh.h:138
virtual std::string ModuleName() const =0
virtual bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:728
static SandeshLevel::type StringToLevel(std::string level)
Definition: sandesh.cc:862
static bool sampled_to_collector_
Definition: cpp/sandesh.h:450
static SandeshCallback response_callback()
Definition: cpp/sandesh.h:307
size_t AtomicDecrementQueueCount(QueueEntryT *entry)
Definition: queue_task.h:435
size_t AtomicIncrementQueueCount(QueueEntryT *entry)
Definition: queue_task.h:431
static EventManager evm
bool DoDropSandeshMessage(const SandeshHeader &header, SandeshLevel::type drop_level)
Definition: sandesh.cc:928
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
Definition: sandesh.cc:396
Sandesh * createT()
Definition: cpp/sandesh.h:621
@ INVALID
Definition: globals.h:147
uint8_t type
Definition: load_balance.h:2
SandeshDerivedRegister(std::string const &s)
Definition: cpp/sandesh.h:657
size_t GetSize() const
Definition: cpp/sandesh.h:461
Sandesh * snh_
Definition: cpp/sandesh.h:456
SandeshElement(Sandesh *snh)
Definition: cpp/sandesh.h:458
static bool get(const T &s)
Definition: cpp/sandesh.h:683
static std::string get(const T &s)
Definition: cpp/sandesh.h:687
void operator()(QueueT &q, bool delete_entry)
Definition: cpp/sandesh.h:601
void operator()(QueueT &q, bool delete_entry)
Definition: cpp/sandesh.h:613
static uint64_t UTCTimestampUsec()
Definition: time_util.h:13