test: Fix test dependancy
[govpp.git] / adapter / vppapiclient / stat_client_wrapper.h
1 // Copyright (c) 2018 Cisco and/or its affiliates.
2 //
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 #ifndef included_stat_client_wrapper_h
16 #define included_stat_client_wrapper_h
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <arpa/inet.h>
22
23 #include <vpp-api/client/stat_client.h> // VPP has to be installed!
24
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
30
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!
34 #endif
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!
38 #endif
39
40 static int
41 govpp_stat_connect(char *socket_name)
42 {
43         return stat_segment_connect(socket_name);
44 }
45
46 static void
47 govpp_stat_disconnect()
48 {
49     stat_segment_disconnect();
50 }
51
52 static uint32_t*
53 govpp_stat_segment_ls(uint8_t **pattern)
54 {
55         return stat_segment_ls(pattern);
56 }
57
58 static int
59 govpp_stat_segment_vec_len(void *vec)
60 {
61         return stat_segment_vec_len(vec);
62 }
63
64 static void
65 govpp_stat_segment_vec_free(void *vec)
66 {
67         stat_segment_vec_free(vec);
68 }
69
70 static char*
71 govpp_stat_segment_dir_index_to_name(uint32_t *dir, uint32_t index)
72 {
73         return stat_segment_index_to_name(dir[index]);
74 }
75
76 static stat_segment_data_t*
77 govpp_stat_segment_dump(uint32_t *counter_vec)
78 {
79         return stat_segment_dump(counter_vec);
80 }
81
82 static stat_segment_data_t
83 govpp_stat_segment_dump_index(stat_segment_data_t *data, int index)
84 {
85         return data[index];
86 }
87
88 static int
89 govpp_stat_segment_data_type(stat_segment_data_t *data)
90 {
91         return data->type;
92 }
93
94 static double
95 govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data)
96 {
97         return data->scalar_value;
98 }
99
100 static counter_t
101 govpp_stat_segment_data_get_error_value(stat_segment_data_t *data)
102 {
103 #ifdef SUPPORTS_ERROR_VECTOR
104         counter_t value = 0;
105         int j;
106         for (j = 0; j < stat_segment_vec_len(data->error_vector); j++) // VPP 19.08+ is required!
107         value += data->error_vector[j];
108         return value;
109 #else
110         return data->error_value; // VPP <19.08
111 #endif
112 }
113
114 static uint64_t**
115 govpp_stat_segment_data_get_simple_counter(stat_segment_data_t *data)
116 {
117         return data->simple_counter_vec;
118 }
119
120 static uint64_t*
121 govpp_stat_segment_data_get_simple_counter_index(stat_segment_data_t *data, int index)
122 {
123         return data->simple_counter_vec[index];
124 }
125
126 static uint64_t
127 govpp_stat_segment_data_get_simple_counter_index_value(stat_segment_data_t *data, int index, int index2)
128 {
129         return data->simple_counter_vec[index][index2];
130 }
131
132 static vlib_counter_t**
133 govpp_stat_segment_data_get_combined_counter(stat_segment_data_t *data)
134 {
135         return data->combined_counter_vec;
136 }
137
138 static vlib_counter_t*
139 govpp_stat_segment_data_get_combined_counter_index(stat_segment_data_t *data, int index)
140 {
141         return data->combined_counter_vec[index];
142 }
143
144 static uint64_t
145 govpp_stat_segment_data_get_combined_counter_index_packets(stat_segment_data_t *data, int index, int index2)
146 {
147         return data->combined_counter_vec[index][index2].packets;
148 }
149
150 static uint64_t
151 govpp_stat_segment_data_get_combined_counter_index_bytes(stat_segment_data_t *data, int index, int index2)
152 {
153         return data->combined_counter_vec[index][index2].bytes;
154 }
155
156 static uint8_t**
157 govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data)
158 {
159 #ifdef SUPPORTS_NAME_VECTOR
160         return data->name_vector; // VPP 19.04 is required!
161 #else
162         return 0;
163 #endif
164 }
165
166 static char*
167 govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index)
168 {
169 #ifdef SUPPORTS_NAME_VECTOR
170         return data->name_vector[index]; // VPP 19.04 is required!
171 #else
172         return 0;
173 #endif
174 }
175
176 static void
177 govpp_stat_segment_data_free(stat_segment_data_t *data)
178 {
179         stat_segment_data_free(data);
180 }
181
182 static uint8_t**
183 govpp_stat_segment_string_vector(uint8_t **string_vec, char *s)
184 {
185         return stat_segment_string_vector(string_vec, s);
186 }
187
188 #endif /* included_stat_client_wrapper_h */