]>
Commit | Line | Data |
---|---|---|
eab6aa62 VB |
1 | /* -*- mode: c; c-file-style: "openbsd" -*- */ |
2 | /* | |
3 | * Copyright (c) 2015 Vincent Bernat <bernat@luffy.cx> | |
4 | * | |
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. | |
8 | * | |
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. | |
16 | */ | |
17 | ||
d02bb461 VB |
18 | #include <stdlib.h> |
19 | #include <sys/socket.h> | |
20 | #include <arpa/inet.h> | |
21 | #include <netinet/in.h> | |
22 | #include <check.h> | |
d02bb461 VB |
23 | #include "common.h" |
24 | ||
25 | char filenameprefix[] = "edp_send"; | |
26 | ||
27 | #ifdef ENABLE_EDP | |
28 | ||
29 | START_TEST (test_send_basic) | |
30 | { | |
31 | int n; | |
32 | /* Packet we should build: | |
33 | Extreme Discovery Protocol | |
34 | Version: 1 | |
35 | Reserved: 0 | |
36 | Data length: 74 | |
37 | Checksum: 0xde22 [correct] | |
38 | [Good: True] | |
39 | [Bad : False] | |
40 | Sequence number: 0 | |
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 | |
45 | TLV Marker: 0x99 | |
46 | TLV type: Display (1) | |
47 | TLV length: 18 | |
48 | Name: First chassis | |
49 | Info: Slot/Port: 1/4, Version: 7.6.4.99 | |
50 | Marker 0x99, length 36, type 2 = Info | |
51 | TLV Marker: 0x99 | |
52 | TLV type: Info (2) | |
53 | TLV length: 36 | |
54 | Slot: 1 | |
55 | Port: 4 | |
56 | Virt chassis: 0 | |
57 | Reserved: 000000000000 | |
58 | Version: 7.6.4 Internal: 99 | |
59 | Version: 0x07060463 | |
60 | Version (major1): 7 | |
61 | Version (major2): 6 | |
62 | Version (sustaining): 4 | |
63 | Version (internal): 99 | |
64 | Connections: FFFFFFFF000000000000000000000000 | |
65 | Null | |
66 | Marker 0x99, length 4, type 0 = Null | |
67 | TLV Marker: 0x99 | |
68 | TLV type: Null (0) | |
69 | TLV length: 4 | |
70 | */ | |
71 | char pkt1[] = { | |
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 }; | |
84 | struct packet *pkt; | |
85 | ||
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"; | |
608b5669 | 91 | strlcpy(hardware.h_ifname, "eth3", sizeof(hardware.h_ifname)); |
d02bb461 VB |
92 | hardware.h_ifindex = 4; |
93 | chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; | |
94 | chassis.c_id = macaddress; | |
4e5f34c5 | 95 | chassis.c_id_len = ETHER_ADDR_LEN; |
d02bb461 VB |
96 | chassis.c_name = "First chassis"; |
97 | /* Build packet */ | |
98 | n = edp_send(NULL, &hardware); | |
99 | if (n != 0) { | |
100 | fail("unable to build packet"); | |
101 | return; | |
102 | } | |
103 | if (TAILQ_EMPTY(&pkts)) { | |
104 | fail("no packets sent"); | |
105 | return; | |
106 | } | |
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"); | |
111 | } | |
112 | END_TEST | |
113 | ||
114 | #ifdef ENABLE_DOT1 | |
115 | START_TEST (test_send_vlans) | |
116 | { | |
117 | int n; | |
118 | /* Packets we should build: | |
119 | Extreme Discovery Protocol | |
120 | Version: 1 | |
121 | Reserved: 0 | |
122 | Data length: 74 | |
123 | Checksum: 0xde20 [correct] | |
124 | [Good: True] | |
125 | [Bad : False] | |
126 | Sequence number: 2 | |
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 | |
131 | TLV Marker: 0x99 | |
132 | TLV type: Display (1) | |
133 | TLV length: 18 | |
134 | Name: First chassis | |
135 | Info: Slot/Port: 1/4, Version: 7.6.4.99 | |
136 | Marker 0x99, length 36, type 2 = Info | |
137 | TLV Marker: 0x99 | |
138 | TLV type: Info (2) | |
139 | TLV length: 36 | |
140 | Slot: 1 | |
141 | Port: 4 | |
142 | Virt chassis: 0 | |
143 | Reserved: 000000000000 | |
144 | Version: 7.6.4 Internal: 99 | |
145 | Version: 0x07060463 | |
146 | Version (major1): 7 | |
147 | Version (major2): 6 | |
148 | Version (sustaining): 4 | |
149 | Version (internal): 99 | |
150 | Connections: FFFFFFFF000000000000000000000000 | |
151 | Null | |
152 | Marker 0x99, length 4, type 0 = Null | |
153 | TLV Marker: 0x99 | |
154 | TLV type: Null (0) | |
155 | TLV length: 4 | |
156 | ||
157 | Extreme Discovery Protocol | |
158 | Version: 1 | |
159 | Reserved: 0 | |
160 | Data length: 102 | |
161 | Checksum: 0x28c4 [correct] | |
162 | [Good: True] | |
163 | [Bad : False] | |
164 | Sequence number: 3 | |
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 | |
169 | TLV Marker: 0x99 | |
170 | TLV type: VL (5) | |
171 | TLV length: 27 | |
172 | Flags: 0x00 | |
173 | 0... .... = Flags-IP: Not set | |
174 | .000 000. = Flags-reserved: 0x00 | |
175 | .... ...0 = Flags-Unknown: Not set | |
176 | Reserved1: 00 | |
177 | Vlan ID: 157 | |
178 | Reserved2: 00000000 | |
179 | IP addr: 0.0.0.0 (0.0.0.0) | |
180 | Name: First VLAN | |
181 | Vlan: ID 1247, Name "Second VLAN" | |
182 | Marker 0x99, length 28, type 5 = VL | |
183 | TLV Marker: 0x99 | |
184 | TLV type: VL (5) | |
185 | TLV length: 28 | |
186 | Flags: 0x00 | |
187 | 0... .... = Flags-IP: Not set | |
188 | .000 000. = Flags-reserved: 0x00 | |
189 | .... ...0 = Flags-Unknown: Not set | |
190 | Reserved1: 00 | |
191 | Vlan ID: 1247 | |
192 | Reserved2: 00000000 | |
193 | IP addr: 0.0.0.0 (0.0.0.0) | |
194 | Name: Second VLAN | |
195 | Vlan: ID 741, Name "Third VLAN" | |
196 | Marker 0x99, length 27, type 5 = VL | |
197 | TLV Marker: 0x99 | |
198 | TLV type: VL (5) | |
199 | TLV length: 27 | |
200 | Flags: 0x00 | |
201 | 0... .... = Flags-IP: Not set | |
202 | .000 000. = Flags-reserved: 0x00 | |
203 | .... ...0 = Flags-Unknown: Not set | |
204 | Reserved1: 00 | |
205 | Vlan ID: 741 | |
206 | Reserved2: 00000000 | |
207 | IP addr: 0.0.0.0 (0.0.0.0) | |
208 | Name: Third VLAN | |
209 | Null | |
210 | Marker 0x99, length 4, type 0 = Null | |
211 | TLV Marker: 0x99 | |
212 | TLV type: Null (0) | |
213 | TLV length: 4 | |
214 | */ | |
215 | char pkt1[] = { | |
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 }; | |
228 | ||
229 | char pkt2[] = { | |
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 }; | |
246 | ||
247 | struct packet *pkt; | |
248 | struct lldpd_vlan vlan1, vlan2, vlan3; | |
249 | ||
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"; | |
608b5669 | 255 | strlcpy(hardware.h_ifname, "eth3", sizeof(hardware.h_ifname)); |
d02bb461 VB |
256 | hardware.h_ifindex = 4; |
257 | chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; | |
258 | chassis.c_id = macaddress; | |
4e5f34c5 | 259 | chassis.c_id_len = ETHER_ADDR_LEN; |
d02bb461 VB |
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); | |
267 | ||
268 | /* Build packet */ | |
269 | n = edp_send(NULL, &hardware); | |
270 | if (n != 0) { | |
271 | fail("unable to build packet"); | |
272 | return; | |
273 | } | |
274 | if (TAILQ_EMPTY(&pkts)) { | |
275 | fail("no packets sent"); | |
276 | return; | |
277 | } | |
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); | |
282 | if (!pkt) { | |
283 | fail("need one more packet"); | |
284 | return; | |
285 | } | |
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"); | |
289 | } | |
290 | END_TEST | |
291 | #endif | |
292 | ||
293 | START_TEST (test_recv_edp) | |
294 | { | |
295 | char pkt1[] = { | |
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, | |
338 | 0x00, 0x04 }; | |
339 | /* This is: | |
340 | IEEE 802.3 Ethernet | |
341 | Destination: Extreme-EDP (00:e0:2b:00:00:00) | |
342 | Source: ExtremeN_05:44:6f (00:04:96:05:44:6f) | |
343 | Length: 324 | |
344 | Logical-Link Control | |
345 | DSAP: SNAP (0xaa) | |
346 | IG Bit: Individual | |
347 | SSAP: SNAP (0xaa) | |
348 | CR Bit: Command | |
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) | |
353 | PID: EDP (0x00bb) | |
354 | Extreme Discovery Protocol | |
355 | Version: 1 | |
356 | Reserved: 0 | |
357 | Data length: 316 | |
358 | Checksum: 0xdf05 [correct] | |
359 | [Good: True] | |
360 | [Bad : False] | |
361 | Sequence number: 783 | |
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 | |
366 | TLV Marker: 0x99 | |
367 | TLV type: Info (2) | |
368 | TLV length: 36 | |
369 | Slot: 1 | |
370 | Port: 1 | |
371 | Virt chassis: 0 | |
372 | Reserved: 000000000000 | |
373 | Version: 7.6.4 Internal: 0 | |
374 | Version: 0x07060400 | |
375 | Version (major1): 7 | |
376 | Version (major2): 6 | |
377 | Version (sustaining): 4 | |
378 | Version (internal): 0 | |
379 | Connections: FFFF0000000000000000000000000000 | |
380 | Display: "ne0501sw.XXXXXX" | |
381 | Marker 0x99, length 260, type 1 = Display | |
382 | TLV Marker: 0x99 | |
383 | TLV type: Display (1) | |
384 | TLV length: 260 | |
385 | Name: ne0501sw.XXXXXX | |
386 | Null | |
387 | Marker 0x99, length 4, type 0 = Null | |
388 | TLV Marker: 0x99 | |
389 | TLV type: Null (0) | |
390 | TLV length: 4 | |
391 | */ | |
392 | ||
393 | #ifdef ENABLE_DOT1 | |
394 | char pkt2[] = { | |
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 }; | |
438 | /* This is: | |
439 | IEEE 802.3 Ethernet | |
440 | Destination: Extreme-EDP (00:e0:2b:00:00:00) | |
441 | Source: ExtremeN_05:44:6f (00:04:96:05:44:6f) | |
442 | Length: 328 | |
443 | Logical-Link Control | |
444 | DSAP: SNAP (0xaa) | |
445 | IG Bit: Individual | |
446 | SSAP: SNAP (0xaa) | |
447 | CR Bit: Command | |
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) | |
452 | PID: EDP (0x00bb) | |
453 | Extreme Discovery Protocol | |
454 | Version: 1 | |
455 | Reserved: 0 | |
456 | Data length: 320 | |
457 | Checksum: 0x7304 [correct] | |
458 | [Good: True] | |
459 | [Bad : False] | |
460 | Sequence number: 784 | |
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 | |
465 | TLV Marker: 0x99 | |
466 | TLV type: VL (5) | |
467 | TLV length: 100 | |
468 | Flags: 0x80 | |
469 | 1... .... = Flags-IP: Set | |
470 | .000 000. = Flags-reserved: 0x00 | |
471 | .... ...0 = Flags-Unknown: Not set | |
472 | Reserved1: 00 | |
473 | Vlan ID: 1 | |
474 | Reserved2: 00000000 | |
475 | IP addr: 0.0.0.0 (0.0.0.0) | |
476 | Name: Default | |
477 | Vlan: ID 0, Name "MacVlanDiscover" | |
478 | Marker 0x99, length 100, type 5 = VL | |
479 | TLV Marker: 0x99 | |
480 | TLV type: VL (5) | |
481 | TLV length: 100 | |
482 | Flags: 0x00 | |
483 | 0... .... = Flags-IP: Not set | |
484 | .000 000. = Flags-reserved: 0x00 | |
485 | .... ...0 = Flags-Unknown: Not set | |
486 | Reserved1: 00 | |
487 | Vlan ID: 0 | |
488 | Reserved2: 00000000 | |
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 | |
493 | TLV Marker: 0x99 | |
494 | TLV type: VL (5) | |
495 | TLV length: 100 | |
496 | Flags: 0x80 | |
497 | 1... .... = Flags-IP: Set | |
498 | .000 000. = Flags-reserved: 0x00 | |
499 | .... ...0 = Flags-Unknown: Not set | |
500 | Reserved1: 00 | |
501 | Vlan ID: 50 | |
502 | Reserved2: 00000000 | |
503 | IP addr: 10.50.0.63 (10.50.0.63) | |
504 | Name: AdminB2 | |
505 | Null | |
506 | Marker 0x99, length 4, type 0 = Null | |
507 | TLV Marker: 0x99 | |
508 | TLV type: Null (0) | |
509 | TLV length: 4 | |
510 | */ | |
511 | struct lldpd_vlan *vlan; | |
512 | #endif | |
513 | struct lldpd_chassis *nchassis = NULL; | |
514 | struct lldpd_port *nport = NULL; | |
515 | struct lldpd cfg; | |
516 | char mac1[] = { 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f }; | |
517 | ||
d79c3de4 | 518 | cfg.g_config.c_mgmt_pattern = NULL; |
d02bb461 VB |
519 | fail_unless(edp_decode(&cfg, pkt1, sizeof(pkt1), &hardware, |
520 | &nchassis, &nport) != -1); | |
521 | if (!nchassis || !nport) { | |
522 | fail("unable to decode packet"); | |
523 | return; | |
524 | } | |
525 | ck_assert_int_eq(nchassis->c_id_subtype, | |
526 | LLDP_CHASSISID_SUBTYPE_LLADDR); | |
4e5f34c5 VB |
527 | ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN); |
528 | fail_unless(memcmp(nchassis->c_id, mac1, ETHER_ADDR_LEN) == 0); | |
d02bb461 VB |
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); | |
538 | ||
539 | #ifdef ENABLE_DOT1 | |
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; | |
544 | ||
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); | |
550 | if (!nport) { | |
551 | fail("unable to find our previous port?"); | |
552 | return; | |
553 | } | |
e6b36c87 | 554 | ck_assert_int_eq(TAILQ_FIRST(&nport->p_chassis->c_mgmt)->m_addr.inet.s_addr, |
d02bb461 VB |
555 | (u_int32_t)inet_addr("10.50.0.63")); |
556 | if (TAILQ_EMPTY(&nport->p_vlans)) { | |
557 | fail("no VLAN"); | |
558 | return; | |
559 | } | |
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); | |
564 | if (!vlan) { | |
565 | fail("no more VLAN"); | |
566 | return; | |
567 | } | |
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); | |
571 | if (!vlan) { | |
572 | fail("no more VLAN"); | |
573 | return; | |
574 | } | |
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); | |
579 | #endif | |
580 | } | |
581 | END_TEST | |
582 | ||
583 | #endif | |
584 | ||
585 | Suite * | |
586 | edp_suite(void) | |
587 | { | |
588 | Suite *s = suite_create("EDP"); | |
589 | ||
590 | #ifdef ENABLE_EDP | |
591 | TCase *tc_send = tcase_create("Send EDP packets"); | |
5fd6695c VB |
592 | TCase *tc_receive = tcase_create("Receive EDP packets"); |
593 | ||
d02bb461 VB |
594 | tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown); |
595 | tcase_add_test(tc_send, test_send_basic); | |
596 | #ifdef ENABLE_DOT1 | |
597 | tcase_add_test(tc_send, test_send_vlans); | |
598 | #endif | |
599 | suite_add_tcase(s, tc_send); | |
600 | ||
d02bb461 VB |
601 | tcase_add_test(tc_receive, test_recv_edp); |
602 | suite_add_tcase(s, tc_receive); | |
603 | #endif | |
604 | ||
605 | return s; | |
606 | } | |
607 | ||
608 | int | |
609 | main() | |
610 | { | |
611 | int number_failed; | |
612 | Suite *s = edp_suite (); | |
613 | SRunner *sr = srunner_create (s); | |
614 | srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because | |
615 | we need to write | |
616 | files */ | |
617 | srunner_run_all (sr, CK_ENV); | |
618 | number_failed = srunner_ntests_failed (sr); | |
619 | srunner_free (sr); | |
620 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | |
621 | } |