summaryrefslogtreecommitdiffstats
path: root/tests/check_edp.c
blob: 726e2dde8c26e40ee598f6a9faf26f933ab5e28a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
/* -*- mode: c; c-file-style: "openbsd" -*- */
/*
 * Copyright (c) 2015 Vincent Bernat <bernat@luffy.cx>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <check.h>
#include "common.h"

char filenameprefix[] = "edp_send";

#ifdef ENABLE_EDP

START_TEST(test_send_basic)
{
	int n;
	/* Packet we should build:
Extreme Discovery Protocol
    Version: 1
    Reserved: 0
    Data length: 74
    Checksum: 0xde22 [correct]
	[Good: True]
	[Bad : False]
    Sequence number: 0
    Machine ID type: MAC (0)
    Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
    Display: "First chassis"
	Marker 0x99, length 18, type 1 = Display
	    TLV Marker: 0x99
	    TLV type: Display (1)
	    TLV length: 18
	Name: First chassis
    Info: Slot/Port: 1/4, Version: 7.6.4.99
	Marker 0x99, length 36, type 2 = Info
	    TLV Marker: 0x99
	    TLV type: Info (2)
	    TLV length: 36
	Slot: 1
	Port: 4
	Virt chassis: 0
	Reserved: 000000000000
	Version: 7.6.4 Internal: 99
	    Version: 0x07060463
	    Version (major1): 7
	    Version (major2): 6
	    Version (sustaining): 4
	    Version (internal): 99
	Connections: FFFFFFFF000000000000000000000000
    Null
	Marker 0x99, length 4, type 0 = Null
	    TLV Marker: 0x99
	    TLV type: Null (0)
	    TLV length: 4
	 */
	char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7,
		0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb,
		0x01, 0x00, 0x00, 0x4a, 0xde, 0x22, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x10,
		0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, 0x00, 0x12, 0x46, 0x69, 0x72, 0x73,
		0x74, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x99, 0x02,
		0x00, 0x24, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00,
		0x00, 0x04 };
	struct packet *pkt;

	/* Populate port and chassis */
	hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
	hardware.h_lport.p_id = "Not used";
	hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
	hardware.h_lport.p_descr = "Not used";
	strlcpy(hardware.h_ifname, "eth3", sizeof(hardware.h_ifname));
	hardware.h_ifindex = 4;
	chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
	chassis.c_id = macaddress;
	chassis.c_id_len = ETHER_ADDR_LEN;
	chassis.c_name = "First chassis";
	/* Build packet */
	n = edp_send(NULL, &hardware);
	if (n != 0) {
		fail("unable to build packet");
		return;
	}
	if (TAILQ_EMPTY(&pkts)) {
		fail("no packets sent");
		return;
	}
	pkt = TAILQ_FIRST(&pkts);
	ck_assert_int_eq(pkt->size, sizeof(pkt1));
	fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
	fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
}
END_TEST

