#include <vnet/l2/l2_input.h>
#include <vnet/udp/udp_local.h>
-#include <vpp/api/vpe_msg_enum.h>
#include <vnet/l2/l2_classify.h>
#include <vnet/l2/l2_vtr.h>
#include <vnet/classify/in_out_acl.h>
#include <inttypes.h>
#include <sys/stat.h>
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-/* declare message handlers for each api */
+#include <vlibmemory/memclnt.api_enum.h>
+#include <vlibmemory/memclnt.api_types.h>
+#include <vlibmemory/memclnt.api_tojson.h>
+#include <vlibmemory/memclnt.api_fromjson.h>
#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
+#include <vlibmemory/memclnt.api.h>
#undef vl_endianfun
+#define vl_calcsizefun
+#include <vlibmemory/memclnt.api.h>
+#undef vl_calcsizefun
+
/* instantiate all the print functions we know about */
-#if VPP_API_TEST_BUILTIN == 0
-#define vl_print(handle, ...)
-#else
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#endif
#define vl_printfun
-#include <vpp/api/vpe_all_api_h.h>
+#include <vlibmemory/memclnt.api.h>
#undef vl_printfun
#define __plugin_msg_base 0
}
#if VPP_API_TEST_BUILTIN == 0
-static uword
-api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
-{
- vat_main_t *vam = va_arg (*args, vat_main_t *);
- u32 *result = va_arg (*args, u32 *);
- u8 *if_name;
- uword *p;
-
- if (!unformat (input, "%s", &if_name))
- return 0;
-
- p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
- if (p == 0)
- return 0;
- *result = p[0];
- return 1;
-}
/* Parse an IP4 address %d.%d.%d.%d. */
uword
}
-static void
-vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
-
- vam->retval = retval;
- vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
- vam->result_ready = 1;
-}
-
-static void
-vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
- void *oldheap;
- u8 *reply;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "reply_in_shmem",
- ntohl (mp->reply_in_shmem));
- /* Toss the shared-memory original... */
- oldheap = vl_msg_push_heap ();
-
- reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
- vec_free (reply);
-
- vl_msg_pop_heap (oldheap);
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static void
-vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
-
- vec_reset_length (vam->cmd_reply);
-
- vam->retval = retval;
- if (retval == 0)
- vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
- vam->result_ready = 1;
-}
-
-static void
-vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
- u8 *reply = 0; /* reply vector */
-
- reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
- vec_reset_length (vam->cmd_reply);
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_string_copy (&node, "reply", reply);
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
- vec_free (reply);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static void vl_api_get_node_index_reply_t_handler
- (vl_api_get_node_index_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
- if (vam->async_mode)
- {
- vam->async_errors += (retval < 0);
- }
- else
- {
- vam->retval = retval;
- if (retval == 0)
- errmsg ("node index %d", ntohl (mp->node_index));
- vam->result_ready = 1;
- }
-}
-
-static void vl_api_get_node_index_reply_t_handler_json
- (vl_api_get_node_index_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static void vl_api_get_next_index_reply_t_handler
- (vl_api_get_next_index_reply_t * mp)
+static void vl_api_get_first_msg_id_reply_t_handler
+ (vl_api_get_first_msg_id_reply_t * mp)
{
vat_main_t *vam = &vat_main;
i32 retval = ntohl (mp->retval);
- if (vam->async_mode)
- {
- vam->async_errors += (retval < 0);
- }
- else
- {
- vam->retval = retval;
- if (retval == 0)
- errmsg ("next node index %d", ntohl (mp->next_index));
- vam->result_ready = 1;
- }
-}
-
-static void vl_api_get_next_index_reply_t_handler_json
- (vl_api_get_next_index_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-static void vl_api_add_node_next_reply_t_handler
- (vl_api_add_node_next_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
if (vam->async_mode)
{
vam->async_errors += (retval < 0);
else
{
vam->retval = retval;
- if (retval == 0)
- errmsg ("next index %d", ntohl (mp->next_index));
vam->result_ready = 1;
}
-}
-
-static void vl_api_add_node_next_reply_t_handler_json
- (vl_api_add_node_next_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static void vl_api_show_version_reply_t_handler
- (vl_api_show_version_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
-
if (retval >= 0)
{
- errmsg (" program: %s", mp->program);
- errmsg (" version: %s", mp->version);
- errmsg (" build date: %s", mp->build_date);
- errmsg ("build directory: %s", mp->build_directory);
+ errmsg ("first message id %d", ntohs (mp->first_msg_id));
}
- vam->retval = retval;
- vam->result_ready = 1;
}
-static void vl_api_show_version_reply_t_handler_json
- (vl_api_show_version_reply_t * mp)
+static void vl_api_get_first_msg_id_reply_t_handler_json
+ (vl_api_get_first_msg_id_reply_t * mp)
{
vat_main_t *vam = &vat_main;
vat_json_node_t node;
vat_json_init_object (&node);
vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_string_copy (&node, "program", mp->program);
- vat_json_object_add_string_copy (&node, "version", mp->version);
- vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
- vat_json_object_add_string_copy (&node, "build_directory",
- mp->build_directory);
+ vat_json_object_add_uint (&node, "first_msg_id",
+ (uint) ntohs (mp->first_msg_id));
vat_json_print (vam->ofp, &node);
vat_json_free (&node);
vam->result_ready = 1;
}
-static void vl_api_show_threads_reply_t_handler
- (vl_api_show_threads_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
- int i, count = 0;
-
- if (retval >= 0)
- count = ntohl (mp->count);
-
- for (i = 0; i < count; i++)
- print (vam->ofp,
- "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
- ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
- mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
- ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
- ntohl (mp->thread_data[i].cpu_socket));
-
- vam->retval = retval;
- vam->result_ready = 1;
-}
-
-static void vl_api_show_threads_reply_t_handler_json
- (vl_api_show_threads_reply_t * mp)
+/* Format hex dump. */
+u8 *
+format_hex_bytes (u8 * s, va_list * va)
{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
- vl_api_thread_data_t *td;
- i32 retval = ntohl (mp->retval);
- int i, count = 0;
+ u8 *bytes = va_arg (*va, u8 *);
+ int n_bytes = va_arg (*va, int);
+ uword i;
- if (retval >= 0)
- count = ntohl (mp->count);
+ /* Print short or long form depending on byte count. */
+ uword short_form = n_bytes <= 32;
+ u32 indent = format_get_indent (s);
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", retval);
- vat_json_object_add_uint (&node, "count", count);
+ if (n_bytes == 0)
+ return s;
- for (i = 0; i < count; i++)
+ for (i = 0; i < n_bytes; i++)
{
- td = &mp->thread_data[i];
- vat_json_object_add_uint (&node, "id", ntohl (td->id));
- vat_json_object_add_string_copy (&node, "name", td->name);
- vat_json_object_add_string_copy (&node, "type", td->type);
- vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
- vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
- vat_json_object_add_int (&node, "core", ntohl (td->id));
- vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
+ if (!short_form && (i % 32) == 0)
+ s = format (s, "%08x: ", i);
+ s = format (s, "%02x", bytes[i]);
+ if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
+ s = format (s, "\n%U", format_white_space, indent);
}
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = retval;
- vam->result_ready = 1;
-}
-
-static int
-api_show_threads (vat_main_t * vam)
-{
- vl_api_show_threads_t *mp;
- int ret;
-
- print (vam->ofp,
- "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
- "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
-
- M (SHOW_THREADS, mp);
-
- S (mp);
- W (ret);
- return ret;
+ return s;
}
-#define vl_api_bridge_domain_details_t_endian vl_noop_handler
-#define vl_api_bridge_domain_details_t_print vl_noop_handler
-
-static void vl_api_control_ping_reply_t_handler
- (vl_api_control_ping_reply_t * mp)
+static void
+vl_api_control_ping_reply_t_handler (vl_api_control_ping_reply_t *mp)
{
vat_main_t *vam = &vat_main;
i32 retval = ntohl (mp->retval);
vam->socket_client_main->control_pings_outstanding--;
}
-static void vl_api_control_ping_reply_t_handler_json
- (vl_api_control_ping_reply_t * mp)
+static void
+vl_api_control_ping_reply_t_handler_json (vl_api_control_ping_reply_t *mp)
{
vat_main_t *vam = &vat_main;
i32 retval = ntohl (mp->retval);
vam->result_ready = 1;
}
-
-static void vl_api_get_first_msg_id_reply_t_handler
- (vl_api_get_first_msg_id_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
-
- if (vam->async_mode)
- {
- vam->async_errors += (retval < 0);
- }
- else
- {
- vam->retval = retval;
- vam->result_ready = 1;
- }
- if (retval >= 0)
- {
- errmsg ("first message id %d", ntohs (mp->first_msg_id));
- }
-}
-
-static void vl_api_get_first_msg_id_reply_t_handler_json
- (vl_api_get_first_msg_id_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "first_msg_id",
- (uint) ntohs (mp->first_msg_id));
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static void vl_api_get_node_graph_reply_t_handler
- (vl_api_get_node_graph_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
- u8 *pvt_copy, *reply;
- void *oldheap;
- vlib_node_t *node;
- int i;
-
- if (vam->async_mode)
- {
- vam->async_errors += (retval < 0);
- }
- else
- {
- vam->retval = retval;
- vam->result_ready = 1;
- }
-
- /* "Should never happen..." */
- if (retval != 0)
- return;
-
- reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
- pvt_copy = vec_dup (reply);
-
- /* Toss the shared-memory original... */
- oldheap = vl_msg_push_heap ();
-
- vec_free (reply);
-
- vl_msg_pop_heap (oldheap);
-
- if (vam->graph_nodes)
- {
- hash_free (vam->graph_node_index_by_name);
-
- for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
- {
- node = vam->graph_nodes[0][i];
- vec_free (node->name);
- vec_free (node->next_nodes);
- vec_free (node);
- }
- vec_free (vam->graph_nodes[0]);
- vec_free (vam->graph_nodes);
- }
-
- vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
- vam->graph_nodes = vlib_node_unserialize (pvt_copy);
- vec_free (pvt_copy);
-
- for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
- {
- node = vam->graph_nodes[0][i];
- hash_set_mem (vam->graph_node_index_by_name, node->name, i);
- }
-}
-
-static void vl_api_get_node_graph_reply_t_handler_json
- (vl_api_get_node_graph_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- void *oldheap;
- vat_json_node_t node;
- u8 *reply;
-
- /* $$$$ make this real? */
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
-
- reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
-
- /* Toss the shared-memory original... */
- oldheap = vl_msg_push_heap ();
-
- vec_free (reply);
-
- vl_msg_pop_heap (oldheap);
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-/* Format hex dump. */
-u8 *
-format_hex_bytes (u8 * s, va_list * va)
-{
- u8 *bytes = va_arg (*va, u8 *);
- int n_bytes = va_arg (*va, int);
- uword i;
-
- /* Print short or long form depending on byte count. */
- uword short_form = n_bytes <= 32;
- u32 indent = format_get_indent (s);
-
- if (n_bytes == 0)
- return s;
-
- for (i = 0; i < n_bytes; i++)
- {
- if (!short_form && (i % 32) == 0)
- s = format (s, "%08x: ", i);
- s = format (s, "%02x", bytes[i]);
- if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
- s = format (s, "\n%U", format_white_space, indent);
- }
-
- return s;
-}
-
/*
* Generate boilerplate reply handlers, which
* dig the return value out of the xxx_reply_t API message,
* a single function, but that could break in subtle ways.
*/
-#define foreach_standard_reply_retval_handler _ (session_rule_add_del_reply)
+#define foreach_standard_reply_retval_handler
#define _(n) \
static void vl_api_##n##_t_handler \
#define foreach_vpe_api_reply_msg \
_ (GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
- _ (GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
- _ (CONTROL_PING_REPLY, control_ping_reply) \
- _ (CLI_REPLY, cli_reply) \
- _ (CLI_INBAND_REPLY, cli_inband_reply) \
- _ (GET_NODE_INDEX_REPLY, get_node_index_reply) \
- _ (GET_NEXT_INDEX_REPLY, get_next_index_reply) \
- _ (ADD_NODE_NEXT_REPLY, add_node_next_reply) \
- _ (SHOW_VERSION_REPLY, show_version_reply) \
- _ (SHOW_THREADS_REPLY, show_threads_reply) \
- _ (APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
- _ (SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
- _ (SESSION_RULES_DETAILS, session_rules_details)
+ _ (CONTROL_PING_REPLY, control_ping_reply)
#define foreach_standalone_reply_msg \
case L2_VTR_ ## op: \
return "" # op;
-/*
- * Pass CLI buffers directly in the CLI_INBAND API message,
- * instead of an additional shared memory area.
- */
-static int
-exec_inband (vat_main_t * vam)
+static const char *
+str_vtr_op (u32 vtr_op)
{
- vl_api_cli_inband_t *mp;
- unformat_input_t *i = vam->input;
- int ret;
-
- if (vec_len (i->buffer) == 0)
- return -1;
-
- if (vam->exec_mode == 0 && unformat (i, "mode"))
+ switch (vtr_op)
{
- vam->exec_mode = 1;
- return 0;
- }
- if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
- {
- vam->exec_mode = 0;
- return 0;
+ STR_VTR_OP_CASE (DISABLED);
+ STR_VTR_OP_CASE (PUSH_1);
+ STR_VTR_OP_CASE (PUSH_2);
+ STR_VTR_OP_CASE (POP_1);
+ STR_VTR_OP_CASE (POP_2);
+ STR_VTR_OP_CASE (TRANSLATE_1_1);
+ STR_VTR_OP_CASE (TRANSLATE_1_2);
+ STR_VTR_OP_CASE (TRANSLATE_2_1);
+ STR_VTR_OP_CASE (TRANSLATE_2_2);
}
- /*
- * In order for the CLI command to work, it
- * must be a vector ending in \n, not a C-string ending
- * in \n\0.
- */
- M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
- vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
-
- S (mp);
- W (ret);
- /* json responses may or may not include a useful reply... */
- if (vec_len (vam->cmd_reply))
- print (vam->ofp, "%v", (char *) (vam->cmd_reply));
- return ret;
-}
-
-int
-exec (vat_main_t *vam)
-{
- return exec_inband (vam);
-}
-
-int
-api_sw_interface_dump (vat_main_t *vam)
-{
- return 0;
+ return "UNKNOWN";
}
uword
if (match == 0)
clib_warning ("BUG: match 0");
- _vec_len (mask) = match * sizeof (u32x4);
+ vec_set_len (mask, match * sizeof (u32x4));
*matchp = match;
*maskp = mask;
else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
;
else
- break;
- }
-
- if (l4 && !l3)
- {
- vec_free (match);
- vec_free (l2);
- vec_free (l4);
- return 0;
- }
-
- if (match || l2 || l3 || l4)
- {
- if (l2 || l3 || l4)
- {
- /* "Win a free Ethernet header in every packet" */
- if (l2 == 0)
- vec_validate_aligned (l2, 13, sizeof (u32x4));
- match = l2;
- if (vec_len (l3))
- {
- vec_append_aligned (match, l3, sizeof (u32x4));
- vec_free (l3);
- }
- if (vec_len (l4))
- {
- vec_append_aligned (match, l4, sizeof (u32x4));
- vec_free (l4);
- }
- }
-
- /* Make sure the vector is big enough even if key is all 0's */
- vec_validate_aligned
- (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
- sizeof (u32x4));
-
- /* Set size, include skipped vectors */
- _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
-
- *matchp = match;
-
- return 1;
- }
-
- return 0;
-}
-
-static int
-api_get_node_index (vat_main_t *vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_get_node_index_t *mp;
- u8 *name = 0;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "node %s", &name))
- ;
- else
- break;
- }
- if (name == 0)
- {
- errmsg ("node name required");
- return -99;
- }
- if (vec_len (name) >= ARRAY_LEN (mp->node_name))
- {
- errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
- return -99;
- }
-
- M (GET_NODE_INDEX, mp);
- clib_memcpy (mp->node_name, name, vec_len (name));
- vec_free (name);
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_get_next_index (vat_main_t *vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_get_next_index_t *mp;
- u8 *node_name = 0, *next_node_name = 0;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "node-name %s", &node_name))
- ;
- else if (unformat (i, "next-node-name %s", &next_node_name))
- break;
- }
-
- if (node_name == 0)
- {
- errmsg ("node name required");
- return -99;
- }
- if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
- {
- errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
- return -99;
- }
-
- if (next_node_name == 0)
- {
- errmsg ("next node name required");
- return -99;
- }
- if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
- {
- errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
- return -99;
- }
-
- M (GET_NEXT_INDEX, mp);
- clib_memcpy (mp->node_name, node_name, vec_len (node_name));
- clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
- vec_free (node_name);
- vec_free (next_node_name);
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_add_node_next (vat_main_t *vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_add_node_next_t *mp;
- u8 *name = 0;
- u8 *next = 0;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "node %s", &name))
- ;
- else if (unformat (i, "next %s", &next))
- ;
- else
- break;
- }
- if (name == 0)
- {
- errmsg ("node name required");
- return -99;
- }
- if (vec_len (name) >= ARRAY_LEN (mp->node_name))
- {
- errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
- return -99;
+ break;
}
- if (next == 0)
+
+ if (l4 && !l3)
{
- errmsg ("next node required");
- return -99;
+ vec_free (match);
+ vec_free (l2);
+ vec_free (l4);
+ return 0;
}
- if (vec_len (next) >= ARRAY_LEN (mp->next_name))
+
+ if (match || l2 || l3 || l4)
{
- errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
- return -99;
- }
+ if (l2 || l3 || l4)
+ {
+ /* "Win a free Ethernet header in every packet" */
+ if (l2 == 0)
+ vec_validate_aligned (l2, 13, sizeof (u32x4));
+ match = l2;
+ if (vec_len (l3))
+ {
+ vec_append_aligned (match, l3, sizeof (u32x4));
+ vec_free (l3);
+ }
+ if (vec_len (l4))
+ {
+ vec_append_aligned (match, l4, sizeof (u32x4));
+ vec_free (l4);
+ }
+ }
- M (ADD_NODE_NEXT, mp);
- clib_memcpy (mp->node_name, name, vec_len (name));
- clib_memcpy (mp->next_name, next, vec_len (next));
- vec_free (name);
- vec_free (next);
+ /* Make sure the vector is big enough even if key is all 0's */
+ vec_validate_aligned
+ (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
+ sizeof (u32x4));
- S (mp);
- W (ret);
- return ret;
+ /* Set size, include skipped vectors */
+ vec_set_len (match, (match_n_vectors + skip_n_vectors) * sizeof (u32x4));
+
+ *matchp = match;
+
+ return 1;
+ }
+
+ return 0;
}
#define foreach_vtr_op \
_ ("translate-2-1", L2_VTR_TRANSLATE_2_1) \
_ ("translate-2-2", L2_VTR_TRANSLATE_2_2)
-static int
-api_show_version (vat_main_t *vam)
-{
- vl_api_show_version_t *mp;
- int ret;
-
- M (SHOW_VERSION, mp);
-
- S (mp);
- W (ret);
- return ret;
-}
-
static int
api_get_first_msg_id (vat_main_t *vam)
{
return ret;
}
-static int
-api_get_node_graph (vat_main_t *vam)
-{
- vl_api_get_node_graph_t *mp;
- int ret;
-
- M (GET_NODE_GRAPH, mp);
-
- /* send it... */
- S (mp);
- /* Wait for the reply */
- W (ret);
- return ret;
-}
-
#define foreach_pbb_vtr_op \
_("disable", L2_VTR_DISABLED) \
_("pop", L2_VTR_POP_2) \
_("push", L2_VTR_PUSH_2)
-
-static void vl_api_app_namespace_add_del_reply_t_handler
- (vl_api_app_namespace_add_del_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- i32 retval = ntohl (mp->retval);
- if (vam->async_mode)
- {
- vam->async_errors += (retval < 0);
- }
- else
- {
- vam->retval = retval;
- if (retval == 0)
- errmsg ("app ns index %d\n", ntohl (mp->appns_index));
- vam->result_ready = 1;
- }
-}
-
-static void vl_api_app_namespace_add_del_reply_t_handler_json
- (vl_api_app_namespace_add_del_reply_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t node;
-
- vat_json_init_object (&node);
- vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
- vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
-
- vat_json_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
-static int
-api_app_namespace_add_del (vat_main_t * vam)
-{
- vl_api_app_namespace_add_del_t *mp;
- unformat_input_t *i = vam->input;
- u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
- u32 sw_if_index, ip4_fib_id, ip6_fib_id;
- u64 secret;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "id %_%v%_", &ns_id))
- ;
- else if (unformat (i, "secret %lu", &secret))
- secret_set = 1;
- else if (unformat (i, "sw_if_index %d", &sw_if_index))
- sw_if_index_set = 1;
- else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
- ;
- else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
- ;
- else
- break;
- }
- if (!ns_id || !secret_set || !sw_if_index_set)
- {
- errmsg ("namespace id, secret and sw_if_index must be set");
- return -99;
- }
- if (vec_len (ns_id) > 64)
- {
- errmsg ("namespace id too long");
- return -99;
- }
- M (APP_NAMESPACE_ADD_DEL, mp);
-
- vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
- mp->secret = clib_host_to_net_u64 (secret);
- mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
- mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
- mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
- vec_free (ns_id);
- S (mp);
- W (ret);
- return ret;
-}
-
static int
api_sock_init_shm (vat_main_t * vam)
{
#endif
}
-static void
-vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
-{
- vat_main_t *vam = &vat_main;
- fib_prefix_t lcl, rmt;
-
- ip_prefix_decode (&mp->lcl, &lcl);
- ip_prefix_decode (&mp->rmt, &rmt);
-
- if (lcl.fp_proto == FIB_PROTOCOL_IP4)
- {
- print (vam->ofp,
- "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
- clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
- mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
- clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
- &rmt.fp_addr.ip4, rmt.fp_len,
- clib_net_to_host_u16 (mp->rmt_port),
- clib_net_to_host_u32 (mp->action_index), mp->tag);
- }
- else
- {
- print (vam->ofp,
- "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
- clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
- mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
- clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
- &rmt.fp_addr.ip6, rmt.fp_len,
- clib_net_to_host_u16 (mp->rmt_port),
- clib_net_to_host_u32 (mp->action_index), mp->tag);
- }
-}
-
-static void
-vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
- mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t *node = NULL;
- struct in6_addr ip6;
- struct in_addr ip4;
-
- fib_prefix_t lcl, rmt;
-
- ip_prefix_decode (&mp->lcl, &lcl);
- ip_prefix_decode (&mp->rmt, &rmt);
-
- if (VAT_JSON_ARRAY != vam->json_tree.type)
- {
- ASSERT (VAT_JSON_NONE == vam->json_tree.type);
- vat_json_init_array (&vam->json_tree);
- }
- node = vat_json_array_add (&vam->json_tree);
- vat_json_init_object (node);
-
- vat_json_object_add_uint (node, "appns_index",
- clib_net_to_host_u32 (mp->appns_index));
- vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
- vat_json_object_add_uint (node, "scope", mp->scope);
- vat_json_object_add_uint (node, "action_index",
- clib_net_to_host_u32 (mp->action_index));
- vat_json_object_add_uint (node, "lcl_port",
- clib_net_to_host_u16 (mp->lcl_port));
- vat_json_object_add_uint (node, "rmt_port",
- clib_net_to_host_u16 (mp->rmt_port));
- vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
- vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
- vat_json_object_add_string_copy (node, "tag", mp->tag);
- if (lcl.fp_proto == FIB_PROTOCOL_IP4)
- {
- clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
- vat_json_object_add_ip4 (node, "lcl_ip", ip4);
- clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
- vat_json_object_add_ip4 (node, "rmt_ip", ip4);
- }
- else
- {
- clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
- vat_json_object_add_ip6 (node, "lcl_ip", ip6);
- clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
- vat_json_object_add_ip6 (node, "rmt_ip", ip6);
- }
-}
-
-static int
-api_session_rule_add_del (vat_main_t * vam)
-{
- vl_api_session_rule_add_del_t *mp;
- unformat_input_t *i = vam->input;
- u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
- u32 appns_index = 0, scope = 0;
- ip4_address_t lcl_ip4, rmt_ip4;
- ip6_address_t lcl_ip6, rmt_ip6;
- u8 is_ip4 = 1, conn_set = 0;
- u8 is_add = 1, *tag = 0;
- int ret;
- fib_prefix_t lcl, rmt;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "del"))
- is_add = 0;
- else if (unformat (i, "add"))
- ;
- else if (unformat (i, "proto tcp"))
- proto = 0;
- else if (unformat (i, "proto udp"))
- proto = 1;
- else if (unformat (i, "appns %d", &appns_index))
- ;
- else if (unformat (i, "scope %d", &scope))
- ;
- else if (unformat (i, "tag %_%v%_", &tag))
- ;
- else
- if (unformat
- (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
- &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
- &rmt_port))
- {
- is_ip4 = 1;
- conn_set = 1;
- }
- else
- if (unformat
- (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
- &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
- &rmt_port))
- {
- is_ip4 = 0;
- conn_set = 1;
- }
- else if (unformat (i, "action %d", &action))
- ;
- else
- break;
- }
- if (proto == ~0 || !conn_set || action == ~0)
- {
- errmsg ("transport proto, connection and action must be set");
- return -99;
- }
-
- if (scope > 3)
- {
- errmsg ("scope should be 0-3");
- return -99;
- }
-
- M (SESSION_RULE_ADD_DEL, mp);
-
- clib_memset (&lcl, 0, sizeof (lcl));
- clib_memset (&rmt, 0, sizeof (rmt));
- if (is_ip4)
- {
- ip_set (&lcl.fp_addr, &lcl_ip4, 1);
- ip_set (&rmt.fp_addr, &rmt_ip4, 1);
- lcl.fp_len = lcl_plen;
- rmt.fp_len = rmt_plen;
- }
- else
- {
- ip_set (&lcl.fp_addr, &lcl_ip6, 0);
- ip_set (&rmt.fp_addr, &rmt_ip6, 0);
- lcl.fp_len = lcl_plen;
- rmt.fp_len = rmt_plen;
- }
-
-
- ip_prefix_encode (&lcl, &mp->lcl);
- ip_prefix_encode (&rmt, &mp->rmt);
- mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
- mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
- mp->transport_proto =
- proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
- mp->action_index = clib_host_to_net_u32 (action);
- mp->appns_index = clib_host_to_net_u32 (appns_index);
- mp->scope = scope;
- mp->is_add = is_add;
- if (tag)
- {
- clib_memcpy (mp->tag, tag, vec_len (tag));
- vec_free (tag);
- }
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_session_rules_dump (vat_main_t * vam)
-{
- vl_api_session_rules_dump_t *mp;
- vl_api_control_ping_t *mp_ping;
- int ret;
-
- if (!vam->json_output)
- {
- print (vam->ofp, "%=20s", "Session Rules");
- }
-
- M (SESSION_RULES_DUMP, mp);
- /* send it... */
- S (mp);
-
- /* Use a control ping for synchronization */
- MPING (CONTROL_PING, mp_ping);
- S (mp_ping);
-
- /* Wait for a reply... */
- W (ret);
- return ret;
-}
-
static int
q_or_quit (vat_main_t * vam)
{
print (vam->ofp, "Help is available for the following:");
- /* *INDENT-OFF* */
hash_foreach_pair (p, vam->function_by_name,
({
vec_add1 (cmds, (u8 *)(p->key));
}));
- /* *INDENT-ON* */
vec_sort_with_function (cmds, cmd_cmp);
int i;
hash_pair_t *p;
- /* *INDENT-OFF* */
- hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
- ({
- vec_add2 (sort_me, sm, 1);
- sm->name = (u8 *)(p->key);
- sm->value = (u8 *) (p->value[0]);
- }));
- /* *INDENT-ON* */
+ hash_foreach_pair (p, vam->macro_main.the_value_table_hash, ({
+ vec_add2 (sort_me, sm, 1);
+ sm->name = (u8 *) (p->key);
+ sm->value = (u8 *) (p->value[0]);
+ }));
vec_sort_with_function (sort_me, macro_sort_cmp);
hash_pair_t *hp;
int i;
- /* *INDENT-OFF* */
hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
({
vec_add2 (nses, ns, 1);
ns->name = (u8 *)(hp->key);
ns->value = (u32) hp->value[0];
}));
- /* *INDENT-ON* */
vec_sort_with_function (nses, value_sort_cmp);
return 0;
}
+int exec (vat_main_t *vam) __attribute__ ((weak));
+int
+exec (vat_main_t *vam)
+{
+ return -1;
+}
+
+static int
+name_sort_cmp (void *a1, void *a2)
+{
+ name_sort_t *n1 = a1;
+ name_sort_t *n2 = a2;
+
+ return strcmp ((char *) n1->name, (char *) n2->name);
+}
+
+static int
+dump_interface_table (vat_main_t *vam)
+{
+ hash_pair_t *p;
+ name_sort_t *nses = 0, *ns;
+
+ if (vam->json_output)
+ {
+ clib_warning (
+ "JSON output supported only for VPE API calls and dump_stats_table");
+ return -99;
+ }
+
+ hash_foreach_pair (p, vam->sw_if_index_by_interface_name, ({
+ vec_add2 (nses, ns, 1);
+ ns->name = (u8 *) (p->key);
+ ns->value = (u32) p->value[0];
+ }));
+
+ vec_sort_with_function (nses, name_sort_cmp);
+
+ print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
+ vec_foreach (ns, nses)
+ {
+ print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
+ }
+ vec_free (nses);
+ return 0;
+}
+
+static int
+dump_sub_interface_table (vat_main_t *vam)
+{
+ const sw_interface_subif_t *sub = NULL;
+
+ if (vam->json_output)
+ {
+ clib_warning (
+ "JSON output supported only for VPE API calls and dump_stats_table");
+ return -99;
+ }
+
+ print (vam->ofp, "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
+ "Interface", "sw_if_index", "sub id", "dot1ad", "tags", "outer id",
+ "inner id", "exact", "default", "outer any", "inner any");
+
+ vec_foreach (sub, vam->sw_if_subif_table)
+ {
+ print (vam->ofp, "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
+ sub->interface_name, sub->sw_if_index, sub->sub_id,
+ sub->sub_dot1ad ? "dot1ad" : "dot1q", sub->sub_number_of_tags,
+ sub->sub_outer_vlan_id, sub->sub_inner_vlan_id,
+ sub->sub_exact_match, sub->sub_default,
+ sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
+ if (sub->vtr_op != L2_VTR_DISABLED)
+ {
+ print (vam->ofp,
+ " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
+ "tag1: %d tag2: %d ]",
+ str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q, sub->vtr_tag1,
+ sub->vtr_tag2);
+ }
+ }
+
+ return 0;
+}
+
/* List of API message constructors, CLI names map to api_xxx */
#define foreach_vpe_api_msg \
-_(get_node_index, "node <node-name") \
-_(add_node_next, "node <node-name> next <next-node-name>") \
-_(show_version, "") \
-_(show_threads, "") \
_(get_first_msg_id, "client <name>") \
-_(get_node_graph, " ") \
-_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
_(sock_init_shm, "size <nnn>") \
-_(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
-_(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
- "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
-_(session_rules_dump, "") \
-
/* List of command functions, CLI names map directly to functions */
-#define foreach_cli_function \
-_(comment, "usage: comment <ignore-rest-of-line>") \
-_(dump_macro_table, "usage: dump_macro_table ") \
-_(dump_msg_api_table, "usage: dump_msg_api_table") \
-_(elog_setup, "usage: elog_setup [nevents, default 128K]") \
-_(elog_disable, "usage: elog_disable") \
-_(elog_enable, "usage: elog_enable") \
-_(elog_save, "usage: elog_save <filename>") \
-_(get_msg_id, "usage: get_msg_id name_and_crc") \
-_(echo, "usage: echo <message>") \
-_(exec, "usage: exec <vpe-debug-CLI-command>") \
-_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
-_(help, "usage: help") \
-_(q, "usage: quit") \
-_(quit, "usage: quit") \
-_(search_node_table, "usage: search_node_table <name>...") \
-_(set, "usage: set <variable-name> <value>") \
-_(script, "usage: script <file-name>") \
-_(statseg, "usage: statseg") \
-_(unset, "usage: unset <variable-name>")
+#define foreach_cli_function \
+ _ (comment, "usage: comment <ignore-rest-of-line>") \
+ _ (dump_interface_table, "usage: dump_interface_table") \
+ _ (dump_sub_interface_table, "usage: dump_sub_interface_table") \
+ _ (dump_macro_table, "usage: dump_macro_table ") \
+ _ (dump_msg_api_table, "usage: dump_msg_api_table") \
+ _ (elog_setup, "usage: elog_setup [nevents, default 128K]") \
+ _ (elog_disable, "usage: elog_disable") \
+ _ (elog_enable, "usage: elog_enable") \
+ _ (elog_save, "usage: elog_save <filename>") \
+ _ (get_msg_id, "usage: get_msg_id name_and_crc") \
+ _ (echo, "usage: echo <message>") \
+ _ (help, "usage: help") \
+ _ (q, "usage: quit") \
+ _ (quit, "usage: quit") \
+ _ (search_node_table, "usage: search_node_table <name>...") \
+ _ (set, "usage: set <variable-name> <value>") \
+ _ (script, "usage: script <file-name>") \
+ _ (statseg, "usage: statseg") \
+ _ (unset, "usage: unset <variable-name>")
#define _(N,n) \
static void vl_api_##n##_t_handler_uni \
void
vat_api_hookup (vat_main_t * vam)
{
-#define _(N,n) \
- vl_msg_api_set_handlers(VL_API_##N, #n, \
- vl_api_##n##_t_handler_uni, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
+#define _(N, n) \
+ vl_msg_api_config (&(vl_msg_api_msg_config_t){ \
+ .id = VL_API_##N + 1, \
+ .name = #n, \
+ .handler = vl_api_##n##_t_handler_uni, \
+ .endian = vl_api_##n##_t_endian, \
+ .format_fn = vl_api_##n##_t_format, \
+ .size = sizeof (vl_api_##n##_t), \
+ .traced = 1, \
+ .tojson = vl_api_##n##_t_tojson, \
+ .fromjson = vl_api_##n##_t_fromjson, \
+ .calc_size = vl_api_##n##_t_calc_size, \
+ });
foreach_vpe_api_reply_msg;
#if VPP_API_TEST_BUILTIN == 0
foreach_standalone_reply_msg;
#undef _
#if (VPP_API_TEST_BUILTIN==0)
- vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
+ vl_msg_api_set_first_available_msg_id (VL_MSG_MEMCLNT_LAST + 1);
vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));