]>
Commit | Line | Data |
---|---|---|
74971473 JG |
1 | /* |
2 | * This file is part of the PCEPlib, a PCEP protocol library. | |
3 | * | |
4 | * Copyright (C) 2020 Volta Networks https://voltanet.io/ | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public License | |
17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
18 | * | |
19 | * Author : Brady Johnson <brady@voltanet.io> | |
20 | * | |
21 | */ | |
22 | ||
23 | ||
1f8031f7 DL |
24 | #ifdef HAVE_CONFIG_H |
25 | #include "config.h" | |
26 | #endif | |
27 | ||
fadf00aa | 28 | #include <assert.h> |
74971473 JG |
29 | #include <stdio.h> |
30 | #include <stdlib.h> | |
31 | #include <unistd.h> | |
7ed8c4b1 JG |
32 | #include <sys/types.h> |
33 | #include <sys/stat.h> | |
34 | ||
74971473 JG |
35 | |
36 | #include <CUnit/CUnit.h> | |
37 | ||
a58ba888 MS |
38 | #include <zebra.h> |
39 | ||
74971473 JG |
40 | #include "pcep_msg_encoding.h" |
41 | #include "pcep_msg_messages.h" | |
42 | #include "pcep_msg_tools.h" | |
43 | #include "pcep_msg_tools_test.h" | |
44 | #include "pcep_utils_double_linked_list.h" | |
45 | #include "pcep_utils_logging.h" | |
46 | #include "pcep_utils_memory.h" | |
47 | ||
48 | const uint8_t any_obj_class = 255; | |
49 | ||
50 | uint16_t pcep_open_hexbyte_strs_length = 28; | |
51 | const char *pcep_open_odl_hexbyte_strs[] = { | |
52 | "20", "01", "00", "1c", "01", "10", "00", "18", "20", "1e", | |
53 | "78", "55", "00", "10", "00", "04", "00", "00", "00", "3f", | |
54 | "00", "1a", "00", "04", "00", "00", "00", "00"}; | |
55 | ||
56 | /* PCEP INITIATE str received from ODL with 4 objects: [SRP, LSP, Endpoints, | |
57 | * ERO] The LSP has a SYMBOLIC_PATH_NAME TLV. The ERO has 2 IPV4 Endpoints. */ | |
58 | uint16_t pcep_initiate_hexbyte_strs_length = 68; | |
59 | const char *pcep_initiate_hexbyte_strs[] = { | |
60 | "20", "0c", "00", "44", "21", "12", "00", "0c", "00", "00", "00", "00", | |
61 | "00", "00", "00", "01", "20", "10", "00", "14", "00", "00", "00", "09", | |
62 | "00", "11", "00", "08", "66", "61", "39", "33", "33", "39", "32", "39", | |
63 | "04", "10", "00", "0c", "7f", "00", "00", "01", "28", "28", "28", "28", | |
64 | "07", "10", "00", "14", "01", "08", "0a", "00", "01", "01", "18", "00", | |
65 | "01", "08", "0a", "00", "07", "04", "18", "00"}; | |
66 | ||
67 | uint16_t pcep_initiate2_hexbyte_strs_length = 72; | |
68 | const char *pcep_initiate2_hexbyte_strs[] = { | |
69 | "20", "0c", "00", "48", "21", "12", "00", "14", "00", "00", "00", "00", | |
70 | "00", "00", "00", "01", "00", "1c", "00", "04", "00", "00", "00", "01", | |
71 | "20", "10", "00", "14", "00", "00", "00", "09", "00", "11", "00", "08", | |
72 | "36", "65", "31", "31", "38", "39", "32", "31", "04", "10", "00", "0c", | |
73 | "c0", "a8", "14", "05", "01", "01", "01", "01", "07", "10", "00", "10", | |
74 | "05", "0c", "10", "01", "03", "e8", "a0", "00", "01", "01", "01", "01"}; | |
75 | ||
76 | uint16_t pcep_update_hexbyte_strs_length = 48; | |
77 | const char *pcep_update_hexbyte_strs[] = { | |
78 | "20", "0b", "00", "30", "21", "12", "00", "14", "00", "00", "00", "00", | |
79 | "00", "00", "00", "01", "00", "1c", "00", "04", "00", "00", "00", "01", | |
80 | "20", "10", "00", "08", "00", "02", "a0", "09", "07", "10", "00", "10", | |
81 | "05", "0c", "10", "01", "03", "e8", "a0", "00", "01", "01", "01", "01"}; | |
82 | ||
83 | /* Test that pcep_msg_read() can read multiple messages in 1 call */ | |
84 | uint16_t pcep_open_initiate_hexbyte_strs_length = 100; | |
85 | const char *pcep_open_initiate_odl_hexbyte_strs[] = { | |
86 | "20", "01", "00", "1c", "01", "10", "00", "18", "20", "1e", "78", "55", | |
87 | "00", "10", "00", "04", "00", "00", "00", "3f", "00", "1a", "00", "04", | |
88 | "00", "00", "00", "00", "20", "0c", "00", "48", "21", "12", "00", "14", | |
89 | "00", "00", "00", "00", "00", "00", "00", "01", "00", "1c", "00", "04", | |
90 | "00", "00", "00", "01", "20", "10", "00", "14", "00", "00", "00", "09", | |
91 | "00", "11", "00", "08", "36", "65", "31", "31", "38", "39", "32", "31", | |
92 | "04", "10", "00", "0c", "c0", "a8", "14", "05", "01", "01", "01", "01", | |
93 | "07", "10", "00", "10", "05", "0c", "10", "01", "03", "e8", "a0", "00", | |
94 | "01", "01", "01", "01"}; | |
95 | ||
96 | uint16_t pcep_open_cisco_pce_hexbyte_strs_length = 28; | |
97 | const char *pcep_open_cisco_pce_hexbyte_strs[] = { | |
98 | "20", "01", "00", "1c", "01", "10", "00", "18", "20", "3c", | |
99 | "78", "00", "00", "10", "00", "04", "00", "00", "00", "05", | |
100 | "00", "1a", "00", "04", "00", "00", "00", "0a"}; | |
101 | ||
102 | uint16_t pcep_update_cisco_pce_hexbyte_strs_length = 100; | |
103 | const char *pcep_update_cisco_pce_hexbyte_strs[] = { | |
104 | "20", "0b", "00", "64", "21", "10", "00", "14", "00", "00", "00", "00", | |
105 | "00", "00", "00", "01", "00", "1c", "00", "04", "00", "00", "00", "01", | |
106 | "20", "10", "00", "18", "80", "00", "f0", "89", "00", "07", "00", "0c", | |
107 | "00", "00", "00", "09", "00", "03", "00", "04", "00", "00", "00", "01", | |
108 | "07", "10", "00", "28", "24", "0c", "10", "01", "04", "65", "50", "00", | |
109 | "0a", "0a", "0a", "05", "24", "0c", "10", "01", "04", "65", "20", "00", | |
110 | "0a", "0a", "0a", "02", "24", "0c", "10", "01", "04", "65", "10", "00", | |
111 | "0a", "0a", "0a", "01", "06", "10", "00", "0c", "00", "00", "00", "02", | |
112 | "41", "f0", "00", "00"}; | |
113 | ||
114 | uint16_t pcep_report_cisco_pcc_hexbyte_strs_length = 148; | |
115 | const char *pcep_report_cisco_pcc_hexbyte_strs[] = { | |
116 | "20", "0a", "00", "94", "21", "10", "00", "14", "00", "00", "00", "00", | |
117 | "00", "00", "00", "00", "00", "1c", "00", "04", "00", "00", "00", "01", | |
118 | "20", "10", "00", "3c", "80", "00", "f0", "09", "00", "12", "00", "10", | |
119 | "0a", "0a", "0a", "06", "00", "02", "00", "0f", "0a", "0a", "0a", "06", | |
120 | "0a", "0a", "0a", "01", "00", "11", "00", "0d", "63", "66", "67", "5f", | |
121 | "52", "36", "2d", "74", "6f", "2d", "52", "31", "00", "00", "00", "00", | |
122 | "ff", "e1", "00", "06", "00", "00", "05", "dd", "70", "00", "00", "00", | |
123 | "07", "10", "00", "04", "09", "10", "00", "14", "00", "00", "00", "00", | |
124 | "00", "00", "00", "00", "00", "00", "00", "00", "07", "07", "01", "00", | |
125 | "05", "12", "00", "08", "00", "00", "00", "00", "05", "52", "00", "08", | |
126 | "00", "00", "00", "00", "06", "10", "00", "0c", "00", "00", "00", "02", | |
127 | "00", "00", "00", "00", "06", "10", "00", "0c", "00", "00", "01", "04", | |
128 | "41", "80", "00", "00"}; | |
129 | ||
130 | /* Cisco PcInitiate with the following objects: | |
131 | * SRP, LSP, Endpoint, Inter-layer, Switch-layer, ERO | |
132 | */ | |
133 | uint16_t pcep_initiate_cisco_pcc_hexbyte_strs_length = 104; | |
134 | const char *pcep_initiate_cisco_pcc_hexbyte_strs[] = { | |
135 | "20", "0c", "00", "68", "21", "10", "00", "14", "00", "00", "00", "00", | |
136 | "00", "00", "00", "01", "00", "1c", "00", "04", "00", "00", "00", "01", | |
137 | "20", "10", "00", "30", "00", "00", "00", "89", "00", "11", "00", "13", | |
138 | "50", "4f", "4c", "31", "5f", "50", "43", "49", "4e", "49", "54", "41", | |
139 | "54", "45", "5f", "54", "45", "53", "54", "00", "00", "07", "00", "0c", | |
140 | "00", "00", "00", "09", "00", "03", "00", "04", "00", "00", "00", "01", | |
141 | "04", "10", "00", "0c", "0a", "0a", "0a", "0a", "0a", "0a", "0a", "04", | |
142 | "24", "10", "00", "08", "00", "00", "01", "4d", "25", "10", "00", "08", | |
143 | "00", "00", "00", "64", "07", "10", "00", "04"}; | |
144 | ||
145 | struct pcep_message *create_message(uint8_t msg_type, uint8_t obj1_class, | |
146 | uint8_t obj2_class, uint8_t obj3_class, | |
147 | uint8_t obj4_class); | |
a58ba888 | 148 | int convert_hexstrs_to_binary(char *filename, const char *hexbyte_strs[], |
74971473 JG |
149 | uint16_t hexbyte_strs_length); |
150 | ||
151 | int pcep_tools_test_suite_setup(void) | |
152 | { | |
153 | pceplib_memory_reset(); | |
154 | return 0; | |
155 | } | |
156 | ||
157 | int pcep_tools_test_suite_teardown(void) | |
158 | { | |
159 | printf("\n"); | |
160 | pceplib_memory_dump(); | |
161 | return 0; | |
162 | } | |
163 | ||
164 | void pcep_tools_test_setup(void) | |
165 | { | |
166 | } | |
167 | ||
168 | void pcep_tools_test_teardown(void) | |
169 | { | |
170 | } | |
171 | ||
a58ba888 MS |
172 | static const char BASE_TMPFILE[] = "/tmp/pceplib_XXXXXX"; |
173 | static int BASE_TMPFILE_SIZE = sizeof(BASE_TMPFILE); | |
174 | ||
74971473 JG |
175 | /* Reads an array of hexbyte strs, and writes them to a temporary file. |
176 | * The caller should close the returned file. */ | |
b8cc7b62 | 177 | int convert_hexstrs_to_binary(char *filename, const char *hexbyte_strs[], |
74971473 JG |
178 | uint16_t hexbyte_strs_length) |
179 | { | |
7ed8c4b1 | 180 | mode_t oldumask; |
b8cc7b62 | 181 | oldumask = umask(S_IXUSR | S_IXGRP | S_IWOTH | S_IROTH | S_IXOTH); |
7ed8c4b1 JG |
182 | /* Set umask before anything for security */ |
183 | umask(0027); | |
a58ba888 MS |
184 | |
185 | strlcpy(filename, BASE_TMPFILE, BASE_TMPFILE_SIZE); | |
186 | int fd = mkstemp(filename); | |
7ed8c4b1 | 187 | umask(oldumask); |
a58ba888 | 188 | |
7ed8c4b1 JG |
189 | if (fd == -1) |
190 | return -1; | |
74971473 JG |
191 | |
192 | int i = 0; | |
193 | for (; i < hexbyte_strs_length; i++) { | |
194 | uint8_t byte = (uint8_t)strtol(hexbyte_strs[i], 0, 16); | |
195 | if (write(fd, (char *)&byte, 1) < 0) { | |
196 | return -1; | |
197 | } | |
198 | } | |
199 | ||
200 | /* Go back to the beginning of the file */ | |
201 | lseek(fd, 0, SEEK_SET); | |
202 | return fd; | |
203 | } | |
204 | ||
205 | static bool pcep_obj_has_tlv(struct pcep_object_header *obj_hdr) | |
206 | { | |
207 | if (obj_hdr->tlv_list == NULL) { | |
208 | return false; | |
209 | } | |
210 | ||
211 | return (obj_hdr->tlv_list->num_entries > 0); | |
212 | } | |
213 | ||
214 | void test_pcep_msg_read_pcep_initiate() | |
215 | { | |
a58ba888 MS |
216 | char filename[BASE_TMPFILE_SIZE]; |
217 | ||
b8cc7b62 | 218 | int fd = convert_hexstrs_to_binary(filename, pcep_initiate_hexbyte_strs, |
74971473 | 219 | pcep_initiate_hexbyte_strs_length); |
b8cc7b62 QY |
220 | if (fd == -1) { |
221 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
222 | return; |
223 | } | |
74971473 JG |
224 | double_linked_list *msg_list = pcep_msg_read(fd); |
225 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 226 | assert(msg_list != NULL); |
74971473 JG |
227 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
228 | ||
229 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
230 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 4); | |
231 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_INITIATE); | |
232 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
233 | pcep_initiate_hexbyte_strs_length); | |
234 | ||
235 | /* Verify each of the object types */ | |
236 | ||
237 | /* SRP object */ | |
238 | double_linked_list_node *node = msg->obj_list->head; | |
239 | struct pcep_object_header *obj_hdr = | |
240 | (struct pcep_object_header *)node->data; | |
241 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_SRP); | |
242 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_SRP); | |
243 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, | |
244 | pcep_object_get_length_by_hdr(obj_hdr)); | |
245 | CU_ASSERT_FALSE(pcep_obj_has_tlv(obj_hdr)); | |
246 | ||
247 | /* LSP object and its TLV*/ | |
248 | node = node->next_node; | |
249 | obj_hdr = (struct pcep_object_header *)node->data; | |
250 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_LSP); | |
251 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_LSP); | |
252 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 20); | |
253 | CU_ASSERT_EQUAL(((struct pcep_object_lsp *)obj_hdr)->plsp_id, 0); | |
254 | CU_ASSERT_TRUE(((struct pcep_object_lsp *)obj_hdr)->flag_d); | |
255 | CU_ASSERT_TRUE(((struct pcep_object_lsp *)obj_hdr)->flag_a); | |
256 | CU_ASSERT_FALSE(((struct pcep_object_lsp *)obj_hdr)->flag_s); | |
257 | CU_ASSERT_FALSE(((struct pcep_object_lsp *)obj_hdr)->flag_r); | |
258 | CU_ASSERT_FALSE(((struct pcep_object_lsp *)obj_hdr)->flag_c); | |
259 | ||
260 | /* LSP TLV */ | |
261 | CU_ASSERT_TRUE(pcep_obj_has_tlv(obj_hdr)); | |
262 | CU_ASSERT_EQUAL(obj_hdr->tlv_list->num_entries, 1); | |
263 | struct pcep_object_tlv_header *tlv = | |
264 | (struct pcep_object_tlv_header *)obj_hdr->tlv_list->head->data; | |
265 | CU_ASSERT_EQUAL(tlv->type, PCEP_OBJ_TLV_TYPE_SYMBOLIC_PATH_NAME); | |
266 | CU_ASSERT_EQUAL(tlv->encoded_tlv_length, 8); | |
267 | ||
268 | /* Endpoints object */ | |
269 | node = node->next_node; | |
270 | obj_hdr = (struct pcep_object_header *)node->data; | |
271 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_ENDPOINTS); | |
272 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_ENDPOINT_IPV4); | |
273 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, | |
274 | pcep_object_get_length_by_hdr(obj_hdr)); | |
275 | CU_ASSERT_FALSE(pcep_obj_has_tlv(obj_hdr)); | |
276 | ||
277 | /* ERO object */ | |
278 | node = node->next_node; | |
279 | obj_hdr = (struct pcep_object_header *)node->data; | |
280 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_ERO); | |
281 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_ERO); | |
282 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 20); | |
283 | ||
284 | /* ERO Subobjects */ | |
285 | double_linked_list *ero_subobj_list = | |
286 | ((struct pcep_object_ro *)obj_hdr)->sub_objects; | |
287 | CU_ASSERT_PTR_NOT_NULL(ero_subobj_list); | |
fadf00aa | 288 | assert(ero_subobj_list != NULL); |
74971473 JG |
289 | CU_ASSERT_EQUAL(ero_subobj_list->num_entries, 2); |
290 | double_linked_list_node *subobj_node = ero_subobj_list->head; | |
291 | struct pcep_object_ro_subobj *subobj_hdr = | |
292 | (struct pcep_object_ro_subobj *)subobj_node->data; | |
293 | CU_ASSERT_EQUAL(subobj_hdr->ro_subobj_type, RO_SUBOBJ_TYPE_IPV4); | |
294 | struct in_addr ero_subobj_ip; | |
295 | inet_pton(AF_INET, "10.0.1.1", &ero_subobj_ip); | |
296 | CU_ASSERT_EQUAL( | |
297 | ((struct pcep_ro_subobj_ipv4 *)subobj_hdr)->ip_addr.s_addr, | |
298 | ero_subobj_ip.s_addr); | |
299 | CU_ASSERT_EQUAL( | |
300 | ((struct pcep_ro_subobj_ipv4 *)subobj_hdr)->prefix_length, 24); | |
301 | ||
302 | subobj_hdr = | |
303 | (struct pcep_object_ro_subobj *)subobj_node->next_node->data; | |
304 | CU_ASSERT_EQUAL(subobj_hdr->ro_subobj_type, RO_SUBOBJ_TYPE_IPV4); | |
305 | inet_pton(AF_INET, "10.0.7.4", &ero_subobj_ip); | |
306 | CU_ASSERT_EQUAL( | |
307 | ((struct pcep_ro_subobj_ipv4 *)subobj_hdr)->ip_addr.s_addr, | |
308 | ero_subobj_ip.s_addr); | |
309 | CU_ASSERT_EQUAL( | |
310 | ((struct pcep_ro_subobj_ipv4 *)subobj_hdr)->prefix_length, 24); | |
311 | ||
312 | pcep_msg_free_message_list(msg_list); | |
313 | close(fd); | |
a58ba888 | 314 | unlink(filename); |
74971473 JG |
315 | } |
316 | ||
317 | ||
318 | void test_pcep_msg_read_pcep_initiate2() | |
319 | { | |
a58ba888 MS |
320 | char filename[BASE_TMPFILE_SIZE]; |
321 | ||
b8cc7b62 QY |
322 | int fd = |
323 | convert_hexstrs_to_binary(filename, pcep_initiate2_hexbyte_strs, | |
324 | pcep_initiate2_hexbyte_strs_length); | |
325 | if (fd == -1) { | |
326 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
327 | return; |
328 | } | |
74971473 JG |
329 | double_linked_list *msg_list = pcep_msg_read(fd); |
330 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 331 | assert(msg_list != NULL); |
74971473 JG |
332 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
333 | ||
334 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
335 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 4); | |
336 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_INITIATE); | |
337 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
338 | pcep_initiate2_hexbyte_strs_length); | |
339 | ||
340 | /* Verify each of the object types */ | |
341 | ||
342 | /* SRP object */ | |
343 | double_linked_list_node *node = msg->obj_list->head; | |
344 | struct pcep_object_header *obj_hdr = | |
345 | (struct pcep_object_header *)node->data; | |
346 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_SRP); | |
347 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_SRP); | |
348 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 20); | |
349 | CU_ASSERT_TRUE(pcep_obj_has_tlv(obj_hdr)); | |
350 | /* TODO test the TLVs */ | |
351 | ||
352 | /* LSP object and its TLV*/ | |
353 | node = node->next_node; | |
354 | obj_hdr = (struct pcep_object_header *)node->data; | |
355 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_LSP); | |
356 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_LSP); | |
357 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 20); | |
358 | ||
359 | /* LSP TLV */ | |
360 | CU_ASSERT_TRUE(pcep_obj_has_tlv(obj_hdr)); | |
361 | CU_ASSERT_EQUAL(obj_hdr->tlv_list->num_entries, 1); | |
362 | struct pcep_object_tlv_header *tlv = | |
363 | (struct pcep_object_tlv_header *)obj_hdr->tlv_list->head->data; | |
364 | CU_ASSERT_EQUAL(tlv->type, PCEP_OBJ_TLV_TYPE_SYMBOLIC_PATH_NAME); | |
365 | CU_ASSERT_EQUAL(tlv->encoded_tlv_length, 8); | |
366 | ||
367 | /* Endpoints object */ | |
368 | node = node->next_node; | |
369 | obj_hdr = (struct pcep_object_header *)node->data; | |
370 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_ENDPOINTS); | |
371 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_ENDPOINT_IPV4); | |
372 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, | |
373 | pcep_object_get_length_by_hdr(obj_hdr)); | |
374 | CU_ASSERT_FALSE(pcep_obj_has_tlv(obj_hdr)); | |
375 | ||
376 | /* ERO object */ | |
377 | node = node->next_node; | |
378 | obj_hdr = (struct pcep_object_header *)node->data; | |
379 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_ERO); | |
380 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_ERO); | |
381 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 16); | |
382 | ||
383 | /* ERO Subobjects */ | |
384 | double_linked_list *ero_subobj_list = | |
385 | ((struct pcep_object_ro *)obj_hdr)->sub_objects; | |
386 | CU_ASSERT_PTR_NOT_NULL(ero_subobj_list); | |
fadf00aa | 387 | assert(ero_subobj_list != NULL); |
74971473 JG |
388 | CU_ASSERT_EQUAL(ero_subobj_list->num_entries, 0); |
389 | double_linked_list_node *subobj_node = ero_subobj_list->head; | |
390 | CU_ASSERT_PTR_NULL(subobj_node); | |
391 | /* We no longer support draft07 SR sub-object type=5, and only support | |
392 | type=36 struct pcep_object_ro_subobj *subobj_hdr = (struct | |
393 | pcep_object_ro_subobj *) subobj_node->data; | |
394 | CU_ASSERT_EQUAL(subobj_hdr->ro_subobj_type, RO_SUBOBJ_TYPE_SR); | |
395 | struct pcep_ro_subobj_sr *subobj_sr = (struct pcep_ro_subobj_sr *) | |
396 | subobj_hdr; CU_ASSERT_EQUAL(subobj_sr->nai_type, | |
397 | PCEP_SR_SUBOBJ_NAI_IPV4_NODE); CU_ASSERT_TRUE(subobj_sr->flag_m); | |
398 | CU_ASSERT_FALSE(subobj_sr->flag_c); | |
399 | CU_ASSERT_FALSE(subobj_sr->flag_s); | |
400 | CU_ASSERT_FALSE(subobj_sr->flag_f); | |
401 | CU_ASSERT_EQUAL(subobj_sr->sid, 65576960); | |
402 | CU_ASSERT_EQUAL(*((uint32_t *) subobj_sr->nai_list->head->data), | |
403 | 0x01010101); | |
404 | */ | |
405 | ||
406 | pcep_msg_free_message_list(msg_list); | |
407 | close(fd); | |
a58ba888 | 408 | unlink(filename); |
74971473 JG |
409 | } |
410 | ||
411 | void test_pcep_msg_read_pcep_open() | |
412 | { | |
a58ba888 MS |
413 | char filename[BASE_TMPFILE_SIZE]; |
414 | ||
b8cc7b62 | 415 | int fd = convert_hexstrs_to_binary(filename, pcep_open_odl_hexbyte_strs, |
74971473 | 416 | pcep_open_hexbyte_strs_length); |
b8cc7b62 QY |
417 | if (fd == -1) { |
418 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
419 | return; |
420 | } | |
74971473 JG |
421 | double_linked_list *msg_list = pcep_msg_read(fd); |
422 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 423 | assert(msg_list != NULL); |
74971473 JG |
424 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
425 | ||
426 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
427 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 1); | |
428 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_OPEN); | |
429 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
430 | pcep_open_hexbyte_strs_length); | |
431 | ||
432 | /* Verify the Open message */ | |
433 | struct pcep_object_header *obj_hdr = | |
434 | (struct pcep_object_header *)msg->obj_list->head->data; | |
435 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_OPEN); | |
436 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_OPEN); | |
437 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 24); | |
438 | CU_ASSERT_TRUE(pcep_obj_has_tlv(obj_hdr)); | |
439 | ||
440 | /* Open TLV: Stateful PCE Capability */ | |
441 | CU_ASSERT_EQUAL(obj_hdr->tlv_list->num_entries, 2); | |
442 | double_linked_list_node *tlv_node = obj_hdr->tlv_list->head; | |
443 | struct pcep_object_tlv_header *tlv = | |
444 | (struct pcep_object_tlv_header *)tlv_node->data; | |
445 | CU_ASSERT_EQUAL(tlv->type, PCEP_OBJ_TLV_TYPE_STATEFUL_PCE_CAPABILITY); | |
446 | CU_ASSERT_EQUAL(tlv->encoded_tlv_length, 4); | |
447 | ||
448 | /* Open TLV: SR PCE Capability */ | |
449 | tlv_node = tlv_node->next_node; | |
450 | tlv = (struct pcep_object_tlv_header *)tlv_node->data; | |
451 | CU_ASSERT_EQUAL(tlv->type, PCEP_OBJ_TLV_TYPE_SR_PCE_CAPABILITY); | |
452 | CU_ASSERT_EQUAL(tlv->encoded_tlv_length, 4); | |
453 | ||
454 | pcep_msg_free_message_list(msg_list); | |
455 | close(fd); | |
a58ba888 | 456 | unlink(filename); |
74971473 JG |
457 | } |
458 | ||
459 | void test_pcep_msg_read_pcep_update() | |
460 | { | |
a58ba888 MS |
461 | char filename[BASE_TMPFILE_SIZE]; |
462 | ||
b8cc7b62 | 463 | int fd = convert_hexstrs_to_binary(filename, pcep_update_hexbyte_strs, |
74971473 | 464 | pcep_update_hexbyte_strs_length); |
b8cc7b62 QY |
465 | if (fd == -1) { |
466 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
467 | return; |
468 | } | |
74971473 JG |
469 | double_linked_list *msg_list = pcep_msg_read(fd); |
470 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 471 | assert(msg_list != NULL); |
74971473 JG |
472 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
473 | ||
474 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
475 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 3); | |
476 | ||
477 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_UPDATE); | |
478 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
479 | pcep_update_hexbyte_strs_length); | |
480 | ||
481 | /* Verify each of the object types */ | |
482 | ||
483 | double_linked_list_node *node = msg->obj_list->head; | |
484 | ||
485 | /* SRP object */ | |
486 | struct pcep_object_header *obj_hdr = | |
487 | (struct pcep_object_header *)node->data; | |
488 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_SRP); | |
489 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_SRP); | |
490 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 20); | |
491 | CU_ASSERT_TRUE(pcep_obj_has_tlv(obj_hdr)); | |
492 | ||
493 | /* SRP TLV */ | |
494 | CU_ASSERT_EQUAL(obj_hdr->tlv_list->num_entries, 1); | |
495 | struct pcep_object_tlv_header *tlv = | |
496 | (struct pcep_object_tlv_header *)obj_hdr->tlv_list->head->data; | |
497 | CU_ASSERT_EQUAL(tlv->type, PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE); | |
498 | CU_ASSERT_EQUAL(tlv->encoded_tlv_length, 4); | |
499 | /* TODO verify the path setup type */ | |
500 | ||
501 | /* LSP object */ | |
502 | node = node->next_node; | |
503 | obj_hdr = (struct pcep_object_header *)node->data; | |
504 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_LSP); | |
505 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_LSP); | |
506 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, | |
507 | pcep_object_get_length_by_hdr(obj_hdr)); | |
508 | CU_ASSERT_FALSE(pcep_obj_has_tlv(obj_hdr)); | |
509 | ||
510 | /* ERO object */ | |
511 | node = node->next_node; | |
512 | obj_hdr = (struct pcep_object_header *)node->data; | |
513 | CU_ASSERT_EQUAL(obj_hdr->object_class, PCEP_OBJ_CLASS_ERO); | |
514 | CU_ASSERT_EQUAL(obj_hdr->object_type, PCEP_OBJ_TYPE_ERO); | |
515 | CU_ASSERT_EQUAL(obj_hdr->encoded_object_length, 16); | |
516 | ||
517 | /* ERO Subobjects */ | |
518 | double_linked_list *ero_subobj_list = | |
519 | ((struct pcep_object_ro *)obj_hdr)->sub_objects; | |
520 | CU_ASSERT_PTR_NOT_NULL(ero_subobj_list); | |
fadf00aa | 521 | assert(ero_subobj_list != NULL); |
74971473 JG |
522 | CU_ASSERT_EQUAL(ero_subobj_list->num_entries, 0); |
523 | double_linked_list_node *subobj_node = ero_subobj_list->head; | |
524 | CU_ASSERT_PTR_NULL(subobj_node); | |
525 | /* We no longer support draft07 SR sub-object type=5, and only support | |
526 | type=36 struct pcep_object_ro_subobj *subobj_hdr = (struct | |
527 | pcep_object_ro_subobj *) subobj_node->data; | |
528 | CU_ASSERT_EQUAL(subobj_hdr->ro_subobj_type, RO_SUBOBJ_TYPE_SR); | |
529 | struct pcep_ro_subobj_sr *subobj_sr = (struct pcep_ro_subobj_sr *) | |
530 | subobj_hdr; CU_ASSERT_EQUAL(subobj_sr->nai_type, | |
531 | PCEP_SR_SUBOBJ_NAI_IPV4_NODE); CU_ASSERT_TRUE(subobj_sr->flag_m); | |
532 | CU_ASSERT_FALSE(subobj_sr->flag_c); | |
533 | CU_ASSERT_FALSE(subobj_sr->flag_s); | |
534 | CU_ASSERT_FALSE(subobj_sr->flag_f); | |
535 | CU_ASSERT_EQUAL(subobj_sr->sid, 65576960); | |
536 | CU_ASSERT_EQUAL(*((uint32_t *) subobj_sr->nai_list->head->data), | |
537 | 0x01010101); | |
538 | */ | |
539 | ||
540 | pcep_msg_free_message_list(msg_list); | |
541 | close(fd); | |
a58ba888 | 542 | unlink(filename); |
74971473 JG |
543 | } |
544 | ||
545 | void test_pcep_msg_read_pcep_open_initiate() | |
546 | { | |
a58ba888 MS |
547 | char filename[BASE_TMPFILE_SIZE]; |
548 | ||
74971473 | 549 | int fd = convert_hexstrs_to_binary( |
a58ba888 | 550 | filename, pcep_open_initiate_odl_hexbyte_strs, |
74971473 | 551 | pcep_open_initiate_hexbyte_strs_length); |
b8cc7b62 QY |
552 | if (fd == -1) { |
553 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
554 | return; |
555 | } | |
74971473 JG |
556 | double_linked_list *msg_list = pcep_msg_read(fd); |
557 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 558 | assert(msg_list != NULL); |
74971473 JG |
559 | CU_ASSERT_EQUAL(msg_list->num_entries, 2); |
560 | ||
561 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
562 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 1); | |
563 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_OPEN); | |
564 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
565 | pcep_open_hexbyte_strs_length); | |
566 | ||
567 | msg = (struct pcep_message *)msg_list->head->next_node->data; | |
568 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 4); | |
569 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_INITIATE); | |
570 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
571 | pcep_initiate2_hexbyte_strs_length); | |
572 | ||
573 | pcep_msg_free_message_list(msg_list); | |
574 | close(fd); | |
a58ba888 | 575 | unlink(filename); |
74971473 JG |
576 | } |
577 | ||
578 | void test_pcep_msg_read_pcep_open_cisco_pce() | |
579 | { | |
a58ba888 MS |
580 | char filename[BASE_TMPFILE_SIZE]; |
581 | ||
74971473 | 582 | int fd = convert_hexstrs_to_binary( |
a58ba888 | 583 | filename, pcep_open_cisco_pce_hexbyte_strs, |
74971473 | 584 | pcep_open_cisco_pce_hexbyte_strs_length); |
b8cc7b62 QY |
585 | if (fd == -1) { |
586 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
587 | return; |
588 | } | |
74971473 JG |
589 | double_linked_list *msg_list = pcep_msg_read(fd); |
590 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 591 | assert(msg_list != NULL); |
74971473 JG |
592 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
593 | ||
594 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
595 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_OPEN); | |
596 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
597 | pcep_open_hexbyte_strs_length); | |
598 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 1); | |
599 | ||
600 | /* Open object */ | |
601 | struct pcep_object_open *open = | |
602 | (struct pcep_object_open *)msg->obj_list->head->data; | |
603 | CU_ASSERT_EQUAL(open->header.object_class, PCEP_OBJ_CLASS_OPEN); | |
604 | CU_ASSERT_EQUAL(open->header.object_type, PCEP_OBJ_TYPE_OPEN); | |
605 | CU_ASSERT_EQUAL(open->header.encoded_object_length, 24); | |
606 | CU_ASSERT_EQUAL(open->open_deadtimer, 120); | |
607 | CU_ASSERT_EQUAL(open->open_keepalive, 60); | |
608 | CU_ASSERT_EQUAL(open->open_sid, 0); | |
609 | CU_ASSERT_EQUAL(open->open_version, 1); | |
610 | CU_ASSERT_PTR_NOT_NULL(open->header.tlv_list); | |
fadf00aa | 611 | assert(open->header.tlv_list != NULL); |
74971473 JG |
612 | CU_ASSERT_EQUAL(open->header.tlv_list->num_entries, 2); |
613 | ||
614 | /* Stateful PCE Capability TLV */ | |
615 | double_linked_list_node *tlv_node = open->header.tlv_list->head; | |
616 | struct pcep_object_tlv_stateful_pce_capability *pce_cap_tlv = | |
617 | (struct pcep_object_tlv_stateful_pce_capability *) | |
618 | tlv_node->data; | |
619 | CU_ASSERT_EQUAL(pce_cap_tlv->header.type, | |
620 | PCEP_OBJ_TLV_TYPE_STATEFUL_PCE_CAPABILITY); | |
621 | CU_ASSERT_EQUAL(pce_cap_tlv->header.encoded_tlv_length, 4); | |
622 | CU_ASSERT_TRUE(pce_cap_tlv->flag_u_lsp_update_capability); | |
623 | CU_ASSERT_TRUE(pce_cap_tlv->flag_i_lsp_instantiation_capability); | |
624 | CU_ASSERT_FALSE(pce_cap_tlv->flag_s_include_db_version); | |
625 | CU_ASSERT_FALSE(pce_cap_tlv->flag_t_triggered_resync); | |
626 | CU_ASSERT_FALSE(pce_cap_tlv->flag_d_delta_lsp_sync); | |
627 | CU_ASSERT_FALSE(pce_cap_tlv->flag_f_triggered_initial_sync); | |
628 | ||
629 | /* SR PCE Capability TLV */ | |
630 | tlv_node = tlv_node->next_node; | |
631 | struct pcep_object_tlv_sr_pce_capability *sr_pce_cap_tlv = | |
632 | (struct pcep_object_tlv_sr_pce_capability *)tlv_node->data; | |
633 | CU_ASSERT_EQUAL(sr_pce_cap_tlv->header.type, | |
634 | PCEP_OBJ_TLV_TYPE_SR_PCE_CAPABILITY); | |
635 | CU_ASSERT_EQUAL(sr_pce_cap_tlv->header.encoded_tlv_length, 4); | |
636 | CU_ASSERT_FALSE(sr_pce_cap_tlv->flag_n); | |
637 | CU_ASSERT_FALSE(sr_pce_cap_tlv->flag_x); | |
638 | CU_ASSERT_EQUAL(sr_pce_cap_tlv->max_sid_depth, 10); | |
639 | ||
640 | pcep_msg_free_message_list(msg_list); | |
641 | close(fd); | |
a58ba888 | 642 | unlink(filename); |
74971473 JG |
643 | } |
644 | ||
645 | void test_pcep_msg_read_pcep_update_cisco_pce() | |
646 | { | |
a58ba888 MS |
647 | char filename[BASE_TMPFILE_SIZE]; |
648 | ||
74971473 | 649 | int fd = convert_hexstrs_to_binary( |
a58ba888 | 650 | filename, pcep_update_cisco_pce_hexbyte_strs, |
74971473 | 651 | pcep_update_cisco_pce_hexbyte_strs_length); |
b8cc7b62 QY |
652 | if (fd == -1) { |
653 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
654 | return; |
655 | } | |
74971473 JG |
656 | double_linked_list *msg_list = pcep_msg_read(fd); |
657 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 658 | assert(msg_list != NULL); |
74971473 JG |
659 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
660 | ||
661 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
662 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_UPDATE); | |
663 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
664 | pcep_update_cisco_pce_hexbyte_strs_length); | |
665 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 4); | |
666 | ||
667 | /* SRP object */ | |
668 | double_linked_list_node *obj_node = msg->obj_list->head; | |
669 | struct pcep_object_srp *srp = (struct pcep_object_srp *)obj_node->data; | |
670 | CU_ASSERT_EQUAL(srp->header.object_class, PCEP_OBJ_CLASS_SRP); | |
671 | CU_ASSERT_EQUAL(srp->header.object_type, PCEP_OBJ_TYPE_SRP); | |
672 | CU_ASSERT_EQUAL(srp->header.encoded_object_length, 20); | |
673 | CU_ASSERT_PTR_NOT_NULL(srp->header.tlv_list); | |
fadf00aa | 674 | assert(srp->header.tlv_list != NULL); |
74971473 JG |
675 | CU_ASSERT_EQUAL(srp->header.tlv_list->num_entries, 1); |
676 | CU_ASSERT_EQUAL(srp->srp_id_number, 1); | |
677 | CU_ASSERT_FALSE(srp->flag_lsp_remove); | |
678 | ||
679 | /* SRP Path Setup Type TLV */ | |
680 | double_linked_list_node *tlv_node = srp->header.tlv_list->head; | |
681 | struct pcep_object_tlv_path_setup_type *pst_tlv = | |
682 | (struct pcep_object_tlv_path_setup_type *)tlv_node->data; | |
683 | CU_ASSERT_EQUAL(pst_tlv->header.type, | |
684 | PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE); | |
685 | CU_ASSERT_EQUAL(pst_tlv->header.encoded_tlv_length, 4); | |
686 | CU_ASSERT_EQUAL(pst_tlv->path_setup_type, 1); | |
687 | ||
688 | /* LSP object */ | |
689 | obj_node = obj_node->next_node; | |
690 | struct pcep_object_lsp *lsp = (struct pcep_object_lsp *)obj_node->data; | |
691 | CU_ASSERT_EQUAL(lsp->header.object_class, PCEP_OBJ_CLASS_LSP); | |
692 | CU_ASSERT_EQUAL(lsp->header.object_type, PCEP_OBJ_TYPE_LSP); | |
693 | CU_ASSERT_EQUAL(lsp->header.encoded_object_length, 24); | |
694 | CU_ASSERT_PTR_NOT_NULL(lsp->header.tlv_list); | |
fadf00aa | 695 | assert(lsp->header.tlv_list != NULL); |
74971473 JG |
696 | CU_ASSERT_EQUAL(lsp->header.tlv_list->num_entries, 1); |
697 | CU_ASSERT_EQUAL(lsp->plsp_id, 524303); | |
698 | CU_ASSERT_EQUAL(lsp->operational_status, PCEP_LSP_OPERATIONAL_DOWN); | |
699 | CU_ASSERT_TRUE(lsp->flag_a); | |
700 | CU_ASSERT_TRUE(lsp->flag_c); | |
701 | CU_ASSERT_TRUE(lsp->flag_d); | |
702 | CU_ASSERT_FALSE(lsp->flag_r); | |
703 | CU_ASSERT_FALSE(lsp->flag_s); | |
704 | ||
705 | /* LSP Vendor Info TLV */ | |
706 | tlv_node = lsp->header.tlv_list->head; | |
707 | struct pcep_object_tlv_vendor_info *vendor_tlv = | |
708 | (struct pcep_object_tlv_vendor_info *)tlv_node->data; | |
709 | CU_ASSERT_EQUAL(vendor_tlv->header.type, PCEP_OBJ_TLV_TYPE_VENDOR_INFO); | |
710 | CU_ASSERT_EQUAL(vendor_tlv->header.encoded_tlv_length, 12); | |
711 | CU_ASSERT_EQUAL(vendor_tlv->enterprise_number, 9); | |
712 | CU_ASSERT_EQUAL(vendor_tlv->enterprise_specific_info, 0x00030004); | |
713 | ||
714 | /* ERO object */ | |
715 | obj_node = obj_node->next_node; | |
716 | struct pcep_object_ro *ero = (struct pcep_object_ro *)obj_node->data; | |
717 | CU_ASSERT_EQUAL(ero->header.object_class, PCEP_OBJ_CLASS_ERO); | |
718 | CU_ASSERT_EQUAL(ero->header.object_type, PCEP_OBJ_TYPE_ERO); | |
719 | CU_ASSERT_EQUAL(ero->header.encoded_object_length, 40); | |
720 | CU_ASSERT_PTR_NULL(ero->header.tlv_list); | |
721 | CU_ASSERT_PTR_NOT_NULL(ero->sub_objects); | |
fadf00aa | 722 | assert(ero->sub_objects != NULL); |
74971473 JG |
723 | CU_ASSERT_EQUAL(ero->sub_objects->num_entries, 3); |
724 | ||
725 | /* ERO Subobjects */ | |
726 | double_linked_list_node *ero_subobj_node = ero->sub_objects->head; | |
727 | struct pcep_ro_subobj_sr *sr_subobj_ipv4_node = | |
728 | (struct pcep_ro_subobj_sr *)ero_subobj_node->data; | |
729 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->ro_subobj.ro_subobj_type, | |
730 | RO_SUBOBJ_TYPE_SR); | |
731 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->ro_subobj.flag_subobj_loose_hop); | |
732 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->nai_type, | |
733 | PCEP_SR_SUBOBJ_NAI_IPV4_NODE); | |
734 | CU_ASSERT_TRUE(sr_subobj_ipv4_node->flag_m); | |
735 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_c); | |
736 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_f); | |
737 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_s); | |
738 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->sid, 73748480); | |
739 | CU_ASSERT_EQUAL( | |
740 | *((uint32_t *)sr_subobj_ipv4_node->nai_list->head->data), | |
741 | htonl(0x0a0a0a05)); | |
742 | ||
743 | ero_subobj_node = ero_subobj_node->next_node; | |
744 | sr_subobj_ipv4_node = (struct pcep_ro_subobj_sr *)ero_subobj_node->data; | |
745 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->ro_subobj.ro_subobj_type, | |
746 | RO_SUBOBJ_TYPE_SR); | |
747 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->ro_subobj.flag_subobj_loose_hop); | |
748 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->nai_type, | |
749 | PCEP_SR_SUBOBJ_NAI_IPV4_NODE); | |
750 | CU_ASSERT_TRUE(sr_subobj_ipv4_node->flag_m); | |
751 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_c); | |
752 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_f); | |
753 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_s); | |
754 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->sid, 73736192); | |
755 | CU_ASSERT_EQUAL( | |
756 | *((uint32_t *)sr_subobj_ipv4_node->nai_list->head->data), | |
757 | htonl(0x0a0a0a02)); | |
758 | ||
759 | ero_subobj_node = ero_subobj_node->next_node; | |
760 | sr_subobj_ipv4_node = (struct pcep_ro_subobj_sr *)ero_subobj_node->data; | |
761 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->ro_subobj.ro_subobj_type, | |
762 | RO_SUBOBJ_TYPE_SR); | |
763 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->ro_subobj.flag_subobj_loose_hop); | |
764 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->nai_type, | |
765 | PCEP_SR_SUBOBJ_NAI_IPV4_NODE); | |
766 | CU_ASSERT_TRUE(sr_subobj_ipv4_node->flag_m); | |
767 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_c); | |
768 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_f); | |
769 | CU_ASSERT_FALSE(sr_subobj_ipv4_node->flag_s); | |
770 | CU_ASSERT_EQUAL(sr_subobj_ipv4_node->sid, 73732096); | |
771 | CU_ASSERT_EQUAL( | |
772 | *((uint32_t *)sr_subobj_ipv4_node->nai_list->head->data), | |
773 | htonl(0x0a0a0a01)); | |
774 | ||
775 | /* Metric object */ | |
776 | obj_node = obj_node->next_node; | |
777 | struct pcep_object_metric *metric = | |
778 | (struct pcep_object_metric *)obj_node->data; | |
779 | CU_ASSERT_EQUAL(metric->header.object_class, PCEP_OBJ_CLASS_METRIC); | |
780 | CU_ASSERT_EQUAL(metric->header.object_type, PCEP_OBJ_TYPE_METRIC); | |
781 | CU_ASSERT_EQUAL(metric->header.encoded_object_length, 12); | |
782 | CU_ASSERT_PTR_NULL(metric->header.tlv_list); | |
783 | CU_ASSERT_FALSE(metric->flag_b); | |
784 | CU_ASSERT_FALSE(metric->flag_c); | |
785 | CU_ASSERT_EQUAL(metric->type, PCEP_METRIC_TE); | |
786 | CU_ASSERT_EQUAL(metric->value, 30.0); | |
787 | ||
788 | pcep_msg_free_message_list(msg_list); | |
789 | close(fd); | |
a58ba888 | 790 | unlink(filename); |
74971473 JG |
791 | } |
792 | ||
793 | void test_pcep_msg_read_pcep_report_cisco_pcc() | |
794 | { | |
a58ba888 MS |
795 | char filename[BASE_TMPFILE_SIZE]; |
796 | ||
74971473 | 797 | int fd = convert_hexstrs_to_binary( |
a58ba888 | 798 | filename, pcep_report_cisco_pcc_hexbyte_strs, |
74971473 | 799 | pcep_report_cisco_pcc_hexbyte_strs_length); |
b8cc7b62 QY |
800 | if (fd == -1) { |
801 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
802 | return; |
803 | } | |
74971473 JG |
804 | double_linked_list *msg_list = pcep_msg_read(fd); |
805 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 806 | assert(msg_list != NULL); |
74971473 JG |
807 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
808 | ||
809 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
810 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_REPORT); | |
811 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
812 | pcep_report_cisco_pcc_hexbyte_strs_length); | |
813 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 8); | |
814 | ||
815 | /* SRP object */ | |
816 | double_linked_list_node *obj_node = msg->obj_list->head; | |
817 | struct pcep_object_srp *srp = (struct pcep_object_srp *)obj_node->data; | |
818 | CU_ASSERT_EQUAL(srp->header.object_class, PCEP_OBJ_CLASS_SRP); | |
819 | CU_ASSERT_EQUAL(srp->header.object_type, PCEP_OBJ_TYPE_SRP); | |
820 | CU_ASSERT_EQUAL(srp->header.encoded_object_length, 20); | |
821 | CU_ASSERT_PTR_NOT_NULL(srp->header.tlv_list); | |
fadf00aa | 822 | assert(srp->header.tlv_list != NULL); |
74971473 JG |
823 | CU_ASSERT_EQUAL(srp->header.tlv_list->num_entries, 1); |
824 | CU_ASSERT_EQUAL(srp->srp_id_number, 0); | |
825 | CU_ASSERT_FALSE(srp->flag_lsp_remove); | |
826 | ||
827 | /* SRP Path Setup Type TLV */ | |
828 | double_linked_list_node *tlv_node = srp->header.tlv_list->head; | |
829 | struct pcep_object_tlv_path_setup_type *pst_tlv = | |
830 | (struct pcep_object_tlv_path_setup_type *)tlv_node->data; | |
831 | CU_ASSERT_EQUAL(pst_tlv->header.type, | |
832 | PCEP_OBJ_TLV_TYPE_PATH_SETUP_TYPE); | |
833 | CU_ASSERT_EQUAL(pst_tlv->header.encoded_tlv_length, 4); | |
834 | CU_ASSERT_EQUAL(pst_tlv->path_setup_type, 1); | |
835 | ||
836 | /* LSP object */ | |
837 | obj_node = obj_node->next_node; | |
838 | struct pcep_object_lsp *lsp = (struct pcep_object_lsp *)obj_node->data; | |
839 | CU_ASSERT_EQUAL(lsp->header.object_class, PCEP_OBJ_CLASS_LSP); | |
840 | CU_ASSERT_EQUAL(lsp->header.object_type, PCEP_OBJ_TYPE_LSP); | |
841 | CU_ASSERT_EQUAL(lsp->header.encoded_object_length, 60); | |
842 | CU_ASSERT_PTR_NOT_NULL(lsp->header.tlv_list); | |
5fe7f5b4 JG |
843 | /* The TLV with ID 65505 is now recognized, and its in the list */ |
844 | CU_ASSERT_EQUAL(lsp->header.tlv_list->num_entries, 3); | |
74971473 JG |
845 | CU_ASSERT_EQUAL(lsp->plsp_id, 524303); |
846 | CU_ASSERT_EQUAL(lsp->operational_status, PCEP_LSP_OPERATIONAL_DOWN); | |
847 | CU_ASSERT_TRUE(lsp->flag_a); | |
848 | CU_ASSERT_TRUE(lsp->flag_d); | |
849 | CU_ASSERT_FALSE(lsp->flag_c); | |
850 | CU_ASSERT_FALSE(lsp->flag_r); | |
851 | CU_ASSERT_FALSE(lsp->flag_s); | |
852 | ||
853 | /* LSP IPv4 LSP Identifier TLV */ | |
854 | tlv_node = lsp->header.tlv_list->head; | |
855 | struct pcep_object_tlv_ipv4_lsp_identifier *ipv4_lsp_id = | |
856 | (struct pcep_object_tlv_ipv4_lsp_identifier *)tlv_node->data; | |
857 | CU_ASSERT_EQUAL(ipv4_lsp_id->header.type, | |
858 | PCEP_OBJ_TLV_TYPE_IPV4_LSP_IDENTIFIERS); | |
859 | CU_ASSERT_EQUAL(ipv4_lsp_id->header.encoded_tlv_length, 16); | |
860 | CU_ASSERT_EQUAL(ipv4_lsp_id->ipv4_tunnel_sender.s_addr, | |
861 | htonl(0x0a0a0a06)); | |
862 | CU_ASSERT_EQUAL(ipv4_lsp_id->ipv4_tunnel_endpoint.s_addr, | |
863 | htonl(0x0a0a0a01)); | |
864 | CU_ASSERT_EQUAL(ipv4_lsp_id->extended_tunnel_id.s_addr, | |
865 | htonl(0x0a0a0a06)); | |
866 | CU_ASSERT_EQUAL(ipv4_lsp_id->tunnel_id, 15); | |
867 | CU_ASSERT_EQUAL(ipv4_lsp_id->lsp_id, 2); | |
868 | ||
869 | /* LSP Symbolic Path Name TLV */ | |
870 | tlv_node = tlv_node->next_node; | |
871 | struct pcep_object_tlv_symbolic_path_name *sym_path_name = | |
872 | (struct pcep_object_tlv_symbolic_path_name *)tlv_node->data; | |
873 | CU_ASSERT_EQUAL(sym_path_name->header.type, | |
874 | PCEP_OBJ_TLV_TYPE_SYMBOLIC_PATH_NAME); | |
875 | CU_ASSERT_EQUAL(sym_path_name->header.encoded_tlv_length, 13); | |
876 | CU_ASSERT_EQUAL(sym_path_name->symbolic_path_name_length, 13); | |
877 | CU_ASSERT_EQUAL( | |
878 | strncmp(sym_path_name->symbolic_path_name, "cfg_R6-to-R1", 13), | |
879 | 0); | |
880 | ||
881 | /* ERO object */ | |
882 | obj_node = obj_node->next_node; | |
883 | struct pcep_object_ro *ero = (struct pcep_object_ro *)obj_node->data; | |
884 | CU_ASSERT_EQUAL(ero->header.object_class, PCEP_OBJ_CLASS_ERO); | |
885 | CU_ASSERT_EQUAL(ero->header.object_type, PCEP_OBJ_TYPE_ERO); | |
886 | CU_ASSERT_EQUAL(ero->header.encoded_object_length, 4); | |
887 | CU_ASSERT_PTR_NULL(ero->header.tlv_list); | |
888 | CU_ASSERT_PTR_NOT_NULL(ero->sub_objects); | |
fadf00aa | 889 | assert(ero->sub_objects != NULL); |
74971473 JG |
890 | CU_ASSERT_EQUAL(ero->sub_objects->num_entries, 0); |
891 | ||
892 | /* LSPA object */ | |
893 | obj_node = obj_node->next_node; | |
894 | struct pcep_object_lspa *lspa = | |
895 | (struct pcep_object_lspa *)obj_node->data; | |
896 | CU_ASSERT_EQUAL(lspa->header.object_class, PCEP_OBJ_CLASS_LSPA); | |
897 | CU_ASSERT_EQUAL(lspa->header.object_type, PCEP_OBJ_TYPE_LSPA); | |
898 | CU_ASSERT_EQUAL(lspa->header.encoded_object_length, 20); | |
899 | CU_ASSERT_PTR_NULL(lspa->header.tlv_list); | |
900 | CU_ASSERT_TRUE(lspa->flag_local_protection); | |
901 | CU_ASSERT_EQUAL(lspa->holding_priority, 7); | |
902 | CU_ASSERT_EQUAL(lspa->setup_priority, 7); | |
903 | CU_ASSERT_EQUAL(lspa->lspa_include_all, 0); | |
904 | CU_ASSERT_EQUAL(lspa->lspa_include_any, 0); | |
905 | CU_ASSERT_EQUAL(lspa->lspa_exclude_any, 0); | |
906 | ||
907 | /* Bandwidth object 1 */ | |
908 | obj_node = obj_node->next_node; | |
909 | struct pcep_object_bandwidth *bandwidth = | |
910 | (struct pcep_object_bandwidth *)obj_node->data; | |
911 | CU_ASSERT_EQUAL(bandwidth->header.object_class, | |
912 | PCEP_OBJ_CLASS_BANDWIDTH); | |
913 | CU_ASSERT_EQUAL(bandwidth->header.object_type, | |
914 | PCEP_OBJ_TYPE_BANDWIDTH_REQ); | |
915 | CU_ASSERT_EQUAL(bandwidth->header.encoded_object_length, 8); | |
916 | CU_ASSERT_EQUAL(bandwidth->bandwidth, 0); | |
917 | ||
918 | /* Bandwidth object 2 */ | |
919 | obj_node = obj_node->next_node; | |
920 | bandwidth = (struct pcep_object_bandwidth *)obj_node->data; | |
921 | CU_ASSERT_EQUAL(bandwidth->header.object_class, | |
922 | PCEP_OBJ_CLASS_BANDWIDTH); | |
923 | CU_ASSERT_EQUAL(bandwidth->header.object_type, | |
924 | PCEP_OBJ_TYPE_BANDWIDTH_CISCO); | |
925 | CU_ASSERT_EQUAL(bandwidth->header.encoded_object_length, 8); | |
926 | CU_ASSERT_EQUAL(bandwidth->bandwidth, 0); | |
927 | ||
928 | /* Metric object 1 */ | |
929 | obj_node = obj_node->next_node; | |
930 | struct pcep_object_metric *metric = | |
931 | (struct pcep_object_metric *)obj_node->data; | |
932 | CU_ASSERT_EQUAL(metric->header.object_class, PCEP_OBJ_CLASS_METRIC); | |
933 | CU_ASSERT_EQUAL(metric->header.object_type, PCEP_OBJ_TYPE_METRIC); | |
934 | CU_ASSERT_EQUAL(metric->header.encoded_object_length, 12); | |
935 | CU_ASSERT_PTR_NULL(metric->header.tlv_list); | |
936 | CU_ASSERT_FALSE(metric->flag_b); | |
937 | CU_ASSERT_FALSE(metric->flag_c); | |
938 | CU_ASSERT_EQUAL(metric->type, PCEP_METRIC_TE); | |
939 | CU_ASSERT_EQUAL(metric->value, 0); | |
940 | ||
941 | /* Metric object 2 */ | |
942 | obj_node = obj_node->next_node; | |
943 | metric = (struct pcep_object_metric *)obj_node->data; | |
944 | CU_ASSERT_EQUAL(metric->header.object_class, PCEP_OBJ_CLASS_METRIC); | |
945 | CU_ASSERT_EQUAL(metric->header.object_type, PCEP_OBJ_TYPE_METRIC); | |
946 | CU_ASSERT_EQUAL(metric->header.encoded_object_length, 12); | |
947 | CU_ASSERT_PTR_NULL(metric->header.tlv_list); | |
948 | CU_ASSERT_TRUE(metric->flag_b); | |
949 | CU_ASSERT_FALSE(metric->flag_c); | |
950 | CU_ASSERT_EQUAL(metric->type, PCEP_METRIC_AGGREGATE_BW); | |
951 | CU_ASSERT_EQUAL(metric->value, 16.0); | |
952 | ||
953 | pcep_msg_free_message_list(msg_list); | |
954 | close(fd); | |
a58ba888 | 955 | unlink(filename); |
74971473 JG |
956 | } |
957 | ||
958 | void test_pcep_msg_read_pcep_initiate_cisco_pcc() | |
959 | { | |
a58ba888 MS |
960 | char filename[BASE_TMPFILE_SIZE]; |
961 | ||
74971473 | 962 | int fd = convert_hexstrs_to_binary( |
a58ba888 | 963 | filename, pcep_initiate_cisco_pcc_hexbyte_strs, |
74971473 | 964 | pcep_initiate_cisco_pcc_hexbyte_strs_length); |
b8cc7b62 QY |
965 | if (fd == -1) { |
966 | CU_ASSERT_TRUE(fd >= 0); | |
7ed8c4b1 JG |
967 | return; |
968 | } | |
74971473 JG |
969 | double_linked_list *msg_list = pcep_msg_read(fd); |
970 | CU_ASSERT_PTR_NOT_NULL(msg_list); | |
fadf00aa | 971 | assert(msg_list != NULL); |
74971473 JG |
972 | CU_ASSERT_EQUAL(msg_list->num_entries, 1); |
973 | ||
974 | struct pcep_message *msg = (struct pcep_message *)msg_list->head->data; | |
975 | CU_ASSERT_EQUAL(msg->msg_header->type, PCEP_TYPE_INITIATE); | |
976 | CU_ASSERT_EQUAL(msg->encoded_message_length, | |
977 | pcep_initiate_cisco_pcc_hexbyte_strs_length); | |
978 | CU_ASSERT_EQUAL(msg->obj_list->num_entries, 6); | |
979 | ||
980 | /* SRP object */ | |
981 | double_linked_list_node *obj_node = msg->obj_list->head; | |
982 | struct pcep_object_srp *srp = (struct pcep_object_srp *)obj_node->data; | |
983 | CU_ASSERT_EQUAL(srp->header.object_class, PCEP_OBJ_CLASS_SRP); | |
984 | CU_ASSERT_EQUAL(srp->header.object_type, PCEP_OBJ_TYPE_SRP); | |
985 | CU_ASSERT_EQUAL(srp->header.encoded_object_length, 20); | |
986 | CU_ASSERT_PTR_NOT_NULL(srp->header.tlv_list); | |
fadf00aa | 987 | assert(srp->header.tlv_list != NULL); |
74971473 JG |
988 | CU_ASSERT_EQUAL(srp->header.tlv_list->num_entries, 1); |
989 | CU_ASSERT_EQUAL(srp->srp_id_number, 1); | |
990 | CU_ASSERT_FALSE(srp->flag_lsp_remove); | |
991 | ||
992 | /* LSP object */ | |
993 | obj_node = obj_node->next_node; | |
994 | struct pcep_object_lsp *lsp = (struct pcep_object_lsp *)obj_node->data; | |
995 | CU_ASSERT_EQUAL(lsp->header.object_class, PCEP_OBJ_CLASS_LSP); | |
996 | CU_ASSERT_EQUAL(lsp->header.object_type, PCEP_OBJ_TYPE_LSP); | |
997 | CU_ASSERT_EQUAL(lsp->header.encoded_object_length, 48); | |
998 | CU_ASSERT_PTR_NOT_NULL(lsp->header.tlv_list); | |
fadf00aa | 999 | assert(lsp->header.tlv_list != NULL); |
74971473 JG |
1000 | CU_ASSERT_EQUAL(lsp->header.tlv_list->num_entries, 2); |
1001 | CU_ASSERT_EQUAL(lsp->plsp_id, 0); | |
1002 | CU_ASSERT_EQUAL(lsp->operational_status, PCEP_LSP_OPERATIONAL_DOWN); | |
1003 | CU_ASSERT_TRUE(lsp->flag_a); | |
1004 | CU_ASSERT_TRUE(lsp->flag_d); | |
1005 | CU_ASSERT_TRUE(lsp->flag_c); | |
1006 | CU_ASSERT_FALSE(lsp->flag_r); | |
1007 | CU_ASSERT_FALSE(lsp->flag_s); | |
1008 | ||
1009 | /* Endpoint object */ | |
1010 | obj_node = obj_node->next_node; | |
1011 | struct pcep_object_endpoints_ipv4 *endpoint = | |
1012 | (struct pcep_object_endpoints_ipv4 *)obj_node->data; | |
1013 | CU_ASSERT_EQUAL(endpoint->header.object_class, | |
1014 | PCEP_OBJ_CLASS_ENDPOINTS); | |
1015 | CU_ASSERT_EQUAL(endpoint->header.object_type, | |
1016 | PCEP_OBJ_TYPE_ENDPOINT_IPV4); | |
1017 | CU_ASSERT_EQUAL(endpoint->header.encoded_object_length, 12); | |
1018 | CU_ASSERT_PTR_NULL(endpoint->header.tlv_list); | |
1019 | CU_ASSERT_EQUAL(endpoint->src_ipv4.s_addr, htonl(0x0a0a0a0a)); | |
1020 | CU_ASSERT_EQUAL(endpoint->dst_ipv4.s_addr, htonl(0x0a0a0a04)); | |
1021 | ||
1022 | /* Inter-Layer object */ | |
1023 | obj_node = obj_node->next_node; | |
1024 | struct pcep_object_inter_layer *inter_layer = | |
1025 | (struct pcep_object_inter_layer *)obj_node->data; | |
1026 | CU_ASSERT_EQUAL(inter_layer->header.object_class, | |
1027 | PCEP_OBJ_CLASS_INTER_LAYER); | |
1028 | CU_ASSERT_EQUAL(inter_layer->header.object_type, | |
1029 | PCEP_OBJ_TYPE_INTER_LAYER); | |
1030 | CU_ASSERT_EQUAL(inter_layer->header.encoded_object_length, 8); | |
1031 | CU_ASSERT_PTR_NULL(inter_layer->header.tlv_list); | |
1032 | CU_ASSERT_TRUE(inter_layer->flag_i); | |
1033 | CU_ASSERT_FALSE(inter_layer->flag_m); | |
1034 | CU_ASSERT_TRUE(inter_layer->flag_t); | |
1035 | ||
1036 | /* Switch-Layer object */ | |
1037 | obj_node = obj_node->next_node; | |
1038 | struct pcep_object_switch_layer *switch_layer = | |
1039 | (struct pcep_object_switch_layer *)obj_node->data; | |
1040 | CU_ASSERT_EQUAL(switch_layer->header.object_class, | |
1041 | PCEP_OBJ_CLASS_SWITCH_LAYER); | |
1042 | CU_ASSERT_EQUAL(switch_layer->header.object_type, | |
1043 | PCEP_OBJ_TYPE_SWITCH_LAYER); | |
1044 | CU_ASSERT_EQUAL(switch_layer->header.encoded_object_length, 8); | |
1045 | CU_ASSERT_PTR_NULL(switch_layer->header.tlv_list); | |
fadf00aa | 1046 | assert(switch_layer->header.tlv_list == NULL); |
74971473 | 1047 | CU_ASSERT_PTR_NOT_NULL(switch_layer->switch_layer_rows); |
fadf00aa | 1048 | assert(switch_layer->switch_layer_rows != NULL); |
74971473 JG |
1049 | CU_ASSERT_EQUAL(switch_layer->switch_layer_rows->num_entries, 1); |
1050 | struct pcep_object_switch_layer_row *switch_layer_row = | |
1051 | (struct pcep_object_switch_layer_row *) | |
1052 | switch_layer->switch_layer_rows->head->data; | |
1053 | CU_ASSERT_EQUAL(switch_layer_row->lsp_encoding_type, 0); | |
1054 | CU_ASSERT_EQUAL(switch_layer_row->switching_type, 0); | |
1055 | CU_ASSERT_FALSE(switch_layer_row->flag_i); | |
1056 | ||
1057 | /* ERO object */ | |
1058 | obj_node = obj_node->next_node; | |
1059 | struct pcep_object_ro *ero = (struct pcep_object_ro *)obj_node->data; | |
1060 | CU_ASSERT_EQUAL(ero->header.object_class, PCEP_OBJ_CLASS_ERO); | |
1061 | CU_ASSERT_EQUAL(ero->header.object_type, PCEP_OBJ_TYPE_ERO); | |
1062 | CU_ASSERT_EQUAL(ero->header.encoded_object_length, 4); | |
1063 | CU_ASSERT_PTR_NULL(ero->header.tlv_list); | |
1064 | ||
1065 | pcep_msg_free_message_list(msg_list); | |
1066 | close(fd); | |
a58ba888 | 1067 | unlink(filename); |
74971473 JG |
1068 | } |
1069 | ||
1070 | void test_validate_message_header() | |
1071 | { | |
1072 | uint8_t pcep_message_invalid_version[] = {0x40, 0x01, 0x04, 0x00}; | |
1073 | uint8_t pcep_message_invalid_flags[] = {0x22, 0x01, 0x04, 0x00}; | |
1074 | uint8_t pcep_message_invalid_length[] = {0x20, 0x01, 0x00, 0x00}; | |
1075 | uint8_t pcep_message_invalid_type[] = {0x20, 0xff, 0x04, 0x00}; | |
1076 | uint8_t pcep_message_valid[] = {0x20, 0x01, 0x00, 0x04}; | |
1077 | ||
1078 | /* Verify invalid message header version */ | |
1079 | CU_ASSERT_TRUE( | |
1080 | pcep_decode_validate_msg_header(pcep_message_invalid_version) | |
1081 | < 0); | |
1082 | ||
1083 | /* Verify invalid message header flags */ | |
1084 | CU_ASSERT_TRUE( | |
1085 | pcep_decode_validate_msg_header(pcep_message_invalid_flags) | |
1086 | < 0); | |
1087 | ||
1088 | /* Verify invalid message header lengths */ | |
1089 | CU_ASSERT_TRUE( | |
1090 | pcep_decode_validate_msg_header(pcep_message_invalid_length) | |
1091 | < 0); | |
1092 | pcep_message_invalid_length[3] = 0x05; | |
1093 | CU_ASSERT_TRUE( | |
1094 | pcep_decode_validate_msg_header(pcep_message_invalid_length) | |
1095 | < 0); | |
1096 | ||
1097 | /* Verify invalid message header types */ | |
1098 | CU_ASSERT_TRUE( | |
1099 | pcep_decode_validate_msg_header(pcep_message_invalid_type) < 0); | |
1100 | pcep_message_invalid_type[1] = 0x00; | |
1101 | CU_ASSERT_TRUE( | |
1102 | pcep_decode_validate_msg_header(pcep_message_invalid_type) < 0); | |
1103 | ||
1104 | /* Verify a valid message header */ | |
1105 | CU_ASSERT_EQUAL(pcep_decode_validate_msg_header(pcep_message_valid), 4); | |
1106 | } | |
1107 | ||
1108 | /* Internal util function */ | |
1109 | struct pcep_message *create_message(uint8_t msg_type, uint8_t obj1_class, | |
1110 | uint8_t obj2_class, uint8_t obj3_class, | |
1111 | uint8_t obj4_class) | |
1112 | { | |
1113 | struct pcep_message *msg = | |
1114 | pceplib_malloc(PCEPLIB_MESSAGES, sizeof(struct pcep_message)); | |
1115 | msg->obj_list = dll_initialize(); | |
1116 | msg->msg_header = pceplib_malloc(PCEPLIB_MESSAGES, | |
1117 | sizeof(struct pcep_message_header)); | |
1118 | msg->msg_header->type = msg_type; | |
1119 | msg->encoded_message = NULL; | |
1120 | ||
1121 | if (obj1_class > 0) { | |
1122 | struct pcep_object_header *obj_hdr = pceplib_malloc( | |
1123 | PCEPLIB_MESSAGES, sizeof(struct pcep_object_header)); | |
1124 | obj_hdr->object_class = obj1_class; | |
1125 | obj_hdr->tlv_list = NULL; | |
1126 | dll_append(msg->obj_list, obj_hdr); | |
1127 | } | |
1128 | ||
1129 | if (obj2_class > 0) { | |
1130 | struct pcep_object_header *obj_hdr = pceplib_malloc( | |
1131 | PCEPLIB_MESSAGES, sizeof(struct pcep_object_header)); | |
1132 | obj_hdr->object_class = obj2_class; | |
1133 | obj_hdr->tlv_list = NULL; | |
1134 | dll_append(msg->obj_list, obj_hdr); | |
1135 | } | |
1136 | ||
1137 | if (obj3_class > 0) { | |
1138 | struct pcep_object_header *obj_hdr = pceplib_malloc( | |
1139 | PCEPLIB_MESSAGES, sizeof(struct pcep_object_header)); | |
1140 | obj_hdr->object_class = obj3_class; | |
1141 | obj_hdr->tlv_list = NULL; | |
1142 | dll_append(msg->obj_list, obj_hdr); | |
1143 | } | |
1144 | ||
1145 | if (obj4_class > 0) { | |
1146 | struct pcep_object_header *obj_hdr = pceplib_malloc( | |
1147 | PCEPLIB_MESSAGES, sizeof(struct pcep_object_header)); | |
1148 | obj_hdr->object_class = obj4_class; | |
1149 | obj_hdr->tlv_list = NULL; | |
1150 | dll_append(msg->obj_list, obj_hdr); | |
1151 | } | |
1152 | ||
1153 | return msg; | |
1154 | } | |
1155 | ||
1156 | void test_validate_message_objects() | |
1157 | { | |
1158 | /* Valid Open message */ | |
1159 | struct pcep_message *msg = | |
1160 | create_message(PCEP_TYPE_OPEN, PCEP_OBJ_CLASS_OPEN, 0, 0, 0); | |
1161 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1162 | pcep_msg_free_message(msg); | |
1163 | ||
1164 | /* Valid KeepAlive message */ | |
1165 | msg = create_message(PCEP_TYPE_KEEPALIVE, 0, 0, 0, 0); | |
1166 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1167 | pcep_msg_free_message(msg); | |
1168 | ||
1169 | /* Valid PcReq message */ | |
1170 | /* Using object_class=255 to verify it can take any object */ | |
1171 | msg = create_message(PCEP_TYPE_PCREQ, PCEP_OBJ_CLASS_RP, | |
1172 | PCEP_OBJ_CLASS_ENDPOINTS, any_obj_class, 0); | |
1173 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1174 | pcep_msg_free_message(msg); | |
1175 | ||
1176 | /* Valid PcRep message */ | |
1177 | msg = create_message(PCEP_TYPE_PCREP, PCEP_OBJ_CLASS_RP, any_obj_class, | |
1178 | 0, 0); | |
1179 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1180 | pcep_msg_free_message(msg); | |
1181 | ||
1182 | /* Valid Notify message */ | |
1183 | msg = create_message(PCEP_TYPE_PCNOTF, PCEP_OBJ_CLASS_NOTF, | |
1184 | any_obj_class, 0, 0); | |
1185 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1186 | pcep_msg_free_message(msg); | |
1187 | ||
1188 | /* Valid Error message */ | |
1189 | msg = create_message(PCEP_TYPE_ERROR, PCEP_OBJ_CLASS_ERROR, | |
1190 | any_obj_class, 0, 0); | |
1191 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1192 | pcep_msg_free_message(msg); | |
1193 | ||
1194 | /* Valid Close message */ | |
1195 | msg = create_message(PCEP_TYPE_CLOSE, PCEP_OBJ_CLASS_CLOSE, 0, 0, 0); | |
1196 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1197 | pcep_msg_free_message(msg); | |
1198 | ||
1199 | /* Valid Report message */ | |
1200 | msg = create_message(PCEP_TYPE_REPORT, PCEP_OBJ_CLASS_SRP, | |
1201 | PCEP_OBJ_CLASS_LSP, any_obj_class, any_obj_class); | |
1202 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1203 | pcep_msg_free_message(msg); | |
1204 | ||
1205 | /* Valid Update message */ | |
1206 | msg = create_message(PCEP_TYPE_UPDATE, PCEP_OBJ_CLASS_SRP, | |
1207 | PCEP_OBJ_CLASS_LSP, any_obj_class, any_obj_class); | |
1208 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1209 | pcep_msg_free_message(msg); | |
1210 | ||
1211 | /* Valid Initiate message */ | |
1212 | msg = create_message(PCEP_TYPE_INITIATE, PCEP_OBJ_CLASS_SRP, | |
1213 | PCEP_OBJ_CLASS_LSP, any_obj_class, any_obj_class); | |
1214 | CU_ASSERT_TRUE(validate_message_objects(msg)); | |
1215 | pcep_msg_free_message(msg); | |
1216 | } | |
1217 | ||
1218 | void test_validate_message_objects_invalid() | |
1219 | { | |
1220 | /* unsupported message ID = 0 | |
1221 | * {NO_OBJECT, NO_OBJECT, NO_OBJECT, NO_OBJECT} */ | |
1222 | struct pcep_message *msg = create_message(0, any_obj_class, 0, 0, 0); | |
1223 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1224 | pcep_msg_free_message(msg); | |
1225 | ||
1226 | /* Open message | |
1227 | * {PCEP_OBJ_CLASS_OPEN, NO_OBJECT, NO_OBJECT, NO_OBJECT} */ | |
1228 | msg = create_message(PCEP_TYPE_OPEN, 0, 0, 0, 0); | |
1229 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1230 | pcep_msg_free_message(msg); | |
1231 | ||
1232 | msg = create_message(PCEP_TYPE_OPEN, any_obj_class, 0, 0, 0); | |
1233 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1234 | pcep_msg_free_message(msg); | |
1235 | ||
1236 | msg = create_message(PCEP_TYPE_OPEN, PCEP_OBJ_CLASS_OPEN, any_obj_class, | |
1237 | 0, 0); | |
1238 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1239 | pcep_msg_free_message(msg); | |
1240 | ||
1241 | /* KeepAlive message | |
1242 | * {NO_OBJECT, NO_OBJECT, NO_OBJECT, NO_OBJECT} */ | |
1243 | msg = create_message(PCEP_TYPE_KEEPALIVE, any_obj_class, 0, 0, 0); | |
1244 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1245 | pcep_msg_free_message(msg); | |
1246 | ||
1247 | /* PcReq message | |
1248 | * {PCEP_OBJ_CLASS_RP, PCEP_OBJ_CLASS_ENDPOINTS, ANY_OBJECT, ANY_OBJECT} | |
1249 | */ | |
1250 | msg = create_message(PCEP_TYPE_PCREQ, 0, 0, 0, 0); | |
1251 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1252 | pcep_msg_free_message(msg); | |
1253 | ||
1254 | msg = create_message(PCEP_TYPE_PCREQ, PCEP_OBJ_CLASS_RP, any_obj_class, | |
1255 | 0, 0); | |
1256 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1257 | pcep_msg_free_message(msg); | |
1258 | ||
1259 | /* PcRep message | |
1260 | * {PCEP_OBJ_CLASS_RP, ANY_OBJECT, ANY_OBJECT, ANY_OBJECT} */ | |
1261 | msg = create_message(PCEP_TYPE_PCREP, 0, 0, 0, 0); | |
1262 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1263 | pcep_msg_free_message(msg); | |
1264 | ||
1265 | msg = create_message(PCEP_TYPE_PCREP, any_obj_class, 0, 0, 0); | |
1266 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1267 | pcep_msg_free_message(msg); | |
1268 | ||
1269 | /* Notify message | |
1270 | * {PCEP_OBJ_CLASS_NOTF, ANY_OBJECT, ANY_OBJECT, ANY_OBJECT} */ | |
1271 | msg = create_message(PCEP_TYPE_PCNOTF, 0, 0, 0, 0); | |
1272 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1273 | pcep_msg_free_message(msg); | |
1274 | ||
1275 | msg = create_message(PCEP_TYPE_PCNOTF, any_obj_class, 0, 0, 0); | |
1276 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1277 | pcep_msg_free_message(msg); | |
1278 | ||
1279 | /* Error message | |
1280 | * {PCEP_OBJ_CLASS_ERROR, ANY_OBJECT, ANY_OBJECT, ANY_OBJECT} */ | |
1281 | msg = create_message(PCEP_TYPE_ERROR, 0, 0, 0, 0); | |
1282 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1283 | pcep_msg_free_message(msg); | |
1284 | ||
1285 | msg = create_message(PCEP_TYPE_ERROR, any_obj_class, 0, 0, 0); | |
1286 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1287 | pcep_msg_free_message(msg); | |
1288 | ||
1289 | /* Close message | |
1290 | * {PCEP_OBJ_CLASS_CLOSE, NO_OBJECT, NO_OBJECT, NO_OBJECT} */ | |
1291 | msg = create_message(PCEP_TYPE_CLOSE, 0, 0, 0, 0); | |
1292 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1293 | pcep_msg_free_message(msg); | |
1294 | ||
1295 | msg = create_message(PCEP_TYPE_CLOSE, any_obj_class, 0, 0, 0); | |
1296 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1297 | pcep_msg_free_message(msg); | |
1298 | ||
1299 | /* unsupported message ID = 8 | |
1300 | * {NO_OBJECT, NO_OBJECT, NO_OBJECT, NO_OBJECT} */ | |
1301 | msg = create_message(8, any_obj_class, 0, 0, 0); | |
1302 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1303 | pcep_msg_free_message(msg); | |
1304 | ||
1305 | /* unsupported message ID = 9 | |
1306 | * {NO_OBJECT, NO_OBJECT, NO_OBJECT, NO_OBJECT} */ | |
1307 | msg = create_message(9, any_obj_class, 0, 0, 0); | |
1308 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1309 | pcep_msg_free_message(msg); | |
1310 | ||
1311 | /* Report message | |
1312 | * {PCEP_OBJ_CLASS_SRP, PCEP_OBJ_CLASS_LSP, ANY_OBJECT, ANY_OBJECT} */ | |
1313 | msg = create_message(PCEP_TYPE_REPORT, 0, 0, 0, 0); | |
1314 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1315 | pcep_msg_free_message(msg); | |
1316 | ||
1317 | msg = create_message(PCEP_TYPE_REPORT, any_obj_class, 0, 0, 0); | |
1318 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1319 | pcep_msg_free_message(msg); | |
1320 | ||
1321 | msg = create_message(PCEP_TYPE_REPORT, PCEP_OBJ_CLASS_SRP, 0, 0, 0); | |
1322 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1323 | pcep_msg_free_message(msg); | |
1324 | ||
1325 | msg = create_message(PCEP_TYPE_REPORT, PCEP_OBJ_CLASS_SRP, | |
1326 | any_obj_class, 0, 0); | |
1327 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1328 | pcep_msg_free_message(msg); | |
1329 | ||
1330 | /* Update message | |
1331 | * {PCEP_OBJ_CLASS_SRP, PCEP_OBJ_CLASS_LSP, ANY_OBJECT, ANY_OBJECT} */ | |
1332 | msg = create_message(PCEP_TYPE_UPDATE, 0, 0, 0, 0); | |
1333 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1334 | pcep_msg_free_message(msg); | |
1335 | ||
1336 | msg = create_message(PCEP_TYPE_UPDATE, any_obj_class, 0, 0, 0); | |
1337 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1338 | pcep_msg_free_message(msg); | |
1339 | ||
1340 | msg = create_message(PCEP_TYPE_UPDATE, PCEP_OBJ_CLASS_SRP, 0, 0, 0); | |
1341 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1342 | pcep_msg_free_message(msg); | |
1343 | ||
1344 | msg = create_message(PCEP_TYPE_UPDATE, PCEP_OBJ_CLASS_SRP, | |
1345 | any_obj_class, 0, 0); | |
1346 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1347 | pcep_msg_free_message(msg); | |
1348 | ||
1349 | /* Initiate message | |
1350 | * {PCEP_OBJ_CLASS_SRP, PCEP_OBJ_CLASS_LSP, ANY_OBJECT, ANY_OBJECT} */ | |
1351 | msg = create_message(PCEP_TYPE_INITIATE, 0, 0, 0, 0); | |
1352 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1353 | pcep_msg_free_message(msg); | |
1354 | ||
1355 | msg = create_message(PCEP_TYPE_INITIATE, any_obj_class, 0, 0, 0); | |
1356 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1357 | pcep_msg_free_message(msg); | |
1358 | ||
1359 | msg = create_message(PCEP_TYPE_INITIATE, PCEP_OBJ_CLASS_SRP, 0, 0, 0); | |
1360 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1361 | pcep_msg_free_message(msg); | |
1362 | ||
1363 | msg = create_message(PCEP_TYPE_INITIATE, PCEP_OBJ_CLASS_SRP, | |
1364 | any_obj_class, 0, 0); | |
1365 | CU_ASSERT_FALSE(validate_message_objects(msg)); | |
1366 | pcep_msg_free_message(msg); | |
1367 | } |