#  ifdef ENABLE_DOT1
START_TEST(test_send_vlans)
{
	int n;
	/* Packets we should build:
Extreme Discovery Protocol
    Version: 1
    Reserved: 0
    Data length: 74
    Checksum: 0xde20 [correct]
	[Good: True]
	[Bad : False]
    Sequence number: 2
    Machine ID type: MAC (0)
    Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
    Display: "First chassis"
	Marker 0x99, length 18, type 1 = Display
	    TLV Marker: 0x99
	    TLV type: Display (1)
	    TLV length: 18
	Name: First chassis
    Info: Slot/Port: 1/4, Version: 7.6.4.99
	Marker 0x99, length 36, type 2 = Info
	    TLV Marker: 0x99
	    TLV type: Info (2)
	    TLV length: 36
	Slot: 1
	Port: 4
	Virt chassis: 0
	Reserved: 000000000000
	Version: 7.6.4 Internal: 99
	    Version: 0x07060463
	    Version (major1): 7
	    Version (major2): 6
	    Version (sustaining): 4
	    Version (internal): 99
	Connections: FFFFFFFF000000000000000000000000
    Null
	Marker 0x99, length 4, type 0 = Null
	    TLV Marker: 0x99
	    TLV type: Null (0)
	    TLV length: 4

Extreme Discovery Protocol
    Version: 1
    Reserved: 0
    Data length: 102
    Checksum: 0x28c4 [correct]
	[Good: True]
	[Bad : False]
    Sequence number: 3
    Machine ID type: MAC (0)
    Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
    Vlan: ID 157, Name "First VLAN"
	Marker 0x99, length 27, type 5 = VL
	    TLV Marker: 0x99
	    TLV type: VL (5)
	    TLV length: 27
	Flags: 0x00
	    0... .... = Flags-IP: Not set
	    .000 000. = Flags-reserved: 0x00
	    .... ...0 = Flags-Unknown: Not set
	Reserved1: 00
	Vlan ID: 157
	Reserved2: 00000000
	IP addr: 0.0.0.0 (0.0.0.0)
	Name: First VLAN
    Vlan: ID 1247, Name "Second VLAN"
	Marker 0x99, length 28, type 5 = VL
	    TLV Marker: 0x99
	    TLV type: VL (5)
	    TLV length: 28
	Flags: 0x00
	    0... .... = Flags-IP: Not set
	    .000 000. = Flags-reserved: 0x00
	    .... ...0 = Flags-Unknown: Not set
	Reserved1: 00
	Vlan ID: 1247
	Reserved2: 00000000
	IP addr: 0.0.0.0 (0.0.0.0)
	Name: Second VLAN
    Vlan: ID 741, Name "Third VLAN"
	Marker 0x99, length 27, type 5 = VL
	    TLV Marker: 0x99
	    TLV type: VL (5)
	    TLV length: 27
	Flags: 0x00
	    0... .... = Flags-IP: Not set
	    .000 000. = Flags-reserved: 0x00
	    .... ...0 = Flags-Unknown: Not set
	Reserved1: 00
	Vlan ID: 741
	Reserved2: 00000000
	IP addr: 0.0.0.0 (0.0.0.0)
	Name: Third VLAN
    Null
	Marker 0x99, length 4, type 0 = Null
	    TLV Marker: 0x99
	    TLV type: Null (0)
	    TLV length: 4
	*/
	char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7,
		0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb,
		0x01, 0x00, 0x00, 0x4a, 0xde, 0x20, 0x00, 0x02, 0x00, 0x00, 0x5e, 0x10,
		0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, 0x00, 0x12, 0x46, 0x69, 0x72, 0x73,
		0x74, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x99, 0x02,
		0x00, 0x24, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00,
		0x00, 0x04 };

	char pkt2[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7,
		0x84, 0xad, 0x00, 0x6e, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb,
		0x01, 0x00, 0x00, 0x66, 0x28, 0xc4, 0x00, 0x03, 0x00, 0x00, 0x5e, 0x10,
		0x8e, 0xe7, 0x84, 0xad, 0x99, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x9d,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69, 0x72, 0x73,
		0x74, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00, 0x1c, 0x00,
		0x00, 0x04, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53,
		0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99,
		0x05, 0x00, 0x1b, 0x00, 0x00, 0x02, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x54, 0x68, 0x69, 0x72, 0x64, 0x20, 0x56, 0x4c, 0x41,
		0x4e, 0x00, 0x99, 0x00, 0x00, 0x04 };

	struct packet *pkt;
	struct lldpd_vlan vlan1, vlan2, vlan3;

	/* Populate port and chassis */
	hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
	hardware.h_lport.p_id = "Not used";
	hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
	hardware.h_lport.p_descr = "Not used";
	strlcpy(hardware.h_ifname, "eth3", sizeof(hardware.h_ifname));
	hardware.h_ifindex = 4;
	chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
	chassis.c_id = macaddress;
	chassis.c_id_len = ETHER_ADDR_LEN;
	chassis.c_name = "First chassis";
	vlan1.v_name = "First VLAN";
	vlan1.v_vid = 157;
	vlan2.v_name = "Second VLAN";
	vlan2.v_vid = 1247;
	vlan3.v_name = "Third VLAN";
	vlan3.v_vid = 741;
	TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan1, v_entries);
	TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan2, v_entries);
	TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan3, v_entries);

	/* Build packet */
	n = edp_send(NULL, &hardware);
	if (n != 0) {
		fail("unable to build packet");
		return;
	}
	if (TAILQ_EMPTY(&pkts)) {
		fail("no packets sent");
		return;
	}
	pkt = TAILQ_FIRST(&pkts);
	ck_assert_int_eq(pkt->size, sizeof(pkt1));
	fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
	pkt = TAILQ_NEXT(pkt, next);
	if (!pkt) {
		fail("need one more packet");
		return;
	}
	ck_assert_int_eq(pkt->size, sizeof(pkt2));
	fail_unless(memcmp(pkt->data, pkt2, sizeof(pkt2)) == 0);
	fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than two packets sent");
}
END_TEST
#  endif

