]> git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/check_cdp.c
tests/integration: reduce the number of emulated neighbor
[thirdparty/lldpd.git] / tests / check_cdp.c
1 /* -*- mode: c; c-file-style: "openbsd" -*- */
2 /*
3 * Copyright (c) 2015 Vincent Bernat <bernat@luffy.cx>
4 *
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.
8 *
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.
16 */
17
18 #include <stdlib.h>
19 #include <sys/socket.h>
20 #include <arpa/inet.h>
21 #include <netinet/in.h>
22 #include <check.h>
23 #include "common.h"
24
25 char filenameprefix[] = "cdp_send";
26
27 #ifdef ENABLE_CDP
28
29 START_TEST (test_send_cdpv1)
30 {
31 int n;
32 /* Packet we should build:
33 IEEE 802.3 Ethernet
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)
36 Length: 106
37 Logical-Link Control
38 DSAP: SNAP (0xaa)
39 IG Bit: Individual
40 SSAP: SNAP (0xaa)
41 CR Bit: Command
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)
46 PID: CDP (0x2000)
47 Cisco Discovery Protocol
48 Version: 1
49 TTL: 180 seconds
50 Checksum: 0x3af7 [correct]
51 [Good: True]
52 [Bad : False]
53 Device ID: First chassis
54 Type: Device ID (0x0001)
55 Length: 17
56 Device ID: First chassis
57 Addresses
58 Type: Addresses (0x0002)
59 Length: 17
60 Number of addresses: 1
61 IP address: 172.17.142.37
62 Protocol type: NLPID
63 Protocol length: 1
64 Protocol: IP
65 Address length: 4
66 IP address: 172.17.142.37
67 Port ID: FastEthernet 1/5
68 Type: Port ID (0x0003)
69 Length: 20
70 Sent through Interface: FastEthernet 1/5
71 Capabilities
72 Type: Capabilities (0x0004)
73 Length: 8
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
82 Software Version
83 Type: Software version (0x0005)
84 Length: 23
85 Software Version: Chassis description
86 Platform: Linux
87 Type: Platform (0x0006)
88 Length: 9
89 Platform: Linux
90 */
91 char pkt1[] = {
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 };
107 struct packet *pkt;
108 in_addr_t addr;
109 struct lldpd_mgmt *mgmt;
110 struct lldpd cfg = {
111 .g_config = {
112 .c_platform = "Linux"
113 }
114 };
115
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);
131 if (mgmt == NULL)
132 ck_abort();
133 TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries);
134
135 /* Build packet */
136 n = cdpv1_send(&cfg, &hardware);
137 if (n != 0) {
138 fail("unable to build packet");
139 return;
140 }
141 if (TAILQ_EMPTY(&pkts)) {
142 fail("no packets sent");
143 return;
144 }
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");
149 }
150 END_TEST
151
152 START_TEST (test_send_cdpv2)
153 {
154 int n;
155 /* Packet we should build:
156 IEEE 802.3 Ethernet
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)
159 the factory default)
160 Length: 111
161 Logical-Link Control
162 DSAP: SNAP (0xaa)
163 IG Bit: Individual
164 SSAP: SNAP (0xaa)
165 CR Bit: Command
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)
170 PID: CDP (0x2000)
171 Cisco Discovery Protocol
172 Version: 2
173 TTL: 180 seconds
174 Checksum: 0x5926 [correct]
175 [Good: True]
176 [Bad : False]
177 Device ID: Second chassis
178 Type: Device ID (0x0001)
179 Length: 18
180 Device ID: Second chassis
181 Addresses
182 Type: Addresses (0x0002)
183 Length: 26
184 Number of addresses: 2
185 IP address: 172.17.142.36
186 Protocol type: NLPID
187 Protocol length: 1
188 Protocol: IP
189 Address length: 4
190 IP address: 172.17.142.36
191 IP address: 172.17.142.38
192 Protocol type: NLPID
193 Protocol length: 1
194 Protocol: IP
195 Address length: 4
196 IP address: 172.17.142.38
197 Port ID: Gigabit Ethernet 5/8
198 Type: Port ID (0x0003)
199 Length: 24
200 Sent through Interface: Gigabit Ethernet 5/8
201 Capabilities
202 Type: Capabilities (0x0004)
203 Length: 8
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
212 Software Version
213 Type: Software version (0x0005)
214 Length: 23
215 Software Version: Chassis description
216 Platform: Linux
217 Type: Platform (0x0006)
218 Length: 9
219 Platform: Linux
220 */
221 char pkt1[] = {
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 };
239 struct packet *pkt;
240 in_addr_t addr1;
241 in_addr_t addr2;
242 struct lldpd_mgmt *mgmt1;
243 struct lldpd_mgmt *mgmt2;
244 struct lldpd cfg = {
245 .g_config = {
246 .c_platform = "Linux"
247 }
248 };
249
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)
270 ck_abort();
271 TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt1, m_entries);
272 TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt2, m_entries);
273
274 /* Build packet */
275 n = cdpv2_send(&cfg, &hardware);
276 if (n != 0) {
277 fail("unable to build packet");
278 return;
279 }
280 if (TAILQ_EMPTY(&pkts)) {
281 fail("no packets sent");
282 return;
283 }
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");
288 }
289 END_TEST
290
291 START_TEST (test_recv_cdpv1)
292 {
293 char pkt1[] = {
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 };
332 /* This is:
333 IEEE 802.3 Ethernet
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)
336 Length: 286
337 Logical-Link Control
338 DSAP: SNAP (0xaa)
339 IG Bit: Individual
340 SSAP: SNAP (0xaa)
341 CR Bit: Command
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)
346 PID: CDP (0x2000)
347 Cisco Discovery Protocol
348 Version: 1
349 TTL: 180 seconds
350 Checksum: 0xdff0 [correct]
351 [Good: True]
352 [Bad : False]
353 Device ID: R1
354 Type: Device ID (0x0001)
355 Length: 6
356 Device ID: R1
357 Addresses
358 Type: Addresses (0x0002)
359 Length: 17
360 Number of addresses: 1
361 IP address: 192.168.10.1
362 Protocol type: NLPID
363 Protocol length: 1
364 Protocol: IP
365 Address length: 4
366 IP address: 192.168.10.1
367 Port ID: Ethernet0
368 Type: Port ID (0x0003)
369 Length: 13
370 Sent through Interface: Ethernet0
371 Capabilities
372 Type: Capabilities (0x0004)
373 Length: 8
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
382 Software Version
383 Type: Software version (0x0005)
384 Length: 216
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
389 Platform: cisco 1601
390 Type: Platform (0x0006)
391 Length: 14
392 Platform: cisco 1601
393 */
394 struct lldpd_chassis *nchassis = NULL;
395 struct lldpd_port *nport = NULL;
396
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");
402 return;
403 }
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");
425 }
426 END_TEST
427
428 START_TEST (test_recv_cdpv2)
429 {
430 char pkt1[] = {
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 };
471 /* This is:
472 IEEE 802.3 Ethernet
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)
475 Length: 304
476 Logical-Link Control
477 DSAP: SNAP (0xaa)
478 IG Bit: Individual
479 SSAP: SNAP (0xaa)
480 CR Bit: Command
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)
485 PID: CDP (0x2000)
486 Cisco Discovery Protocol
487 Version: 2
488 TTL: 180 seconds
489 Checksum: 0x5427 [correct]
490 [Good: True]
491 [Bad : False]
492 Device ID: rtbg6test01
493 Type: Device ID (0x0001)
494 Length: 15
495 Device ID: rtbg6test01
496 Software Version
497 Type: Software version (0x0005)
498 Length: 211
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)
505 Length: 17
506 Platform: cisco 7206VXR
507 Addresses
508 Type: Addresses (0x0002)
509 Length: 17
510 Number of addresses: 1
511 IP address: 172.66.55.3
512 Protocol type: NLPID
513 Protocol length: 1
514 Protocol: IP
515 Address length: 4
516 IP address: 172.66.55.3
517 Port ID: FastEthernet0/0
518 Type: Port ID (0x0003)
519 Length: 19
520 Sent through Interface: FastEthernet0/0
521 Capabilities
522 Type: Capabilities (0x0004)
523 Length: 8
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
532 Duplex: Half
533 Type: Duplex (0x000b)
534 Length: 5
535 Duplex: Half
536 */
537 struct lldpd_chassis *nchassis = NULL;
538 struct lldpd_port *nport = NULL;
539
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");
545 return;
546 }
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");
569 }
570 END_TEST
571
572 #endif
573
574 Suite *
575 cdp_suite(void)
576 {
577 Suite *s = suite_create("CDP");
578
579 #ifdef ENABLE_CDP
580 TCase *tc_send = tcase_create("Send CDP packets");
581 TCase *tc_receive = tcase_create("Receive CDP packets");
582
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);
587
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);
591 #endif
592
593 return s;
594 }
595
596 int
597 main()
598 {
599 int number_failed;
600 Suite *s = cdp_suite ();
601 SRunner *sr = srunner_create (s);
602 srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because
603 we need to write
604 files */
605 srunner_run_all (sr, CK_ENV);
606 number_failed = srunner_ntests_failed (sr);
607 srunner_free (sr);
608 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
609 }