aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/src/modules/hicn_light
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2022-09-23 15:27:34 +0000
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2022-09-23 15:39:43 +0000
commitd2072866a012548f1f9e9bc93d9b8d7a84b654f5 (patch)
tree02f4900849de793ca68259f5cdf126e91ef5484f /ctrl/libhicnctrl/src/modules/hicn_light
parentadbdfdf7489e1909f29e2dd02edb7d15c258ed19 (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/modules/hicn_light')
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/base.h13
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/connection.h16
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/listener.h13
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/route.h14
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/stats.c104
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/stats.h44
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/strategy.h16
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/subscription.h18
8 files changed, 126 insertions, 112 deletions
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 */