return;
*p = 0;
- s = format (0, "%s/lib/" CLIB_TARGET_TRIPLET "/vat2_plugins:"
- "%s/lib/vat2_plugins", path, path);
+ s = format (0, "%s/" CLIB_LIB_DIR "/vat2_plugins", path, path);
vec_add1 (s, 0);
vat2_plugin_path = (char *) s;
}
static int
vat2_exec_command_by_name (char *msgname, cJSON *o)
{
+ u32 crc = 0;
if (filter_message (msgname))
return 0;
cJSON *crc_obj = cJSON_GetObjectItem (o, "_crc");
- if (!crc_obj)
+ if (crc_obj)
{
- fprintf (stderr, "Missing '_crc' element!\n");
- return -1;
+ char *crc_str = cJSON_GetStringValue (crc_obj);
+ crc = (u32) strtol (crc_str, NULL, 16);
}
- char *crc_str = cJSON_GetStringValue (crc_obj);
- u32 crc = (u32) strtol (crc_str, NULL, 16);
uword *p = hash_get_mem (function_by_name, msgname);
if (!p)
fprintf (stderr, "No such command %s\n", msgname);
return -1;
}
- if (crc != apifuncs[p[0]].crc)
+ if (crc && crc != apifuncs[p[0]].crc)
{
fprintf (stderr, "API CRC does not match: %s!\n", msgname);
}
"Usage: vat2 [OPTION] <message-name> <JSON object>\n"
"Send API message to VPP and print reply\n"
"\n"
- "-d, --debug Print additional information\n"
- "-p, --prefix Specify shared memory prefix to connect to a given VPP "
- "instance\n"
- "-f, --file File containing a JSON object with the arguments for "
- "the message to send\n"
- "--dump-apis List all APIs available in VAT2 (might not reflect "
- "running VPP)\n"
- "-t, --template Print a template JSON object for given API message\n"
+ "-d, --debug Print additional information\n"
+ "-p, --prefix <prefix> Specify shared memory prefix to connect "
+ "to a given VPP instance\n"
+ "-f, --file <filename> File containing a JSON object with the "
+ "arguments for the message to send\n"
+ "-t, --template <message-name> Print a template JSON object for given API"
+ " message\n"
+ "--dump-apis List all APIs available in VAT2 (might "
+ "not reflect running VPP)\n"
"\n";
printf ("%s", help_string);
}
{
/* Create a heap of 64MB */
clib_mem_init (0, 64 << 20);
- char *filename = 0, *prefix = 0;
+ char *filename = 0, *prefix = 0, *template = 0;
int index;
int c;
opterr = 0;
cJSON *o = 0;
int option_index = 0;
bool dump_api = false;
- bool template = false;
+ bool debug = false;
char *msgname = 0;
- static int debug_flag;
static struct option long_options[] = {
- { "debug", no_argument, &debug_flag, 1 },
- { "prefix", optional_argument, 0, 'p' },
+ { "debug", no_argument, 0, 'd' },
+ { "prefix", required_argument, 0, 'p' },
{ "file", required_argument, 0, 'f' },
{ "dump-apis", no_argument, 0, 0 },
- { "template", no_argument, 0, 't' },
+ { "template", required_argument, 0, 't' },
{ 0, 0, 0, 0 }
};
- while ((c = getopt_long (argc, argv, "hdp:f:", long_options,
+ while ((c = getopt_long (argc, argv, "hdp:f:t:", long_options,
&option_index)) != -1)
{
switch (c)
debug = true;
break;
case 't':
- template = true;
+ template = optarg;
break;
case 'p':
prefix = optarg;
abort ();
}
}
- debug = debug_flag == 1 ? true : false;
- DBG ("debug = %d, filename = %s shared memory prefix: %s\n", debug, filename,
- prefix);
+ DBG ("debug = %d, filename = %s, template = %s, shared memory prefix: %s\n",
+ debug, filename, template, prefix);
for (index = optind; index < argc; index++)
DBG ("Non-option argument %s\n", argv[index]);
if (template)
{
- print_template (argv[index]);
+ print_template (template);
exit (0);
}