diff options
author | Enrico Loparco (eloparco) <eloparco@cisco.com> | 2022-09-23 15:27:34 +0000 |
---|---|---|
committer | Enrico Loparco (eloparco) <eloparco@cisco.com> | 2022-09-23 15:39:43 +0000 |
commit | d2072866a012548f1f9e9bc93d9b8d7a84b654f5 (patch) | |
tree | 02f4900849de793ca68259f5cdf126e91ef5484f /ctrl/libhicnctrl/src | |
parent | adbdfdf7489e1909f29e2dd02edb7d15c258ed19 (diff) |
fix(stats): fix forwarder statistics retrieval
Ref: HICN-794
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com>
Change-Id: I13162174f45855989727f92e96c11a1d48d710dd
Diffstat (limited to 'ctrl/libhicnctrl/src')
-rw-r--r-- | ctrl/libhicnctrl/src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/commands/command_stats.c | 12 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/CMakeLists.txt | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light.c | 23 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/base.h | 13 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/connection.h | 16 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/listener.h | 13 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/route.h | 14 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/stats.c | 104 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/stats.h | 44 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/strategy.h | 16 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/subscription.h | 18 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/object_vft.c | 3 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/objects/stats.c | 101 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/objects/stats.h | 29 |
15 files changed, 257 insertions, 155 deletions
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 |