API descriptors
vppapigen creates, for every .api file which defines messages, a const
description of its messages and types in <file>.api_desc.c, which is
compiled into the plugin or the library of the file. The plugin registers it with
vl_api_desc_register () when it sets up its message ids, so that generic code
can work with any message without functions which are generated for each message.
The messages of memclnt.api and of srmpls, which are registered by hand,
have descriptors too.
A descriptor has, for the file, its name, its CRC and its options, and for every message and type:
the name, the kind (message, typedef, union, enum,
enumflagor alias), the CRC and the options of a message, its brief description from the\briefof its comment, and for a request message the message which answers it and the message of the details of a dump,for every field its name, its kind, its offset and size in the packed C structure, the length of a fixed array, the field which has the length of a variable length array, whether it is a string, for a tagged union the field which has the tag and the name and the value of the tag of each arm, whether it is converted to network byte order, and its description from the
@paramline of the comment.vppapigenwarns about a@paramwhich is not a field,the values of an enum and its underlying type, and what an alias is an alias of.
The types of the imported files which are used are included, so a descriptor
does not depend on other descriptors. The layout is checked by the compiler,
the generated code asserts the sizeof and the offsetof of every type.
The descriptors are declared in src/vlibapi/api_desc.h.
vl_api_desc_find_msg (am, msg_id) returns the descriptor of a registered
message and am->desc_files has the descriptors of all the files.
What uses them
vl_api_desc_msg_to_json ()converts a message to JSON. It is used byapi trace save-json,api trace dump-jsonand byformat_vl_api_msg_json (). The members are_msgname,_crcand the fields, except_vl_msg_id,client_indexandcontext. The text is written by clib_json. VPP does not register the generatedvl_api_<msg>_t_tojsonfunctions any more.vl_api_desc_msg_from_json ()converts JSON to a message, the opposite of the conversion above. It is used byapi trace replay-json, which parses the file with clib_json. Every field of the message has to be in the JSON. VPP does not register the generatedvl_api_<msg>_t_fromjsonfunctions any more.vl_api_desc_msg_format ()creates the text of a message, which is whatformat_vl_api_msg_text ()and the text output ofapi trace dumpprint. VPP does not register the generatedvl_api_<msg>_t_formatfunctions any more.vl_api_desc_msg_calc_size ()calculates the size of a received message from the lengths in its fields. The message handler drops a message which is smaller than that, as such a message could make the byte order conversion or the handler read past its end. VPP does not register the generatedvl_api_<msg>_t_calc_sizefunctions any more, and a message which has no descriptor is not checked.vl_api_msg_endian (am, msg_id, msg, to_net)converts a message to or from network byte order, which is big endian, by interpreting its descriptor. VPP does not register the generatedvl_api_<msg>_t_endianfunctions any more, a message which has no descriptor is still converted by the handler it was registered with. The descriptor tells which fields are tags of unions and which are lengths, the conversion reads them before it converts them. The steps of a message are worked out when it is first used, and kept.
Showing the descriptors
show api descriptor shows what is registered:
vpp# show api descriptor module vpe
module vpe, crc 0xbbfa7484, 6 messages, 0 types
Name Kind ID CRC Size Reply
show_version message 1594 51077d14 10 show_version_reply
show_version_reply message 1595 c919bde1 362
show_vpe_system_time message 1596 51077d14 10 show_vpe_system_time_reply
show_vpe_system_time_reply message 1597 7ffd8193 18
log_dump message 1598 6ab31753 18 log_details
log_details message 1599 03d61cc0 306
show api descriptorlists the files with their CRC and the number of messages and types.show api descriptor module <name>lists the messages and the types of a file, with the id, the CRC, the size and the reply of a message.show api descriptor message <name>andshow api descriptor type <name>show the layout of one of them, the names are completed. The description of a message, from the\briefof its comment in the.apifile, and the description of each of its fields, from the@paramlines, are shown too:
vpp# show api descriptor message ip_route_lookup
message ip_route_lookup
Lookup IP route from a table
id 1144, crc 710d6471
size 33
Field Type Kind Offset Size Array Notes Description
_vl_msg_id u16 u16 0 2
client_index u32 u32 2 4 no endian opaque cookie to identify the sender
context u32 u32 6 4
table_id u32 u32 10 4 The IP table to look the route up in
exact u8 u8 14 1 0 for normal route lookup, 1 for exact match only
prefix vl_api_prefix_t struct 15 18 The prefix (or host) for route lookup.
The output can be shown as JSON with | json.