From d2072866a012548f1f9e9bc93d9b8d7a84b654f5 Mon Sep 17 00:00:00 2001 From: "Enrico Loparco (eloparco)" Date: Fri, 23 Sep 2022 15:27:34 +0000 Subject: fix(stats): fix forwarder statistics retrieval Ref: HICN-794 Signed-off-by: Enrico Loparco (eloparco) Change-Id: I13162174f45855989727f92e96c11a1d48d710dd --- ctrl/libhicnctrl/src/modules/CMakeLists.txt | 2 + ctrl/libhicnctrl/src/modules/hicn_light.c | 23 ++--- ctrl/libhicnctrl/src/modules/hicn_light/base.h | 13 +-- .../src/modules/hicn_light/connection.h | 16 ---- ctrl/libhicnctrl/src/modules/hicn_light/listener.h | 13 --- ctrl/libhicnctrl/src/modules/hicn_light/route.h | 14 --- ctrl/libhicnctrl/src/modules/hicn_light/stats.c | 104 +++++++++++++++++++++ ctrl/libhicnctrl/src/modules/hicn_light/stats.h | 44 +++++---- ctrl/libhicnctrl/src/modules/hicn_light/strategy.h | 16 ---- .../src/modules/hicn_light/subscription.h | 18 ---- 10 files changed, 140 insertions(+), 123 deletions(-) create mode 100644 ctrl/libhicnctrl/src/modules/hicn_light/stats.c (limited to 'ctrl/libhicnctrl/src/modules') 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 -#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 +#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 */ -- cgit 1.2.3-korg