vom: Add support for new stats
[vpp.git] / extras / vom / vom / stat_client.hpp
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __VOM_STAT_CLIENT_H__
17 #define __VOM_STAT_CLIENT_H__
18
19 #include <iostream>
20 #include <string>
21 #include <vector>
22
23 extern "C" {
24 #include <vpp-api/client/stat_client.h>
25 }
26
27 namespace VOM {
28
29 typedef struct
30 {
31   uint64_t packets;
32   uint64_t bytes;
33 } counter_t;
34
35 typedef uint64_t stat_counter_t;
36 /**
37  * A representation of a stat client in VPP
38  */
39 class stat_client
40 {
41 public:
42   /**
43    * stat data representation
44    */
45   struct stat_data_t
46   {
47     /**
48      * stat data constructor
49      */
50     stat_data_t();
51
52     /**
53      * stat data custom constructor
54      */
55     stat_data_t(stat_segment_data_t* stat_seg_data);
56
57     /**
58      * get name of stat
59      */
60     const std::string& name() const;
61
62     /**
63      * get type of stat
64      */
65     const stat_directory_type_t& type() const;
66
67     /**
68      * Get pointer to actual data
69      */
70     double get_stat_segment_scalar_data();
71     uint64_t get_stat_segment_error_data();
72     uint64_t** get_stat_segment_simple_counter_data();
73     counter_t** get_stat_segment_combined_counter_data();
74
75   private:
76     /**
77      * name of stat data
78      */
79     const std::string m_name;
80
81     /**
82      * type of stat data
83      */
84     const stat_directory_type_t m_type;
85
86     /**
87      * union of pointers to actual stat data
88      */
89     union
90     {
91       double m_scalar_value;
92       uint64_t m_error_Value;
93       uint64_t** m_simple_counter_vec;
94       counter_t** m_combined_counter_vec;
95     };
96   };
97
98   /**
99    * vector of stat_data_t
100    */
101   typedef std::vector<stat_data_t> stat_data_vec_t;
102
103   /**
104    * Stat Client constructor with custom socket name
105    */
106   stat_client(std::string& socket_name);
107
108   /**
109    * Stat Client constructor with custom vector of patterns
110    */
111   stat_client(std::vector<std::string>& pattern);
112
113   /**
114    * Stat Client constructor with custom socket name and vector of patterns
115    */
116   stat_client(std::string socket_name, std::vector<std::string> patterns);
117
118   /**
119    * Stat Client constructor
120    */
121   stat_client();
122
123   /**
124    * Stat Client destructor
125    */
126   ~stat_client();
127
128   /**
129    * Stat Client copy constructor
130    */
131   stat_client(const stat_client& o);
132
133   /**
134    * Connect to stat segment
135    */
136   int connect();
137
138   /**
139    * Disconnect to stat segment
140    */
141   void disconnect();
142
143   /**
144    * Get vector length of VPP style vector
145    */
146   int vec_len(void* vec);
147
148   /**
149    * Free VPP style vector
150    */
151   void vec_free(void* vec);
152
153   /**
154    * ls on the stat directory using given pattern
155    */
156   void ls();
157
158   /**
159    * dump all the stats for given pattern
160    */
161   const stat_data_vec_t& dump();
162
163   /**
164    * dump stats for given index in stat directory
165    */
166   const stat_data_vec_t& dump_entry(uint32_t index);
167
168   /**
169    * Free stat segment data
170    */
171   void data_free();
172
173   double heartbeat();
174
175   /**
176    * get index to name of stat
177    */
178   std::string index_to_name(uint32_t index);
179
180 private:
181   /**
182    * socket name
183    */
184   std::string m_socket_name;
185
186   /**
187    * vector of patterns for stats
188    */
189   std::vector<std::string> m_patterns;
190
191   /**
192    * connection bit
193    */
194   int m_stat_connect;
195
196   /**
197    * Pointer to VPP style vector of stat indexes
198    */
199   uint32_t* m_counter_vec;
200
201   /**
202    * Pointer to stat segment
203    */
204   stat_segment_data_t* m_stat_seg_data;
205
206   /**
207    * Vector of stat data
208    */
209   stat_data_vec_t m_stat_data;
210 };
211 }; // namespace VOM
212
213 /*
214  * fd.io coding-style-patch-verification: ON
215  *
216  * Local Variables:
217  * eval: (c-set-style "mozilla")
218  * End:
219  */
220
221 #endif