summaryrefslogtreecommitdiffstats
path: root/isisd/isis_pdu_counter.c
blob: a3605a32a16234db97ea524d474844565379a6f3 (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
109
110
111
112
113
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * IS-IS Routing protocol - isis_pdu_counter.c
 * Copyright (C) 2018 Christian Franke, for NetDEF Inc.
 */

#include <zebra.h>

#include "vty.h"

#include "isisd/isisd.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_pdu.h"
#include "isisd/isis_pdu_counter.h"

static int pdu_type_to_counter_index(uint8_t pdu_type)
{
	switch (pdu_type) {
	case L1_LAN_HELLO:
		return L1_LAN_HELLO_INDEX;
	case L2_LAN_HELLO:
		return L2_LAN_HELLO_INDEX;
	case P2P_HELLO:
		return P2P_HELLO_INDEX;
	case L1_LINK_STATE:
		return L1_LINK_STATE_INDEX;
	case L2_LINK_STATE:
		return L2_LINK_STATE_INDEX;
	case FS_LINK_STATE:
		return FS_LINK_STATE_INDEX;
	case L1_COMPLETE_SEQ_NUM:
		return L1_COMPLETE_SEQ_NUM_INDEX;
	case L2_COMPLETE_SEQ_NUM:
		return L2_COMPLETE_SEQ_NUM_INDEX;
	case L1_PARTIAL_SEQ_NUM:
		return L1_PARTIAL_SEQ_NUM_INDEX;
	case L2_PARTIAL_SEQ_NUM:
		return L2_PARTIAL_SEQ_NUM_INDEX;
	default:
		return -1;
	}
}

static const char *pdu_counter_index_to_name(enum pdu_counter_index index)
{
	switch (index) {
	case L1_LAN_HELLO_INDEX:
		return " L1 IIH";
	case L2_LAN_HELLO_INDEX:
		return " L2 IIH";
	case P2P_HELLO_INDEX:
		return "P2P IIH";
	case L1_LINK_STATE_INDEX:
		return " L1 LSP";
	case L2_LINK_STATE_INDEX:
		return " L2 LSP";
	case FS_LINK_STATE_INDEX:
		return " FS LSP";
	case L1_COMPLETE_SEQ_NUM_INDEX:
		return "L1 CSNP";
	case L2_COMPLETE_SEQ_NUM_INDEX:
		return "L2 CSNP";
	case L1_PARTIAL_SEQ_NUM_INDEX:
		return "L1 PSNP";
	case L2_PARTIAL_SEQ_NUM_INDEX:
		return "L2 PSNP";
	case PDU_COUNTER_SIZE:
		return "???????";
	}

	assert(!"Reached end of function where we were not expecting to");
}

void pdu_counter_count(pdu_counter_t counter, uint8_t pdu_type)
{
	int index = pdu_type_to_counter_index(pdu_type);

	if (index < 0)
		return;

	counter[index]++;
}

void pdu_counter_print(struct vty *vty, const char *prefix,
		       pdu_counter_t counter)
{
	for (int i = 0; i < PDU_COUNTER_SIZE; i++) {
		if (!counter[i])
			continue;
		vty_out(vty, "%s%s: %" PRIu64 "\n", prefix,
			pdu_counter_index_to_name(i), counter[i]);
	}
}

void pdu_counter_count_drop(struct isis_area *area, uint8_t pdu_type)
{
	pdu_counter_count(area->pdu_drop_counters, pdu_type);

	if (area->log_pdu_drops) {
		isis_log_pdu_drops(
			area, pdu_counter_index_to_name(
				      pdu_type_to_counter_index(pdu_type)));
	}
}

uint64_t pdu_counter_get_count(pdu_counter_t counter, uint8_t pdu_type)
{
	int index = pdu_type_to_counter_index(pdu_type);

	if (index < 0)
		return -1;
	return counter[index];
}