summaryrefslogtreecommitdiffstats
path: root/src/tools/vppapigen
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2020-11-18 19:17:48 +0100
committerNeale Ranns <nranns@cisco.com>2020-11-25 08:25:50 +0000
commitdf87f8092f5b6b54eef0d5acf3c27c2e398a401a (patch)
tree762a3da5d6757c6f475ffce6dcfae2b65b2c3850 /src/tools/vppapigen
parentc95cfa218b214bd1c67dc165b4ed1fb7a224bdad (diff)
api: vat2 and json autogeneration for api messages
VAT2: A completely auto-generated replacement of VAT. Reads input message in JSON from stdin and outputs received messages in JSON. A VAT2 plugin is automatically built for a .api file. There no longer a need for a separate _test.c. Example: vat2 show_version {} { "_msgname": "show_version_reply", "retval": 0, "program": "vpe", "version": "21.01-rc0~411-gf6eb348a6", "build_date": "2020-11-19T09:49:25", "build_directory": "/vpp/autogen3" } vat2 sw_interface_dump '{"sw_if_index": -1, "name_filter_valid": 0, "name_filter": ""}' [{ "_msgname": "sw_interface_details", "sw_if_index": 0, "sup_sw_if_index": 0, "l2_address": "00:00:00:00:00:00", "flags": "Invalid ENUM", "type": "IF_API_TYPE_HARDWARE", "link_duplex": "LINK_DUPLEX_API_UNKNOWN", "link_speed": 0, "link_mtu": 0, "mtu": [0, 0, 0, 0], "sub_id": 0, "sub_number_of_tags": 0, "sub_outer_vlan_id": 0, "sub_inner_vlan_id": 0, "sub_if_flags": "Invalid ENUM", "vtr_op": 0, "vtr_push_dot1q": 0, "vtr_tag1": 0, "vtr_tag2": 0, "outer_tag": 0, "b_dmac": "00:00:00:00:00:00", "b_smac": "00:00:00:00:00:00", "b_vlanid": 0, "i_sid": 0, "interface_name": "local0", "interface_dev_type": "local", "tag": "" }] This is the first phase and vat2 is not integrated in packaging yet. Type: feature Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: Ib45ddeafb180ea7da8c5dc274a9274d7a4edc876 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/tools/vppapigen')
-rwxr-xr-xsrc/tools/vppapigen/vppapigen.py662
-rw-r--r--src/tools/vppapigen/vppapigen_c.py1126
2 files changed, 1345 insertions, 443 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py
index b828706f814..da008231a32 100755
--- a/src/tools/vppapigen/vppapigen.py
+++ b/src/tools/vppapigen/vppapigen.py
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
-import ply.lex as lex
-import ply.yacc as yacc
import sys
import argparse
import keyword
@@ -9,6 +7,8 @@ import logging
import binascii
import os
from subprocess import Popen, PIPE
+import ply.lex as lex
+import ply.yacc as yacc
assert sys.version_info >= (3, 5), \
"Not supported Python version: {}".format(sys.version)
@@ -147,6 +147,14 @@ class VPPAPILexer(object):
t_ignore = ' \t'
+def vla_mark_length_field(block):
+ if isinstance(block[-1], Array):
+ lengthfield = block[-1].lengthfield
+ for b in block:
+ if b.fieldname == lengthfield:
+ b.is_lengthfield = True
+
+
def vla_is_last_check(name, block):
vla = False
for i, b in enumerate(block):
@@ -175,7 +183,8 @@ def vla_is_last_check(name, block):
class Service():
- def __init__(self, caller, reply, events=None, stream_message=None, stream=False):
+ def __init__(self, caller, reply, events=None, stream_message=None,
+ stream=False):
self.caller = caller
self.reply = reply
self.stream = stream
@@ -186,6 +195,7 @@ class Service():
class Typedef():
def __init__(self, name, flags, block):
self.name = name
+ self.type = 'Typedef'
self.flags = flags
self.block = block
self.crc = str(block).encode()
@@ -199,6 +209,7 @@ class Typedef():
global_type_add(name, self)
self.vla = vla_is_last_check(name, block)
+ vla_mark_length_field(self.block)
def __repr__(self):
return self.name + str(self.flags) + str(self.block)
@@ -207,6 +218,7 @@ class Typedef():
class Using():
def __init__(self, name, flags, alias):
self.name = name
+ self.type = 'Using'
self.vla = False
self.block = []
self.manual_print = True
@@ -226,6 +238,8 @@ class Using():
else:
a = {'type': alias.fieldtype}
self.alias = a
+ self.using = alias
+
#
# Should have been:
# self.crc = str(alias).encode()
@@ -264,6 +278,7 @@ class Union():
class Define():
def __init__(self, name, flags, block):
self.name = name
+ self.type = 'Define'
self.flags = flags
self.block = block
self.dont_trace = False
@@ -294,6 +309,8 @@ class Define():
block = [x for x in block if x not in remove]
self.block = block
self.vla = vla_is_last_check(name, block)
+ vla_mark_length_field(self.block)
+
self.crc = str(block).encode()
def __repr__(self):
@@ -305,6 +322,8 @@ class Enum():
self.name = name
self.enumtype = enumtype
self.vla = False
+ self.type = 'Enum'
+ self.manual_print = False
count = 0
block2 = []
@@ -324,7 +343,8 @@ class Enum():
except KeyError:
block3.append([b['id'], count])
if bc_set:
- raise ValueError("Backward compatible enum must be last {!r} {!r}"
+ raise ValueError("Backward compatible enum must "
+ "be last {!r} {!r}"
.format(name, b['id']))
self.block = block2
self.crc = str(block3).encode()
@@ -335,7 +355,7 @@ class Enum():
class Import():
-
+ _initialized = False
def __new__(cls, *args, **kwargs):
if args[0] not in seen_imports:
instance = super().__new__(cls)
@@ -347,18 +367,17 @@ class Import():
def __init__(self, filename, revision):
if self._initialized:
return
- else:
- self.filename = filename
- # Deal with imports
- parser = VPPAPI(filename=filename, revision=revision)
- dirlist = dirlist_get()
- f = filename
- for dir in dirlist:
- f = os.path.join(dir, filename)
- if os.path.exists(f):
- break
- self.result = parser.parse_filename(f, None)
- self._initialized = True
+ self.filename = filename
+ # Deal with imports
+ parser = VPPAPI(filename=filename, revision=revision)
+ dirlist = dirlist_get()
+ f = filename
+ for dir in dirlist:
+ f = os.path.join(dir, filename)
+ if os.path.exists(f):
+ break
+ self.result = parser.parse_filename(f, None)
+ self._initialized = True
def __repr__(self):
return self.filename
@@ -402,6 +421,7 @@ class Field():
def __init__(self, fieldtype, name, limit=None):
self.type = 'Field'
self.fieldtype = fieldtype
+ self.is_lengthfield = False
if self.fieldtype == 'string':
raise ValueError("The string type {!r} is an "
@@ -475,8 +495,8 @@ class VPPAPIParser(object):
def _coord(self, lineno, column=None):
return Coord(
- file=self.filename,
- line=lineno, column=column)
+ file=self.filename,
+ line=lineno, column=column)
def _token_coord(self, p, token_idx):
""" Returns the coordinates for the YaccProduction object 'p' indexed
@@ -842,7 +862,7 @@ class VPPAPIParser(object):
self._parse_error('At end of input', self.filename)
-class VPPAPI(object):
+class VPPAPI():
def __init__(self, debug=False, filename='', logger=None, revision=None):
self.lexer = lex.lex(module=VPPAPILexer(filename), debug=debug)
@@ -868,11 +888,11 @@ class VPPAPI(object):
try:
data, errs = proc.communicate()
if proc.returncode != 0:
- print('File not found: {}:{}'.format(self.revision,
- filename), file=sys.stderr)
+ print('File not found: {}:{}'
+ .format(self.revision, filename), file=sys.stderr)
sys.exit(2)
return self.parse_string(data, debug=debug)
- except Exception as e:
+ except Exception:
sys.exit(3)
else:
try:
@@ -916,14 +936,11 @@ class VPPAPI(object):
for o2 in o:
if isinstance(o2, Service):
s['Service'].append(o2)
- elif (isinstance(o, Enum) or
- isinstance(o, Typedef) or
- isinstance(o, Using) or
- isinstance(o, Union)):
+ elif isinstance(o, (Enum, Typedef, Union, Using)):
s['types'].append(o)
- elif (isinstance(o, Counter)):
+ elif isinstance(o, Counter):
s['Counters'].append(o)
- elif (isinstance(o, Paths)):
+ elif isinstance(o, Paths):
s['Paths'].append(o)
else:
if tname not in s:
@@ -986,9 +1003,8 @@ class VPPAPI(object):
if d[:-8]+'_get' in msgs:
if d[:-8]+'_get' in svcs:
continue
- else:
- raise ValueError('{} should be in a stream service'
- .format(d[:-8]+'_get'))
+ raise ValueError('{} should be in a stream service'
+ .format(d[:-8]+'_get'))
if d[:-8]+'_dump' in msgs:
continue
raise ValueError('{} missing dump or get message'
@@ -1006,14 +1022,10 @@ class VPPAPI(object):
return s
def process_imports(self, objs, in_import, result):
- imported_objs = []
for o in objs:
# Only allow the following object types from imported file
- if in_import and not (isinstance(o, Enum) or
- isinstance(o, Union) or
- isinstance(o, Typedef) or
- isinstance(o, Import) or
- isinstance(o, Using)):
+ if in_import and not isinstance(o, (Enum, Import, Typedef,
+ Union, Using)):
continue
if isinstance(o, Import):
result.append(o)
@@ -1067,284 +1079,284 @@ def foldup_blocks(block, crc):
# a different result and fail the comparison.
fixup_crc_dict = {
- "abf_policy_add_del": { 0xc6131197: 0xee66f93e },
- "abf_policy_details": { 0xb7487fa4: 0x6769e504 },
- "acl_add_replace": { 0xee5c2f18: 0x1cabdeab },
- "acl_details": { 0x95babae0: 0x7a97f21c },
- "macip_acl_add": { 0xce6fbad0: 0xd648fd0a },
- "macip_acl_add_replace": { 0x2a461dd4: 0xe34402a7 },
- "macip_acl_details": { 0x27135b59: 0x57c7482f },
- "dhcp_proxy_config": { 0x4058a689: 0x6767230e },
- "dhcp_client_config": { 0x1af013ea: 0x959b80a3 },
- "dhcp_compl_event": { 0x554a44e5: 0xe908fd1d },
- "dhcp_client_details": { 0x3c5cd28a: 0xacd82f5a },
- "dhcp_proxy_details": { 0xdcbaf540: 0xce16f044 },
- "dhcp6_send_client_message": { 0xf8222476: 0xf6f14ef0 },
- "dhcp6_pd_send_client_message": { 0x3739fd8d: 0x64badb8 },
- "dhcp6_reply_event": { 0x85b7b17e: 0x9f3af9e5 },
- "dhcp6_pd_reply_event": { 0x5e878029: 0xcb3e462b },
- "ip6_add_del_address_using_prefix": { 0x3982f30a: 0x9b3d11e0 },
- "gbp_bridge_domain_add": { 0x918e8c01: 0x8454bfdf },
- "gbp_bridge_domain_details": { 0x51d51be9: 0x2acd15f9 },
- "gbp_route_domain_add": { 0x204c79e1: 0x2d0afe38 },
- "gbp_route_domain_details": { 0xa78bfbca: 0x8ab11375 },
- "gbp_endpoint_add": { 0x7b3af7de: 0x9ce16d5a },
- "gbp_endpoint_details": { 0x8dd8fbd3: 0x8aecb60 },
- "gbp_endpoint_group_add": { 0x301ddf15: 0x8e0f4054 },
- "gbp_endpoint_group_details": { 0xab71d723: 0x8f38292c },
- "gbp_subnet_add_del": { 0xa8803c80: 0x888aca35 },
- "gbp_subnet_details": { 0xcbc5ca18: 0x4ed84156 },
- "gbp_contract_add_del": { 0xaa8d652d: 0x553e275b },
- "gbp_contract_details": { 0x65dec325: 0x2a18db6e },
- "gbp_ext_itf_add_del": { 0x7606d0e1: 0x12ed5700 },
- "gbp_ext_itf_details": { 0x519c3d3c: 0x408a45c0 },
- "gtpu_add_del_tunnel": { 0xca983a2b: 0x9a9c0426 },
- "gtpu_tunnel_update_tteid": { 0x79f33816: 0x8a2db108 },
- "gtpu_tunnel_details": { 0x27f434ae: 0x4535cf95 },
- "igmp_listen": { 0x19a49f1e: 0x3f93a51a },
- "igmp_details": { 0x38f09929: 0x52f12a89 },
- "igmp_event": { 0x85fe93ec: 0xd7696eaf },
- "igmp_group_prefix_set": { 0x5b14a5ce: 0xd4f20ac5 },
- "igmp_group_prefix_details": { 0x259ccd81: 0xc3b3c526 },
- "ikev2_set_responder": { 0xb9aa4d4e: 0xf0d3dc80 },
- "vxlan_gpe_ioam_export_enable_disable": { 0xd4c76d3a: 0xe4d4ebfa },
- "ioam_export_ip6_enable_disable": { 0xd4c76d3a: 0xe4d4ebfa },
- "vxlan_gpe_ioam_vni_enable": { 0xfbb5fb1: 0x997161fb },
- "vxlan_gpe_ioam_vni_disable": { 0xfbb5fb1: 0x997161fb },
- "vxlan_gpe_ioam_transit_enable": { 0x3d3ec657: 0x553f5b7b },
- "vxlan_gpe_ioam_transit_disable": { 0x3d3ec657: 0x553f5b7b },
- "udp_ping_add_del": { 0xfa2628fc: 0xc692b188 },
- "l3xc_update": { 0xe96aabdf: 0x787b1d3 },
- "l3xc_details": { 0xbc5bf852: 0xd4f69627 },
- "sw_interface_lacp_details": { 0xd9a83d2f: 0x745ae0ba },
- "lb_conf": { 0x56cd3261: 0x22ddb739 },
- "lb_add_del_vip": { 0x6fa569c7: 0xd15b7ddc },
- "lb_add_del_as": { 0x35d72500: 0x78628987 },
- "lb_vip_dump": { 0x56110cb7: 0xc7bcb124 },
- "lb_vip_details": { 0x1329ec9b: 0x8f39bed },
- "lb_as_details": { 0x8d24c29e: 0x9c39f60e },
- "mactime_add_del_range": { 0xcb56e877: 0x101858ef },
- "mactime_details": { 0xda25b13a: 0x44921c06 },
- "map_add_domain": { 0x249f195c: 0x7a5a18c9 },
- "map_domain_details": { 0x796edb50: 0xfc1859dd },
- "map_param_add_del_pre_resolve": { 0xdae5af03: 0x17008c66 },
- "map_param_get_reply": { 0x26272c90: 0x28092156 },
- "memif_details": { 0xda34feb9: 0xd0382c4c },
- "dslite_add_del_pool_addr_range": { 0xde2a5b02: 0xc448457a },
- "dslite_set_aftr_addr": { 0x78b50fdf: 0x1e955f8d },
- "dslite_get_aftr_addr_reply": { 0x8e23608e: 0x38e30db1 },
- "dslite_set_b4_addr": { 0x78b50fdf: 0x1e955f8d },
- "dslite_get_b4_addr_reply": { 0x8e23608e: 0x38e30db1 },
- "nat44_add_del_address_range": { 0x6f2b8055: 0xd4c7568c },
- "nat44_address_details": { 0xd1beac1: 0x45410ac4 },
- "nat44_add_del_static_mapping": { 0x5ae5f03e: 0xe165e83b },
- "nat44_static_mapping_details": { 0x6cb40b2: 0x1a433ef7 },
- "nat44_add_del_identity_mapping": { 0x2faaa22: 0x8e12743f },
- "nat44_identity_mapping_details": { 0x2a52a030: 0x36d21351 },
- "nat44_add_del_interface_addr": { 0x4aed50c0: 0xfc835325 },
- "nat44_interface_addr_details": { 0xe4aca9ca: 0x3e687514 },
- "nat44_user_session_details": { 0x2cf6e16d: 0x1965fd69 },
- "nat44_add_del_lb_static_mapping": { 0x4f68ee9d: 0x53b24611 },
- "nat44_lb_static_mapping_add_del_local": { 0x7ca47547: 0x2910a151 },
- "nat44_lb_static_mapping_details": { 0xed5ce876: 0x2267b9e8 },
- "nat44_del_session": { 0x15a5bf8c: 0x4c49c387 },
- "nat_det_add_del_map": { 0x1150a190: 0x112fde05 },
- "nat_det_map_details": { 0xad91dc83: 0x88000ee1 },
- "nat_det_close_session_out": { 0xf6b259d1: 0xc1b6cbfb },
- "nat_det_close_session_in": { 0x3c68e073: 0xa10ef64 },
- "nat64_add_del_pool_addr_range": { 0xa3b944e3: 0x21234ef3 },
- "nat64_add_del_static_bib": { 0x1c404de5: 0x90fae58a },
- "nat64_bib_details": { 0x43bc3ddf: 0x62c8541d },
- "nat64_st_details": { 0xdd3361ed: 0xc770d620 },
- "nat66_add_del_static_mapping": { 0x3ed88f71: 0xfb64e50b },
- "nat66_static_mapping_details": { 0xdf39654b: 0x5c568448 },
- "nsh_add_del_map": { 0xa0f42b0: 0x898d857d },
- "nsh_map_details": { 0x2fefcf49: 0xb34ac8a1 },
- "nsim_cross_connect_enable_disable": { 0x9c3ead86: 0x16f70bdf },
- "pppoe_add_del_session": { 0xf6fd759e: 0x46ace853 },
- "pppoe_session_details": { 0x4b8e8a4a: 0x332bc742 },
- "stn_add_del_rule": { 0x224c6edd: 0x53f751e6 },
- "stn_rules_details": { 0xa51935a6: 0xb0f6606c },
- "svs_route_add_del": { 0xe49bc63c: 0xd39e31fc },
- "svs_details": { 0x6282cd55: 0xb8523d64 },
- "vmxnet3_details": { 0x6a1a5498: 0x829ba055 },
- "vrrp_vr_add_del": { 0xc5cf15aa: 0x6dc4b881 },
- "vrrp_vr_details": { 0x46edcebd: 0x412fa71 },
- "vrrp_vr_set_peers": { 0x20bec71f: 0xbaa2e52b },
- "vrrp_vr_peer_details": { 0x3d99c108: 0xabd9145e },
- "vrrp_vr_track_if_add_del": { 0xd67df299: 0x337f4ba4 },
- "vrrp_vr_track_if_details": { 0x73c36f81: 0x99bcca9c },
- "proxy_arp_add_del": { 0x1823c3e7: 0x85486cbd },
- "proxy_arp_details": { 0x5b948673: 0x9228c150 },
- "bfd_udp_get_echo_source_reply": { 0xe3d736a1: 0x1e00cfce },
- "bfd_udp_add": { 0x939cd26a: 0x7a6d1185 },
- "bfd_udp_mod": { 0x913df085: 0x783a3ff6 },
- "bfd_udp_del": { 0xdcb13a89: 0x8096514d },
- "bfd_udp_session_details": { 0x9fb2f2d: 0x60653c02 },
- "bfd_udp_session_set_flags": { 0x4b4bdfd: 0xcf313851 },
- "bfd_udp_auth_activate": { 0x21fd1bdb: 0x493ee0ec },
- "bfd_udp_auth_deactivate": { 0x9a05e2e0: 0x99978c32 },
- "bier_route_add_del": { 0xfd02f3ea: 0xf29edca0 },
- "bier_route_details": { 0x4008caee: 0x39ee6a56 },
- "bier_disp_entry_add_del": { 0x9eb80cb4: 0x648323eb },
- "bier_disp_entry_details": { 0x84c218f1: 0xe5b039a9 },
- "bond_create": { 0xf1dbd4ff: 0x48883c7e },
- "bond_enslave": { 0xe7d14948: 0x76ecfa7 },
- "sw_interface_bond_details": { 0xbb7c929b: 0xf5ef2106 },
- "pipe_create_reply": { 0xb7ce310c: 0xd4c2c2b3 },
- "pipe_details": { 0xc52b799d: 0x43ac107a },
- "tap_create_v2": { 0x2d0d6570: 0x445835fd },
- "sw_interface_tap_v2_details": { 0x1e2b2a47: 0xe53c16de },
- "sw_interface_vhost_user_details": { 0xcee1e53: 0x98530df1 },
- "virtio_pci_create": { 0x1944f8db: 0xa9f1370c },
- "sw_interface_virtio_pci_details": { 0x6ca9c167: 0x16187f3a },
- "p2p_ethernet_add": { 0x36a1a6dc: 0xeeb8e717 },
- "p2p_ethernet_del": { 0x62f81c8c: 0xb62c386 },
- "geneve_add_del_tunnel": { 0x99445831: 0x976693b5 },
- "geneve_tunnel_details": { 0x6b16eb24: 0xe27e2748 },
- "gre_tunnel_add_del": { 0xa27d7f17: 0x6efc9c22 },
- "gre_tunnel_details": { 0x24435433: 0x3bfbf1 },
- "sw_interface_set_flags": { 0xf5aec1b8: 0x6a2b491a },
- "sw_interface_event": { 0x2d3d95a7: 0xf709f78d },
- "sw_interface_details": { 0x6c221fc7: 0x17b69fa2 },
- "sw_interface_add_del_address": { 0x5463d73b: 0x5803d5c4 },
- "sw_interface_set_unnumbered": { 0x154a6439: 0x938ef33b },
- "sw_interface_set_mac_address": { 0xc536e7eb: 0x6aca746a },
- "sw_interface_set_rx_mode": { 0xb04d1cfe: 0x780f5cee },
- "sw_interface_rx_placement_details": { 0x9e44a7ce: 0xf6d7d024 },
- "create_subif": { 0x790ca755: 0xcb371063 },
- "ip_neighbor_add_del": { 0x607c257: 0x105518b6 },
- "ip_neighbor_dump": { 0xd817a484: 0xcd831298 },
- "ip_neighbor_details": { 0xe29d79f0: 0x870e80b9 },
- "want_ip_neighbor_events": { 0x73e70a86: 0x1a312870 },
- "ip_neighbor_event": { 0xbdb092b2: 0x83933131 },
- "ip_route_add_del": { 0xb8ecfe0d: 0xc1ff832d },
- "ip_route_details": { 0xbda8f315: 0xd1ffaae1 },
- "ip_route_lookup": { 0x710d6471: 0xe2986185 },
- "ip_route_lookup_reply": { 0x5d8febcb: 0xae99de8e },
- "ip_mroute_add_del": { 0x85d762f3: 0xf6627d17 },
- "ip_mroute_details": { 0x99341a45: 0xc1cb4b44 },
- "ip_address_details": { 0xee29b797: 0xb1199745 },
- "ip_unnumbered_details": { 0xcc59bd42: 0xaa12a483 },
- "mfib_signal_details": { 0x6f4a4cfb: 0x64398a9a },
- "ip_punt_redirect": { 0x6580f635: 0xa9a5592c },
- "ip_punt_redirect_details": { 0x2cef63e7: 0x3924f5d3 },
- "ip_container_proxy_add_del": { 0x7df1dff1: 0x91189f40 },
- "ip_container_proxy_details": { 0xa8085523: 0xee460e8 },
- "ip_source_and_port_range_check_add_del": { 0x92a067e3: 0x8bfc76f2 },
- "sw_interface_ip6_set_link_local_address": { 0x1c10f15f: 0x2931d9fa },
- "ip_reassembly_enable_disable": { 0xeb77968d: 0x885c85a6 },
- "set_punt": { 0xaa83d523: 0x83799618 },
- "punt_socket_register": { 0x95268cbf: 0xc8cd10fa },
- "punt_socket_details": { 0xde575080: 0x1de0ce75 },
- "punt_socket_deregister": { 0x98fc9102: 0x98a444f4 },
- "sw_interface_ip6nd_ra_prefix": { 0x82cc1b28: 0xe098785f },
- "ip6nd_proxy_add_del": { 0xc2e4a686: 0x3fdf6659 },
- "ip6nd_proxy_details": { 0x30b9ff4a: 0xd35be8ff },
- "ip6_ra_event": { 0x364c1c5: 0x47e8cfbe },
- "set_ipfix_exporter": { 0x5530c8a0: 0x69284e07 },
- "ipfix_exporter_details": { 0xdedbfe4: 0x11e07413 },
- "ipip_add_tunnel": { 0x2ac399f5: 0xa9decfcd },
- "ipip_6rd_add_tunnel": { 0xb9ec1863: 0x56e93cc0 },
- "ipip_tunnel_details": { 0xd31cb34e: 0x53236d75 },
- "ipsec_spd_entry_add_del": { 0x338b7411: 0x9f384b8d },
- "ipsec_spd_details": { 0x5813d7a2: 0xf2222790 },
- "ipsec_sad_entry_add_del": { 0xab64b5c6: 0xb8def364 },
- "ipsec_tunnel_protect_update": { 0x30d5f133: 0x143f155d },
- "ipsec_tunnel_protect_del": { 0xcd239930: 0xddd2ba36 },
- "ipsec_tunnel_protect_details": { 0x21663a50: 0xac6c823b },
- "ipsec_tunnel_if_add_del": { 0x20e353fa: 0x2b135e68 },
- "ipsec_sa_details": { 0x345d14a7: 0xb30c7f41 },
- "l2_xconnect_details": { 0x472b6b67: 0xc8aa6b37 },
- "l2_fib_table_details": { 0xa44ef6b8: 0xe8d2fc72 },
- "l2fib_add_del": { 0xeddda487: 0xf29d796c },
- "l2_macs_event": { 0x44b8fd64: 0x2eadfc8b },
- "bridge_domain_details": { 0xfa506fd: 0x979f549d },
- "l2_interface_pbb_tag_rewrite": { 0x38e802a8: 0x612efa5a },
- "l2_patch_add_del": { 0xa1f6a6f3: 0x522f3445 },
- "sw_interface_set_l2_xconnect": { 0x4fa28a85: 0x1aaa2dbb },
- "sw_interface_set_l2_bridge": { 0xd0678b13: 0x2e483cd0 },
- "bd_ip_mac_add_del": { 0x257c869: 0x5f2b84e2 },
- "bd_ip_mac_details": { 0x545af86a: 0xa52f8044 },
- "l2_arp_term_event": { 0x6963e07a: 0x85ff71ea },
- "l2tpv3_create_tunnel": { 0x15bed0c2: 0x596892cb },
- "sw_if_l2tpv3_tunnel_details": { 0x50b88993: 0x1dab5c7e },
- "lisp_add_del_local_eid": { 0x4e5a83a2: 0x21f573bd },
- "lisp_add_del_map_server": { 0xce19e32d: 0x6598ea7c },
- "lisp_add_del_map_resolver": { 0xce19e32d: 0x6598ea7c },
- "lisp_use_petr": { 0xd87dbad9: 0x9e141831 },
- "show_lisp_use_petr_reply": { 0x22b9a4b0: 0xdcad8a81 },
- "lisp_add_del_remote_mapping": { 0x6d5c789e: 0xfae8ed77 },
- "lisp_add_del_adjacency": { 0x2ce0e6f6: 0xcf5edb61 },
- "lisp_locator_details": { 0x2c620ffe: 0xc0c4c2a7 },
- "lisp_eid_table_details": { 0x1c29f792: 0x4bc32e3a },
- "lisp_eid_table_dump": { 0x629468b5: 0xb959b73b },
- "lisp_adjacencies_get_reply": { 0x807257bf: 0x3f97bcdd },
- "lisp_map_resolver_details": { 0x3e78fc57: 0x82a09deb },
- "lisp_map_server_details": { 0x3e78fc57: 0x82a09deb },
- "one_add_del_local_eid": { 0x4e5a83a2: 0x21f573bd },
- "one_add_del_map_server": { 0xce19e32d: 0x6598ea7c },
- "one_add_del_map_resolver": { 0xce19e32d: 0x6598ea7c },
- "one_use_petr": { 0xd87dbad9: 0x9e141831 },
- "show_one_use_petr_reply": { 0x84a03528: 0x10e744a6 },
- "one_add_del_remote_mapping": { 0x6d5c789e: 0xfae8ed77 },
- "one_add_del_l2_arp_entry": { 0x1aa5e8b3: 0x33209078 },
- "one_l2_arp_entries_get_reply": { 0xb0dd200f: 0xb0a47bbe },
- "one_add_del_ndp_entry": { 0xf8a287c: 0xd1629a2f },
- "one_ndp_entries_get_reply": { 0x70719b1a: 0xbd34161 },
- "one_add_del_adjacency": { 0x9e830312: 0xe48e7afe },
- "one_locator_details": { 0x2c620ffe: 0xc0c4c2a7 },
- "one_eid_table_details": { 0x1c29f792: 0x4bc32e3a },
- "one_eid_table_dump": { 0xbd190269: 0x95151038 },
- "one_adjacencies_get_reply": { 0x85bab89: 0xa8ed89a5 },
- "one_map_resolver_details": { 0x3e78fc57: 0x82a09deb },
- "one_map_server_details": { 0x3e78fc57: 0x82a09deb },
- "one_stats_details": { 0x2eb74678: 0xff6ef238 },
- "gpe_add_del_fwd_entry": { 0xf0847644: 0xde6df50f },
- "gpe_fwd_entries_get_reply": { 0xc4844876: 0xf9f53f1b },
- "gpe_fwd_entry_path_details": { 0x483df51a: 0xee80b19a },
- "gpe_add_del_native_fwd_rpath": { 0x43fc8b54: 0x812da2f2 },
- "gpe_native_fwd_rpaths_get_reply": { 0x7a1ca5a2: 0x79d54eb9 },
- "sw_interface_set_lldp": { 0x57afbcd4: 0xd646ae0f },
- "mpls_ip_bind_unbind": { 0xc7533b32: 0x48249a27 },
- "mpls_tunnel_add_del": { 0x44350ac1: 0xe57ce61d },
- "mpls_tunnel_details": { 0x57118ae3: 0xf3c0928e },
- "mpls_route_add_del": { 0x8e1d1e07: 0x343cff54 },
- "mpls_route_details": { 0x9b5043dc: 0xd0ac384c },
- "policer_add_del": { 0x2b31dd38: 0xcb948f6e },
- "policer_details": { 0x72d0e248: 0xa43f781a },
- "qos_store_enable_disable": { 0xf3abcc8b: 0x3507235e },
- "qos_store_details": { 0x3ee0aad7: 0x38a6d48 },
- "qos_record_enable_disable": { 0x2f1a4a38: 0x25b33f88 },
- "qos_record_details": { 0xa425d4d3: 0x4956ccdd },
- "session_rule_add_del": { 0xe4895422: 0xe31f9443 },
- "session_rules_details": { 0x28d71830: 0x304b91f0 },
- "sw_interface_span_enable_disable": { 0x23ddd96b: 0xacc8fea1 },
- "sw_interface_span_details": { 0x8a20e79f: 0x55643fc },
- "sr_mpls_steering_add_del": { 0x64acff63: 0x7d1b0a0b },
- "sr_mpls_policy_assign_endpoint_color": { 0xe7eb978: 0x5e1c5c13 },
- "sr_localsid_add_del": { 0x5a36c324: 0x26fa3309 },
- "sr_policy_add": { 0x44ac92e8: 0xec79ee6a },
- "sr_policy_mod": { 0xb97bb56e: 0xe531a102 },
- "sr_steering_add_del": { 0xe46b0a0f: 0x3711dace },
- "sr_localsids_details": { 0x2e9221b9: 0x6a6c0265 },
- "sr_policies_details": { 0xdb6ff2a1: 0x7ec2d93 },
- "sr_steering_pol_details": { 0xd41258c9: 0x1c1ee786 },
- "syslog_set_sender": { 0xb8011d0b: 0xbb641285 },
- "syslog_get_sender_reply": { 0x424cfa4e: 0xd3da60ac },
- "tcp_configure_src_addresses": { 0x67eede0d: 0x4b02b946 },
- "teib_entry_add_del": { 0x8016cfd2: 0x5aa0a538 },
- "teib_details": { 0x981ee1a1: 0xe3b6a503 },
- "udp_encap_add": { 0xf74a60b1: 0x61d5fc48 },
- "udp_encap_details": { 0x8cfb9c76: 0x87c82821 },
- "vxlan_gbp_tunnel_add_del": { 0x6c743427: 0x8c819166 },
- "vxlan_gbp_tunnel_details": { 0x66e94a89: 0x1da24016 },
- "vxlan_gpe_add_del_tunnel": { 0xa645b2b0: 0x7c6da6ae },
- "vxlan_gpe_tunnel_details": { 0x968fc8b: 0x57712346 },
- "vxlan_add_del_tunnel": { 0xc09dc80: 0xa35dc8f5 },
- "vxlan_tunnel_details": { 0xc3916cb1: 0xe782f70f },
- "vxlan_offload_rx": { 0x9cc95087: 0x89a1564b },
- "log_details": { 0x3d61cc0: 0x255827a1 },
+ "abf_policy_add_del": {0xc6131197: 0xee66f93e},
+ "abf_policy_details": {0xb7487fa4: 0x6769e504},
+ "acl_add_replace": {0xee5c2f18: 0x1cabdeab},
+ "acl_details": {0x95babae0: 0x7a97f21c},
+ "macip_acl_add": {0xce6fbad0: 0xd648fd0a},
+ "macip_acl_add_replace": {0x2a461dd4: 0xe34402a7},
+ "macip_acl_details": {0x27135b59: 0x57c7482f},
+ "dhcp_proxy_config": {0x4058a689: 0x6767230e},
+ "dhcp_client_config": {0x1af013ea: 0x959b80a3},
+ "dhcp_compl_event": {0x554a44e5: 0xe908fd1d},
+ "dhcp_client_details": {0x3c5cd28a: 0xacd82f5a},
+ "dhcp_proxy_details": {0xdcbaf540: 0xce16f044},
+ "dhcp6_send_client_message": {0xf8222476: 0xf6f14ef0},
+ "dhcp6_pd_send_client_message": {0x3739fd8d: 0x64badb8},
+ "dhcp6_reply_event": {0x85b7b17e: 0x9f3af9e5},
+ "dhcp6_pd_reply_event": {0x5e878029: 0xcb3e462b},
+ "ip6_add_del_address_using_prefix": {0x3982f30a: 0x9b3d11e0},
+ "gbp_bridge_domain_add": {0x918e8c01: 0x8454bfdf},
+ "gbp_bridge_domain_details": {0x51d51be9: 0x2acd15f9},
+ "gbp_route_domain_add": {0x204c79e1: 0x2d0afe38},
+ "gbp_route_domain_details": {0xa78bfbca: 0x8ab11375},
+ "gbp_endpoint_add": {0x7b3af7de: 0x9ce16d5a},
+ "gbp_endpoint_details": {0x8dd8fbd3: 0x8aecb60},
+ "gbp_endpoint_group_add": {0x301ddf15: 0x8e0f4054},
+ "gbp_endpoint_group_details": {0xab71d723: 0x8f38292c},
+ "gbp_subnet_add_del": {0xa8803c80: 0x888aca35},
+ "gbp_subnet_details": {0xcbc5ca18: 0x4ed84156},
+ "gbp_contract_add_del": {0xaa8d652d: 0x553e275b},
+ "gbp_contract_details": {0x65dec325: 0x2a18db6e},
+ "gbp_ext_itf_add_del": {0x7606d0e1: 0x12ed5700},
+ "gbp_ext_itf_details": {0x519c3d3c: 0x408a45c0},
+ "gtpu_add_del_tunnel": {0xca983a2b: 0x9a9c0426},
+ "gtpu_tunnel_update_tteid": {0x79f33816: 0x8a2db108},
+ "gtpu_tunnel_details": {0x27f434ae: 0x4535cf95},
+ "igmp_listen": {0x19a49f1e: 0x3f93a51a},
+ "igmp_details": {0x38f09929: 0x52f12a89},
+ "igmp_event": {0x85fe93ec: 0xd7696eaf},
+ "igmp_group_prefix_set": {0x5b14a5ce: 0xd4f20ac5},
+ "igmp_group_prefix_details": {0x259ccd81: 0xc3b3c526},
+ "ikev2_set_responder": {0xb9aa4d4e: 0xf0d3dc80},
+ "vxlan_gpe_ioam_export_enable_disable": {0xd4c76d3a: 0xe4d4ebfa},
+ "ioam_export_ip6_enable_disable": {0xd4c76d3a: 0xe4d4ebfa},
+ "vxlan_gpe_ioam_vni_enable": {0xfbb5fb1: 0x997161fb},
+ "vxlan_gpe_ioam_vni_disable": {0xfbb5fb1: 0x997161fb},
+ "vxlan_gpe_ioam_transit_enable": {0x3d3ec657: 0x553f5b7b},
+ "vxlan_gpe_ioam_transit_disable": {0x3d3ec657: 0x553f5b7b},
+ "udp_ping_add_del": {0xfa2628fc: 0xc692b188},
+ "l3xc_update": {0xe96aabdf: 0x787b1d3},
+ "l3xc_details": {0xbc5bf852: 0xd4f69627},
+ "sw_interface_lacp_details": {0xd9a83d2f: 0x745ae0ba},
+ "lb_conf": {0x56cd3261: 0x22ddb739},
+ "lb_add_del_vip": {0x6fa569c7: 0xd15b7ddc},
+ "lb_add_del_as": {0x35d72500: 0x78628987},
+ "lb_vip_dump": {0x56110cb7: 0xc7bcb124},
+ "lb_vip_details": {0x1329ec9b: 0x8f39bed},
+ "lb_as_details": {0x8d24c29e: 0x9c39f60e},
+ "mactime_add_del_range": {0xcb56e877: 0x101858ef},
+ "mactime_details": {0xda25b13a: 0x44921c06},
+ "map_add_domain": {0x249f195c: 0x7a5a18c9},
+ "map_domain_details": {0x796edb50: 0xfc1859dd},
+ "map_param_add_del_pre_resolve": {0xdae5af03: 0x17008c66},
+ "map_param_get_reply": {0x26272c90: 0x28092156},
+ "memif_details": {0xda34feb9: 0xd0382c4c},
+ "dslite_add_del_pool_addr_range": {0xde2a5b02: 0xc448457a},
+ "dslite_set_aftr_addr": {0x78b50fdf: 0x1e955f8d},
+ "dslite_get_aftr_addr_reply": {0x8e23608e: 0x38e30db1},
+ "dslite_set_b4_addr": {0x78b50fdf: 0x1e955f8d},
+ "dslite_get_b4_addr_reply": {0x8e23608e: 0x38e30db1},
+ "nat44_add_del_address_range": {0x6f2b8055: 0xd4c7568c},
+ "nat44_address_details": {0xd1beac1: 0x45410ac4},
+ "nat44_add_del_static_mapping": {0x5ae5f03e: 0xe165e83b},
+ "nat44_static_mapping_details": {0x6cb40b2: 0x1a433ef7},
+ "nat44_add_del_identity_mapping": {0x2faaa22: 0x8e12743f},
+ "nat44_identity_mapping_details": {0x2a52a030: 0x36d21351},
+ "nat44_add_del_interface_addr": {0x4aed50c0: 0xfc835325},
+ "nat44_interface_addr_details": {0xe4aca9ca: 0x3e687514},
+ "nat44_user_session_details": {0x2cf6e16d: 0x1965fd69},
+ "nat44_add_del_lb_static_mapping": {0x4f68ee9d: 0x53b24611},
+ "nat44_lb_static_mapping_add_del_local": {0x7ca47547: 0x2910a151},
+ "nat44_lb_static_mapping_details": {0xed5ce876: 0x2267b9e8},
+ "nat44_del_session": {0x15a5bf8c: 0x4c49c387},
+ "nat_det_add_del_map": {0x1150a190: 0x112fde05},
+ "nat_det_map_details": {0xad91dc83: 0x88000ee1},
+ "nat_det_close_session_out": {0xf6b259d1: 0xc1b6cbfb},
+ "nat_det_close_session_in": {0x3c68e073: 0xa10ef64},
+ "nat64_add_del_pool_addr_range": {0xa3b944e3: 0x21234ef3},
+ "nat64_add_del_static_bib": {0x1c404de5: 0x90fae58a},
+ "nat64_bib_details": {0x43bc3ddf: 0x62c8541d},
+ "nat64_st_details": {0xdd3361ed: 0xc770d620},
+ "nat66_add_del_static_mapping": {0x3ed88f71: 0xfb64e50b},
+ "nat66_static_mapping_details": {0xdf39654b: 0x5c568448},
+ "nsh_add_del_map": {0xa0f42b0: 0x898d857d},
+ "nsh_map_details": {0x2fefcf49: 0xb34ac8a1},
+ "nsim_cross_connect_enable_disable": {0x9c3ead86: 0x16f70bdf},
+ "pppoe_add_del_session": {0xf6fd759e: 0x46ace853},
+ "pppoe_session_details": {0x4b8e8a4a: 0x332bc742},
+ "stn_add_del_rule": {0x224c6edd: 0x53f751e6},
+ "stn_rules_details": {0xa51935a6: 0xb0f6606c},
+ "svs_route_add_del": {0xe49bc63c: 0xd39e31fc},
+ "svs_details": {0x6282cd55: 0xb8523d64},
+ "vmxnet3_details": {0x6a1a5498: 0x829ba055},
+ "vrrp_vr_add_del": {0xc5cf15aa: 0x6dc4b881},
+ "vrrp_vr_details": {0x46edcebd: 0x412fa71},
+ "vrrp_vr_set_peers": {0x20bec71f: 0xbaa2e52b},
+ "vrrp_vr_peer_details": {0x3d99c108: 0xabd9145e},
+ "vrrp_vr_track_if_add_del": {0xd67df299: 0x337f4ba4},
+ "vrrp_vr_track_if_details": {0x73c36f81: 0x99bcca9c},
+ "proxy_arp_add_del": {0x1823c3e7: 0x85486cbd},
+ "proxy_arp_details": {0x5b948673: 0x9228c150},
+ "bfd_udp_get_echo_source_reply": {0xe3d736a1: 0x1e00cfce},
+ "bfd_udp_add": {0x939cd26a: 0x7a6d1185},
+ "bfd_udp_mod": {0x913df085: 0x783a3ff6},
+ "bfd_udp_del": {0xdcb13a89: 0x8096514d},
+ "bfd_udp_session_details": {0x9fb2f2d: 0x60653c02},
+ "bfd_udp_session_set_flags": {0x4b4bdfd: 0xcf313851},
+ "bfd_udp_auth_activate": {0x21fd1bdb: 0x493ee0ec},
+ "bfd_udp_auth_deactivate": {0x9a05e2e0: 0x99978c32},
+ "bier_route_add_del": {0xfd02f3ea: 0xf29edca0},
+ "bier_route_details": {0x4008caee: 0x39ee6a56},
+ "bier_disp_entry_add_del": {0x9eb80cb4: 0x648323eb},
+ "bier_disp_entry_details": {0x84c218f1: 0xe5b039a9},
+ "bond_create": {0xf1dbd4ff: 0x48883c7e},
+ "bond_enslave": {0xe7d14948: 0x76ecfa7},
+ "sw_interface_bond_details": {0xbb7c929b: 0xf5ef2106},
+ "pipe_create_reply": {0xb7ce310c: 0xd4c2c2b3},
+ "pipe_details": {0xc52b799d: 0x43ac107a},
+ "tap_create_v2": {0x2d0d6570: 0x445835fd},
+ "sw_interface_tap_v2_details": {0x1e2b2a47: 0xe53c16de},
+ "sw_interface_vhost_user_details": {0xcee1e53: 0x98530df1},
+ "virtio_pci_create": {0x1944f8db: 0xa9f1370c},
+ "sw_interface_virtio_pci_details": {0x6ca9c167: 0x16187f3a},
+ "p2p_ethernet_add": {0x36a1a6dc: 0xeeb8e717},
+ "p2p_ethernet_del": {0x62f81c8c: 0xb62c386},
+ "geneve_add_del_tunnel": {0x99445831: 0x976693b5},
+ "geneve_tunnel_details": {0x6b16eb24: 0xe27e2748},
+ "gre_tunnel_add_del": {0xa27d7f17: 0x6efc9c22},
+ "gre_tunnel_details": {0x24435433: 0x3bfbf1},
+ "sw_interface_set_flags": {0xf5aec1b8: 0x6a2b491a},
+ "sw_interface_event": {0x2d3d95a7: 0xf709f78d},
+ "sw_interface_details": {0x6c221fc7: 0x17b69fa2},
+ "sw_interface_add_del_address": {0x5463d73b: 0x5803d5c4},
+ "sw_interface_set_unnumbered": {0x154a6439: 0x938ef33b},
+ "sw_interface_set_mac_address": {0xc536e7eb: 0x6aca746a},
+ "sw_interface_set_rx_mode": {0xb04d1cfe: 0x780f5cee},
+ "sw_interface_rx_placement_details": {0x9e44a7ce: 0xf6d7d024},
+ "create_subif": {0x790ca755: 0xcb371063},
+ "ip_neighbor_add_del": {0x607c257: 0x105518b6},
+ "ip_neighbor_dump": {0xd817a484: 0xcd831298},
+ "ip_neighbor_details": {0xe29d79f0: 0x870e80b9},
+ "want_ip_neighbor_events": {0x73e70a86: 0x1a312870},
+ "ip_neighbor_event": {0xbdb092b2: 0x83933131},
+ "ip_route_add_del": {0xb8ecfe0d: 0xc1ff832d},
+ "ip_route_details": {0xbda8f315: 0xd1ffaae1},
+ "ip_route_lookup": {0x710d6471: 0xe2986185},
+ "ip_route_lookup_reply": {0x5d8febcb: 0xae99de8e},
+ "ip_mroute_add_del": {0x85d762f3: 0xf6627d17},
+ "ip_mroute_details": {0x99341a45: 0xc1cb4b44},
+ "ip_address_details": {0xee29b797: 0xb1199745},
+ "ip_unnumbered_details": {0xcc59bd42: 0xaa12a483},
+ "mfib_signal_details": {0x6f4a4cfb: 0x64398a9a},
+ "ip_punt_redirect": {0x6580f635: 0xa9a5592c},
+ "ip_punt_redirect_details": {0x2cef63e7: 0x3924f5d3},
+ "ip_container_proxy_add_del": {0x7df1dff1: 0x91189f40},
+ "ip_container_proxy_details": {0xa8085523: 0xee460e8},
+ "ip_source_and_port_range_check_add_del": {0x92a067e3: 0x8bfc76f2},
+ "sw_interface_ip6_set_link_local_address": {0x1c10f15f: 0x2931d9fa},
+ "ip_reassembly_enable_disable": {0xeb77968d: 0x885c85a6},
+ "set_punt": {0xaa83d523: 0x83799618},
+ "punt_socket_register": {0x95268cbf: 0xc8cd10fa},
+ "punt_socket_details": {0xde575080: 0x1de0ce75},
+ "punt_socket_deregister": {0x98fc9102: 0x98a444f4},
+ "sw_interface_ip6nd_ra_prefix": {0x82cc1b28: 0xe098785f},
+ "ip6nd_proxy_add_del": {0xc2e4a686: 0x3fdf6659},
+ "ip6nd_proxy_details": {0x30b9ff4a: 0xd35be8ff},
+ "ip6_ra_event": {0x364c1c5: 0x47e8cfbe},
+ "set_ipfix_exporter": {0x5530c8a0: 0x69284e07},
+ "ipfix_exporter_details": {0xdedbfe4: 0x11e07413},
+ "ipip_add_tunnel": {0x2ac399f5: 0xa9decfcd},
+ "ipip_6rd_add_tunnel": {0xb9ec1863: 0x56e93cc0},
+ "ipip_tunnel_details": {0xd31cb34e: 0x53236d75},
+ "ipsec_spd_entry_add_del": {0x338b7411: 0x9f384b8d},
+ "ipsec_spd_details": {0x5813d7a2: 0xf2222790},
+ "ipsec_sad_entry_add_del": {0xab64b5c6: 0xb8def364},
+ "ipsec_tunnel_protect_update": {0x30d5f133: 0x143f155d},
+ "ipsec_tunnel_protect_del": {0xcd239930: 0xddd2ba36},
+ "ipsec_tunnel_protect_details": {0x21663a50: 0xac6c823b},
+ "ipsec_tunnel_if_add_del": {0x20e353fa: 0x2b135e68},
+ "ipsec_sa_details": {0x345d14a7: 0xb30c7f41},
+ "l2_xconnect_details": {0x472b6b67: 0xc8aa6b37},
+ "l2_fib_table_details": {0xa44ef6b8: 0xe8d2fc72},
+ "l2fib_add_del": {0xeddda487: 0xf29d796c},
+ "l2_macs_event": {0x44b8fd64: 0x2eadfc8b},
+ "bridge_domain_details": {0xfa506fd: 0x979f549d},
+ "l2_interface_pbb_tag_rewrite": {0x38e802a8: 0x612efa5a},
+ "l2_patch_add_del": {0xa1f6a6f3: 0x522f3445},
+ "sw_interface_set_l2_xconnect": {0x4fa28a85: 0x1aaa2dbb},
+ "sw_interface_set_l2_bridge": {0xd0678b13: 0x2e483cd0},
+ "bd_ip_mac_add_del": {0x257c869: 0x5f2b84e2},
+ "bd_ip_mac_details": {0x545af86a: 0xa52f8044},
+ "l2_arp_term_event": {0x6963e07a: 0x85ff71ea},
+ "l2tpv3_create_tunnel": {0x15bed0c2: 0x596892cb},
+ "sw_if_l2tpv3_tunnel_details": {0x50b88993: 0x1dab5c7e},
+ "lisp_add_del_local_eid": {0x4e5a83a2: 0x21f573bd},
+ "lisp_add_del_map_server": {0xce19e32d: 0x6598ea7c},
+ "lisp_add_del_map_resolver": {0xce19e32d: 0x6598ea7c},
+ "lisp_use_petr": {0xd87dbad9: 0x9e141831},
+ "show_lisp_use_petr_reply": {0x22b9a4b0: 0xdcad8a81},
+ "lisp_add_del_remote_mapping": {0x6d5c789e: 0xfae8ed77},
+ "lisp_add_del_adjacency": {0x2ce0e6f6: 0xcf5edb61},
+ "lisp_locator_details": {0x2c620ffe: 0xc0c4c2a7},
+ "lisp_eid_table_details": {0x1c29f792: 0x4bc32e3a},
+ "lisp_eid_table_dump": {0x629468b5: 0xb959b73b},
+ "lisp_adjacencies_get_reply": {0x807257bf: 0x3f97bcdd},
+ "lisp_map_resolver_details": {0x3e78fc57: 0x82a09deb},
+ "lisp_map_server_details": {0x3e78fc57: 0x82a09deb},
+ "one_add_del_local_eid": {0x4e5a83a2: 0x21f573bd},
+ "one_add_del_map_server": {0xce19e32d: 0x6598ea7c},
+ "one_add_del_map_resolver": {0xce19e32d: 0x6598ea7c},
+ "one_use_petr": {0xd87dbad9: 0x9e141831},
+ "show_one_use_petr_reply": {0x84a03528: 0x10e744a6},
+ "one_add_del_remote_mapping": {0x6d5c789e: 0xfae8ed77},
+ "one_add_del_l2_arp_entry": {0x1aa5e8b3: 0x33209078},
+ "one_l2_arp_entries_get_reply": {0xb0dd200f: 0xb0a47bbe},
+ "one_add_del_ndp_entry": {0xf8a287c: 0xd1629a2f},
+ "one_ndp_entries_get_reply": {0x70719b1a: 0xbd34161},
+ "one_add_del_adjacency": {0x9e830312: 0xe48e7afe},
+ "one_locator_details": {0x2c620ffe: 0xc0c4c2a7},
+ "one_eid_table_details": {0x1c29f792: 0x4bc32e3a},
+ "one_eid_table_dump": {0xbd190269: 0x95151038},
+ "one_adjacencies_get_reply": {0x85bab89: 0xa8ed89a5},
+ "one_map_resolver_details": {0x3e78fc57: 0x82a09deb},
+ "one_map_server_details": {0x3e78fc57: 0x82a09deb},
+ "one_stats_details": {0x2eb74678: 0xff6ef238},
+ "gpe_add_del_fwd_entry": {0xf0847644: 0xde6df50f},
+ "gpe_fwd_entries_get_reply": {0xc4844876: 0xf9f53f1b},
+ "gpe_fwd_entry_path_details": {0x483df51a: 0xee80b19a},
+ "gpe_add_del_native_fwd_rpath": {0x43fc8b54: 0x812da2f2},
+ "gpe_native_fwd_rpaths_get_reply": {0x7a1ca5a2: 0x79d54eb9},
+ "sw_interface_set_lldp": {0x57afbcd4: 0xd646ae0f},
+ "mpls_ip_bind_unbind": {0xc7533b32: 0x48249a27},
+ "mpls_tunnel_add_del": {0x44350ac1: 0xe57ce61d},
+ "mpls_tunnel_details": {0x57118ae3: 0xf3c0928e},
+ "mpls_route_add_del": {0x8e1d1e07: 0x343cff54},
+ "mpls_route_details": {0x9b5043dc: 0xd0ac384c},
+ "policer_add_del": {0x2b31dd38: 0xcb948f6e},
+ "policer_details": {0x72d0e248: 0xa43f781a},
+ "qos_store_enable_disable": {0xf3abcc8b: 0x3507235e},
+ "qos_store_details": {0x3ee0aad7: 0x38a6d48},
+ "qos_record_enable_disable": {0x2f1a4a38: 0x25b33f88},
+ "qos_record_details": {0xa425d4d3: 0x4956ccdd},
+ "session_rule_add_del": {0xe4895422: 0xe31f9443},
+ "session_rules_details": {0x28d71830: 0x304b91f0},
+ "sw_interface_span_enable_disable": {0x23ddd96b: 0xacc8fea1},
+ "sw_interface_span_details": {0x8a20e79f: 0x55643fc},
+ "sr_mpls_steering_add_del": {0x64acff63: 0x7d1b0a0b},
+ "sr_mpls_policy_assign_endpoint_color": {0xe7eb978: 0x5e1c5c13},
+ "sr_localsid_add_del": {0x5a36c324: 0x26fa3309},
+ "sr_policy_add": {0x44ac92e8: 0xec79ee6a},
+ "sr_policy_mod": {0xb97bb56e: 0xe531a102},
+ "sr_steering_add_del": {0xe46b0a0f: 0x3711dace},
+ "sr_localsids_details": {0x2e9221b9: 0x6a6c0265},
+ "sr_policies_details": {0xdb6ff2a1: 0x7ec2d93},
+ "sr_steering_pol_details": {0xd41258c9: 0x1c1ee786},
+ "syslog_set_sender": {0xb8011d0b: 0xbb641285},
+ "syslog_get_sender_reply": {0x424cfa4e: 0xd3da60ac},
+ "tcp_configure_src_addresses": {0x67eede0d: 0x4b02b946},
+ "teib_entry_add_del": {0x8016cfd2: 0x5aa0a538},
+ "teib_details": {0x981ee1a1: 0xe3b6a503},
+ "udp_encap_add": {0xf74a60b1: 0x61d5fc48},
+ "udp_encap_details": {0x8cfb9c76: 0x87c82821},
+ "vxlan_gbp_tunnel_add_del": {0x6c743427: 0x8c819166},
+ "vxlan_gbp_tunnel_details": {0x66e94a89: 0x1da24016},
+ "vxlan_gpe_add_del_tunnel": {0xa645b2b0: 0x7c6da6ae},
+ "vxlan_gpe_tunnel_details": {0x968fc8b: 0x57712346},
+ "vxlan_add_del_tunnel": {0xc09dc80: 0xa35dc8f5},
+ "vxlan_tunnel_details": {0xc3916cb1: 0xe782f70f},
+ "vxlan_offload_rx": {0x9cc95087: 0x89a1564b},
+ "log_details": {0x3d61cc0: 0x255827a1},
}
@@ -1358,6 +1370,7 @@ def foldup_crcs(s):
if f.crc in fixup_crc_dict.get(f.name):
f.crc = fixup_crc_dict.get(f.name).get(f.crc)
+
#
# Main
#
@@ -1365,13 +1378,13 @@ def main():
if sys.version_info < (3, 5,):
log.exception('vppapigen requires a supported version of python. '
'Please use version 3.5 or greater. '
- 'Using {}'.format(sys.version))
+ 'Using %s', sys.version)
return 1
cliparser = argparse.ArgumentParser(description='VPP API generator')
- cliparser.add_argument('--pluginpath', default=""),
- cliparser.add_argument('--includedir', action='append'),
- cliparser.add_argument('--outputdir', action='store'),
+ cliparser.add_argument('--pluginpath', default="")
+ cliparser.add_argument('--includedir', action='append')
+ cliparser.add_argument('--outputdir', action='store')
cliparser.add_argument('--input')
cliparser.add_argument('--output', nargs='?',
type=argparse.FileType('w', encoding='UTF-8'),
@@ -1431,8 +1444,8 @@ def main():
plugin = SourceFileLoader(args.output_module,
module_path).load_module()
except Exception as err:
- log.exception('Error importing output plugin: {}, {}'
- .format(module_path, err))
+ log.exception('Error importing output plugin: %s, %s',
+ module_path, err)
return 1
parser = VPPAPI(debug=args.debug, filename=filename, logger=log,
@@ -1461,6 +1474,8 @@ def main():
s = parser.process(result)
else:
s = parser.process(parsed_objects)
+ imports = parser.process_imports(parsed_objects, False, result)
+ s['imported'] = parser.process(imports)
# Add msg_id field
s['Define'] = add_msg_id(s['Define'])
@@ -1482,8 +1497,7 @@ def main():
if result:
print(result, file=args.output)
else:
- log.exception('Running plugin failed: {} {}'
- .format(filename, result))
+ log.exception('Running plugin failed: %s %s', filename, result)
return 1
return 0
diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py
index a8790744054..4369dd86690 100644
--- a/src/tools/vppapigen/vppapigen_c.py
+++ b/src/tools/vppapigen/vppapigen_c.py
@@ -1,4 +1,28 @@
-# C generation
+#
+# Copyright (c) 2020 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# 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.
+#
+
+#
+# Provide two classes FromJSON and TOJSON that converts between JSON and VPP's
+# binary API format
+#
+
+'''
+This module creates C code for core VPP, VPP plugins and client side VAT and
+VAT2 tests.
+'''
+
import datetime
import os
import time
@@ -8,10 +32,588 @@ import shutil
process_imports = False
-datestring = datetime.datetime.utcfromtimestamp(
+###############################################################################
+class ToJSON():
+ '''Class to generate functions converting from VPP binary API to JSON.'''
+ _dispatch = {}
+ noprint_fields = {'_vl_msg_id': None,
+ 'client_index': None,
+ 'context': None}
+ is_number = {'u8': None,
+ 'i8': None,
+ 'u16': None,
+ 'i16': None,
+ 'u32': None,
+ 'i32': None,
+ 'u64': None,
+ 'i64': None,
+ 'f64': None,
+ }
+
+ def __init__(self, module, types, defines, imported_types, stream):
+ self.stream = stream
+ self.module = module
+ self.defines = defines
+ self.types = types
+ self.types_hash = {'vl_api_'+d.name+'_t':
+ d for d in types + imported_types}
+ self.defines_hash = {d.name: d for d in defines}
+
+ def header(self):
+ '''Output the top boilerplate.'''
+ write = self.stream.write
+ write('#ifndef included_{}_api_tojson_h\n'.format(self.module))
+ write('#define included_{}_api_tojson_h\n'.format(self.module))
+ write('#include <vppinfra/cJSON.h>\n\n')
+ write('#include <vat2/jsonconvert.h>\n\n')
+
+ def footer(self):
+ '''Output the bottom boilerplate.'''
+ write = self.stream.write
+ write('#endif\n')
+
+ def get_json_func(self, t):
+ '''Given the type, returns the function to use to create a
+ cJSON object'''
+ vt_type = None
+ try:
+ vt = self.types_hash[t]
+ if vt.type == 'Using' and 'length' not in vt.alias:
+ vt_type = vt.alias['type']
+ except KeyError:
+ vt = t
+
+ if t in self.is_number or vt_type in self.is_number:
+ return 'cJSON_AddNumberToObject', '', False
+ if t == 'bool':
+ return 'cJSON_AddBoolToObject', '', False
+
+ # Lookup type name check if it's enum
+ if vt.type == 'Enum':
+ return '{t}_tojson'.format(t=t), '', True
+ return '{t}_tojson'.format(t=t), '&', True
+
+ def get_json_array_func(self, t):
+ '''Given a type returns the function to create a cJSON object
+ for arrays.'''
+ if t in self.is_number:
+ return 'cJSON_CreateNumber', ''
+ if t == 'bool':
+ return 'cJSON_CreateBool', ''
+ return '{t}_tojson'.format(t=t), '&'
+
+ def print_string(self, o):
+ '''Create cJSON object from vl_api_string_t'''
+ write = self.stream.write
+ if o.modern_vla:
+ write(' vl_api_string_cJSON_AddToObject(o, "{n}", &a->{n});\n'
+ .format(n=o.fieldname))
+ else:
+
+ write(' cJSON_AddStringToObject(o, "{n}", (char *)a->{n});\n'
+ .format(n=o.fieldname))
+
+ def print_field(self, o):
+ '''Called for every field in a typedef or define.'''
+ write = self.stream.write
+ if o.fieldname in self.noprint_fields:
+ return
+
+ f, p, newobj = self.get_json_func(o.fieldtype)
+
+ if newobj:
+ write(' cJSON_AddItemToObject(o, "{n}", {f}({p}a->{n}));\n'
+ .format(f=f, p=p, n=o.fieldname))
+ else:
+ write(' {f}(o, "{n}", {p}a->{n});\n'
+ .format(f=f, p=p, n=o.fieldname))
+
+ _dispatch['Field'] = print_field
+
+ def print_array(self, o):
+ '''Converts a VPP API array to cJSON array.'''
+ write = self.stream.write
+
+ forloop = '''\
+ {{
+ int i;
+ cJSON *array = cJSON_AddArrayToObject(o, "{n}");
+ for (i = 0; i < {lfield}; i++) {{
+ cJSON_AddItemToArray(array, {f}({p}a->{n}[i]));
+ }}
+ }}
+'''
+
+ if o.fieldtype == 'string':
+ self.print_string(o)
+ return
+
+ lfield = 'a->' + o.lengthfield if o.lengthfield else o.length
+ if o.fieldtype == 'u8':
+ write(' {\n')
+ # What is length field doing here?
+ write(' u8 *s = format(0, "0x%U", format_hex_bytes, '
+ '&a->{n}, {lfield});\n'
+ .format(n=o.fieldname, lfield=lfield))
+ write(' cJSON_AddStringToObject(o, "{n}", (char *)s);\n'
+ .format(n=o.fieldname))
+ write(' vec_free(s);\n')
+ write(' }\n')
+ return
+
+ f, p = self.get_json_array_func(o.fieldtype)
+ write(forloop.format(lfield=lfield,
+ t=o.fieldtype,
+ n=o.fieldname,
+ f=f,
+ p=p))
+
+ _dispatch['Array'] = print_array
+
+ def print_enum(self, o):
+ '''Create cJSON object (string) for VPP API enum'''
+ write = self.stream.write
+ write('static inline cJSON *vl_api_{name}_t_tojson '
+ '(vl_api_{name}_t a) {{\n'.format(name=o.name))
+
+ write(" switch(a) {\n")
+ for b in o.block:
+ write(" case %s:\n" % b[1])
+ write(' return cJSON_CreateString("{}");\n'.format(b[0]))
+ write(' default: return cJSON_CreateString("Invalid ENUM");\n')
+ write(' }\n')
+ write(' return 0;\n')
+ write('}\n')
+
+ _dispatch['Enum'] = print_enum
+
+ def print_typedef(self, o):
+ '''Create cJSON (dictionary) object from VPP API typedef'''
+ write = self.stream.write
+ write('static inline cJSON *vl_api_{name}_t_tojson '
+ '(vl_api_{name}_t *a) {{\n'.format(name=o.name))
+ write(' cJSON *o = cJSON_CreateObject();\n')
+
+ for t in o.block:
+ self._dispatch[t.type](self, t)
+
+ write(' return o;\n')
+ write('}\n')
+
+ def print_define(self, o):
+ '''Create cJSON (dictionary) object from VPP API define'''
+ write = self.stream.write
+ write('static inline cJSON *vl_api_{name}_t_tojson '
+ '(vl_api_{name}_t *a) {{\n'.format(name=o.name))
+ write(' cJSON *o = cJSON_CreateObject();\n')
+ write(' cJSON_AddStringToObject(o, "_msgname", "{}");\n'
+ .format(o.name))
+
+ for t in o.block:
+ self._dispatch[t.type](self, t)
+
+ write(' return o;\n')
+ write('}\n')
+
+ def print_using(self, o):
+ '''Create cJSON (dictionary) object from VPP API aliased type'''
+ if o.manual_print:
+ return
+
+ write = self.stream.write
+ write('static inline cJSON *vl_api_{name}_t_tojson '
+ '(vl_api_{name}_t *a) {{\n'.format(name=o.name))
+
+ write(' u8 *s = format(0, "%U", format_vl_api_{}_t, a);\n'
+ .format(o.name))
+ write(' cJSON *o = cJSON_CreateString((char *)s);\n')
+ write(' vec_free(s);\n')
+ write(' return o;\n')
+ write('}\n')
+
+ _dispatch['Typedef'] = print_typedef
+ _dispatch['Define'] = print_define
+ _dispatch['Using'] = print_using
+ _dispatch['Union'] = print_typedef
+
+ def generate_function(self, t):
+ '''Main entry point'''
+ write = self.stream.write
+ if t.manual_print:
+ write('/* Manual print {} */\n'.format(t.name))
+ return
+ self._dispatch[t.type](self, t)
+
+ def generate_types(self):
+ '''Main entry point'''
+ for t in self.types:
+ self.generate_function(t)
+
+ def generate_defines(self):
+ '''Main entry point'''
+ for t in self.defines:
+ self.generate_function(t)
+
+
+class FromJSON():
+ '''
+ Parse JSON objects into VPP API binary message structures.
+ '''
+ _dispatch = {}
+ noprint_fields = {'_vl_msg_id': None,
+ 'client_index': None,
+ 'context': None}
+ is_number = {'u8': None,
+ 'i8': None,
+ 'u16': None,
+ 'i16': None,
+ 'u32': None,
+ 'i32': None,
+ 'u64': None,
+ 'i64': None,
+ 'f64': None,
+ }
+
+ def __init__(self, module, types, defines, imported_types, stream):
+ self.stream = stream
+ self.module = module
+ self.defines = defines
+ self.types = types
+ self.types_hash = {'vl_api_'+d.name+'_t':
+ d for d in types + imported_types}
+ self.defines_hash = {d.name: d for d in defines}
+
+ def header(self):
+ '''Output the top boilerplate.'''
+ write = self.stream.write
+ write('#ifndef included_{}_api_fromjson_h\n'.format(self.module))
+ write('#define included_{}_api_fromjson_h\n'.format(self.module))
+ write('#include <vppinfra/cJSON.h>\n\n')
+ write('#include <vat2/jsonconvert.h>\n\n')
+
+ def is_base_type(self, t):
+ '''Check if a type is one of the VPP API base types'''
+ if t in self.is_number:
+ return True
+ if t == 'bool':
+ return True
+ return False
+
+ def footer(self):
+ '''Output the bottom boilerplate.'''
+ write = self.stream.write
+ write('#endif\n')
+
+ def print_string(self, o, toplevel=False):
+ '''Convert JSON string to vl_api_string_t'''
+ write = self.stream.write
+
+ msgvar = "a" if toplevel else "mp"
+ msgsize = "l" if toplevel else "*len"
+
+ if o.modern_vla:
+ write(' char *p = cJSON_GetStringValue(item);\n')
+ write(' size_t plen = strlen(p);\n')
+ write(' {msgvar} = realloc({msgvar}, {msgsize} + plen);\n'
+ .format(msgvar=msgvar, msgsize=msgsize))
+ write(' vl_api_c_string_to_api_string(p, (void *){msgvar} + '
+ '{msgsize} - sizeof(vl_api_string_t));\n'
+ .format(msgvar=msgvar, msgsize=msgsize))
+ write(' {msgsize} += plen;\n'.format(msgsize=msgsize))
+ else:
+ write(' strncpy_s((char *)a->{n}, sizeof(a->{n}), '
+ 'cJSON_GetStringValue(item), sizeof(a->{n}) - 1);\n'
+ .format(n=o.fieldname))
+
+ def print_field(self, o, toplevel=False):
+ '''Called for every field in a typedef or define.'''
+ write = self.stream.write
+ write(' // start field {}\n'.format(o.fieldname))
+ if o.fieldname in self.noprint_fields:
+ return
+ is_bt = self.is_base_type(o.fieldtype)
+ t = 'vl_api_{}'.format(o.fieldtype) if is_bt else o.fieldtype
+
+ msgvar = "a" if toplevel else "mp"
+ msgsize = "&l" if toplevel else "len"
+
+ if is_bt:
+ write(' vl_api_{t}_fromjson(item, &a->{n});\n'
+ .format(t=o.fieldtype, n=o.fieldname))
+ else:
+ write(' {msgvar} = {t}_fromjson({msgvar}, '
+ '{msgsize}, item, &a->{n});\n'
+ .format(t=t, n=o.fieldname, msgvar=msgvar, msgsize=msgsize))
+ write(' if (!{msgvar}) return 0;\n'.format(msgvar=msgvar))
+
+ write(' // end field {}\n'.format(o.fieldname))
+
+ _dispatch['Field'] = print_field
+
+ def print_array(self, o, toplevel=False):
+ '''Convert JSON array to VPP API array'''
+ write = self.stream.write
+
+ forloop = '''\
+ {{
+ int i;
+ cJSON *array = cJSON_GetObjectItem(o, "{n}");
+ int size = cJSON_GetArraySize(array);
+ if (size != {lfield}) return 0;
+ for (i = 0; i < size; i++) {{
+ cJSON *e = cJSON_GetArrayItem(array, i);
+ {call}
+ }}
+ }}
+'''
+ forloop_vla = '''\
+ {{
+ int i;
+ cJSON *array = cJSON_GetObjectItem(o, "{n}");
+ int size = cJSON_GetArraySize(array);
+ {lfield} = size;
+ {msgvar} = realloc({msgvar}, {msgsize} + sizeof({t}) * size);
+ {t} *d = (void *){msgvar} + {msgsize};
+ {msgsize} += sizeof({t}) * size;
+ for (i = 0; i < size; i++) {{
+ cJSON *e = cJSON_GetArrayItem(array, i);
+ {call}
+ }}
+ }}
+'''
+ t = o.fieldtype
+ if o.fieldtype == 'string':
+ self.print_string(o, toplevel)
+ return
+
+ lfield = 'a->' + o.lengthfield if o.lengthfield else o.length
+ msgvar = "a" if toplevel else "mp"
+ msgsize = "l" if toplevel else "*len"
+
+ if o.fieldtype == 'u8':
+ if o.lengthfield:
+ write(' s = u8string_fromjson(o, "{}");\n'
+ .format(o.fieldname))
+ write(' if (!s) return 0;\n')
+ write(' {} = vec_len(s);\n'.format(lfield))
+
+ write(' {msgvar} = realloc({msgvar}, {msgsize} + '
+ 'vec_len(s));\n'.format(msgvar=msgvar, msgsize=msgsize))
+ write(' memcpy((void *){msgvar} + {msgsize}, s, '
+ 'vec_len(s));\n'.format(msgvar=msgvar, msgsize=msgsize))
+ write(' {msgsize} += vec_len(s);\n'.format(msgsize=msgsize))
+
+ write(' vec_free(s);\n')
+ else:
+ write(' u8string_fromjson2(o, "{n}", a->{n});\n'
+ .format(n=o.fieldname))
+ return
+
+ is_bt = self.is_base_type(o.fieldtype)
+
+ if o.lengthfield:
+ if is_bt:
+ call = ('vl_api_{t}_fromjson(e, &d[i]);'
+ .format(t=o.fieldtype))
+ else:
+ call = ('{t}_fromjson({msgvar}, len, e, &d[i]); '
+ .format(t=o.fieldtype, msgvar=msgvar))
+ write(forloop_vla.format(lfield=lfield,
+ t=o.fieldtype,
+ n=o.fieldname,
+ call=call,
+ msgvar=msgvar,
+ msgsize=msgsize))
+ else:
+ if is_bt:
+ call = ('vl_api_{t}_fromjson(e, &a->{n}[i]);'
+ .format(t=t, n=o.fieldname))
+ else:
+ call = ('a = {}_fromjson({}, len, e, &a->{}[i]);'
+ .format(t, msgvar, o.fieldname))
+ write(forloop.format(lfield=lfield,
+ t=t,
+ n=o.fieldname,
+ call=call,
+ msgvar=msgvar,
+ msgsize=msgsize))
+
+ _dispatch['Array'] = print_array
+
+ def print_enum(self, o):
+ '''Convert to JSON enum(string) to VPP API enum (int)'''
+ write = self.stream.write
+ write('static inline void *vl_api_{n}_t_fromjson '
+ '(void *mp, int *len, cJSON *o, vl_api_{n}_t *a) {{\n'
+ .format(n=o.name))
+ write(' char *p = cJSON_GetStringValue(o);\n')
+ for b in o.block:
+ write(' if (strcmp(p, "{}") == 0) {{*a = {}; return mp;}}\n'
+ .format(b[0], b[1]))
+ write(' return 0;\n')
+ write('}\n')
+
+ _dispatch['Enum'] = print_enum
+
+ def print_typedef(self, o):
+ '''Convert from JSON object to VPP API binary representation'''
+ write = self.stream.write
+
+ write('static inline void *vl_api_{name}_t_fromjson (void *mp, '
+ 'int *len, cJSON *o, vl_api_{name}_t *a) {{\n'
+ .format(name=o.name))
+ write(' cJSON *item __attribute__ ((unused));\n')
+ write(' u8 *s __attribute__ ((unused));\n')
+ for t in o.block:
+ if t.type == 'Field' and t.is_lengthfield:
+ continue
+ write(' item = cJSON_GetObjectItem(o, "{}");\n'
+ .format(t.fieldname))
+ write(' if (!item) return 0;\n')
+
+ self._dispatch[t.type](self, t)
+
+ write(' return mp;\n')
+ write('}\n')
+
+ def print_union(self, o):
+ '''Convert JSON object to VPP API binary union'''
+ write = self.stream.write
+
+ write('static inline void *vl_api_{name}_t_fromjson (void *mp, '
+ 'int *len, cJSON *o, vl_api_{name}_t *a) {{\n'
+ .format(name=o.name))
+ write(' cJSON *item __attribute__ ((unused));\n')
+ write(' u8 *s __attribute__ ((unused));\n')
+ for t in o.block:
+ if t.type == 'Field' and t.is_lengthfield:
+ continue
+ write(' item = cJSON_GetObjectItem(o, "{}");\n'
+ .format(t.fieldname))
+ write(' if (item) {\n')
+ self._dispatch[t.type](self, t)
+ write(' };\n')
+ write(' return mp;\n')
+ write('}\n')
+
+ def print_define(self, o):
+ '''Convert JSON object to VPP API message'''
+ write = self.stream.write
+ write('static inline vl_api_{name}_t *vl_api_{name}_t_fromjson '
+ '(cJSON *o, int *len) {{\n'.format(name=o.name))
+ write(' cJSON *item __attribute__ ((unused));\n')
+ write(' u8 *s __attribute__ ((unused));\n')
+ write(' int l = sizeof(vl_api_{}_t);\n'.format(o.name))
+ write(' vl_api_{}_t *a = malloc(l);\n'.format(o.name))
+
+ for t in o.block:
+ if t.fieldname in self.noprint_fields:
+ continue
+ if t.type == 'Field' and t.is_lengthfield:
+ continue
+ write(' // processing {}: {} {}\n'
+ .format(o.name, t.fieldtype, t.fieldname))
+
+ write(' item = cJSON_GetObjectItem(o, "{}");\n'
+ .format(t.fieldname))
+ write(' if (!item) return 0;\n')
+ self._dispatch[t.type](self, t, toplevel=True)
+ write('\n')
+
+ write('\n')
+ write(' *len = l;\n')
+ write(' return a;\n')
+ write('}\n')
+
+ def print_using(self, o):
+ '''Convert JSON field to VPP type alias'''
+ write = self.stream.write
+
+ if o.manual_print:
+ return
+
+ t = o.using
+ write('static inline void *vl_api_{name}_t_fromjson (void *mp, '
+ 'int *len, cJSON *o, vl_api_{name}_t *a) {{\n'
+ .format(name=o.name))
+ if 'length' in o.alias:
+ if t.fieldtype != 'u8':
+ raise ValueError("Error in processing type {} for {}"
+ .format(t.fieldtype, o.name))
+ write(' vl_api_u8_string_fromjson(o, (u8 *)a, {});\n'
+ .format(o.alias['length']))
+ else:
+ write(' vl_api_{t}_fromjson(o, ({t} *)a);\n'
+ .format(t=t.fieldtype))
+
+ write(' return mp;\n')
+ write('}\n')
+
+ _dispatch['Typedef'] = print_typedef
+ _dispatch['Define'] = print_define
+ _dispatch['Using'] = print_using
+ _dispatch['Union'] = print_union
+
+ def generate_function(self, t):
+ '''Main entry point'''
+ write = self.stream.write
+ if t.manual_print:
+ write('/* Manual print {} */\n'.format(t.name))
+ return
+ self._dispatch[t.type](self, t)
+
+ def generate_types(self):
+ '''Main entry point'''
+ for t in self.types:
+ self.generate_function(t)
+
+ def generate_defines(self):
+ '''Main entry point'''
+ for t in self.defines:
+ self.generate_function(t)
+
+
+def generate_tojson(s, modulename, stream):
+ '''Generate all functions to convert from API to JSON'''
+ write = stream.write
+
+ write('/* Imported API files */\n')
+ for i in s['Import']:
+ f = i.filename.replace('plugins/', '')
+ write('#include <{}_tojson.h>\n'.format(f))
+
+ pp = ToJSON(modulename, s['types'], s['Define'], s['imported']['types'],
+ stream)
+ pp.header()
+ pp.generate_types()
+ pp.generate_defines()
+ pp.footer()
+ return ''
+
+
+def generate_fromjson(s, modulename, stream):
+ '''Generate all functions to convert from JSON to API'''
+ write = stream.write
+ write('/* Imported API files */\n')
+ for i in s['Import']:
+ f = i.filename.replace('plugins/', '')
+ write('#include <{}_fromjson.h>\n'.format(f))
+
+ pp = FromJSON(modulename, s['types'], s['Define'], s['imported']['types'],
+ stream)
+ pp.header()
+ pp.generate_types()
+ pp.generate_defines()
+ pp.footer()
+
+ return ''
+
+###############################################################################
+
+
+DATESTRING = datetime.datetime.utcfromtimestamp(
int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
-input_filename = 'inputfil'
-top_boilerplate = '''\
+TOP_BOILERPLATE = '''\
/*
* VLIB API definitions {datestring}
* Input file: {input_filename}
@@ -32,7 +634,7 @@ top_boilerplate = '''\
#define VL_API_PACKED(x) x __attribute__ ((packed))
'''
-bottom_boilerplate = '''\
+BOTTOM_BOILERPLATE = '''\
/****** API CRC (whole file) *****/
#ifdef vl_api_version
@@ -43,6 +645,7 @@ vl_api_version({input_filename}, {file_crc:#08x})
def msg_ids(s):
+ '''Generate macro to map API message id to handler'''
output = '''\
/****** Message ID / handler enum ******/
@@ -59,6 +662,7 @@ def msg_ids(s):
def msg_names(s):
+ '''Generate calls to name mapping macro'''
output = '''\
/****** Message names ******/
@@ -75,6 +679,7 @@ def msg_names(s):
def msg_name_crc_list(s, suffix):
+ '''Generate list of names to CRC mappings'''
output = '''\
/****** Message name, crc list ******/
@@ -92,6 +697,7 @@ def msg_name_crc_list(s, suffix):
def api2c(fieldtype):
+ '''Map between API type names and internal VPP type names'''
mappingtable = {'string': 'vl_api_string_t', }
if fieldtype in mappingtable:
return mappingtable[fieldtype]
@@ -99,7 +705,7 @@ def api2c(fieldtype):
def typedefs(filename):
-
+ '''Include in the main files to the types file'''
output = '''\
/****** Typedefs ******/
@@ -111,7 +717,7 @@ def typedefs(filename):
return output
-format_strings = {'u8': '%u',
+FORMAT_STRINGS = {'u8': '%u',
'bool': '%u',
'i8': '%d',
'u16': '%u',
@@ -122,18 +728,20 @@ format_strings = {'u8': '%u',
'i64': '%lld',
'f64': '%.2f'}
-noprint_fields = {'_vl_msg_id': None,
- 'client_index': None,
- 'context': None}
-
class Printfun():
+ '''Functions for pretty printing VPP API messages'''
_dispatch = {}
+ noprint_fields = {'_vl_msg_id': None,
+ 'client_index': None,
+ 'context': None}
def __init__(self, stream):
self.stream = stream
- def print_string(self, o, stream):
+ @staticmethod
+ def print_string(o, stream):
+ '''Pretty print a vl_api_string_t'''
write = stream.write
if o.modern_vla:
write(' if (vl_api_string_len(&a->{f}) > 0) {{\n'
@@ -151,11 +759,12 @@ class Printfun():
.format(f=o.fieldname))
def print_field(self, o, stream):
+ '''Pretty print API field'''
write = stream.write
- if o.fieldname in noprint_fields:
+ if o.fieldname in self.noprint_fields:
return
- if o.fieldtype in format_strings:
- f = format_strings[o.fieldtype]
+ if o.fieldtype in FORMAT_STRINGS:
+ f = FORMAT_STRINGS[o.fieldtype]
write(' s = format(s, "\\n%U{n}: {f}", '
'format_white_space, indent, a->{n});\n'
.format(n=o.fieldname, f=f))
@@ -168,6 +777,7 @@ class Printfun():
_dispatch['Field'] = print_field
def print_array(self, o, stream):
+ '''Pretty print API array'''
write = stream.write
forloop = '''\
@@ -185,7 +795,8 @@ class Printfun():
'''
if o.fieldtype == 'string':
- return self.print_string(o, stream)
+ self.print_string(o, stream)
+ return
if o.fieldtype == 'u8':
if o.lengthfield:
@@ -199,29 +810,33 @@ class Printfun():
return
lfield = 'a->' + o.lengthfield if o.lengthfield else o.length
- if o.fieldtype in format_strings:
+ if o.fieldtype in FORMAT_STRINGS:
write(forloop_format.format(lfield=lfield,
- t=format_strings[o.fieldtype],
+ t=FORMAT_STRINGS[o.fieldtype],
n=o.fieldname))
else:
write(forloop.format(lfield=lfield, t=o.fieldtype, n=o.fieldname))
_dispatch['Array'] = print_array
- def print_alias(self, k, v, stream):
+ @staticmethod
+ def print_alias(k, v, stream):
+ '''Pretty print type alias'''
write = stream.write
if ('length' in v.alias and v.alias['length'] and
v.alias['type'] == 'u8'):
write(' return format(s, "%U", format_hex_bytes, a, {});\n'
.format(v.alias['length']))
- elif v.alias['type'] in format_strings:
+ elif v.alias['type'] in FORMAT_STRINGS:
write(' return format(s, "{}", *a);\n'
- .format(format_strings[v.alias['type']]))
+ .format(FORMAT_STRINGS[v.alias['type']]))
else:
write(' return format(s, "{} (print not implemented)");\n'
.format(k))
- def print_enum(self, o, stream):
+ @staticmethod
+ def print_enum(o, stream):
+ '''Pretty print API enum'''
write = stream.write
write(" switch(*a) {\n")
for b in o:
@@ -232,6 +847,7 @@ class Printfun():
_dispatch['Enum'] = print_enum
def print_obj(self, o, stream):
+ '''Entry point'''
write = stream.write
if o.type in self._dispatch:
@@ -242,6 +858,7 @@ class Printfun():
def printfun(objs, stream, modulename):
+ '''Main entry point for pretty print function generation'''
write = stream.write
h = '''\
@@ -294,6 +911,7 @@ static inline void *vl_api_{name}_t_print (vl_api_{name}_t *a, void *handle)
def printfun_types(objs, stream, modulename):
+ '''Pretty print API types'''
write = stream.write
pp = Printfun(stream)
@@ -345,7 +963,8 @@ static inline u8 *format_vl_api_{name}_t (u8 *s, va_list * args)
write("\n#endif /* vl_printfun_types */\n")
-def imports(imports):
+def generate_imports(imports):
+ '''Add #include matching the API import statements'''
output = '/* Imported API files */\n'
output += '#ifndef vl_api_version\n'
@@ -356,7 +975,7 @@ def imports(imports):
return output
-endian_strings = {
+ENDIAN_STRINGS = {
'u16': 'clib_net_to_host_u16',
'u32': 'clib_net_to_host_u32',
'u64': 'clib_net_to_host_u64',
@@ -368,6 +987,7 @@ endian_strings = {
def endianfun_array(o):
+ '''Generate endian functions for arrays'''
forloop = '''\
for (i = 0; i < {length}; i++) {{
a->{name}[i] = {format}(a->{name}[i]);
@@ -385,10 +1005,10 @@ def endianfun_array(o):
output += ' /* a->{n} = a->{n} (no-op) */\n'.format(n=o.fieldname)
else:
lfield = 'a->' + o.lengthfield if o.lengthfield else o.length
- if o.fieldtype in endian_strings:
+ if o.fieldtype in ENDIAN_STRINGS:
output += (forloop
.format(length=lfield,
- format=endian_strings[o.fieldtype],
+ format=ENDIAN_STRINGS[o.fieldtype],
name=o.fieldname))
else:
output += (forloop_format
@@ -396,23 +1016,26 @@ def endianfun_array(o):
name=o.fieldname))
return output
-no_endian_conversion = {'client_index': None}
+
+NO_ENDIAN_CONVERSION = {'client_index': None}
+
def endianfun_obj(o):
+ '''Generate endian conversion function for type'''
output = ''
if o.type == 'Array':
return endianfun_array(o)
- elif o.type != 'Field':
+ if o.type != 'Field':
output += (' s = format(s, "\\n{} {} {} (print not implemented");\n'
.format(o.type, o.fieldtype, o.fieldname))
return output
- if o.fieldname in no_endian_conversion:
+ if o.fieldname in NO_ENDIAN_CONVERSION:
output += ' /* a->{n} = a->{n} (no-op) */\n'.format(n=o.fieldname)
return output
- if o.fieldtype in endian_strings:
+ if o.fieldtype in ENDIAN_STRINGS:
output += (' a->{name} = {format}(a->{name});\n'
.format(name=o.fieldname,
- format=endian_strings[o.fieldtype]))
+ format=ENDIAN_STRINGS[o.fieldtype]))
elif o.fieldtype.startswith('vl_api_'):
output += (' {type}_endian(&a->{name});\n'
.format(type=o.fieldtype, name=o.fieldname))
@@ -423,6 +1046,7 @@ def endianfun_obj(o):
def endianfun(objs, modulename):
+ '''Main entry point for endian function generation'''
output = '''\
/****** Endian swap functions *****/\n\
@@ -449,9 +1073,9 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a)
for t in objs:
if t.__class__.__name__ == 'Enum':
output += signature.format(name=t.name)
- if t.enumtype in endian_strings:
+ if t.enumtype in ENDIAN_STRINGS:
output += (' *a = {}(*a);\n'
- .format(endian_strings[t.enumtype]))
+ .format(ENDIAN_STRINGS[t.enumtype]))
else:
output += (' /* a->{name} = a->{name} (no-op) */\n'
.format(name=t.name))
@@ -469,9 +1093,9 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a)
t.alias['type'] == 'u8'):
output += (' /* a->{name} = a->{name} (no-op) */\n'
.format(name=t.name))
- elif t.alias['type'] in format_strings:
+ elif t.alias['type'] in FORMAT_STRINGS:
output += (' *a = {}(*a);\n'
- .format(endian_strings[t.alias['type']]))
+ .format(ENDIAN_STRINGS[t.alias['type']]))
else:
output += ' /* Not Implemented yet {} */'.format(t.name)
output += '}\n\n'
@@ -490,6 +1114,7 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a)
def version_tuple(s, module):
+ '''Generate semantic version string'''
output = '''\
/****** Version tuple *****/
@@ -508,9 +1133,10 @@ def version_tuple(s, module):
def generate_include_enum(s, module, stream):
+ '''Generate <name>.api_enum.h'''
write = stream.write
- if len(s['Define']):
+ if 'Define' in s:
write('typedef enum {\n')
for t in s['Define']:
write(' VL_API_{},\n'.format(t.name.upper()))
@@ -518,7 +1144,8 @@ def generate_include_enum(s, module, stream):
write('}} vl_api_{}_enum_t;\n'.format(module))
-def generate_include_counters(s, module, stream):
+def generate_include_counters(s, stream):
+ '''Include file for the counter data model types.'''
write = stream.write
for counters in s:
@@ -530,14 +1157,11 @@ def generate_include_counters(s, module, stream):
write(' {}_N_ERROR\n'.format(csetname.upper()))
write('}} vl_counter_{}_enum_t;\n'.format(csetname))
- # write('extern char *{}_error_strings[];\n'.format(csetname))
- # write('extern char *{}_description_strings[];\n'.format(csetname))
write('extern vl_counter_t {}_error_counters[];\n'.format(csetname))
-#
-# Generate separate API _types file.
-#
+
def generate_include_types(s, module, stream):
+ '''Generate separate API _types file.'''
write = stream.write
write('#ifndef included_{module}_api_types_h\n'.format(module=module))
@@ -546,11 +1170,14 @@ def generate_include_types(s, module, stream):
if 'version' in s['Option']:
v = s['Option']['version']
(major, minor, patch) = v.split('.')
- write('#define VL_API_{m}_API_VERSION_MAJOR {v}\n'.format(m=module.upper(), v=major))
- write('#define VL_API_{m}_API_VERSION_MINOR {v}\n'.format(m=module.upper(), v=minor))
- write('#define VL_API_{m}_API_VERSION_PATCH {v}\n'.format(m=module.upper(), v=patch))
-
- if len(s['Import']):
+ write('#define VL_API_{m}_API_VERSION_MAJOR {v}\n'
+ .format(m=module.upper(), v=major))
+ write('#define VL_API_{m}_API_VERSION_MINOR {v}\n'
+ .format(m=module.upper(), v=minor))
+ write('#define VL_API_{m}_API_VERSION_PATCH {v}\n'
+ .format(m=module.upper(), v=patch))
+
+ if 'Import' in s:
write('/* Imported API files */\n')
for i in s['Import']:
filename = i.filename.replace('plugins/', '')
@@ -560,7 +1187,8 @@ def generate_include_types(s, module, stream):
tname = o.__class__.__name__
if tname == 'Using':
if 'length' in o.alias:
- write('typedef %s vl_api_%s_t[%s];\n' % (o.alias['type'], o.name, o.alias['length']))
+ write('typedef %s vl_api_%s_t[%s];\n' %
+ (o.alias['type'], o.name, o.alias['length']))
else:
write('typedef %s vl_api_%s_t;\n' % (o.alias['type'], o.name))
elif tname == 'Enum':
@@ -580,20 +1208,21 @@ def generate_include_types(s, module, stream):
% (size1, size2, err_str))
else:
if tname == 'Union':
- write("typedef union __attribute__ ((packed)) _vl_api_%s {\n" % o.name)
+ write("typedef union __attribute__ ((packed)) _vl_api_%s {\n"
+ % o.name)
else:
write(("typedef struct __attribute__ ((packed)) _vl_api_%s {\n")
- % o.name)
+ % o.name)
for b in o.block:
if b.type == 'Option':
continue
if b.type == 'Field':
- write(" %s %s;\n" % (api2c(b.fieldtype),
- b.fieldname))
+ write(" %s %s;\n" % (api2c(b.fieldtype),
+ b.fieldname))
elif b.type == 'Array':
if b.lengthfield:
- write(" %s %s[0];\n" % (api2c(b.fieldtype),
- b.fieldname))
+ write(" %s %s[0];\n" % (api2c(b.fieldtype),
+ b.fieldname))
else:
# Fixed length strings decay to nul terminated u8
if b.fieldtype == 'string':
@@ -623,6 +1252,7 @@ def generate_include_types(s, module, stream):
def generate_c_boilerplate(services, defines, counters, file_crc,
module, stream):
+ '''VPP side plugin.'''
write = stream.write
define_hash = {d.name: d for d in defines}
@@ -644,34 +1274,36 @@ def generate_c_boilerplate(services, defines, counters, file_crc,
write('setup_message_id_table (void) {\n')
write(' api_main_t *am = my_api_main;\n')
write(' vl_msg_api_msg_config_t c;\n')
- write(' u16 msg_id_base = vl_msg_api_get_msg_ids ("{}_{crc:08x}", VL_MSG_{m}_LAST);\n'
+ write(' u16 msg_id_base = vl_msg_api_get_msg_ids ("{}_{crc:08x}", '
+ 'VL_MSG_{m}_LAST);\n'
.format(module, crc=file_crc, m=module.upper()))
-
for d in defines:
write(' vl_msg_api_add_msg_name_crc (am, "{n}_{crc:08x}",\n'
' VL_API_{ID} + msg_id_base);\n'
.format(n=d.name, ID=d.name.upper(), crc=d.crc))
for s in services:
d = define_hash[s.caller]
- write(' c = (vl_msg_api_msg_config_t) {{.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'
- ' .is_autoendian = 0}};\n'
+ write(' c = (vl_msg_api_msg_config_t) '
+ ' {{.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'
+ ' .is_autoendian = 0}};\n'
.format(n=s.caller, ID=s.caller.upper()))
write(' vl_msg_api_config (&c);\n')
try:
d = define_hash[s.reply]
- write(' c = (vl_msg_api_msg_config_t) {{.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'
- ' .is_autoendian = 0}};\n'
+ write(' c = (vl_msg_api_msg_config_t) '
+ '{{.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'
+ ' .is_autoendian = 0}};\n'
.format(n=s.reply, ID=s.reply.upper()))
write(' vl_msg_api_config (&c);\n')
except KeyError:
@@ -686,16 +1318,6 @@ def generate_c_boilerplate(services, defines, counters, file_crc,
for cnt in counters:
csetname = cnt.name
- '''
- write('char *{}_error_strings[] = {{\n'.format(csetname))
- for c in cnt.block:
- write(' "{}",\n'.format(c['name']))
- write('};\n')
- write('char *{}_description_strings[] = {{\n'.format(csetname))
- for c in cnt.block:
- write(' "{}",\n'.format(c['description']))
- write('};\n')
- '''
write('vl_counter_t {}_error_counters[] = {{\n'.format(csetname))
for c in cnt.block:
write(' {\n')
@@ -705,14 +1327,16 @@ def generate_c_boilerplate(services, defines, counters, file_crc,
write(' },\n')
write('};\n')
-def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, stream):
+
+def generate_c_test_boilerplate(services, defines, file_crc, module, plugin,
+ stream):
+ '''Generate code for legacy style VAT. To be deleted.'''
write = stream.write
- define_hash = {d.name:d for d in defines}
- replies = {}
+ define_hash = {d.name: d for d in defines}
hdr = '''\
-#define vl_endianfun /* define message structures */
+#define vl_endianfun /* define message structures */
#include "{module}.api.h"
#undef vl_endianfun
@@ -728,19 +1352,23 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
for s in services:
try:
d = define_hash[s.reply]
- except:
+ except KeyError:
continue
if d.manual_print:
- write('/* Manual definition requested for: vl_api_{n}_t_handler() */\n'
+ write('/*\n'
+ ' * Manual definition requested for: \n'
+ ' * vl_api_{n}_t_handler()\n'
+ ' */\n'
.format(n=s.reply))
continue
if not define_hash[s.caller].autoreply:
- write('/* Only autoreply is supported (vl_api_{n}_t_handler()) */\n'
+ write('/* Generation not supported (vl_api_{n}_t_handler()) */\n'
.format(n=s.reply))
continue
write('#ifndef VL_API_{n}_T_HANDLER\n'.format(n=s.reply.upper()))
write('static void\n')
- write('vl_api_{n}_t_handler (vl_api_{n}_t * mp) {{\n'.format(n=s.reply))
+ write('vl_api_{n}_t_handler (vl_api_{n}_t * mp) {{\n'
+ .format(n=s.reply))
write(' vat_main_t * vam = {}_test_main.vat_main;\n'.format(module))
write(' i32 retval = ntohl(mp->retval);\n')
write(' if (vam->async_mode) {\n')
@@ -764,23 +1392,31 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
write('static void\n')
write('setup_message_id_table (vat_main_t * vam, u16 msg_id_base) {\n')
for s in services:
- write(' 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'
+ write(' 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'
' sizeof(vl_api_{n}_t), 1);\n'
.format(n=s.reply, ID=s.reply.upper()))
- write(' hash_set_mem (vam->function_by_name, "{n}", api_{n});\n'.format(n=s.caller))
+ write(' hash_set_mem (vam->function_by_name, "{n}", api_{n});\n'
+ .format(n=s.caller))
try:
write(' hash_set_mem (vam->help_by_name, "{n}", "{help}");\n'
- .format(n=s.caller, help=define_hash[s.caller].options['vat_help']))
- except:
+ .format(n=s.caller,
+ help=define_hash[s.caller].options['vat_help']))
+ except KeyError:
pass
# Events
for e in s.events:
- write(' 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'
+ write(' 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'
' sizeof(vl_api_{n}_t), 1);\n'
.format(n=e, ID=e.upper()))
@@ -788,14 +1424,17 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
if plugin:
write('clib_error_t * vat_plugin_register (vat_main_t *vam)\n')
else:
- write('clib_error_t * vat_{}_plugin_register (vat_main_t *vam)\n'.format(module))
+ write('clib_error_t * vat_{}_plugin_register (vat_main_t *vam)\n'
+ .format(module))
write('{\n')
write(' {n}_test_main_t * mainp = &{n}_test_main;\n'.format(n=module))
write(' mainp->vat_main = vam;\n')
- write(' mainp->msg_id_base = vl_client_get_first_plugin_msg_id ("{n}_{crc:08x}");\n'
+ write(' mainp->msg_id_base = vl_client_get_first_plugin_msg_id '
+ ' ("{n}_{crc:08x}");\n'
.format(n=module, crc=file_crc))
write(' if (mainp->msg_id_base == (u16) ~0)\n')
- write(' return clib_error_return (0, "{} plugin not loaded...");\n'.format(module))
+ write(' return clib_error_return (0, "{} plugin not loaded...");\n'
+ .format(module))
write(' setup_message_id_table (vam, mainp->msg_id_base);\n')
write('#ifdef VL_API_LOCAL_SETUP_MESSAGE_ID_TABLE\n')
write(' VL_API_LOCAL_SETUP_MESSAGE_ID_TABLE(vam);\n')
@@ -803,30 +1442,255 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
write(' return 0;\n')
write('}\n')
+
+def apifunc(func):
+ '''Check if a method is generated already.'''
+ def _f(module, d, processed, *args):
+ if d.name in processed:
+ return None
+ processed[d.name] = True
+ return func(module, d, *args)
+ return _f
+
+
+def c_test_api_service(s, dump, stream):
+ '''Generate JSON code for a service.'''
+ write = stream.write
+
+ req_reply_template = '''\
+static cJSON *
+api_{n} (cJSON *o)
+{{
+ vl_api_{n}_t *mp;
+ int len;
+ if (!o) return 0;
+ mp = vl_api_{n}_t_fromjson(o, &len);
+ if (!mp) {{
+ fprintf(stderr, "Failed converting JSON to API\\n");
+ return 0;
+ }}
+
+ mp->_vl_msg_id = vac_get_msg_index(VL_API_{N}_CRC);
+ vl_api_{n}_t_endian(mp);
+ vac_write((char *)mp, len);
+ free(mp);
+
+ /* Read reply */
+ char *p;
+ int l;
+ vac_read(&p, &l, 5); // XXX: Fix timeout
+ // XXX Will fail in case of event received. Do loop
+ if (ntohs(*((u16 *)p)) != vac_get_msg_index(VL_API_{R}_CRC)) {{
+ fprintf(stderr, "Mismatched reply\\n");
+ return 0;
+ }}
+ vl_api_{r}_t *rmp = (vl_api_{r}_t *)p;
+ vl_api_{r}_t_endian(rmp);
+ return vl_api_{r}_t_tojson(rmp);
+}}
+
+'''
+ dump_details_template = '''\
+static cJSON *
+api_{n} (cJSON *o)
+{{
+ u16 msg_id = vac_get_msg_index(VL_API_{N}_CRC);
+ int len;
+ if (!o) return 0;
+ vl_api_{n}_t *mp = vl_api_{n}_t_fromjson(o, &len);
+ if (!mp) {{
+ fprintf(stderr, "Failed converting JSON to API\\n");
+ return 0;
+ }}
+ mp->_vl_msg_id = msg_id;
+ vl_api_{n}_t_endian(mp);
+ vac_write((char *)mp, len);
+ free(mp);
+
+ vat2_control_ping(123); // FIX CONTEXT
+ cJSON *reply = cJSON_CreateArray();
+
+ u16 ping_reply_msg_id = vac_get_msg_index(VL_API_CONTROL_PING_REPLY_CRC);
+ u16 details_msg_id = vac_get_msg_index(VL_API_{R}_CRC);
+
+ while (1) {{
+ /* Read reply */
+ char *p;
+ int l;
+ vac_read(&p, &l, 5); // XXX: Fix timeout
+
+ /* Message can be one of [_details, control_ping_reply
+ * or unrelated event]
+ */
+ u16 reply_msg_id = ntohs(*((u16 *)p));
+ if (reply_msg_id == ping_reply_msg_id) {{
+ break;
+ }}
+
+ if (reply_msg_id == details_msg_id) {{
+ vl_api_{r}_t *rmp = (vl_api_{r}_t *)p;
+ vl_api_{r}_t_endian(rmp);
+ cJSON_AddItemToArray(reply, vl_api_{r}_t_tojson(rmp));
+ }}
+ }}
+ return reply;
+}}
+
+'''
+ gets_details_reply_template = '''\
+static cJSON *
+api_{n} (cJSON *o)
+{{
+ u16 msg_id = vac_get_msg_index(VL_API_{N}_CRC);
+ int len = 0;
+ if (!o) return 0;
+ vl_api_{n}_t *mp = vl_api_{n}_t_fromjson(o, &len);
+ if (!mp) {{
+ fprintf(stderr, "Failed converting JSON to API\\n");
+ return 0;
+ }}
+ mp->_vl_msg_id = msg_id;
+
+ vl_api_{n}_t_endian(mp);
+ vac_write((char *)mp, len);
+ free(mp);
+
+ cJSON *reply = cJSON_CreateArray();
+
+ u16 reply_msg_id = vac_get_msg_index(VL_API_{R}_CRC);
+ u16 details_msg_id = vac_get_msg_index(VL_API_{D}_CRC);
+
+ while (1) {{
+ /* Read reply */
+ char *p;
+ int l;
+ vac_read(&p, &l, 5); // XXX: Fix timeout
+
+ /* Message can be one of [_details, control_ping_reply
+ * or unrelated event]
+ */
+ u16 msg_id = ntohs(*((u16 *)p));
+ if (msg_id == reply_msg_id) {{
+ vl_api_{r}_t *rmp = (vl_api_{r}_t *)p;
+ vl_api_{r}_t_endian(rmp);
+ cJSON_AddItemToArray(reply, vl_api_{r}_t_tojson(rmp));
+ break;
+ }}
+
+ if (msg_id == details_msg_id) {{
+ vl_api_{d}_t *rmp = (vl_api_{d}_t *)p;
+ vl_api_{d}_t_endian(rmp);
+ cJSON_AddItemToArray(reply, vl_api_{d}_t_tojson(rmp));
+ }}
+ }}
+ return reply;
+}}
+
+'''
+
+ if dump:
+ if s.stream_message:
+ write(gets_details_reply_template
+ .format(n=s.caller, r=s.reply, N=s.caller.upper(),
+ R=s.reply.upper(), d=s.stream_message,
+ D=s.stream_message.upper()))
+ else:
+ write(dump_details_template.format(n=s.caller, r=s.reply,
+ N=s.caller.upper(),
+ R=s.reply.upper()))
+ else:
+ write(req_reply_template.format(n=s.caller, r=s.reply,
+ N=s.caller.upper(),
+ R=s.reply.upper()))
+
+
+def generate_c_test2_boilerplate(services, defines, module, stream):
+ '''Generate code for VAT2 plugin.'''
+ write = stream.write
+
+ define_hash = {d.name: d for d in defines}
+ # replies = {}
+
+ hdr = '''\
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+#include <vnet/ip/ip_format_fns.h>
+#include <vnet/ethernet/ethernet_format_fns.h>
+
+#define vl_typedefs /* define message structures */
+#include <vpp/api/vpe_all_api_h.h>
+#undef vl_typedefs
+
+#include "{module}.api_enum.h"
+#include "{module}.api_types.h"
+
+#define vl_endianfun /* define message structures */
+#include "{module}.api.h"
+#undef vl_endianfun
+
+#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
+#define vl_printfun
+#include "{module}.api.h"
+#undef vl_printfun
+
+#include "{module}.api_tojson.h"
+#include "{module}.api_fromjson.h"
+#include <vpp-api/client/vppapiclient.h>
+
+#include <vat2/vat2_helpers.h>
+
+'''
+
+ write(hdr.format(module=module))
+
+ for s in services:
+ if s.reply not in define_hash:
+ continue
+ c_test_api_service(s, s.stream, stream)
+
+ write('void vat2_register_function(char *, cJSON * (*)(cJSON *));\n')
+ # write('__attribute__((constructor))')
+ write('clib_error_t *\n')
+ write('vat2_register_plugin (void) {\n')
+ for s in services:
+ write(' vat2_register_function("{n}", api_{n});\n'
+ .format(n=s.caller))
+ write(' return 0;\n')
+ write('}\n')
+
+
#
# Plugin entry point
#
-def run(args, input_filename, s):
+def run(args, apifilename, s):
+ '''Main plugin entry point.'''
stream = StringIO()
if not args.outputdir:
sys.stderr.write('Missing --outputdir argument')
return None
- basename = os.path.basename(input_filename)
- filename, file_extension = os.path.splitext(basename)
+ basename = os.path.basename(apifilename)
+ filename, _ = os.path.splitext(basename)
modulename = filename.replace('.', '_')
filename_enum = os.path.join(args.outputdir + '/' + basename + '_enum.h')
filename_types = os.path.join(args.outputdir + '/' + basename + '_types.h')
filename_c = os.path.join(args.outputdir + '/' + basename + '.c')
filename_c_test = os.path.join(args.outputdir + '/' + basename + '_test.c')
+ filename_c_test2 = (os.path.join(args.outputdir + '/' + basename +
+ '_test2.c'))
+ filename_c_tojson = (os.path.join(args.outputdir +
+ '/' + basename + '_tojson.h'))
+ filename_c_fromjson = (os.path.join(args.outputdir + '/' +
+ basename + '_fromjson.h'))
# Generate separate types file
st = StringIO()
generate_include_types(s, modulename, st)
- with open (filename_types, 'w') as fd:
- st.seek (0)
- shutil.copyfileobj (st, fd)
+ with open(filename_types, 'w') as fd:
+ st.seek(0)
+ shutil.copyfileobj(st, fd)
st.close()
# Generate separate enum file
@@ -834,35 +1698,59 @@ def run(args, input_filename, s):
st.write('#ifndef included_{}_api_enum_h\n'.format(modulename))
st.write('#define included_{}_api_enum_h\n'.format(modulename))
generate_include_enum(s, modulename, st)
- generate_include_counters(s['Counters'], modulename, st)
+ generate_include_counters(s['Counters'], st)
st.write('#endif\n')
- with open (filename_enum, 'w') as fd:
- st.seek (0)
- shutil.copyfileobj (st, fd)
+ with open(filename_enum, 'w') as fd:
+ st.seek(0)
+ shutil.copyfileobj(st, fd)
st.close()
# Generate separate C file
st = StringIO()
generate_c_boilerplate(s['Service'], s['Define'], s['Counters'],
s['file_crc'], modulename, st)
- with open (filename_c, 'w') as fd:
- st.seek (0)
+ with open(filename_c, 'w') as fd:
+ st.seek(0)
shutil.copyfileobj(st, fd)
st.close()
# Generate separate C test file
st = StringIO()
- plugin = True if 'plugin' in input_filename else False
- generate_c_test_boilerplate(s['Service'], s['Define'], s['file_crc'],
+ plugin = bool('plugin' in apifilename)
+ generate_c_test_boilerplate(s['Service'], s['Define'],
+ s['file_crc'],
modulename, plugin, st)
- with open (filename_c_test, 'w') as fd:
- st.seek (0)
+ with open(filename_c_test, 'w') as fd:
+ st.seek(0)
+ shutil.copyfileobj(st, fd)
+ st.close()
+
+ # Fully autogenerated VATv2 C test file
+ st = StringIO()
+ generate_c_test2_boilerplate(s['Service'], s['Define'],
+ modulename, st)
+ with open(filename_c_test2, 'w') as fd:
+ st.seek(0)
+ shutil.copyfileobj(st, fd)
+ st.close() #
+
+ # Generate separate JSON file
+ st = StringIO()
+ generate_tojson(s, modulename, st)
+ with open(filename_c_tojson, 'w') as fd:
+ st.seek(0)
+ shutil.copyfileobj(st, fd)
+ st.close()
+ st = StringIO()
+ generate_fromjson(s, modulename, st)
+ with open(filename_c_fromjson, 'w') as fd:
+ st.seek(0)
shutil.copyfileobj(st, fd)
st.close()
- output = top_boilerplate.format(datestring=datestring,
+ output = TOP_BOILERPLATE.format(datestring=DATESTRING,
input_filename=basename)
- output += imports(s['Import'])
+ output += generate_imports(s['Import'])
output += msg_ids(s)
output += msg_names(s)
output += msg_name_crc_list(s, filename)
@@ -873,7 +1761,7 @@ def run(args, input_filename, s):
stream.close()
output += endianfun(s['types'] + s['Define'], modulename)
output += version_tuple(s, basename)
- output += bottom_boilerplate.format(input_filename=basename,
+ output += BOTTOM_BOILERPLATE.format(input_filename=basename,
file_crc=s['file_crc'])
return output