summaryrefslogtreecommitdiffstats
path: root/vppapigen/node.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2016-11-10 14:22:49 -0500
committerDamjan Marion <dmarion.lists@gmail.com>2016-11-21 18:11:41 +0000
commit557d128b68a1213e056f5eed9fe6f230ca3f3144 (patch)
tree6b31ac462efacf3f6937788c9b7af1420497c9fc /vppapigen/node.c
parentfca670b0ec9f74aa977fe479a5517ad6367ee898 (diff)
Add client-side msg_name_and_crc -> msg_index table
vppapigen now generates per-message crcs. Verified that whitespace and real changes in message A don't change the crc for message B, etc. Fixed the sample and flowperpkt plugins to participate. Others need the same treatment. They don't build due to python/java language binding build issues. To use the scheme: Client connects as usual. Then call: u32 vl_api_get_msg_index(char * name_and_crc) name_and_crc is a string like: "flowperpkt_tx_interface_add_del_753301f3", aka the message name with _%08x <expected crc> appended. Try these vpp-api-test commands to play with it: vat# dump_msg_api_table <snip> [366]: punt_reply_cca27fbe [367]: ipsec_spd_dump_5e9ae88e [368]: ipsec_spd_details_6f7821b0 [369]: sample_macswap_enable_disable_0f2813e2 [370]: sample_macswap_enable_disable_reply_476738e5 [371]: flowperpkt_tx_interface_add_del_753301f3 [372]: flowperpkt_tx_interface_add_del_reply_d47e6e0b vat# get_msg_id sample_macswap_enable_disable_reply_476738e5 'sample_macswap_enable_disable_reply_476738e5' has message index 370 vat# get_msg_id sample_macswap_enable_disable_reply_476738e3 'sample_macswap_enable_disable_reply_476738e3' not found CRCs may vary, etc. vppapigen is used to build a set of JSON representations of each API file from vpp-api/Makefile.am and that is in turn used by each language binding (Java, Python, Lua). Change-Id: I3d64582e779dac5f20cddec79c562c288d8fd9c6 Signed-off-by: Dave Barach <dave@barachs.net> Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'vppapigen/node.c')
-rw-r--r--vppapigen/node.c146
1 files changed, 141 insertions, 5 deletions
diff --git a/vppapigen/node.c b/vppapigen/node.c
index fa7146ae497..4460fd5f933 100644
--- a/vppapigen/node.c
+++ b/vppapigen/node.c
@@ -18,6 +18,7 @@
*/
#include <stdio.h>
+#include <stdbool.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
@@ -33,6 +34,7 @@
FILE *ofp;
FILE *pythonfp;
+FILE *jsonfp;
time_t starttime;
char *vlib_app_name;
char *input_filename;
@@ -130,6 +132,12 @@ void primtype_recursive_generate(node_t *this, enum passid which, FILE *ofp,
fputs("', ", pythonfp);
break;
+ case JSON_PASS:
+ fputs("[\"", jsonfp);
+ fputs((char *)type_name, jsonfp);
+ fputs("\", ", jsonfp);
+ break;
+
default:
fprintf(stderr, "primtype_recursive_generate: unimp pass %d\n", which);
break;
@@ -377,6 +385,24 @@ void node_define_generate (node_t *this, enum passid which, FILE *fp)
fprintf(fp, "),\n\n");
break;
+ case JSON_PASS:
+ fprintf(fp, "[\"%s\",\n", CDATA0);
+ child = this->deeper;
+ indent += 4;
+ while (child) {
+ node_vft_t *vftp = the_vft[child->type];
+ indent_me(fp);
+ vftp->generate(child, which, fp);
+ child = child->peer;
+ fprintf(fp, ",\n");
+ }
+ indent_me(fp);
+ fprintf (fp, "{\"crc\" : \"0x%08x\"}\n", (u32)(u64)CDATA3);
+ indent -= 4;
+ indent_me(fp);
+ fprintf(fp, "]");
+ break;
+
default:
fprintf(stderr, "node_define_generate: unimp pass %d\n", which);
break;
@@ -537,6 +563,10 @@ void node_scalar_generate (node_t *this, enum passid which, FILE *fp)
fprintf(fp, "'%s'),\n", CDATA0);
break;
+ case JSON_PASS:
+ fprintf(fp, "\"%s\"]", CDATA0);
+ break;
+
default:
fprintf(stderr, "node_scalar_generate: unimp pass %d\n", which);
}
@@ -658,6 +688,14 @@ void node_vector_generate (node_t *this, enum passid which, FILE *fp)
}
break;
+ case JSON_PASS:
+ if (CDATA2 != 0) { /* variable length vector */
+ fprintf(fp, "\"%s\", %d, \"%s\"]", CDATA0, IDATA1, CDATA2);
+ } else {
+ fprintf(fp, "\"%s\", %d]", CDATA0, IDATA1);
+ }
+ break;
+
default:
fprintf(stderr, "node_vector_generate: unimp pass %d\n", which);
}
@@ -746,6 +784,15 @@ void node_complex_generate (node_t *this, enum passid which, FILE *fp)
}
break;
+ case JSON_PASS:
+ fprintf(fp, "[\"%s\", ", CDATA0);
+ deeper = this->deeper;
+ if (deeper) {
+ vftp = the_vft[deeper->type];
+ vftp->generate(deeper, which, fp);
+ }
+ break;
+
default:
fprintf(stderr, "node_complex_generate unimp pass %d...\n", which);
break;
@@ -879,6 +926,7 @@ YYSTYPE add_define (YYSTYPE a1, YYSTYPE a2)
np = make_node(NODE_DEFINE);
np->data[0] = a1;
+ np->data[3] = (void *) message_crc;
deeper((YYSTYPE)np, a2);
return ((YYSTYPE) np);
}
@@ -1065,15 +1113,11 @@ void generate_top_boilerplate(FILE *fp)
fprintf (fp, " * Input file: %s\n", input_filename);
fprintf (fp, " * Automatically generated: please edit the input file ");
fprintf (fp, "NOT this file!\n");
-
- /* Moron Acme trigger workaround */
- fprintf (fp, " * %syright (c) %s by Cisco Systems, Inc.\n", "Cop",
- &datestring[20]);
fprintf (fp, " */\n\n");
fprintf (fp, "#if defined(vl_msg_id)||defined(vl_union_id)||");
fprintf (fp, "defined(vl_printfun) \\\n ||defined(vl_endianfun)||");
fprintf (fp, " defined(vl_api_version)||defined(vl_typedefs) \\\n");
- fprintf (fp, " ||defined(vl_msg_name)\n");
+ fprintf (fp, " ||defined(vl_msg_name)||defined(vl_msg_name_crc_list)\n");
fprintf (fp, "/* ok, something was selected */\n");
fprintf (fp, "#else\n");
fprintf (fp, "#warning no content included from %s\n", input_filename);
@@ -1141,6 +1185,37 @@ void generate_msg_names(YYSTYPE a1, FILE *fp)
fprintf (fp, "#endif\n\n");
}
+void generate_msg_name_crc_list (YYSTYPE a1, FILE *fp)
+{
+ node_t *np = (node_t *)a1;
+ char *unique_suffix, *cp;
+
+ unique_suffix = sxerox(fixed_name);
+
+ cp = unique_suffix;
+ while (*cp && (*cp != '.'))
+ cp++;
+ if (*cp == '.')
+ *cp = 0;
+
+ fprintf (fp, "\n/****** Message name, crc list ******/\n\n");
+
+ fprintf (fp, "#ifdef vl_msg_name_crc_list\n");
+ fprintf (fp, "#define foreach_vl_msg_name_crc_%s ", unique_suffix);
+
+ while (np) {
+ if (np->type == NODE_DEFINE) {
+ if (!(np->flags & NODE_FLAG_TYPEONLY)) {
+ fprintf (fp, "\\\n_(VL_API_%s, %s, %08x) ",
+ uppercase (np->data[0]), (i8 *) np->data[0],
+ (u32)(u64)np->data[3]);
+ }
+ }
+ np = np->peer;
+ }
+ fprintf (fp, "\n#endif\n\n");
+}
+
void generate_typedefs(YYSTYPE a1, FILE *fp)
{
node_t *np = (node_t *)a1;
@@ -1341,6 +1416,47 @@ void generate_python_msg_definitions(YYSTYPE a1, FILE *fp)
fprintf (fp, "\n]\n");
}
+static bool
+is_typeonly_check(node_t *np, bool typeonly)
+{
+ bool is_typeonly = (np->flags & NODE_FLAG_TYPEONLY);
+ return (is_typeonly == typeonly);
+}
+
+static void
+generate_json_definitions(YYSTYPE a1, FILE *fp, bool typeonly)
+{
+ node_t *np = (node_t *)a1;
+ node_vft_t *vftp;
+ indent_me(fp);
+ if (typeonly)
+ fprintf (fp, "\"types\" : [\n");
+ else
+ fprintf (fp, "\"messages\" : [\n");
+
+ /* Walk the top-level node-list */
+ bool comma = false;
+ indent += 4;
+ while (np) {
+ if (np->type == NODE_DEFINE && is_typeonly_check(np, typeonly)) {
+ /* Yeah, this is pedantic */
+ vftp = the_vft[np->type];
+ indent_me(fp);
+ vftp->generate(np, JSON_PASS, fp);
+ comma = true;
+ }
+ np = np->peer;
+ if (comma && np &&
+ np->type == NODE_DEFINE && is_typeonly_check(np, typeonly))
+ fprintf (fp, ",\n");
+
+ }
+ indent -= 4;
+ fprintf (fp, "\n");
+ indent_me(fp);
+ fprintf(fp, "]");
+}
+
void generate_python_typeonly_definitions(YYSTYPE a1, FILE *fp)
{
node_t *np = (node_t *)a1;
@@ -1368,6 +1484,22 @@ void generate_python(YYSTYPE a1, FILE *fp)
fprintf (fp, "vl_api_version = 0x%08x\n\n", (unsigned int)input_crc);
}
+void generate_json(YYSTYPE a1, FILE *fp)
+{
+ fprintf (fp, "{\n");
+ indent += 4;
+ generate_json_definitions(a1, fp, true);
+ fprintf (fp, ",\n");
+ generate_json_definitions(a1, fp, false);
+
+ /*
+ * API CRC signature
+ */
+ fprintf (fp, ",\n\"vl_api_version\" :\"0x%08x\"\n",
+ (unsigned int)input_crc);
+ fprintf (fp, "}\n");
+}
+
void generate(YYSTYPE a1)
{
if (dump_tree) {
@@ -1381,6 +1513,7 @@ void generate(YYSTYPE a1)
generate_msg_ids(a1, ofp);
generate_msg_names(a1, ofp);
+ generate_msg_name_crc_list(a1, ofp);
generate_typedefs(a1, ofp);
generate_uniondefs(a1, ofp);
generate_printfun(a1, ofp);
@@ -1391,4 +1524,7 @@ void generate(YYSTYPE a1)
if (pythonfp) {
generate_python(a1, pythonfp);
}
+ if (jsonfp) {
+ generate_json(a1, jsonfp);
+ }
}