GBP: add allowed ethertypes to contracts
[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 /**
30  * A representation of a stat client in VPP
31  */
32 class stat_client
33 {
34 public:
35   /**
36    * stat data representation
37    */
38   struct stat_data_t
39   {
40     /**
41      * stat data custom constructor
42      */
43     stat_data_t(const stat_segment_data_t& stat_seg_data);
44
45     /**
46      * get name of stat
47      */
48     const std::string& name() const;
49
50     /**
51      * get type of stat
52      */
53     const stat_directory_type_t& type() const;
54
55     /**
56      * Get pointer to actual data
57      */
58     double get_stat_segment_scalar_data() const;
59     uint64_t get_stat_segment_error_data() const;
60     uint64_t** get_stat_segment_simple_counter_data() const;
61     vlib_counter_t** get_stat_segment_combined_counter_data() const;
62
63   private:
64     /**
65      * name of stat data
66      */
67     const std::string m_name;
68
69     /**
70      * type of stat data
71      */
72     const stat_directory_type_t m_type;
73
74     /**
75      * union of pointers to actual stat data
76      */
77     union
78     {
79       double m_scalar_value;
80       uint64_t m_error_value;
81       counter_t** m_simple_counter_vec;
82       vlib_counter_t** m_combined_counter_vec;
83     };
84   };
85
86   /**
87    * vector of stat_data_t
88    */
89   typedef std::vector<stat_data_t> stat_data_vec_t;
90
91   /**
92    * Stat Client constructor with custom socket name
93    */
94   stat_client(std::string& socket_name);
95
96   /**
97    * Stat Client constructor with custom vector of patterns
98    */
99   stat_client(std::vector<std::string>& pattern);
100
101   /**
102    * Stat Client constructor with custom socket name and vector of patterns
103    */
104   stat_client(std::string socket_name, std::vector<std::string> patterns);
105
106   /**
107    * Stat Client constructor
108    */
109   stat_client();
110
111   /**
112    * Stat Client destructor
113    */
114   ~stat_client();
115
116   /**
117    * Stat Client copy constructor
118    */
119   stat_client(const stat_client& o);
120
121   /**
122    * Connect to stat segment
123    */
124   int connect();
125
126   /**
127    * Disconnect to stat segment
128    */
129   void disconnect();
130
131   /**
132    * dump all the stats for given pattern
133    */
134   const stat_data_vec_t& dump();
135
136   /**
137    * dump stats for given index in stat directory
138    */
139   const stat_data_vec_t& dump_entry(uint32_t index);
140
141   /**
142    * Get vector length of VPP style vector
143    */
144   int vec_len(void* vec);
145
146   double heartbeat();
147
148   /**
149    * get index to name of stat
150    */
151   std::string index_to_name(uint32_t index);
152
153 private:
154   /**
155    * Free VPP style vector
156    */
157   void vec_free(void* vec);
158
159   /**
160    * Free stat segment data
161    */
162   void data_free();
163
164   /**
165    * ls on the stat directory using given pattern
166    */
167   void ls();
168
169   /**
170    * socket name
171    */
172   std::string m_socket_name;
173
174   /**
175    * vector of patterns for stats
176    */
177   std::vector<std::string> m_patterns;
178
179   /**
180    * connection bit
181    */
182   int m_stat_connect;
183
184   /**
185    * Pointer to VPP style vector of stat indexes
186    */
187   uint32_t* m_counter_vec;
188
189   /**
190    * Pointer to stat segment
191    */
192   stat_segment_data_t* m_stat_seg_data;
193
194   /**
195    * Vector of stat data
196    */
197   stat_data_vec_t m_stat_data;
198 };
199 }; // namespace VOM
200
201 /*
202  * fd.io coding-style-patch-verification: ON
203  *
204  * Local Variables:
205  * eval: (c-set-style "mozilla")
206  * End:
207  */
208
209 #endif