START_TEST(test_recv_edp)
{
	char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05,
		0x44, 0x6f, 0x01, 0x44, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb,
		0x01, 0x00, 0x01, 0x3c, 0x05, 0xdf, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x04,
		0x96, 0x05, 0x44, 0x6f, 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x04, 0x00,
		0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x99, 0x01, 0x01, 0x04, 0x6e, 0x65, 0x30, 0x35,
		0x30, 0x31, 0x73, 0x77, 0x2e, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x03, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x79, 0x0d, 0xec,
		0xff, 0xff, 0xff, 0xff, 0x80, 0xa7, 0x8b, 0x24, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x17, 0x08, 0x7e, 0xe5, 0xe2, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee,
		0x00, 0x00, 0x00, 0x02, 0x81, 0xb2, 0x19, 0xf0, 0x00, 0x00, 0x00, 0x02,
		0x80, 0xa5, 0x67, 0x20, 0xee, 0xee, 0xee, 0xee, 0x80, 0xea, 0x8c, 0xac,
		0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
		0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xa4, 0x86, 0x2c,
		0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
		0xee, 0xee, 0xee, 0xee, 0x00, 0x00, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee,
		0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
		0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
		0x99, 0x00, 0x00, 0x04 };
	/* This is:
IEEE 802.3 Ethernet
    Destination: Extreme-EDP (00:e0:2b:00:00:00)
    Source: ExtremeN_05:44:6f (00:04:96:05:44:6f)
    Length: 324
Logical-Link Control
    DSAP: SNAP (0xaa)
    IG Bit: Individual
    SSAP: SNAP (0xaa)
    CR Bit: Command
    Control field: U, func=UI (0x03)
	000. 00.. = Command: Unnumbered Information (0x00)
	.... ..11 = Frame type: Unnumbered frame (0x03)
    Organization Code: Extreme Networks (0x00e02b)
    PID: EDP (0x00bb)
Extreme Discovery Protocol
    Version: 1
    Reserved: 0
    Data length: 316
    Checksum: 0xdf05 [correct]
	[Good: True]
	[Bad : False]
    Sequence number: 783
    Machine ID type: MAC (0)
    Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f)
    Info: Slot/Port: 1/1, Version: 7.6.4.0
	Marker 0x99, length 36, type 2 = Info
	    TLV Marker: 0x99
	    TLV type: Info (2)
	    TLV length: 36
	Slot: 1
	Port: 1
	Virt chassis: 0
	Reserved: 000000000000
	Version: 7.6.4 Internal: 0
	    Version: 0x07060400
	    Version (major1): 7
	    Version (major2): 6
	    Version (sustaining): 4
	    Version (internal): 0
	Connections: FFFF0000000000000000000000000000
    Display: "ne0501sw.XXXXXX"
	Marker 0x99, length 260, type 1 = Display
	    TLV Marker: 0x99
	    TLV type: Display (1)
	    TLV length: 260
	Name: ne0501sw.XXXXXX
    Null
	Marker 0x99, length 4, type 0 = Null
	    TLV Marker: 0x99
	    TLV type: Null (0)
	    TLV length: 4
	*/

