summaryrefslogtreecommitdiffstats
path: root/src/plugins/cdp/cdp_node.c
blob: f9ee251c022da986a880fdbe2bf3ca1a4be8109a (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
114
115
116
117
118
119
120
121
122

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { co
/*
 * Copyright (c) 2011-2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/L
incoming announcements, and a "process" node to periodically send announcements. The interior node is neither pipelined nor dual-looped, because it would be very unusual to see more than one CDP packet in a given input frame. So, it's a very simple / straightforward example. */ /* * packet counter strings * Dump these counters via the "show error" CLI command */ static char *cdp_error_strings[] = { #define _(sym,string) string, foreach_cdp_error #undef _ }; /* * We actually send all cdp pkts to the "error" node after scanning * them, so the graph node has only one next-index. The "error-drop" * node automatically bumps our per-node packet counters for us. */ typedef enum { CDP_INPUT_NEXT_NORMAL, CDP_INPUT_N_NEXT, } cdp_next_t; /* * Process a frame of cdp packets * Expect 1 packet / frame */ static uword cdp_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { u32 n_left_from, *from; cdp_input_trace_t *t0; from = vlib_frame_vector_args (frame); /* array of buffer indices */ n_left_from = frame->n_vectors; /* number of buffer indices */ while (n_left_from > 0) { u32 bi0; vlib_buffer_t *b0; u32 next0, error0; bi0 = from[0]; b0 = vlib_get_buffer (vm, bi0); next0 = CDP_INPUT_NEXT_NORMAL; /* scan this cdp pkt. error0 is the counter index to bump */ error0 = cdp_input (vm, b0, bi0); b0->error = node->errors[error0]; /* If this pkt is traced, snapshoot the data */ if (b0->flags & VLIB_BUFFER_IS_TRACED) { int len; t0 = vlib_add_trace (vm, node, b0, sizeof (*t0)); len = (b0->current_length < sizeof (t0->data)) ? b0->current_length : sizeof (t0->data); t0->len = len; clib_memcpy (t0->data, vlib_buffer_get_current (b0), len); } /* push this pkt to the next graph node, always error-drop */ vlib_set_next_frame_buffer (vm, node, next0, bi0); from += 1; n_left_from -= 1; } return frame->n_vectors; } /* * cdp input graph node declaration */ /* *INDENT-OFF* */ VLIB_REGISTER_NODE (cdp_input_node, static) = { .function = cdp_node_fn, .name = "cdp-input", .vector_size = sizeof (u32), .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = CDP_N_ERROR, .error_strings = cdp_error_strings, .format_trace = cdp_input_format_trace, .n_next_nodes = CDP_INPUT_N_NEXT, .next_nodes = { [CDP_INPUT_NEXT_NORMAL] = "error-drop", }, }; /* *INDENT-ON* */ /* * cdp periodic function */ static uword cdp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) { cdp_main_t *cm = &cdp_main; f64 poll_time_remaining; uword event_type, *event_data = 0; /* Start w/ cdp disabled */ poll_time_remaining = 86400.0; while (1) { /* sleep until next poll time, or msg serialize event occurs */ poll_time_remaining = vlib_process_wait_for_event_or_clock (vm, poll_time_remaining); event_type = vlib_process_get_events (vm, &event_data); switch (event_type) { case ~0: /* no events => timeout */ break; case CDP_EVENT_ENABLE: if (!cm->cdp_protocol_registered) { /* * Dynamically register the cdp input node * with the snap classifier */ snap_register_input_protocol (vm, "cdp-input", 0xC /* ieee_oui, Cisco */ , 0x2000 /* protocol CDP */ , cdp_input_node.index); snap_register_input_protocol (vm, "cdp-input", 0xC /* ieee_oui, Cisco */ , 0x2004 /* protocol CDP */ , cdp_input_node.index); #if 0 /* * Keep this code for reference... * Register with the hdlc classifier */ hdlc_register_input_protocol (vm, HDLC_PROTOCOL_cdp, cdp_input_node.index); #endif /* with ethernet input (for SRP) */ ethernet_register_input_type (vm, ETHERNET_TYPE_CDP /* CDP */ , cdp_input_node.index); cm->cdp_protocol_registered = 1; } poll_time_remaining = 10.0; break; case CDP_EVENT_DISABLE: poll_time_remaining = 86400.0; break; default: clib_warning ("BUG: event type 0x%wx", event_type); break; } vec_reset_length (event_data); /* peer timeout scan, send announcements */ if (vlib_process_suspend_time_is_zero (poll_time_remaining)) { cdp_periodic (vm); poll_time_remaining = 10.0; } } return 0; } void vnet_cdp_create_periodic_process (cdp_main_t * cmp) { /* Already created the process node? */ if (cmp->cdp_process_node_index > 0) return; /* No, create it now and make a note of the node index */ cmp->cdp_process_node_index = vlib_process_create (cmp->vlib_main, "cdp-process", cdp_process, 16 /* log2_n_stack_bytes */ ); } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */