diff options
Diffstat (limited to 'ctrl/libhicnctrl')
22 files changed, 318 insertions, 220 deletions
diff --git a/ctrl/libhicnctrl/includes/CMakeLists.txt b/ctrl/libhicnctrl/includes/CMakeLists.txt index 554021c48..63b8aa9a7 100644 --- a/ctrl/libhicnctrl/includes/CMakeLists.txt +++ b/ctrl/libhicnctrl/includes/CMakeLists.txt @@ -46,6 +46,7 @@ set(TO_INSTALL_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/objects/policy.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/objects/punting.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/objects/route.h + ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/objects/stats.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/objects/strategy.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/objects/subscription.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/parse.h diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h index 21a5e548f..ad3f8fcc3 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h @@ -194,47 +194,17 @@ typedef struct hc_result_s hc_result_t; #define UNSUPPORTED_CMD_ERROR -3 /*----------------------------------------------------------------------------* - * Strategy - *----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------* * WLDR *----------------------------------------------------------------------------*/ // per connection int hc_wldr_set(hc_sock_t *s /* XXX */); -/*----------------------------------------------------------------------------* - * MAP-Me - *----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------* - * Policies - *----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------* - * Subscription - *----------------------------------------------------------------------------*/ -// Topics - -#if 0 -/* Result */ - -hc_msg_t *hc_result_get_msg(hc_sock_t *s, hc_result_t *result); -int hc_result_get_cmd_id(hc_sock_t *s, hc_result_t *result); -bool hc_result_get_success(hc_sock_t *s, hc_result_t *result); -void hc_result_free(hc_result_t *result); -#endif - /* Object */ -// FIXME -#define MAXSZ_HC_SUBSCRIPTION 1 - #define MAXSZ_HC_OBJECT \ MAX8(MAXSZ_HC_CONNECTION, MAXSZ_HC_LISTENER, MAXSZ_HC_ROUTE, MAXSZ_HC_FACE, \ - MAXSZ_HC_PUNTING, MAXSZ_HC_STRATEGY, MAXSZ_HC_POLICY, \ - MAXSZ_HC_SUBSCRIPTION) + MAXSZ_HC_PUNTING, MAXSZ_HC_STRATEGY, MAXSZ_HC_POLICY, MAXSZ_HC_STATS) typedef struct { hc_action_t action; @@ -244,10 +214,6 @@ typedef struct { // NEW API CALLS -// XXX private ? -int _hc_execute(hc_sock_t *s, hc_action_t action, hc_object_type_t object_type, - hc_object_t *object, hc_result_callback_t callback, - void *callback_data, hc_data_t **pdata); int hc_execute(hc_sock_t *s, hc_action_t action, hc_object_type_t object_type, hc_object_t *object, hc_data_t **pdata); int hc_execute_async(hc_sock_t *s, hc_action_t action, @@ -289,11 +255,6 @@ int hc_connection_set_priority(hc_sock_t *s, const char *conn_id_or_name, int hc_connection_set_tags(hc_sock_t *s, const char *conn_id_or_name, policy_tags_t tags); -/* -int hc_connection_remove_by_id(hc_sock_t * s, char * name); -int hc_connection_remove_by_name(hc_sock_t * s, char * name); -*/ - int hc_connection_set_admin_state(hc_sock_t *s, const char *conn_id_or_name, face_state_t state); int hc_connection_set_priority(hc_sock_t *s, const char *conn_id_or_name, @@ -357,8 +318,9 @@ int hc_punting_list(hc_sock_t *s, hc_data_t **pdata); int hc_subscription_create(hc_sock_t *s, hc_subscription_t *subscription); int hc_subscription_delete(hc_sock_t *s, hc_subscription_t *subscription); -int hc_stats_get(hc_sock_t *s, hc_data_t **pdata); // General stats -int hc_stats_list(hc_sock_t *s, hc_data_t **pdata); // Per-face stats -int hc_stats_snprintf(char *s, size_t size, const hicn_light_stats_t *stats); +int hc_stats_list(hc_sock_t *s, hc_data_t **pdata); +int hc_stats_snprintf(char *s, size_t size, const hc_stats_t *stats); +int hc_face_stats_list(hc_sock_t *s, hc_data_t **pdata); +int hc_face_stats_snprintf(char *s, size_t size, const hc_face_stats_t *stats); #endif /* HICNTRL_API */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h b/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h index 34667cc1b..426b82fa9 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h @@ -91,8 +91,8 @@ typedef enum { _(active_interface_update, ACTIVE_INTERFACE_UPDATE) \ _(subscription_add, SUBSCRIPTION_ADD) \ _(subscription_remove, SUBSCRIPTION_REMOVE) \ - _(stats_get, STATS_GET) \ - _(stats_list, STATS_LIST) + _(stats_list, STATS_LIST) \ + _(face_stats_list, FACE_STATS_LIST) typedef enum { COMMAND_TYPE_UNDEFINED, @@ -339,12 +339,12 @@ typedef struct { // General stats typedef struct { void *_; -} cmd_stats_get_t; +} cmd_stats_list_t; // Per-face stats typedef struct { void *_; -} cmd_stats_list_t; +} cmd_face_stats_list_t; typedef void *cmd_active_interface_update_t; @@ -498,14 +498,9 @@ typedef struct { /* Statistics */ +// General stats typedef struct { - cmd_header_t header; - hicn_light_stats_t payload; -} msg_stats_get_reply_t; - -typedef struct { - uint32_t id; - connection_stats_t stats; + hc_stats_t stats; } cmd_stats_list_item_t; typedef struct { @@ -513,6 +508,16 @@ typedef struct { cmd_stats_list_item_t payload; } msg_stats_list_reply_t; +// Per-face stats +typedef struct { + hc_face_stats_t stats; +} cmd_face_stats_list_item_t; + +typedef struct { + cmd_header_t header; + cmd_face_stats_list_item_t payload; +} msg_face_stats_list_reply_t; + //===== size of commands ====== // REMINDER: when a new_command is added, the following switch has to be // updated. diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/object.h b/ctrl/libhicnctrl/includes/hicn/ctrl/object.h index c659d1824..74b88c515 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/object.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/object.h @@ -22,17 +22,7 @@ #define HICNCTRL_OBJECT_H #include <hicn/ctrl/object_type.h> - -#include <hicn/ctrl/objects/listener.h> -#include <hicn/ctrl/objects/connection.h> -#include <hicn/ctrl/objects/route.h> -#include <hicn/ctrl/objects/punting.h> -#include <hicn/ctrl/objects/strategy.h> -#include <hicn/ctrl/objects/policy.h> -#include <hicn/ctrl/objects/subscription.h> -#include <hicn/ctrl/objects/cache.h> -#include <hicn/ctrl/objects/mapme.h> -#include <hicn/ctrl/objects/active_interface.h> +#include <hicn/ctrl/objects.h> typedef union { hc_connection_t connection; @@ -41,6 +31,8 @@ typedef union { hc_face_t face; // hc_data_t *data; hc_punting_t punting; + hc_stats_t stats; + hc_face_stats_t face_stats; hc_strategy_t strategy; hc_policy_t policy; hc_subscription_t subscription; diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/object_type.h b/ctrl/libhicnctrl/includes/hicn/ctrl/object_type.h index 39a2d188e..4c5a8c425 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/object_type.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/object_type.h @@ -38,6 +38,7 @@ _(SUBSCRIPTION) \ _(ACTIVE_INTERFACE) \ _(STATS) \ + _(FACE_STATS) \ _(N) typedef enum { diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects.h index 4f560a2f3..5509f99a8 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/objects.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects.h @@ -5,7 +5,13 @@ #include <hicn/ctrl/objects/face.h> #include <hicn/ctrl/objects/listener.h> #include <hicn/ctrl/objects/route.h> +#include <hicn/ctrl/objects/punting.h> +#include <hicn/ctrl/objects/stats.h> #include <hicn/ctrl/objects/strategy.h> +#include <hicn/ctrl/objects/policy.h> #include <hicn/ctrl/objects/subscription.h> +#include <hicn/ctrl/objects/cache.h> +#include <hicn/ctrl/objects/mapme.h> +#include <hicn/ctrl/objects/active_interface.h> #endif /* HICNCTRL_OBJECTS_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/objects/stats.h b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/stats.h new file mode 100644 index 000000000..31c590dee --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/objects/stats.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021-2022 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. + */ + +/** + * \file objects/stats.h + * \brief Stats. + */ + +#ifndef HICNCTRL_OBJECTS_STATS_H +#define HICNCTRL_OBJECTS_STATS_H + +#define MAXSZ_HC_STATS 600 + +typedef hicn_light_stats_t hc_stats_t; +typedef connection_stats_t hc_face_stats_t; + +#endif /* HICNCTRL_OBJECTS_STATS_H */ diff --git a/ctrl/libhicnctrl/src/CMakeLists.txt b/ctrl/libhicnctrl/src/CMakeLists.txt index a9a7d3db4..5dbd70ffe 100644 --- a/ctrl/libhicnctrl/src/CMakeLists.txt +++ b/ctrl/libhicnctrl/src/CMakeLists.txt @@ -41,6 +41,7 @@ set(SOURCE_FILES objects/listener.c objects/route.c objects/strategy.c + objects/stats.c objects/subscription.c parse.c request.c @@ -56,6 +57,7 @@ set(HEADER_FILES objects/face.h objects/listener.h objects/route.h + objects/stats.h objects/strategy.h objects/subscription.h request.h @@ -114,6 +116,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES Android OR ${CMAKE_SYSTEM_NAME} MATCHES iOS) ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/face.c ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/listener.c ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/route.c + ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/stats.c ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/strategy.c ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/subscription.c ) @@ -122,6 +125,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES Android OR ${CMAKE_SYSTEM_NAME} MATCHES iOS) ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/face.h ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/listener.h ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/route.h + ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/stats.h ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/strategy.h ${CMAKE_CURRENT_SOURCE_DIR}/modules/hicn_light/subscription.h ) diff --git a/ctrl/libhicnctrl/src/commands/command_stats.c b/ctrl/libhicnctrl/src/commands/command_stats.c index 7c58b105e..f02a68069 100644 --- a/ctrl/libhicnctrl/src/commands/command_stats.c +++ b/ctrl/libhicnctrl/src/commands/command_stats.c @@ -3,16 +3,16 @@ /* Commands */ -static const command_parser_t command_stats_get = { - .action = ACTION_GET, +static const command_parser_t command_stats_list = { + .action = ACTION_LIST, .object_type = OBJECT_TYPE_STATS, .nparams = 0, }; -COMMAND_REGISTER(command_stats_get); +COMMAND_REGISTER(command_stats_list); -static const command_parser_t command_stats_list = { +static const command_parser_t command_face_stats_list = { .action = ACTION_LIST, - .object_type = OBJECT_TYPE_STATS, + .object_type = OBJECT_TYPE_FACE_STATS, .nparams = 0, }; -COMMAND_REGISTER(command_stats_list); +COMMAND_REGISTER(command_face_stats_list); diff --git a/ctrl/libhicnctrl/src/modules/CMakeLists.txt b/ctrl/libhicnctrl/src/modules/CMakeLists.txt index 682192c6c..b1b63a5f9 100644 --- a/ctrl/libhicnctrl/src/modules/CMakeLists.txt +++ b/ctrl/libhicnctrl/src/modules/CMakeLists.txt @@ -20,6 +20,7 @@ list(APPEND HICNLIGHT_MODULE_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/face.c ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/listener.c ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/route.c + ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/stats.c ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/strategy.c ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/subscription.c ) @@ -30,6 +31,7 @@ list(APPEND HICNLIGHT_MODULE_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/face.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/listener.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/route.h + ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/stats.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/strategy.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn_light/subscription.h ) diff --git a/ctrl/libhicnctrl/src/modules/hicn_light.c b/ctrl/libhicnctrl/src/modules/hicn_light.c index 729d98f89..379cd2fa9 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light.c +++ b/ctrl/libhicnctrl/src/modules/hicn_light.c @@ -41,6 +41,7 @@ #include "../objects/connection.h" // hc_connection_has_local #include "../objects/listener.h" // hc_listener_is_local #include "../objects/route.h" // hc_route_has_face +#include "../objects/stats.h" #include "../request.h" #include "../socket_private.h" #include "hicn_light.h" @@ -50,6 +51,7 @@ #include "hicn_light/listener.h" #include "hicn_light/face.h" #include "hicn_light/route.h" +#include "hicn_light/stats.h" #include "hicn_light/strategy.h" #include "hicn_light/subscription.h" @@ -1283,20 +1285,18 @@ static ssize_t hicnlight_prepare(hc_sock_t *sock, hc_request_t *request, break; } - /* - * Generic requests should complete after a single call to hicnlight_send, - * with *pdata = NULL. If *pdata is not NULL, that means the request has - * completed and we can close it. - * It is the responsability of each state machine to complete the request - * otherwise. - */ -#if 1 + /* + * Generic requests should complete after a single call to hicnlight_send, + * with *pdata = NULL. If *pdata is not NULL, that means the request has + * completed and we can close it. + * It is the responsability of each state machine to complete the request + * otherwise. + */ hc_data_t *data = hc_request_get_data(current_request); if (data) { hc_request_set_complete(current_request); return 0; } -#endif return hicnlight_prepare_generic(sock, request, buffer); } @@ -1391,7 +1391,6 @@ int hc_sock_initialize_module(hc_sock_t *s) { * We do this because initialization in the static struct fails with * 'initializer element is not constant' */ -#if 1 hc_sock_light.object_vft[OBJECT_TYPE_LISTENER] = hicnlight_listener_module_ops; hc_sock_light.object_vft[OBJECT_TYPE_CONNECTION] = @@ -1403,11 +1402,13 @@ int hc_sock_initialize_module(hc_sock_t *s) { hc_sock_light.object_vft[OBJECT_TYPE_WLDR] = HC_MODULE_OBJECT_OPS_EMPTY; hc_sock_light.object_vft[OBJECT_TYPE_POLICY] = HC_MODULE_OBJECT_OPS_EMPTY; hc_sock_light.object_vft[OBJECT_TYPE_ROUTE] = hicnlight_route_module_ops; + hc_sock_light.object_vft[OBJECT_TYPE_STATS] = hicnlight_stats_module_ops; + hc_sock_light.object_vft[OBJECT_TYPE_FACE_STATS] = + hicnlight_face_stats_module_ops; hc_sock_light.object_vft[OBJECT_TYPE_STRATEGY] = hicnlight_strategy_module_ops; hc_sock_light.object_vft[OBJECT_TYPE_SUBSCRIPTION] = hicnlight_subscription_module_ops; -#endif if (s) s->ops = hc_sock_light; return 0; diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/base.h b/ctrl/libhicnctrl/src/modules/hicn_light/base.h index fb6a68147..ea6fc1bc9 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/base.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/base.h @@ -3,16 +3,13 @@ #include <hicn/ctrl/hicn-light.h> -#if 1 #ifdef __APPLE__ #define RANDBYTE() (u8)(arc4random() & 0xFF) #else #define RANDBYTE() (u8)(random() & 0xFF) #endif -#else -#define RANDBYTE() (u8)(rand() & 0xFF) -#endif +// TODO: is this used? #define foreach_hc_command \ _(connection_add) \ _(connection_remove) \ @@ -36,14 +33,6 @@ _(subscription_add) \ _(subscription_remove) -#if 0 -const char *command_type_str[] = { -#define _(l, u) [COMMAND_TYPE_##u] = STRINGIZE(u), - foreach_command_type -#undef _ -}; -#endif - typedef union { #define _(x) cmd_##x##_t x; foreach_hc_command diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/connection.h b/ctrl/libhicnctrl/src/modules/hicn_light/connection.h index 77204e6b2..21f3a2fbc 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/connection.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/connection.h @@ -6,22 +6,6 @@ int hc_connection_to_local_listener(const hc_connection_t *connection, hc_listener_t *listener); -#if 1 - DECLARE_MODULE_OBJECT_OPS_H(hicnlight, connection); -// extern const hc_module_object_ops_t hicnlight_connection_module_ops; - -#else - -int _hicnlight_connection_parse(const uint8_t *buffer, size_t size, - hc_object_t *object); - -int hicnlight_connection_serialize_create(const hc_object_t *object, - uint8_t *packet); -int hicnlight_connection_serialize_delete(const hc_object_t *object, - uint8_t *packet); -int hicnlight_connection_serialize_list(const hc_object_t *object, - uint8_t *packet); -#endif #endif /* HICNCTRL_MODULE_HICNLIGHT_CONNECTION_H */ diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/listener.h b/ctrl/libhicnctrl/src/modules/hicn_light/listener.h index 27ef8434d..67eadfbb1 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/listener.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/listener.h @@ -3,19 +3,6 @@ #include "../../module.h" -#if 1 DECLARE_MODULE_OBJECT_OPS_H(hicnlight, listener); -#else - -int _hicnlight_listener_parse(const uint8_t *buffer, size_t size, - hc_object_t *object); - -int hicnlight_listener_serialize_create(const hc_object_t *object, - uint8_t *packet); -int hicnlight_listener_serialize_delete(const hc_object_t *object, - uint8_t *packet); -int hicnlight_listener_serialize_list(const hc_object_t *object, - uint8_t *packet); -#endif #endif /* HICNCTRL_MODULE_HICNLIGHT_LISTENER_H */ diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/route.h b/ctrl/libhicnctrl/src/modules/hicn_light/route.h index e86e8b8c3..825253a42 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/route.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/route.h @@ -23,20 +23,6 @@ #include "../../module.h" -#if 1 - DECLARE_MODULE_OBJECT_OPS_H(hicnlight, route); -#else - -int _hicnlight_route_parse(const uint8_t *buffer, size_t size, - hc_object_t *object); -int hicnlight_route_serialize_create(const hc_object_t *object, - uint8_t *packet); -int hicnlight_route_serialize_delete(const hc_object_t *object, - uint8_t *packet); -int hicnlight_route_serialize_list(const hc_object_t *object, uint8_t *packet); - -#endif - #endif /* HICNCTRL_MODULE_HICNLIGHT_ROUTE_H */ diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/stats.c b/ctrl/libhicnctrl/src/modules/hicn_light/stats.c new file mode 100644 index 000000000..81c506770 --- /dev/null +++ b/ctrl/libhicnctrl/src/modules/hicn_light/stats.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 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. + */ + +/** + * \file modules/hicn_light/stats.c + * \brief Implementation of stats object VFT for hicn_light. + */ + +#include <hicn/util/log.h> +#include "base.h" +#include "stats.h" + +/* GENERAL STATS */ + +int hicnlight_stats_parse(const uint8_t *buffer, size_t size, + hc_stats_t *stats) { + if (size != sizeof(cmd_stats_list_item_t)) return -1; + + cmd_stats_list_item_t *item = (cmd_stats_list_item_t *)buffer; + *stats = item->stats; + return 0; +} + +int _hicnlight_stats_parse(const uint8_t *buffer, size_t size, + hc_object_t *object) { + return hicnlight_stats_parse(buffer, size, &object->stats); +} + +int hicnlight_stats_serialize_create(const hc_object_t *object, + uint8_t *packet) { + return -1; +} + +int hicnlight_stats_serialize_delete(const hc_object_t *object, + uint8_t *packet) { + return -1; +} + +int hicnlight_stats_serialize_list(const hc_object_t *object, uint8_t *packet) { + msg_stats_list_t *msg = (msg_stats_list_t *)packet; + *msg = (msg_stats_list_t){.header = { + .message_type = REQUEST_LIGHT, + .command_id = COMMAND_TYPE_STATS_LIST, + .length = 0, + .seq_num = 0, + }}; + + return sizeof(msg_header_t); // Do not use msg_stats_list_t +} + +DECLARE_MODULE_OBJECT_OPS(hicnlight, stats); + +/* PER-FACE STATS */ + +int hicnlight_face_stats_parse(const uint8_t *buffer, size_t size, + hc_face_stats_t *stats) { + if (size != sizeof(cmd_face_stats_list_item_t)) return -1; + + cmd_face_stats_list_item_t *item = (cmd_face_stats_list_item_t *)buffer; + *stats = item->stats; + return 0; +} + +int _hicnlight_face_stats_parse(const uint8_t *buffer, size_t size, + hc_object_t *object) { + return hicnlight_face_stats_parse(buffer, size, &object->face_stats); +} + +int hicnlight_face_stats_serialize_create(const hc_object_t *object, + uint8_t *packet) { + return -1; +} + +int hicnlight_face_stats_serialize_delete(const hc_object_t *object, + uint8_t *packet) { + return -1; +} + +int hicnlight_face_stats_serialize_list(const hc_object_t *object, + uint8_t *packet) { + msg_face_stats_list_t *msg = (msg_face_stats_list_t *)packet; + *msg = (msg_face_stats_list_t){.header = { + .message_type = REQUEST_LIGHT, + .command_id = COMMAND_TYPE_FACE_STATS_LIST, + .length = 0, + .seq_num = 0, + }}; + + return sizeof(msg_header_t); // Do not use msg_stats_list_t +} + +DECLARE_MODULE_OBJECT_OPS(hicnlight, face_stats); diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/stats.h b/ctrl/libhicnctrl/src/modules/hicn_light/stats.h index 34594bb72..9509be86c 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/stats.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/stats.h @@ -1,26 +1,24 @@ +/* + * Copyright (c) 2022 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. + */ -#if 0 +#ifndef HICNCTRL_MODULE_HICNLIGHT_STATS_H +#define HICNCTRL_MODULE_HICNLIGHT_STATS_H -int hc_stats_snprintf(char *s, size_t size, const hicn_light_stats_t *stats) { - return snprintf( - s, size, - "pkts processed: %u\n\tinterests: %u\n\t" - "data: %u\npkts from cache count: %u\npkts no pit count: " - "%u\nexpired:\n\t interests: " - "%u\n\t data: %u\ninterests aggregated: " - "%u\nlru evictions: " - "%u\ndropped: " - "%u\ninterests retx: " - "%u\npit entries: %u\ncs entries: %u", - stats->forwarder.countReceived, stats->forwarder.countInterestsReceived, - stats->forwarder.countObjectsReceived, - stats->forwarder.countInterestsSatisfiedFromStore, - stats->forwarder.countDroppedNoReversePath, - stats->forwarder.countInterestsExpired, stats->forwarder.countDataExpired, - stats->pkt_cache.n_lru_evictions, stats->forwarder.countDropped, - stats->forwarder.countInterestsAggregated, - stats->forwarder.countInterestsRetransmitted, - stats->pkt_cache.n_pit_entries, stats->pkt_cache.n_cs_entries); -} +#include "../../module.h" -#endif +DECLARE_MODULE_OBJECT_OPS_H(hicnlight, stats); +DECLARE_MODULE_OBJECT_OPS_H(hicnlight, face_stats); + +#endif /* HICNCTRL_MODULE_HICNLIGHT_STATS_H */ diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/strategy.h b/ctrl/libhicnctrl/src/modules/hicn_light/strategy.h index 6b1933960..9fa809751 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/strategy.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/strategy.h @@ -3,22 +3,6 @@ #include "../../module.h" -#if 1 - DECLARE_MODULE_OBJECT_OPS_H(hicnlight, strategy); -int _hicnlight_strategy_parse(const uint8_t *buffer, size_t size, - hc_object_t *object); - -int hicnlight_strategy_serialize_create(const hc_object_t *object, - uint8_t *packet); - -int hicnlight_strategy_serialize_delete(const hc_object_t *object, - uint8_t *packet); - -int hicnlight_strategy_serialize_list(const hc_object_t *object, - uint8_t *packet); - -#endif - #endif /* HICNCTRL_MODULE_HICNLIGHT_STRATEGY_H */ diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/subscription.h b/ctrl/libhicnctrl/src/modules/hicn_light/subscription.h index a4edf556b..d67bdd9ba 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/subscription.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/subscription.h @@ -3,24 +3,6 @@ #include "../../module.h" -#if 1 - DECLARE_MODULE_OBJECT_OPS_H(hicnlight, subscription); -#else - -int _hicnlight_subscription_parse(const uint8_t *buffer, size_t size, - hc_object_t *object); - -int hicnlight_subscription_serialize_create(const hc_object_t *object, - uint8_t *packet); - -int hicnlight_subscription_serialize_delete(const hc_object_t *object, - uint8_t *packet); - -int hicnlight_subscription_serialize_list(const hc_object_t *object, - uint8_t *packet); - -#endif - #endif /* HICNCTRL_MODULE_HICNLIGHT_SUBSCRIPTION_H */ diff --git a/ctrl/libhicnctrl/src/object_vft.c b/ctrl/libhicnctrl/src/object_vft.c index 808c0f913..01d2dab88 100644 --- a/ctrl/libhicnctrl/src/object_vft.c +++ b/ctrl/libhicnctrl/src/object_vft.c @@ -4,6 +4,7 @@ #include "objects/connection.h" #include "objects/route.h" #include "objects/face.h" +#include "objects/stats.h" #include "objects/strategy.h" #include "objects/subscription.h" #include "objects/active_interface.h" @@ -13,6 +14,8 @@ const hc_object_ops_t *object_vft[] = { [OBJECT_TYPE_CONNECTION] = &hc_connection_ops, [OBJECT_TYPE_ROUTE] = &hc_route_ops, [OBJECT_TYPE_FACE] = &hc_face_ops, + [OBJECT_TYPE_FACE_STATS] = &hc_face_stats_ops, + [OBJECT_TYPE_STATS] = &hc_stats_ops, [OBJECT_TYPE_STRATEGY] = &hc_strategy_ops, [OBJECT_TYPE_SUBSCRIPTION] = &hc_subscription_ops, [OBJECT_TYPE_ACTIVE_INTERFACE] = &hc_active_interface_ops, diff --git a/ctrl/libhicnctrl/src/objects/stats.c b/ctrl/libhicnctrl/src/objects/stats.c index 2c3135d3c..f9d0e1de7 100644 --- a/ctrl/libhicnctrl/src/objects/stats.c +++ b/ctrl/libhicnctrl/src/objects/stats.c @@ -18,42 +18,91 @@ * \brief Implementation of stats. */ -#include <string.h> - #include <hicn/ctrl/api.h> -#include <hicn/ctrl/object.h> -#include <hicn/ctrl/objects/stats.h> #include <hicn/util/log.h> #include "../object_vft.h" -#include "../object_private.h" -int hc_stats_snprintf(char *s, size_t size, const hc_stats_t *stats) { -#if 0 - INFO("Connection #%d:", conn_stats->id); - INFO("\tinterests received: %d pkts (%d bytes)", - conn_stats->stats.interests.rx_pkts, - conn_stats->stats.interests.rx_bytes); - INFO("\tinterests transmitted: %d pkts (%d bytes)", - conn_stats->stats.interests.tx_pkts, - conn_stats->stats.interests.tx_bytes); - INFO("\tdata received: %d pkts (%d bytes)", - conn_stats->stats.data.rx_pkts, - conn_stats->stats.data.rx_bytes); - INFO("\tdata transmitted: %d pkts (%d bytes)", - conn_stats->stats.data.tx_pkts, - conn_stats->stats.data.tx_bytes); -#endif +/* GENERAL STATS */ + +int _hc_stats_validate(const hc_object_t *object, bool allow_partial) { + // Nothing to validate return 0; } -int hc_stats_get(hc_sock_t *s, hc_data_t **pdata) { - hc_object_t object; - memset(&object, 0, sizeof(hc_object_t)); - object.listener = *listener; - return hc_execute(s, ACTION_GET, OBJECT_TYPE_STATS, &object, pdata); +int _hc_stats_cmp(const hc_object_t *object1, const hc_object_t *object2) { + ERROR("[_hc_stats_cmp] Not implemented"); + return -1; +} + +int _hc_stats_snprintf(char *s, size_t size, const hc_object_t *object) { + return hc_stats_snprintf(s, size, &object->stats); +} + +int hc_stats_snprintf(char *s, size_t size, const hc_stats_t *stats) { + return snprintf( + s, size, + "*** STATS ***\nreceived = %u (interest = %u, data = %u)\ndropped = %u " + "(interest = %u, data = %u, other = %u)\nforwarded = { interests = " + "%u, data = %u }\ndropped_reason = { connection_not_found = %u, " + "send_failure = %u, no_route_in_fib = %u }\ninterest processing = { " + "aggregated = %u, retransmitted = %u, satisfied_from_cs = %u, " + "expired_interests = %u, expired_data = %u }\ndata processing = { " + "no_reverse_path = %u }\npacket cache = {PIT size = %u, CS size = %u, " + "eviction = %u}", + stats->forwarder.countReceived, stats->forwarder.countInterestsReceived, + stats->forwarder.countObjectsReceived, stats->forwarder.countDropped, + stats->forwarder.countInterestsDropped, + stats->forwarder.countObjectsDropped, stats->forwarder.countOtherDropped, + stats->forwarder.countInterestForwarded, + stats->forwarder.countObjectsForwarded, + stats->forwarder.countDroppedConnectionNotFound, + stats->forwarder.countSendFailures, stats->forwarder.countDroppedNoRoute, + stats->forwarder.countInterestsAggregated, + stats->forwarder.countInterestsRetransmitted, + stats->forwarder.countInterestsSatisfiedFromStore, + stats->forwarder.countInterestsExpired, stats->forwarder.countDataExpired, + stats->forwarder.countDroppedNoReversePath, + stats->pkt_cache.n_pit_entries, stats->pkt_cache.n_cs_entries, + stats->pkt_cache.n_lru_evictions); } int hc_stats_list(hc_sock_t *s, hc_data_t **pdata) { return hc_execute(s, ACTION_LIST, OBJECT_TYPE_STATS, NULL, pdata); } + +DECLARE_OBJECT_OPS(OBJECT_TYPE_STATS, stats); + +/* PER-FACE STATS */ + +int _hc_face_stats_validate(const hc_object_t *object, bool allow_partial) { + // Nothing to validate + return 0; +} + +int _hc_face_stats_cmp(const hc_object_t *object1, const hc_object_t *object2) { + ERROR("[_hc_stats_cmp] Not implemented"); + return -1; +} + +int _hc_face_stats_snprintf(char *s, size_t size, const hc_object_t *object) { + return hc_face_stats_snprintf(s, size, &object->face_stats); +} + +int hc_face_stats_snprintf(char *s, size_t size, const hc_face_stats_t *stats) { + return snprintf( + s, size, + "conn #%u:\tinterests =\t{ rx packets = %u, rx bytes = %u, " + "tx packets = %u, tx bytes = %u }\n\t\tdata =\t\t{ rx packets " + "= %u, rx bytes = %u, " + "tx packets = %u, tx bytes = %u }", + stats->conn_id, stats->interests.rx_pkts, stats->interests.rx_bytes, + stats->interests.tx_pkts, stats->interests.tx_bytes, stats->data.rx_pkts, + stats->data.rx_bytes, stats->data.tx_pkts, stats->data.tx_bytes); +} + +int hc_face_stats_list(hc_sock_t *s, hc_data_t **pdata) { + return hc_execute(s, ACTION_LIST, OBJECT_TYPE_FACE_STATS, NULL, pdata); +} + +DECLARE_OBJECT_OPS(OBJECT_TYPE_FACE_STATS, face_stats);
\ No newline at end of file diff --git a/ctrl/libhicnctrl/src/objects/stats.h b/ctrl/libhicnctrl/src/objects/stats.h new file mode 100644 index 000000000..3a4f04b2e --- /dev/null +++ b/ctrl/libhicnctrl/src/objects/stats.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 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. + */ + +/** + * \file stats.h + * \brief Stats. + */ + +#ifndef HICNCTRL_IMPL_OBJECTS_STATS_H +#define HICNCTRL_IMPL_OBJECTS_STATS_H + +#include "../object_vft.h" + +DECLARE_OBJECT_OPS_H(OBJECT_TYPE_STATS, stats); +DECLARE_OBJECT_OPS_H(OBJECT_TYPE_FACE_STATS, face_stats); + +#endif /* HICNCTRL_IMPL_OBJECTS_STATS_H */
\ No newline at end of file |