blob: 038ad74ac0e3d10f254187ea0fcdc46338e1ecca [file] [log] [blame]
Ole Troandf87f802020-11-18 19:17:48 +01001/*
2 * Copyright (c) 2020 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef included_json_convert_h
17#define included_json_convert_h
18
19#include <stdbool.h>
20#include <vppinfra/cJSON.h>
21#include <vnet/ethernet/mac_address.h>
22#include <vnet/ip/ip6_packet.h>
23#include <vnet/ip/ip_types.api_types.h>
24#include <vnet/ethernet/ethernet_types.api_types.h>
25
26#define foreach_vat2_fromjson \
27 _(i8) \
28 _(u8) \
29 _(i16) \
30 _(u16) \
31 _(i32) \
32 _(u32) \
33 _(u64) \
34 _(f64)
35
36#define _(T) \
37 int vl_api_ ##T## _fromjson(cJSON *o, T *d);
Ole Troan71134f22021-02-17 14:10:04 +010038foreach_vat2_fromjson
Ole Troandf87f802020-11-18 19:17:48 +010039#undef _
40
Ole Troan71134f22021-02-17 14:10:04 +010041 /* Prototypes */
42 int
43 vl_api_bool_fromjson (cJSON *o, bool *d);
44int vl_api_ip4_address_t_fromjson (void **mp, int *len, cJSON *o,
45 vl_api_ip4_address_t *a);
46int vl_api_ip4_prefix_t_fromjson (void **mp, int *len, cJSON *o,
47 vl_api_ip4_prefix_t *a);
48int vl_api_ip4_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o,
49 vl_api_ip4_prefix_t *a);
50int vl_api_ip6_address_t_fromjson (void **mp, int *len, cJSON *o,
51 vl_api_ip6_address_t *a);
52int vl_api_ip6_prefix_t_fromjson (void **mp, int *len, cJSON *o,
53 vl_api_ip6_prefix_t *a);
54int vl_api_ip6_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o,
55 vl_api_ip6_prefix_t *a);
56int vl_api_address_t_fromjson (void **mp, int *len, cJSON *o,
57 vl_api_address_t *a);
58int vl_api_prefix_t_fromjson (void **mp, int *len, cJSON *o,
59 vl_api_prefix_t *a);
60int vl_api_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o,
61 vl_api_prefix_t *a);
62int vl_api_mac_address_t_fromjson (void **mp, int *len, cJSON *o,
63 vl_api_mac_address_t *a);
Ole Troandf87f802020-11-18 19:17:48 +010064
Ole Troan71134f22021-02-17 14:10:04 +010065uword unformat_ip4_address (unformat_input_t *input, va_list *args);
66uword unformat_ip6_address (unformat_input_t *input, va_list *args);
67u8 *format_ip6_address (u8 *s, va_list *args);
68uword unformat_mac_address (unformat_input_t *input, va_list *args);
69u8 *format_ip4_address (u8 *s, va_list *args);
70u8 *format_vl_api_interface_index_t (u8 *s, va_list *args);
71u8 *format_vl_api_timestamp_t (u8 *s, va_list *args);
72u8 *format_vl_api_timedelta_t (u8 *s, va_list *args);
73uword unformat_vl_api_timedelta_t (unformat_input_t *input, va_list *args);
74uword unformat_vl_api_timestamp_t (unformat_input_t *input, va_list *args);
75u8 *format_vl_api_gbp_scope_t (u8 *s, va_list *args);
76uword unformat_vl_api_gbp_scope_t (unformat_input_t *input, va_list *args);
Ole Troandf87f802020-11-18 19:17:48 +010077
Ole Troan71134f22021-02-17 14:10:04 +010078int vl_api_c_string_to_api_string (const char *buf, vl_api_string_t *str);
79void vl_api_string_cJSON_AddToObject (cJSON *const object,
80 const char *const name,
81 vl_api_string_t *astr);
Ole Troandf87f802020-11-18 19:17:48 +010082
Ole Troan71134f22021-02-17 14:10:04 +010083u8 *u8string_fromjson (cJSON *o, char *fieldname);
84int u8string_fromjson2 (cJSON *o, char *fieldname, u8 *data);
85int vl_api_u8_string_fromjson (cJSON *o, u8 *s, int len);
Ole Troandf87f802020-11-18 19:17:48 +010086
87#define foreach_vat2_tojson \
88 _(ip4_address) \
89 _(ip4_prefix) \
90 _(ip6_address) \
91 _(ip6_prefix) \
92 _(address) \
93 _(prefix) \
94 _(mac_address)
95
96#define _(T) \
97 cJSON *vl_api_ ##T## _t_tojson(vl_api_ ##T## _t *);
98 foreach_vat2_tojson
99#undef _
100
101cJSON *vl_api_ip4_address_with_prefix_t_tojson (vl_api_ip4_prefix_t *a);
102cJSON *vl_api_ip6_address_with_prefix_t_tojson (vl_api_ip6_prefix_t *a);
103cJSON *vl_api_address_with_prefix_t_tojson (vl_api_prefix_t *a);
104
105#endif