1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2015 Vincent Bernat <bernat@luffy.cx>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/socket.h>
20 #include <arpa/inet.h>
21 #include <netinet/in.h>
25 char filenameprefix
[] = "cdp_send";
29 START_TEST (test_send_cdpv1
)
32 /* Packet we should build:
34 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
35 Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
42 Control field: U, func=UI (0x03)
43 000. 00.. = Command: Unnumbered Information (0x00)
44 .... ..11 = Frame type: Unnumbered frame (0x03)
45 Organization Code: Cisco (0x00000c)
47 Cisco Discovery Protocol
50 Checksum: 0x3af7 [correct]
53 Device ID: First chassis
54 Type: Device ID (0x0001)
56 Device ID: First chassis
58 Type: Addresses (0x0002)
60 Number of addresses: 1
61 IP address: 172.17.142.37
66 IP address: 172.17.142.37
67 Port ID: FastEthernet 1/5
68 Type: Port ID (0x0003)
70 Sent through Interface: FastEthernet 1/5
72 Type: Capabilities (0x0004)
74 Capabilities: 0x00000011
75 .... .... .... .... .... .... .... ...1 = Is a Router
76 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
77 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
78 .... .... .... .... .... .... .... 0... = Not a Switch
79 .... .... .... .... .... .... ...1 .... = Is a Host
80 .... .... .... .... .... .... ..0. .... = Not IGMP capable
81 .... .... .... .... .... .... .0.. .... = Not a Repeater
83 Type: Software version (0x0005)
85 Software Version: Chassis description
87 Type: Platform (0x0006)
92 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10,
93 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6a, 0xaa, 0xaa,
94 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4,
95 0x3a, 0xf7, 0x00, 0x01, 0x00, 0x11, 0x46, 0x69,
96 0x72, 0x73, 0x74, 0x20, 0x63, 0x68, 0x61, 0x73,
97 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x11, 0x00,
98 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00, 0x04,
99 0xac, 0x11, 0x8e, 0x25, 0x00, 0x03, 0x00, 0x14,
100 0x46, 0x61, 0x73, 0x74, 0x45, 0x74, 0x68, 0x65,
101 0x72, 0x6e, 0x65, 0x74, 0x20, 0x31, 0x2f, 0x35,
102 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x11,
103 0x00, 0x05, 0x00, 0x17, 0x43, 0x68, 0x61, 0x73,
104 0x73, 0x69, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63,
105 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00,
106 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 };
109 struct lldpd_mgmt
*mgmt
;
112 .c_platform
= "Linux"
116 /* Populate port and chassis */
117 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_IFNAME
;
118 hardware
.h_lport
.p_id
= "Not used";
119 hardware
.h_lport
.p_id_len
= strlen(hardware
.h_lport
.p_id
);
120 hardware
.h_lport
.p_descr
= "FastEthernet 1/5";
121 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
122 chassis
.c_id
= macaddress
;
123 chassis
.c_id_len
= ETHER_ADDR_LEN
;
124 chassis
.c_name
= "First chassis";
125 chassis
.c_descr
= "Chassis description";
126 chassis
.c_cap_available
= chassis
.c_cap_enabled
= LLDP_CAP_ROUTER
;
127 TAILQ_INIT(&chassis
.c_mgmt
);
128 addr
= inet_addr("172.17.142.37");
129 mgmt
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
130 &addr
, sizeof(in_addr_t
), 0);
133 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt
, m_entries
);
136 n
= cdpv1_send(&cfg
, &hardware
);
138 fail("unable to build packet");
141 if (TAILQ_EMPTY(&pkts
)) {
142 fail("no packets sent");
145 pkt
= TAILQ_FIRST(&pkts
);
146 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
147 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
148 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
152 START_TEST (test_send_cdpv2
)
155 /* Packet we should build:
157 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
158 Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
166 Control field: U, func=UI (0x03)
167 000. 00.. = Command: Unnumbered Information (0x00)
168 .... ..11 = Frame type: Unnumbered frame (0x03)
169 Organization Code: Cisco (0x00000c)
171 Cisco Discovery Protocol
174 Checksum: 0x5926 [correct]
177 Device ID: Second chassis
178 Type: Device ID (0x0001)
180 Device ID: Second chassis
182 Type: Addresses (0x0002)
184 Number of addresses: 2
185 IP address: 172.17.142.36
190 IP address: 172.17.142.36
191 IP address: 172.17.142.38
196 IP address: 172.17.142.38
197 Port ID: Gigabit Ethernet 5/8
198 Type: Port ID (0x0003)
200 Sent through Interface: Gigabit Ethernet 5/8
202 Type: Capabilities (0x0004)
204 Capabilities: 0x00000019
205 .... .... .... .... .... .... .... ...1 = Is a Router
206 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
207 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
208 .... .... .... .... .... .... .... 1... = Is a Switch
209 .... .... .... .... .... .... ...1 .... = Is a Host
210 .... .... .... .... .... .... ..0. .... = Not IGMP capable
211 .... .... .... .... .... .... .0.. .... = Not a Repeater
213 Type: Software version (0x0005)
215 Software Version: Chassis description
217 Type: Platform (0x0006)
222 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10,
223 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x78, 0xaa, 0xaa,
224 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
225 0xc8, 0x67, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65,
226 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61,
227 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x1a,
228 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0xcc, 0x00,
229 0x04, 0xac, 0x11, 0x8e, 0x24, 0x01, 0x01, 0xcc,
230 0x00, 0x04, 0xac, 0x11, 0x8e, 0x26, 0x00, 0x03,
231 0x00, 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69,
232 0x74, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e,
233 0x65, 0x74, 0x20, 0x35, 0x2f, 0x38, 0x00, 0x04,
234 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05,
235 0x00, 0x17, 0x43, 0x68, 0x61, 0x73, 0x73, 0x69,
236 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
237 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00,
238 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 };
242 struct lldpd_mgmt
*mgmt1
;
243 struct lldpd_mgmt
*mgmt2
;
246 .c_platform
= "Linux"
250 /* Populate port and chassis */
251 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_LLADDR
;
252 hardware
.h_lport
.p_id
= macaddress
;
253 hardware
.h_lport
.p_id_len
= ETHER_ADDR_LEN
;
254 hardware
.h_lport
.p_descr
= "Gigabit Ethernet 5/8";
255 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
256 chassis
.c_id
= macaddress
;
257 chassis
.c_id_len
= ETHER_ADDR_LEN
;
258 chassis
.c_name
= "Second chassis";
259 chassis
.c_descr
= "Chassis description";
260 chassis
.c_cap_available
= chassis
.c_cap_enabled
=
261 LLDP_CAP_ROUTER
| LLDP_CAP_BRIDGE
;
262 TAILQ_INIT(&chassis
.c_mgmt
);
263 addr1
= inet_addr("172.17.142.36");
264 addr2
= inet_addr("172.17.142.38");
265 mgmt1
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
266 &addr1
, sizeof(in_addr_t
), 0);
267 mgmt2
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
268 &addr2
, sizeof(in_addr_t
), 0);
269 if (mgmt1
== NULL
|| mgmt2
== NULL
)
271 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt1
, m_entries
);
272 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt2
, m_entries
);
275 n
= cdpv2_send(&cfg
, &hardware
);
277 fail("unable to build packet");
280 if (TAILQ_EMPTY(&pkts
)) {
281 fail("no packets sent");
284 pkt
= TAILQ_FIRST(&pkts
);
285 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
286 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
287 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
291 START_TEST (test_recv_cdpv1
)
294 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x00, 0xe0,
295 0x1e, 0xd5, 0xd5, 0x15, 0x01, 0x1e, 0xaa, 0xaa,
296 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4,
297 0xdf, 0xf0, 0x00, 0x01, 0x00, 0x06, 0x52, 0x31,
298 0x00, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01,
299 0x01, 0x01, 0xcc, 0x00, 0x04, 0xc0, 0xa8, 0x0a,
300 0x01, 0x00, 0x03, 0x00, 0x0d, 0x45, 0x74, 0x68,
301 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x00, 0x04,
302 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x05,
303 0x00, 0xd8, 0x43, 0x69, 0x73, 0x63, 0x6f, 0x20,
304 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
305 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, 0x70, 0x65,
306 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x53,
307 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x53, 0x6f,
308 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x0a,
309 0x49, 0x4f, 0x53, 0x20, 0x28, 0x74, 0x6d, 0x29,
310 0x20, 0x31, 0x36, 0x30, 0x30, 0x20, 0x53, 0x6f,
311 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x28,
312 0x43, 0x31, 0x36, 0x30, 0x30, 0x2d, 0x4e, 0x59,
313 0x2d, 0x4c, 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72,
314 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x31, 0x2e,
315 0x32, 0x28, 0x31, 0x32, 0x29, 0x50, 0x2c, 0x20,
316 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20,
317 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45,
318 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, 0x43,
319 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74,
320 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x38,
321 0x36, 0x2d, 0x31, 0x39, 0x39, 0x38, 0x20, 0x62,
322 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
323 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c,
324 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, 0x6f,
325 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54,
326 0x75, 0x65, 0x20, 0x30, 0x33, 0x2d, 0x4d, 0x61,
327 0x72, 0x2d, 0x39, 0x38, 0x20, 0x30, 0x36, 0x3a,
328 0x33, 0x33, 0x20, 0x62, 0x79, 0x20, 0x64, 0x73,
329 0x63, 0x68, 0x77, 0x61, 0x72, 0x74, 0x00, 0x06,
330 0x00, 0x0e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
331 0x31, 0x36, 0x30, 0x31 };
334 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
335 Source: Cisco_d5:d5:15 (00:e0:1e:d5:d5:15)
342 Control field: U, func=UI (0x03)
343 000. 00.. = Command: Unnumbered Information (0x00)
344 .... ..11 = Frame type: Unnumbered frame (0x03)
345 Organization Code: Cisco (0x00000c)
347 Cisco Discovery Protocol
350 Checksum: 0xdff0 [correct]
354 Type: Device ID (0x0001)
358 Type: Addresses (0x0002)
360 Number of addresses: 1
361 IP address: 192.168.10.1
366 IP address: 192.168.10.1
368 Type: Port ID (0x0003)
370 Sent through Interface: Ethernet0
372 Type: Capabilities (0x0004)
374 Capabilities: 0x00000011
375 .... .... .... .... .... .... .... ...1 = Is a Router
376 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
377 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
378 .... .... .... .... .... .... .... 0... = Not a Switch
379 .... .... .... .... .... .... ...1 .... = Is a Host
380 .... .... .... .... .... .... ..0. .... = Not IGMP capable
381 .... .... .... .... .... .... .0.. .... = Not a Repeater
383 Type: Software version (0x0005)
385 Software Version: Cisco Internetwork Operating System Software
386 IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)
387 Copyright (c) 1986-1998 by cisco Systems, Inc.
388 Compiled Tue 03-Mar-98 06:33 by dschwart
390 Type: Platform (0x0006)
394 struct lldpd_chassis
*nchassis
= NULL
;
395 struct lldpd_port
*nport
= NULL
;
397 fail_unless(cdpv1_guess(pkt1
, sizeof(pkt1
)));
398 fail_unless(cdp_decode(NULL
, pkt1
, sizeof(pkt1
), &hardware
,
399 &nchassis
, &nport
) != -1);
400 if (!nchassis
|| !nport
) {
401 fail("unable to decode packet");
404 ck_assert_int_eq(nchassis
->c_id_subtype
,
405 LLDP_CHASSISID_SUBTYPE_LOCAL
);
406 ck_assert_int_eq(nchassis
->c_id_len
, 2);
407 fail_unless(memcmp(nchassis
->c_id
, "R1", 2) == 0);
408 ck_assert_str_eq(nchassis
->c_name
, "R1");
409 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
410 (u_int32_t
)inet_addr("192.168.10.1"));
411 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_iface
, 0);
412 ck_assert_int_eq(nport
->p_id_subtype
,
413 LLDP_PORTID_SUBTYPE_IFNAME
);
414 ck_assert_int_eq(nport
->p_id_len
, strlen("Ethernet0"));
415 fail_unless(memcmp(nport
->p_id
,
416 "Ethernet0", strlen("Ethernet0")) == 0);
417 ck_assert_str_eq(nport
->p_descr
, "Ethernet0");
418 ck_assert_int_eq(nchassis
->c_cap_enabled
, LLDP_CAP_ROUTER
);
419 ck_assert_str_eq(nchassis
->c_descr
,
420 "cisco 1601 running on\n"
421 "Cisco Internetwork Operating System Software \n"
422 "IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)\n"
423 "Copyright (c) 1986-1998 by cisco Systems, Inc.\n"
424 "Compiled Tue 03-Mar-98 06:33 by dschwart");
428 START_TEST (test_recv_cdpv2
)
431 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0xca, 0x00,
432 0x68, 0x46, 0x00, 0x00, 0x01, 0x30, 0xaa, 0xaa,
433 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
434 0x54, 0x27, 0x00, 0x01, 0x00, 0x0f, 0x72, 0x74,
435 0x62, 0x67, 0x36, 0x74, 0x65, 0x73, 0x74, 0x30,
436 0x31, 0x00, 0x05, 0x00, 0xd3, 0x43, 0x69, 0x73,
437 0x63, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72,
438 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
439 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e,
440 0x67, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
441 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
442 0x65, 0x20, 0x0a, 0x49, 0x4f, 0x53, 0x20, 0x28,
443 0x74, 0x6d, 0x29, 0x20, 0x37, 0x32, 0x30, 0x30,
444 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
445 0x65, 0x20, 0x28, 0x43, 0x37, 0x32, 0x30, 0x30,
446 0x2d, 0x50, 0x2d, 0x4d, 0x29, 0x2c, 0x20, 0x56,
447 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31,
448 0x32, 0x2e, 0x32, 0x28, 0x34, 0x36, 0x29, 0x2c,
449 0x20, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45,
450 0x20, 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52,
451 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a,
452 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
453 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39,
454 0x38, 0x36, 0x2d, 0x32, 0x30, 0x30, 0x37, 0x20,
455 0x62, 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f,
456 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73,
457 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43,
458 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20,
459 0x54, 0x68, 0x75, 0x20, 0x32, 0x36, 0x2d, 0x41,
460 0x70, 0x72, 0x2d, 0x30, 0x37, 0x20, 0x32, 0x31,
461 0x3a, 0x35, 0x36, 0x20, 0x62, 0x79, 0x20, 0x70,
462 0x77, 0x61, 0x64, 0x65, 0x00, 0x06, 0x00, 0x11,
463 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x37, 0x32,
464 0x30, 0x36, 0x56, 0x58, 0x52, 0x00, 0x02, 0x00,
465 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc,
466 0x00, 0x04, 0xac, 0x42, 0x37, 0x03, 0x00, 0x03,
467 0x00, 0x13, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74,
468 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x2f,
469 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
470 0x00, 0x00, 0x0b, 0x00, 0x05, 0x00 };
473 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
474 Source: ca:00:68:46:00:00 (ca:00:68:46:00:00)
481 Control field: U, func=UI (0x03)
482 000. 00.. = Command: Unnumbered Information (0x00)
483 .... ..11 = Frame type: Unnumbered frame (0x03)
484 Organization Code: Cisco (0x00000c)
486 Cisco Discovery Protocol
489 Checksum: 0x5427 [correct]
492 Device ID: rtbg6test01
493 Type: Device ID (0x0001)
495 Device ID: rtbg6test01
497 Type: Software version (0x0005)
499 Software Version: Cisco Internetwork Operating System Software
500 IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)
501 Copyright (c) 1986-2007 by cisco Systems, Inc.
502 Compiled Thu 26-Apr-07 21:56 by pwade
503 Platform: cisco 7206VXR
504 Type: Platform (0x0006)
506 Platform: cisco 7206VXR
508 Type: Addresses (0x0002)
510 Number of addresses: 1
511 IP address: 172.66.55.3
516 IP address: 172.66.55.3
517 Port ID: FastEthernet0/0
518 Type: Port ID (0x0003)
520 Sent through Interface: FastEthernet0/0
522 Type: Capabilities (0x0004)
524 Capabilities: 0x00000000
525 .... .... .... .... .... .... .... ...0 = Not a Router
526 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
527 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
528 .... .... .... .... .... .... .... 0... = Not a Switch
529 .... .... .... .... .... .... ...0 .... = Not a Host
530 .... .... .... .... .... .... ..0. .... = Not IGMP capable
531 .... .... .... .... .... .... .0.. .... = Not a Repeater
533 Type: Duplex (0x000b)
537 struct lldpd_chassis
*nchassis
= NULL
;
538 struct lldpd_port
*nport
= NULL
;
540 fail_unless(cdpv2_guess(pkt1
, sizeof(pkt1
)));
541 fail_unless(cdp_decode(NULL
, pkt1
, sizeof(pkt1
), &hardware
,
542 &nchassis
, &nport
) != -1);
543 if (!nchassis
|| !nport
) {
544 fail("unable to decode packet");
547 ck_assert_int_eq(nchassis
->c_id_subtype
,
548 LLDP_CHASSISID_SUBTYPE_LOCAL
);
549 ck_assert_int_eq(nchassis
->c_id_len
, strlen("rtbg6test01"));
550 fail_unless(memcmp(nchassis
->c_id
,
551 "rtbg6test01", strlen("rtbg6test01")) == 0);
552 ck_assert_str_eq(nchassis
->c_name
, "rtbg6test01");
553 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
554 (u_int32_t
)inet_addr("172.66.55.3"));
555 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_iface
, 0);
556 ck_assert_int_eq(nport
->p_id_subtype
,
557 LLDP_PORTID_SUBTYPE_IFNAME
);
558 ck_assert_int_eq(nport
->p_id_len
, strlen("FastEthernet0/0"));
559 fail_unless(memcmp(nport
->p_id
,
560 "FastEthernet0/0", strlen("FastEthernet0/0")) == 0);
561 ck_assert_str_eq(nport
->p_descr
, "FastEthernet0/0");
562 ck_assert_int_eq(nchassis
->c_cap_enabled
, LLDP_CAP_STATION
);
563 ck_assert_str_eq(nchassis
->c_descr
,
564 "cisco 7206VXR running on\n"
565 "Cisco Internetwork Operating System Software \n"
566 "IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)\n"
567 "Copyright (c) 1986-2007 by cisco Systems, Inc.\n"
568 "Compiled Thu 26-Apr-07 21:56 by pwade");
577 Suite
*s
= suite_create("CDP");
580 TCase
*tc_send
= tcase_create("Send CDP packets");
581 TCase
*tc_receive
= tcase_create("Receive CDP packets");
583 tcase_add_checked_fixture(tc_send
, pcap_setup
, pcap_teardown
);
584 tcase_add_test(tc_send
, test_send_cdpv1
);
585 tcase_add_test(tc_send
, test_send_cdpv2
);
586 suite_add_tcase(s
, tc_send
);
588 tcase_add_test(tc_receive
, test_recv_cdpv1
);
589 tcase_add_test(tc_receive
, test_recv_cdpv2
);
590 suite_add_tcase(s
, tc_receive
);
600 Suite
*s
= cdp_suite ();
601 SRunner
*sr
= srunner_create (s
);
602 srunner_set_fork_status (sr
, CK_NOFORK
); /* Can't fork because
605 srunner_run_all (sr
, CK_ENV
);
606 number_failed
= srunner_ntests_failed (sr
);
608 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;