blob: dc6c66d52c3ee0ce910206016e12b750550c9c7f [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_protocol_h__
16#define __included_cdp_protocol_h__
17
18#include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
19#include <vnet/llc/llc.h>
20#include <vnet/snap/snap.h>
21#include <vnet/srp/packet.h>
22
Dave Barach861bd212016-08-09 08:55:49 -040023typedef CLIB_PACKED (struct
24 {
25 u8 version;
26 u8 ttl;
27 u16 checksum; /* 1's complement of the 1's complement sum */
28 u8 data[0];
29 }) cdp_hdr_t;
Dave Barachced48e72016-02-08 15:57:35 -050030
Dave Barach861bd212016-08-09 08:55:49 -040031typedef struct
32{
Dave Barachced48e72016-02-08 15:57:35 -050033 u8 dst_address[6];
34 u8 src_address[6];
35 u16 len;
36} ethernet_802_3_header_t;
37
Dave Barach861bd212016-08-09 08:55:49 -040038typedef CLIB_PACKED (struct
39 {
40 ethernet_802_3_header_t ethernet;
41 llc_header_t llc; snap_header_t snap; cdp_hdr_t cdp;
42 }) ethernet_llc_snap_and_cdp_header_t;
Dave Barachced48e72016-02-08 15:57:35 -050043
Dave Barach861bd212016-08-09 08:55:49 -040044typedef CLIB_PACKED (struct
45 {
46 hdlc_header_t hdlc; cdp_hdr_t cdp;
47 }) hdlc_and_cdp_header_t;
Dave Barachced48e72016-02-08 15:57:35 -050048
Dave Barach861bd212016-08-09 08:55:49 -040049typedef CLIB_PACKED (struct
50 {
51 srp_header_t srp;
52 ethernet_header_t ethernet; cdp_hdr_t cdp;
53 }) srp_and_cdp_header_t;
Dave Barachced48e72016-02-08 15:57:35 -050054
Dave Barach861bd212016-08-09 08:55:49 -040055typedef CLIB_PACKED (struct
56 {
57 u16 t;
58 u16 l;
59 u8 v[0];
60 }) cdp_tlv_t;
Dave Barachced48e72016-02-08 15:57:35 -050061
62/*
Damjan Marion607de1a2016-08-16 22:53:54 +020063 * TLV codes.
Dave Barachced48e72016-02-08 15:57:35 -050064 */
65#define foreach_cdp_tlv_type \
66_(unused) \
67_(device_name) /* uniquely identifies the device */ \
68_(address) /* list of addresses this device has */ \
69_(port_id) /* port CDP packet was sent out on */ \
70_(capabilities) /* funct. capabilities of the device */ \
71_(version) /* version */ \
72_(platform) /* hardware platform of this device */ \
73_(ipprefix) /* An IP network prefix */ \
74_(hello) /* Pprotocol piggyback hello msg */ \
75_(vtp_domain) /* VTP management domain */ \
76_(native_vlan) /* Native VLAN number */ \
77_(duplex) /* The interface duplex mode */ \
78_(appl_vlan) /* Appliance VLAN-ID TLV */ \
79_(trigger) /* For sending trigger TLV msgs. */ \
80_(power) /* Power consumption of that device */ \
81_(mtu) /* MTU defined for sending intf. */ \
82_(trust) /* Extended trust TLV */ \
83_(cos) /* COS for Untrusted Port TLV */ \
84_(sysname) /* System name (FQDN of device) */ \
85_(sysobject) /* OID of sysObjectID MIB object */ \
86_(mgmt_addr) /* SNMP manageable addrs. of device */ \
87_(physical_loc) /* Physical Location of the device */ \
88_(mgmt_addr2) /* External Port-ID */ \
89_(power_requested) \
90_(power_available) \
91_(port_unidirectional) \
92_(unknown_28) \
93_(energywise) \
94_(unknown_30) \
95_(spare_poe)
96
Dave Barach861bd212016-08-09 08:55:49 -040097typedef enum
98{
Dave Barachced48e72016-02-08 15:57:35 -050099#define _(t) CDP_TLV_##t,
Dave Barach861bd212016-08-09 08:55:49 -0400100 foreach_cdp_tlv_type
Dave Barachced48e72016-02-08 15:57:35 -0500101#undef _
102} cdp_tlv_code_t;
103
104/*
105 The address TLV looks as follows:
106
107 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108 | Number of addresses |
109 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110 | IDRP encoded address |
111 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112
113 An address is encoded in IDRP format:
114
115 0 1 2 3
116 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
117 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
118 | PT | PT Length | Protocol (variable) ...
119 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
120 | Address length | Address (variable) ...
121 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
122
Damjan Marion607de1a2016-08-16 22:53:54 +0200123 PT: Protocol type
124 1 = NLPID format
Dave Barachced48e72016-02-08 15:57:35 -0500125 2 = 802.2 format
126
Damjan Marion607de1a2016-08-16 22:53:54 +0200127 PT Length:
Dave Barachced48e72016-02-08 15:57:35 -0500128 Length of protocol field, 1 for PT = 1, and either 3 or 8 for
129 802.2 format depending if SNAP is used for PT = 2.
130
131 The encodings for the other protocols have the following format:
132
133 field: <SSAP><DSAP><CTRL><-------OUI------><protocl_TYPE>
134 | | | | | | | | |
135 bytes: 0 1 2 3 4 5 6 7 8
Damjan Marion607de1a2016-08-16 22:53:54 +0200136
Dave Barachced48e72016-02-08 15:57:35 -0500137 where the first 3 bytes are 0xAAAA03 for SNAP encoded addresses.
138 The OUI is 000000 for ethernet and <protocl_TYPE>
139 is the assigned Ethernet type code for the particular protocol.
Damjan Marion607de1a2016-08-16 22:53:54 +0200140 e.g. for DECnet the encoding is AAAA03 000000 6003.
Dave Barachced48e72016-02-08 15:57:35 -0500141 for IPv6 the encoding is AAAA03 000000 86DD
142*/
143
144/*
145 * Capabilities.
146 */
147
148#define CDP_ROUTER_DEVICE 0x0001
149#define CDP_TB_DEVICE 0x0002
150#define CDP_SRB_DEVICE 0x0004
151#define CDP_SWITCH_DEVICE 0x0008
152#define CDP_HOST_DEVICE 0x0010
153#define CDP_IGMP_DEVICE 0x0020
154#define CDP_REPEATER_DEVICE 0x0040
155
156/*
157 The protocol-hello TLV looks as follows:
158
159 0 1 2 3
160 012345678901234567890123456789012345678
161 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
162 | Type | Length |
163 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
164 | OUI |
165 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
166 | Protocol ID |
167 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
168 | up to 27 bytes of message |
169 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
170*/
171
172/*
173 * These macros define the valid values for the Duplex TLV.
174 */
175#define CDP_DUPLEX_TLV_HALF 0x0
176#define CDP_DUPLEX_TLV_FULL 0x1
177
178#endif /* __included_cdp_protocol_h__ */
Dave Barach861bd212016-08-09 08:55:49 -0400179
180/*
181 * fd.io coding-style-patch-verification: ON
182 *
183 * Local Variables:
184 * eval: (c-set-style "gnu")
185 * End:
186 */