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
;
113 .c_platform
= "Linux"
117 /* Populate port and chassis */
118 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_IFNAME
;
119 hardware
.h_lport
.p_id
= "Not used";
120 hardware
.h_lport
.p_id_len
= strlen(hardware
.h_lport
.p_id
);
121 hardware
.h_lport
.p_descr
= "FastEthernet 1/5";
122 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
123 chassis
.c_id
= macaddress
;
124 chassis
.c_id_len
= ETHER_ADDR_LEN
;
125 chassis
.c_name
= "First chassis";
126 chassis
.c_descr
= "Chassis description";
127 chassis
.c_cap_available
= chassis
.c_cap_enabled
= LLDP_CAP_ROUTER
;
128 TAILQ_INIT(&chassis
.c_mgmt
);
129 addr
= inet_addr("172.17.142.37");
130 mgmt
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
131 &addr
, sizeof(in_addr_t
), 0);
134 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt
, m_entries
);
137 n
= cdpv1_send(&cfg
, &hardware
);
139 fail("unable to build packet");
142 if (TAILQ_EMPTY(&pkts
)) {
143 fail("no packets sent");
146 pkt
= TAILQ_FIRST(&pkts
);
147 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
148 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
149 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
153 START_TEST (test_send_cdpv2
)
156 /* Packet we should build:
158 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
159 Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
167 Control field: U, func=UI (0x03)
168 000. 00.. = Command: Unnumbered Information (0x00)
169 .... ..11 = Frame type: Unnumbered frame (0x03)
170 Organization Code: Cisco (0x00000c)
172 Cisco Discovery Protocol
175 Checksum: 0x5926 [correct]
178 Device ID: Second chassis
179 Type: Device ID (0x0001)
181 Device ID: Second chassis
183 Type: Addresses (0x0002)
185 Number of addresses: 2
186 IP address: 172.17.142.36
191 IP address: 172.17.142.36
192 IP address: 172.17.142.38
197 IP address: 172.17.142.38
198 Port ID: Gigabit Ethernet 5/8
199 Type: Port ID (0x0003)
201 Sent through Interface: Gigabit Ethernet 5/8
203 Type: Capabilities (0x0004)
205 Capabilities: 0x00000019
206 .... .... .... .... .... .... .... ...1 = Is a Router
207 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
208 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
209 .... .... .... .... .... .... .... 1... = Is a Switch
210 .... .... .... .... .... .... ...1 .... = Is a Host
211 .... .... .... .... .... .... ..0. .... = Not IGMP capable
212 .... .... .... .... .... .... .0.. .... = Not a Repeater
214 Type: Software version (0x0005)
216 Software Version: Chassis description
218 Type: Platform (0x0006)
223 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10,
224 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x78, 0xaa, 0xaa,
225 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
226 0xc8, 0x67, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65,
227 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61,
228 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x1a,
229 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0xcc, 0x00,
230 0x04, 0xac, 0x11, 0x8e, 0x24, 0x01, 0x01, 0xcc,
231 0x00, 0x04, 0xac, 0x11, 0x8e, 0x26, 0x00, 0x03,
232 0x00, 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69,
233 0x74, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e,
234 0x65, 0x74, 0x20, 0x35, 0x2f, 0x38, 0x00, 0x04,
235 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05,
236 0x00, 0x17, 0x43, 0x68, 0x61, 0x73, 0x73, 0x69,
237 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
238 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00,
239 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 };
243 struct lldpd_mgmt
*mgmt1
;
244 struct lldpd_mgmt
*mgmt2
;
248 .c_platform
= "Linux"
252 /* Populate port and chassis */
253 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_LLADDR
;
254 hardware
.h_lport
.p_id
= macaddress
;
255 hardware
.h_lport
.p_id_len
= ETHER_ADDR_LEN
;
256 hardware
.h_lport
.p_descr
= "Gigabit Ethernet 5/8";
257 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
258 chassis
.c_id
= macaddress
;
259 chassis
.c_id_len
= ETHER_ADDR_LEN
;
260 chassis
.c_name
= "Second chassis";
261 chassis
.c_descr
= "Chassis description";
262 chassis
.c_cap_available
= chassis
.c_cap_enabled
=
263 LLDP_CAP_ROUTER
| LLDP_CAP_BRIDGE
;
264 TAILQ_INIT(&chassis
.c_mgmt
);
265 addr1
= inet_addr("172.17.142.36");
266 addr2
= inet_addr("172.17.142.38");
267 mgmt1
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
268 &addr1
, sizeof(in_addr_t
), 0);
269 mgmt2
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
270 &addr2
, sizeof(in_addr_t
), 0);
271 if (mgmt1
== NULL
|| mgmt2
== NULL
)
273 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt1
, m_entries
);
274 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt2
, m_entries
);
277 n
= cdpv2_send(&cfg
, &hardware
);
279 fail("unable to build packet");
282 if (TAILQ_EMPTY(&pkts
)) {
283 fail("no packets sent");
286 pkt
= TAILQ_FIRST(&pkts
);
287 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
288 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
289 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
293 START_TEST (test_recv_cdpv1
)
296 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x00, 0xe0,
297 0x1e, 0xd5, 0xd5, 0x15, 0x01, 0x1e, 0xaa, 0xaa,
298 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4,
299 0xdf, 0xf0, 0x00, 0x01, 0x00, 0x06, 0x52, 0x31,
300 0x00, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01,
301 0x01, 0x01, 0xcc, 0x00, 0x04, 0xc0, 0xa8, 0x0a,
302 0x01, 0x00, 0x03, 0x00, 0x0d, 0x45, 0x74, 0x68,
303 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x00, 0x04,
304 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x05,
305 0x00, 0xd8, 0x43, 0x69, 0x73, 0x63, 0x6f, 0x20,
306 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
307 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, 0x70, 0x65,
308 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x53,
309 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x53, 0x6f,
310 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x0a,
311 0x49, 0x4f, 0x53, 0x20, 0x28, 0x74, 0x6d, 0x29,
312 0x20, 0x31, 0x36, 0x30, 0x30, 0x20, 0x53, 0x6f,
313 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x28,
314 0x43, 0x31, 0x36, 0x30, 0x30, 0x2d, 0x4e, 0x59,
315 0x2d, 0x4c, 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72,
316 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x31, 0x2e,
317 0x32, 0x28, 0x31, 0x32, 0x29, 0x50, 0x2c, 0x20,
318 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20,
319 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45,
320 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, 0x43,
321 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74,
322 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x38,
323 0x36, 0x2d, 0x31, 0x39, 0x39, 0x38, 0x20, 0x62,
324 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
325 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c,
326 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, 0x6f,
327 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54,
328 0x75, 0x65, 0x20, 0x30, 0x33, 0x2d, 0x4d, 0x61,
329 0x72, 0x2d, 0x39, 0x38, 0x20, 0x30, 0x36, 0x3a,
330 0x33, 0x33, 0x20, 0x62, 0x79, 0x20, 0x64, 0x73,
331 0x63, 0x68, 0x77, 0x61, 0x72, 0x74, 0x00, 0x06,
332 0x00, 0x0e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
333 0x31, 0x36, 0x30, 0x31 };
336 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
337 Source: Cisco_d5:d5:15 (00:e0:1e:d5:d5:15)
344 Control field: U, func=UI (0x03)
345 000. 00.. = Command: Unnumbered Information (0x00)
346 .... ..11 = Frame type: Unnumbered frame (0x03)
347 Organization Code: Cisco (0x00000c)
349 Cisco Discovery Protocol
352 Checksum: 0xdff0 [correct]
356 Type: Device ID (0x0001)
360 Type: Addresses (0x0002)
362 Number of addresses: 1
363 IP address: 192.168.10.1
368 IP address: 192.168.10.1
370 Type: Port ID (0x0003)
372 Sent through Interface: Ethernet0
374 Type: Capabilities (0x0004)
376 Capabilities: 0x00000011
377 .... .... .... .... .... .... .... ...1 = Is a Router
378 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
379 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
380 .... .... .... .... .... .... .... 0... = Not a Switch
381 .... .... .... .... .... .... ...1 .... = Is a Host
382 .... .... .... .... .... .... ..0. .... = Not IGMP capable
383 .... .... .... .... .... .... .0.. .... = Not a Repeater
385 Type: Software version (0x0005)
387 Software Version: Cisco Internetwork Operating System Software
388 IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)
389 Copyright (c) 1986-1998 by cisco Systems, Inc.
390 Compiled Tue 03-Mar-98 06:33 by dschwart
392 Type: Platform (0x0006)
396 struct lldpd_chassis
*nchassis
= NULL
;
397 struct lldpd_port
*nport
= NULL
;
399 fail_unless(cdpv1_guess(pkt1
, sizeof(pkt1
)));
400 fail_unless(cdp_decode(NULL
, pkt1
, sizeof(pkt1
), &hardware
,
401 &nchassis
, &nport
) != -1);
402 if (!nchassis
|| !nport
) {
403 fail("unable to decode packet");
406 ck_assert_int_eq(nchassis
->c_id_subtype
,
407 LLDP_CHASSISID_SUBTYPE_LOCAL
);
408 ck_assert_int_eq(nchassis
->c_id_len
, 2);
409 fail_unless(memcmp(nchassis
->c_id
, "R1", 2) == 0);
410 ck_assert_str_eq(nchassis
->c_name
, "R1");
411 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
412 (u_int32_t
)inet_addr("192.168.10.1"));
413 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_iface
, 0);
414 ck_assert_int_eq(nport
->p_id_subtype
,
415 LLDP_PORTID_SUBTYPE_IFNAME
);
416 ck_assert_int_eq(nport
->p_id_len
, strlen("Ethernet0"));
417 fail_unless(memcmp(nport
->p_id
,
418 "Ethernet0", strlen("Ethernet0")) == 0);
419 ck_assert_str_eq(nport
->p_descr
, "Ethernet0");
420 ck_assert_int_eq(nchassis
->c_cap_enabled
, LLDP_CAP_ROUTER
);
421 ck_assert_str_eq(nchassis
->c_descr
,
422 "cisco 1601 running on\n"
423 "Cisco Internetwork Operating System Software \n"
424 "IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)\n"
425 "Copyright (c) 1986-1998 by cisco Systems, Inc.\n"
426 "Compiled Tue 03-Mar-98 06:33 by dschwart");
430 START_TEST (test_recv_cdpv2
)
433 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0xca, 0x00,
434 0x68, 0x46, 0x00, 0x00, 0x01, 0x30, 0xaa, 0xaa,
435 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
436 0x54, 0x27, 0x00, 0x01, 0x00, 0x0f, 0x72, 0x74,
437 0x62, 0x67, 0x36, 0x74, 0x65, 0x73, 0x74, 0x30,
438 0x31, 0x00, 0x05, 0x00, 0xd3, 0x43, 0x69, 0x73,
439 0x63, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72,
440 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
441 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e,
442 0x67, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
443 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
444 0x65, 0x20, 0x0a, 0x49, 0x4f, 0x53, 0x20, 0x28,
445 0x74, 0x6d, 0x29, 0x20, 0x37, 0x32, 0x30, 0x30,
446 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
447 0x65, 0x20, 0x28, 0x43, 0x37, 0x32, 0x30, 0x30,
448 0x2d, 0x50, 0x2d, 0x4d, 0x29, 0x2c, 0x20, 0x56,
449 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31,
450 0x32, 0x2e, 0x32, 0x28, 0x34, 0x36, 0x29, 0x2c,
451 0x20, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45,
452 0x20, 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52,
453 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a,
454 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
455 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39,
456 0x38, 0x36, 0x2d, 0x32, 0x30, 0x30, 0x37, 0x20,
457 0x62, 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f,
458 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73,
459 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43,
460 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20,
461 0x54, 0x68, 0x75, 0x20, 0x32, 0x36, 0x2d, 0x41,
462 0x70, 0x72, 0x2d, 0x30, 0x37, 0x20, 0x32, 0x31,
463 0x3a, 0x35, 0x36, 0x20, 0x62, 0x79, 0x20, 0x70,
464 0x77, 0x61, 0x64, 0x65, 0x00, 0x06, 0x00, 0x11,
465 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x37, 0x32,
466 0x30, 0x36, 0x56, 0x58, 0x52, 0x00, 0x02, 0x00,
467 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc,
468 0x00, 0x04, 0xac, 0x42, 0x37, 0x03, 0x00, 0x03,
469 0x00, 0x13, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74,
470 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x2f,
471 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
472 0x00, 0x00, 0x0b, 0x00, 0x05, 0x00 };
475 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
476 Source: ca:00:68:46:00:00 (ca:00:68:46:00:00)
483 Control field: U, func=UI (0x03)
484 000. 00.. = Command: Unnumbered Information (0x00)
485 .... ..11 = Frame type: Unnumbered frame (0x03)
486 Organization Code: Cisco (0x00000c)
488 Cisco Discovery Protocol
491 Checksum: 0x5427 [correct]
494 Device ID: rtbg6test01
495 Type: Device ID (0x0001)
497 Device ID: rtbg6test01
499 Type: Software version (0x0005)
501 Software Version: Cisco Internetwork Operating System Software
502 IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)
503 Copyright (c) 1986-2007 by cisco Systems, Inc.
504 Compiled Thu 26-Apr-07 21:56 by pwade
505 Platform: cisco 7206VXR
506 Type: Platform (0x0006)
508 Platform: cisco 7206VXR
510 Type: Addresses (0x0002)
512 Number of addresses: 1
513 IP address: 172.66.55.3
518 IP address: 172.66.55.3
519 Port ID: FastEthernet0/0
520 Type: Port ID (0x0003)
522 Sent through Interface: FastEthernet0/0
524 Type: Capabilities (0x0004)
526 Capabilities: 0x00000000
527 .... .... .... .... .... .... .... ...0 = Not a Router
528 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
529 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
530 .... .... .... .... .... .... .... 0... = Not a Switch
531 .... .... .... .... .... .... ...0 .... = Not a Host
532 .... .... .... .... .... .... ..0. .... = Not IGMP capable
533 .... .... .... .... .... .... .0.. .... = Not a Repeater
535 Type: Duplex (0x000b)
539 struct lldpd_chassis
*nchassis
= NULL
;
540 struct lldpd_port
*nport
= NULL
;
542 fail_unless(cdpv2_guess(pkt1
, sizeof(pkt1
)));
543 fail_unless(cdp_decode(NULL
, pkt1
, sizeof(pkt1
), &hardware
,
544 &nchassis
, &nport
) != -1);
545 if (!nchassis
|| !nport
) {
546 fail("unable to decode packet");
549 ck_assert_int_eq(nchassis
->c_id_subtype
,
550 LLDP_CHASSISID_SUBTYPE_LOCAL
);
551 ck_assert_int_eq(nchassis
->c_id_len
, strlen("rtbg6test01"));
552 fail_unless(memcmp(nchassis
->c_id
,
553 "rtbg6test01", strlen("rtbg6test01")) == 0);
554 ck_assert_str_eq(nchassis
->c_name
, "rtbg6test01");
555 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
556 (u_int32_t
)inet_addr("172.66.55.3"));
557 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_iface
, 0);
558 ck_assert_int_eq(nport
->p_id_subtype
,
559 LLDP_PORTID_SUBTYPE_IFNAME
);
560 ck_assert_int_eq(nport
->p_id_len
, strlen("FastEthernet0/0"));
561 fail_unless(memcmp(nport
->p_id
,
562 "FastEthernet0/0", strlen("FastEthernet0/0")) == 0);
563 ck_assert_str_eq(nport
->p_descr
, "FastEthernet0/0");
564 ck_assert_int_eq(nchassis
->c_cap_enabled
, LLDP_CAP_STATION
);
565 ck_assert_str_eq(nchassis
->c_descr
,
566 "cisco 7206VXR running on\n"
567 "Cisco Internetwork Operating System Software \n"
568 "IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)\n"
569 "Copyright (c) 1986-2007 by cisco Systems, Inc.\n"
570 "Compiled Thu 26-Apr-07 21:56 by pwade");
579 Suite
*s
= suite_create("CDP");
582 TCase
*tc_send
= tcase_create("Send CDP packets");
583 TCase
*tc_receive
= tcase_create("Receive CDP packets");
585 tcase_add_checked_fixture(tc_send
, pcap_setup
, pcap_teardown
);
586 tcase_add_test(tc_send
, test_send_cdpv1
);
587 tcase_add_test(tc_send
, test_send_cdpv2
);
588 suite_add_tcase(s
, tc_send
);
590 tcase_add_test(tc_receive
, test_recv_cdpv1
);
591 tcase_add_test(tc_receive
, test_recv_cdpv2
);
592 suite_add_tcase(s
, tc_receive
);
602 Suite
*s
= cdp_suite ();
603 SRunner
*sr
= srunner_create (s
);
604 srunner_set_fork_status (sr
, CK_NOFORK
); /* Can't fork because
607 srunner_run_all (sr
, CK_ENV
);
608 number_failed
= srunner_ntests_failed (sr
);
610 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;