aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/src/objects/stats.c
blob: f9d0e1de73a85280073a332b70af424268e5cf0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * 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 stats.c
 * \brief Implementation of stats.
 */

#include <hicn/ctrl/api.h>
#include <hicn/util/log.h>

#include "../object_vft.h"

/* GENERAL STATS */

int _hc_stats_validate(const hc_object_t *object, bool allow_partial) {
  // Nothing to validate
  return 0;
}

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);