]> git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/check_cdp.c
Support for multiple IPv4/IPv6 management addresses.
[thirdparty/lldpd.git] / tests / check_cdp.c
1 #define _GNU_SOURCE 1
2 #include <stdlib.h>
3 #include <sys/socket.h>
4 #include <arpa/inet.h>
5 #include <netinet/in.h>
6 #include <check.h>
7 #include "../src/lldpd.h"
8 #include "common.h"
9
10 char filenameprefix[] = "cdp_send";
11
12 #ifdef ENABLE_CDP
13
14 START_TEST (test_send_cdpv1)
15 {
16 int n;
17 /* Packet we should build:
18 IEEE 802.3 Ethernet
19 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
20 Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
21 Length: 106
22 Logical-Link Control
23 DSAP: SNAP (0xaa)
24 IG Bit: Individual
25 SSAP: SNAP (0xaa)
26 CR Bit: Command
27 Control field: U, func=UI (0x03)
28 000. 00.. = Command: Unnumbered Information (0x00)
29 .... ..11 = Frame type: Unnumbered frame (0x03)
30 Organization Code: Cisco (0x00000c)
31 PID: CDP (0x2000)
32 Cisco Discovery Protocol
33 Version: 1
34 TTL: 180 seconds
35 Checksum: 0x3af7 [correct]
36 [Good: True]
37 [Bad : False]
38 Device ID: First chassis
39 Type: Device ID (0x0001)
40 Length: 17
41 Device ID: First chassis
42 Addresses
43 Type: Addresses (0x0002)
44 Length: 17
45 Number of addresses: 1
46 IP address: 172.17.142.37
47 Protocol type: NLPID
48 Protocol length: 1
49 Protocol: IP
50 Address length: 4
51 IP address: 172.17.142.37
52 Port ID: FastEthernet 1/5
53 Type: Port ID (0x0003)
54 Length: 20
55 Sent through Interface: FastEthernet 1/5
56 Capabilities
57 Type: Capabilities (0x0004)
58 Length: 8
59 Capabilities: 0x00000011
60 .... .... .... .... .... .... .... ...1 = Is a Router
61 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
62 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
63 .... .... .... .... .... .... .... 0... = Not a Switch
64 .... .... .... .... .... .... ...1 .... = Is a Host
65 .... .... .... .... .... .... ..0. .... = Not IGMP capable
66 .... .... .... .... .... .... .0.. .... = Not a Repeater
67 Software Version
68 Type: Software version (0x0005)
69 Length: 23
70 Software Version: Chassis description
71 Platform: Linux
72 Type: Platform (0x0006)
73 Length: 9
74 Platform: Linux
75 */
76 char pkt1[] = {
77 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10,
78 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6a, 0xaa, 0xaa,
79 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4,
80 0x3a, 0xf7, 0x00, 0x01, 0x00, 0x11, 0x46, 0x69,
81 0x72, 0x73, 0x74, 0x20, 0x63, 0x68, 0x61, 0x73,
82 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x11, 0x00,
83 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00, 0x04,
84 0xac, 0x11, 0x8e, 0x25, 0x00, 0x03, 0x00, 0x14,
85 0x46, 0x61, 0x73, 0x74, 0x45, 0x74, 0x68, 0x65,
86 0x72, 0x6e, 0x65, 0x74, 0x20, 0x31, 0x2f, 0x35,
87 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x11,
88 0x00, 0x05, 0x00, 0x17, 0x43, 0x68, 0x61, 0x73,
89 0x73, 0x69, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63,
90 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00,
91 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 };
92 struct packet *pkt;
93
94 /* Populate port and chassis */
95 hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
96 hardware.h_lport.p_id = "Not used";
97 hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
98 hardware.h_lport.p_descr = "FastEthernet 1/5";
99 chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
100 chassis.c_id = macaddress;
101 chassis.c_id_len = ETH_ALEN;
102 chassis.c_name = "First chassis";
103 chassis.c_descr = "Chassis description";
104 chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER;
105 TAILQ_INIT(&chassis.c_mgmt);
106 in_addr_t addr = inet_addr("172.17.142.37");
107 struct lldpd_mgmt *mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4,
108 &addr, sizeof(in_addr_t), 0);
109 if (mgmt == NULL)
110 ck_abort();
111 TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries);
112
113 /* Build packet */
114 n = cdpv1_send(NULL, &hardware);
115 if (n != 0) {
116 fail("unable to build packet");
117 return;
118 }
119 if (TAILQ_EMPTY(&pkts)) {
120 fail("no packets sent");
121 return;
122 }
123 pkt = TAILQ_FIRST(&pkts);
124 ck_assert_int_eq(pkt->size, sizeof(pkt1));
125 fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
126 fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
127 }
128 END_TEST
129
130 START_TEST (test_send_cdpv2)
131 {
132 int n;
133 /* Packet we should build:
134 IEEE 802.3 Ethernet
135 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
136 Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
137 the factory default)
138 Length: 111
139 Logical-Link Control
140 DSAP: SNAP (0xaa)
141 IG Bit: Individual
142 SSAP: SNAP (0xaa)
143 CR Bit: Command
144 Control field: U, func=UI (0x03)
145 000. 00.. = Command: Unnumbered Information (0x00)
146 .... ..11 = Frame type: Unnumbered frame (0x03)
147 Organization Code: Cisco (0x00000c)
148 PID: CDP (0x2000)
149 Cisco Discovery Protocol
150 Version: 2
151 TTL: 180 seconds
152 Checksum: 0x5926 [correct]
153 [Good: True]
154 [Bad : False]
155 Device ID: Second chassis
156 Type: Device ID (0x0001)
157 Length: 18
158 Device ID: Second chassis
159 Addresses
160 Type: Addresses (0x0002)
161 Length: 17
162 Number of addresses: 1
163 IP address: 172.17.142.36
164 Protocol type: NLPID
165 Protocol length: 1
166 Protocol: IP
167 Address length: 4
168 IP address: 172.17.142.36
169 Port ID: Gigabit Ethernet 5/8
170 Type: Port ID (0x0003)
171 Length: 24
172 Sent through Interface: Gigabit Ethernet 5/8
173 Capabilities
174 Type: Capabilities (0x0004)
175 Length: 8
176 Capabilities: 0x00000019
177 .... .... .... .... .... .... .... ...1 = Is a Router
178 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
179 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
180 .... .... .... .... .... .... .... 1... = Is a Switch
181 .... .... .... .... .... .... ...1 .... = Is a Host
182 .... .... .... .... .... .... ..0. .... = Not IGMP capable
183 .... .... .... .... .... .... .0.. .... = Not a Repeater
184 Software Version
185 Type: Software version (0x0005)
186 Length: 23
187 Software Version: Chassis description
188 Platform: Linux
189 Type: Platform (0x0006)
190 Length: 9
191 Platform: Linux
192 */
193 char pkt1[] = {
194 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10,
195 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6f, 0xaa, 0xaa,
196 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
197 0x59, 0x26, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65,
198 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61,
199 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x11,
200 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00,
201 0x04, 0xac, 0x11, 0x8e, 0x24, 0x00, 0x03, 0x00,
202 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69, 0x74,
203 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e, 0x65,
204 0x74, 0x20, 0x35, 0x2f, 0x38, 0x00, 0x04, 0x00,
205 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05, 0x00,
206 0x17, 0x43, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73,
207 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70,
208 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x09,
209 0x4c, 0x69, 0x6e, 0x75, 0x78 };
210 struct packet *pkt;
211
212 /* Populate port and chassis */
213 hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
214 hardware.h_lport.p_id = macaddress;
215 hardware.h_lport.p_id_len = ETH_ALEN;
216 hardware.h_lport.p_descr = "Gigabit Ethernet 5/8";
217 chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
218 chassis.c_id = macaddress;
219 chassis.c_id_len = ETH_ALEN;
220 chassis.c_name = "Second chassis";
221 chassis.c_descr = "Chassis description";
222 chassis.c_cap_available = chassis.c_cap_enabled =
223 LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE;
224 TAILQ_INIT(&chassis.c_mgmt);
225 in_addr_t addr = inet_addr("172.17.142.36");
226 struct lldpd_mgmt *mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4,
227 &addr, sizeof(in_addr_t), 0);
228 if (mgmt == NULL)
229 ck_abort();
230 TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries);
231
232 /* Build packet */
233 n = cdpv2_send(NULL, &hardware);
234 if (n != 0) {
235 fail("unable to build packet");
236 return;
237 }
238 if (TAILQ_EMPTY(&pkts)) {
239 fail("no packets sent");
240 return;
241 }
242 pkt = TAILQ_FIRST(&pkts);
243 ck_assert_int_eq(pkt->size, sizeof(pkt1));
244 fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
245 fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
246 }
247 END_TEST
248
249 START_TEST (test_recv_cdpv1)
250 {
251 char pkt1[] = {
252 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x00, 0xe0,
253 0x1e, 0xd5, 0xd5, 0x15, 0x01, 0x1e, 0xaa, 0xaa,
254 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4,
255 0xdf, 0xf0, 0x00, 0x01, 0x00, 0x06, 0x52, 0x31,
256 0x00, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01,
257 0x01, 0x01, 0xcc, 0x00, 0x04, 0xc0, 0xa8, 0x0a,
258 0x01, 0x00, 0x03, 0x00, 0x0d, 0x45, 0x74, 0x68,
259 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x00, 0x04,
260 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x05,
261 0x00, 0xd8, 0x43, 0x69, 0x73, 0x63, 0x6f, 0x20,
262 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
263 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, 0x70, 0x65,
264 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x53,
265 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x53, 0x6f,
266 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x0a,
267 0x49, 0x4f, 0x53, 0x20, 0x28, 0x74, 0x6d, 0x29,
268 0x20, 0x31, 0x36, 0x30, 0x30, 0x20, 0x53, 0x6f,
269 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x28,
270 0x43, 0x31, 0x36, 0x30, 0x30, 0x2d, 0x4e, 0x59,
271 0x2d, 0x4c, 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72,
272 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x31, 0x2e,
273 0x32, 0x28, 0x31, 0x32, 0x29, 0x50, 0x2c, 0x20,
274 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20,
275 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45,
276 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, 0x43,
277 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74,
278 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x38,
279 0x36, 0x2d, 0x31, 0x39, 0x39, 0x38, 0x20, 0x62,
280 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
281 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c,
282 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, 0x6f,
283 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54,
284 0x75, 0x65, 0x20, 0x30, 0x33, 0x2d, 0x4d, 0x61,
285 0x72, 0x2d, 0x39, 0x38, 0x20, 0x30, 0x36, 0x3a,
286 0x33, 0x33, 0x20, 0x62, 0x79, 0x20, 0x64, 0x73,
287 0x63, 0x68, 0x77, 0x61, 0x72, 0x74, 0x00, 0x06,
288 0x00, 0x0e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
289 0x31, 0x36, 0x30, 0x31 };
290 /* This is:
291 IEEE 802.3 Ethernet
292 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
293 Source: Cisco_d5:d5:15 (00:e0:1e:d5:d5:15)
294 Length: 286
295 Logical-Link Control
296 DSAP: SNAP (0xaa)
297 IG Bit: Individual
298 SSAP: SNAP (0xaa)
299 CR Bit: Command
300 Control field: U, func=UI (0x03)
301 000. 00.. = Command: Unnumbered Information (0x00)
302 .... ..11 = Frame type: Unnumbered frame (0x03)
303 Organization Code: Cisco (0x00000c)
304 PID: CDP (0x2000)
305 Cisco Discovery Protocol
306 Version: 1
307 TTL: 180 seconds
308 Checksum: 0xdff0 [correct]
309 [Good: True]
310 [Bad : False]
311 Device ID: R1
312 Type: Device ID (0x0001)
313 Length: 6
314 Device ID: R1
315 Addresses
316 Type: Addresses (0x0002)
317 Length: 17
318 Number of addresses: 1
319 IP address: 192.168.10.1
320 Protocol type: NLPID
321 Protocol length: 1
322 Protocol: IP
323 Address length: 4
324 IP address: 192.168.10.1
325 Port ID: Ethernet0
326 Type: Port ID (0x0003)
327 Length: 13
328 Sent through Interface: Ethernet0
329 Capabilities
330 Type: Capabilities (0x0004)
331 Length: 8
332 Capabilities: 0x00000011
333 .... .... .... .... .... .... .... ...1 = Is a Router
334 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
335 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
336 .... .... .... .... .... .... .... 0... = Not a Switch
337 .... .... .... .... .... .... ...1 .... = Is a Host
338 .... .... .... .... .... .... ..0. .... = Not IGMP capable
339 .... .... .... .... .... .... .0.. .... = Not a Repeater
340 Software Version
341 Type: Software version (0x0005)
342 Length: 216
343 Software Version: Cisco Internetwork Operating System Software
344 IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)
345 Copyright (c) 1986-1998 by cisco Systems, Inc.
346 Compiled Tue 03-Mar-98 06:33 by dschwart
347 Platform: cisco 1601
348 Type: Platform (0x0006)
349 Length: 14
350 Platform: cisco 1601
351 */
352 struct lldpd_chassis *nchassis = NULL;
353 struct lldpd_port *nport = NULL;
354
355 fail_unless(cdpv1_guess(pkt1, sizeof(pkt1)));
356 fail_unless(cdp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
357 &nchassis, &nport) != -1);
358 if (!nchassis || !nport) {
359 fail("unable to decode packet");
360 return;
361 }
362 ck_assert_int_eq(nchassis->c_id_subtype,
363 LLDP_CHASSISID_SUBTYPE_LOCAL);
364 ck_assert_int_eq(nchassis->c_id_len, 2);
365 fail_unless(memcmp(nchassis->c_id, "R1", 2) == 0);
366 ck_assert_str_eq(nchassis->c_name, "R1");
367 ck_assert_int_eq(nchassis->c_mgmt.tqh_first->m_addr.inet.s_addr,
368 (u_int32_t)inet_addr("192.168.10.1"));
369 ck_assert_int_eq(nchassis->c_mgmt.tqh_first->m_iface, 0);
370 ck_assert_int_eq(nport->p_id_subtype,
371 LLDP_PORTID_SUBTYPE_IFNAME);
372 ck_assert_int_eq(nport->p_id_len, strlen("Ethernet0"));
373 fail_unless(memcmp(nport->p_id,
374 "Ethernet0", strlen("Ethernet0")) == 0);
375 ck_assert_str_eq(nport->p_descr, "Ethernet0");
376 ck_assert_int_eq(nchassis->c_cap_enabled, LLDP_CAP_ROUTER);
377 ck_assert_str_eq(nchassis->c_descr,
378 "cisco 1601 running on\n"
379 "Cisco Internetwork Operating System Software \n"
380 "IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)\n"
381 "Copyright (c) 1986-1998 by cisco Systems, Inc.\n"
382 "Compiled Tue 03-Mar-98 06:33 by dschwart");
383 }
384 END_TEST
385
386 START_TEST (test_recv_cdpv2)
387 {
388 char pkt1[] = {
389 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0xca, 0x00,
390 0x68, 0x46, 0x00, 0x00, 0x01, 0x30, 0xaa, 0xaa,
391 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
392 0x54, 0x27, 0x00, 0x01, 0x00, 0x0f, 0x72, 0x74,
393 0x62, 0x67, 0x36, 0x74, 0x65, 0x73, 0x74, 0x30,
394 0x31, 0x00, 0x05, 0x00, 0xd3, 0x43, 0x69, 0x73,
395 0x63, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72,
396 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
397 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e,
398 0x67, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
399 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
400 0x65, 0x20, 0x0a, 0x49, 0x4f, 0x53, 0x20, 0x28,
401 0x74, 0x6d, 0x29, 0x20, 0x37, 0x32, 0x30, 0x30,
402 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
403 0x65, 0x20, 0x28, 0x43, 0x37, 0x32, 0x30, 0x30,
404 0x2d, 0x50, 0x2d, 0x4d, 0x29, 0x2c, 0x20, 0x56,
405 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31,
406 0x32, 0x2e, 0x32, 0x28, 0x34, 0x36, 0x29, 0x2c,
407 0x20, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45,
408 0x20, 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52,
409 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a,
410 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
411 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39,
412 0x38, 0x36, 0x2d, 0x32, 0x30, 0x30, 0x37, 0x20,
413 0x62, 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f,
414 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73,
415 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43,
416 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20,
417 0x54, 0x68, 0x75, 0x20, 0x32, 0x36, 0x2d, 0x41,
418 0x70, 0x72, 0x2d, 0x30, 0x37, 0x20, 0x32, 0x31,
419 0x3a, 0x35, 0x36, 0x20, 0x62, 0x79, 0x20, 0x70,
420 0x77, 0x61, 0x64, 0x65, 0x00, 0x06, 0x00, 0x11,
421 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x37, 0x32,
422 0x30, 0x36, 0x56, 0x58, 0x52, 0x00, 0x02, 0x00,
423 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc,
424 0x00, 0x04, 0xac, 0x42, 0x37, 0x03, 0x00, 0x03,
425 0x00, 0x13, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74,
426 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x2f,
427 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
428 0x00, 0x00, 0x0b, 0x00, 0x05, 0x00 };
429 /* This is:
430 IEEE 802.3 Ethernet
431 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
432 Source: ca:00:68:46:00:00 (ca:00:68:46:00:00)
433 Length: 304
434 Logical-Link Control
435 DSAP: SNAP (0xaa)
436 IG Bit: Individual
437 SSAP: SNAP (0xaa)
438 CR Bit: Command
439 Control field: U, func=UI (0x03)
440 000. 00.. = Command: Unnumbered Information (0x00)
441 .... ..11 = Frame type: Unnumbered frame (0x03)
442 Organization Code: Cisco (0x00000c)
443 PID: CDP (0x2000)
444 Cisco Discovery Protocol
445 Version: 2
446 TTL: 180 seconds
447 Checksum: 0x5427 [correct]
448 [Good: True]
449 [Bad : False]
450 Device ID: rtbg6test01
451 Type: Device ID (0x0001)
452 Length: 15
453 Device ID: rtbg6test01
454 Software Version
455 Type: Software version (0x0005)
456 Length: 211
457 Software Version: Cisco Internetwork Operating System Software
458 IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)
459 Copyright (c) 1986-2007 by cisco Systems, Inc.
460 Compiled Thu 26-Apr-07 21:56 by pwade
461 Platform: cisco 7206VXR
462 Type: Platform (0x0006)
463 Length: 17
464 Platform: cisco 7206VXR
465 Addresses
466 Type: Addresses (0x0002)
467 Length: 17
468 Number of addresses: 1
469 IP address: 172.66.55.3
470 Protocol type: NLPID
471 Protocol length: 1
472 Protocol: IP
473 Address length: 4
474 IP address: 172.66.55.3
475 Port ID: FastEthernet0/0
476 Type: Port ID (0x0003)
477 Length: 19
478 Sent through Interface: FastEthernet0/0
479 Capabilities
480 Type: Capabilities (0x0004)
481 Length: 8
482 Capabilities: 0x00000000
483 .... .... .... .... .... .... .... ...0 = Not a Router
484 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
485 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
486 .... .... .... .... .... .... .... 0... = Not a Switch
487 .... .... .... .... .... .... ...0 .... = Not a Host
488 .... .... .... .... .... .... ..0. .... = Not IGMP capable
489 .... .... .... .... .... .... .0.. .... = Not a Repeater
490 Duplex: Half
491 Type: Duplex (0x000b)
492 Length: 5
493 Duplex: Half
494 */
495 struct lldpd_chassis *nchassis = NULL;
496 struct lldpd_port *nport = NULL;
497
498 fail_unless(cdpv2_guess(pkt1, sizeof(pkt1)));
499 fail_unless(cdp_decode(NULL, pkt1, sizeof(pkt1), &hardware,
500 &nchassis, &nport) != -1);
501 if (!nchassis || !nport) {
502 fail("unable to decode packet");
503 return;
504 }
505 ck_assert_int_eq(nchassis->c_id_subtype,
506 LLDP_CHASSISID_SUBTYPE_LOCAL);
507 ck_assert_int_eq(nchassis->c_id_len, strlen("rtbg6test01"));
508 fail_unless(memcmp(nchassis->c_id,
509 "rtbg6test01", strlen("rtbg6test01")) == 0);
510 ck_assert_str_eq(nchassis->c_name, "rtbg6test01");
511 ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_addr.inet.s_addr,
512 (u_int32_t)inet_addr("172.66.55.3"));
513 ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_iface, 0);
514 ck_assert_int_eq(nport->p_id_subtype,
515 LLDP_PORTID_SUBTYPE_IFNAME);
516 ck_assert_int_eq(nport->p_id_len, strlen("FastEthernet0/0"));
517 fail_unless(memcmp(nport->p_id,
518 "FastEthernet0/0", strlen("FastEthernet0/0")) == 0);
519 ck_assert_str_eq(nport->p_descr, "FastEthernet0/0");
520 ck_assert_int_eq(nchassis->c_cap_enabled, LLDP_CAP_STATION);
521 ck_assert_str_eq(nchassis->c_descr,
522 "cisco 7206VXR running on\n"
523 "Cisco Internetwork Operating System Software \n"
524 "IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)\n"
525 "Copyright (c) 1986-2007 by cisco Systems, Inc.\n"
526 "Compiled Thu 26-Apr-07 21:56 by pwade");
527 }
528 END_TEST
529
530 #endif
531
532 Suite *
533 cdp_suite(void)
534 {
535 Suite *s = suite_create("CDP");
536
537 #ifdef ENABLE_CDP
538 TCase *tc_send = tcase_create("Send CDP packets");
539 tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown);
540 tcase_add_test(tc_send, test_send_cdpv1);
541 tcase_add_test(tc_send, test_send_cdpv2);
542 suite_add_tcase(s, tc_send);
543
544 TCase *tc_receive = tcase_create("Receive CDP packets");
545 tcase_add_test(tc_receive, test_recv_cdpv1);
546 tcase_add_test(tc_receive, test_recv_cdpv2);
547 suite_add_tcase(s, tc_receive);
548 #endif
549
550 return s;
551 }
552
553 int
554 main()
555 {
556 int number_failed;
557 Suite *s = cdp_suite ();
558 SRunner *sr = srunner_create (s);
559 srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because
560 we need to write
561 files */
562 srunner_run_all (sr, CK_ENV);
563 number_failed = srunner_ntests_failed (sr);
564 srunner_free (sr);
565 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
566 }