3 #include <sys/socket.h>
5 #include <netinet/in.h>
7 #include "../src/lldpd.h"
10 char filenameprefix
[] = "cdp_send";
14 START_TEST (test_send_cdpv1
)
17 /* Packet we should build:
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)
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)
32 Cisco Discovery Protocol
35 Checksum: 0x3af7 [correct]
38 Device ID: First chassis
39 Type: Device ID (0x0001)
41 Device ID: First chassis
43 Type: Addresses (0x0002)
45 Number of addresses: 1
46 IP address: 172.17.142.37
51 IP address: 172.17.142.37
52 Port ID: FastEthernet 1/5
53 Type: Port ID (0x0003)
55 Sent through Interface: FastEthernet 1/5
57 Type: Capabilities (0x0004)
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
68 Type: Software version (0x0005)
70 Software Version: Chassis description
72 Type: Platform (0x0006)
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 };
94 struct lldpd_mgmt
*mgmt
;
96 /* Populate port and chassis */
97 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_IFNAME
;
98 hardware
.h_lport
.p_id
= "Not used";
99 hardware
.h_lport
.p_id_len
= strlen(hardware
.h_lport
.p_id
);
100 hardware
.h_lport
.p_descr
= "FastEthernet 1/5";
101 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
102 chassis
.c_id
= macaddress
;
103 chassis
.c_id_len
= ETH_ALEN
;
104 chassis
.c_name
= "First chassis";
105 chassis
.c_descr
= "Chassis description";
106 chassis
.c_cap_available
= chassis
.c_cap_enabled
= LLDP_CAP_ROUTER
;
107 TAILQ_INIT(&chassis
.c_mgmt
);
108 addr
= inet_addr("172.17.142.37");
109 mgmt
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
110 &addr
, sizeof(in_addr_t
), 0);
113 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt
, m_entries
);
116 n
= cdpv1_send(NULL
, &hardware
);
118 fail("unable to build packet");
121 if (TAILQ_EMPTY(&pkts
)) {
122 fail("no packets sent");
125 pkt
= TAILQ_FIRST(&pkts
);
126 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
127 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
128 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
132 START_TEST (test_send_cdpv2
)
135 /* Packet we should build:
137 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
138 Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
146 Control field: U, func=UI (0x03)
147 000. 00.. = Command: Unnumbered Information (0x00)
148 .... ..11 = Frame type: Unnumbered frame (0x03)
149 Organization Code: Cisco (0x00000c)
151 Cisco Discovery Protocol
154 Checksum: 0x5926 [correct]
157 Device ID: Second chassis
158 Type: Device ID (0x0001)
160 Device ID: Second chassis
162 Type: Addresses (0x0002)
164 Number of addresses: 2
165 IP address: 172.17.142.36
170 IP address: 172.17.142.36
171 IP address: 172.17.142.38
176 IP address: 172.17.142.38
177 Port ID: Gigabit Ethernet 5/8
178 Type: Port ID (0x0003)
180 Sent through Interface: Gigabit Ethernet 5/8
182 Type: Capabilities (0x0004)
184 Capabilities: 0x00000019
185 .... .... .... .... .... .... .... ...1 = Is a Router
186 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
187 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
188 .... .... .... .... .... .... .... 1... = Is a Switch
189 .... .... .... .... .... .... ...1 .... = Is a Host
190 .... .... .... .... .... .... ..0. .... = Not IGMP capable
191 .... .... .... .... .... .... .0.. .... = Not a Repeater
193 Type: Software version (0x0005)
195 Software Version: Chassis description
197 Type: Platform (0x0006)
202 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10,
203 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x78, 0xaa, 0xaa,
204 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
205 0xc8, 0x67, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65,
206 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61,
207 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x1a,
208 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0xcc, 0x00,
209 0x04, 0xac, 0x11, 0x8e, 0x24, 0x01, 0x01, 0xcc,
210 0x00, 0x04, 0xac, 0x11, 0x8e, 0x26, 0x00, 0x03,
211 0x00, 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69,
212 0x74, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e,
213 0x65, 0x74, 0x20, 0x35, 0x2f, 0x38, 0x00, 0x04,
214 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05,
215 0x00, 0x17, 0x43, 0x68, 0x61, 0x73, 0x73, 0x69,
216 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
217 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00,
218 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 };
222 struct lldpd_mgmt
*mgmt1
;
223 struct lldpd_mgmt
*mgmt2
;
225 /* Populate port and chassis */
226 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_LLADDR
;
227 hardware
.h_lport
.p_id
= macaddress
;
228 hardware
.h_lport
.p_id_len
= ETH_ALEN
;
229 hardware
.h_lport
.p_descr
= "Gigabit Ethernet 5/8";
230 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
231 chassis
.c_id
= macaddress
;
232 chassis
.c_id_len
= ETH_ALEN
;
233 chassis
.c_name
= "Second chassis";
234 chassis
.c_descr
= "Chassis description";
235 chassis
.c_cap_available
= chassis
.c_cap_enabled
=
236 LLDP_CAP_ROUTER
| LLDP_CAP_BRIDGE
;
237 TAILQ_INIT(&chassis
.c_mgmt
);
238 addr1
= inet_addr("172.17.142.36");
239 addr2
= inet_addr("172.17.142.38");
240 mgmt1
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
241 &addr1
, sizeof(in_addr_t
), 0);
242 mgmt2
= lldpd_alloc_mgmt(LLDPD_AF_IPV4
,
243 &addr2
, sizeof(in_addr_t
), 0);
244 if (mgmt1
== NULL
|| mgmt2
== NULL
)
246 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt1
, m_entries
);
247 TAILQ_INSERT_TAIL(&chassis
.c_mgmt
, mgmt2
, m_entries
);
250 n
= cdpv2_send(NULL
, &hardware
);
252 fail("unable to build packet");
255 if (TAILQ_EMPTY(&pkts
)) {
256 fail("no packets sent");
259 pkt
= TAILQ_FIRST(&pkts
);
260 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
261 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
262 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
266 START_TEST (test_recv_cdpv1
)
269 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x00, 0xe0,
270 0x1e, 0xd5, 0xd5, 0x15, 0x01, 0x1e, 0xaa, 0xaa,
271 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4,
272 0xdf, 0xf0, 0x00, 0x01, 0x00, 0x06, 0x52, 0x31,
273 0x00, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01,
274 0x01, 0x01, 0xcc, 0x00, 0x04, 0xc0, 0xa8, 0x0a,
275 0x01, 0x00, 0x03, 0x00, 0x0d, 0x45, 0x74, 0x68,
276 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x00, 0x04,
277 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x05,
278 0x00, 0xd8, 0x43, 0x69, 0x73, 0x63, 0x6f, 0x20,
279 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
280 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, 0x70, 0x65,
281 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x53,
282 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x53, 0x6f,
283 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x0a,
284 0x49, 0x4f, 0x53, 0x20, 0x28, 0x74, 0x6d, 0x29,
285 0x20, 0x31, 0x36, 0x30, 0x30, 0x20, 0x53, 0x6f,
286 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x28,
287 0x43, 0x31, 0x36, 0x30, 0x30, 0x2d, 0x4e, 0x59,
288 0x2d, 0x4c, 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72,
289 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x31, 0x2e,
290 0x32, 0x28, 0x31, 0x32, 0x29, 0x50, 0x2c, 0x20,
291 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20,
292 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45,
293 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, 0x43,
294 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74,
295 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x38,
296 0x36, 0x2d, 0x31, 0x39, 0x39, 0x38, 0x20, 0x62,
297 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
298 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c,
299 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, 0x6f,
300 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54,
301 0x75, 0x65, 0x20, 0x30, 0x33, 0x2d, 0x4d, 0x61,
302 0x72, 0x2d, 0x39, 0x38, 0x20, 0x30, 0x36, 0x3a,
303 0x33, 0x33, 0x20, 0x62, 0x79, 0x20, 0x64, 0x73,
304 0x63, 0x68, 0x77, 0x61, 0x72, 0x74, 0x00, 0x06,
305 0x00, 0x0e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20,
306 0x31, 0x36, 0x30, 0x31 };
309 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
310 Source: Cisco_d5:d5:15 (00:e0:1e:d5:d5:15)
317 Control field: U, func=UI (0x03)
318 000. 00.. = Command: Unnumbered Information (0x00)
319 .... ..11 = Frame type: Unnumbered frame (0x03)
320 Organization Code: Cisco (0x00000c)
322 Cisco Discovery Protocol
325 Checksum: 0xdff0 [correct]
329 Type: Device ID (0x0001)
333 Type: Addresses (0x0002)
335 Number of addresses: 1
336 IP address: 192.168.10.1
341 IP address: 192.168.10.1
343 Type: Port ID (0x0003)
345 Sent through Interface: Ethernet0
347 Type: Capabilities (0x0004)
349 Capabilities: 0x00000011
350 .... .... .... .... .... .... .... ...1 = Is a Router
351 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
352 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
353 .... .... .... .... .... .... .... 0... = Not a Switch
354 .... .... .... .... .... .... ...1 .... = Is a Host
355 .... .... .... .... .... .... ..0. .... = Not IGMP capable
356 .... .... .... .... .... .... .0.. .... = Not a Repeater
358 Type: Software version (0x0005)
360 Software Version: Cisco Internetwork Operating System Software
361 IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)
362 Copyright (c) 1986-1998 by cisco Systems, Inc.
363 Compiled Tue 03-Mar-98 06:33 by dschwart
365 Type: Platform (0x0006)
369 struct lldpd_chassis
*nchassis
= NULL
;
370 struct lldpd_port
*nport
= NULL
;
372 fail_unless(cdpv1_guess(pkt1
, sizeof(pkt1
)));
373 fail_unless(cdp_decode(NULL
, pkt1
, sizeof(pkt1
), &hardware
,
374 &nchassis
, &nport
) != -1);
375 if (!nchassis
|| !nport
) {
376 fail("unable to decode packet");
379 ck_assert_int_eq(nchassis
->c_id_subtype
,
380 LLDP_CHASSISID_SUBTYPE_LOCAL
);
381 ck_assert_int_eq(nchassis
->c_id_len
, 2);
382 fail_unless(memcmp(nchassis
->c_id
, "R1", 2) == 0);
383 ck_assert_str_eq(nchassis
->c_name
, "R1");
384 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
385 (u_int32_t
)inet_addr("192.168.10.1"));
386 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_iface
, 0);
387 ck_assert_int_eq(nport
->p_id_subtype
,
388 LLDP_PORTID_SUBTYPE_IFNAME
);
389 ck_assert_int_eq(nport
->p_id_len
, strlen("Ethernet0"));
390 fail_unless(memcmp(nport
->p_id
,
391 "Ethernet0", strlen("Ethernet0")) == 0);
392 ck_assert_str_eq(nport
->p_descr
, "Ethernet0");
393 ck_assert_int_eq(nchassis
->c_cap_enabled
, LLDP_CAP_ROUTER
);
394 ck_assert_str_eq(nchassis
->c_descr
,
395 "cisco 1601 running on\n"
396 "Cisco Internetwork Operating System Software \n"
397 "IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1)\n"
398 "Copyright (c) 1986-1998 by cisco Systems, Inc.\n"
399 "Compiled Tue 03-Mar-98 06:33 by dschwart");
403 START_TEST (test_recv_cdpv2
)
406 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0xca, 0x00,
407 0x68, 0x46, 0x00, 0x00, 0x01, 0x30, 0xaa, 0xaa,
408 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4,
409 0x54, 0x27, 0x00, 0x01, 0x00, 0x0f, 0x72, 0x74,
410 0x62, 0x67, 0x36, 0x74, 0x65, 0x73, 0x74, 0x30,
411 0x31, 0x00, 0x05, 0x00, 0xd3, 0x43, 0x69, 0x73,
412 0x63, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72,
413 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20,
414 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e,
415 0x67, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
416 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
417 0x65, 0x20, 0x0a, 0x49, 0x4f, 0x53, 0x20, 0x28,
418 0x74, 0x6d, 0x29, 0x20, 0x37, 0x32, 0x30, 0x30,
419 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72,
420 0x65, 0x20, 0x28, 0x43, 0x37, 0x32, 0x30, 0x30,
421 0x2d, 0x50, 0x2d, 0x4d, 0x29, 0x2c, 0x20, 0x56,
422 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31,
423 0x32, 0x2e, 0x32, 0x28, 0x34, 0x36, 0x29, 0x2c,
424 0x20, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45,
425 0x20, 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52,
426 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a,
427 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
428 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39,
429 0x38, 0x36, 0x2d, 0x32, 0x30, 0x30, 0x37, 0x20,
430 0x62, 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f,
431 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73,
432 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43,
433 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20,
434 0x54, 0x68, 0x75, 0x20, 0x32, 0x36, 0x2d, 0x41,
435 0x70, 0x72, 0x2d, 0x30, 0x37, 0x20, 0x32, 0x31,
436 0x3a, 0x35, 0x36, 0x20, 0x62, 0x79, 0x20, 0x70,
437 0x77, 0x61, 0x64, 0x65, 0x00, 0x06, 0x00, 0x11,
438 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x37, 0x32,
439 0x30, 0x36, 0x56, 0x58, 0x52, 0x00, 0x02, 0x00,
440 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc,
441 0x00, 0x04, 0xac, 0x42, 0x37, 0x03, 0x00, 0x03,
442 0x00, 0x13, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74,
443 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x2f,
444 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00,
445 0x00, 0x00, 0x0b, 0x00, 0x05, 0x00 };
448 Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc)
449 Source: ca:00:68:46:00:00 (ca:00:68:46:00:00)
456 Control field: U, func=UI (0x03)
457 000. 00.. = Command: Unnumbered Information (0x00)
458 .... ..11 = Frame type: Unnumbered frame (0x03)
459 Organization Code: Cisco (0x00000c)
461 Cisco Discovery Protocol
464 Checksum: 0x5427 [correct]
467 Device ID: rtbg6test01
468 Type: Device ID (0x0001)
470 Device ID: rtbg6test01
472 Type: Software version (0x0005)
474 Software Version: Cisco Internetwork Operating System Software
475 IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)
476 Copyright (c) 1986-2007 by cisco Systems, Inc.
477 Compiled Thu 26-Apr-07 21:56 by pwade
478 Platform: cisco 7206VXR
479 Type: Platform (0x0006)
481 Platform: cisco 7206VXR
483 Type: Addresses (0x0002)
485 Number of addresses: 1
486 IP address: 172.66.55.3
491 IP address: 172.66.55.3
492 Port ID: FastEthernet0/0
493 Type: Port ID (0x0003)
495 Sent through Interface: FastEthernet0/0
497 Type: Capabilities (0x0004)
499 Capabilities: 0x00000000
500 .... .... .... .... .... .... .... ...0 = Not a Router
501 .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge
502 .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
503 .... .... .... .... .... .... .... 0... = Not a Switch
504 .... .... .... .... .... .... ...0 .... = Not a Host
505 .... .... .... .... .... .... ..0. .... = Not IGMP capable
506 .... .... .... .... .... .... .0.. .... = Not a Repeater
508 Type: Duplex (0x000b)
512 struct lldpd_chassis
*nchassis
= NULL
;
513 struct lldpd_port
*nport
= NULL
;
515 fail_unless(cdpv2_guess(pkt1
, sizeof(pkt1
)));
516 fail_unless(cdp_decode(NULL
, pkt1
, sizeof(pkt1
), &hardware
,
517 &nchassis
, &nport
) != -1);
518 if (!nchassis
|| !nport
) {
519 fail("unable to decode packet");
522 ck_assert_int_eq(nchassis
->c_id_subtype
,
523 LLDP_CHASSISID_SUBTYPE_LOCAL
);
524 ck_assert_int_eq(nchassis
->c_id_len
, strlen("rtbg6test01"));
525 fail_unless(memcmp(nchassis
->c_id
,
526 "rtbg6test01", strlen("rtbg6test01")) == 0);
527 ck_assert_str_eq(nchassis
->c_name
, "rtbg6test01");
528 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
529 (u_int32_t
)inet_addr("172.66.55.3"));
530 ck_assert_int_eq(TAILQ_FIRST(&nchassis
->c_mgmt
)->m_iface
, 0);
531 ck_assert_int_eq(nport
->p_id_subtype
,
532 LLDP_PORTID_SUBTYPE_IFNAME
);
533 ck_assert_int_eq(nport
->p_id_len
, strlen("FastEthernet0/0"));
534 fail_unless(memcmp(nport
->p_id
,
535 "FastEthernet0/0", strlen("FastEthernet0/0")) == 0);
536 ck_assert_str_eq(nport
->p_descr
, "FastEthernet0/0");
537 ck_assert_int_eq(nchassis
->c_cap_enabled
, LLDP_CAP_STATION
);
538 ck_assert_str_eq(nchassis
->c_descr
,
539 "cisco 7206VXR running on\n"
540 "Cisco Internetwork Operating System Software \n"
541 "IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1)\n"
542 "Copyright (c) 1986-2007 by cisco Systems, Inc.\n"
543 "Compiled Thu 26-Apr-07 21:56 by pwade");
552 Suite
*s
= suite_create("CDP");
555 TCase
*tc_send
= tcase_create("Send CDP packets");
556 TCase
*tc_receive
= tcase_create("Receive CDP packets");
558 tcase_add_checked_fixture(tc_send
, pcap_setup
, pcap_teardown
);
559 tcase_add_test(tc_send
, test_send_cdpv1
);
560 tcase_add_test(tc_send
, test_send_cdpv2
);
561 suite_add_tcase(s
, tc_send
);
563 tcase_add_test(tc_receive
, test_recv_cdpv1
);
564 tcase_add_test(tc_receive
, test_recv_cdpv2
);
565 suite_add_tcase(s
, tc_receive
);
575 Suite
*s
= cdp_suite ();
576 SRunner
*sr
= srunner_create (s
);
577 srunner_set_fork_status (sr
, CK_NOFORK
); /* Can't fork because
580 srunner_run_all (sr
, CK_ENV
);
581 number_failed
= srunner_ntests_failed (sr
);
583 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;