#  ifdef ENABLE_DOT1
	char pkt2[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05,
		0x44, 0x6f, 0x01, 0x48, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb,
		0x01, 0x00, 0x01, 0x40, 0x73, 0x04, 0x03, 0x10, 0x00, 0x00, 0x00, 0x04,
		0x96, 0x05, 0x44, 0x6f, 0x99, 0x05, 0x00, 0x64, 0x80, 0x00, 0x00, 0x01,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x65, 0x66, 0x61,
		0x75, 0x6c, 0x74, 0x00, 0x43, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x73,
		0x61, 0x76, 0x65, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20, 0x64,
		0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x76,
		0x20, 0x28, 0x25, 0x64, 0x29, 0x0a, 0x00, 0x00, 0x4e, 0x6f, 0x20, 0x62,
		0x72, 0x69, 0x64, 0x67, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x73, 0x75,
		0x70, 0x65, 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49, 0x6e, 0x73,
		0x74, 0x20, 0x25, 0x64, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05, 0x00, 0x64,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x4d, 0x61, 0x63, 0x56, 0x6c, 0x61, 0x6e, 0x44, 0x69, 0x73, 0x63, 0x6f,
		0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x99, 0x05, 0x00, 0x64, 0x80, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00,
		0x0a, 0x32, 0x00, 0x3f, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x42, 0x32, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 };
	/* This is:
IEEE 802.3 Ethernet
    Destination: Extreme-EDP (00:e0:2b:00:00:00)
    Source: ExtremeN_05:44:6f (00:04:96:05:44:6f)
    Length: 328
Logical-Link Control
    DSAP: SNAP (0xaa)
    IG Bit: Individual
    SSAP: SNAP (0xaa)
    CR Bit: Command
    Control field: U, func=UI (0x03)
	000. 00.. = Command: Unnumbered Information (0x00)
	.... ..11 = Frame type: Unnumbered frame (0x03)
    Organization Code: Extreme Networks (0x00e02b)
    PID: EDP (0x00bb)
Extreme Discovery Protocol
    Version: 1
    Reserved: 0
    Data length: 320
    Checksum: 0x7304 [correct]
	[Good: True]
	[Bad : False]
    Sequence number: 784
    Machine ID type: MAC (0)
    Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f)
    Vlan: ID 1, Name "Default"
	Marker 0x99, length 100, type 5 = VL
	    TLV Marker: 0x99
	    TLV type: VL (5)
	    TLV length: 100
	Flags: 0x80
	    1... .... = Flags-IP: Set
	    .000 000. = Flags-reserved: 0x00
	    .... ...0 = Flags-Unknown: Not set
	Reserved1: 00
	Vlan ID: 1
	Reserved2: 00000000
	IP addr: 0.0.0.0 (0.0.0.0)
	Name: Default
    Vlan: ID 0, Name "MacVlanDiscover"
	Marker 0x99, length 100, type 5 = VL
	    TLV Marker: 0x99
	    TLV type: VL (5)
	    TLV length: 100
	Flags: 0x00
	    0... .... = Flags-IP: Not set
	    .000 000. = Flags-reserved: 0x00
	    .... ...0 = Flags-Unknown: Not set
	Reserved1: 00
	Vlan ID: 0
	Reserved2: 00000000
	IP addr: 0.0.0.0 (0.0.0.0)
	Name: MacVlanDiscover
    Vlan: ID 50, Name "AdminB2"
	Marker 0x99, length 100, type 5 = VL
	    TLV Marker: 0x99
	    TLV type: VL (5)
	    TLV length: 100
	Flags: 0x80
	    1... .... = Flags-IP: Set
	    .000 000. = Flags-reserved: 0x00
	    .... ...0 = Flags-Unknown: Not set
	Reserved1: 00
	Vlan ID: 50
	Reserved2: 00000000
	IP addr: 10.50.0.63 (10.50.0.63)
	Name: AdminB2
    Null
	Marker 0x99, length 4, type 0 = Null
	    TLV Marker: 0x99
	    TLV type: Null (0)
	    TLV length: 4
	*/
	struct lldpd_vlan *vlan;
