Fix compilation for VPP 19.01
[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
36 static int
37 govpp_stat_connect(char *socket_name)
38 {
39         return stat_segment_connect(socket_name);
40 }
41
42 static void
43 govpp_stat_disconnect()
44 {
45     stat_segment_disconnect();
46 }
47
48 static uint32_t*
49 govpp_stat_segment_ls(uint8_t **pattern)
50 {
51         return stat_segment_ls(pattern);
52 }
53
54 static int
55 govpp_stat_segment_vec_len(void *vec)
56 {
57         return stat_segment_vec_len(vec);
58 }
59
60 static void
61 govpp_stat_segment_vec_free(void *vec)
62 {
63         stat_segment_vec_free(vec);
64 }
65
66 static char*
67 govpp_stat_segment_dir_index_to_name(uint32_t *dir, uint32_t index)
68 {
69         return stat_segment_index_to_name(dir[index]);
70 }
71
72 static stat_segment_data_t*
73 govpp_stat_segment_dump(uint32_t *counter_vec)
74 {
75         return stat_segment_dump(counter_vec);
76 }
77
78 static stat_segment_data_t
79 govpp_stat_segment_dump_index(stat_segment_data_t *data, int index)
80 {
81         return data[index];
82 }
83
84 static int
85 govpp_stat_segment_data_type(stat_segment_data_t *data)
86 {
87         return data->type;
88 }
89
90 static double
91 govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data)
92 {
93         return data->scalar_value;
94 }
95
96 static double
97 govpp_stat_segment_data_get_error_value(stat_segment_data_t *data)
98 {
99         return data->error_value;
100 }
101
102 static uint64_t**
103 govpp_stat_segment_data_get_simple_counter(stat_segment_data_t *data)
104 {
105         return data->simple_counter_vec;
106 }
107
108 static uint64_t*
109 govpp_stat_segment_data_get_simple_counter_index(stat_segment_data_t *data, int index)
110 {
111         return data->simple_counter_vec[index];
112 }
113
114 static uint64_t
115 govpp_stat_segment_data_get_simple_counter_index_value(stat_segment_data_t *data, int index, int index2)
116 {
117         return data->simple_counter_vec[index][index2];
118 }
119
120 static vlib_counter_t**
121 govpp_stat_segment_data_get_combined_counter(stat_segment_data_t *data)
122 {
123         return data->combined_counter_vec;
124 }
125
126 static vlib_counter_t*
127 govpp_stat_segment_data_get_combined_counter_index(stat_segment_data_t *data, int index)
128 {
129         return data->combined_counter_vec[index];
130 }
131
132 static uint64_t
133 govpp_stat_segment_data_get_combined_counter_index_packets(stat_segment_data_t *data, int index, int index2)
134 {
135         return data->combined_counter_vec[index][index2].packets;
136 }
137
138 static uint64_t
139 govpp_stat_segment_data_get_combined_counter_index_bytes(stat_segment_data_t *data, int index, int index2)
140 {
141         return data->combined_counter_vec[index][index2].bytes;
142 }
143
144 static uint8_t**
145 govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data)
146 {
147 #ifdef SUPPORTS_NAME_VECTOR
148         return data->name_vector; // VPP 19.04 is required!
149 #else
150         return 0;
151 #endif
152 }
153
154 static char*
155 govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index)
156 {
157 #ifdef SUPPORTS_NAME_VECTOR
158         return data->name_vector[index]; // VPP 19.04 is required!
159 #else
160         return 0;
161 #endif
162 }
163
164 static void
165 govpp_stat_segment_data_free(stat_segment_data_t *data)
166 {
167         stat_segment_data_free(data);
168 }
169
170 static uint8_t**
171 govpp_stat_segment_string_vector(uint8_t ** string_vector, char *string)
172 {
173         return stat_segment_string_vector(string_vector, string);
174 }
175
176 #endif /* included_stat_client_wrapper_h */