]> git.ipfire.org Git - thirdparty/lldpd.git/blame - tests/check_edp.c
build: fix "make dist"
[thirdparty/lldpd.git] / tests / check_edp.c
CommitLineData
d02bb461
VB
1#define _GNU_SOURCE 1
2#include <stdlib.h>
3#include <sys/socket.h>
4#include <arpa/inet.h>
5#include <netinet/in.h>
6#include <check.h>
d02bb461
VB
7#include "common.h"
8
9char filenameprefix[] = "edp_send";
10
11#ifdef ENABLE_EDP
12
13START_TEST (test_send_basic)
14{
15 int n;
16 /* Packet we should build:
17Extreme Discovery Protocol
18 Version: 1
19 Reserved: 0
20 Data length: 74
21 Checksum: 0xde22 [correct]
22 [Good: True]
23 [Bad : False]
24 Sequence number: 0
25 Machine ID type: MAC (0)
26 Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
27 Display: "First chassis"
28 Marker 0x99, length 18, type 1 = Display
29 TLV Marker: 0x99
30 TLV type: Display (1)
31 TLV length: 18
32 Name: First chassis
33 Info: Slot/Port: 1/4, Version: 7.6.4.99
34 Marker 0x99, length 36, type 2 = Info
35 TLV Marker: 0x99
36 TLV type: Info (2)
37 TLV length: 36
38 Slot: 1
39 Port: 4
40 Virt chassis: 0
41 Reserved: 000000000000
42 Version: 7.6.4 Internal: 99
43 Version: 0x07060463
44 Version (major1): 7
45 Version (major2): 6
46 Version (sustaining): 4
47 Version (internal): 99
48 Connections: FFFFFFFF000000000000000000000000
49 Null
50 Marker 0x99, length 4, type 0 = Null
51 TLV Marker: 0x99
52 TLV type: Null (0)
53 TLV length: 4
54 */
55 char pkt1[] = {
56 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10,
57 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa,
58 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
59 0x00, 0x4a, 0xde, 0x22, 0x00, 0x00, 0x00, 0x00,
60 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01,
61 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20,
62 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00,
63 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03,
64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 };
68 struct packet *pkt;
69
70 /* Populate port and chassis */
71 hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
72 hardware.h_lport.p_id = "Not used";
73 hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
74 hardware.h_lport.p_descr = "Not used";
75 strcpy(hardware.h_ifname, "eth3");
76 hardware.h_ifindex = 4;
77 chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
78 chassis.c_id = macaddress;
79 chassis.c_id_len = ETH_ALEN;
80 chassis.c_name = "First chassis";
81 /* Build packet */
82 n = edp_send(NULL, &hardware);
83 if (n != 0) {
84 fail("unable to build packet");
85 return;
86 }
87 if (TAILQ_EMPTY(&pkts)) {
88 fail("no packets sent");
89 return;
90 }
91 pkt = TAILQ_FIRST(&pkts);
92 ck_assert_int_eq(pkt->size, sizeof(pkt1));
93 fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
94 fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent");
95}
96END_TEST
97
98#ifdef ENABLE_DOT1
99START_TEST (test_send_vlans)
100{
101 int n;
102 /* Packets we should build:
103Extreme Discovery Protocol
104 Version: 1
105 Reserved: 0
106 Data length: 74
107 Checksum: 0xde20 [correct]
108 [Good: True]
109 [Bad : False]
110 Sequence number: 2
111 Machine ID type: MAC (0)
112 Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
113 Display: "First chassis"
114 Marker 0x99, length 18, type 1 = Display
115 TLV Marker: 0x99
116 TLV type: Display (1)
117 TLV length: 18
118 Name: First chassis
119 Info: Slot/Port: 1/4, Version: 7.6.4.99
120 Marker 0x99, length 36, type 2 = Info
121 TLV Marker: 0x99
122 TLV type: Info (2)
123 TLV length: 36
124 Slot: 1
125 Port: 4
126 Virt chassis: 0
127 Reserved: 000000000000
128 Version: 7.6.4 Internal: 99
129 Version: 0x07060463
130 Version (major1): 7
131 Version (major2): 6
132 Version (sustaining): 4
133 Version (internal): 99
134 Connections: FFFFFFFF000000000000000000000000
135 Null
136 Marker 0x99, length 4, type 0 = Null
137 TLV Marker: 0x99
138 TLV type: Null (0)
139 TLV length: 4
140
141Extreme Discovery Protocol
142 Version: 1
143 Reserved: 0
144 Data length: 102
145 Checksum: 0x28c4 [correct]
146 [Good: True]
147 [Bad : False]
148 Sequence number: 3
149 Machine ID type: MAC (0)
150 Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad)
151 Vlan: ID 157, Name "First VLAN"
152 Marker 0x99, length 27, type 5 = VL
153 TLV Marker: 0x99
154 TLV type: VL (5)
155 TLV length: 27
156 Flags: 0x00
157 0... .... = Flags-IP: Not set
158 .000 000. = Flags-reserved: 0x00
159 .... ...0 = Flags-Unknown: Not set
160 Reserved1: 00
161 Vlan ID: 157
162 Reserved2: 00000000
163 IP addr: 0.0.0.0 (0.0.0.0)
164 Name: First VLAN
165 Vlan: ID 1247, Name "Second VLAN"
166 Marker 0x99, length 28, type 5 = VL
167 TLV Marker: 0x99
168 TLV type: VL (5)
169 TLV length: 28
170 Flags: 0x00
171 0... .... = Flags-IP: Not set
172 .000 000. = Flags-reserved: 0x00
173 .... ...0 = Flags-Unknown: Not set
174 Reserved1: 00
175 Vlan ID: 1247
176 Reserved2: 00000000
177 IP addr: 0.0.0.0 (0.0.0.0)
178 Name: Second VLAN
179 Vlan: ID 741, Name "Third VLAN"
180 Marker 0x99, length 27, type 5 = VL
181 TLV Marker: 0x99
182 TLV type: VL (5)
183 TLV length: 27
184 Flags: 0x00
185 0... .... = Flags-IP: Not set
186 .000 000. = Flags-reserved: 0x00
187 .... ...0 = Flags-Unknown: Not set
188 Reserved1: 00
189 Vlan ID: 741
190 Reserved2: 00000000
191 IP addr: 0.0.0.0 (0.0.0.0)
192 Name: Third VLAN
193 Null
194 Marker 0x99, length 4, type 0 = Null
195 TLV Marker: 0x99
196 TLV type: Null (0)
197 TLV length: 4
198 */
199 char pkt1[] = {
200 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10,
201 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa,
202 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
203 0x00, 0x4a, 0xde, 0x20, 0x00, 0x02, 0x00, 0x00,
204 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01,
205 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20,
206 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00,
207 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03,
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff,
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 };
212
213 char pkt2[] = {
214 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10,
215 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6e, 0xaa, 0xaa,
216 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
217 0x00, 0x66, 0x28, 0xc4, 0x00, 0x03, 0x00, 0x00,
218 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x05,
219 0x00, 0x1b, 0x00, 0x00, 0x00, 0x9d, 0x00, 0x00,
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69,
221 0x72, 0x73, 0x74, 0x20, 0x56, 0x4c, 0x41, 0x4e,
222 0x00, 0x99, 0x05, 0x00, 0x1c, 0x00, 0x00, 0x04,
223 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 0x00, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20,
225 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00,
226 0x1b, 0x00, 0x00, 0x02, 0xe5, 0x00, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69,
228 0x72, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00,
229 0x99, 0x00, 0x00, 0x04 };
230
231 struct packet *pkt;
232 struct lldpd_vlan vlan1, vlan2, vlan3;
233
234 /* Populate port and chassis */
235 hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
236 hardware.h_lport.p_id = "Not used";
237 hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
238 hardware.h_lport.p_descr = "Not used";
239 strcpy(hardware.h_ifname, "eth3");
240 hardware.h_ifindex = 4;
241 chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
242 chassis.c_id = macaddress;
243 chassis.c_id_len = ETH_ALEN;
244 chassis.c_name = "First chassis";
245 vlan1.v_name = "First VLAN"; vlan1.v_vid = 157;
246 vlan2.v_name = "Second VLAN"; vlan2.v_vid = 1247;
247 vlan3.v_name = "Third VLAN"; vlan3.v_vid = 741;
248 TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan1, v_entries);
249 TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan2, v_entries);
250 TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan3, v_entries);
251
252 /* Build packet */
253 n = edp_send(NULL, &hardware);
254 if (n != 0) {
255 fail("unable to build packet");
256 return;
257 }
258 if (TAILQ_EMPTY(&pkts)) {
259 fail("no packets sent");
260 return;
261 }
262 pkt = TAILQ_FIRST(&pkts);
263 ck_assert_int_eq(pkt->size, sizeof(pkt1));
264 fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0);
265 pkt = TAILQ_NEXT(pkt, next);
266 if (!pkt) {
267 fail("need one more packet");
268 return;
269 }
270 ck_assert_int_eq(pkt->size, sizeof(pkt2));
271 fail_unless(memcmp(pkt->data, pkt2, sizeof(pkt2)) == 0);
272 fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than two packets sent");
273}
274END_TEST
275#endif
276
277START_TEST (test_recv_edp)
278{
279 char pkt1[] = {
280 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04,
281 0x96, 0x05, 0x44, 0x6f, 0x01, 0x44, 0xaa, 0xaa,
282 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
283 0x01, 0x3c, 0x05, 0xdf, 0x03, 0x0f, 0x00, 0x00,
284 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x02,
285 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06,
287 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289 0x00, 0x00, 0x99, 0x01, 0x01, 0x04, 0x6e, 0x65,
290 0x30, 0x35, 0x30, 0x31, 0x73, 0x77, 0x2e, 0x58,
291 0x58, 0x58, 0x58, 0x58, 0x58, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x03, 0x7b, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x80, 0x79, 0x0d, 0xec, 0xff, 0xff,
295 0xff, 0xff, 0x80, 0xa7, 0x8b, 0x24, 0x00, 0x00,
296 0x00, 0x00, 0x00, 0x17, 0x08, 0x7e, 0xe5, 0xe2,
297 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00,
298 0x00, 0x02, 0x81, 0xb2, 0x19, 0xf0, 0x00, 0x00,
299 0x00, 0x02, 0x80, 0xa5, 0x67, 0x20, 0xee, 0xee,
300 0xee, 0xee, 0x80, 0xea, 0x8c, 0xac, 0x00, 0x00,
301 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
302 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
309 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x80, 0xa4, 0x86, 0x2c, 0xee, 0xee,
316 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
317 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00,
318 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0xe0,
319 0x2b, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
320 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
321 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x99, 0x00,
322 0x00, 0x04 };
323 /* This is:
324IEEE 802.3 Ethernet
325 Destination: Extreme-EDP (00:e0:2b:00:00:00)
326 Source: ExtremeN_05:44:6f (00:04:96:05:44:6f)
327 Length: 324
328Logical-Link Control
329 DSAP: SNAP (0xaa)
330 IG Bit: Individual
331 SSAP: SNAP (0xaa)
332 CR Bit: Command
333 Control field: U, func=UI (0x03)
334 000. 00.. = Command: Unnumbered Information (0x00)
335 .... ..11 = Frame type: Unnumbered frame (0x03)
336 Organization Code: Extreme Networks (0x00e02b)
337 PID: EDP (0x00bb)
338Extreme Discovery Protocol
339 Version: 1
340 Reserved: 0
341 Data length: 316
342 Checksum: 0xdf05 [correct]
343 [Good: True]
344 [Bad : False]
345 Sequence number: 783
346 Machine ID type: MAC (0)
347 Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f)
348 Info: Slot/Port: 1/1, Version: 7.6.4.0
349 Marker 0x99, length 36, type 2 = Info
350 TLV Marker: 0x99
351 TLV type: Info (2)
352 TLV length: 36
353 Slot: 1
354 Port: 1
355 Virt chassis: 0
356 Reserved: 000000000000
357 Version: 7.6.4 Internal: 0
358 Version: 0x07060400
359 Version (major1): 7
360 Version (major2): 6
361 Version (sustaining): 4
362 Version (internal): 0
363 Connections: FFFF0000000000000000000000000000
364 Display: "ne0501sw.XXXXXX"
365 Marker 0x99, length 260, type 1 = Display
366 TLV Marker: 0x99
367 TLV type: Display (1)
368 TLV length: 260
369 Name: ne0501sw.XXXXXX
370 Null
371 Marker 0x99, length 4, type 0 = Null
372 TLV Marker: 0x99
373 TLV type: Null (0)
374 TLV length: 4
375 */
376
377#ifdef ENABLE_DOT1
378 char pkt2[] = {
379 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04,
380 0x96, 0x05, 0x44, 0x6f, 0x01, 0x48, 0xaa, 0xaa,
381 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00,
382 0x01, 0x40, 0x73, 0x04, 0x03, 0x10, 0x00, 0x00,
383 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x05,
384 0x00, 0x64, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00,
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x65,
386 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, 0x43, 0x61,
387 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x61, 0x76,
388 0x65, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65,
389 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
390 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x76, 0x20, 0x28,
391 0x25, 0x64, 0x29, 0x0a, 0x00, 0x00, 0x4e, 0x6f,
392 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20,
393 0x66, 0x6f, 0x72, 0x20, 0x73, 0x75, 0x70, 0x65,
394 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49,
395 0x6e, 0x73, 0x74, 0x20, 0x25, 0x64, 0x00, 0x00,
396 0x00, 0x00, 0x99, 0x05, 0x00, 0x64, 0x00, 0x00,
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
398 0x00, 0x00, 0x4d, 0x61, 0x63, 0x56, 0x6c, 0x61,
399 0x6e, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65,
400 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
406 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05,
409 0x00, 0x64, 0x80, 0x00, 0x00, 0x32, 0x00, 0x00,
410 0x00, 0x00, 0x0a, 0x32, 0x00, 0x3f, 0x41, 0x64,
411 0x6d, 0x69, 0x6e, 0x42, 0x32, 0x00, 0x00, 0x00,
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
413 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
414 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416 0x00, 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, 0x99, 0x00, 0x00, 0x04 };
422 /* This is:
423IEEE 802.3 Ethernet
424 Destination: Extreme-EDP (00:e0:2b:00:00:00)
425 Source: ExtremeN_05:44:6f (00:04:96:05:44:6f)
426 Length: 328
427Logical-Link Control
428 DSAP: SNAP (0xaa)
429 IG Bit: Individual
430 SSAP: SNAP (0xaa)
431 CR Bit: Command
432 Control field: U, func=UI (0x03)
433 000. 00.. = Command: Unnumbered Information (0x00)
434 .... ..11 = Frame type: Unnumbered frame (0x03)
435 Organization Code: Extreme Networks (0x00e02b)
436 PID: EDP (0x00bb)
437Extreme Discovery Protocol
438 Version: 1
439 Reserved: 0
440 Data length: 320
441 Checksum: 0x7304 [correct]
442 [Good: True]
443 [Bad : False]
444 Sequence number: 784
445 Machine ID type: MAC (0)
446 Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f)
447 Vlan: ID 1, Name "Default"
448 Marker 0x99, length 100, type 5 = VL
449 TLV Marker: 0x99
450 TLV type: VL (5)
451 TLV length: 100
452 Flags: 0x80
453 1... .... = Flags-IP: Set
454 .000 000. = Flags-reserved: 0x00
455 .... ...0 = Flags-Unknown: Not set
456 Reserved1: 00
457 Vlan ID: 1
458 Reserved2: 00000000
459 IP addr: 0.0.0.0 (0.0.0.0)
460 Name: Default
461 Vlan: ID 0, Name "MacVlanDiscover"
462 Marker 0x99, length 100, type 5 = VL
463 TLV Marker: 0x99
464 TLV type: VL (5)
465 TLV length: 100
466 Flags: 0x00
467 0... .... = Flags-IP: Not set
468 .000 000. = Flags-reserved: 0x00
469 .... ...0 = Flags-Unknown: Not set
470 Reserved1: 00
471 Vlan ID: 0
472 Reserved2: 00000000
473 IP addr: 0.0.0.0 (0.0.0.0)
474 Name: MacVlanDiscover
475 Vlan: ID 50, Name "AdminB2"
476 Marker 0x99, length 100, type 5 = VL
477 TLV Marker: 0x99
478 TLV type: VL (5)
479 TLV length: 100
480 Flags: 0x80
481 1... .... = Flags-IP: Set
482 .000 000. = Flags-reserved: 0x00
483 .... ...0 = Flags-Unknown: Not set
484 Reserved1: 00
485 Vlan ID: 50
486 Reserved2: 00000000
487 IP addr: 10.50.0.63 (10.50.0.63)
488 Name: AdminB2
489 Null
490 Marker 0x99, length 4, type 0 = Null
491 TLV Marker: 0x99
492 TLV type: Null (0)
493 TLV length: 4
494 */
495 struct lldpd_vlan *vlan;
496#endif
497 struct lldpd_chassis *nchassis = NULL;
498 struct lldpd_port *nport = NULL;
499 struct lldpd cfg;
500 char mac1[] = { 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f };
501
502 cfg.g_mgmt_pattern = NULL;
503 fail_unless(edp_decode(&cfg, pkt1, sizeof(pkt1), &hardware,
504 &nchassis, &nport) != -1);
505 if (!nchassis || !nport) {
506 fail("unable to decode packet");
507 return;
508 }
509 ck_assert_int_eq(nchassis->c_id_subtype,
510 LLDP_CHASSISID_SUBTYPE_LLADDR);
511 ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
512 fail_unless(memcmp(nchassis->c_id, mac1, ETH_ALEN) == 0);
513 ck_assert_int_eq(nport->p_id_subtype,
514 LLDP_PORTID_SUBTYPE_IFNAME);
515 ck_assert_int_eq(nport->p_id_len, strlen("1/1"));
516 fail_unless(memcmp(nport->p_id,
517 "1/1", strlen("1/1")) == 0);
518 ck_assert_str_eq(nport->p_descr, "Slot 1 / Port 1");
519 ck_assert_str_eq(nchassis->c_name, "ne0501sw.XXXXXX");
520 ck_assert_str_eq(nchassis->c_descr, "EDP enabled device, version 7.6.4.0");
521 ck_assert_int_eq(nchassis->c_cap_enabled, 0);
522
523#ifdef ENABLE_DOT1
524 /* Add this port to list of remote port for hardware port */
525 TAILQ_INSERT_TAIL(&hardware.h_rports, nport, p_entries);
526 nport->p_chassis = nchassis;
527 nport->p_protocol = LLDPD_MODE_EDP;
528
529 /* Recept second packet */
530 nchassis = NULL; nport = NULL;
531 fail_unless(edp_decode(&cfg, pkt2, sizeof(pkt2), &hardware,
532 &nchassis, &nport) == -1);
533 nport = TAILQ_FIRST(&hardware.h_rports);
534 if (!nport) {
535 fail("unable to find our previous port?");
536 return;
537 }
e6b36c87 538 ck_assert_int_eq(TAILQ_FIRST(&nport->p_chassis->c_mgmt)->m_addr.inet.s_addr,
d02bb461
VB
539 (u_int32_t)inet_addr("10.50.0.63"));
540 if (TAILQ_EMPTY(&nport->p_vlans)) {
541 fail("no VLAN");
542 return;
543 }
544 vlan = TAILQ_FIRST(&nport->p_vlans);
545 ck_assert_int_eq(vlan->v_vid, 1);
546 ck_assert_str_eq(vlan->v_name, "Default");
547 vlan = TAILQ_NEXT(vlan, v_entries);
548 if (!vlan) {
549 fail("no more VLAN");
550 return;
551 }
552 ck_assert_int_eq(vlan->v_vid, 0);
553 ck_assert_str_eq(vlan->v_name, "MacVlanDiscover");
554 vlan = TAILQ_NEXT(vlan, v_entries);
555 if (!vlan) {
556 fail("no more VLAN");
557 return;
558 }
559 ck_assert_int_eq(vlan->v_vid, 50);
560 ck_assert_str_eq(vlan->v_name, "AdminB2");
561 vlan = TAILQ_NEXT(vlan, v_entries);
562 fail_unless(vlan == NULL);
563#endif
564}
565END_TEST
566
567#endif
568
569Suite *
570edp_suite(void)
571{
572 Suite *s = suite_create("EDP");
573
574#ifdef ENABLE_EDP
575 TCase *tc_send = tcase_create("Send EDP packets");
5fd6695c
VB
576 TCase *tc_receive = tcase_create("Receive EDP packets");
577
d02bb461
VB
578 tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown);
579 tcase_add_test(tc_send, test_send_basic);
580#ifdef ENABLE_DOT1
581 tcase_add_test(tc_send, test_send_vlans);
582#endif
583 suite_add_tcase(s, tc_send);
584
d02bb461
VB
585 tcase_add_test(tc_receive, test_recv_edp);
586 suite_add_tcase(s, tc_receive);
587#endif
588
589 return s;
590}
591
592int
593main()
594{
595 int number_failed;
596 Suite *s = edp_suite ();
597 SRunner *sr = srunner_create (s);
598 srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because
599 we need to write
600 files */
601 srunner_run_all (sr, CK_ENV);
602 number_failed = srunner_ntests_failed (sr);
603 srunner_free (sr);
604 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
605}