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
[] = "edp_send";
29 START_TEST (test_send_basic
)
32 /* Packet we should build:
33 Extreme Discovery Protocol
37 Checksum: 0xde22 [correct]
41 Machine ID type: MAC (0)
42 Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
43 Display: "First chassis"
44 Marker 0x99, length 18, type 1 = Display
49 Info: Slot/Port: 1/4, Version: 7.6.4.99
50 Marker 0x99, length 36, type 2 = Info
57 Reserved: 000000000000
58 Version: 7.6.4 Internal: 99
62 Version (sustaining): 4
63 Version (internal): 99
64 Connections: FFFFFFFF000000000000000000000000
66 Marker 0x99, length 4, type 0 = Null
72 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10,
73 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa,
74 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
75 0x00, 0x4a, 0xde, 0x22, 0x00, 0x00, 0x00, 0x00,
76 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01,
77 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20,
78 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00,
79 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 };
86 /* Populate port and chassis */
87 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_IFNAME
;
88 hardware
.h_lport
.p_id
= "Not used";
89 hardware
.h_lport
.p_id_len
= strlen(hardware
.h_lport
.p_id
);
90 hardware
.h_lport
.p_descr
= "Not used";
91 strlcpy(hardware
.h_ifname
, "eth3", sizeof(hardware
.h_ifname
));
92 hardware
.h_ifindex
= 4;
93 chassis
.c_id_subtype
= LLDP_CHASSISID_SUBTYPE_LLADDR
;
94 chassis
.c_id
= macaddress
;
95 chassis
.c_id_len
= ETHER_ADDR_LEN
;
96 chassis
.c_name
= "First chassis";
98 n
= edp_send(NULL
, &hardware
);
100 fail("unable to build packet");
103 if (TAILQ_EMPTY(&pkts
)) {
104 fail("no packets sent");
107 pkt
= TAILQ_FIRST(&pkts
);
108 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
109 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
110 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than one packet sent");
115 START_TEST (test_send_vlans
)
118 /* Packets we should build:
119 Extreme Discovery Protocol
123 Checksum: 0xde20 [correct]
127 Machine ID type: MAC (0)
128 Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
129 Display: "First chassis"
130 Marker 0x99, length 18, type 1 = Display
132 TLV type: Display (1)
135 Info: Slot/Port: 1/4, Version: 7.6.4.99
136 Marker 0x99, length 36, type 2 = Info
143 Reserved: 000000000000
144 Version: 7.6.4 Internal: 99
148 Version (sustaining): 4
149 Version (internal): 99
150 Connections: FFFFFFFF000000000000000000000000
152 Marker 0x99, length 4, type 0 = Null
157 Extreme Discovery Protocol
161 Checksum: 0x28c4 [correct]
165 Machine ID type: MAC (0)
166 Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
167 Vlan: ID 157, Name "First VLAN"
168 Marker 0x99, length 27, type 5 = VL
173 0... .... = Flags-IP: Not set
174 .000 000. = Flags-reserved: 0x00
175 .... ...0 = Flags-Unknown: Not set
179 IP addr: 0.0.0.0 (0.0.0.0)
181 Vlan: ID 1247, Name "Second VLAN"
182 Marker 0x99, length 28, type 5 = VL
187 0... .... = Flags-IP: Not set
188 .000 000. = Flags-reserved: 0x00
189 .... ...0 = Flags-Unknown: Not set
193 IP addr: 0.0.0.0 (0.0.0.0)
195 Vlan: ID 741, Name "Third VLAN"
196 Marker 0x99, length 27, type 5 = VL
201 0... .... = Flags-IP: Not set
202 .000 000. = Flags-reserved: 0x00
203 .... ...0 = Flags-Unknown: Not set
207 IP addr: 0.0.0.0 (0.0.0.0)
210 Marker 0x99, length 4, type 0 = Null
216 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10,
217 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa,
218 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
219 0x00, 0x4a, 0xde, 0x20, 0x00, 0x02, 0x00, 0x00,
220 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01,
221 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20,
222 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00,
223 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff,
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 };
230 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10,
231 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6e, 0xaa, 0xaa,
232 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
233 0x00, 0x66, 0x28, 0xc4, 0x00, 0x03, 0x00, 0x00,
234 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x05,
235 0x00, 0x1b, 0x00, 0x00, 0x00, 0x9d, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69,
237 0x72, 0x73, 0x74, 0x20, 0x56, 0x4c, 0x41, 0x4e,
238 0x00, 0x99, 0x05, 0x00, 0x1c, 0x00, 0x00, 0x04,
239 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20,
241 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00,
242 0x1b, 0x00, 0x00, 0x02, 0xe5, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69,
244 0x72, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00,
245 0x99, 0x00, 0x00, 0x04 };
248 struct lldpd_vlan vlan1
, vlan2
, vlan3
;
250 /* Populate port and chassis */
251 hardware
.h_lport
.p_id_subtype
= LLDP_PORTID_SUBTYPE_IFNAME
;
252 hardware
.h_lport
.p_id
= "Not used";
253 hardware
.h_lport
.p_id_len
= strlen(hardware
.h_lport
.p_id
);
254 hardware
.h_lport
.p_descr
= "Not used";
255 strlcpy(hardware
.h_ifname
, "eth3", sizeof(hardware
.h_ifname
));
256 hardware
.h_ifindex
= 4;
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
= "First chassis";
261 vlan1
.v_name
= "First VLAN"; vlan1
.v_vid
= 157;
262 vlan2
.v_name
= "Second VLAN"; vlan2
.v_vid
= 1247;
263 vlan3
.v_name
= "Third VLAN"; vlan3
.v_vid
= 741;
264 TAILQ_INSERT_TAIL(&hardware
.h_lport
.p_vlans
, &vlan1
, v_entries
);
265 TAILQ_INSERT_TAIL(&hardware
.h_lport
.p_vlans
, &vlan2
, v_entries
);
266 TAILQ_INSERT_TAIL(&hardware
.h_lport
.p_vlans
, &vlan3
, v_entries
);
269 n
= edp_send(NULL
, &hardware
);
271 fail("unable to build packet");
274 if (TAILQ_EMPTY(&pkts
)) {
275 fail("no packets sent");
278 pkt
= TAILQ_FIRST(&pkts
);
279 ck_assert_int_eq(pkt
->size
, sizeof(pkt1
));
280 fail_unless(memcmp(pkt
->data
, pkt1
, sizeof(pkt1
)) == 0);
281 pkt
= TAILQ_NEXT(pkt
, next
);
283 fail("need one more packet");
286 ck_assert_int_eq(pkt
->size
, sizeof(pkt2
));
287 fail_unless(memcmp(pkt
->data
, pkt2
, sizeof(pkt2
)) == 0);
288 fail_unless(TAILQ_NEXT(pkt
, next
) == NULL
, "more than two packets sent");
293 START_TEST (test_recv_edp
)
296 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04,
297 0x96, 0x05, 0x44, 0x6f, 0x01, 0x44, 0xaa, 0xaa,
298 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
299 0x01, 0x3c, 0x05, 0xdf, 0x03, 0x0f, 0x00, 0x00,
300 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x02,
301 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06,
303 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x99, 0x01, 0x01, 0x04, 0x6e, 0x65,
306 0x30, 0x35, 0x30, 0x31, 0x73, 0x77, 0x2e, 0x58,
307 0x58, 0x58, 0x58, 0x58, 0x58, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 0x00, 0x00, 0x00, 0x03, 0x7b, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x80, 0x79, 0x0d, 0xec, 0xff, 0xff,
311 0xff, 0xff, 0x80, 0xa7, 0x8b, 0x24, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x17, 0x08, 0x7e, 0xe5, 0xe2,
313 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00,
314 0x00, 0x02, 0x81, 0xb2, 0x19, 0xf0, 0x00, 0x00,
315 0x00, 0x02, 0x80, 0xa5, 0x67, 0x20, 0xee, 0xee,
316 0xee, 0xee, 0x80, 0xea, 0x8c, 0xac, 0x00, 0x00,
317 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
318 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00,
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
325 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00,
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 0x00, 0x00, 0x80, 0xa4, 0x86, 0x2c, 0xee, 0xee,
332 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
333 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00,
334 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0xe0,
335 0x2b, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
336 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
337 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x99, 0x00,
341 Destination: Extreme-EDP (00:e0:2b:00:00:00)
342 Source: ExtremeN_05:44:6f (00:04:96:05:44:6f)
349 Control field: U, func=UI (0x03)
350 000. 00.. = Command: Unnumbered Information (0x00)
351 .... ..11 = Frame type: Unnumbered frame (0x03)
352 Organization Code: Extreme Networks (0x00e02b)
354 Extreme Discovery Protocol
358 Checksum: 0xdf05 [correct]
362 Machine ID type: MAC (0)
363 Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f)
364 Info: Slot/Port: 1/1, Version: 7.6.4.0
365 Marker 0x99, length 36, type 2 = Info
372 Reserved: 000000000000
373 Version: 7.6.4 Internal: 0
377 Version (sustaining): 4
378 Version (internal): 0
379 Connections: FFFF0000000000000000000000000000
380 Display: "ne0501sw.XXXXXX"
381 Marker 0x99, length 260, type 1 = Display
383 TLV type: Display (1)
385 Name: ne0501sw.XXXXXX
387 Marker 0x99, length 4, type 0 = Null
395 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04,
396 0x96, 0x05, 0x44, 0x6f, 0x01, 0x48, 0xaa, 0xaa,
397 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
398 0x01, 0x40, 0x73, 0x04, 0x03, 0x10, 0x00, 0x00,
399 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x05,
400 0x00, 0x64, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00,
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x65,
402 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, 0x43, 0x61,
403 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x61, 0x76,
404 0x65, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65,
405 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
406 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x76, 0x20, 0x28,
407 0x25, 0x64, 0x29, 0x0a, 0x00, 0x00, 0x4e, 0x6f,
408 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20,
409 0x66, 0x6f, 0x72, 0x20, 0x73, 0x75, 0x70, 0x65,
410 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49,
411 0x6e, 0x73, 0x74, 0x20, 0x25, 0x64, 0x00, 0x00,
412 0x00, 0x00, 0x99, 0x05, 0x00, 0x64, 0x00, 0x00,
413 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
414 0x00, 0x00, 0x4d, 0x61, 0x63, 0x56, 0x6c, 0x61,
415 0x6e, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65,
416 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05,
425 0x00, 0x64, 0x80, 0x00, 0x00, 0x32, 0x00, 0x00,
426 0x00, 0x00, 0x0a, 0x32, 0x00, 0x3f, 0x41, 0x64,
427 0x6d, 0x69, 0x6e, 0x42, 0x32, 0x00, 0x00, 0x00,
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 };
440 Destination: Extreme-EDP (00:e0:2b:00:00:00)
441 Source: ExtremeN_05:44:6f (00:04:96:05:44:6f)
448 Control field: U, func=UI (0x03)
449 000. 00.. = Command: Unnumbered Information (0x00)
450 .... ..11 = Frame type: Unnumbered frame (0x03)
451 Organization Code: Extreme Networks (0x00e02b)
453 Extreme Discovery Protocol
457 Checksum: 0x7304 [correct]
461 Machine ID type: MAC (0)
462 Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f)
463 Vlan: ID 1, Name "Default"
464 Marker 0x99, length 100, type 5 = VL
469 1... .... = Flags-IP: Set
470 .000 000. = Flags-reserved: 0x00
471 .... ...0 = Flags-Unknown: Not set
475 IP addr: 0.0.0.0 (0.0.0.0)
477 Vlan: ID 0, Name "MacVlanDiscover"
478 Marker 0x99, length 100, type 5 = VL
483 0... .... = Flags-IP: Not set
484 .000 000. = Flags-reserved: 0x00
485 .... ...0 = Flags-Unknown: Not set
489 IP addr: 0.0.0.0 (0.0.0.0)
490 Name: MacVlanDiscover
491 Vlan: ID 50, Name "AdminB2"
492 Marker 0x99, length 100, type 5 = VL
497 1... .... = Flags-IP: Set
498 .000 000. = Flags-reserved: 0x00
499 .... ...0 = Flags-Unknown: Not set
503 IP addr: 10.50.0.63 (10.50.0.63)
506 Marker 0x99, length 4, type 0 = Null
511 struct lldpd_vlan
*vlan
;
513 struct lldpd_chassis
*nchassis
= NULL
;
514 struct lldpd_port
*nport
= NULL
;
516 char mac1
[] = { 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f };
518 cfg
.g_config
.c_mgmt_pattern
= NULL
;
519 fail_unless(edp_decode(&cfg
, pkt1
, sizeof(pkt1
), &hardware
,
520 &nchassis
, &nport
) != -1);
521 if (!nchassis
|| !nport
) {
522 fail("unable to decode packet");
525 ck_assert_int_eq(nchassis
->c_id_subtype
,
526 LLDP_CHASSISID_SUBTYPE_LLADDR
);
527 ck_assert_int_eq(nchassis
->c_id_len
, ETHER_ADDR_LEN
);
528 fail_unless(memcmp(nchassis
->c_id
, mac1
, ETHER_ADDR_LEN
) == 0);
529 ck_assert_int_eq(nport
->p_id_subtype
,
530 LLDP_PORTID_SUBTYPE_IFNAME
);
531 ck_assert_int_eq(nport
->p_id_len
, strlen("1/1"));
532 fail_unless(memcmp(nport
->p_id
,
533 "1/1", strlen("1/1")) == 0);
534 ck_assert_str_eq(nport
->p_descr
, "Slot 1 / Port 1");
535 ck_assert_str_eq(nchassis
->c_name
, "ne0501sw.XXXXXX");
536 ck_assert_str_eq(nchassis
->c_descr
, "EDP enabled device, version 7.6.4.0");
537 ck_assert_int_eq(nchassis
->c_cap_enabled
, 0);
540 /* Add this port to list of remote port for hardware port */
541 TAILQ_INSERT_TAIL(&hardware
.h_rports
, nport
, p_entries
);
542 nport
->p_chassis
= nchassis
;
543 nport
->p_protocol
= LLDPD_MODE_EDP
;
545 /* Recept second packet */
546 nchassis
= NULL
; nport
= NULL
;
547 fail_unless(edp_decode(&cfg
, pkt2
, sizeof(pkt2
), &hardware
,
548 &nchassis
, &nport
) == -1);
549 nport
= TAILQ_FIRST(&hardware
.h_rports
);
551 fail("unable to find our previous port?");
554 ck_assert_int_eq(TAILQ_FIRST(&nport
->p_chassis
->c_mgmt
)->m_addr
.inet
.s_addr
,
555 (u_int32_t
)inet_addr("10.50.0.63"));
556 if (TAILQ_EMPTY(&nport
->p_vlans
)) {
560 vlan
= TAILQ_FIRST(&nport
->p_vlans
);
561 ck_assert_int_eq(vlan
->v_vid
, 1);
562 ck_assert_str_eq(vlan
->v_name
, "Default");
563 vlan
= TAILQ_NEXT(vlan
, v_entries
);
565 fail("no more VLAN");
568 ck_assert_int_eq(vlan
->v_vid
, 0);
569 ck_assert_str_eq(vlan
->v_name
, "MacVlanDiscover");
570 vlan
= TAILQ_NEXT(vlan
, v_entries
);
572 fail("no more VLAN");
575 ck_assert_int_eq(vlan
->v_vid
, 50);
576 ck_assert_str_eq(vlan
->v_name
, "AdminB2");
577 vlan
= TAILQ_NEXT(vlan
, v_entries
);
578 fail_unless(vlan
== NULL
);
588 Suite
*s
= suite_create("EDP");
591 TCase
*tc_send
= tcase_create("Send EDP packets");
592 TCase
*tc_receive
= tcase_create("Receive EDP packets");
594 tcase_add_checked_fixture(tc_send
, pcap_setup
, pcap_teardown
);
595 tcase_add_test(tc_send
, test_send_basic
);
597 tcase_add_test(tc_send
, test_send_vlans
);
599 suite_add_tcase(s
, tc_send
);
601 tcase_add_test(tc_receive
, test_recv_edp
);
602 suite_add_tcase(s
, tc_receive
);
612 Suite
*s
= edp_suite ();
613 SRunner
*sr
= srunner_create (s
);
614 srunner_set_fork_status (sr
, CK_NOFORK
); /* Can't fork because
617 srunner_run_all (sr
, CK_ENV
);
618 number_failed
= srunner_ntests_failed (sr
);
620 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;