FD.io VPP  v16.06
Vector Packet Processing
cdp_protocol.h
Go to the documentation of this file.
1 /*
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 
23 typedef CLIB_PACKED (struct {
24  u8 version;
25  u8 ttl;
26  u16 checksum; /* 1's complement of the 1's complement sum */
27  u8 data[0];
28 }) cdp_hdr_t;
29 
30 typedef struct {
31  u8 dst_address[6];
32  u8 src_address[6];
35 
36 typedef CLIB_PACKED (struct {
37  ethernet_802_3_header_t ethernet;
38  llc_header_t llc;
39  snap_header_t snap;
40  cdp_hdr_t cdp;
41 }) ethernet_llc_snap_and_cdp_header_t;
42 
43 typedef CLIB_PACKED (struct {
44  hdlc_header_t hdlc;
45  cdp_hdr_t cdp;
46 }) hdlc_and_cdp_header_t;
47 
48 typedef CLIB_PACKED (struct {
49  srp_header_t srp;
50  ethernet_header_t ethernet;
51  cdp_hdr_t cdp;
52 }) srp_and_cdp_header_t;
53 
54 typedef CLIB_PACKED (struct {
55  u16 t;
56  u16 l;
57  u8 v[0];
58 }) cdp_tlv_t;
59 
60 /*
61  * TLV codes.
62  */
63 #define foreach_cdp_tlv_type \
64 _(unused) \
65 _(device_name) /* uniquely identifies the device */ \
66 _(address) /* list of addresses this device has */ \
67 _(port_id) /* port CDP packet was sent out on */ \
68 _(capabilities) /* funct. capabilities of the device */ \
69 _(version) /* version */ \
70 _(platform) /* hardware platform of this device */ \
71 _(ipprefix) /* An IP network prefix */ \
72 _(hello) /* Pprotocol piggyback hello msg */ \
73 _(vtp_domain) /* VTP management domain */ \
74 _(native_vlan) /* Native VLAN number */ \
75 _(duplex) /* The interface duplex mode */ \
76 _(appl_vlan) /* Appliance VLAN-ID TLV */ \
77 _(trigger) /* For sending trigger TLV msgs. */ \
78 _(power) /* Power consumption of that device */ \
79 _(mtu) /* MTU defined for sending intf. */ \
80 _(trust) /* Extended trust TLV */ \
81 _(cos) /* COS for Untrusted Port TLV */ \
82 _(sysname) /* System name (FQDN of device) */ \
83 _(sysobject) /* OID of sysObjectID MIB object */ \
84 _(mgmt_addr) /* SNMP manageable addrs. of device */ \
85 _(physical_loc) /* Physical Location of the device */ \
86 _(mgmt_addr2) /* External Port-ID */ \
87 _(power_requested) \
88 _(power_available) \
89 _(port_unidirectional) \
90 _(unknown_28) \
91 _(energywise) \
92 _(unknown_30) \
93 _(spare_poe)
94 
95 typedef enum {
96 #define _(t) CDP_TLV_##t,
98 #undef _
100 
101 /*
102  The address TLV looks as follows:
103 
104  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105  | Number of addresses |
106  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
107  | IDRP encoded address |
108  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
109 
110  An address is encoded in IDRP format:
111 
112  0 1 2 3
113  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
114  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115  | PT | PT Length | Protocol (variable) ...
116  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117  | Address length | Address (variable) ...
118  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 
120  PT: Protocol type
121  1 = NLPID format
122  2 = 802.2 format
123 
124  PT Length:
125  Length of protocol field, 1 for PT = 1, and either 3 or 8 for
126  802.2 format depending if SNAP is used for PT = 2.
127 
128  The encodings for the other protocols have the following format:
129 
130  field: <SSAP><DSAP><CTRL><-------OUI------><protocl_TYPE>
131  | | | | | | | | |
132  bytes: 0 1 2 3 4 5 6 7 8
133 
134  where the first 3 bytes are 0xAAAA03 for SNAP encoded addresses.
135  The OUI is 000000 for ethernet and <protocl_TYPE>
136  is the assigned Ethernet type code for the particular protocol.
137  e.g. for DECnet the encoding is AAAA03 000000 6003.
138  for IPv6 the encoding is AAAA03 000000 86DD
139 */
140 
141 /*
142  * Capabilities.
143  */
144 
145 #define CDP_ROUTER_DEVICE 0x0001
146 #define CDP_TB_DEVICE 0x0002
147 #define CDP_SRB_DEVICE 0x0004
148 #define CDP_SWITCH_DEVICE 0x0008
149 #define CDP_HOST_DEVICE 0x0010
150 #define CDP_IGMP_DEVICE 0x0020
151 #define CDP_REPEATER_DEVICE 0x0040
152 
153 /*
154  The protocol-hello TLV looks as follows:
155 
156  0 1 2 3
157  012345678901234567890123456789012345678
158  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
159  | Type | Length |
160  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
161  | OUI |
162  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
163  | Protocol ID |
164  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165  | up to 27 bytes of message |
166  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167 */
168 
169 /*
170  * These macros define the valid values for the Duplex TLV.
171  */
172 #define CDP_DUPLEX_TLV_HALF 0x0
173 #define CDP_DUPLEX_TLV_FULL 0x1
174 
175 #endif /* __included_cdp_protocol_h__ */
#define foreach_cdp_tlv_type
Definition: cdp_protocol.h:63
cdp_tlv_code_t
Definition: cdp_protocol.h:95
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
typedef CLIB_PACKED(struct{u8 version;u8 ttl;u16 checksum;u8 data[0];}) cdp_hdr_t