OpenSDN source code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
misc_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef ctrlplane_misc_utils_h
6 #define ctrlplane_misc_utils_h
7 
8 #include <sandesh/sandesh_trace.h>
9 #include <sandesh/common/vns_types.h>
10 #include <sandesh/common/vns_constants.h>
11 #include <string>
12 #include <vector>
13 #include <map>
14 #include <ctime>
15 
16 #define VERSION_TRACE_BUF "VersionTrace"
17 
19 
20 #define VERSION_TRACE(obj, ...) do { \
21  obj::TraceMsg(VersionTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \
22 } while (false)
23 
24 #define VERSION_LOG(obj, categ, ...)\
25  do {\
26  obj::Send(g_vns_constants.CategoryNames.find(categ)->second,\
27  SandeshLevel::SYS_INFO, __FILE__, __LINE__, ##__VA_ARGS__);\
28  } while (false)
29 
30 #if (__cplusplus < 201103L)
31  #define ARRAYBYTES_FILL(obj, val) (obj).assign((val));
32  #define GENERIC_RAW_ARRAY(obj) obj.c_array()
33 #else
34  #define ARRAYBYTES_FILL(obj, val) (obj).fill((val));
35  #define GENERIC_RAW_ARRAY(obj) obj.data()
36 #endif
37 
38 
39 class MiscUtils {
40 public:
41  enum BuildModule {
45  Dns,
47  };
48  static std::map<BuildModule, std::string> MapInit() {
49  std::map<BuildModule, std::string> m;
50  m[Agent] = "contrail-vrouter-agent ";
51  m[Analytics] = "contrail-analytics ";
52  m[ControlNode] = "contrail-control ";
53  m[Dns] = "contrail-dns ";
54  return m;
55  }
56  static const std::map<BuildModule, std::string> BuildModuleNames;
57  typedef std::multimap<std::time_t, std::string> FileMMap;
58  static const std::string ContrailVersionCmd;
59  static const std::string CoreFileDir;
60  static const int MaxCoreFiles;
61 
62  static bool GetBuildInfo(BuildModule id, const std::string &build_info, std::string &result);
63  static void GetHostIp(const std::string name, std::vector<std::string> &ip_list);
64  static void LogVersionInfo(const std::string str, Category::type categ);
65  static bool GetPlatformInfo(std::string &distro, std::string &code_name);
66  static time_t GetUpTimeSeconds();
67  static time_t set_startup_time_secs();
68 
69 private:
70  static bool GetContrailVersionInfo(BuildModule id, std::string &rpm_version, std::string &build_num);
71  static std::string BaseName(std::string filename);
72  static bool GetVersionInfoInternal(const std::string &cmd,
73  std::string &rpm_version,
74  std::string &build_num);
75  static time_t startup_time_secs_;
76 };
77 
78 #endif // ctrlplane_misc_utils_h
static std::string BaseName(std::string filename)
Definition: misc_utils.cc:30
static void GetHostIp(const std::string name, std::vector< std::string > &ip_list)
static bool GetBuildInfo(BuildModule id, const std::string &build_info, std::string &result)
Definition: misc_utils.cc:99
static void LogVersionInfo(const std::string str, Category::type categ)
Definition: misc_utils.cc:38
static bool GetPlatformInfo(std::string &distro, std::string &code_name)
Definition: misc_utils.cc:129
static time_t GetUpTimeSeconds()
Definition: misc_utils.cc:169
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
static const int MaxCoreFiles
Definition: misc_utils.h:60
static const std::map< BuildModule, std::string > BuildModuleNames
Definition: misc_utils.h:56
static bool GetContrailVersionInfo(BuildModule id, std::string &rpm_version, std::string &build_num)
Definition: misc_utils.cc:78
static time_t set_startup_time_secs()
Definition: misc_utils.cc:173
SandeshTraceBufferPtr VersionTraceBuf
uint8_t type
Definition: load_balance.h:109
static std::map< BuildModule, std::string > MapInit()
Definition: misc_utils.h:48
static const std::string CoreFileDir
Definition: misc_utils.h:59
static bool GetVersionInfoInternal(const std::string &cmd, std::string &rpm_version, std::string &build_num)
Definition: misc_utils.cc:45
static time_t startup_time_secs_
Definition: misc_utils.h:75
static const std::string ContrailVersionCmd
Definition: misc_utils.h:58
std::multimap< std::time_t, std::string > FileMMap
Definition: misc_utils.h:57