]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_pdu_counter.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / isisd / isis_pdu_counter.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * IS-IS Routing protocol - isis_pdu_counter.c
4 * Copyright (C) 2018 Christian Franke, for NetDEF Inc.
5 */
6
7 #include <zebra.h>
8
9 #include "vty.h"
10
11 #include "isisd/isis_pdu_counter.h"
12 #include "isisd/isisd.h"
13 #include "isisd/isis_circuit.h"
14 #include "isisd/isis_pdu.h"
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 {
46 switch (index) {
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";
67 case PDU_COUNTER_SIZE:
68 return "???????";
69 }
70
71 assert(!"Reached end of function where we were not expecting to");
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 }