blob: 21086c02527f9d1f476025b3f3be4c9afbfa13a5 [file] [log] [blame]
Dave Barachced48e72016-02-08 15:57:35 -05001/*
2 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef __included_cdp_node_h__
16#define __included_cdp_node_h__
17
18#include <vlib/vlib.h>
19#include <vlib/unix/unix.h>
20
21#include <vnet/snap/snap.h>
22#include <vnet/hdlc/hdlc.h>
23#include <vnet/hdlc/packet.h>
24
25#include <vppinfra/format.h>
26#include <vppinfra/hash.h>
27
28#include <vnet/cdp/cdp_protocol.h>
29
Dave Barach861bd212016-08-09 08:55:49 -040030typedef enum
31{
32 CDP_PACKET_TEMPLATE_ETHERNET,
33 CDP_PACKET_TEMPLATE_HDLC,
34 CDP_PACKET_TEMPLATE_SRP,
35 CDP_N_PACKET_TEMPLATES,
Dave Barachced48e72016-02-08 15:57:35 -050036} cdp_packet_template_id_t;
37
Dave Barach861bd212016-08-09 08:55:49 -040038typedef struct
39{
40 /* neighbor's vlib software interface index */
41 u32 sw_if_index;
Dave Barachced48e72016-02-08 15:57:35 -050042
Dave Barach861bd212016-08-09 08:55:49 -040043 /* Timers */
44 f64 last_heard;
45 f64 last_sent;
Dave Barachced48e72016-02-08 15:57:35 -050046
Dave Barach861bd212016-08-09 08:55:49 -040047 /* Neighbor time-to-live (usually 180s) */
48 u8 ttl_in_seconds;
Dave Barachced48e72016-02-08 15:57:35 -050049
Dave Barach861bd212016-08-09 08:55:49 -040050 /* "no cdp run" or similar */
51 u8 disabled;
Dave Barachced48e72016-02-08 15:57:35 -050052
Dave Barach861bd212016-08-09 08:55:49 -040053 /* tx packet template id for this neighbor */
54 u8 packet_template_index;
Dave Barachced48e72016-02-08 15:57:35 -050055
Dave Barach861bd212016-08-09 08:55:49 -040056 /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
57 u8 last_packet_signature_valid;
58 uword last_packet_signature;
Dave Barachced48e72016-02-08 15:57:35 -050059
Dave Barach861bd212016-08-09 08:55:49 -040060 /* Info we actually keep about each neighbor */
61 u8 *device_name;
62 u8 *version;
63 u8 *port_id;
64 u8 *platform;
Dave Barachced48e72016-02-08 15:57:35 -050065
Dave Barach861bd212016-08-09 08:55:49 -040066 /* last received packet, for the J-hash optimization */
67 u8 *last_rx_pkt;
Dave Barachced48e72016-02-08 15:57:35 -050068} cdp_neighbor_t;
69
70#define foreach_neighbor_string_field \
71_(device_name) \
72_(version) \
73_(port_id) \
74_(platform)
75
Dave Barach861bd212016-08-09 08:55:49 -040076typedef struct
77{
78 /* pool of cdp neighbors */
79 cdp_neighbor_t *neighbors;
Dave Barachced48e72016-02-08 15:57:35 -050080
Dave Barach861bd212016-08-09 08:55:49 -040081 /* tx pcap debug enable */
82 u8 tx_pcap_debug;
Dave Barachced48e72016-02-08 15:57:35 -050083
Dave Barach861bd212016-08-09 08:55:49 -040084 /* rapidly find a neighbor by vlib software interface index */
85 uword *neighbor_by_sw_if_index;
Dave Barachced48e72016-02-08 15:57:35 -050086
Dave Barach861bd212016-08-09 08:55:49 -040087 /* Background process node index */
88 u32 cdp_process_node_index;
Dave Barachced48e72016-02-08 15:57:35 -050089
Dave Barach861bd212016-08-09 08:55:49 -040090 /* Packet templates for different encap types */
91 vlib_packet_template_t packet_templates[CDP_N_PACKET_TEMPLATES];
Dave Barachced48e72016-02-08 15:57:35 -050092
Dave Barach861bd212016-08-09 08:55:49 -040093 /* convenience variables */
94 vlib_main_t *vlib_main;
95 vnet_main_t *vnet_main;
Dave Barachced48e72016-02-08 15:57:35 -050096} cdp_main_t;
97
Dave Wallace71612d62017-10-24 01:32:41 -040098extern cdp_main_t cdp_main;
Dave Barachced48e72016-02-08 15:57:35 -050099
100/* Packet counters */
101#define foreach_cdp_error \
102_ (NONE, "good cdp packets (processed)") \
103_ (CACHE_HIT, "good cdp packets (cache hit)") \
104_ (BAD_TLV, "cdp packets with bad TLVs") \
105_ (PROTOCOL_VERSION, "cdp packets with bad protocol versions") \
106_ (CHECKSUM, "cdp packets with bad checksums") \
107_ (DISABLED, "cdp packets received on disabled interfaces")
108
Dave Barach861bd212016-08-09 08:55:49 -0400109typedef enum
110{
Dave Barachced48e72016-02-08 15:57:35 -0500111#define _(sym,str) CDP_ERROR_##sym,
112 foreach_cdp_error
113#undef _
Dave Barach861bd212016-08-09 08:55:49 -0400114 CDP_N_ERROR,
Dave Barachced48e72016-02-08 15:57:35 -0500115} cdp_error_t;
116
117/* cdp packet trace capture */
Dave Barach861bd212016-08-09 08:55:49 -0400118typedef struct
119{
120 u32 len;
121 u8 data[400];
Dave Barachced48e72016-02-08 15:57:35 -0500122} cdp_input_trace_t;
123
Dave Barach861bd212016-08-09 08:55:49 -0400124typedef enum
125{
126 CDP_EVENT_SEND_NEIGHBOR,
127 CDP_EVENT_SEND_KEEPALIVE,
Dave Barachced48e72016-02-08 15:57:35 -0500128} cdp_process_event_t;
129
130
131cdp_error_t cdp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0);
132void cdp_periodic (vlib_main_t * vm);
133void cdp_keepalive (cdp_main_t * cm, cdp_neighbor_t * n);
134u16 cdp_checksum (void *p, int count);
Dave Barach861bd212016-08-09 08:55:49 -0400135u8 *cdp_input_format_trace (u8 * s, va_list * args);
Dave Barachced48e72016-02-08 15:57:35 -0500136
137serialize_function_t serialize_cdp_main, unserialize_cdp_main;
138
139#endif /* __included_cdp_node_h__ */
Dave Barach861bd212016-08-09 08:55:49 -0400140
141/*
142 * fd.io coding-style-patch-verification: ON
143 *
144 * Local Variables:
145 * eval: (c-set-style "gnu")
146 * End:
147 */