From 7cd468a3d7dee7d6c92f69a0bb7061ae208ec727 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Mon, 19 Dec 2016 23:05:39 +0100 Subject: Reorganize source tree to use single autotools instance Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion --- src/vat/main.c | 421 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 src/vat/main.c (limited to 'src/vat/main.c') diff --git a/src/vat/main.c b/src/vat/main.c new file mode 100644 index 00000000..e01d15ec --- /dev/null +++ b/src/vat/main.c @@ -0,0 +1,421 @@ +/* + * Copyright (c) 2015 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. + */ +#include "vat.h" +#include "plugin.h" +#include + +vat_main_t vat_main; + +#include +vpe_api_main_t vpe_api_main; + +void +vat_suspend (vlib_main_t * vm, f64 interval) +{ + /* do nothing in the standalone version, just return */ +} + +void +fformat_append_cr (FILE * ofp, const char *fmt, ...) +{ + va_list va; + + va_start (va, fmt); + (void) va_fformat (ofp, (char *) fmt, &va); + va_end (va); + fformat (ofp, "\n"); +} + +int +connect_to_vpe (char *name) +{ + vat_main_t *vam = &vat_main; + api_main_t *am = &api_main; + + if (vl_client_connect_to_vlib ("/vpe-api", name, 32) < 0) + return -1; + + vam->vl_input_queue = am->shmem_hdr->vl_input_queue; + vam->my_client_index = am->my_client_index; + + return 0; +} + +vlib_main_t vlib_global_main; +vlib_main_t **vlib_mains; +void +vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...) +{ + clib_warning ("BUG"); +} + + +static u8 * +format_api_error (u8 * s, va_list * args) +{ + vat_main_t *vam = va_arg (*args, vat_main_t *); + i32 error = va_arg (*args, u32); + uword *p; + + p = hash_get (vam->error_string_by_error_number, -error); + + if (p) + s = format (s, "%s", p[0]); + else + s = format (s, "%d", error); + return s; +} + +void +do_one_file (vat_main_t * vam) +{ + int rv; + int (*fp) (vat_main_t * vam); + int arg_len; + unformat_input_t _input; + u8 *cmdp, *argsp; + uword *p; + u8 *this_cmd = 0; + + vam->input = &_input; + + /* Used by the "quit" command handler */ + if (setjmp (vam->jump_buf) != 0) + return; + + vam->jump_buf_set = 1; + + while (1) + { + if (vam->ifp == stdin) + { + if (vam->exec_mode == 0) + rv = write (1, "vat# ", 5); + else + rv = write (1, "exec# ", 6); + } + + _vec_len (vam->inbuf) = 4096; + + if (vam->do_exit || + fgets ((char *) vam->inbuf, vec_len (vam->inbuf), vam->ifp) == 0) + break; + + vam->input_line_number++; + + vec_free (this_cmd); + + this_cmd = + (u8 *) clib_macro_eval (&vam->macro_main, (char *) vam->inbuf, + 1 /* complain */ ); + + if (vam->exec_mode == 0) + { + /* Split input into cmd + args */ + cmdp = this_cmd; + + while (cmdp < (this_cmd + vec_len (this_cmd))) + { + if (*cmdp == ' ' || *cmdp == '\t' || *cmdp == '\n') + { + cmdp++; + } + else + break; + } + argsp = cmdp; + while (argsp < (this_cmd + vec_len (this_cmd))) + { + if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n') + { + argsp++; + } + else + break; + } + *argsp++ = 0; + while (argsp < (this_cmd + vec_len (this_cmd))) + { + if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n') + { + argsp++; + } + else + break; + } + + + /* Blank input line? */ + if (*cmdp == 0) + continue; + + p = hash_get_mem (vam->function_by_name, cmdp); + if (p == 0) + { + errmsg ("'%s': function not found\n", cmdp); + continue; + } + + arg_len = strlen ((char *) argsp); + + unformat_init_string (vam->input, (char *) argsp, arg_len); + fp = (void *) p[0]; + } + else + { + unformat_init_string (vam->input, (char *) this_cmd, + strlen ((char *) this_cmd)); + cmdp = this_cmd; + fp = exec; + } + + rv = (*fp) (vam); + if (rv < 0) + errmsg ("%s error: %U\n", cmdp, format_api_error, vam, rv); + unformat_free (vam->input); + + if (vam->regenerate_interface_table) + { + vam->regenerate_interface_table = 0; + api_sw_interface_dump (vam); + } + } +} + +static void +init_error_string_table (vat_main_t * vam) +{ + + vam->error_string_by_error_number = hash_create (0, sizeof (uword)); + +#define _(n,v,s) hash_set (vam->error_string_by_error_number, -v, s); + foreach_vnet_api_error; +#undef _ + + hash_set (vam->error_string_by_error_number, 99, "Misc"); +} + +static i8 * +eval_current_file (macro_main_t * mm, i32 complain) +{ + vat_main_t *vam = &vat_main; + return ((i8 *) format (0, "%s%c", vam->current_file, 0)); +} + +static i8 * +eval_current_line (macro_main_t * mm, i32 complain) +{ + vat_main_t *vam = &vat_main; + return ((i8 *) format (0, "%d%c", vam->input_line_number, 0)); +} + +static void +signal_handler (int signum, siginfo_t * si, ucontext_t * uc) +{ + vat_main_t *vam = &vat_main; + + switch (signum) + { + /* these (caught) signals cause the application to exit */ + case SIGINT: + case SIGTERM: + if (vam->jump_buf_set) + { + vam->do_exit = 1; + return; + } + + /* FALLTHROUGH on purpose */ + + default: + break; + } + + _exit (1); +} + +static void +setup_signal_handlers (void) +{ + uword i; + struct sigaction sa; + + for (i = 1; i < 32; i++) + { + memset (&sa, 0, sizeof (sa)); + sa.sa_sigaction = (void *) signal_handler; + sa.sa_flags = SA_SIGINFO; + + switch (i) + { + /* these signals take the default action */ + case SIGABRT: + case SIGKILL: + case SIGSTOP: + case SIGUSR1: + case SIGUSR2: + continue; + + /* ignore SIGPIPE, SIGCHLD */ + case SIGPIPE: + case SIGCHLD: + sa.sa_sigaction = (void *) SIG_IGN; + break; + + /* catch and handle all other signals */ + default: + break; + } + + if (sigaction (i, &sa, 0) < 0) + clib_unix_warning ("sigaction %U", format_signal, i); + } +} + +int +main (int argc, char **argv) +{ + vat_main_t *vam = &vat_main; + unformat_input_t _argv, *a = &_argv; + u8 **input_files = 0; + u8 *output_file = 0; + u8 *chroot_prefix; + u8 *this_input_file; + u8 interactive = 1; + u8 json_output = 0; + u8 *heap; + mheap_t *h; + int i; + + clib_mem_init (0, 128 << 20); + + heap = clib_mem_get_per_cpu_heap (); + h = mheap_header (heap); + + /* make the main heap thread-safe */ + h->flags |= MHEAP_FLAG_THREAD_SAFE; + + clib_macro_init (&vam->macro_main); + clib_macro_add_builtin (&vam->macro_main, "current_file", + eval_current_file); + clib_macro_add_builtin (&vam->macro_main, "current_line", + eval_current_line); + + init_error_string_table (vam); + + unformat_init_command_line (a, argv); + + while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT) + { + if (unformat (a, "in %s", &this_input_file)) + vec_add1 (input_files, this_input_file); + else if (unformat (a, "out %s", &output_file)) + ; + else if (unformat (a, "script")) + interactive = 0; + else if (unformat (a, "json")) + json_output = 1; + else if (unformat (a, "plugin_path %s", (u8 *) & vat_plugin_path)) + vec_add1 (vat_plugin_path, 0); + else if (unformat (a, "plugin_name_filter %s", + (u8 *) & vat_plugin_name_filter)) + vec_add1 (vat_plugin_name_filter, 0); + else if (unformat (a, "chroot prefix %s", &chroot_prefix)) + { + vl_set_memory_root_path ((char *) chroot_prefix); + } + else + { + fformat (stderr, + "%s: usage [in ... in ] [out ] [script] [json]\n"); + exit (1); + } + } + + if (output_file) + vam->ofp = fopen ((char *) output_file, "w"); + else + vam->ofp = stdout; + + if (vam->ofp == NULL) + { + fformat (stderr, "Couldn't open output file %s\n", + output_file ? (char *) output_file : "stdout"); + exit (1); + } + + clib_time_init (&vam->clib_time); + + vat_api_hookup (vam); + vat_plugin_api_reference (); + + setup_signal_handlers (); + + if (connect_to_vpe ("vpp_api_test") < 0) + { + svm_region_exit (); + fformat (stderr, "Couldn't connect to vpe, exiting...\n"); + exit (1); + } + + vam->json_output = json_output; + + if (!json_output) + { + api_sw_interface_dump (vam); + } + + vec_validate (vam->inbuf, 4096); + + vam->current_file = (u8 *) "plugin-init"; + vat_plugin_init (vam); + + for (i = 0; i < vec_len (input_files); i++) + { + vam->ifp = fopen ((char *) input_files[i], "r"); + if (vam->ifp == NULL) + { + fformat (stderr, "Couldn't open input file %s\n", input_files[i]); + continue; + } + vam->current_file = input_files[i]; + vam->input_line_number = 0; + do_one_file (vam); + fclose (vam->ifp); + } + + if (output_file) + fclose (vam->ofp); + + if (interactive) + { + vam->ifp = stdin; + vam->ofp = stdout; + vam->current_file = (u8 *) "interactive"; + do_one_file (vam); + fclose (vam->ifp); + } + + vl_client_disconnect_from_vlib (); + exit (0); +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg From f15866146adcf3273da6f29f05d42193c7af4b07 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Thu, 30 Mar 2017 09:33:01 -0400 Subject: Fix more "symbol XXX found in none of the libs" warnings Change-Id: I4467f26da5bdcfd76e5914e0124a83b659757947 Signed-off-by: Dave Barach --- gmod/Makefile.am | 2 +- gmod/gmod/mod_vpp.c | 6 +++--- src/vat/main.c | 1 - src/vnet/interface_api.c | 1 + src/vpp/api/api.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/vat/main.c') diff --git a/gmod/Makefile.am b/gmod/Makefile.am index e57f5788..643e170d 100644 --- a/gmod/Makefile.am +++ b/gmod/Makefile.am @@ -21,7 +21,7 @@ libgmodvpp_la_SOURCES = gmod/mod_vpp.c libgmodvpp_la_LDFLAGS = -module -avoid-version -libgmodvpp_la_LIBADD = -lsvm -lsvmdb -lvppinfra +libgmodvpp_la_LIBADD = -lsvm -lsvmdb -lvppinfra -lapr-1 gconfdir = $(prefix)/etc/conf.d gconf_DATA = gmod/vpp.conf diff --git a/gmod/gmod/mod_vpp.c b/gmod/gmod/mod_vpp.c index 572f9ef5..71479d2a 100644 --- a/gmod/gmod/mod_vpp.c +++ b/gmod/gmod/mod_vpp.c @@ -37,14 +37,14 @@ static int vpp_metric_init (apr_pool_t *p) int i; if (str_params) { - debug_msg("[mod_vpp]Received string params: %s", str_params); + clib_warning("[mod_vpp]Received string params: %s", str_params); } /* Multiple name/value pair parameters. */ if (list_params) { - debug_msg("[mod_vpp]Received following params list: "); + clib_warning("[mod_vpp]Received following params list: "); params = (mmparam*) list_params->elts; for(i=0; i< list_params->nelts; i++) { - debug_msg("\tParam: %s = %s", params[i].name, params[i].value); + clib_warning("\tParam: %s = %s", params[i].name, params[i].value); } } diff --git a/src/vat/main.c b/src/vat/main.c index e01d15ec..9e8bb2fe 100644 --- a/src/vat/main.c +++ b/src/vat/main.c @@ -19,7 +19,6 @@ vat_main_t vat_main; #include -vpe_api_main_t vpe_api_main; void vat_suspend (vlib_main_t * vm, f64 interval) diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c index 39c06271..0b4fa81a 100644 --- a/src/vnet/interface_api.c +++ b/src/vnet/interface_api.c @@ -46,6 +46,7 @@ #undef vl_printfun #include +vpe_api_main_t vpe_api_main; #define foreach_vpe_api_msg \ _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \ diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c index 8df40406..7f6a125e 100644 --- a/src/vpp/api/api.c +++ b/src/vpp/api/api.c @@ -158,7 +158,7 @@ typedef enum } resolve_t; static vlib_node_registration_t vpe_resolver_process_node; -vpe_api_main_t vpe_api_main; +extern vpe_api_main_t vpe_api_main; static int arp_change_delete_callback (u32 pool_index, u8 * notused); static int nd_change_delete_callback (u32 pool_index, u8 * notused); -- cgit 1.2.3-korg From 0c6fb530287de2a28ec1c9df5410f87b65323f9d Mon Sep 17 00:00:00 2001 From: Jerome Tollet Date: Tue, 19 Sep 2017 20:30:48 +0100 Subject: Fix usage string for vat Change-Id: Idad65cbb3765500a66f1097126076a2c5fdb4f1b Signed-off-by: Jerome Tollet --- src/vat/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/vat/main.c') diff --git a/src/vat/main.c b/src/vat/main.c index 9e8bb2fe..1bad2ebb 100644 --- a/src/vat/main.c +++ b/src/vat/main.c @@ -338,7 +338,8 @@ main (int argc, char **argv) else { fformat (stderr, - "%s: usage [in ... in ] [out ] [script] [json]\n"); + "%s: usage [in ... in ] [out ] [script] [json]\n", + argv[0]); exit (1); } } -- cgit 1.2.3-korg From fb353ce54efc3abf3c2ba7795d0c9bf7aed6df96 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Wed, 18 Oct 2017 08:03:14 -0400 Subject: CSIT-844: fix binary api rx pthread heap push/pop We need to push/pop the rx pthread's heap without affecting other thread(s). Search clib_per_cpu_mheaps, locate an unused slot. Duplicate the main thread heap pointer in that slot, and set __os_thread_index appropriately. Don't bail out of vpp_api_test with results pending, e.g. at the end of a vpp_api_test script. Even though vpp will eventuallly garbage-collect them, We don't want to leave allocated reply messages lurking in the api message allocation rings... This patch is a manual cherry-pick from gerrit 8862 Change-Id: If3c84abe61496905432bfa36767068bad4bd243b Signed-off-by: Dave Barach --- src/vat/main.c | 13 +++++++++++++ src/vlibmemory/memory_client.c | 25 ++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'src/vat/main.c') diff --git a/src/vat/main.c b/src/vat/main.c index 1bad2ebb..b8856cc9 100644 --- a/src/vat/main.c +++ b/src/vat/main.c @@ -297,6 +297,7 @@ main (int argc, char **argv) u8 *heap; mheap_t *h; int i; + f64 timeout; clib_mem_init (0, 128 << 20); @@ -408,6 +409,18 @@ main (int argc, char **argv) fclose (vam->ifp); } + /* + * Particularly when running a script, don't be in a hurry to leave. + * A reply message queued to this process will end up constipating + * the allocation rings. + */ + timeout = vat_time_now (vam) + 2.0; + while (vam->result_ready == 0 && vat_time_now (vam) < timeout) + ; + + if (vat_time_now (vam) > timeout) + clib_warning ("BUG: message reply spin-wait timeout"); + vl_client_disconnect_from_vlib (); exit (0); } diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c index a162d6bb..8a60a322 100644 --- a/src/vlibmemory/memory_client.c +++ b/src/vlibmemory/memory_client.c @@ -80,6 +80,7 @@ rx_thread_fn (void *arg) unix_shared_memory_queue_t *q; memory_client_main_t *mm = &memory_client_main; api_main_t *am = &api_main; + int i; q = am->vl_input_queue; @@ -87,10 +88,27 @@ rx_thread_fn (void *arg) if (setjmp (mm->rx_thread_jmpbuf) == 0) { mm->rx_thread_jmpbuf_valid = 1; - while (1) + /* + * Find an unused slot in the per-cpu-mheaps array, + * and grab it for this thread. We need to be able to + * push/pop the thread heap without affecting other thread(s). + */ + if (__os_thread_index == 0) { - vl_msg_api_queue_handler (q); + for (i = 0; i < ARRAY_LEN (clib_per_cpu_mheaps); i++) + { + if (clib_per_cpu_mheaps[i] == 0) + { + /* Copy the main thread mheap pointer */ + clib_per_cpu_mheaps[i] = clib_per_cpu_mheaps[0]; + __os_thread_index = i; + break; + } + } + ASSERT (__os_thread_index > 0); } + while (1) + vl_msg_api_queue_handler (q); } pthread_exit (0); } @@ -138,7 +156,7 @@ vl_api_memclnt_create_reply_t_handler (vl_api_memclnt_create_reply_t * mp) /* Recreate the vnet-side API message handler table */ tblv = uword_to_pointer (mp->message_table, u8 *); - serialize_open_vector (sm, tblv); + unserialize_open_data (sm, tblv, vec_len (tblv)); unserialize_integer (sm, &nmsgs, sizeof (u32)); for (i = 0; i < nmsgs; i++) @@ -311,6 +329,7 @@ vl_client_disconnect (void) /* drain the queue */ if (ntohs (rp->_vl_msg_id) != VL_API_MEMCLNT_DELETE_REPLY) { + clib_warning ("queue drain: %d", ntohs (rp->_vl_msg_id)); vl_msg_api_handler ((void *) rp); continue; } -- cgit 1.2.3-korg