summaryrefslogtreecommitdiffstats
path: root/src/tools/vppapigen
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-05-20 16:01:22 +0200
committerOle Tr�an <otroan@employees.org>2022-09-26 08:14:29 +0000
commitfe45f8f5afbf34d68cf992cc32b12432a82cdb38 (patch)
treeae8126e78d184022ef97007e64ac1f3350537a40 /src/tools/vppapigen
parentb70497124840fb6d9e8e5cf7239a41cb2bc7013c (diff)
api: replace print functions wth format
Type: improvement Change-Id: I7f7050c19453a69a7fb6c5e62f8f57db847d9144 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/tools/vppapigen')
-rw-r--r--src/tools/vppapigen/vppapigen_c.py48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py
index a065653e391..b9f9e070e4a 100644
--- a/src/tools/vppapigen/vppapigen_c.py
+++ b/src/tools/vppapigen/vppapigen_c.py
@@ -1028,9 +1028,9 @@ def printfun(objs, stream, modulename):
"""
signature = """\
-static inline void *vl_api_{name}_t_print{suffix} (vl_api_{name}_t *a, void *handle)
+static inline u8 *vl_api_{name}_t_format (u8 *s, va_list *args)
{{
- u8 *s = 0;
+ __attribute__((unused)) vl_api_{name}_t *a = va_arg (*args, vl_api_{name}_t *);
u32 indent __attribute__((unused)) = 2;
int i __attribute__((unused));
"""
@@ -1041,27 +1041,14 @@ static inline void *vl_api_{name}_t_print{suffix} (vl_api_{name}_t *a, void *han
pp = Printfun(stream)
for t in objs:
if t.manual_print:
- write("/***** manual: vl_api_%s_t_print *****/\n\n" % t.name)
+ write("/***** manual: vl_api_%s_t_format *****/\n\n" % t.name)
continue
write(signature.format(name=t.name, suffix=""))
write(" /* Message definition: vl_api_{}_t: */\n".format(t.name))
write(' s = format(s, "vl_api_%s_t:");\n' % t.name)
for o in t.block:
pp.print_obj(o, stream)
- write(" vec_add1(s, 0);\n")
- write(" vl_print (handle, (char *)s);\n")
- write(" vec_free (s);\n")
- write(" return handle;\n")
- write("}\n\n")
-
- write(signature.format(name=t.name, suffix="_json"))
- write(" cJSON * o = vl_api_{}_t_tojson(a);\n".format(t.name))
- write(" (void)s;\n")
- write(" char *out = cJSON_Print(o);\n")
- write(" vl_print(handle, out);\n")
- write(" cJSON_Delete(o);\n")
- write(" cJSON_free(out);\n")
- write(" return handle;\n")
+ write(" return s;\n")
write("}\n\n")
write("\n#endif")
@@ -1103,7 +1090,7 @@ static inline u8 *format_vl_api_{name}_t (u8 *s, va_list * args)
continue
if t.manual_print:
- write("/***** manual: vl_api_%s_t_print *****/\n\n" % t.name)
+ write("/***** manual: vl_api_%s_t_format *****/\n\n" % t.name)
continue
if t.__class__.__name__ == "Using":
@@ -1525,7 +1512,6 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
#undef vl_calsizefun
/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include "{module}.api.h"
#undef vl_printfun
@@ -1556,12 +1542,10 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
" {{.id = VL_API_{ID} + msg_id_base,\n"
' .name = "{n}",\n'
" .handler = vl_api_{n}_t_handler,\n"
- " .cleanup = vl_noop_handler,\n"
" .endian = vl_api_{n}_t_endian,\n"
- " .print = vl_api_{n}_t_print,\n"
+ " .format_fn = vl_api_{n}_t_format,\n"
" .traced = 1,\n"
" .replay = 1,\n"
- " .print_json = vl_api_{n}_t_print_json,\n"
" .tojson = vl_api_{n}_t_tojson,\n"
" .fromjson = vl_api_{n}_t_fromjson,\n"
" .calc_size = vl_api_{n}_t_calc_size,\n"
@@ -1577,12 +1561,10 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
"{{.id = VL_API_{ID} + msg_id_base,\n"
' .name = "{n}",\n'
" .handler = 0,\n"
- " .cleanup = vl_noop_handler,\n"
" .endian = vl_api_{n}_t_endian,\n"
- " .print = vl_api_{n}_t_print,\n"
+ " .format_fn = vl_api_{n}_t_format,\n"
" .traced = 1,\n"
" .replay = 1,\n"
- " .print_json = vl_api_{n}_t_print_json,\n"
" .tojson = vl_api_{n}_t_tojson,\n"
" .fromjson = vl_api_{n}_t_fromjson,\n"
" .calc_size = vl_api_{n}_t_calc_size,\n"
@@ -1631,7 +1613,6 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
#undef vl_calsizefun
/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include "{module}.api.h"
#undef vl_printfun
@@ -1678,8 +1659,10 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
continue
write("static void\n")
write("vl_api_{n}_t_handler (vl_api_{n}_t * mp) {{\n".format(n=e))
- write(' vl_print(0, "{n} event called:");\n'.format(n=e))
- write(" vl_api_{n}_t_print(mp, 0);\n".format(n=e))
+ write(' vlib_cli_output(0, "{n} event called:");\n'.format(n=e))
+ write(
+ ' vlib_cli_output(0, "%U", vl_api_{n}_t_format, mp);\n'.format(n=e)
+ )
write("}\n")
write("static void\n")
@@ -1689,11 +1672,9 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
" vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
' "{n}",\n'
" vl_api_{n}_t_handler, "
- " vl_noop_handler,\n"
" vl_api_{n}_t_endian, "
- " vl_api_{n}_t_print,\n"
+ " vl_api_{n}_t_format,\n"
" sizeof(vl_api_{n}_t), 1,\n"
- " vl_api_{n}_t_print_json,\n"
" vl_api_{n}_t_tojson,\n"
" vl_api_{n}_t_fromjson,\n"
" vl_api_{n}_t_calc_size);\n".format(
@@ -1720,11 +1701,9 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
" vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
' "{n}",\n'
" vl_api_{n}_t_handler, "
- " vl_noop_handler,\n"
" vl_api_{n}_t_endian, "
- " vl_api_{n}_t_print,\n"
+ " vl_api_{n}_t_format,\n"
" sizeof(vl_api_{n}_t), 1,\n"
- " vl_api_{n}_t_print_json,\n"
" vl_api_{n}_t_tojson,\n"
" vl_api_{n}_t_fromjson,\n"
" vl_api_{n}_t_calc_size);\n".format(
@@ -1968,7 +1947,6 @@ def generate_c_test2_boilerplate(services, defines, module, stream):
#include "{module}.api.h"
#undef vl_calsizefun
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include "{module}.api.h"
#undef vl_printfun
n> * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define foreach_gre_protocol \ _ (0x0800, ip4) \ _ (0x86DD, ip6) \ _ (0x6558, teb) \ _ (0x0806, arp) \ _ (0x8847, mpls_unicast) \ _ (0x88BE, erspan) \ _ (0x894F, nsh) typedef enum { #define _(n,f) GRE_PROTOCOL_##f = n, foreach_gre_protocol #undef _ } gre_protocol_t; typedef struct { /* flags and version */ u16 flags_and_version; /* unimplemented at the moment */ #define GRE_FLAGS_CHECKSUM (1 << 15) /* deprecated, according to rfc2784 */ #define GRE_FLAGS_ROUTING (1 << 14) #define GRE_FLAGS_KEY (1 << 13) #define GRE_FLAGS_SEQUENCE (1 << 12) #define GRE_FLAGS_STRICT_SOURCE_ROUTE (1 << 11) /* version 1 is PPTP which we don't support */ #define GRE_SUPPORTED_VERSION 0 #define GRE_VERSION_MASK 0x7 /* 0x800 for ip4, etc. */ u16 protocol; } gre_header_t; /* From draft-foschiano-erspan-03.txt Different frame variants known as "ERSPAN Types" can be distinguished based on the GRE "Protocol Type" field value: Type I and II's value is 0x88BE while Type III's is 0x22EB [ETYPES]. GRE header for ERSPAN Type II encapsulation (8 octets [34:41]) 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|0|0|1|0|00000|000000000|00000| Protocol Type for ERSPAN | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number (increments per packet per session) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Note that in the above GRE header [RFC1701] out of the C, R, K, S, s, Recur, Flags, Version fields only S (bit 03) may be set to 1. The other fields are always set to zero. ERSPAN Type II's frame format also adds a special 8-octet ERSPAN "feature" header on top of the MAC/IPv4/GRE headers to enclose the raw mirrored frames. The ERSPAN Type II feature header is described below: ERSPAN Type II header (8 octets [42:49]) 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Ver | VLAN | COS | En|T| Session ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reserved | Index | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The various fields of the above header are described in this table: Field Position Length Definition [octet:bit] (bits) Ver [42:0] 4 ERSPAN Encapsulation version. This indicates the version of the ERSPAN encapsulation specification. Set to 0x1 for Type II. VLAN [42:4] 12 Original VLAN of the frame, mirrored from the source. If the En field is set to 11, the value of VLAN is undefined. COS [44:0] 3 Original class of service of the frame, mirrored from the source. En [44:3] 2 The trunk encapsulation type associated with the ERSPAN source port for ingress ERSPAN traffic. The possible values are: 00-originally without VLAN tag 01-originally ISL encapsulated 10-originally 802.1Q encapsulated 11-VLAN tag preserved in frame. T [44:5] 1 This bit indicates that the frame copy encapsulated in the ERSPAN packet has been truncated. This occurs if the ERSPAN encapsulated frame exceeds the configured MTU. Session ID [44:6] 10 Identification associated with (ERSPAN ID) each ERSPAN session. Must be unique between the source and the receiver(s). (See section below.) Reserved [46:0] 12 All bits are set to zero Index [47:4] 20 A 20 bit index/port number associated with the ERSPAN traffic's port and direction (ingress/egress). N.B.: This field is platform dependent. */ /* *INDENT-OFF* */ typedef CLIB_PACKED (struct { u32 seq_num; union { struct { u16 ver_vlan; u16 cos_en_t_session; u32 res_index; } t2; u64 t2_u64; }; }) erspan_t2_t; typedef CLIB_PACKED (struct { gre_header_t gre; erspan_t2_t erspan; }) erspan_t2_header_t; /* *INDENT-ON* */ /* u64 template for ERSPAN type 2 header with both EN bits set */ #define ERSPAN_HDR2 0x1000180000000000ul #endif /* included_vnet_gre_packet_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */