]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
39bb53d6 CF |
2 | /* |
3 | * IS-IS Routing protocol - isis_pdu_counter.c | |
4 | * Copyright (C) 2018 Christian Franke, for NetDEF Inc. | |
39bb53d6 CF |
5 | */ |
6 | ||
7 | #include <zebra.h> | |
8 | ||
9 | #include "vty.h" | |
10 | ||
39bb53d6 CF |
11 | #include "isisd/isisd.h" |
12 | #include "isisd/isis_circuit.h" | |
13 | #include "isisd/isis_pdu.h" | |
4b24eae0 | 14 | #include "isisd/isis_pdu_counter.h" |
39bb53d6 CF |
15 | |
16 | static int pdu_type_to_counter_index(uint8_t pdu_type) | |
17 | { | |
18 | switch (pdu_type) { | |
19 | case L1_LAN_HELLO: | |
20 | return L1_LAN_HELLO_INDEX; | |
21 | case L2_LAN_HELLO: | |
22 | return L2_LAN_HELLO_INDEX; | |
23 | case P2P_HELLO: | |
24 | return P2P_HELLO_INDEX; | |
25 | case L1_LINK_STATE: | |
26 | return L1_LINK_STATE_INDEX; | |
27 | case L2_LINK_STATE: | |
28 | return L2_LINK_STATE_INDEX; | |
29 | case FS_LINK_STATE: | |
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; | |
39 | default: | |
40 | return -1; | |
41 | } | |
42 | } | |
43 | ||
44 | static const char *pdu_counter_index_to_name(enum pdu_counter_index index) | |
45 | { | |
89cdc4df | 46 | switch (index) { |
39bb53d6 CF |
47 | case L1_LAN_HELLO_INDEX: |
48 | return " L1 IIH"; | |
49 | case L2_LAN_HELLO_INDEX: | |
50 | return " L2 IIH"; | |
51 | case P2P_HELLO_INDEX: | |
52 | return "P2P IIH"; | |
53 | case L1_LINK_STATE_INDEX: | |
54 | return " L1 LSP"; | |
55 | case L2_LINK_STATE_INDEX: | |
56 | return " L2 LSP"; | |
57 | case FS_LINK_STATE_INDEX: | |
58 | return " FS LSP"; | |
59 | case L1_COMPLETE_SEQ_NUM_INDEX: | |
60 | return "L1 CSNP"; | |
61 | case L2_COMPLETE_SEQ_NUM_INDEX: | |
62 | return "L2 CSNP"; | |
63 | case L1_PARTIAL_SEQ_NUM_INDEX: | |
64 | return "L1 PSNP"; | |
65 | case L2_PARTIAL_SEQ_NUM_INDEX: | |
66 | return "L2 PSNP"; | |
a348c945 | 67 | case PDU_COUNTER_SIZE: |
39bb53d6 CF |
68 | return "???????"; |
69 | } | |
a348c945 DS |
70 | |
71 | assert(!"Reached end of function where we were not expecting to"); | |
39bb53d6 CF |
72 | } |
73 | ||
74 | void pdu_counter_count(pdu_counter_t counter, uint8_t pdu_type) | |
75 | { | |
76 | int index = pdu_type_to_counter_index(pdu_type); | |
77 | ||
78 | if (index < 0) | |
79 | return; | |
80 | ||
81 | counter[index]++; | |
82 | } | |
83 | ||
84 | void pdu_counter_print(struct vty *vty, const char *prefix, | |
85 | pdu_counter_t counter) | |
86 | { | |
87 | for (int i = 0; i < PDU_COUNTER_SIZE; i++) { | |
88 | if (!counter[i]) | |
89 | continue; | |
90 | vty_out(vty, "%s%s: %" PRIu64 "\n", prefix, | |
91 | pdu_counter_index_to_name(i), counter[i]); | |
92 | } | |
93 | } | |
4b24eae0 IL |
94 | |
95 | void pdu_counter_count_drop(struct isis_area *area, uint8_t pdu_type) | |
96 | { | |
97 | pdu_counter_count(area->pdu_drop_counters, pdu_type); | |
98 | ||
99 | if (area->log_pdu_drops) { | |
100 | isis_log_pdu_drops( | |
101 | area, pdu_counter_index_to_name( | |
102 | pdu_type_to_counter_index(pdu_type))); | |
103 | } | |
104 | } | |
105 | ||
106 | uint64_t pdu_counter_get_count(pdu_counter_t counter, uint8_t pdu_type) | |
107 | { | |
108 | int index = pdu_type_to_counter_index(pdu_type); | |
109 | ||
110 | if (index < 0) | |
111 | return -1; | |
112 | return counter[index]; | |
113 | } |