diff options
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/vppapiclient/stat_client.go | 140 | ||||
-rw-r--r-- | adapter/vppapiclient/stat_client_wrapper.h | 176 | ||||
-rw-r--r-- | adapter/vppapiclient/vppapiclient.go | 54 | ||||
-rw-r--r-- | adapter/vppapiclient/vppapiclient_wrapper.h | 71 |
4 files changed, 252 insertions, 189 deletions
diff --git a/adapter/vppapiclient/stat_client.go b/adapter/vppapiclient/stat_client.go index ac47339..2615b65 100644 --- a/adapter/vppapiclient/stat_client.go +++ b/adapter/vppapiclient/stat_client.go @@ -20,146 +20,10 @@ package vppapiclient #cgo CFLAGS: -DPNG_DEBUG=1 #cgo LDFLAGS: -lvppapiclient -#include <stdlib.h> -#include <stdio.h> -#include <stdint.h> -#include <arpa/inet.h> -#include <vpp-api/client/vppapiclient.h> // VPP has to be installed! -#include <vpp-api/client/stat_client.h> - -static int -govpp_stat_connect(char *socket_name) -{ - return stat_segment_connect(socket_name); -} - -static void -govpp_stat_disconnect() -{ - stat_segment_disconnect(); -} - -static uint32_t* -govpp_stat_segment_ls(uint8_t **pattern) -{ - return stat_segment_ls(pattern); -} - -static int -govpp_stat_segment_vec_len(void *vec) -{ - return stat_segment_vec_len(vec); -} - -static void -govpp_stat_segment_vec_free(void *vec) -{ - stat_segment_vec_free(vec); -} - -static char* -govpp_stat_segment_dir_index_to_name(uint32_t *dir, uint32_t index) -{ - return stat_segment_index_to_name(dir[index]); -} - -static stat_segment_data_t* -govpp_stat_segment_dump(uint32_t *counter_vec) -{ - return stat_segment_dump(counter_vec); -} - -static stat_segment_data_t -govpp_stat_segment_dump_index(stat_segment_data_t *data, int index) -{ - return data[index]; -} - -static int -govpp_stat_segment_data_type(stat_segment_data_t *data) -{ - return data->type; -} - -static double -govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data) -{ - return data->scalar_value; -} - -static double -govpp_stat_segment_data_get_error_value(stat_segment_data_t *data) -{ - return data->error_value; -} - -static uint64_t** -govpp_stat_segment_data_get_simple_counter(stat_segment_data_t *data) -{ - return data->simple_counter_vec; -} - -static uint64_t* -govpp_stat_segment_data_get_simple_counter_index(stat_segment_data_t *data, int index) -{ - return data->simple_counter_vec[index]; -} - -static uint64_t -govpp_stat_segment_data_get_simple_counter_index_value(stat_segment_data_t *data, int index, int index2) -{ - return data->simple_counter_vec[index][index2]; -} - -static vlib_counter_t** -govpp_stat_segment_data_get_combined_counter(stat_segment_data_t *data) -{ - return data->combined_counter_vec; -} - -static vlib_counter_t* -govpp_stat_segment_data_get_combined_counter_index(stat_segment_data_t *data, int index) -{ - return data->combined_counter_vec[index]; -} - -static uint64_t -govpp_stat_segment_data_get_combined_counter_index_packets(stat_segment_data_t *data, int index, int index2) -{ - return data->combined_counter_vec[index][index2].packets; -} - -static uint64_t -govpp_stat_segment_data_get_combined_counter_index_bytes(stat_segment_data_t *data, int index, int index2) -{ - return data->combined_counter_vec[index][index2].bytes; -} - -static uint8_t** -govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data) -{ - return data->name_vector; // VPP 19.04 is required! -} - -static char* -govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index) -{ - return data->name_vector[index]; // VPP 19.04 is required! -} - -static void -govpp_stat_segment_data_free(stat_segment_data_t *data) -{ - stat_segment_data_free(data); -} - -static uint8_t** -govpp_stat_segment_string_vector(uint8_t ** string_vector, char *string) -{ - return stat_segment_string_vector(string_vector, string); -} +#include "stat_client_wrapper.h" */ import "C" + import ( "errors" "fmt" diff --git a/adapter/vppapiclient/stat_client_wrapper.h b/adapter/vppapiclient/stat_client_wrapper.h new file mode 100644 index 0000000..9178fb5 --- /dev/null +++ b/adapter/vppapiclient/stat_client_wrapper.h @@ -0,0 +1,176 @@ +// Copyright (c) 2018 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef included_stat_client_wrapper_h +#define included_stat_client_wrapper_h + +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <arpa/inet.h> + +#include <vpp-api/client/stat_client.h> // VPP has to be installed! + +// The stat_client.h defines its version using two macros: +// STAT_VERSION_MAJOR - for major version +// STAT_VERSION_MINOR - for minor version +// both were introduced in VPP 19.04 (not on release, later on stable/1904) +// https://github.com/FDio/vpp/commit/1cb333cdf5ce26557233c5bdb5a18738cb6e1e2c + +// Name vector directory type was introduced in VPP 19.04 +#if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 1 + #define SUPPORTS_NAME_VECTOR // VPP 19.04 is required! +#endif + +static int +govpp_stat_connect(char *socket_name) +{ + return stat_segment_connect(socket_name); +} + +static void +govpp_stat_disconnect() +{ + stat_segment_disconnect(); +} + +static uint32_t* +govpp_stat_segment_ls(uint8_t **pattern) +{ + return stat_segment_ls(pattern); +} + +static int +govpp_stat_segment_vec_len(void *vec) +{ + return stat_segment_vec_len(vec); +} + +static void +govpp_stat_segment_vec_free(void *vec) +{ + stat_segment_vec_free(vec); +} + +static char* +govpp_stat_segment_dir_index_to_name(uint32_t *dir, uint32_t index) +{ + return stat_segment_index_to_name(dir[index]); +} + +static stat_segment_data_t* +govpp_stat_segment_dump(uint32_t *counter_vec) +{ + return stat_segment_dump(counter_vec); +} + +static stat_segment_data_t +govpp_stat_segment_dump_index(stat_segment_data_t *data, int index) +{ + return data[index]; +} + +static int +govpp_stat_segment_data_type(stat_segment_data_t *data) +{ + return data->type; +} + +static double +govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data) +{ + return data->scalar_value; +} + +static double +govpp_stat_segment_data_get_error_value(stat_segment_data_t *data) +{ + return data->error_value; +} + +static uint64_t** +govpp_stat_segment_data_get_simple_counter(stat_segment_data_t *data) +{ + return data->simple_counter_vec; +} + +static uint64_t* +govpp_stat_segment_data_get_simple_counter_index(stat_segment_data_t *data, int index) +{ + return data->simple_counter_vec[index]; +} + +static uint64_t +govpp_stat_segment_data_get_simple_counter_index_value(stat_segment_data_t *data, int index, int index2) +{ + return data->simple_counter_vec[index][index2]; +} + +static vlib_counter_t** +govpp_stat_segment_data_get_combined_counter(stat_segment_data_t *data) +{ + return data->combined_counter_vec; +} + +static vlib_counter_t* +govpp_stat_segment_data_get_combined_counter_index(stat_segment_data_t *data, int index) +{ + return data->combined_counter_vec[index]; +} + +static uint64_t +govpp_stat_segment_data_get_combined_counter_index_packets(stat_segment_data_t *data, int index, int index2) +{ + return data->combined_counter_vec[index][index2].packets; +} + +static uint64_t +govpp_stat_segment_data_get_combined_counter_index_bytes(stat_segment_data_t *data, int index, int index2) +{ + return data->combined_counter_vec[index][index2].bytes; +} + +static uint8_t** +govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data) +{ +#ifdef SUPPORTS_NAME_VECTOR + return data->name_vector; // VPP 19.04 is required! +#else + return 0; +#endif +} + +static char* +govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index) +{ +#ifdef SUPPORTS_NAME_VECTOR + return data->name_vector[index]; // VPP 19.04 is required! +#else + return 0; +#endif +} + +static void +govpp_stat_segment_data_free(stat_segment_data_t *data) +{ + stat_segment_data_free(data); +} + +static uint8_t** +govpp_stat_segment_string_vector(uint8_t ** string_vector, char *string) +{ + return stat_segment_string_vector(string_vector, string); +} + +#endif /* included_stat_client_wrapper_h */ diff --git a/adapter/vppapiclient/vppapiclient.go b/adapter/vppapiclient/vppapiclient.go index f637060..d8465d7 100644 --- a/adapter/vppapiclient/vppapiclient.go +++ b/adapter/vppapiclient/vppapiclient.go @@ -20,56 +20,7 @@ package vppapiclient #cgo CFLAGS: -DPNG_DEBUG=1 #cgo LDFLAGS: -lvppapiclient -#include <stdlib.h> -#include <stdio.h> -#include <stdint.h> -#include <arpa/inet.h> -#include <vpp-api/client/vppapiclient.h> - -extern void go_msg_callback(uint16_t msg_id, void* data, size_t size); - -typedef struct __attribute__((__packed__)) _req_header { - uint16_t msg_id; - uint32_t client_index; - uint32_t context; -} req_header_t; - -typedef struct __attribute__((__packed__)) _reply_header { - uint16_t msg_id; -} reply_header_t; - -static void -govpp_msg_callback(unsigned char *data, int size) -{ - reply_header_t *header = ((reply_header_t *)data); - go_msg_callback(ntohs(header->msg_id), data, size); -} - -static int -govpp_send(uint32_t context, void *data, size_t size) -{ - req_header_t *header = ((req_header_t *)data); - header->context = htonl(context); - return vac_write(data, size); -} - -static int -govpp_connect(char *shm, int rx_qlen) -{ - return vac_connect("govpp", shm, govpp_msg_callback, rx_qlen); -} - -static int -govpp_disconnect() -{ - return vac_disconnect(); -} - -static uint32_t -govpp_get_msg_index(char *name_and_crc) -{ - return vac_get_msg_index(name_and_crc); -} +#include "vppapiclient_wrapper.h" */ import "C" @@ -81,8 +32,9 @@ import ( "time" "unsafe" - "git.fd.io/govpp.git/adapter" "github.com/fsnotify/fsnotify" + + "git.fd.io/govpp.git/adapter" ) var ( diff --git a/adapter/vppapiclient/vppapiclient_wrapper.h b/adapter/vppapiclient/vppapiclient_wrapper.h new file mode 100644 index 0000000..691c782 --- /dev/null +++ b/adapter/vppapiclient/vppapiclient_wrapper.h @@ -0,0 +1,71 @@ +// Copyright (c) 2018 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef included_vppapiclient_wrapper_h +#define included_vppapiclient_wrapper_h + +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <arpa/inet.h> + +#include <vpp-api/client/vppapiclient.h> // VPP has to be installed! + +// function go_msg_callback is defined in vppapiclient.go +extern void go_msg_callback(uint16_t msg_id, void* data, size_t size); + +typedef struct __attribute__((__packed__)) _req_header { + uint16_t msg_id; + uint32_t client_index; + uint32_t context; +} req_header_t; + +typedef struct __attribute__((__packed__)) _reply_header { + uint16_t msg_id; +} reply_header_t; + +static void +govpp_msg_callback(unsigned char *data, int size) +{ + reply_header_t *header = ((reply_header_t *)data); + go_msg_callback(ntohs(header->msg_id), data, size); +} + +static int +govpp_send(uint32_t context, void *data, size_t size) +{ + req_header_t *header = ((req_header_t *)data); + header->context = htonl(context); + return vac_write(data, size); +} + +static int +govpp_connect(char *shm, int rx_qlen) +{ + return vac_connect("govpp", shm, govpp_msg_callback, rx_qlen); +} + +static int +govpp_disconnect() +{ + return vac_disconnect(); +} + +static uint32_t +govpp_get_msg_index(char *name_and_crc) +{ + return vac_get_msg_index(name_and_crc); +} + +#endif /* included_vppapiclient_wrapper_h */ |