#  endif
	struct lldpd_chassis *nchassis = NULL;
	struct lldpd_port *nport = NULL;
	struct lldpd cfg;
	char mac1[] = { 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f };

	cfg.g_config.c_mgmt_pattern = NULL;
	fail_unless(
	    edp_decode(&cfg, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1);
	if (!nchassis || !nport) {
		fail("unable to decode packet");
		return;
	}
	ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LLADDR);
	ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN);
	fail_unless(memcmp(nchassis->c_id, mac1, ETHER_ADDR_LEN) == 0);
	ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_IFNAME);
	ck_assert_int_eq(nport->p_id_len, strlen("1/1"));
	fail_unless(memcmp(nport->p_id, "1/1", strlen("1/1")) == 0);
	ck_assert_str_eq(nport->p_descr, "Slot 1 / Port 1");
	ck_assert_str_eq(nchassis->c_name, "ne0501sw.XXXXXX");
	ck_assert_str_eq(nchassis->c_descr, "EDP enabled device, version 7.6.4.0");
	ck_assert_int_eq(nchassis->c_cap_enabled, 0);

#  ifdef ENABLE_DOT1
	/* Add this port to list of remote port for hardware port */
	TAILQ_INSERT_TAIL(&hardware.h_rports, nport, p_entries);
	nport->p_chassis = nchassis;
	nport->p_protocol = LLDPD_MODE_EDP;

	/* Recept second packet */
	nchassis = NULL;
	nport = NULL;
	fail_unless(
	    edp_decode(&cfg, pkt2, sizeof(pkt2), &hardware, &nchassis, &nport) == -1);
	nport = TAILQ_FIRST(&hardware.h_rports);
	if (!nport) {
		fail("unable to find our previous port?");
		return;
	}
	ck_assert_int_eq(TAILQ_FIRST(&nport->p_chassis->c_mgmt)->m_addr.inet.s_addr,
	    (u_int32_t)inet_addr("10.50.0.63"));
	if (TAILQ_EMPTY(&nport->p_vlans)) {
		fail("no VLAN");
		return;
	}
	vlan = TAILQ_FIRST(&nport->p_vlans);
	ck_assert_int_eq(vlan->v_vid, 1);
	ck_assert_str_eq(vlan->v_name, "Default");
	vlan = TAILQ_NEXT(vlan, v_entries);
	if (!vlan) {
		fail("no more VLAN");
		return;
	}
	ck_assert_int_eq(vlan->v_vid, 0);
	ck_assert_str_eq(vlan->v_name, "MacVlanDiscover");
	vlan = TAILQ_NEXT(vlan, v_entries);
	if (!vlan) {
		fail("no more VLAN");
		return;
	}
	ck_assert_int_eq(vlan->v_vid, 50);
	ck_assert_str_eq(vlan->v_name, "AdminB2");
	vlan = TAILQ_NEXT(vlan, v_entries);
	fail_unless(vlan == NULL);
#  endif
}
END_TEST

#endif

static Suite *
edp_suite(void)
{
	Suite *s = suite_create("EDP");

#ifdef ENABLE_EDP
	TCase *tc_send = tcase_create("Send EDP packets");
	TCase *tc_receive = tcase_create("Receive EDP packets");

	tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown);
	tcase_add_test(tc_send, test_send_basic);
#  ifdef ENABLE_DOT1
	tcase_add_test(tc_send, test_send_vlans);
#  endif
	suite_add_tcase(s, tc_send);

	tcase_add_test(tc_receive, test_recv_edp);
	suite_add_tcase(s, tc_receive);
#endif

	return s;
}

int
main()
{
	int number_failed;
	Suite *s = edp_suite();
	SRunner *sr = srunner_create(s);
	srunner_set_fork_status(sr, CK_NOFORK); /* Can't fork because
						   we need to write
						   files */
	srunner_run_all(sr, CK_ENV);
	number_failed = srunner_ntests_failed(sr);
	srunner_free(sr);
	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}