OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
p/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 <map>
83 
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>
88 #include <base/contrail_ports.h>
89 #include <base/logging.h>
90 #include <base/queue_task.h>
91 #include <base/string_util.h>
92 #include <base/time_util.h>
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>
99 
100 // Forward declaration
101 class EventManager;
102 class SandeshClient;
103 class SandeshSession;
104 
105 // Sandesh Context
107  // Abstract base class for users of sandesh library to
108  // pass in information to used when handling sandesh
109  // request and response
110 protected:
112 public:
113  virtual ~SandeshContext() { }
114 };
115 
116 //
117 // Sandesh
118 //
120 class SandeshMessageTypeStats;
121 class SandeshMessageStats;
122 class SandeshMessageTypeBasicStats;
123 class SandeshMessageBasicStats;
124 class SandeshConnection;
125 class SandeshRequest;
126 
127 
128 struct SandeshElement;
129 
130 class Sandesh {
131 public:
134  typedef WorkQueue<
135  boost::shared_ptr<contrail::sandesh::transport::TMemoryBuffer> >
137  typedef boost::asio::ip::tcp::endpoint Endpoint;
138  typedef boost::function<void (Sandesh *)> SandeshCallback;
139  struct SandeshRole {
140  enum type {
145  };
146  };
147  typedef boost::tuple<size_t, SandeshLevel::type, bool, bool> QueueWaterMarkInfo;
148  typedef std::map<std::string, std::map<std::string,std::string> > DerivedStats;
149 
150  // Initialization APIs
151  static bool InitGenerator(const std::string &module,
152  const std::string &source,
153  const std::string &node_type,
154  const std::string &instance_id,
155  EventManager *evm,
156  unsigned short http_port,
157  const std::vector<std::string> &collectors,
159  DerivedStats ds = DerivedStats(),
160  const SandeshConfig &config = SandeshConfig());
161  static bool InitGenerator(const std::string &module,
162  const std::string &source,
163  const std::string &node_type,
164  const std::string &instance_id,
165  EventManager *evm,
166  unsigned short http_port,
168  DerivedStats ds = DerivedStats(),
169  const SandeshConfig &config = SandeshConfig());
170  static void RecordPort(const std::string& name, const std::string& module,
171  unsigned short port);
172  // Collector
173  static bool InitCollector(const std::string &module,
174  const std::string &source,
175  const std::string &node_type,
176  const std::string &instance_id,
177  EventManager *evm,
178  const std::string &collector_ip, int collector_port,
179  unsigned short http_port,
181  const SandeshConfig &config = SandeshConfig());
182  // Test
183  static bool InitGeneratorTest(const std::string &module,
184  const std::string &source,
185  const std::string &node_type,
186  const std::string &instance_id,
187  EventManager *evm,
188  unsigned short http_port,
190  const SandeshConfig &config = SandeshConfig());
191  static bool ConnectToCollector(const std::string &collector_ip,
192  int collector_port, bool periodicuve = false);
193  static void ReConfigCollectors(const std::vector<std::string>& collector_list);
194  static void Uninit();
195  static void SetDscpValue(uint8_t value);
196 
197  // Disable flow collection
198  static void DisableFlowCollection(bool disable);
200 
201  // Flags to control sending of sandesh from generators
202  static void DisableSendingAllMessages(bool disable);
203  static bool IsSendingAllMessagesDisabled();
204  static void DisableSendingObjectLogs(bool disable);
205  static bool IsSendingObjectLogsDisabled();
206  static bool IsSendingSystemLogsDisabled();
207  static void DisableSendingFlows(bool disable);
208  static bool IsSendingFlowsDisabled();
209  static void set_send_rate_limit(int rate_limit);
210  static uint32_t get_send_rate_limit();
211 
212  // Logging and category APIs
213  static void SetLoggingParams(bool enable_local_log, std::string category,
214  std::string level, bool enable_trace_print = false,
215  bool enable_flow_log = false, bool enable_session_syslog = false);
216  static void SetLoggingParams(bool enable_local_log, std::string category,
217  SandeshLevel::type level, bool enable_trace_print = false,
218  bool enable_flow_log = false);
219  static void SetLoggingLevel(std::string level);
223  static bool IsLocalLoggingEnabled() { return enable_local_log_; }
224  static void SetLocalLogging(bool enable);
225  static bool IsFlowLoggingEnabled() { return enable_flow_log_; }
226  static bool IsSloSyslogEnabled() { return enable_session_syslog_; }
227  static void SetFlowLogging(bool enable);
228  static void SetSessionSyslogging(bool enable_session_syslog);
229  static bool IsTracePrintEnabled() { return enable_trace_print_; }
230  static void SetTracePrint(bool enable);
231  static void SetLoggingCategory(std::string category);
232  static std::string LoggingCategory() { return logging_category_; }
233 
234  //GetSize method to report the size
235  virtual size_t GetSize() const = 0;
236 
237  // Send queue processing
238  static void SetSendQueue(bool enable);
239  static inline bool IsSendQueueEnabled() {
240  return send_queue_enabled_;
241  }
242  static inline bool IsConnectToCollectorEnabled() {
243  return connect_to_collector_;
244  }
246 
247  static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len,
248  int *error, SandeshContext *client_context);
249  static int32_t ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len,
250  int *error, SandeshContext *client_context);
251  static bool SendReady(SandeshConnection * sconn = NULL);
252  static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes);
253  static void UpdateRxMsgFailStats(const std::string &msg_name,
254  uint64_t bytes, SandeshRxDropReason::type dreason);
255  static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes);
256  static void UpdateTxMsgFailStats(const std::string &msg_name,
257  uint64_t bytes, SandeshTxDropReason::type dreason);
258  static void GetMsgStats(
259  std::vector<SandeshMessageTypeStats> *mtype_stats,
260  SandeshMessageStats *magg_stats);
261  static void GetMsgStats(
262  boost::ptr_map<std::string, SandeshMessageTypeStats> *mtype_stats,
263  SandeshMessageStats *magg_stats);
264  static const char * SandeshRoleToString(SandeshRole::type role);
265 
266  virtual void Release() { delete this; }
267  virtual void Log() const = 0;
268  virtual void ForcedLog() const = 0;
269  virtual std::string ToString() const = 0;
270  virtual std::string ModuleName() 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;
275  virtual const uint32_t seqnum() { return seqnum_; }
276  virtual const int32_t versionsig() const = 0;
277  virtual const char *Name() const { return name_.c_str(); }
278  bool Enqueue(SandeshQueue* queue);
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);
281  virtual int32_t WriteBinaryToFile(const std::string& path, int *error);
282  virtual int32_t ReadBinaryFromFile(const std::string& path, int *error);
283 
284  bool IsLoggingAllowed() const;
286 
287  // Accessors
288  static void set_source(std::string &source) { source_ = source; }
289  static std::string source() { return source_; }
290  static void set_module(std::string &module) { module_ = module; }
291  static std::string module() { return module_; }
292  static void set_instance_id(std::string &instance_id) { instance_id_ = instance_id; }
293  static std::string instance_id() { return instance_id_; }
294  static void set_node_type(std::string &node_type) { node_type_ = node_type; }
295  static std::string node_type() { return node_type_; }
296  static SandeshRole::type role() { return role_; }
297  static int http_port() { return http_port_; }
298  static SandeshRxQueue* recv_queue() { return recv_queue_.get(); }
301  static SandeshContext *module_context(const std::string &module_name);
302  static void set_module_context(const std::string &module_name,
304  static void set_response_callback(SandeshCallback response_cb) { response_callback_ = response_cb; }
306  static SandeshClient* client() { return client_; }
307  static SandeshConfig& config() { return config_; }
308 
309  time_t timestamp() const { return timestamp_; }
310  void set_context(std::string context) { context_ = context; }
311  std::string context() const { return context_; }
312  void set_scope(std::string scope) { scope_ = scope; }
313  std::string scope() const { return scope_; }
314  SandeshType::type type() const { return type_; }
315  void set_hints(int32_t hints) { hints_ = hints; }
316  int32_t hints() const { return hints_; }
318  SandeshLevel::type level() const { return level_; }
319  void set_category(std::string category) { category_ = category; }
320  std::string category() const { return category_; }
321  static const char* LevelToString(SandeshLevel::type level);
322  static SandeshLevel::type StringToLevel(std::string level);
323  static log4cplus::Logger& logger() { return logger_; }
324  static log4cplus::Logger& slo_logger() { return slo_logger_; }
325  static log4cplus::Logger& sampled_logger() { return sampled_logger_; }
326  static void set_logger_appender(const std::string &file_name,
327  long max_file_size,
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);
333  static void set_send_to_collector_flags(
334  const std::vector<std::string> &sampled_destination,
335  const std::vector<std::string> &slo_destination);
340 
341 protected:
344  void set_name(const char *name) { name_ = name; }
345 
346  Sandesh(SandeshType::type type, const std::string& name, uint32_t seqno) :
347  seqnum_(seqno),
348  context_(""),
350  scope_(""),
351  type_(type),
352  hints_(0),
353  level_(SandeshLevel::INVALID),
354  category_(""),
355  name_(name) {
356  }
357  Sandesh(SandeshType::type type, const std::string& name, uint32_t seqno, bool no_time_stamp) :
358  seqnum_(seqno),
359  context_(""),
360  scope_(""),
361  type_(type),
362  hints_(0),
363  level_(SandeshLevel::INVALID),
364  category_(""),
365  name_(name) {
366  timestamp_ = no_time_stamp ? 0 : UTCTimestampUsec();
367  }
368  virtual ~Sandesh() {}
369  virtual bool Dispatch(SandeshConnection * sconn = NULL);
370  virtual bool SendEnqueue();
371 
372  static bool HandleTest(SandeshLevel::type level, const
373  std::string& category);
374 
375  static bool IsUnitTest() {
377  }
380  static bool IsLevelUT(SandeshLevel::type level);
383  const std::string& category);
384 
385 private:
386  friend class SandeshTracePerfTest;
387 
388  typedef std::map<std::string, SandeshContext *> ModuleContextMap;
389 
390  static void InitReceive(int recv_task_inst = -1);
391  static void InitClient(EventManager *evm, Endpoint server,
392  const SandeshConfig &config, bool periodicuve);
393  static bool InitClient(EventManager *evm,
394  const std::vector<std::string> &collectors,
395  const SandeshConfig &config);
396  static bool ProcessRecv(SandeshRequest *);
397  static bool Initialize(SandeshRole::type role, const std::string &module,
398  const std::string &source,
399  const std::string &node_type,
400  const std::string &instance_id,
401  EventManager *evm,
402  unsigned short http_port,
404  const SandeshConfig &config = SandeshConfig());
405 
407  static std::string module_;
408  static std::string source_;
409  static std::string node_type_;
410  static std::string instance_id_;
411  static int http_port_;
412  static std::unique_ptr<SandeshRxQueue> recv_queue_;
413  static int recv_task_id_;
416  static bool enable_local_log_; // whether to just enable local logging
417  static bool enable_flow_log_; // whether to enable flow sandesh message logging
418  static bool enable_session_syslog_; // whether to enable syslog for SLO session messages
419  static SandeshLevel::type logging_level_; // current logging level
420  static SandeshLevel::type logging_ut_level_; // ut_debug logging level
421  static std::string logging_category_; // current logging category
422  static bool enable_trace_print_; // whether to print traces locally
423  static bool connect_to_collector_; // whether to connect to collector
425  static bool send_queue_enabled_;
427  static tbb::mutex stats_mutex_;
428  static log4cplus::Logger logger_;
429  static log4cplus::Logger slo_logger_;
430  static log4cplus::Logger sampled_logger_;
431  static bool disable_flow_collection_; // disable flow collection
433  static bool disable_sending_all_;
436 
437  const uint32_t seqnum_;
438  std::string context_;
439  time_t timestamp_;
440  std::string scope_;
442  int32_t hints_;
444  std::string category_;
445  std::string name_;
446  static tbb::atomic<uint32_t> sandesh_send_ratelimit_;
447  static bool slo_to_collector_;
449  static bool slo_to_logger_;
450  static bool sampled_to_logger_;
451 };
452 
455  //Explicit constructor creating only if Sandesh is passed as arg
456  explicit SandeshElement(Sandesh *snh):snh_(snh),size_(snh->GetSize()) {
457  }
459  size_t GetSize() const {
460  return size_;
461  }
462  private:
463  size_t size_;
464 };
465 
466 template<>
468  SandeshElement *element);
469 
470 template<>
472  SandeshElement *element);
473 
474 #define SANDESH_LOG(_Level, _Msg) \
475  do { \
476  if (LoggingDisabled()) break; \
477  LOG4CPLUS_##_Level(Sandesh::logger(), _Msg); \
478  } while (0)
479 
480 class SandeshRequest : public Sandesh,
481  public boost::enable_shared_from_this<SandeshRequest> {
482 public:
483  virtual void HandleRequest() const = 0;
484  virtual bool RequestFromHttp(const std::string& ctx,
485  const std::string& snh_query) = 0;
486  void Release();
487  boost::shared_ptr<const SandeshRequest> SharedPtr() const { return shared_from_this(); }
488  bool Enqueue(SandeshRxQueue* queue);
489 protected:
490  SandeshRequest(const std::string& name, uint32_t seqno) :
491  Sandesh(SandeshType::REQUEST, name, seqno), self_(this) {}
492 
493  template <typename T>
494  friend void boost::checked_delete(T *x);
495  boost::shared_ptr<SandeshRequest> self_;
496 };
497 
498 class SandeshResponse : public Sandesh {
499 public:
500  virtual const bool get_more() const = 0;
501  virtual void set_more(const bool val) = 0;
502  virtual void Response() {}
503 protected:
504  SandeshResponse(const std::string& name, uint32_t seqno) :
505  Sandesh(SandeshType::RESPONSE, name, seqno) {}
506  bool Dispatch(SandeshConnection * sconn = NULL);
507 };
508 
509 class SandeshBuffer : public Sandesh {
510 public:
511  virtual void Process(SandeshContext *context) = 0;
513  set_context(r.context());
515  set_scope(r.scope());
516  set_hints(r.hints());
517  set_type(r.type());
518  set_level(r.level());
519  set_category(r.category());
520  set_name(r.Name());
521  return(*this);
522  }
523 protected:
524  SandeshBuffer(const std::string& name, uint32_t seqno) :
525  Sandesh(SandeshType::BUFFER, name, seqno, true) {}
526 };
527 
528 class SandeshTrace : public Sandesh {
529 public:
530  const uint32_t seqnum() { return xseqnum_; }
531  virtual void SendTrace(const std::string& context, bool more) = 0;
532  const bool get_more() const { return more_; }
533  virtual ~SandeshTrace() {}
534 protected:
535  SandeshTrace(const std::string& name, uint32_t seqno) :
536  Sandesh(SandeshType::TRACE, name, 0), xseqnum_(0), more_(true) {}
537  bool Dispatch(SandeshConnection * sconn = NULL);
538  void set_seqnum(const uint32_t seqnum) { xseqnum_= seqnum; }
539  void set_more(bool more) { more_ = more; }
540 private:
541  uint32_t xseqnum_;
542  bool more_;
543 };
544 
545 class SandeshSystem : public Sandesh {
546 protected:
547  SandeshSystem(const std::string& name, uint32_t seqno) :
548  Sandesh(SandeshType::SYSTEM, name, seqno) {}
549 };
550 
551 class SandeshObject : public Sandesh {
552 protected:
553  SandeshObject(const std::string& name, uint32_t seqno) :
554  Sandesh(SandeshType::OBJECT, name, seqno) {}
555 };
556 
557 class SandeshFlow : public Sandesh {
558 protected:
559  SandeshFlow(const std::string& name, uint32_t seqno) :
560  Sandesh(SandeshType::FLOW, name, seqno) {}
561 };
562 
563 class SandeshFlowSession : public Sandesh {
564 protected:
565  SandeshFlowSession(const std::string& name, uint32_t seqno) :
566  Sandesh(SandeshType::SESSION, name, seqno) {}
567 };
568 
569 class SandeshUVE : public Sandesh {
570 public:
571  const bool get_more() const { return more_; }
572  typedef enum {
573  ST_SYNC = 0,
576  ST_MAX = 3
577  } SendType;
578  virtual std::string DataLog(void) { return std::string(); }
579 protected:
580  SandeshUVE(const std::string& name, uint32_t seqno,
581  SandeshType::type t = SandeshType::UVE) :
582  Sandesh(t, name, seqno), more_(false) {}
583  bool Dispatch(SandeshConnection * sconn = NULL);
584  void set_more(const bool val) { more_=val; }
585 
586  private:
587  bool more_;
588 };
589 
590 class SandeshAlarm : public SandeshUVE {
591 protected:
592  SandeshAlarm(const std::string& name, uint32_t seqno) :
593  SandeshUVE(name, seqno, SandeshType::ALARM) {}
594 };
595 
596 template<>
598  template <typename QueueT>
599  void operator()(QueueT &q, bool delete_entry) {
600  SandeshElement element;
601  while (q.try_pop(element)) {
602  Sandesh *sandesh(element.snh_);
603  sandesh->Release();
604  }
605  }
606 };
607 
608 template<>
610  template <typename QueueT>
611  void operator()(QueueT &q, bool delete_entry) {
612  SandeshRequest *rsandesh;
613  while (q.try_pop(rsandesh)) {
614  rsandesh->Release();
615  }
616  }
617 };
618 
619 template<typename T> Sandesh* createT() { return new T; }
620 
622 public:
623  static Sandesh* CreateInstance(std::string const& s) {
624  map_type::iterator it = GetMap()->find(s);
625  if (it == GetMap()->end()) {
626  return 0;
627  }
628  return it->second();
629  }
630 
631  typedef std::map<std::string, Sandesh*(*)()> map_type;
632 
633  static void Update(map_type &map) {
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()) {
638  GetMap()->erase(b_iter);
639  }
640  GetMap()->insert(*m_iter);
641  }
642  }
643  static map_type::const_iterator Begin() { return GetMap()->begin(); }
644  static map_type::const_iterator End() { return GetMap()->end(); }
645 
646 protected:
647  static map_type* GetMap() {
648  static map_type map_;
649  return &map_;
650  }
651 };
652 
653 template<typename T>
655  SandeshDerivedRegister(std::string const& s) :
656  name_(s) {
657  GetMap()->insert(std::make_pair(s, &createT<T>));
658  }
660  map_type::iterator iter = GetMap()->find(name_);
661  GetMap()->erase(iter);
662  }
663 private:
664  std::string name_;
665 };
666 
667 #define SANDESH_REGISTER_DEC_TYPE(NAME) \
668  static SandeshDerivedRegister<NAME> reg
669 
670 #define SANDESH_REGISTER_DEF_TYPE(NAME) \
671  SandeshDerivedRegister<NAME> NAME::reg(#NAME)
672 
673 bool DoDropSandeshMessage(const SandeshHeader &header,
674  SandeshLevel::type drop_level);
675 
676 log4cplus::LogLevel SandeshLevelTolog4Level(
677  SandeshLevel::type slevel);
678 
679 template <typename T>
681  static bool get(const T& s) { return false; }
682 };
683 template <typename T>
685  static std::string get(const T& s) { return std::string(""); }
686 };
687 #endif // __SANDESH_H__
std::string name_
Definition: p/sandesh.h:445
SandeshAlarm(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:592
SandeshFlow(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:559
SandeshTrace(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:535
SandeshLevel::type level() const
Definition: p/sandesh.h:318
boost::asio::ip::tcp::endpoint Endpoint
Definition: p/sandesh.h:137
log4cplus::LogLevel SandeshLevelTolog4Level(SandeshLevel::type slevel)
Definition: sandesh.cc:395
SandeshLevel::type level_
Definition: p/sandesh.h:443
static void InitClient(EventManager *evm, Endpoint server, const SandeshConfig &config, bool periodicuve)
Definition: sandesh.cc:123
static bool IsTracePrintEnabled()
Definition: p/sandesh.h:229
size_t GetSize() const
Definition: p/sandesh.h:459
static SandeshContext * module_context(const std::string &module_name)
Definition: sandesh.cc:949
static bool disable_sending_object_logs_
Definition: p/sandesh.h:434
static std::string instance_id_
Definition: p/sandesh.h:410
virtual void SendTrace(const std::string &context, bool more)=0
SandeshUVE(const std::string &name, uint32_t seqno, SandeshType::type t=SandeshType::UVE)
Definition: p/sandesh.h:580
static bool sampled_to_collector_
Definition: p/sandesh.h:448
static map_type::const_iterator Begin()
Definition: p/sandesh.h:643
virtual ~SandeshTrace()
Definition: p/sandesh.h:533
static SandeshRole::type role_
Definition: p/sandesh.h:406
static SandeshLevel::type StringToLevel(std::string level)
Definition: sandesh.cc:861
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:749
static void InitReceive(int recv_task_inst=-1)
Definition: sandesh.cc:115
std::string scope() const
Definition: p/sandesh.h:313
static SandeshLevel::type SendingLevel()
Definition: sandesh.cc:975
WorkQueue< SandeshRequest * > SandeshRxQueue
Definition: p/sandesh.h:132
virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:571
virtual void HandleRequest() const =0
SandeshFlowSession(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:565
static void ReConfigCollectors(const std::vector< std::string > &collector_list)
Definition: sandesh.cc:230
static Sandesh * CreateInstance(std::string const &s)
Definition: p/sandesh.h:623
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)
Definition: sandesh.cc:369
const bool get_more() const
Definition: p/sandesh.h:571
virtual std::string ModuleName() const =0
const uint32_t seqnum()
Definition: p/sandesh.h:530
static void set_response_callback(SandeshCallback response_cb)
Definition: p/sandesh.h:304
static bool HandleTest(SandeshLevel::type level, const std::string &category)
Definition: sandesh.cc:966
virtual size_t GetSize() const =0
static bool is_send_sampled_to_logger_enabled()
Definition: p/sandesh.h:339
static bool IsUnitTest()
Definition: p/sandesh.h:375
static void set_instance_id(std::string &instance_id)
Definition: p/sandesh.h:292
static void SetSendQueue(bool enable)
Definition: sandesh.cc:910
SandeshRequest(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:490
static void set_send_rate_limit(int rate_limit)
Definition: sandesh.cc:532
static bool enable_trace_print_
Definition: p/sandesh.h:422
Sandesh(SandeshType::type type, const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:346
static std::unique_ptr< SandeshRxQueue > recv_queue_
Definition: p/sandesh.h:412
virtual void Log() const =0
std::map< std::string, SandeshContext * > ModuleContextMap
Definition: p/sandesh.h:388
virtual int32_t ReadBinaryFromFile(const std::string &path, int *error)
Definition: sandesh.cc:625
Sandesh * snh_
Definition: p/sandesh.h:454
static const char * SandeshRoleToString(SandeshRole::type role)
Definition: sandesh.cc:100
static SandeshLevel::type LoggingLevel()
Definition: p/sandesh.h:221
static void SetDscpValue(uint8_t value)
Definition: sandesh.cc:334
virtual const char * Name() const
Definition: p/sandesh.h:277
SandeshObject(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:553
static log4cplus::Logger sampled_logger_
Definition: p/sandesh.h:430
static log4cplus::Logger & sampled_logger()
Definition: p/sandesh.h:325
std::map< std::string, std::map< std::string, std::string > > DerivedStats
Definition: p/sandesh.h:148
static bool is_send_slo_to_collector_enabled()
Definition: p/sandesh.h:336
static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:872
static void SetLoggingCategory(std::string category)
Definition: sandesh.cc:438
bool more_
Definition: p/sandesh.h:587
static SandeshCallback response_callback()
Definition: p/sandesh.h:305
boost::shared_ptr< const SandeshRequest > SharedPtr() const
Definition: p/sandesh.h:487
static bool ProcessRecv(SandeshRequest *)
Definition: sandesh.cc:563
static bool ConnectToCollector(const std::string &collector_ip, int collector_port, bool periodicuve=false)
Definition: sandesh.cc:212
static int http_port_
Definition: p/sandesh.h:411
static void DisableSendingObjectLogs(bool disable)
Definition: sandesh.cc:504
static tbb::mutex stats_mutex_
Definition: p/sandesh.h:427
static void UpdateRxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshRxDropReason::type dreason)
Definition: sandesh.cc:878
static log4cplus::Logger & slo_logger()
Definition: p/sandesh.h:324
static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:884
static std::string node_type()
Definition: p/sandesh.h:295
void set_category(std::string category)
Definition: p/sandesh.h:319
boost::function< void(Sandesh *)> SandeshCallback
Definition: p/sandesh.h:138
static SandeshLevel::type logging_ut_level_
Definition: p/sandesh.h:420
SandeshDerivedRegister(std::string const &s)
Definition: p/sandesh.h:655
virtual void Response()
Definition: p/sandesh.h:502
bool Enqueue(SandeshRxQueue *queue)
Definition: sandesh.cc:802
static void SetLocalLogging(bool enable)
Definition: sandesh.cc:447
static tbb::atomic< uint32_t > sandesh_send_ratelimit_
Definition: p/sandesh.h:446
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:292
size_t size_
Definition: p/sandesh.h:463
uint32_t xseqnum_
Definition: p/sandesh.h:541
static bool IsFlowLoggingEnabled()
Definition: p/sandesh.h:225
static bool disable_sending_flows_
Definition: p/sandesh.h:435
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
Definition: sandesh.cc:890
uint8_t type
Definition: load_balance.h:109
static bool IsSendingObjectLogsDisabled()
Definition: sandesh.cc:512
static bool disable_flow_collection_
Definition: p/sandesh.h:431
void set_seqnum(const uint32_t seqnum)
Definition: p/sandesh.h:538
static const char * LevelToString(SandeshLevel::type level)
Definition: sandesh.cc:852
std::string category_
Definition: p/sandesh.h:444
static void SetSessionSyslogging(bool enable_session_syslog)
Definition: sandesh.cc:474
static void SetLoggingLevel(std::string level)
Definition: sandesh.cc:390
static std::string node_type_
Definition: p/sandesh.h:409
static SandeshRole::type role()
Definition: p/sandesh.h:296
static std::string module()
Definition: p/sandesh.h:291
virtual int32_t Read(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > iprot)=0
static SandeshLevel::type logging_level_
Definition: p/sandesh.h:419
void set_level(SandeshLevel::type level)
Definition: p/sandesh.h:317
SandeshType::type type() const
Definition: p/sandesh.h:314
std::map< std::string, Sandesh *(*)()> map_type
Definition: p/sandesh.h:631
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:736
static bool enable_flow_log_
Definition: p/sandesh.h:417
std::string category() const
Definition: p/sandesh.h:320
static std::string module_
Definition: p/sandesh.h:407
SandeshResponse(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:504
static bool enable_session_syslog_
Definition: p/sandesh.h:418
std::string context() const
Definition: p/sandesh.h:311
static bool send_queue_enabled_
Definition: p/sandesh.h:425
virtual std::string DataLog(void)
Definition: p/sandesh.h:578
static log4cplus::Logger slo_logger_
Definition: p/sandesh.h:429
static bool IsFlowCollectionDisabled()
Definition: p/sandesh.h:199
bool IsLoggingAllowed() const
Definition: sandesh.cc:835
static map_type::const_iterator End()
Definition: p/sandesh.h:644
Sandesh * createT()
Definition: p/sandesh.h:619
bool DoDropSandeshMessage(const SandeshHeader &header, const SandeshLevel::type drop_level)
Definition: sandesh.cc:927
static SandeshClient * client_
Definition: p/sandesh.h:379
static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:642
static SandeshConfig config_
Definition: p/sandesh.h:432
static int http_port()
Definition: p/sandesh.h:297
static SandeshClient * client()
Definition: p/sandesh.h:306
virtual bool SendEnqueue()
Definition: sandesh.cc:702
virtual const int32_t versionsig() const =0
static std::string logging_category_
Definition: p/sandesh.h:421
virtual void Release()
Definition: p/sandesh.h:266
void set_name(const char *name)
Definition: p/sandesh.h:344
void operator()(QueueT &q, bool delete_entry)
Definition: p/sandesh.h:611
static log4cplus::Logger logger_
Definition: p/sandesh.h:428
time_t timestamp() const
Definition: p/sandesh.h:309
static int32_t ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:684
static bool IsSendingSystemLogsDisabled()
Definition: sandesh.cc:528
void set_more(bool more)
Definition: p/sandesh.h:539
void set_scope(std::string scope)
Definition: p/sandesh.h:312
static void set_module_context(const std::string &module_name, SandeshContext *context)
Definition: sandesh.cc:957
static bool connect_to_collector_
Definition: p/sandesh.h:423
static bool is_send_slo_to_logger_enabled()
Definition: p/sandesh.h:338
const bool get_more() const
Definition: p/sandesh.h:532
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:310
static void set_source(std::string &source)
Definition: p/sandesh.h:288
virtual const bool get_more() const =0
virtual const uint32_t seqnum()
Definition: p/sandesh.h:275
void set_hints(int32_t hints)
Definition: p/sandesh.h:315
time_t timestamp_
Definition: p/sandesh.h:439
const uint32_t seqnum_
Definition: p/sandesh.h:437
size_t AtomicIncrementQueueCount(QueueEntryT *entry)
Definition: queue_task.h:431
static bool IsSendingAllMessagesDisabled()
Definition: sandesh.cc:500
void Release()
Definition: sandesh.cc:569
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:271
SandeshType::type type_
Definition: p/sandesh.h:441
SandeshElement(Sandesh *snh)
Definition: p/sandesh.h:456
size_t AtomicDecrementQueueCount(QueueEntryT *entry)
Definition: queue_task.h:435
WorkQueue< boost::shared_ptr< contrail::sandesh::transport::TMemoryBuffer > > SandeshBufferQueue
Definition: p/sandesh.h:136
void set_type(SandeshType::type type)
Definition: p/sandesh.h:343
virtual int32_t ReadBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:590
static uint64_t UTCTimestampUsec()
Definition: time_util.h:13
static bool enable_local_log_
Definition: p/sandesh.h:416
virtual ~Sandesh()
Definition: p/sandesh.h:368
std::string context_
Definition: p/sandesh.h:438
static std::string LoggingCategory()
Definition: p/sandesh.h:232
static bool IsConnectToCollectorEnabled()
Definition: p/sandesh.h:242
virtual void ForcedLog() const =0
void set_context(std::string context)
Definition: p/sandesh.h:310
void operator()(QueueT &q, bool delete_entry)
Definition: p/sandesh.h:599
void set_timestamp(time_t timestamp)
Definition: p/sandesh.h:342
static uint32_t get_send_rate_limit()
Definition: sandesh.cc:540
int32_t hints() const
Definition: p/sandesh.h:316
static map_type * GetMap()
Definition: p/sandesh.h:647
static SandeshRxQueue * recv_queue()
Definition: p/sandesh.h:298
Sandesh(SandeshType::type type, const std::string &name, uint32_t seqno, bool no_time_stamp)
Definition: p/sandesh.h:357
bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:759
WorkQueue< SandeshElement > SandeshQueue
Definition: p/sandesh.h:133
static bool IsLoggingDroppedAllowed(SandeshType::type)
Definition: sandesh.cc:844
static bool disable_sending_all_
Definition: p/sandesh.h:433
static bool IsLocalLoggingEnabled()
Definition: p/sandesh.h:223
static SandeshCallback response_callback_
Definition: p/sandesh.h:378
int32_t hints_
Definition: p/sandesh.h:442
boost::shared_ptr< SandeshRequest > self_
Definition: p/sandesh.h:495
static bool IsLevelUT(SandeshLevel::type level)
Definition: sandesh.cc:816
virtual std::string ToString() const =0
static void DisableFlowCollection(bool disable)
Definition: sandesh.cc:484
static void set_client_context(SandeshContext *context)
Definition: p/sandesh.h:300
virtual int32_t Write(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > oprot) const =0
static void Uninit()
Definition: sandesh.cc:341
static void SetFlowLogging(bool enable)
Definition: sandesh.cc:465
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:1003
SandeshBuffer & operator=(const SandeshBuffer &r)
Definition: p/sandesh.h:512
static SandeshMessageStatistics msg_stats_
Definition: p/sandesh.h:426
static log4cplus::Logger & logger()
Definition: p/sandesh.h:323
SandeshSystem(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:547
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:144
static std::string source()
Definition: p/sandesh.h:289
virtual bool Dispatch(SandeshConnection *sconn=NULL)
Definition: sandesh.cc:727
static void RecordPort(const std::string &name, const std::string &module, unsigned short port)
Definition: sandesh.cc:191
static bool sampled_to_logger_
Definition: p/sandesh.h:450
static bool slo_to_collector_
Definition: p/sandesh.h:447
friend class SandeshTracePerfTest
Definition: p/sandesh.h:386
static bool is_send_sampled_to_collector_enabled()
Definition: p/sandesh.h:337
static SandeshLevel::type LoggingUtLevel()
Definition: p/sandesh.h:222
static void Update(map_type &map)
Definition: p/sandesh.h:633
static std::string source_
Definition: p/sandesh.h:408
static void set_node_type(std::string &node_type)
Definition: p/sandesh.h:294
boost::tuple< size_t, SandeshLevel::type, bool, bool > QueueWaterMarkInfo
Definition: p/sandesh.h:147
SandeshBuffer(const std::string &name, uint32_t seqno)
Definition: p/sandesh.h:524
static void DisableSendingAllMessages(bool disable)
Definition: sandesh.cc:492
static EventManager * event_manager_
Definition: p/sandesh.h:424
static void GetMsgStats(std::vector< SandeshMessageTypeStats > *mtype_stats, SandeshMessageStats *magg_stats)
Definition: sandesh.cc:896
std::string scope_
Definition: p/sandesh.h:440
void set_more(const bool val)
Definition: p/sandesh.h:584
static SandeshContext * client_context_
Definition: p/sandesh.h:414
static bool IsSendingFlowsDisabled()
Definition: sandesh.cc:524
static bool slo_to_logger_
Definition: p/sandesh.h:449
static bool IsLevelCategoryLoggingAllowed(SandeshType::type type, SandeshLevel::type level, const std::string &category)
Definition: sandesh.cc:821
static void DisableSendingFlows(bool disable)
Definition: sandesh.cc:516
virtual bool RequestFromHttp(const std::string &ctx, const std::string &snh_query)=0
static int recv_task_id_
Definition: p/sandesh.h:413
static void set_send_to_collector_flags(const std::vector< std::string > &sampled_destination, const std::vector< std::string > &slo_destination)
Definition: sandesh.cc:1056
virtual void set_more(const bool val)=0
static void SetTracePrint(bool enable)
Definition: sandesh.cc:456
static bool IsSendQueueEnabled()
Definition: p/sandesh.h:239
static SandeshContext * client_context()
Definition: p/sandesh.h:299
static bool IsSloSyslogEnabled()
Definition: p/sandesh.h:226
static ModuleContextMap module_context_
Definition: p/sandesh.h:415
static EventManager evm
static std::string instance_id()
Definition: p/sandesh.h:293
virtual int32_t WriteBinaryToFile(const std::string &path, int *error)
Definition: sandesh.cc:608
static void set_module(std::string &module)
Definition: p/sandesh.h:290
virtual void Process(SandeshContext *context)=0
static SandeshConfig & config()
Definition: p/sandesh.h:307
bool Enqueue(SandeshQueue *queue)
Definition: sandesh.cc:544
virtual ~SandeshContext()
Definition: p/sandesh.h:113