1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IS-IS Routing protocol - isis_pdu_counter.c
4 * Copyright (C) 2018 Christian Franke, for NetDEF Inc.
11 #include "isisd/isisd.h"
12 #include "isisd/isis_circuit.h"
13 #include "isisd/isis_pdu.h"
14 #include "isisd/isis_pdu_counter.h"
16 static int pdu_type_to_counter_index(uint8_t pdu_type
)
20 return L1_LAN_HELLO_INDEX
;
22 return L2_LAN_HELLO_INDEX
;
24 return P2P_HELLO_INDEX
;
26 return L1_LINK_STATE_INDEX
;
28 return L2_LINK_STATE_INDEX
;
30 return FS_LINK_STATE_INDEX
;
31 case L1_COMPLETE_SEQ_NUM
:
32 return L1_COMPLETE_SEQ_NUM_INDEX
;
33 case L2_COMPLETE_SEQ_NUM
:
34 return L2_COMPLETE_SEQ_NUM_INDEX
;
35 case L1_PARTIAL_SEQ_NUM
:
36 return L1_PARTIAL_SEQ_NUM_INDEX
;
37 case L2_PARTIAL_SEQ_NUM
:
38 return L2_PARTIAL_SEQ_NUM_INDEX
;
44 static const char *pdu_counter_index_to_name(enum pdu_counter_index index
)
47 case L1_LAN_HELLO_INDEX
:
49 case L2_LAN_HELLO_INDEX
:
53 case L1_LINK_STATE_INDEX
:
55 case L2_LINK_STATE_INDEX
:
57 case FS_LINK_STATE_INDEX
:
59 case L1_COMPLETE_SEQ_NUM_INDEX
:
61 case L2_COMPLETE_SEQ_NUM_INDEX
:
63 case L1_PARTIAL_SEQ_NUM_INDEX
:
65 case L2_PARTIAL_SEQ_NUM_INDEX
:
67 case PDU_COUNTER_SIZE
:
71 assert(!"Reached end of function where we were not expecting to");
74 void pdu_counter_count(pdu_counter_t counter
, uint8_t pdu_type
)
76 int index
= pdu_type_to_counter_index(pdu_type
);
84 void pdu_counter_print(struct vty
*vty
, const char *prefix
,
85 pdu_counter_t counter
)
87 for (int i
= 0; i
< PDU_COUNTER_SIZE
; i
++) {
90 vty_out(vty
, "%s%s: %" PRIu64
"\n", prefix
,
91 pdu_counter_index_to_name(i
), counter
[i
]);
95 void pdu_counter_count_drop(struct isis_area
*area
, uint8_t pdu_type
)
97 pdu_counter_count(area
->pdu_drop_counters
, pdu_type
);
99 if (area
->log_pdu_drops
) {
101 area
, pdu_counter_index_to_name(
102 pdu_type_to_counter_index(pdu_type
)));
106 uint64_t pdu_counter_get_count(pdu_counter_t counter
, uint8_t pdu_type
)
108 int index
= pdu_type_to_counter_index(pdu_type
);
112 return counter
[index
];