4 import ply.yacc as yacc
12 from subprocess import Popen, PIPE
14 assert sys.version_info >= (3, 6), \
15 "Not supported Python version: {}".format(sys.version)
16 log = logging.getLogger('vppapigen')
18 # Ensure we don't leave temporary files around
19 sys.dont_write_bytecode = True
25 # Global dictionary of new types (including enums)
31 def global_type_add(name, obj):
32 '''Add new type to the dictionary of types '''
33 type_name = 'vl_api_' + name + '_t'
34 if type_name in global_types:
35 raise KeyError("Attempted redefinition of {!r} with {!r}.".format(
37 global_types[type_name] = obj
40 # All your trace are belong to us!
41 def exception_handler(exception_type, exception, traceback):
42 print("%s: %s" % (exception_type.__name__, exception))
48 class VPPAPILexer(object):
49 def __init__(self, filename):
50 self.filename = filename
62 'typeonly': 'TYPEONLY',
63 'manual_print': 'MANUAL_PRINT',
64 'manual_endian': 'MANUAL_ENDIAN',
65 'dont_trace': 'DONT_TRACE',
66 'autoreply': 'AUTOREPLY',
85 tokens = ['STRING_LITERAL',
86 'ID', 'NUM'] + list(reserved.values())
88 t_ignore_LINE_COMMENT = '//.*'
101 r'0[xX][0-9a-fA-F]+|-?\d+\.?\d*'
102 base = 16 if t.value.startswith('0x') else 10
104 t.value = float(t.value)
106 t.value = int(t.value, base)
110 r'[a-zA-Z_][a-zA-Z_0-9]*'
111 # Check for reserved words
112 t.type = VPPAPILexer.reserved.get(t.value, 'ID')
116 def t_STRING_LITERAL(self, t):
117 r'\"([^\\\n]|(\\.))*?\"'
118 t.value = str(t.value).replace("\"", "")
121 # C or C++ comment (ignore)
122 def t_comment(self, t):
123 r'(/\*(.|\n)*?\*/)|(//.*)'
124 t.lexer.lineno += t.value.count('\n')
126 # Error handling rule
127 def t_error(self, t):
128 raise ParseError("Illegal character '{}' ({})"
129 "in {}: line {}".format(t.value[0],
130 hex(ord(t.value[0])),
135 # Define a rule so we can track line numbers
136 def t_newline(self, t):
138 t.lexer.lineno += len(t.value)
140 literals = ":{}[];=.,"
142 # A string containing ignored characters (spaces and tabs)
146 def crc_block_combine(block, crc):
147 s = str(block).encode()
148 return binascii.crc32(s, crc) & 0xffffffff
151 def vla_is_last_check(name, block):
153 for i, b in enumerate(block):
154 if isinstance(b, Array) and b.vla:
156 if i + 1 < len(block):
158 'VLA field "{}" must be the last field in message "{}"'
159 .format(b.fieldname, name))
160 elif b.fieldtype.startswith('vl_api_'):
161 if global_types[b.fieldtype].vla:
163 if i + 1 < len(block):
165 'VLA field "{}" must be the last '
166 'field in message "{}"'
167 .format(b.fieldname, name))
168 elif b.fieldtype == 'string' and b.length == 0:
170 if i + 1 < len(block):
172 'VLA field "{}" must be the last '
173 'field in message "{}"'
174 .format(b.fieldname, name))
179 def __init__(self, caller, reply, events=None, stream_message=None, stream=False):
183 self.stream_message = stream_message
184 self.events = [] if events is None else events
188 def __init__(self, name, flags, block):
192 self.crc = str(block).encode()
193 self.manual_print = False
194 self.manual_endian = False
196 if f == 'manual_print':
197 self.manual_print = True
198 elif f == 'manual_endian':
199 self.manual_endian = True
201 global_type_add(name, self)
203 self.vla = vla_is_last_check(name, block)
206 return self.name + str(self.flags) + str(self.block)
210 def __init__(self, name, flags, alias):
214 self.manual_print = True
215 self.manual_endian = True
217 self.manual_print = False
218 self.manual_endian = False
220 if f == 'manual_print':
221 self.manual_print = True
222 elif f == 'manual_endian':
223 self.manual_endian = True
225 if isinstance(alias, Array):
226 a = {'type': alias.fieldtype,
227 'length': alias.length}
229 a = {'type': alias.fieldtype}
231 self.crc = str(alias).encode()
232 global_type_add(name, self)
235 return self.name + str(self.alias)
239 def __init__(self, name, flags, block):
241 self.manual_print = False
242 self.manual_endian = False
246 if f == 'manual_print':
247 self.manual_print = True
248 elif f == 'manual_endian':
249 self.manual_endian = True
252 self.crc = str(block).encode()
253 self.vla = vla_is_last_check(name, block)
255 global_type_add(name, self)
258 return str(self.block)
262 def __init__(self, name, flags, block):
266 self.dont_trace = False
267 self.manual_print = False
268 self.manual_endian = False
269 self.autoreply = False
270 self.singular = False
273 if f == 'dont_trace':
274 self.dont_trace = True
275 elif f == 'manual_print':
276 self.manual_print = True
277 elif f == 'manual_endian':
278 self.manual_endian = True
279 elif f == 'autoreply':
280 self.autoreply = True
284 if isinstance(b, Option):
285 if b[1] == 'singular' and b[2] == 'true':
288 self.options[b.option] = b.value
291 block = [x for x in block if x not in remove]
293 self.vla = vla_is_last_check(name, block)
294 self.crc = str(block).encode()
297 return self.name + str(self.flags) + str(self.block)
301 def __init__(self, name, block, enumtype='u32'):
303 self.enumtype = enumtype
307 for i, b in enumerate(block):
312 block[i] = [b, count]
315 self.crc = str(block).encode()
316 global_type_add(name, self)
319 return self.name + str(self.block)
324 def __new__(cls, *args, **kwargs):
325 if args[0] not in seen_imports:
326 instance = super().__new__(cls)
327 instance._initialized = False
328 seen_imports[args[0]] = instance
330 return seen_imports[args[0]]
332 def __init__(self, filename, revision):
333 if self._initialized:
336 self.filename = filename
338 parser = VPPAPI(filename=filename, revision=revision)
339 dirlist = dirlist_get()
342 f = os.path.join(dir, filename)
343 if os.path.exists(f):
345 self.result = parser.parse_filename(f, None)
346 self._initialized = True
353 def __init__(self, option, value):
357 self.crc = str(option).encode()
360 return str(self.option)
362 def __getitem__(self, index):
363 return self.option[index]
367 def __init__(self, fieldtype, name, length, modern_vla=False):
369 self.fieldtype = fieldtype
370 self.fieldname = name
371 self.modern_vla = modern_vla
372 if type(length) is str:
373 self.lengthfield = length
378 self.lengthfield = None
382 return str([self.fieldtype, self.fieldname, self.length,
387 def __init__(self, fieldtype, name, limit=None):
389 self.fieldtype = fieldtype
391 if self.fieldtype == 'string':
392 raise ValueError("The string type {!r} is an "
393 "array type ".format(name))
395 if name in keyword.kwlist:
396 raise ValueError("Fieldname {!r} is a python keyword and is not "
397 "accessible via the python API. ".format(name))
398 self.fieldname = name
402 return str([self.fieldtype, self.fieldname])
406 """ Coordinates of a syntactic element. Consists of:
409 - (optional) column number, for the Lexer
411 __slots__ = ('file', 'line', 'column', '__weakref__')
413 def __init__(self, file, line, column=None):
419 str = "%s:%s" % (self.file, self.line)
421 str += ":%s" % self.column
425 class ParseError(Exception):
432 class VPPAPIParser(object):
433 tokens = VPPAPILexer.tokens
435 def __init__(self, filename, logger, revision=None):
436 self.filename = filename
439 self.revision = revision
441 def _parse_error(self, msg, coord):
442 raise ParseError("%s: %s" % (coord, msg))
444 def _parse_warning(self, msg, coord):
446 self.logger.warning("%s: %s" % (coord, msg))
448 def _coord(self, lineno, column=None):
451 line=lineno, column=column)
453 def _token_coord(self, p, token_idx):
454 """ Returns the coordinates for the YaccProduction object 'p' indexed
455 with 'token_idx'. The coordinate includes the 'lineno' and
456 'column'. Both follow the lex semantic, starting from 1.
458 last_cr = p.lexer.lexdata.rfind('\n', 0, p.lexpos(token_idx))
461 column = (p.lexpos(token_idx) - (last_cr))
462 return self._coord(p.lineno(token_idx), column)
464 def p_slist(self, p):
482 def p_import(self, p):
483 '''import : IMPORT STRING_LITERAL ';' '''
484 p[0] = Import(p[2], revision=self.revision)
486 def p_service(self, p):
487 '''service : SERVICE '{' service_statements '}' ';' '''
490 def p_service_statements(self, p):
491 '''service_statements : service_statement
492 | service_statements service_statement'''
498 def p_service_statement(self, p):
499 '''service_statement : RPC ID RETURNS NULL ';'
500 | RPC ID RETURNS ID ';'
501 | RPC ID RETURNS STREAM ID ';'
502 | RPC ID RETURNS ID EVENTS event_list ';' '''
504 # Verify that caller and reply differ
506 'Reply ID ({}) should not be equal to Caller ID'.format(p[2]),
507 self._token_coord(p, 1))
509 p[0] = Service(p[2], p[4], p[6])
511 p[0] = Service(p[2], p[5], stream=True)
513 p[0] = Service(p[2], p[4])
515 def p_service_statement2(self, p):
516 '''service_statement : RPC ID RETURNS ID STREAM ID ';' '''
517 p[0] = Service(p[2], p[4], stream_message=p[6], stream=True)
519 def p_event_list(self, p):
520 '''event_list : events
521 | event_list events '''
527 def p_event(self, p):
533 '''enum : ENUM ID '{' enum_statements '}' ';' '''
534 p[0] = Enum(p[2], p[4])
536 def p_enum_type(self, p):
537 ''' enum : ENUM ID ':' enum_size '{' enum_statements '}' ';' '''
539 p[0] = Enum(p[2], p[6], enumtype=p[4])
541 p[0] = Enum(p[2], p[4])
543 def p_enum_size(self, p):
549 def p_define(self, p):
550 '''define : DEFINE ID '{' block_statements_opt '}' ';' '''
552 p[0] = Define(p[2], [], p[4])
554 def p_define_flist(self, p):
555 '''define : flist DEFINE ID '{' block_statements_opt '}' ';' '''
557 if 'typeonly' in p[1]:
558 self._parse_error('legacy typedef. use typedef: {} {}[{}];'
559 .format(p[1], p[2], p[4]),
560 self._token_coord(p, 1))
562 p[0] = Define(p[3], p[1], p[5])
564 def p_flist(self, p):
573 '''flag : MANUAL_PRINT
582 def p_typedef(self, p):
583 '''typedef : TYPEDEF ID '{' block_statements_opt '}' ';' '''
584 p[0] = Typedef(p[2], [], p[4])
586 def p_typedef_flist(self, p):
587 '''typedef : flist TYPEDEF ID '{' block_statements_opt '}' ';' '''
588 p[0] = Typedef(p[3], p[1], p[5])
590 def p_typedef_alias(self, p):
591 '''typedef : TYPEDEF declaration '''
592 p[0] = Using(p[2].fieldname, [], p[2])
594 def p_typedef_alias_flist(self, p):
595 '''typedef : flist TYPEDEF declaration '''
596 p[0] = Using(p[3].fieldname, p[1], p[3])
598 def p_block_statements_opt(self, p):
599 '''block_statements_opt : block_statements '''
602 def p_block_statements(self, p):
603 '''block_statements : block_statement
604 | block_statements block_statement'''
610 def p_block_statement(self, p):
611 '''block_statement : declaration
615 def p_enum_statements(self, p):
616 '''enum_statements : enum_statement
617 | enum_statements enum_statement'''
623 def p_enum_statement(self, p):
624 '''enum_statement : ID '=' NUM ','
631 def p_field_options(self, p):
632 '''field_options : field_option
633 | field_options field_option'''
637 p[0] = {**p[1], **p[2]}
639 def p_field_option(self, p):
641 | ID '=' assignee ','
650 def p_declaration(self, p):
651 '''declaration : type_specifier ID ';'
652 | type_specifier ID '[' field_options ']' ';' '''
654 p[0] = Field(p[1], p[2], p[4])
656 p[0] = Field(p[1], p[2])
658 self._parse_error('ERROR', self._token_coord(p, 1))
659 self.fields.append(p[2])
661 def p_declaration_array_vla(self, p):
662 '''declaration : type_specifier ID '[' ']' ';' '''
663 p[0] = Array(p[1], p[2], 0, modern_vla=True)
665 def p_declaration_array(self, p):
666 '''declaration : type_specifier ID '[' NUM ']' ';'
667 | type_specifier ID '[' ID ']' ';' '''
670 return self._parse_error(
671 'array: %s' % p.value,
672 self._coord(lineno=p.lineno))
674 # Make this error later
675 if type(p[4]) is int and p[4] == 0:
676 # XXX: Line number is wrong
677 self._parse_warning('Old Style VLA: {} {}[{}];'
678 .format(p[1], p[2], p[4]),
679 self._token_coord(p, 1))
681 if type(p[4]) is str and p[4] not in self.fields:
682 # Verify that length field exists
683 self._parse_error('Missing length field: {} {}[{}];'
684 .format(p[1], p[2], p[4]),
685 self._token_coord(p, 1))
686 p[0] = Array(p[1], p[2], p[4])
688 def p_option(self, p):
689 '''option : OPTION ID '=' assignee ';' '''
690 p[0] = Option(p[2], p[4])
692 def p_assignee(self, p):
699 def p_type_specifier(self, p):
700 '''type_specifier : U8
713 # Do a second pass later to verify that user defined types are defined
714 def p_typedef_specifier(self, p):
715 '''type_specifier : ID '''
716 if p[1] not in global_types:
717 self._parse_error('Undefined type: {}'.format(p[1]),
718 self._token_coord(p, 1))
721 def p_union(self, p):
722 '''union : UNION ID '{' block_statements_opt '}' ';' '''
723 p[0] = Union(p[2], [], p[4])
725 def p_union_flist(self, p):
726 '''union : flist UNION ID '{' block_statements_opt '}' ';' '''
727 p[0] = Union(p[3], p[1], p[5])
729 # Error rule for syntax errors
730 def p_error(self, p):
733 'before: %s' % p.value,
734 self._coord(lineno=p.lineno))
736 self._parse_error('At end of input', self.filename)
739 class VPPAPI(object):
741 def __init__(self, debug=False, filename='', logger=None, revision=None):
742 self.lexer = lex.lex(module=VPPAPILexer(filename), debug=debug)
743 self.parser = yacc.yacc(module=VPPAPIParser(filename, logger,
745 write_tables=False, debug=debug)
747 self.revision = revision
748 self.filename = filename
750 def parse_string(self, code, debug=0, lineno=1):
751 self.lexer.lineno = lineno
752 return self.parser.parse(code, lexer=self.lexer, debug=debug)
754 def parse_fd(self, fd, debug=0):
756 return self.parse_string(data, debug=debug)
758 def parse_filename(self, filename, debug=0):
760 git_show = f'git show {self.revision}:{filename}'
761 proc = Popen(git_show.split(), stdout=PIPE, encoding='utf-8')
763 data, errs = proc.communicate()
764 if proc.returncode != 0:
765 print(f'File not found: {self.revision}:{filename}', file=sys.stderr)
767 return self.parse_string(data, debug=debug)
768 except Exception as e:
772 with open(filename, encoding='utf-8') as fd:
773 return self.parse_fd(fd, None)
774 except FileNotFoundError:
775 print(f'File not found: {filename}', file=sys.stderr)
778 def autoreply_block(self, name, parent):
779 block = [Field('u32', 'context'),
780 Field('i32', 'retval')]
781 # inherhit the parent's options
782 for k, v in parent.options.items():
783 block.append(Option(k, v))
784 return Define(name + '_reply', [], block)
786 def process(self, objs):
795 tname = o.__class__.__name__
797 crc = binascii.crc32(o.crc, crc) & 0xffffffff
798 except AttributeError:
800 if isinstance(o, Define):
803 s[tname].append(self.autoreply_block(o.name, o))
804 elif isinstance(o, Option):
805 s[tname][o.option] = o.value
806 elif type(o) is list:
808 if isinstance(o2, Service):
809 s['Service'].append(o2)
810 elif (isinstance(o, Enum) or
811 isinstance(o, Typedef) or
812 isinstance(o, Using) or
813 isinstance(o, Union)):
817 raise ValueError('Unknown class type: {} {}'
821 msgs = {d.name: d for d in s['Define']}
822 svcs = {s.caller: s for s in s['Service']}
823 replies = {s.reply: s for s in s['Service']}
829 if service not in msgs:
831 'Service definition refers to unknown message'
832 ' definition: {}'.format(service))
833 if svcs[service].reply != 'null' and \
834 svcs[service].reply not in msgs:
835 raise ValueError('Service definition refers to unknown message'
836 ' definition in reply: {}'
837 .format(svcs[service].reply))
838 if service in replies:
839 raise ValueError('Service definition refers to message'
840 ' marked as reply: {}'.format(service))
841 for event in svcs[service].events:
842 if event not in msgs:
843 raise ValueError('Service definition refers to unknown '
844 'event: {} in message: {}'
845 .format(event, service))
846 seen_services[event] = True
848 # Create services implicitly
850 if d in seen_services:
852 if msgs[d].singular is True:
854 if d.endswith('_reply'):
857 if d[:-6] not in msgs:
858 raise ValueError('{} missing calling message'
861 if d.endswith('_dump'):
864 if d[:-5]+'_details' in msgs:
865 s['Service'].append(Service(d, d[:-5]+'_details',
868 raise ValueError('{} missing details message'
872 if d.endswith('_details'):
873 if d[:-8]+'_dump' not in msgs:
874 raise ValueError('{} missing dump message'
880 if d+'_reply' in msgs:
881 s['Service'].append(Service(d, d+'_reply'))
884 '{} missing reply message ({}) or service definition'
885 .format(d, d+'_reply'))
889 def process_imports(self, objs, in_import, result):
892 # Only allow the following object types from imported file
893 if in_import and not (isinstance(o, Enum) or
894 isinstance(o, Union) or
895 isinstance(o, Typedef) or
896 isinstance(o, Import) or
897 isinstance(o, Using)):
899 if isinstance(o, Import):
901 result = self.process_imports(o.result, True, result)
907 # Add message ids to each message.
910 o.block.insert(0, Field('u16', '_vl_msg_id'))
917 def dirlist_add(dirs):
920 dirlist = dirlist + dirs
927 def foldup_blocks(block, crc):
929 # Look up CRC in user defined types
930 if b.fieldtype.startswith('vl_api_'):
932 t = global_types[b.fieldtype]
934 crc = crc_block_combine(t.block, crc)
935 crc = foldup_blocks(t.block, crc)
936 except AttributeError:
941 # keep the CRCs of the existing types of messages compatible with the
942 # old "erroneous" way of calculating the CRC. For that - make a pointed
943 # adjustment of the CRC function.
944 # This is the purpose of the first element of the per-message dictionary.
945 # The second element is there to avoid weakening the duplicate-detecting
946 # properties of crc32. This way, if the new way of calculating the CRC
947 # happens to collide with the old (buggy) way - we will still get
948 # a different result and fail the comparison.
951 "abf_policy_add_del": { 0xc6131197: 0xee66f93e },
952 "abf_policy_details": { 0xb7487fa4: 0x6769e504 },
953 "acl_add_replace": { 0xee5c2f18: 0x1cabdeab },
954 "acl_details": { 0x95babae0: 0x7a97f21c },
955 "macip_acl_add": { 0xce6fbad0: 0xd648fd0a },
956 "macip_acl_add_replace": { 0x2a461dd4: 0xe34402a7 },
957 "macip_acl_details": { 0x27135b59: 0x57c7482f },
958 "dhcp_proxy_config": { 0x4058a689: 0x6767230e },
959 "dhcp_client_config": { 0x1af013ea: 0x959b80a3 },
960 "dhcp_compl_event": { 0x554a44e5: 0xe908fd1d },
961 "dhcp_client_details": { 0x3c5cd28a: 0xacd82f5a },
962 "dhcp_proxy_details": { 0xdcbaf540: 0xce16f044 },
963 "dhcp6_send_client_message": { 0xf8222476: 0xf6f14ef0 },
964 "dhcp6_pd_send_client_message": { 0x3739fd8d: 0x64badb8 },
965 "dhcp6_reply_event": { 0x85b7b17e: 0x9f3af9e5 },
966 "dhcp6_pd_reply_event": { 0x5e878029: 0xcb3e462b },
967 "ip6_add_del_address_using_prefix": { 0x3982f30a: 0x9b3d11e0 },
968 "gbp_bridge_domain_add": { 0x918e8c01: 0x8454bfdf },
969 "gbp_bridge_domain_details": { 0x51d51be9: 0x2acd15f9 },
970 "gbp_route_domain_add": { 0x204c79e1: 0x2d0afe38 },
971 "gbp_route_domain_details": { 0xa78bfbca: 0x8ab11375 },
972 "gbp_endpoint_add": { 0x7b3af7de: 0x9ce16d5a },
973 "gbp_endpoint_details": { 0x8dd8fbd3: 0x8aecb60 },
974 "gbp_endpoint_group_add": { 0x301ddf15: 0x8e0f4054 },
975 "gbp_endpoint_group_details": { 0xab71d723: 0x8f38292c },
976 "gbp_subnet_add_del": { 0xa8803c80: 0x888aca35 },
977 "gbp_subnet_details": { 0xcbc5ca18: 0x4ed84156 },
978 "gbp_contract_add_del": { 0xaa8d652d: 0x553e275b },
979 "gbp_contract_details": { 0x65dec325: 0x2a18db6e },
980 "gbp_ext_itf_add_del": { 0x7606d0e1: 0x12ed5700 },
981 "gbp_ext_itf_details": { 0x519c3d3c: 0x408a45c0 },
982 "gtpu_add_del_tunnel": { 0xca983a2b: 0x9a9c0426 },
983 "gtpu_tunnel_update_tteid": { 0x79f33816: 0x8a2db108 },
984 "gtpu_tunnel_details": { 0x27f434ae: 0x4535cf95 },
985 "igmp_listen": { 0x19a49f1e: 0x3f93a51a },
986 "igmp_details": { 0x38f09929: 0x52f12a89 },
987 "igmp_event": { 0x85fe93ec: 0xd7696eaf },
988 "igmp_group_prefix_set": { 0x5b14a5ce: 0xd4f20ac5 },
989 "igmp_group_prefix_details": { 0x259ccd81: 0xc3b3c526 },
990 "ikev2_set_responder": { 0xb9aa4d4e: 0xf0d3dc80 },
991 "vxlan_gpe_ioam_export_enable_disable": { 0xd4c76d3a: 0xe4d4ebfa },
992 "ioam_export_ip6_enable_disable": { 0xd4c76d3a: 0xe4d4ebfa },
993 "vxlan_gpe_ioam_vni_enable": { 0xfbb5fb1: 0x997161fb },
994 "vxlan_gpe_ioam_vni_disable": { 0xfbb5fb1: 0x997161fb },
995 "vxlan_gpe_ioam_transit_enable": { 0x3d3ec657: 0x553f5b7b },
996 "vxlan_gpe_ioam_transit_disable": { 0x3d3ec657: 0x553f5b7b },
997 "udp_ping_add_del": { 0xfa2628fc: 0xc692b188 },
998 "l3xc_update": { 0xe96aabdf: 0x787b1d3 },
999 "l3xc_details": { 0xbc5bf852: 0xd4f69627 },
1000 "sw_interface_lacp_details": { 0xd9a83d2f: 0x745ae0ba },
1001 "lb_conf": { 0x56cd3261: 0x22ddb739 },
1002 "lb_add_del_vip": { 0x6fa569c7: 0xd15b7ddc },
1003 "lb_add_del_as": { 0x35d72500: 0x78628987 },
1004 "lb_vip_dump": { 0x56110cb7: 0xc7bcb124 },
1005 "lb_vip_details": { 0x1329ec9b: 0x8f39bed },
1006 "lb_as_details": { 0x8d24c29e: 0x9c39f60e },
1007 "mactime_add_del_range": { 0xcb56e877: 0x101858ef },
1008 "mactime_details": { 0xda25b13a: 0x44921c06 },
1009 "map_add_domain": { 0x249f195c: 0x7a5a18c9 },
1010 "map_domain_details": { 0x796edb50: 0xfc1859dd },
1011 "map_param_add_del_pre_resolve": { 0xdae5af03: 0x17008c66 },
1012 "map_param_get_reply": { 0x26272c90: 0x28092156 },
1013 "memif_details": { 0xda34feb9: 0xd0382c4c },
1014 "dslite_add_del_pool_addr_range": { 0xde2a5b02: 0xc448457a },
1015 "dslite_set_aftr_addr": { 0x78b50fdf: 0x1e955f8d },
1016 "dslite_get_aftr_addr_reply": { 0x8e23608e: 0x38e30db1 },
1017 "dslite_set_b4_addr": { 0x78b50fdf: 0x1e955f8d },
1018 "dslite_get_b4_addr_reply": { 0x8e23608e: 0x38e30db1 },
1019 "nat44_add_del_address_range": { 0x6f2b8055: 0xd4c7568c },
1020 "nat44_address_details": { 0xd1beac1: 0x45410ac4 },
1021 "nat44_add_del_static_mapping": { 0x5ae5f03e: 0xe165e83b },
1022 "nat44_static_mapping_details": { 0x6cb40b2: 0x1a433ef7 },
1023 "nat44_add_del_identity_mapping": { 0x2faaa22: 0x8e12743f },
1024 "nat44_identity_mapping_details": { 0x2a52a030: 0x36d21351 },
1025 "nat44_add_del_interface_addr": { 0x4aed50c0: 0xfc835325 },
1026 "nat44_interface_addr_details": { 0xe4aca9ca: 0x3e687514 },
1027 "nat44_user_session_details": { 0x2cf6e16d: 0x1965fd69 },
1028 "nat44_add_del_lb_static_mapping": { 0x4f68ee9d: 0x53b24611 },
1029 "nat44_lb_static_mapping_add_del_local": { 0x7ca47547: 0x2910a151 },
1030 "nat44_lb_static_mapping_details": { 0xed5ce876: 0x2267b9e8 },
1031 "nat44_del_session": { 0x15a5bf8c: 0x4c49c387 },
1032 "nat_det_add_del_map": { 0x1150a190: 0x112fde05 },
1033 "nat_det_map_details": { 0xad91dc83: 0x88000ee1 },
1034 "nat_det_close_session_out": { 0xf6b259d1: 0xc1b6cbfb },
1035 "nat_det_close_session_in": { 0x3c68e073: 0xa10ef64 },
1036 "nat64_add_del_pool_addr_range": { 0xa3b944e3: 0x21234ef3 },
1037 "nat64_add_del_static_bib": { 0x1c404de5: 0x90fae58a },
1038 "nat64_bib_details": { 0x43bc3ddf: 0x62c8541d },
1039 "nat64_st_details": { 0xdd3361ed: 0xc770d620 },
1040 "nat66_add_del_static_mapping": { 0x3ed88f71: 0xfb64e50b },
1041 "nat66_static_mapping_details": { 0xdf39654b: 0x5c568448 },
1042 "nsh_add_del_map": { 0xa0f42b0: 0x898d857d },
1043 "nsh_map_details": { 0x2fefcf49: 0xb34ac8a1 },
1044 "nsim_cross_connect_enable_disable": { 0x9c3ead86: 0x16f70bdf },
1045 "pppoe_add_del_session": { 0xf6fd759e: 0x46ace853 },
1046 "pppoe_session_details": { 0x4b8e8a4a: 0x332bc742 },
1047 "stn_add_del_rule": { 0x224c6edd: 0x53f751e6 },
1048 "stn_rules_details": { 0xa51935a6: 0xb0f6606c },
1049 "svs_route_add_del": { 0xe49bc63c: 0xd39e31fc },
1050 "svs_details": { 0x6282cd55: 0xb8523d64 },
1051 "vmxnet3_details": { 0x6a1a5498: 0x829ba055 },
1052 "vrrp_vr_add_del": { 0xc5cf15aa: 0x6dc4b881 },
1053 "vrrp_vr_details": { 0x46edcebd: 0x412fa71 },
1054 "vrrp_vr_set_peers": { 0x20bec71f: 0xbaa2e52b },
1055 "vrrp_vr_peer_details": { 0x3d99c108: 0xabd9145e },
1056 "vrrp_vr_track_if_add_del": { 0xd67df299: 0x337f4ba4 },
1057 "vrrp_vr_track_if_details": { 0x73c36f81: 0x99bcca9c },
1058 "proxy_arp_add_del": { 0x1823c3e7: 0x85486cbd },
1059 "proxy_arp_details": { 0x5b948673: 0x9228c150 },
1060 "bfd_udp_get_echo_source_reply": { 0xe3d736a1: 0x1e00cfce },
1061 "bfd_udp_add": { 0x939cd26a: 0x7a6d1185 },
1062 "bfd_udp_mod": { 0x913df085: 0x783a3ff6 },
1063 "bfd_udp_del": { 0xdcb13a89: 0x8096514d },
1064 "bfd_udp_session_details": { 0x9fb2f2d: 0x60653c02 },
1065 "bfd_udp_session_set_flags": { 0x4b4bdfd: 0xcf313851 },
1066 "bfd_udp_auth_activate": { 0x21fd1bdb: 0x493ee0ec },
1067 "bfd_udp_auth_deactivate": { 0x9a05e2e0: 0x99978c32 },
1068 "bier_route_add_del": { 0xfd02f3ea: 0xf29edca0 },
1069 "bier_route_details": { 0x4008caee: 0x39ee6a56 },
1070 "bier_disp_entry_add_del": { 0x9eb80cb4: 0x648323eb },
1071 "bier_disp_entry_details": { 0x84c218f1: 0xe5b039a9 },
1072 "bond_create": { 0xf1dbd4ff: 0x48883c7e },
1073 "bond_enslave": { 0xe7d14948: 0x76ecfa7 },
1074 "sw_interface_bond_details": { 0xbb7c929b: 0xf5ef2106 },
1075 "pipe_create_reply": { 0xb7ce310c: 0xd4c2c2b3 },
1076 "pipe_details": { 0xc52b799d: 0x43ac107a },
1077 "tap_create_v2": { 0x2d0d6570: 0x445835fd },
1078 "sw_interface_tap_v2_details": { 0x1e2b2a47: 0xe53c16de },
1079 "sw_interface_vhost_user_details": { 0xcee1e53: 0x98530df1 },
1080 "virtio_pci_create": { 0x1944f8db: 0xa9f1370c },
1081 "sw_interface_virtio_pci_details": { 0x6ca9c167: 0x16187f3a },
1082 "p2p_ethernet_add": { 0x36a1a6dc: 0xeeb8e717 },
1083 "p2p_ethernet_del": { 0x62f81c8c: 0xb62c386 },
1084 "geneve_add_del_tunnel": { 0x99445831: 0x976693b5 },
1085 "geneve_tunnel_details": { 0x6b16eb24: 0xe27e2748 },
1086 "gre_tunnel_add_del": { 0xa27d7f17: 0x6efc9c22 },
1087 "gre_tunnel_details": { 0x24435433: 0x3bfbf1 },
1088 "sw_interface_set_flags": { 0xf5aec1b8: 0x6a2b491a },
1089 "sw_interface_event": { 0x2d3d95a7: 0xf709f78d },
1090 "sw_interface_details": { 0x6c221fc7: 0x17b69fa2 },
1091 "sw_interface_add_del_address": { 0x5463d73b: 0x5803d5c4 },
1092 "sw_interface_set_unnumbered": { 0x154a6439: 0x938ef33b },
1093 "sw_interface_set_mac_address": { 0xc536e7eb: 0x6aca746a },
1094 "sw_interface_set_rx_mode": { 0xb04d1cfe: 0x780f5cee },
1095 "sw_interface_rx_placement_details": { 0x9e44a7ce: 0xf6d7d024 },
1096 "create_subif": { 0x790ca755: 0xcb371063 },
1097 "ip_neighbor_add_del": { 0x607c257: 0x105518b6 },
1098 "ip_neighbor_dump": { 0xd817a484: 0xcd831298 },
1099 "ip_neighbor_details": { 0xe29d79f0: 0x870e80b9 },
1100 "want_ip_neighbor_events": { 0x73e70a86: 0x1a312870 },
1101 "ip_neighbor_event": { 0xbdb092b2: 0x83933131 },
1102 "ip_route_add_del": { 0xb8ecfe0d: 0xc1ff832d },
1103 "ip_route_details": { 0xbda8f315: 0xd1ffaae1 },
1104 "ip_route_lookup": { 0x710d6471: 0xe2986185 },
1105 "ip_route_lookup_reply": { 0x5d8febcb: 0xae99de8e },
1106 "ip_mroute_add_del": { 0x85d762f3: 0xf6627d17 },
1107 "ip_mroute_details": { 0x99341a45: 0xc1cb4b44 },
1108 "ip_address_details": { 0xee29b797: 0xb1199745 },
1109 "ip_unnumbered_details": { 0xcc59bd42: 0xaa12a483 },
1110 "mfib_signal_details": { 0x6f4a4cfb: 0x64398a9a },
1111 "ip_punt_redirect": { 0x6580f635: 0xa9a5592c },
1112 "ip_punt_redirect_details": { 0x2cef63e7: 0x3924f5d3 },
1113 "ip_container_proxy_add_del": { 0x7df1dff1: 0x91189f40 },
1114 "ip_container_proxy_details": { 0xa8085523: 0xee460e8 },
1115 "ip_source_and_port_range_check_add_del": { 0x92a067e3: 0x8bfc76f2 },
1116 "sw_interface_ip6_set_link_local_address": { 0x1c10f15f: 0x2931d9fa },
1117 "ip_reassembly_enable_disable": { 0xeb77968d: 0x885c85a6 },
1118 "set_punt": { 0xaa83d523: 0x83799618 },
1119 "punt_socket_register": { 0x95268cbf: 0xc8cd10fa },
1120 "punt_socket_details": { 0xde575080: 0x1de0ce75 },
1121 "punt_socket_deregister": { 0x98fc9102: 0x98a444f4 },
1122 "sw_interface_ip6nd_ra_prefix": { 0x82cc1b28: 0xe098785f },
1123 "ip6nd_proxy_add_del": { 0xc2e4a686: 0x3fdf6659 },
1124 "ip6nd_proxy_details": { 0x30b9ff4a: 0xd35be8ff },
1125 "ip6_ra_event": { 0x364c1c5: 0x47e8cfbe },
1126 "set_ipfix_exporter": { 0x5530c8a0: 0x69284e07 },
1127 "ipfix_exporter_details": { 0xdedbfe4: 0x11e07413 },
1128 "ipip_add_tunnel": { 0x2ac399f5: 0xa9decfcd },
1129 "ipip_6rd_add_tunnel": { 0xb9ec1863: 0x56e93cc0 },
1130 "ipip_tunnel_details": { 0xd31cb34e: 0x53236d75 },
1131 "ipsec_spd_entry_add_del": { 0x338b7411: 0x9f384b8d },
1132 "ipsec_spd_details": { 0x5813d7a2: 0xf2222790 },
1133 "ipsec_sad_entry_add_del": { 0xab64b5c6: 0xb8def364 },
1134 "ipsec_tunnel_protect_update": { 0x30d5f133: 0x143f155d },
1135 "ipsec_tunnel_protect_del": { 0xcd239930: 0xddd2ba36 },
1136 "ipsec_tunnel_protect_details": { 0x21663a50: 0xac6c823b },
1137 "ipsec_tunnel_if_add_del": { 0x20e353fa: 0x2b135e68 },
1138 "ipsec_sa_details": { 0x345d14a7: 0xb30c7f41 },
1139 "l2_xconnect_details": { 0x472b6b67: 0xc8aa6b37 },
1140 "l2_fib_table_details": { 0xa44ef6b8: 0xe8d2fc72 },
1141 "l2fib_add_del": { 0xeddda487: 0xf29d796c },
1142 "l2_macs_event": { 0x44b8fd64: 0x2eadfc8b },
1143 "bridge_domain_details": { 0xfa506fd: 0x979f549d },
1144 "l2_interface_pbb_tag_rewrite": { 0x38e802a8: 0x612efa5a },
1145 "l2_patch_add_del": { 0xa1f6a6f3: 0x522f3445 },
1146 "sw_interface_set_l2_xconnect": { 0x4fa28a85: 0x1aaa2dbb },
1147 "sw_interface_set_l2_bridge": { 0xd0678b13: 0x2e483cd0 },
1148 "bd_ip_mac_add_del": { 0x257c869: 0x5f2b84e2 },
1149 "bd_ip_mac_details": { 0x545af86a: 0xa52f8044 },
1150 "l2_arp_term_event": { 0x6963e07a: 0x85ff71ea },
1151 "l2tpv3_create_tunnel": { 0x15bed0c2: 0x596892cb },
1152 "sw_if_l2tpv3_tunnel_details": { 0x50b88993: 0x1dab5c7e },
1153 "lisp_add_del_local_eid": { 0x4e5a83a2: 0x21f573bd },
1154 "lisp_add_del_map_server": { 0xce19e32d: 0x6598ea7c },
1155 "lisp_add_del_map_resolver": { 0xce19e32d: 0x6598ea7c },
1156 "lisp_use_petr": { 0xd87dbad9: 0x9e141831 },
1157 "show_lisp_use_petr_reply": { 0x22b9a4b0: 0xdcad8a81 },
1158 "lisp_add_del_remote_mapping": { 0x6d5c789e: 0xfae8ed77 },
1159 "lisp_add_del_adjacency": { 0x2ce0e6f6: 0xcf5edb61 },
1160 "lisp_locator_details": { 0x2c620ffe: 0xc0c4c2a7 },
1161 "lisp_eid_table_details": { 0x1c29f792: 0x4bc32e3a },
1162 "lisp_eid_table_dump": { 0x629468b5: 0xb959b73b },
1163 "lisp_adjacencies_get_reply": { 0x807257bf: 0x3f97bcdd },
1164 "lisp_map_resolver_details": { 0x3e78fc57: 0x82a09deb },
1165 "lisp_map_server_details": { 0x3e78fc57: 0x82a09deb },
1166 "one_add_del_local_eid": { 0x4e5a83a2: 0x21f573bd },
1167 "one_add_del_map_server": { 0xce19e32d: 0x6598ea7c },
1168 "one_add_del_map_resolver": { 0xce19e32d: 0x6598ea7c },
1169 "one_use_petr": { 0xd87dbad9: 0x9e141831 },
1170 "show_one_use_petr_reply": { 0x84a03528: 0x10e744a6 },
1171 "one_add_del_remote_mapping": { 0x6d5c789e: 0xfae8ed77 },
1172 "one_add_del_l2_arp_entry": { 0x1aa5e8b3: 0x33209078 },
1173 "one_l2_arp_entries_get_reply": { 0xb0dd200f: 0xb0a47bbe },
1174 "one_add_del_ndp_entry": { 0xf8a287c: 0xd1629a2f },
1175 "one_ndp_entries_get_reply": { 0x70719b1a: 0xbd34161 },
1176 "one_add_del_adjacency": { 0x9e830312: 0xe48e7afe },
1177 "one_locator_details": { 0x2c620ffe: 0xc0c4c2a7 },
1178 "one_eid_table_details": { 0x1c29f792: 0x4bc32e3a },
1179 "one_eid_table_dump": { 0xbd190269: 0x95151038 },
1180 "one_adjacencies_get_reply": { 0x85bab89: 0xa8ed89a5 },
1181 "one_map_resolver_details": { 0x3e78fc57: 0x82a09deb },
1182 "one_map_server_details": { 0x3e78fc57: 0x82a09deb },
1183 "one_stats_details": { 0x2eb74678: 0xff6ef238 },
1184 "gpe_add_del_fwd_entry": { 0xf0847644: 0xde6df50f },
1185 "gpe_fwd_entries_get_reply": { 0xc4844876: 0xf9f53f1b },
1186 "gpe_fwd_entry_path_details": { 0x483df51a: 0xee80b19a },
1187 "gpe_add_del_native_fwd_rpath": { 0x43fc8b54: 0x812da2f2 },
1188 "gpe_native_fwd_rpaths_get_reply": { 0x7a1ca5a2: 0x79d54eb9 },
1189 "sw_interface_set_lldp": { 0x57afbcd4: 0xd646ae0f },
1190 "mpls_ip_bind_unbind": { 0xc7533b32: 0x48249a27 },
1191 "mpls_tunnel_add_del": { 0x44350ac1: 0xe57ce61d },
1192 "mpls_tunnel_details": { 0x57118ae3: 0xf3c0928e },
1193 "mpls_route_add_del": { 0x8e1d1e07: 0x343cff54 },
1194 "mpls_route_details": { 0x9b5043dc: 0xd0ac384c },
1195 "policer_add_del": { 0x2b31dd38: 0xcb948f6e },
1196 "policer_details": { 0x72d0e248: 0xa43f781a },
1197 "qos_store_enable_disable": { 0xf3abcc8b: 0x3507235e },
1198 "qos_store_details": { 0x3ee0aad7: 0x38a6d48 },
1199 "qos_record_enable_disable": { 0x2f1a4a38: 0x25b33f88 },
1200 "qos_record_details": { 0xa425d4d3: 0x4956ccdd },
1201 "session_rule_add_del": { 0xe4895422: 0xe31f9443 },
1202 "session_rules_details": { 0x28d71830: 0x304b91f0 },
1203 "sw_interface_span_enable_disable": { 0x23ddd96b: 0xacc8fea1 },
1204 "sw_interface_span_details": { 0x8a20e79f: 0x55643fc },
1205 "sr_mpls_steering_add_del": { 0x64acff63: 0x7d1b0a0b },
1206 "sr_mpls_policy_assign_endpoint_color": { 0xe7eb978: 0x5e1c5c13 },
1207 "sr_localsid_add_del": { 0x5a36c324: 0x26fa3309 },
1208 "sr_policy_add": { 0x44ac92e8: 0xec79ee6a },
1209 "sr_policy_mod": { 0xb97bb56e: 0xe531a102 },
1210 "sr_steering_add_del": { 0xe46b0a0f: 0x3711dace },
1211 "sr_localsids_details": { 0x2e9221b9: 0x6a6c0265 },
1212 "sr_policies_details": { 0xdb6ff2a1: 0x7ec2d93 },
1213 "sr_steering_pol_details": { 0xd41258c9: 0x1c1ee786 },
1214 "syslog_set_sender": { 0xb8011d0b: 0xbb641285 },
1215 "syslog_get_sender_reply": { 0x424cfa4e: 0xd3da60ac },
1216 "tcp_configure_src_addresses": { 0x67eede0d: 0x4b02b946 },
1217 "teib_entry_add_del": { 0x8016cfd2: 0x5aa0a538 },
1218 "teib_details": { 0x981ee1a1: 0xe3b6a503 },
1219 "udp_encap_add": { 0xf74a60b1: 0x61d5fc48 },
1220 "udp_encap_details": { 0x8cfb9c76: 0x87c82821 },
1221 "vxlan_gbp_tunnel_add_del": { 0x6c743427: 0x8c819166 },
1222 "vxlan_gbp_tunnel_details": { 0x66e94a89: 0x1da24016 },
1223 "vxlan_gpe_add_del_tunnel": { 0xa645b2b0: 0x7c6da6ae },
1224 "vxlan_gpe_tunnel_details": { 0x968fc8b: 0x57712346 },
1225 "vxlan_add_del_tunnel": { 0xc09dc80: 0xa35dc8f5 },
1226 "vxlan_tunnel_details": { 0xc3916cb1: 0xe782f70f },
1227 "vxlan_offload_rx": { 0x9cc95087: 0x89a1564b },
1228 "log_details": { 0x3d61cc0: 0x255827a1 },
1234 f.crc = foldup_blocks(f.block,
1235 binascii.crc32(f.crc) & 0xffffffff)
1237 # fixup the CRCs to make the fix seamless
1238 if f.name in fixup_crc_dict:
1239 if f.crc in fixup_crc_dict.get(f.name):
1240 f.crc = fixup_crc_dict.get(f.name).get(f.crc)
1246 if sys.version_info < (3, 5,):
1247 log.exception('vppapigen requires a supported version of python. '
1248 'Please use version 3.5 or greater. '
1249 'Using {}'.format(sys.version))
1252 cliparser = argparse.ArgumentParser(description='VPP API generator')
1253 cliparser.add_argument('--pluginpath', default=""),
1254 cliparser.add_argument('--includedir', action='append'),
1255 cliparser.add_argument('--outputdir', action='store'),
1256 cliparser.add_argument('--input')
1257 cliparser.add_argument('--output', nargs='?',
1258 type=argparse.FileType('w', encoding='UTF-8'),
1261 cliparser.add_argument('output_module', nargs='?', default='C')
1262 cliparser.add_argument('--debug', action='store_true')
1263 cliparser.add_argument('--show-name', nargs=1)
1264 cliparser.add_argument('--git-revision',
1265 help="Git revision to use for opening files")
1266 args = cliparser.parse_args()
1268 dirlist_add(args.includedir)
1270 sys.excepthook = exception_handler
1274 filename = args.show_name[0]
1276 filename = args.input
1281 logging.basicConfig(stream=sys.stdout, level=logging.WARNING)
1283 logging.basicConfig()
1285 parser = VPPAPI(debug=args.debug, filename=filename, logger=log,
1286 revision=args.git_revision)
1290 parsed_objects = parser.parse_fd(sys.stdin, log)
1292 parsed_objects = parser.parse_filename(args.input, log)
1293 except ParseError as e:
1294 print('Parse error: ', e, file=sys.stderr)
1297 # Build a list of objects. Hash of lists.
1300 if args.output_module == 'C':
1301 s = parser.process(parsed_objects)
1303 result = parser.process_imports(parsed_objects, False, result)
1304 s = parser.process(result)
1307 s['Define'] = add_msg_id(s['Define'])
1310 foldup_crcs(s['Define'])
1316 pp = pprint.PrettyPrinter(indent=4, stream=sys.stderr)
1317 for t in s['Define']:
1318 pp.pprint([t.name, t.flags, t.block])
1319 for t in s['types']:
1320 pp.pprint([t.name, t.block])
1323 # Generate representation
1325 from importlib.machinery import SourceFileLoader
1329 if not args.pluginpath:
1331 cand.append(os.path.dirname(os.path.realpath(__file__)))
1332 cand.append(os.path.dirname(os.path.realpath(__file__)) +
1336 if os.path.isfile('{}vppapigen_{}.py'
1337 .format(c, args.output_module.lower())):
1341 pluginpath = args.pluginpath + '/'
1342 if pluginpath == '':
1343 log.exception('Output plugin not found')
1345 module_path = '{}vppapigen_{}.py'.format(pluginpath,
1346 args.output_module.lower())
1349 plugin = SourceFileLoader(args.output_module,
1350 module_path).load_module()
1351 except Exception as err:
1352 log.exception('Error importing output plugin: {}, {}'
1353 .format(module_path, err))
1356 result = plugin.run(args, filename, s)
1358 print(result, file=args.output)
1360 log.exception('Running plugin failed: {} {}'
1361 .format(filename, result))
1366 if __name__ == '__main__':