FD.io VPP  v21.01.1
Vector Packet Processing
stat_client.hpp
Go to the documentation of this file.
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" {
25 }
26 
27 namespace VOM {
28 
29 /**
30  * A representation of a stat client in VPP
31  */
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;
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  {
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  bool 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: OFF
203  *
204  * Local Variables:
205  * eval: (c-set-style "mozilla")
206  * End:
207  */
208 
209 #endif
const stat_directory_type_t & type() const
get type of stat
Definition: stat_client.cpp:53
const char *const string
Definition: cJSON.h:172
vlib_counter_t ** get_stat_segment_combined_counter_data() const
Definition: stat_client.cpp:77
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
stat_client()
Stat Client constructor.
vlib_counter_t ** m_combined_counter_vec
Definition: stat_client.hpp:82
int vec_len(void *vec)
Get vector length of VPP style vector.
stat_directory_type_t
double get_stat_segment_scalar_data() const
Get pointer to actual data.
Definition: stat_client.cpp:59
stat data representation
Definition: stat_client.hpp:38
void disconnect()
Disconnect to stat segment.
A representation of a stat client in VPP.
Definition: stat_client.hpp:32
uint64_t * get_stat_segment_error_data() const
Definition: stat_client.cpp:65
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
const stat_data_vec_t & dump_entry(uint32_t index)
dump stats for given index in stat directory
std::vector< stat_data_t > stat_data_vec_t
vector of stat_data_t
Definition: stat_client.hpp:89
~stat_client()
Stat Client destructor.
uint64_t ** get_stat_segment_simple_counter_data() const
Definition: stat_client.cpp:71
std::string index_to_name(uint32_t index)
get index to name of stat
int connect()
Connect to stat segment.
const stat_data_vec_t & dump()
dump all the stats for given pattern
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
u32 index
Definition: flow_types.api:221
const std::string & name() const
get name of stat
Definition: stat_client.cpp:47
stat_data_t(const stat_segment_data_t &stat_seg_data)
stat data custom constructor
Definition: stat_client.cpp:20