1 // 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:
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef included_stat_client_wrapper_h
16 #define included_stat_client_wrapper_h
21 #include <arpa/inet.h>
23 #include <vpp-api/client/stat_client.h> // VPP has to be installed!
25 // The stat_client.h defines its version using two macros:
26 // STAT_VERSION_MAJOR - for major version
27 // STAT_VERSION_MINOR - for minor version
28 // both were introduced in VPP 19.04 (not on release, later on stable/1904)
29 // https://github.com/FDio/vpp/commit/1cb333cdf5ce26557233c5bdb5a18738cb6e1e2c
31 // Name vector directory type was introduced in VPP 19.04
32 #if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 1
33 #define SUPPORTS_NAME_VECTOR // VPP 19.04 is required!
35 // Error value was changed into vector in VPP 19.08
36 #if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 2
37 #define SUPPORTS_ERROR_VECTOR // VPP 19.08 is required!
41 govpp_stat_connect(char *socket_name)
43 return stat_segment_connect(socket_name);
47 govpp_stat_disconnect()
49 stat_segment_disconnect();
53 govpp_stat_segment_ls(uint8_t **pattern)
55 return stat_segment_ls(pattern);
59 govpp_stat_segment_vec_len(void *vec)
61 return stat_segment_vec_len(vec);
65 govpp_stat_segment_vec_free(void *vec)
67 stat_segment_vec_free(vec);
71 govpp_stat_segment_dir_index_to_name(uint32_t *dir, uint32_t index)
73 return stat_segment_index_to_name(dir[index]);
76 static stat_segment_data_t*
77 govpp_stat_segment_dump(uint32_t *counter_vec)
79 return stat_segment_dump(counter_vec);
82 static stat_segment_data_t
83 govpp_stat_segment_dump_index(stat_segment_data_t *data, int index)
89 govpp_stat_segment_data_type(stat_segment_data_t *data)
95 govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data)
97 return data->scalar_value;
101 govpp_stat_segment_data_get_error_value(stat_segment_data_t *data)
103 #ifdef SUPPORTS_ERROR_VECTOR
106 for (j = 0; j < stat_segment_vec_len(data->error_vector); j++) // VPP 19.08+ is required!
107 value += data->error_vector[j];
110 return data->error_value; // VPP <19.08
115 govpp_stat_segment_data_get_simple_counter(stat_segment_data_t *data)
117 return data->simple_counter_vec;
121 govpp_stat_segment_data_get_simple_counter_index(stat_segment_data_t *data, int index)
123 return data->simple_counter_vec[index];
127 govpp_stat_segment_data_get_simple_counter_index_value(stat_segment_data_t *data, int index, int index2)
129 return data->simple_counter_vec[index][index2];
132 static vlib_counter_t**
133 govpp_stat_segment_data_get_combined_counter(stat_segment_data_t *data)
135 return data->combined_counter_vec;
138 static vlib_counter_t*
139 govpp_stat_segment_data_get_combined_counter_index(stat_segment_data_t *data, int index)
141 return data->combined_counter_vec[index];
145 govpp_stat_segment_data_get_combined_counter_index_packets(stat_segment_data_t *data, int index, int index2)
147 return data->combined_counter_vec[index][index2].packets;
151 govpp_stat_segment_data_get_combined_counter_index_bytes(stat_segment_data_t *data, int index, int index2)
153 return data->combined_counter_vec[index][index2].bytes;
157 govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data)
159 #ifdef SUPPORTS_NAME_VECTOR
160 return data->name_vector; // VPP 19.04 is required!
167 govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index)
169 #ifdef SUPPORTS_NAME_VECTOR
170 return data->name_vector[index]; // VPP 19.04 is required!
177 govpp_stat_segment_data_free(stat_segment_data_t *data)
179 stat_segment_data_free(data);
183 govpp_stat_segment_string_vector(uint8_t **string_vec, char *s)
185 return stat_segment_string_vector(string_vec, s);
188 #endif /* included_stat_client_wrapper_h */