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