]>
Commit | Line | Data |
---|---|---|
39bb53d6 CF |
1 | /* |
2 | * IS-IS Routing protocol - isis_pdu_counter.c | |
3 | * Copyright (C) 2018 Christian Franke, for NetDEF Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the Free | |
7 | * Software Foundation; either version 2 of the License, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
20 | #include <zebra.h> | |
21 | ||
22 | #include "vty.h" | |
23 | ||
24 | #include "isisd/isis_pdu_counter.h" | |
25 | #include "isisd/isisd.h" | |
26 | #include "isisd/isis_circuit.h" | |
27 | #include "isisd/isis_pdu.h" | |
28 | ||
29 | static int pdu_type_to_counter_index(uint8_t pdu_type) | |
30 | { | |
31 | switch (pdu_type) { | |
32 | case L1_LAN_HELLO: | |
33 | return L1_LAN_HELLO_INDEX; | |
34 | case L2_LAN_HELLO: | |
35 | return L2_LAN_HELLO_INDEX; | |
36 | case P2P_HELLO: | |
37 | return P2P_HELLO_INDEX; | |
38 | case L1_LINK_STATE: | |
39 | return L1_LINK_STATE_INDEX; | |
40 | case L2_LINK_STATE: | |
41 | return L2_LINK_STATE_INDEX; | |
42 | case FS_LINK_STATE: | |
43 | return FS_LINK_STATE_INDEX; | |
44 | case L1_COMPLETE_SEQ_NUM: | |
45 | return L1_COMPLETE_SEQ_NUM_INDEX; | |
46 | case L2_COMPLETE_SEQ_NUM: | |
47 | return L2_COMPLETE_SEQ_NUM_INDEX; | |
48 | case L1_PARTIAL_SEQ_NUM: | |
49 | return L1_PARTIAL_SEQ_NUM_INDEX; | |
50 | case L2_PARTIAL_SEQ_NUM: | |
51 | return L2_PARTIAL_SEQ_NUM_INDEX; | |
52 | default: | |
53 | return -1; | |
54 | } | |
55 | } | |
56 | ||
57 | static const char *pdu_counter_index_to_name(enum pdu_counter_index index) | |
58 | { | |
89cdc4df | 59 | switch (index) { |
39bb53d6 CF |
60 | case L1_LAN_HELLO_INDEX: |
61 | return " L1 IIH"; | |
62 | case L2_LAN_HELLO_INDEX: | |
63 | return " L2 IIH"; | |
64 | case P2P_HELLO_INDEX: | |
65 | return "P2P IIH"; | |
66 | case L1_LINK_STATE_INDEX: | |
67 | return " L1 LSP"; | |
68 | case L2_LINK_STATE_INDEX: | |
69 | return " L2 LSP"; | |
70 | case FS_LINK_STATE_INDEX: | |
71 | return " FS LSP"; | |
72 | case L1_COMPLETE_SEQ_NUM_INDEX: | |
73 | return "L1 CSNP"; | |
74 | case L2_COMPLETE_SEQ_NUM_INDEX: | |
75 | return "L2 CSNP"; | |
76 | case L1_PARTIAL_SEQ_NUM_INDEX: | |
77 | return "L1 PSNP"; | |
78 | case L2_PARTIAL_SEQ_NUM_INDEX: | |
79 | return "L2 PSNP"; | |
80 | default: | |
81 | return "???????"; | |
82 | } | |
83 | } | |
84 | ||
85 | void pdu_counter_count(pdu_counter_t counter, uint8_t pdu_type) | |
86 | { | |
87 | int index = pdu_type_to_counter_index(pdu_type); | |
88 | ||
89 | if (index < 0) | |
90 | return; | |
91 | ||
92 | counter[index]++; | |
93 | } | |
94 | ||
95 | void pdu_counter_print(struct vty *vty, const char *prefix, | |
96 | pdu_counter_t counter) | |
97 | { | |
98 | for (int i = 0; i < PDU_COUNTER_SIZE; i++) { | |
99 | if (!counter[i]) | |
100 | continue; | |
101 | vty_out(vty, "%s%s: %" PRIu64 "\n", prefix, | |
102 | pdu_counter_index_to_name(i), counter[i]); | |
103 | } | |
104 | } |