FD.io VPP  v21.06-3-gbb25fbf28
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
VOM::stat_client::connect
int connect()
Connect to stat segment.
Definition: stat_client.cpp:137
VOM::stat_client::stat_data_t::m_error_vec
counter_t * m_error_vec
Definition: stat_client.hpp:80
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::stat_client::stat_data_t::name
const std::string & name() const
get name of stat
Definition: stat_client.cpp:47
VOM::stat_client::stat_data_t
stat data representation
Definition: stat_client.hpp:38
VOM::stat_client::stat_data_t::type
const stat_directory_type_t & type() const
get type of stat
Definition: stat_client.cpp:53
VOM::stat_client::stat_data_t::m_simple_counter_vec
counter_t ** m_simple_counter_vec
Definition: stat_client.hpp:81
VOM::stat_client::stat_data_t::get_stat_segment_error_data
uint64_t * get_stat_segment_error_data() const
Definition: stat_client.cpp:65
VOM::stat_client::stat_data_t::get_stat_segment_combined_counter_data
vlib_counter_t ** get_stat_segment_combined_counter_data() const
Definition: stat_client.cpp:77
stat_directory_type_t
stat_directory_type_t
Definition: stat_segment_shared.h:19
VOM::stat_client::disconnect
void disconnect()
Disconnect to stat segment.
Definition: stat_client.cpp:147
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
VOM::stat_client::vec_len
int vec_len(void *vec)
Get vector length of VPP style vector.
Definition: stat_client.cpp:155
VOM::stat_client::stat_data_t::m_combined_counter_vec
vlib_counter_t ** m_combined_counter_vec
Definition: stat_client.hpp:82
VOM::stat_client::stat_data_t::get_stat_segment_scalar_data
double get_stat_segment_scalar_data() const
Get pointer to actual data.
Definition: stat_client.cpp:59
VOM::stat_client::stat_data_t::stat_data_t
stat_data_t(const stat_segment_data_t &stat_seg_data)
stat data custom constructor
Definition: stat_client.cpp:20
VOM::counter_t
Definition: types.hpp:386
index
u32 index
Definition: flow_types.api:221
VOM::stat_client::stat_data_vec_t
std::vector< stat_data_t > stat_data_vec_t
vector of stat_data_t
Definition: stat_client.hpp:89
stat_segment_data_t
Definition: stat_client.h:35
VOM::stat_client::stat_client
stat_client()
Stat Client constructor.
Definition: stat_client.cpp:112
VOM::stat_client::stat_data_t::get_stat_segment_simple_counter_data
uint64_t ** get_stat_segment_simple_counter_data() const
Definition: stat_client.cpp:71
VOM::stat_client
A representation of a stat client in VPP.
Definition: stat_client.hpp:32
VOM::stat_client::dump
const stat_data_vec_t & dump()
dump all the stats for given pattern
Definition: stat_client.cpp:178
VOM::stat_client::stat_data_t::m_scalar_value
double m_scalar_value
Definition: stat_client.hpp:79
VOM::stat_client::index_to_name
std::string index_to_name(uint32_t index)
get index to name of stat
Definition: stat_client.cpp:234
VOM::stat_client::dump_entry
const stat_data_vec_t & dump_entry(uint32_t index)
dump stats for given index in stat directory
Definition: stat_client.cpp:200
VOM::stat_client::~stat_client
~stat_client()
Stat Client destructor.
Definition: stat_client.cpp:123
stat_client.h
VOM::stat_client::heartbeat
double heartbeat()
Definition: stat_client.cpp:228
string
const char *const string
Definition: cJSON.h:172