OpenSDN source code
bgp_debug.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef SRC_BGP_BGP_DEBUG_H_
7 #define SRC_BGP_BGP_DEBUG_H_
8 
9 #if !defined(__BGP_DEBUG__)
10 
11 #define BGP_DEBUG(...)
12 
13 #else
14 
15 class DBEntry;
16 class DBTable;
17 class IPeer;
18 
19 class BgpDebug {
20 public:
21  static void Debug(DBTable *t, DBEntry *r, IPeer *p,
22  const char *file, const char *function, int line,
23  char *msg);
24  static bool Enabled() { return enable_; }
25 private:
26  static bool enable_;
27  static bool enable_stack_trace_;
28 };
29 
30 //
31 // Generic debug macro to print a peer, instance, table, and route information
32 // if provided. (Use NULL to omit a particular field). It also prints caller
33 // file name, function name, class name and line number
34 //
35 // TODO(ananth): Have a simple way to filter messages such as filter based on
36 // server, instance, table, peer, route, etc.
37 //
38 //
39 #define __FUNC__ __FUNCTION__
40 
41 #define BGP_DEBUG(dtable, dpeer, droute, format, args...) \
42 do { \
43  if (!BgpDebug::Enabled()) { \
44  break; \
45  } \
46  char msg[1024]; \
47  snprintf(msg, sizeof(msg), format, ##args); \
48  \
49  BgpDebug::Debug(static_cast<DBTable *>(dtable), \
50  static_cast<DBEntry *>(droute), \
51  static_cast<IPeer *>(dpeer), \
52  __FILE__, __FUNC__, __LINE__, msg); \
53 } while (0)
54 
55 #endif // __BGP_DEBUG__
56 
57 #endif // SRC_BGP_BGP_DEBUG_H_
Definition: ipeer.h:187