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