NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
upf_accel_json_parser.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include <arpa/inet.h>
31 #include <json-c/json.h>
32 #include <rte_byteorder.h>
33 
34 #include <doca_error.h>
35 #include <doca_log.h>
36 
37 #include "upf_accel.h"
38 
39 DOCA_LOG_REGISTER(UPF_ACCEL::JSON_PARSER);
40 
41 /*
42  * Parse uint64_t property from a json object
43  *
44  * @container [in]: json container
45  * @name [in]: property name
46  * @val [out]: pointer to store the result at
47  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
48  */
49 static doca_error_t upf_accel_json_u64_parse(struct json_object *container, const char *name, uint64_t *val)
50 {
51  struct json_object *field;
52 
53  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_int) {
54  DOCA_LOG_ERR("Failed to parse JSON object u64 field '%s' from object: %s",
55  name,
56  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
57  return DOCA_ERROR_UNEXPECTED;
58  }
59 
60  assert(val);
61  *val = json_object_get_int64(field);
62  return DOCA_SUCCESS;
63 }
64 
65 /*
66  * Parse uint64_t property from a json object, such that the value is encoded
67  * as a string
68  *
69  * @container [in]: json container
70  * @name [in]: property name
71  * @val [out]: pointer to store the result at
72  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
73  */
74 static doca_error_t upf_accel_json_u64_from_string_parse(struct json_object *container, const char *name, uint64_t *val)
75 {
76  struct json_object *field;
77  uint64_t tmp;
78 
79  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_string) {
80  DOCA_LOG_ERR("Failed to parse JSON object string field %s from object: %s",
81  name,
82  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
83  return DOCA_ERROR_UNEXPECTED;
84  }
85 
86  if (sscanf(json_object_get_string(field), "%lu", &tmp) != 1) {
87  DOCA_LOG_ERR("Failed to convert JSON string object to u64 from field %s object: %s",
88  name,
89  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
90  return DOCA_ERROR_UNEXPECTED;
91  }
92 
93  assert(val);
94  *val = tmp;
95  return DOCA_SUCCESS;
96 }
97 
98 /*
99  * Parse uint32_t property from a json object
100  *
101  * @container [in]: json container
102  * @name [in]: property name
103  * @val [out]: pointer to store the result at
104  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
105  */
106 static doca_error_t upf_accel_json_u32_parse(struct json_object *container, const char *name, uint32_t *val)
107 {
108  struct json_object *field;
109 
110  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_int) {
111  DOCA_LOG_ERR("Failed to parse JSON object u32 field '%s' from object: %s",
112  name,
113  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
114  return DOCA_ERROR_UNEXPECTED;
115  }
116 
117  assert(val);
118  *val = json_object_get_int(field);
119  return DOCA_SUCCESS;
120 }
121 
122 /*
123  * Parse array property from a json object
124  *
125  * @container [in]: json container
126  * @name [in]: property name
127  * @val_size [in]: array maximum size
128  * @val [out]: pointer to store the result at
129  * @val_num [out]: number of elements in the result
130  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
131  */
132 static doca_error_t upf_accel_json_u32_arr_parse(struct json_object *container,
133  const char *name,
134  size_t val_size,
135  uint32_t *val,
136  uint32_t *val_num)
137 {
138  struct json_object *elem;
139  struct json_object *arr;
140  size_t elems_num;
141  size_t i;
142 
143  if (!json_object_object_get_ex(container, name, &arr) || json_object_get_type(arr) != json_type_array) {
144  DOCA_LOG_ERR("Failed to parse JSON object u32 array field '%s' from object: %s",
145  name,
146  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
147  return DOCA_ERROR_UNEXPECTED;
148  }
149 
150  elems_num = json_object_array_length(arr);
151  if (elems_num > val_size) {
152  DOCA_LOG_ERR("JSON object u32 array field '%s' too big: %s",
153  name,
154  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
155  return DOCA_ERROR_NO_MEMORY;
156  }
157 
158  assert(val);
159  assert(val_num);
160  for (i = 0; i < elems_num; i++) {
161  elem = json_object_array_get_idx(arr, i);
162  if (!elem || json_object_get_type(elem) != json_type_int) {
163  DOCA_LOG_ERR("Failed to parse JSON object u32 array field '%s' from object: %s",
164  name,
165  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
166  return DOCA_ERROR_UNEXPECTED;
167  }
168 
169  val[i] = json_object_get_int(elem);
170  }
171 
172  *val_num = elems_num;
173  return DOCA_SUCCESS;
174 }
175 
176 /*
177  * Parse uint8_t property from a json object
178  *
179  * @container [in]: json container
180  * @name [in]: property name
181  * @val [out]: pointer to store the result at
182  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
183  */
184 static doca_error_t upf_accel_json_u8_parse(struct json_object *container, const char *name, uint8_t *val)
185 {
186  struct json_object *field;
187  int tmp;
188 
189  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_int) {
190  DOCA_LOG_ERR("Failed to parse JSON object u8 field '%s' from object: %s",
191  name,
192  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
193  return DOCA_ERROR_UNEXPECTED;
194  }
195 
196  assert(val);
197  tmp = json_object_get_int(field);
198  if (tmp > UINT8_MAX) {
199  DOCA_LOG_ERR("JSON object u8 field '%s' is too big, object: %s",
200  name,
201  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
202  return DOCA_ERROR_TOO_BIG;
203  }
204  *val = tmp;
205  return DOCA_SUCCESS;
206 }
207 
208 /*
209  * Parse uint8_t property from a json object, such that the value is encoded
210  * as a string
211  *
212  * @container [in]: json container
213  * @name [in]: property name
214  * @val [out]: pointer to store the result at
215  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
216  */
217 static doca_error_t upf_accel_json_u8_from_string_parse(struct json_object *container, const char *name, uint8_t *val)
218 {
219  struct json_object *field;
220  uint8_t tmp;
221 
222  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_string) {
223  DOCA_LOG_ERR("Failed to parse JSON object string field %s from object: %s",
224  name,
225  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
226  return DOCA_ERROR_UNEXPECTED;
227  }
228 
229  if (sscanf(json_object_get_string(field), "%hhu", &tmp) != 1) {
230  DOCA_LOG_ERR("Failed to convert JSON string object to integer from field %s object: %s",
231  name,
232  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
233  return DOCA_ERROR_UNEXPECTED;
234  }
235 
236  assert(val);
237  *val = tmp;
238  return DOCA_SUCCESS;
239 }
240 
241 /*
242  * Parse mac property from a json object, such that the value is encoded
243  * as a string
244  *
245  * @container [in]: json container
246  * @name [in]: property name
247  * @val [out]: pointer to store the result at
248  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
249  */
250 static doca_error_t upf_accel_json_mac_from_string_parse(struct json_object *container,
251  const char *name,
252  uint8_t val[DOCA_FLOW_ETHER_ADDR_LEN])
253 {
254  uint8_t tmp[DOCA_FLOW_ETHER_ADDR_LEN];
255  struct json_object *field;
256 
257  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_string) {
258  DOCA_LOG_ERR("Failed to parse JSON object string field %s from object: %s",
259  name,
260  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
261  return DOCA_ERROR_UNEXPECTED;
262  }
263 
264  if (sscanf(json_object_get_string(field),
265  "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%*c",
266  &tmp[0],
267  &tmp[1],
268  &tmp[2],
269  &tmp[3],
270  &tmp[4],
271  &tmp[5]) != DOCA_FLOW_ETHER_ADDR_LEN) {
272  DOCA_LOG_ERR("Failed to convert JSON string object to integer array from field %s object: %s",
273  name,
274  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
275  return DOCA_ERROR_UNEXPECTED;
276  }
277 
278  assert(val);
279  val[0] = tmp[0];
280  val[1] = tmp[1];
281  val[2] = tmp[2];
282  val[3] = tmp[3];
283  val[4] = tmp[4];
284  val[5] = tmp[5];
285 
286  return DOCA_SUCCESS;
287 }
288 
289 /*
290  * Parse string property from a json object
291  *
292  * @container [in]: json container
293  * @name [in]: property name
294  * @val [out]: pointer to store the result at
295  * @val_len [out]: result length
296  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
297  */
298 static doca_error_t upf_accel_json_string_parse(struct json_object *container,
299  const char *name,
300  char *val,
301  size_t val_len)
302 {
303  struct json_object *field;
304 
305  if (!json_object_object_get_ex(container, name, &field) || json_object_get_type(field) != json_type_string) {
306  DOCA_LOG_ERR("Failed to parse JSON object string field '%s' from object: %s",
307  name,
308  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
309  return DOCA_ERROR_UNEXPECTED;
310  }
311 
312  if ((uint32_t)json_object_get_string_len(field) >= val_len) {
313  DOCA_LOG_ERR("Failed to copy JSON object string field '%s': string too big", name);
314  return DOCA_ERROR_TOO_BIG;
315  }
316 
317  assert(val);
318  strncpy(val, json_object_get_string(field), val_len);
319  return DOCA_SUCCESS;
320 }
321 
322 /*
323  * Parse IP and netmask
324  *
325  * @str_addr [in]: IP and netmask string in the form of xxx.xxx.xxx.xxx/xx
326  * @val [out]: pointer to store the result at
327  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
328  */
329 static doca_error_t upf_accel_str_to_ip_netmask_parse(const char *str_addr, struct upf_accel_ip_addr *val)
330 {
331  uint8_t o1, o2, o3, o4;
332  uint8_t netmask = 0;
333 
334  if (sscanf(str_addr, "%hhd.%hhd.%hhd.%hhd/%hhd", &o1, &o2, &o3, &o4, &netmask) < 4)
335  return DOCA_ERROR_UNEXPECTED;
336 
337  val->v4 = ((uint32_t)o1 << 24) | ((uint32_t)o2 << 16) | ((uint32_t)o3 << 8) | (uint32_t)o4;
338  val->netmask = netmask ? netmask : 32;
339  return DOCA_SUCCESS;
340 }
341 
342 /*
343  * Parse port range
344  *
345  * @str_port [in]: port range in form of xxx-xxx
346  * @val [out]: pointer to store the result at
347  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
348  */
350 {
351  uint16_t from_port;
352  uint16_t to_port;
353  int ret;
354 
355  ret = sscanf(str_port, "%hu-%hu", &from_port, &to_port);
356  if (!ret)
357  return DOCA_ERROR_UNEXPECTED;
358  else if (ret == 1)
359  to_port = from_port;
360 
361  val->from = from_port;
362  val->to = to_port;
363  return DOCA_SUCCESS;
364 }
365 
366 /*
367  * Parse IP property from a json object
368  *
369  * @container [in]: json container
370  * @name [in]: property name
371  * @val [out]: pointer to store the result at
372  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
373  */
374 static doca_error_t upf_accel_json_ip_parse(struct json_object *container,
375  const char *name,
376  struct upf_accel_ip_addr *val)
377 {
378  struct json_object *field;
379  struct json_object *ip;
380  const char *str_addr;
381 
382  if (!json_object_object_get_ex(container, name, &ip)) {
383  DOCA_LOG_ERR("Failed to parse JSON object IP field '%s' from object: %s",
384  name,
385  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
386  return DOCA_ERROR_UNEXPECTED;
387  }
388 
389  if (!json_object_object_get_ex(ip, "v4", &field) || json_object_get_type(field) != json_type_string) {
390  DOCA_LOG_ERR("Failed to parse JSON object IPv4 from object: %s",
391  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
392  return DOCA_ERROR_UNEXPECTED;
393  }
394 
395  str_addr = json_object_get_string(field);
396  assert(val);
397  if (upf_accel_str_to_ip_netmask_parse(str_addr, val) != DOCA_SUCCESS) {
398  DOCA_LOG_ERR("Failed to parse JSON object IPv4 from object: %s",
399  json_object_to_json_string_ext(container, JSON_C_TO_STRING_PRETTY));
400  }
401 
402  return DOCA_SUCCESS;
403 }
404 
405 /*
406  * Parse FTEID group
407  *
408  * @local_fteid [in]: json object of the group
409  * @upf_accel_pdr [out]: pointer to store the result at
410  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
411  */
412 static doca_error_t upf_accel_local_fteid_parse(struct json_object *local_fteid, struct upf_accel_pdr *upf_accel_pdr)
413 {
414  if (upf_accel_json_u32_parse(local_fteid, "teid_start", &upf_accel_pdr->pdi_local_teid_start) != DOCA_SUCCESS ||
417  return DOCA_ERROR_UNEXPECTED;
418 
419  return DOCA_SUCCESS;
420 }
421 
422 /*
423  * Parse user equipment group
424  *
425  * @ue [in]: json object of the group
426  * @upf_accel_pdr [out]: pointer to store the result at
427  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
428  */
429 static doca_error_t upf_accel_ue_parse(struct json_object *ue, struct upf_accel_pdr *upf_accel_pdr)
430 {
431  return upf_accel_json_ip_parse(ue, "ip", &upf_accel_pdr->pdi_ueip);
432 }
433 
434 /*
435  * Parse protocol
436  *
437  * @str_proto [in]: protocol in form of ip/tcp/udp
438  * @val [out]: pointer to store the result at
439  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
440  */
441 static doca_error_t upf_accel_str_to_proto_parse(const char *str_proto, uint16_t *val)
442 {
443  uint16_t tmp;
444 
445  if (!strcmp(str_proto, "ip"))
446  *val = 0;
447  else if (!strcmp(str_proto, "tcp"))
448  *val = 6;
449  else if (!strcmp(str_proto, "udp"))
450  *val = 17;
451  else if (sscanf(str_proto, "%hu", &tmp) == 1)
452  *val = tmp;
453  else
454  return DOCA_ERROR_UNEXPECTED;
455 
456  return DOCA_SUCCESS;
457 }
458 
459 /*
460  * Parse SDF filter group
461  *
462  * @sdf_arr [in]: json object of the group
463  * @upf_accel_pdr [out]: pointer to store the result at
464  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
465  */
466 static doca_error_t upf_accel_sdf_parse(struct json_object *sdf_arr, struct upf_accel_pdr *upf_accel_pdr)
467 {
468  char str_description[129] = {0};
469  struct json_object *sdf;
470  char *parse_ctx;
471  char *token;
472 
473  if (json_object_array_length(sdf_arr) != 1) {
474  DOCA_LOG_ERR("Failed to parse PDR SDF - unexpected size of object array: %s",
475  json_object_to_json_string_ext(sdf_arr, JSON_C_TO_STRING_PRETTY));
476  return DOCA_ERROR_UNEXPECTED;
477  }
478  sdf = json_object_array_get_idx(sdf_arr, 0);
479  if (!sdf) {
480  DOCA_LOG_ERR("Failed to parse JSON PDR SDF object: %s",
481  json_object_to_json_string_ext(sdf_arr, JSON_C_TO_STRING_PRETTY));
482  return DOCA_ERROR_UNEXPECTED;
483  }
484 
485  if (upf_accel_json_string_parse(sdf, "description", str_description, sizeof(str_description) - 1) !=
486  DOCA_SUCCESS)
487  return DOCA_ERROR_UNEXPECTED;
488 
489  token = strtok_r(str_description, " ", &parse_ctx);
490  if (!token || strcmp(token, "permit")) {
491  DOCA_LOG_ERR("Only 'permit' action is supported in JSON PDR SDF FD, got token '%s' from object: %s",
492  token ? token : "NULL",
493  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
494  return DOCA_ERROR_UNEXPECTED;
495  }
496  token = strtok_r(NULL, " ", &parse_ctx);
497  if (!token || strcmp(token, "out")) {
498  DOCA_LOG_ERR(
499  "Only outer header description is supported in JSON PDR SDF FD, got token '%s' from object: %s",
500  token ? token : "NULL",
501  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
502  return DOCA_ERROR_UNEXPECTED;
503  }
504  token = strtok_r(NULL, " ", &parse_ctx);
506  DOCA_LOG_ERR("Failed to parse protocol in JSON PDR SDF FD, got token '%s' from object: %s",
507  token ? token : "NULL",
508  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
509  return DOCA_ERROR_UNEXPECTED;
510  }
511  token = strtok_r(NULL, " ", &parse_ctx);
512  if (!token || strcmp(token, "from")) {
513  DOCA_LOG_ERR("Unexpected value JSON PDR SDF FD 'from', got token '%s' from object: %s",
514  token ? token : "NULL",
515  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
516  return DOCA_ERROR_UNEXPECTED;
517  }
518  token = strtok_r(NULL, " ", &parse_ctx);
519  if (!token || (strcmp(token, "any") &&
521  DOCA_LOG_ERR(
522  "Failed to parse IP address in JSON PDR SDF FD 'from' position, got token '%s' from object: %s",
523  token ? token : "NULL",
524  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
525  return DOCA_ERROR_UNEXPECTED;
526  }
527  token = strtok_r(NULL, " ", &parse_ctx);
528  if (!token) {
529  DOCA_LOG_ERR("Empty port range in JSON PDR SDF FD 'from' position in object: %s",
530  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
531  return DOCA_ERROR_UNEXPECTED;
533  token = strtok_r(NULL, " ", &parse_ctx);
534  } else {
537  }
538 
539  if (!token || strcmp(token, "to")) {
540  DOCA_LOG_ERR("Unexpected value JSON PDR SDF FD 'to', got token '%s' from object: %s",
541  token ? token : "NULL",
542  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
543  return DOCA_ERROR_UNEXPECTED;
544  }
545  token = strtok_r(NULL, " ", &parse_ctx);
546  if (!token || (strcmp(token, "assigned") &&
548  DOCA_LOG_ERR(
549  "Failed to parse IP address in JSON PDR SDF FD 'to' position, got token '%s' from object: %s",
550  token ? token : "NULL",
551  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
552  return DOCA_ERROR_UNEXPECTED;
553  }
554  token = strtok_r(NULL, " ", &parse_ctx);
555  if (token) {
557  DOCA_LOG_ERR(
558  "Failed to parse port range in JSON PDR SDF FD 'to' position, got token '%s' from object: %s",
559  token,
560  json_object_to_json_string_ext(sdf, JSON_C_TO_STRING_PRETTY));
561  return DOCA_ERROR_UNEXPECTED;
562  }
563  } else {
565  upf_accel_pdr->pdi_sdf_to_port_range.to = UINT16_MAX;
566  }
567 
568  return DOCA_SUCCESS;
569 }
570 
571 /*
572  * Parse PDI group
573  *
574  * @pdi [in]: json object of the group
575  * @upf_accel_pdr [out]: pointer to store the result at
576  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
577  */
578 static doca_error_t upf_accel_pdi_parse(struct json_object *pdi, struct upf_accel_pdr *upf_accel_pdr)
579 {
580  struct json_object *local_fteid;
581  struct json_object *ue;
582  struct json_object *si;
583  doca_error_t err;
584  uint8_t pdi_si;
585 
586  if (!json_object_object_get_ex(pdi, "sourceInterface", &si)) {
587  DOCA_LOG_ERR("Failed to parse JSON PDR SI child object");
588  return DOCA_ERROR_UNEXPECTED;
589  }
590 
591  if (upf_accel_json_u8_from_string_parse(si, "type", &pdi_si) != DOCA_SUCCESS ||
592  (pdi_si != UPF_ACCEL_PDR_PDI_SI_UL && pdi_si != UPF_ACCEL_PDR_PDI_SI_DL)) {
593  DOCA_LOG_ERR("Unexpected pdi si %u", pdi_si);
594  return DOCA_ERROR_UNEXPECTED;
595  }
596  upf_accel_pdr->pdi_si = pdi_si;
597 
598  if (json_object_object_get_ex(pdi, "localFT", &local_fteid)) {
599  err = upf_accel_local_fteid_parse(local_fteid, upf_accel_pdr);
600  if (err != DOCA_SUCCESS)
601  return err;
602  }
603 
604  if (json_object_object_get(pdi, "qfi") &&
606  return DOCA_ERROR_UNEXPECTED;
607 
608  if (!json_object_object_get_ex(pdi, "userEquipment", &ue) ||
610  return DOCA_ERROR_UNEXPECTED;
611 
612  if (!json_object_object_get_ex(pdi, "sdf", &ue) || upf_accel_sdf_parse(ue, upf_accel_pdr) != DOCA_SUCCESS)
613  return DOCA_ERROR_UNEXPECTED;
614 
615  return DOCA_SUCCESS;
616 }
617 
618 /*
619  * Parse list of CreatePDR nodes from json
620  *
621  * @pdr_arr [in]: list of CreaePDR json nodes
622  * @cfg [out]: the result is stored inside cfg
623  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
624  */
625 static doca_error_t upf_accel_pdr_parse(struct json_object *pdr_arr, struct upf_accel_config *cfg)
626 {
627  struct json_object *pdr;
628  struct json_object *pdi;
630  struct upf_accel_pdrs *pdrs;
631  doca_error_t err;
632  size_t num_pdrs;
633  size_t i;
634 
635  num_pdrs = json_object_array_length(pdr_arr);
636  pdrs = rte_zmalloc("UPF PDRs", sizeof(*pdrs) + sizeof(pdrs->arr_pdrs[0]) * num_pdrs, RTE_CACHE_LINE_SIZE);
637  if (!pdrs) {
638  DOCA_LOG_ERR("Failed to allocate PDR memory");
639  return DOCA_ERROR_NO_MEMORY;
640  }
641  pdrs->num_pdrs = num_pdrs;
642 
643  for (i = 0; i < num_pdrs; i++) {
644  pdr = json_object_array_get_idx(pdr_arr, i);
645  upf_accel_pdr = &pdrs->arr_pdrs[i];
646  if (!pdr) {
647  DOCA_LOG_ERR("Failed to parse JSON PDR object id %lu", i);
648  err = DOCA_ERROR_UNEXPECTED;
649  goto err_pdr;
650  }
651  DOCA_LOG_DBG("PDR:\n%s", json_object_to_json_string_ext(pdr, JSON_C_TO_STRING_PRETTY));
652 
653  if (upf_accel_json_u32_parse(pdr, "pdrId", &upf_accel_pdr->id) != DOCA_SUCCESS ||
657  "urrIds",
662  "qerIds",
666  err = DOCA_ERROR_UNEXPECTED;
667  goto err_pdr;
668  }
669 
671  DOCA_LOG_ERR("Max Supported Rate Meters Num is: %lu", UPF_ACCEL_MAX_PDR_NUM_RATE_METERS);
673  goto err_pdr;
674  }
675 
676  if ((upf_accel_pdr->qerids_num == 0) || (upf_accel_pdr->urrids_num != 1)) {
677  DOCA_LOG_ERR("Each PDR must have at least one QER (has %u) and exactly one URR (has %u)",
681  goto err_pdr;
682  }
683 
684  if (!json_object_object_get_ex(pdr, "pdi", &pdi)) {
685  DOCA_LOG_ERR("Failed to parse JSON PDR PDI child object");
686  err = DOCA_ERROR_UNEXPECTED;
687  goto err_pdr;
688  }
690  if (err != DOCA_SUCCESS)
691  goto err_pdr;
692 
694  "Parsed PDR id=%u\n\tfarId=%u first_urrid=%u first_qerid=%u\n\tPDI SI=%u QFI=%hhu teid_start=%u teid_end=%u IP=%x/%hhu UEIP=%x/%hhu\n\t\tSDF proto=%d from=%x/%hhu:%hu-%hu to=%x/%hhu:%hu-%hu",
695  upf_accel_pdr->id,
697  upf_accel_pdr->urrids[0],
698  upf_accel_pdr->qerids[0],
703  rte_be_to_cpu_32(upf_accel_pdr->pdi_local_teid_ip.v4),
705  rte_be_to_cpu_32(upf_accel_pdr->pdi_ueip.v4),
708  rte_be_to_cpu_32(upf_accel_pdr->pdi_sdf_from_ip.v4),
710  rte_be_to_cpu_16(upf_accel_pdr->pdi_sdf_from_port_range.from),
711  rte_be_to_cpu_16(upf_accel_pdr->pdi_sdf_from_port_range.to),
712  rte_be_to_cpu_32(upf_accel_pdr->pdi_sdf_to_ip.v4),
714  rte_be_to_cpu_16(upf_accel_pdr->pdi_sdf_to_port_range.from),
715  rte_be_to_cpu_16(upf_accel_pdr->pdi_sdf_to_port_range.to));
716  }
717 
718  cfg->pdrs = pdrs;
719  return DOCA_SUCCESS;
720 
721 err_pdr:
722  rte_free(pdrs);
723  return err;
724 }
725 
726 /*
727  * Cleanup items were created by upf_accel_pdr_parse
728  *
729  * @cfg [out]: UPF Acceleration configuration
730  */
732 {
733  rte_free(cfg->pdrs);
734  cfg->pdrs = NULL;
735 }
736 
737 /*
738  * Parse OH (outer header) group
739  *
740  * @oh [in]: json object of the group
741  * @upf_accel_far [out]: pointer to store the result at
742  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
743  */
744 static doca_error_t upf_accel_oh_parse(struct json_object *oh, struct upf_accel_far *upf_accel_far)
745 {
747  return DOCA_ERROR_UNEXPECTED;
748 
750  DOCA_LOG_ERR("Failed to parse JSON object IP from object: %s",
751  json_object_to_json_string_ext(oh, JSON_C_TO_STRING_PRETTY));
752  return DOCA_ERROR_UNEXPECTED;
753  }
754 
755  return DOCA_SUCCESS;
756 }
757 
758 /*
759  * Parse FP (Forwarding Policy) group
760  *
761  * @fp [in]: json object of the group
762  * @upf_accel_far [out]: pointer to store the result at
763  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
764  */
765 static doca_error_t upf_accel_fp_parse(struct json_object *fp, struct upf_accel_far *upf_accel_far)
766 {
767  struct json_object *oh;
768 
769  if (json_object_object_get_ex(fp, "outerHeader", &oh)) {
771  return DOCA_ERROR_UNEXPECTED;
772  }
773 
774  return DOCA_SUCCESS;
775 }
776 
777 /*
778  * Parse list of CreateFAR nodes from json
779  *
780  * @far_arr [in]: list of CreaeFAR json nodes
781  * @cfg [out]: the result is stored inside cfg
782  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
783  */
784 static doca_error_t upf_accel_far_parse(struct json_object *far_arr, struct upf_accel_config *cfg)
785 {
786  struct json_object *far;
788  struct json_object *fp;
789  struct upf_accel_fars *fars;
790  doca_error_t err;
791  size_t num_fars;
792  size_t i;
793 
794  num_fars = json_object_array_length(far_arr);
795  fars = rte_zmalloc("UPF FARs", sizeof(*fars) + sizeof(fars->arr_fars[0]) * num_fars, RTE_CACHE_LINE_SIZE);
796  if (!fars) {
797  DOCA_LOG_ERR("Failed to allocate FAR memory");
798  return DOCA_ERROR_NO_MEMORY;
799  }
800  fars->num_fars = num_fars;
801 
802  for (i = 0; i < num_fars; i++) {
803  far = json_object_array_get_idx(far_arr, i);
804  upf_accel_far = &fars->arr_fars[i];
805  if (!far) {
806  DOCA_LOG_ERR("Failed to parse JSON FAR object id %lu", i);
807  err = DOCA_ERROR_UNEXPECTED;
808  goto err_far;
809  }
810  DOCA_LOG_DBG("FAR:\n%s", json_object_to_json_string_ext(far, JSON_C_TO_STRING_PRETTY));
811 
812  if (upf_accel_json_u32_parse(far, "farId", &upf_accel_far->id) != DOCA_SUCCESS) {
813  err = DOCA_ERROR_UNEXPECTED;
814  goto err_far;
815  }
816 
817  if (json_object_object_get_ex(far, "fp", &fp)) {
819  if (err != DOCA_SUCCESS)
820  goto err_far;
821  }
822 
823  DOCA_LOG_INFO("Parsed FAR id=%u:\n"
824  "\tOuter Header ip=%x/%hhu",
825  upf_accel_far->id,
826  rte_be_to_cpu_32(upf_accel_far->fp_oh_ip.v4),
828  }
829 
830  cfg->fars = fars;
831  return DOCA_SUCCESS;
832 
833 err_far:
834  rte_free(fars);
835  return err;
836 }
837 
838 /*
839  * Cleanup items were created by upf_accel_far_parse
840  *
841  * @cfg [out]: UPF Acceleration configuration
842  */
844 {
845  rte_free(cfg->fars);
846  cfg->fars = NULL;
847 }
848 
849 /*
850  * Parse volume quota group
851  *
852  * @volume_quota [in]: json object of the group
853  * @upf_accel_urr [out]: pointer to store the result at
854  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
855  */
856 static doca_error_t upf_accel_volume_quota_parse(struct json_object *volume_quota, struct upf_accel_urr *upf_accel_urr)
857 {
858  if (upf_accel_json_u64_parse(volume_quota, "totalVolume", &upf_accel_urr->volume_quota_total_volume) !=
859  DOCA_SUCCESS)
860  return DOCA_ERROR_UNEXPECTED;
861 
862  return DOCA_SUCCESS;
863 }
864 
865 /*
866  * Parse list of CreateURR nodes from json
867  *
868  * @urr_arr [in]: list of CreaeURR json nodes
869  * @cfg [out]: the result is stored inside cfg
870  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
871  */
872 static doca_error_t upf_accel_urr_parse(struct json_object *urr_arr, struct upf_accel_config *cfg)
873 {
874  struct json_object *volume_quota;
875  struct json_object *urr;
877  struct upf_accel_urrs *urrs;
878  doca_error_t err;
879  size_t num_urrs;
880  size_t i;
881 
882  num_urrs = json_object_array_length(urr_arr);
883  urrs = rte_zmalloc("UPF URRs", sizeof(*urrs) + sizeof(urrs->arr_urrs[0]) * num_urrs, RTE_CACHE_LINE_SIZE);
884  if (!urrs) {
885  DOCA_LOG_ERR("Failed to allocate URR memory");
886  return DOCA_ERROR_NO_MEMORY;
887  }
888  urrs->num_urrs = num_urrs;
889 
890  for (i = 0; i < num_urrs; i++) {
891  urr = json_object_array_get_idx(urr_arr, i);
892  upf_accel_urr = &urrs->arr_urrs[i];
893  if (!urr) {
894  DOCA_LOG_ERR("Failed to parse JSON URR object id %lu", i);
895  err = DOCA_ERROR_UNEXPECTED;
896  goto err_far;
897  }
898  DOCA_LOG_DBG("URR:\n%s", json_object_to_json_string_ext(urr, JSON_C_TO_STRING_PRETTY));
899 
900  if (upf_accel_json_u32_parse(urr, "urrId", &upf_accel_urr->id) != DOCA_SUCCESS) {
901  err = DOCA_ERROR_UNEXPECTED;
902  goto err_far;
903  }
904 
905  if (!json_object_object_get_ex(urr, "volumeQuota", &volume_quota)) {
906  DOCA_LOG_ERR("Failed to parse JSON URR volume quota child object");
907  err = DOCA_ERROR_UNEXPECTED;
908  goto err_far;
909  }
910  err = upf_accel_volume_quota_parse(volume_quota, upf_accel_urr);
911  if (err != DOCA_SUCCESS)
912  goto err_far;
913 
914  DOCA_LOG_INFO("Parsed URR id=%u volume_quota_total_volume=%lu\n",
915  upf_accel_urr->id,
917  }
918 
919  cfg->urrs = urrs;
920  return DOCA_SUCCESS;
921 
922 err_far:
923  rte_free(urrs);
924  return err;
925 }
926 
927 /*
928  * Cleanup items were created by upf_accel_urr_parse
929  *
930  * @cfg [out]: UPF Acceleration configuration
931  */
933 {
934  rte_free(cfg->urrs);
935  cfg->urrs = NULL;
936 }
937 
938 /*
939  * Parse MBR group
940  *
941  * @mbr [in]: json object of the group
942  * @upf_accel_qer [out]: pointer to store the result at
943  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
944  */
945 static doca_error_t upf_accel_mbr_parse(struct json_object *mbr, struct upf_accel_qer *upf_accel_qer)
946 {
949  return DOCA_ERROR_UNEXPECTED;
950 
951  return DOCA_SUCCESS;
952 }
953 
954 /*
955  * Parse list of CreateQER nodes from json
956  *
957  * @qer_arr [in]: list of CreaeQER json nodes
958  * @cfg [out]: the result is stored inside cfg
959  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
960  */
961 static doca_error_t upf_accel_qer_parse(struct json_object *qer_arr, struct upf_accel_config *cfg)
962 {
963  struct json_object *mbr;
964  struct json_object *qer;
966  struct upf_accel_qers *qers;
967  doca_error_t err;
968  size_t num_qers;
969  size_t i;
970 
971  num_qers = json_object_array_length(qer_arr);
972  qers = rte_zmalloc("UPF QERs", sizeof(*qers) + sizeof(qers->arr_qers[0]) * num_qers, RTE_CACHE_LINE_SIZE);
973  if (!qers) {
974  DOCA_LOG_ERR("Failed to allocate QER memory");
975  return DOCA_ERROR_NO_MEMORY;
976  }
977  qers->num_qers = num_qers;
979  DOCA_LOG_ERR("Max Supported Meters Tables Num is: %lu", UPF_ACCEL_MAX_PDR_NUM_RATE_METERS);
981  goto err_far;
982  }
983 
984  for (i = 0; i < num_qers; i++) {
985  qer = json_object_array_get_idx(qer_arr, i);
986  upf_accel_qer = &qers->arr_qers[i];
987  if (!qer) {
988  DOCA_LOG_ERR("Failed to parse JSON QER object id %lu", i);
989  err = DOCA_ERROR_UNEXPECTED;
990  goto err_far;
991  }
992  DOCA_LOG_DBG("QER:\n%s", json_object_to_json_string_ext(qer, JSON_C_TO_STRING_PRETTY));
993 
994  if (upf_accel_json_u32_parse(qer, "qerId", &upf_accel_qer->id) != DOCA_SUCCESS ||
996  err = DOCA_ERROR_UNEXPECTED;
997  goto err_far;
998  }
999 
1000  if (!json_object_object_get_ex(qer, "maxBitRate", &mbr)) {
1001  DOCA_LOG_ERR("Failed to parse JSON QER mbr child object");
1002  err = DOCA_ERROR_UNEXPECTED;
1003  goto err_far;
1004  }
1005  err = upf_accel_mbr_parse(mbr, upf_accel_qer);
1006  if (err != DOCA_SUCCESS)
1007  goto err_far;
1008 
1009  DOCA_LOG_INFO("Parsed QER id=%u\n"
1010  "\tqfi=%hhu\n"
1011  "\tMBR dl=%lu ul=%lu\n",
1012  upf_accel_qer->id,
1013  upf_accel_qer->qfi,
1016  }
1017 
1018  cfg->qers = qers;
1019  return DOCA_SUCCESS;
1020 
1021 err_far:
1022  rte_free(qers);
1023  return err;
1024 }
1025 
1026 /*
1027  * Cleanup items were created by upf_accel_qer_parse
1028  *
1029  * @cfg [out]: UPF Acceleration configuration
1030  */
1032 {
1033  rte_free(cfg->qers);
1034  cfg->qers = NULL;
1035 }
1036 
1037 /*
1038  * Parse SMF input
1039  *
1040  * @cfg [out]: UPF Acceleration configuration
1041  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
1042  */
1044 {
1045  struct json_object *pdr_arr;
1046  struct json_object *far_arr;
1047  struct json_object *urr_arr;
1048  struct json_object *qer_arr;
1049  struct json_object *root;
1050  doca_error_t err;
1051 
1052  root = json_object_from_file(cfg->smf_config_file_path);
1053  if (!root) {
1054  DOCA_LOG_ERR("Failed to parse JSON SMF config: %s", cfg->smf_config_file_path);
1055  return DOCA_ERROR_IO_FAILED;
1056  }
1057 
1058  if (!json_object_object_get_ex(root, "createPdr", &pdr_arr) ||
1059  json_object_get_type(pdr_arr) != json_type_array) {
1060  DOCA_LOG_ERR("Failed to parse JSON PDR array");
1061  err = DOCA_ERROR_EMPTY;
1062  goto err_json;
1063  }
1064 
1065  if (!json_object_object_get_ex(root, "createFar", &far_arr) ||
1066  json_object_get_type(far_arr) != json_type_array) {
1067  DOCA_LOG_ERR("Failed to parse JSON FAR array");
1068  err = DOCA_ERROR_EMPTY;
1069  goto err_json;
1070  }
1071 
1072  if (!json_object_object_get_ex(root, "createUrr", &urr_arr) ||
1073  json_object_get_type(urr_arr) != json_type_array) {
1074  DOCA_LOG_ERR("Failed to parse JSON URR array");
1075  err = DOCA_ERROR_EMPTY;
1076  goto err_json;
1077  }
1078 
1079  if (!json_object_object_get_ex(root, "createQer", &qer_arr) ||
1080  json_object_get_type(qer_arr) != json_type_array) {
1081  DOCA_LOG_ERR("Failed to parse JSON QER array");
1082  err = DOCA_ERROR_EMPTY;
1083  goto err_json;
1084  }
1085 
1086  err = upf_accel_pdr_parse(pdr_arr, cfg);
1087  if (err != DOCA_SUCCESS)
1088  goto err_json;
1089 
1090  err = upf_accel_far_parse(far_arr, cfg);
1091  if (err != DOCA_SUCCESS)
1092  goto err_pdr;
1093 
1094  err = upf_accel_urr_parse(urr_arr, cfg);
1095  if (err != DOCA_SUCCESS)
1096  goto err_far;
1097 
1098  err = upf_accel_qer_parse(qer_arr, cfg);
1099  if (err != DOCA_SUCCESS)
1100  goto err_urr;
1101 
1102  json_object_put(root);
1103  return DOCA_SUCCESS;
1104 
1105 err_urr:
1107 err_far:
1109 err_pdr:
1111 err_json:
1112  json_object_put(root);
1113  return err;
1114 }
1115 
1116 /*
1117  * Cleanup items were created by upf_accel_smf_parse
1118  *
1119  * @cfg [out]: UPF Acceleration configuration
1120  */
1122 {
1127 }
1128 
1129 /*
1130  * Parse list of CreateVXLAN nodes from json
1131  *
1132  * @vxlan_arr [in]: list of CreaeVXLAN json nodes
1133  * @cfg [out]: the result is stored inside cfg
1134  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
1135  */
1136 static doca_error_t upf_accel_vxlan_arr_parse(struct json_object *vxlan_arr, struct upf_accel_config *cfg)
1137 {
1139  struct upf_accel_vxlans *vxlans;
1140  struct json_object *vxlan;
1141  size_t num_vxlans;
1142  doca_error_t err;
1143  size_t i;
1144 
1145  num_vxlans = json_object_array_length(vxlan_arr);
1146  vxlans = rte_zmalloc("UPF VXLANs",
1147  sizeof(*vxlans) + sizeof(vxlans->arr_vxlans[0]) * num_vxlans,
1148  RTE_CACHE_LINE_SIZE);
1149  if (!vxlans) {
1150  DOCA_LOG_ERR("Failed to allocate VXLAN memory");
1151  return DOCA_ERROR_NO_MEMORY;
1152  }
1153  vxlans->num_vxlans = num_vxlans;
1154 
1155  for (i = 0; i < num_vxlans; i++) {
1156  vxlan = json_object_array_get_idx(vxlan_arr, i);
1157  upf_accel_vxlan = &vxlans->arr_vxlans[i];
1158  if (!vxlan) {
1159  DOCA_LOG_ERR("Failed to parse JSON VXLAN object id %lu", i);
1160  err = DOCA_ERROR_UNEXPECTED;
1161  goto err_vxlan;
1162  }
1163  DOCA_LOG_DBG("VXLAN:\n%s", json_object_to_json_string_ext(vxlan, JSON_C_TO_STRING_PRETTY));
1164 
1165  if (upf_accel_json_u32_parse(vxlan, "vxlanId", &upf_accel_vxlan->id) != DOCA_SUCCESS) {
1166  err = DOCA_ERROR_UNEXPECTED;
1167  goto err_vxlan;
1168  }
1169 
1170  if (upf_accel_json_u32_parse(vxlan, "vni", &upf_accel_vxlan->vni) != DOCA_SUCCESS) {
1171  err = DOCA_ERROR_UNEXPECTED;
1172  goto err_vxlan;
1173  }
1174 
1176  err = DOCA_ERROR_UNEXPECTED;
1177  goto err_vxlan;
1178  }
1179 
1180  DOCA_LOG_INFO("Parsed VXLAN id=%u:\n"
1181  "\tMAC=%hhu:%hhu:%hhu:%hhu:%hhu:%hhu\n"
1182  "\tVNI=%u\n",
1184  upf_accel_vxlan->mac[0],
1185  upf_accel_vxlan->mac[1],
1186  upf_accel_vxlan->mac[2],
1187  upf_accel_vxlan->mac[3],
1188  upf_accel_vxlan->mac[4],
1189  upf_accel_vxlan->mac[5],
1190  upf_accel_vxlan->vni);
1191  }
1192 
1193  cfg->vxlans = vxlans;
1194  return DOCA_SUCCESS;
1195 
1196 err_vxlan:
1197  rte_free(vxlans);
1198  return err;
1199 }
1200 
1201 /*
1202  * Cleanup items created by upf_accel_vxlan_arr_parse
1203  *
1204  * @cfg [out]: UPF Acceleration configuration
1205  */
1207 {
1208  rte_free(cfg->vxlans);
1209  cfg->vxlans = NULL;
1210 }
1211 
1212 /*
1213  * Parse VXLAN input
1214  *
1215  * @cfg [out]: UPF Acceleration configuration
1216  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
1217  */
1219 {
1220  struct json_object *vxlan_arr;
1221  struct json_object *root;
1222  doca_error_t err;
1223 
1224  root = json_object_from_file(cfg->vxlan_config_file_path);
1225  if (!root) {
1226  DOCA_LOG_ERR("Failed to parse JSON VXLAN config: %s", cfg->vxlan_config_file_path);
1227  return DOCA_ERROR_IO_FAILED;
1228  }
1229 
1230  if (!json_object_object_get_ex(root, "CreateVXLAN", &vxlan_arr) ||
1231  json_object_get_type(vxlan_arr) != json_type_array) {
1232  DOCA_LOG_ERR("Failed to parse JSON VXLAN array");
1233  err = DOCA_ERROR_EMPTY;
1234  goto err_json;
1235  }
1236 
1237  err = upf_accel_vxlan_arr_parse(vxlan_arr, cfg);
1238  if (err != DOCA_SUCCESS)
1239  goto err_json;
1240 
1241  json_object_put(root);
1242  return DOCA_SUCCESS;
1243 
1244 err_json:
1245  json_object_put(root);
1246  return err;
1247 }
1248 
1249 /*
1250  * Cleanup items created by upf_accel_vxlan_parse
1251  *
1252  * @cfg [out]: UPF Acceleration configuration
1253  */
1255 {
1257 }
#define NULL
Definition: __stddef_null.h:26
enum doca_error doca_error_t
DOCA API return codes.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_TOO_BIG
Definition: doca_error.h:65
@ DOCA_ERROR_UNEXPECTED
Definition: doca_error.h:60
@ DOCA_ERROR_IO_FAILED
Definition: doca_error.h:55
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
@ DOCA_ERROR_EMPTY
Definition: doca_error.h:63
#define DOCA_FLOW_ETHER_ADDR_LEN
Definition: doca_flow_net.h:36
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
Definition: doca_log.h:496
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
rte_ipv6_hdr ip
Definition: psp_gw_flows.cpp:4
uint32_t fp_oh_teid
Definition: upf_accel.h:217
uint32_t id
Definition: upf_accel.h:215
struct upf_accel_ip_addr fp_oh_ip
Definition: upf_accel.h:216
struct upf_accel_far arr_fars[]
Definition: upf_accel.h:222
size_t num_fars
Definition: upf_accel.h:221
uint32_t qerids[UPF_ACCEL_PDR_QERIDS_LEN]
Definition: upf_accel.h:195
struct upf_accel_ip_addr pdi_sdf_to_ip
Definition: upf_accel.h:205
uint32_t urrids_num
Definition: upf_accel.h:192
uint8_t pdi_qfi
Definition: upf_accel.h:202
uint16_t pdi_sdf_proto
Definition: upf_accel.h:201
struct upf_accel_ip_addr pdi_local_teid_ip
Definition: upf_accel.h:199
struct upf_accel_ip_addr pdi_sdf_from_ip
Definition: upf_accel.h:203
uint32_t qerids_num
Definition: upf_accel.h:194
uint32_t pdi_local_teid_start
Definition: upf_accel.h:197
uint32_t pdi_local_teid_end
Definition: upf_accel.h:198
struct upf_accel_ip_addr pdi_ueip
Definition: upf_accel.h:200
uint32_t urrids[UPF_ACCEL_PDR_URRIDS_LEN]
Definition: upf_accel.h:193
struct upf_accel_ip_port_range pdi_sdf_from_port_range
Definition: upf_accel.h:204
enum upf_accel_pdr_pdi_si pdi_si
Definition: upf_accel.h:196
struct upf_accel_ip_port_range pdi_sdf_to_port_range
Definition: upf_accel.h:206
uint32_t farid
Definition: upf_accel.h:191
uint32_t id
Definition: upf_accel.h:190
struct upf_accel_pdr arr_pdrs[]
Definition: upf_accel.h:211
size_t num_pdrs
Definition: upf_accel.h:210
uint32_t id
Definition: upf_accel.h:236
uint8_t qfi
Definition: upf_accel.h:237
uint64_t mbr_dl_mbr
Definition: upf_accel.h:238
uint64_t mbr_ul_mbr
Definition: upf_accel.h:239
size_t num_qers
Definition: upf_accel.h:243
struct upf_accel_qer arr_qers[]
Definition: upf_accel.h:244
uint64_t volume_quota_total_volume
Definition: upf_accel.h:227
uint32_t id
Definition: upf_accel.h:226
size_t num_urrs
Definition: upf_accel.h:231
struct upf_accel_urr arr_urrs[]
Definition: upf_accel.h:232
uint32_t vni
Definition: upf_accel.h:249
uint32_t id
Definition: upf_accel.h:248
uint8_t mac[DOCA_FLOW_ETHER_ADDR_LEN]
Definition: upf_accel.h:250
size_t num_vxlans
Definition: upf_accel.h:254
struct upf_accel_vxlan arr_vxlans[]
Definition: upf_accel.h:255
#define UPF_ACCEL_PDR_URRIDS_LEN
Definition: upf_accel.h:50
#define UPF_ACCEL_PDR_QERIDS_LEN
Definition: upf_accel.h:51
#define UPF_ACCEL_MAX_PDR_NUM_RATE_METERS
Definition: upf_accel.h:71
#define UPF_ACCEL_MAX_NUM_PDR
Definition: upf_accel.h:54
@ UPF_ACCEL_PDR_PDI_SI_DL
Definition: upf_accel.h:104
@ UPF_ACCEL_PDR_PDI_SI_UL
Definition: upf_accel.h:103
static void upf_accel_far_cleanup(struct upf_accel_config *cfg)
static doca_error_t upf_accel_json_u32_parse(struct json_object *container, const char *name, uint32_t *val)
void upf_accel_vxlan_cleanup(struct upf_accel_config *cfg)
static void upf_accel_qer_cleanup(struct upf_accel_config *cfg)
doca_error_t upf_accel_vxlan_parse(struct upf_accel_config *cfg)
static void upf_accel_vxlan_arr_cleanup(struct upf_accel_config *cfg)
static doca_error_t upf_accel_sdf_parse(struct json_object *sdf_arr, struct upf_accel_pdr *upf_accel_pdr)
static doca_error_t upf_accel_json_u64_from_string_parse(struct json_object *container, const char *name, uint64_t *val)
static doca_error_t upf_accel_volume_quota_parse(struct json_object *volume_quota, struct upf_accel_urr *upf_accel_urr)
static doca_error_t upf_accel_json_u32_arr_parse(struct json_object *container, const char *name, size_t val_size, uint32_t *val, uint32_t *val_num)
static doca_error_t upf_accel_json_ip_parse(struct json_object *container, const char *name, struct upf_accel_ip_addr *val)
static doca_error_t upf_accel_oh_parse(struct json_object *oh, struct upf_accel_far *upf_accel_far)
static doca_error_t upf_accel_json_u8_parse(struct json_object *container, const char *name, uint8_t *val)
static doca_error_t upf_accel_qer_parse(struct json_object *qer_arr, struct upf_accel_config *cfg)
static doca_error_t upf_accel_str_to_proto_parse(const char *str_proto, uint16_t *val)
static doca_error_t upf_accel_str_to_ip_netmask_parse(const char *str_addr, struct upf_accel_ip_addr *val)
static void upf_accel_urr_cleanup(struct upf_accel_config *cfg)
static doca_error_t upf_accel_urr_parse(struct json_object *urr_arr, struct upf_accel_config *cfg)
static doca_error_t upf_accel_local_fteid_parse(struct json_object *local_fteid, struct upf_accel_pdr *upf_accel_pdr)
void upf_accel_smf_cleanup(struct upf_accel_config *cfg)
DOCA_LOG_REGISTER(UPF_ACCEL::JSON_PARSER)
static void upf_accel_pdr_cleanup(struct upf_accel_config *cfg)
static doca_error_t upf_accel_json_string_parse(struct json_object *container, const char *name, char *val, size_t val_len)
static doca_error_t upf_accel_pdr_parse(struct json_object *pdr_arr, struct upf_accel_config *cfg)
static doca_error_t upf_accel_json_u64_parse(struct json_object *container, const char *name, uint64_t *val)
static doca_error_t upf_accel_mbr_parse(struct json_object *mbr, struct upf_accel_qer *upf_accel_qer)
static doca_error_t upf_accel_far_parse(struct json_object *far_arr, struct upf_accel_config *cfg)
static doca_error_t upf_accel_fp_parse(struct json_object *fp, struct upf_accel_far *upf_accel_far)
doca_error_t upf_accel_smf_parse(struct upf_accel_config *cfg)
static doca_error_t upf_accel_vxlan_arr_parse(struct json_object *vxlan_arr, struct upf_accel_config *cfg)
static doca_error_t upf_accel_str_to_port_range_parse(const char *str_port, struct upf_accel_ip_port_range *val)
static doca_error_t upf_accel_json_u8_from_string_parse(struct json_object *container, const char *name, uint8_t *val)
static doca_error_t upf_accel_ue_parse(struct json_object *ue, struct upf_accel_pdr *upf_accel_pdr)
static doca_error_t upf_accel_json_mac_from_string_parse(struct json_object *container, const char *name, uint8_t val[DOCA_FLOW_ETHER_ADDR_LEN])
static doca_error_t upf_accel_pdi_parse(struct json_object *pdi, struct upf_accel_pdr *upf_accel_pdr)