summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2021-09-27 17:11:34 +0200
committerFlorin Coras <florin.coras@gmail.com>2021-09-28 15:17:37 +0000
commit3459ece6da90627b161e2128b5926f1e58e7db65 (patch)
tree1416cae6fa48c233cfe1cf7b69d0446fef77aa50
parent7d0e30bc642f9137188e962f3d1fe38303e674ba (diff)
misc: vpe.api messages dynamically allocated
This is the last in the series of moving API messages from vpp/api/vpe.api to vlibmemory/memclnt.api. This patch makes the remaining vpe.api messages dynamic, to help VAT2 binary-api command. Moves the VAT test code to a separate file and removes the now unnused API meta files. Type: improvement Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I01dd78eaff1d3715dff17d2643bf0f7f0089935b Signed-off-by: Ole Troan <ot@cisco.com>
-rw-r--r--src/plugins/vrrp/vrrp_all_api_h.h11
-rw-r--r--src/plugins/vrrp/vrrp_msg_enum.h23
-rw-r--r--src/vat/api_format.c78
-rw-r--r--src/vlibmemory/memory_api.c8
-rw-r--r--src/vlibmemory/vlib_api.c2
-rw-r--r--src/vnet/classify/classify_api.c9
-rw-r--r--src/vpp-api/client/client.c16
-rw-r--r--src/vpp-api/client/test.c6
-rw-r--r--src/vpp/CMakeLists.txt6
-rw-r--r--src/vpp/api/api.c76
-rw-r--r--src/vpp/api/api_test.c99
-rw-r--r--src/vpp/api/test_client.c1538
-rw-r--r--src/vpp/api/test_ha.c245
-rw-r--r--src/vpp/api/types.h5
-rw-r--r--src/vpp/api/vpe_all_api_h.h33
-rw-r--r--src/vpp/api/vpe_msg_enum.h37
-rw-r--r--src/vpp/vnet/main.c4
17 files changed, 150 insertions, 2046 deletions
diff --git a/src/plugins/vrrp/vrrp_all_api_h.h b/src/plugins/vrrp/vrrp_all_api_h.h
deleted file mode 100644
index 4f45909de70..00000000000
--- a/src/plugins/vrrp/vrrp_all_api_h.h
+++ /dev/null
@@ -1,11 +0,0 @@
-
-/*
- * vrrp_all_api_h.h - vrrp plug-in api #include file
- *
- * Copyright 2019-2020 Rubicon Communications, LLC (Netgate)
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- */
-/* Include the generated file, see BUILT_SOURCES in Makefile.am */
-#include <vrrp/vrrp.api.h>
diff --git a/src/plugins/vrrp/vrrp_msg_enum.h b/src/plugins/vrrp/vrrp_msg_enum.h
deleted file mode 100644
index 48ae619205a..00000000000
--- a/src/plugins/vrrp/vrrp_msg_enum.h
+++ /dev/null
@@ -1,23 +0,0 @@
-
-/*
- * vrrp_msg_enum.h - vrrp plug-in message enumeration
- *
- * Copyright 2019-2020 Rubicon Communications, LLC (Netgate)
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- */
-#ifndef included_vrrp_msg_enum_h
-#define included_vrrp_msg_enum_h
-
-#include <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum {
-#include <vrrp/vrrp_all_api_h.h>
- /* We'll want to know how many messages IDs we need... */
- VL_MSG_FIRST_AVAILABLE,
-} vl_msg_id_t;
-#undef vl_msg_id
-
-#endif /* included_vrrp_msg_enum_h */
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 33e5a275551..1458fde5190 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -29,7 +29,6 @@
#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>
@@ -56,14 +55,11 @@
#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>
#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
+#include <vlibmemory/memclnt.api.h>
#undef vl_endianfun
/* instantiate all the print functions we know about */
@@ -73,7 +69,7 @@
#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
@@ -579,44 +575,6 @@ ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
}
-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);
- }
- vam->retval = retval;
- vam->result_ready = 1;
-}
-
-static void vl_api_show_version_reply_t_handler_json
- (vl_api_show_version_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_print (vam->ofp, &node);
- vat_json_free (&node);
-
- vam->retval = ntohl (mp->retval);
- vam->result_ready = 1;
-}
-
#define vl_api_bridge_domain_details_t_endian vl_noop_handler
#define vl_api_bridge_domain_details_t_print vl_noop_handler
@@ -735,7 +693,6 @@ foreach_standard_reply_retval_handler;
#define foreach_vpe_api_reply_msg \
_ (GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
- _ (SHOW_VERSION_REPLY, show_version_reply) \
#define foreach_standalone_reply_msg \
@@ -2014,19 +1971,6 @@ api_unformat_classify_match (unformat_input_t * input, va_list * args)
_ ("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)
{
vl_api_get_first_msg_id_t *mp;
@@ -2638,7 +2582,6 @@ exec (vat_main_t *vam)
/* List of API message constructors, CLI names map to api_xxx */
#define foreach_vpe_api_msg \
-_(show_version, "") \
_(get_first_msg_id, "client <name>") \
_(sock_init_shm, "size <nnn>") \
/* List of command functions, CLI names map directly to functions */
@@ -2681,13 +2624,10 @@ foreach_standalone_reply_msg;
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_set_handlers (VL_API_##N + 1, #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);
foreach_vpe_api_reply_msg;
#if VPP_API_TEST_BUILTIN == 0
foreach_standalone_reply_msg;
@@ -2695,7 +2635,7 @@ vat_api_hookup (vat_main_t * vam)
#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));
diff --git a/src/vlibmemory/memory_api.c b/src/vlibmemory/memory_api.c
index 4287bd36e5f..9db27ebd574 100644
--- a/src/vlibmemory/memory_api.c
+++ b/src/vlibmemory/memory_api.c
@@ -457,6 +457,14 @@ vl_mem_api_init (const char *region_name)
foreach_vlib_api_msg;
#undef _
+#define vl_msg_name_crc_list
+#include <vlibmemory/memclnt.api.h>
+#undef vl_msg_name_crc_list
+
+#define _(id, n, crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
+ foreach_vl_msg_name_crc_memclnt;
+#undef _
+
/*
* special-case freeing of memclnt_delete messages, so we can
* simply munmap pairwise / private API segments...
diff --git a/src/vlibmemory/vlib_api.c b/src/vlibmemory/vlib_api.c
index 0d9444619af..6962ea01f5d 100644
--- a/src/vlibmemory/vlib_api.c
+++ b/src/vlibmemory/vlib_api.c
@@ -22,7 +22,7 @@
#include <vlibmemory/vlib.api_enum.h>
#include <vlibmemory/vlib.api_types.h>
-u16 msg_id_base;
+static u16 msg_id_base;
#define REPLY_MSG_ID_BASE msg_id_base
#include <vlibapi/api_helper_macros.h>
diff --git a/src/vnet/classify/classify_api.c b/src/vnet/classify/classify_api.c
index 39f7b98007d..ccfe8a0ae65 100644
--- a/src/vnet/classify/classify_api.c
+++ b/src/vnet/classify/classify_api.c
@@ -915,6 +915,15 @@ static void vl_api_output_acl_set_interface_t_handler
static clib_error_t *
classify_api_hookup (vlib_main_t * vm)
{
+ api_main_t *am = vlibapi_get_main ();
+
+ /*
+ * Trace space for classifier mask+match
+ */
+ am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
+ am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size +=
+ 5 * sizeof (u32x4);
+
/*
* Set up the (msg_name, crc, message-id) table
*/
diff --git a/src/vpp-api/client/client.c b/src/vpp-api/client/client.c
index 902ed3bd625..542df9d414b 100644
--- a/src/vpp-api/client/client.c
+++ b/src/vpp-api/client/client.c
@@ -30,7 +30,8 @@
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
-#include <vpp/api/vpe_msg_enum.h>
+#include <vlibmemory/memclnt.api_enum.h>
+#include <vlibmemory/memclnt.api_types.h>
#include "vppapiclient.h"
@@ -48,14 +49,6 @@ bool rx_thread_done;
* vac_read() -> resumes RX thread
*/
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_endianfun
-
typedef struct {
u8 connected_to_vlib;
pthread_t rx_thread_handle;
@@ -497,10 +490,11 @@ vac_read (char **p, int *l, u16 timeout)
/*
* XXX: Makes the assumption that client_index is the first member
*/
-typedef VL_API_PACKED(struct _vl_api_header {
+typedef struct _vl_api_header
+{
u16 _vl_msg_id;
u32 client_index;
-}) vl_api_header_t;
+} __attribute__ ((packed)) vl_api_header_t;
static u32
vac_client_index (void)
diff --git a/src/vpp-api/client/test.c b/src/vpp-api/client/test.c
index 4e98dc03a14..b7e6f017445 100644
--- a/src/vpp-api/client/test.c
+++ b/src/vpp-api/client/test.c
@@ -32,7 +32,6 @@
#include <vlib/unix/unix.h>
#include <vlibapi/api.h>
#include <vppinfra/time.h>
-#include <vpp/api/vpe_msg_enum.h>
#include <signal.h>
#include "vppapiclient.h"
#include "stat_client.h"
@@ -40,9 +39,8 @@
#include <vlibmemory/vlib.api_enum.h>
#include <vlibmemory/vlib.api_types.h>
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
+#include <vpp/api/vpe.api_enum.h>
+#include <vpp/api/vpe.api_types.h>
volatile int sigterm_received = 0;
volatile u32 result_ready;
diff --git a/src/vpp/CMakeLists.txt b/src/vpp/CMakeLists.txt
index 32f702de36d..32984c0cee9 100644
--- a/src/vpp/CMakeLists.txt
+++ b/src/vpp/CMakeLists.txt
@@ -85,8 +85,6 @@ add_vpp_executable(vpp
)
add_vpp_headers(vpp
- api/vpe_msg_enum.h
- api/vpe_all_api_h.h
stats/stat_segment.h
stats/stat_segment_shared.h
)
@@ -141,6 +139,10 @@ add_vpp_test_library(vpp
${VPP_API_FILES}
)
+add_vat_test_library(vpp
+ api/api_test.c
+)
+
##############################################################################
# minimal interactive startup.conf - only if not present
##############################################################################
diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c
index 70dfd1f8271..7b1b7902680 100644
--- a/src/vpp/api/api.c
+++ b/src/vpp/api/api.c
@@ -58,28 +58,14 @@
#include <vnet/ip/format.h>
-#include <vpp/api/vpe_msg_enum.h>
#include <vpp/api/types.h>
-#include <vnet/classify/classify.api_enum.h>
-#include <vnet/ip/ip.api_enum.h>
-
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_endianfun
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_printfun
-#include <vlibapi/api_helper_macros.h>
-#define foreach_vpe_api_msg \
- _ (SHOW_VERSION, show_version) \
- _ (SHOW_VPE_SYSTEM_TIME, show_vpe_system_time) \
- _ (LOG_DUMP, log_dump)
+#include <vpp/api/vpe.api_enum.h>
+#include <vpp/api/vpe.api_types.h>
+
+static u16 msg_id_base;
+#define REPLY_MSG_ID_BASE msg_id_base
+#include <vlibapi/api_helper_macros.h>
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
@@ -165,7 +151,7 @@ show_log_details (vl_api_registration_t * reg, u32 context,
rmp = vl_msg_api_alloc (msg_size);
clib_memset (rmp, 0, msg_size);
- rmp->_vl_msg_id = ntohs (VL_API_LOG_DETAILS);
+ rmp->_vl_msg_id = ntohs (VL_API_LOG_DETAILS + msg_id_base);
rmp->context = context;
rmp->timestamp = clib_host_to_net_f64 (timestamp);
@@ -244,8 +230,6 @@ static void vl_api_##nn##_t_handler ( \
vl_msg_api_free (mp); \
}
-static void setup_message_id_table (api_main_t * am);
-
/*
* vpe_api_hookup
* Add vpe's API message handlers to the table.
@@ -253,37 +237,14 @@ static void setup_message_id_table (api_main_t * am);
* added the client registration handlers.
* See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
*/
+#include <vpp/api/vpe.api.c>
static clib_error_t *
vpe_api_hookup (vlib_main_t * vm)
{
- api_main_t *am = vlibapi_get_main ();
-
-#define _(N,n) \
- vl_msg_api_set_handlers(VL_API_##N, #n, \
- vl_api_##n##_t_handler, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_vpe_api_msg;
-#undef _
-
- /*
- * Trace space for classifier mask+match
- */
- am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
- am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size +=
- 5 * sizeof (u32x4);
-
- /*
- * Thread-safe API messages
- */
- am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
-
/*
* Set up the (msg_name, crc, message-id) table
*/
- setup_message_id_table (am);
+ msg_id_base = setup_message_id_table ();
return 0;
}
@@ -433,25 +394,6 @@ get_unformat_vnet_sw_interface (void)
return (void *) &unformat_vnet_sw_interface;
}
-#define vl_msg_name_crc_list
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (api_main_t * am)
-{
-#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
- foreach_vl_msg_name_crc_memclnt;
- foreach_vl_msg_name_crc_vpe;
-#undef _
-
-#define vl_api_version_tuple(n,mj, mi, p) \
- vl_msg_api_add_version (am, #n, mj, mi, p);
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_api_version_tuple
-}
-
-
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vpp/api/api_test.c b/src/vpp/api/api_test.c
new file mode 100644
index 00000000000..0893d485607
--- /dev/null
+++ b/src/vpp/api/api_test.c
@@ -0,0 +1,99 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2021 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/vat.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+#include <vpp/api/types.h>
+
+#include <vpp/api/vpe.api_enum.h>
+#include <vpp/api/vpe.api_types.h>
+
+#define __plugin_msg_base vpe_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
+/* Declare message IDs */
+#include <vnet/format_fns.h>
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+ vat_main_t *vat_main;
+} vpe_test_main_t;
+
+vpe_test_main_t vpe_test_main;
+
+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_log_dump (vat_main_t *vam)
+{
+ /* Not yet implemented */
+ return -1;
+}
+
+static int
+api_show_vpe_system_time (vat_main_t *vam)
+{
+ /* Not yet implemented */
+ return -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);
+ }
+ vam->retval = retval;
+ vam->result_ready = 1;
+}
+
+static void
+vl_api_log_details_t_handler (vl_api_log_details_t *mp)
+{
+ /* Not yet implemented */
+}
+
+static void
+vl_api_show_vpe_system_time_reply_t_handler (
+ vl_api_show_vpe_system_time_reply_t *mp)
+{
+ /* Not yet implemented */
+}
+
+#include <vpp/api/vpe.api_test.c>
diff --git a/src/vpp/api/test_client.c b/src/vpp/api/test_client.c
deleted file mode 100644
index 38afefa8601..00000000000
--- a/src/vpp/api/test_client.c
+++ /dev/null
@@ -1,1538 +0,0 @@
-/*
- *------------------------------------------------------------------
- * api.c - message handler registration
- *
- * Copyright (c) 2010 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 <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <time.h>
-#include <fcntl.h>
-#include <string.h>
-#include <vppinfra/clib.h>
-#include <vppinfra/vec.h>
-#include <vppinfra/hash.h>
-#include <vppinfra/bitmap.h>
-#include <vppinfra/fifo.h>
-#include <vppinfra/time.h>
-#include <vppinfra/heap.h>
-#include <vppinfra/pool.h>
-#include <vppinfra/format.h>
-#include <vppinfra/error.h>
-
-#include <vnet/vnet.h>
-#include <vlib/vlib.h>
-#include <vlib/unix/unix.h>
-#include <vlibapi/api.h>
-#include <vlibmemory/api.h>
-
-#include <vpp/api/vpe_msg_enum.h>
-
-#include <vnet/ip/ip.h>
-#include <vnet/interface.h>
-
-#define f64_endian(a)
-#define f64_print(a,b)
-
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_printfun
-
-vl_shmem_hdr_t *shmem_hdr;
-
-typedef struct
-{
- int link_events_on;
- int stats_on;
- int oam_events_on;
-
- /* convenience */
- svm_queue_t *vl_input_queue;
- u32 my_client_index;
-} test_main_t;
-
-test_main_t test_main;
-
-/*
- * Satisfy external references when -lvlib is not available.
- */
-
-void
-vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
-{
- clib_warning ("vlib_cli_output called...");
-}
-
-u8 *
-format_ethernet_address (u8 * s, va_list * args)
-{
- u8 *a = va_arg (*args, u8 *);
-
- return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
- a[0], a[1], a[2], a[3], a[4], a[5]);
-}
-
-static void
-vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t * mp)
-{
- char *duplex, *speed;
-
- switch (mp->link_duplex << VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT)
- {
- case VNET_HW_INTERFACE_FLAG_HALF_DUPLEX:
- duplex = "half";
- break;
- case VNET_HW_INTERFACE_FLAG_FULL_DUPLEX:
- duplex = "full";
- break;
- default:
- duplex = "bogus";
- break;
- }
- switch (mp->link_speed << VNET_HW_INTERFACE_FLAG_SPEED_SHIFT)
- {
- case VNET_HW_INTERFACE_FLAG_SPEED_10M:
- speed = "10Mbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_100M:
- speed = "100Mbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_1G:
- speed = "1Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_2_5G:
- speed = "2.5Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_5G:
- speed = "5Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_10G:
- speed = "10Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_20G:
- speed = "20Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_25G:
- speed = "25Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_40G:
- speed = "40Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_50G:
- speed = "50Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_56G:
- speed = "56Gbps";
- break;
- case VNET_HW_INTERFACE_FLAG_SPEED_100G:
- speed = "100Gbps";
- break;
- default:
- speed = "bogus";
- break;
- }
- fformat (stdout,
- "details: %s device_type %s sw_if_index %d sup_sw_if_index %d "
- "link_duplex %s link_speed %s", mp->interface_name,
- mp->interface_dev_type, ntohl (mp->sw_if_index),
- ntohl (mp->sup_sw_if_index), duplex, speed);
-
- if (mp->l2_address_length)
- fformat (stdout, " l2 address: %U\n",
- format_ethernet_address, mp->l2_address);
- else
- fformat (stdout, "\n");
-}
-
-static void
-vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
-{
- fformat (stdout, "set flags: sw_if_index %d, admin %s\n",
- ntohl (mp->sw_if_index), mp->admin_up_down ? "up" : "down");
-}
-
-static void
- vl_api_sw_interface_set_flags_reply_t_handler
- (vl_api_sw_interface_set_flags_reply_t * mp)
-{
- fformat (stdout, "set flags reply: reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_want_interface_events_reply_t_handler
- (vl_api_want_interface_events_reply_t * mp)
-{
-}
-
-static void
-vl_api_want_stats_reply_t_handler (vl_api_want_stats_reply_t * mp)
-{
- fformat (stdout, "want stats reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_want_oam_events_reply_t_handler (vl_api_want_oam_events_reply_t * mp)
-{
- fformat (stdout, "want oam reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_ip_add_del_route_reply_t_handler (vl_api_ip_add_del_route_reply_t * mp)
-{
- fformat (stdout, "add_route reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_sw_interface_add_del_address_reply_t_handler
- (vl_api_sw_interface_add_del_address_reply_t * mp)
-{
- fformat (stdout, "add_del_address reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_sw_interface_set_table_reply_t_handler
- (vl_api_sw_interface_set_table_reply_t * mp)
-{
- fformat (stdout, "set_table reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_tap_connect_reply_t_handler (vl_api_tap_connect_reply_t * mp)
-{
- fformat (stdout, "tap connect reply %d, sw_if_index %d\n",
- ntohl (mp->retval), ntohl (mp->sw_if_index));
-}
-
-static void
-vl_api_create_vlan_subif_reply_t_handler (vl_api_create_vlan_subif_reply_t *
- mp)
-{
- fformat (stdout, "create vlan subif reply %d, sw_if_index %d\n",
- ntohl (mp->retval), ntohl (mp->sw_if_index));
-}
-
-static void vl_api_proxy_arp_add_del_reply_t_handler
- (vl_api_proxy_arp_add_del_reply_t * mp)
-{
- fformat (stdout, "add del proxy arp reply %d\n", ntohl (mp->retval));
-}
-
-static void vl_api_proxy_arp_intfc_enable_disable_reply_t_handler
- (vl_api_proxy_arp_intfc_enable_disable_reply_t * mp)
-{
- fformat (stdout, "proxy arp intfc ena/dis reply %d\n", ntohl (mp->retval));
-}
-
-static void vl_api_ip_neighbor_add_del_reply_t_handler
- (vl_api_ip_neighbor_add_del_reply_t * mp)
-{
- fformat (stdout, "ip neighbor add del reply %d\n", ntohl (mp->retval));
-}
-
-#if 0
-static void
-vl_api_vnet_interface_counters_t_handler (vl_api_vnet_interface_counters_t *
- mp)
-{
- char *counter_name;
- u32 count, sw_if_index;
- int i;
-
- count = ntohl (mp->count);
- sw_if_index = ntohl (mp->first_sw_if_index);
- if (mp->is_combined == 0)
- {
- u64 *vp, v;
- vp = (u64 *) mp->data;
-
- switch (mp->vnet_counter_type)
- {
- case VNET_INTERFACE_COUNTER_DROP:
- counter_name = "drop";
- break;
- case VNET_INTERFACE_COUNTER_PUNT:
- counter_name = "punt";
- break;
- case VNET_INTERFACE_COUNTER_IP4:
- counter_name = "ip4";
- break;
- case VNET_INTERFACE_COUNTER_IP6:
- counter_name = "ip6";
- break;
- case VNET_INTERFACE_COUNTER_RX_NO_BUF:
- counter_name = "rx-no-buf";
- break;
- case VNET_INTERFACE_COUNTER_RX_MISS:
- counter_name = "rx-miss";
- break;
- case VNET_INTERFACE_COUNTER_RX_ERROR:
- counter_name = "rx-error";
- break;
- case VNET_INTERFACE_COUNTER_TX_ERROR:
- counter_name = "tx-error (fifo-full)";
- break;
- default:
- counter_name = "bogus";
- break;
- }
- for (i = 0; i < count; i++)
- {
- v = clib_mem_unaligned (vp, u64);
- v = clib_net_to_host_u64 (v);
- vp++;
- fformat (stdout, "%d.%s %lld\n", sw_if_index, counter_name, v);
- sw_if_index++;
- }
- }
- else
- {
- vlib_counter_t *vp;
- u64 packets, bytes;
- vp = (vlib_counter_t *) mp->data;
-
- switch (mp->vnet_counter_type)
- {
- case VNET_INTERFACE_COUNTER_RX:
- counter_name = "rx";
- break;
- case VNET_INTERFACE_COUNTER_TX:
- counter_name = "tx";
- break;
- default:
- counter_name = "bogus";
- break;
- }
- for (i = 0; i < count; i++)
- {
- packets = clib_mem_unaligned (&vp->packets, u64);
- packets = clib_net_to_host_u64 (packets);
- bytes = clib_mem_unaligned (&vp->bytes, u64);
- bytes = clib_net_to_host_u64 (bytes);
- vp++;
- fformat (stdout, "%d.%s.packets %lld\n",
- sw_if_index, counter_name, packets);
- fformat (stdout, "%d.%s.bytes %lld\n",
- sw_if_index, counter_name, bytes);
- sw_if_index++;
- }
- }
-}
-#endif
-
-/* Format an IP4 address. */
-u8 *
-format_ip4_address (u8 * s, va_list * args)
-{
- u8 *a = va_arg (*args, u8 *);
- return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
-}
-
-/* Format an IP4 route destination and length. */
-u8 *
-format_ip4_address_and_length (u8 * s, va_list * args)
-{
- u8 *a = va_arg (*args, u8 *);
- u8 l = va_arg (*args, u32);
- return format (s, "%U/%d", format_ip4_address, a, l);
-}
-
-static void
-vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp)
-{
- int i;
- vl_api_ip4_fib_counter_t *ctrp;
- u32 count;
-
- count = ntohl (mp->count);
-
- fformat (stdout, "fib id %d, count this msg %d\n",
- ntohl (mp->vrf_id), count);
-
- ctrp = mp->c;
- for (i = 0; i < count; i++)
- {
- fformat (stdout, "%U: %lld packets, %lld bytes\n",
- format_ip4_address_and_length, &ctrp->address,
- (u32) ctrp->address_length,
- clib_net_to_host_u64 (ctrp->packets),
- clib_net_to_host_u64 (ctrp->bytes));
- ctrp++;
- }
-}
-
-/* Format an IP6 address. */
-u8 *
-format_ip6_address (u8 * s, va_list * args)
-{
- ip6_address_t *a = va_arg (*args, ip6_address_t *);
- u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
-
- i_max_n_zero = ARRAY_LEN (a->as_u16);
- max_n_zeros = 0;
- i_first_zero = i_max_n_zero;
- n_zeros = 0;
- for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
- {
- u32 is_zero = a->as_u16[i] == 0;
- if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
- {
- i_first_zero = i;
- n_zeros = 0;
- }
- n_zeros += is_zero;
- if ((!is_zero && n_zeros > max_n_zeros)
- || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
- {
- i_max_n_zero = i_first_zero;
- max_n_zeros = n_zeros;
- i_first_zero = ARRAY_LEN (a->as_u16);
- n_zeros = 0;
- }
- }
-
- last_double_colon = 0;
- for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
- {
- if (i == i_max_n_zero && max_n_zeros > 1)
- {
- s = format (s, "::");
- i += max_n_zeros - 1;
- last_double_colon = 1;
- }
- else
- {
- s = format (s, "%s%x",
- (last_double_colon || i == 0) ? "" : ":",
- clib_net_to_host_u16 (a->as_u16[i]));
- last_double_colon = 0;
- }
- }
-
- return s;
-}
-
-/* Format an IP6 route destination and length. */
-u8 *
-format_ip6_address_and_length (u8 * s, va_list * args)
-{
- ip6_address_t *a = va_arg (*args, ip6_address_t *);
- u8 l = va_arg (*args, u32);
- return format (s, "%U/%d", format_ip6_address, a, l);
-}
-
-static void
-vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp)
-{
- int i;
- vl_api_ip6_fib_counter_t *ctrp;
- u32 count;
-
- count = ntohl (mp->count);
-
- fformat (stdout, "fib id %d, count this msg %d\n",
- ntohl (mp->vrf_id), count);
-
- ctrp = mp->c;
- for (i = 0; i < count; i++)
- {
- fformat (stdout, "%U: %lld packets, %lld bytes\n",
- format_ip6_address_and_length, &ctrp->address,
- (u32) ctrp->address_length,
- clib_net_to_host_u64 (ctrp->packets),
- clib_net_to_host_u64 (ctrp->bytes));
- ctrp++;
- }
-}
-
-static void
-vl_api_oam_event_t_handler (vl_api_oam_event_t * mp)
-{
- fformat (stdout, "OAM: %U now %s\n",
- format_ip4_address, &mp->dst_address,
- mp->state == 1 ? "alive" : "dead");
-}
-
-static void
-vl_api_oam_add_del_reply_t_handler (vl_api_oam_add_del_reply_t * mp)
-{
- fformat (stdout, "oam add del reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_reset_fib_reply_t_handler (vl_api_reset_fib_reply_t * mp)
-{
- fformat (stdout, "fib reset reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_dhcp_proxy_set_vss_reply_t_handler (vl_api_dhcp_proxy_set_vss_reply_t *
- mp)
-{
- fformat (stdout, "dhcp proxy set vss reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_dhcp_proxy_config_reply_t_handler (vl_api_dhcp_proxy_config_reply_t *
- mp)
-{
- fformat (stdout, "dhcp proxy config reply %d\n", ntohl (mp->retval));
-}
-
-static void
-vl_api_set_ip_flow_hash_reply_t_handler (vl_api_set_ip_flow_hash_reply_t * mp)
-{
- fformat (stdout, "set ip flow hash reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_sw_interface_ip6nd_ra_config_reply_t_handler
- (vl_api_sw_interface_ip6nd_ra_config_reply_t * mp)
-{
- fformat (stdout, "ip6 nd ra-config reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_sw_interface_ip6nd_ra_prefix_reply_t_handler
- (vl_api_sw_interface_ip6nd_ra_prefix_reply_t * mp)
-{
- fformat (stdout, "ip6 nd ra-prefix reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_sw_interface_ip6_enable_disable_reply_t_handler
- (vl_api_sw_interface_ip6_enable_disable_reply_t * mp)
-{
- fformat (stdout, "ip6 enable/disable reply %d\n", ntohl (mp->retval));
-}
-
-static void
- vl_api_sw_interface_ip6_set_link_local_address_reply_t_handler
- (vl_api_sw_interface_ip6_set_link_local_address_reply_t * mp)
-{
- fformat (stdout, "ip6 set link-local address reply %d\n",
- ntohl (mp->retval));
-}
-
-static void vl_api_create_loopback_reply_t_handler
- (vl_api_create_loopback_reply_t * mp)
-{
- fformat (stdout, "create loopback status %d, sw_if_index %d\n",
- ntohl (mp->retval), ntohl (mp->sw_if_index));
-}
-
-static void vl_api_create_loopback_instance_reply_t_handler
- (vl_api_create_loopback_instance_reply_t * mp)
-{
- fformat (stdout, "create loopback status %d, sw_if_index %d\n",
- ntohl (mp->retval), ntohl (mp->sw_if_index));
-}
-
-static void vl_api_l2_patch_add_del_reply_t_handler
- (vl_api_l2_patch_add_del_reply_t * mp)
-{
- fformat (stdout, "l2 patch reply %d\n", ntohl (mp->retval));
-}
-
-static void vl_api_sw_interface_set_l2_xconnect_reply_t_handler
- (vl_api_sw_interface_set_l2_xconnect_reply_t * mp)
-{
- fformat (stdout, "l2_xconnect reply %d\n", ntohl (mp->retval));
-}
-
-static void vl_api_sw_interface_set_l2_bridge_reply_t_handler
- (vl_api_sw_interface_set_l2_bridge_reply_t * mp)
-{
- fformat (stdout, "l2_bridge reply %d\n", ntohl (mp->retval));
-}
-
-static void
-noop_handler (void *notused)
-{
-}
-
-#define vl_api_vnet_ip4_fib_counters_t_endian noop_handler
-#define vl_api_vnet_ip4_fib_counters_t_print noop_handler
-#define vl_api_vnet_ip6_fib_counters_t_endian noop_handler
-#define vl_api_vnet_ip6_fib_counters_t_print noop_handler
-
-#define foreach_api_msg \
-_(SW_INTERFACE_DETAILS, sw_interface_details) \
-_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
-_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
-_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
-_(WANT_STATS_REPLY, want_stats_reply) \
-_(WANT_OAM_EVENTS_REPLY, want_oam_events_reply) \
-_(OAM_EVENT, oam_event) \
-_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
-_(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
-_(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
-_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
-_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, sw_interface_add_del_address_reply) \
-_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
-_(TAP_CONNECT_REPLY, tap_connect_reply) \
-_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
-_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
-_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, proxy_arp_intfc_enable_disable_reply) \
-_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
-_(RESET_FIB_REPLY, reset_fib_reply) \
-_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
-_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
-_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
-_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, sw_interface_ip6nd_ra_config_reply) \
-_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, sw_interface_ip6nd_ra_prefix_reply) \
-_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, sw_interface_ip6_enable_disable_reply) \
-_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, sw_interface_ip6_set_link_local_address_reply) \
- _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
- _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
-_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
-_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, sw_interface_set_l2_xconnect_reply) \
-_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, sw_interface_set_l2_bridge_reply)
-
-int
-connect_to_vpe (char *name)
-{
- int rv = 0;
-
- rv = vl_client_connect_to_vlib ("/vpe-api", name, 32);
-
-#define _(N,n) \
- vl_msg_api_set_handlers(VL_API_##N, #n, \
- vl_api_##n##_t_handler, \
- noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_api_msg;
-#undef _
-
- shmem_hdr = api_main.shmem_hdr;
-
- return rv;
-}
-
-int
-disconnect_from_vpe (void)
-{
- vl_client_disconnect_from_vlib ();
- return 0;
-}
-
-void
-link_up_down_enable_disable (test_main_t * tm, int enable)
-{
- vl_api_want_interface_events_t *mp;
-
- /* Request admin / link up down messages */
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_WANT_INTERFACE_EVENTS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->enable_disable = enable;
- mp->pid = getpid ();
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
- tm->link_events_on = enable;
-}
-
-void
-stats_enable_disable (test_main_t * tm, int enable)
-{
- vl_api_want_stats_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_WANT_STATS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->enable_disable = enable;
- mp->pid = getpid ();
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
- tm->stats_on = enable;
-}
-
-void
-oam_events_enable_disable (test_main_t * tm, int enable)
-{
- vl_api_want_oam_events_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_WANT_OAM_EVENTS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->enable_disable = enable;
- mp->pid = getpid ();
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
- tm->oam_events_on = enable;
-}
-
-void
-oam_add_del (test_main_t * tm, int is_add)
-{
- vl_api_oam_add_del_t *mp;
- ip4_address_t tmp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_OAM_ADD_DEL);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->is_add = is_add;
-
- tmp.as_u32 = ntohl (0xc0a80101); /* 192.168.1.1 */
- clib_memcpy (mp->src_address, tmp.as_u8, 4);
-
- tmp.as_u32 = ntohl (0xc0a80103); /* 192.168.1.3 */
- clib_memcpy (mp->dst_address, tmp.as_u8, 4);
-
- mp->vrf_id = 0;
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-dump (test_main_t * tm)
-{
- vl_api_sw_interface_dump_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DUMP);
- mp->client_index = tm->my_client_index;
- mp->name_filter_valid = 1;
- strncpy ((char *) mp->name_filter, "eth", sizeof (mp->name_filter) - 1);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_del_ip4_route (test_main_t * tm, int enable_disable)
-{
- vl_api_ip_add_del_route_t *mp;
- u32 tmp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_IP_ADD_DEL_ROUTE);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->table_id = ntohl (0);
-
- mp->next_hop_sw_if_index = ntohl (5);
- mp->is_add = enable_disable;
- mp->next_hop_weight = 1;
-
- /* Next hop: 6.0.0.1 */
- tmp = ntohl (0x06000001);
- clib_memcpy (mp->next_hop_address, &tmp, sizeof (tmp));
-
- /* Destination: 10.0.0.1/32 */
- tmp = ntohl (0x0);
- clib_memcpy (mp->dst_address, &tmp, sizeof (tmp));
- mp->dst_address_length = 0;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_del_ip6_route (test_main_t * tm, int enable_disable)
-{
- vl_api_ip_add_del_route_t *mp;
- u64 tmp[2];
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_IP_ADD_DEL_ROUTE);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->next_hop_sw_if_index = ntohl (5);
- mp->is_add = enable_disable;
- mp->is_ipv6 = 1;
- mp->next_hop_weight = 1;
- mp->dst_address_length = 64;
-
- /* add/del dabe::/64 via db01::11 */
-
- tmp[0] = clib_host_to_net_u64 (0xdabe000000000000ULL);
- tmp[1] = clib_host_to_net_u64 (0x0ULL);
- clib_memcpy (mp->dst_address, &tmp[0], 8);
- clib_memcpy (&mp->dst_address[8], &tmp[1], 8);
-
- tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
- tmp[1] = clib_host_to_net_u64 (0x11ULL);
- clib_memcpy (mp->next_hop_address, &tmp[0], 8);
- clib_memcpy (&mp->next_hop_address[8], &tmp[1], 8);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_del_interface_address (test_main_t * tm, int enable_disable)
-{
- vl_api_sw_interface_add_del_address_t *mp;
- u32 tmp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->is_add = enable_disable;
- mp->address_length = 8;
-
- tmp = ntohl (0x01020304);
- clib_memcpy (mp->address, &tmp, 4);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_del_v6_interface_address (test_main_t * tm, int enable_disable)
-{
- vl_api_sw_interface_add_del_address_t *mp;
- u64 tmp[2];
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->is_ipv6 = 1;
- mp->sw_if_index = ntohl (5);
- mp->is_add = enable_disable;
- mp->address_length = 64;
-
- tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
- tmp[1] = clib_host_to_net_u64 (0x11ULL);
-
- clib_memcpy (mp->address, &tmp[0], 8);
- clib_memcpy (&mp->address[8], &tmp[1], 8);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-del_all_interface_addresses (test_main_t * tm)
-{
- vl_api_sw_interface_add_del_address_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->del_all = 1;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-set_interface_table (test_main_t * tm, int is_ipv6, u32 vrf_id)
-{
- vl_api_sw_interface_set_table_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_TABLE);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->is_ipv6 = is_ipv6;
- mp->vrf_id = ntohl (vrf_id);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-connect_unix_tap (test_main_t * tm, char *name)
-{
- vl_api_tap_connect_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_TAP_CONNECT);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- strncpy ((char *) mp->tap_name, name, sizeof (mp->tap_name) - 1);
- mp->use_random_mac = 1;
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-create_vlan_subif (test_main_t * tm, u32 vlan_id)
-{
- vl_api_create_vlan_subif_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_CREATE_VLAN_SUBIF);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->vlan_id = ntohl (vlan_id);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_del_proxy_arp (test_main_t * tm, int is_add)
-{
- vl_api_proxy_arp_add_del_t *mp;
- u32 tmp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_ADD_DEL);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->proxy.vrf_id = ntohl (11);
- mp->is_add = is_add;
-
- /* proxy fib 11, 1.1.1.1 -> 1.1.1.10 */
- tmp = ntohl (0x01010101);
- clib_memcpy (mp->proxy.low_address, &tmp, 4);
-
- tmp = ntohl (0x0101010a);
- clib_memcpy (mp->proxy.hi_address, &tmp, 4);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-proxy_arp_intfc_enable_disable (test_main_t * tm, int enable_disable)
-{
- vl_api_proxy_arp_intfc_enable_disable_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (6);
- mp->enable_disable = enable_disable;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_ip4_neighbor (test_main_t * tm, int add_del)
-{
- vl_api_ip_neighbor_add_del_t *mp;
- u32 tmp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_ADD_DEL);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (6);
- mp->is_add = add_del;
-
- clib_memset (mp->mac_address, 0xbe, sizeof (mp->mac_address));
-
- tmp = ntohl (0x0101010a);
- clib_memcpy (mp->dst_address, &tmp, 4);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-add_ip6_neighbor (test_main_t * tm, int add_del)
-{
- vl_api_ip_neighbor_add_del_t *mp;
- u64 tmp[2];
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_ADD_DEL);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (6);
- mp->is_add = add_del;
- mp->is_ipv6 = 1;
-
- clib_memset (mp->mac_address, 0xbe, sizeof (mp->mac_address));
-
- tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
- tmp[1] = clib_host_to_net_u64 (0x11ULL);
-
- clib_memcpy (mp->dst_address, &tmp[0], 8);
- clib_memcpy (&mp->dst_address[8], &tmp[1], 8);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-reset_fib (test_main_t * tm, u8 is_ip6)
-{
- vl_api_reset_fib_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_RESET_FIB);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->vrf_id = ntohl (11);
- mp->is_ipv6 = is_ip6;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-dhcpv6_set_vss (test_main_t * tm)
-{
- vl_api_dhcp_proxy_set_vss_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_SET_VSS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->oui = ntohl (6);
- mp->tbl_id = ntohl (60);
- mp->is_add = 1;
- mp->is_ipv6 = 1;
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-dhcpv4_set_vss (test_main_t * tm)
-{
- vl_api_dhcp_proxy_set_vss_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_SET_VSS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->oui = ntohl (4);
- mp->tbl_id = ntohl (40);
- mp->is_add = 1;
- mp->is_ipv6 = 0;
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-dhcp_set_vss (test_main_t * tm)
-{
- dhcpv4_set_vss (tm);
- dhcpv6_set_vss (tm);
-}
-
-void
-dhcp_set_proxy (test_main_t * tm, int ipv6)
-{
- vl_api_dhcp_proxy_config_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_CONFIG);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->is_ipv6 = ipv6;
- mp->is_add = 1;
- mp->dhcp_server[0] = 0x20;
- mp->dhcp_server[1] = 0x01;
- mp->dhcp_server[2] = 0xab;
- mp->dhcp_server[3] = 0xcd;
- mp->dhcp_server[4] = 0x12;
- mp->dhcp_server[5] = 0x34;
- mp->dhcp_server[6] = 0xfe;
- mp->dhcp_server[7] = 0xdc;
- mp->dhcp_server[14] = 0;
- mp->dhcp_server[15] = 0x2;
-
- mp->dhcp_src_address[0] = 0x20;
- mp->dhcp_src_address[1] = 0x01;
- mp->dhcp_src_address[2] = 0xab;
- mp->dhcp_src_address[3] = 0xcd;
- mp->dhcp_src_address[4] = 0x12;
- mp->dhcp_src_address[5] = 0x34;
- mp->dhcp_src_address[6] = 0x56;
- mp->dhcp_src_address[7] = 0x78;
- mp->dhcp_src_address[14] = 0;
- mp->dhcp_src_address[15] = 0x2;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-set_ip_flow_hash (test_main_t * tm, u8 is_ip6)
-{
- vl_api_set_ip_flow_hash_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SET_IP_FLOW_HASH);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->vrf_id = 0;
- mp->is_ipv6 = is_ip6;
- mp->dst = 1;
- mp->reverse = 1;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-ip6nd_ra_config (test_main_t * tm, int is_no)
-{
- vl_api_sw_interface_ip6nd_ra_config_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
-
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->is_no = is_no;
-
- mp->suppress = 1;
-
-
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG);
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-ip6nd_ra_prefix (test_main_t * tm, int is_no)
-{
- vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
- u64 tmp[2];
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
-
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->is_no = is_no;
-
- mp->use_default = 1;
-
-
- tmp[0] = clib_host_to_net_u64 (0xdb01000000000000ULL);
- tmp[1] = clib_host_to_net_u64 (0x11ULL);
-
-
- clib_memcpy (mp->address, &tmp[0], 8);
- clib_memcpy (&mp->address[8], &tmp[1], 8);
-
- mp->address_length = 64;
-
-
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX);
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-ip6_enable_disable (test_main_t * tm, int enable)
-{
- vl_api_sw_interface_ip6_enable_disable_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
-
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->enable = (enable == 1);;
-
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE);
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-loop_create (test_main_t * tm)
-{
- vl_api_create_loopback_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
-
- mp->_vl_msg_id = ntohs (VL_API_CREATE_LOOPBACK);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-ip6_set_link_local_address (test_main_t * tm)
-{
- vl_api_sw_interface_ip6_set_link_local_address_t *mp;
- u64 tmp[2];
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
-
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
-
- tmp[0] = clib_host_to_net_u64 (0xfe80000000000000ULL);
- tmp[1] = clib_host_to_net_u64 (0x11ULL);
-
- ip6_address_encode ((ip6_address_encode *) & tmp, mp->address);
-
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-
-void
-set_flags (test_main_t * tm, int up_down)
-{
- vl_api_sw_interface_set_flags_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
-
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_FLAGS);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->sw_if_index = ntohl (5);
- mp->admin_up_down = up_down;
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-
-}
-
-void
-l2_patch_add_del (test_main_t * tm, int is_add)
-{
- vl_api_l2_patch_add_del_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_L2_PATCH_ADD_DEL);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->is_add = is_add;
- mp->rx_sw_if_index = ntohl (1);
- mp->tx_sw_if_index = ntohl (2);
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-l2_xconnect (test_main_t * tm)
-{
- vl_api_sw_interface_set_l2_xconnect_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_L2_XCONNECT);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->rx_sw_if_index = ntohl (5);
- mp->tx_sw_if_index = ntohl (6);
- mp->enable = 1;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-void
-l2_bridge (test_main_t * tm)
-{
- vl_api_sw_interface_set_l2_bridge_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_SET_L2_BRIDGE);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
- mp->rx_sw_if_index = ntohl (5);
- mp->bd_id = ntohl (6);
- mp->bvi = ntohl (1);
- mp->shg = ntohl (0);
- mp->enable = 1;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-int
-main (int argc, char **argv)
-{
- api_main_t *am = vlibapi_get_main ();
- test_main_t *tm = &test_main;
- int ch;
-
- connect_to_vpe ("test_client");
-
- tm->vl_input_queue = shmem_hdr->vl_input_queue;
- tm->my_client_index = am->my_client_index;
-
- fformat (stdout, "Type 'h' for help, 'q' to quit...\n");
-
- while (1)
- {
- ch = getchar ();
- switch (ch)
- {
- case 'q':
- goto done;
- case 'd':
- dump (tm);
- break;
- case 'L':
- link_up_down_enable_disable (tm, 1 /* enable_disable */ );
- break;
- case 'l':
- link_up_down_enable_disable (tm, 0 /* enable_disable */ );
- break;
- case 'S':
- stats_enable_disable (tm, 1 /* enable_disable */ );
- break;
- case 's':
- stats_enable_disable (tm, 0 /* enable_disable */ );
- break;
- case '3':
- add_del_ip4_route (tm, 0 /* add */ );
- break;
- case '4':
- add_del_ip4_route (tm, 1 /* add */ );
- break;
- case '5':
- add_del_ip6_route (tm, 0 /* add */ );
- break;
- case '6':
- add_del_ip6_route (tm, 1 /* add */ );
- break;
- case 'A':
- add_del_interface_address (tm, 1 /* add */ );
- break;
- case 'a':
- add_del_interface_address (tm, 0 /* add */ );
- break;
- case 'B':
- add_del_v6_interface_address (tm, 1 /* add */ );
- break;
- case 'b':
- add_del_v6_interface_address (tm, 0 /* add */ );
- break;
- case 'E':
- l2_patch_add_del (tm, 1 /* is_add */ );
- break;
- case 'e':
- l2_patch_add_del (tm, 0 /* is_add */ );
- break;
- case 'z':
- del_all_interface_addresses (tm);
- break;
- case 't':
- set_interface_table (tm, 0 /* is_ipv6 */ ,
- 11 /* my amp goes to 11 */ );
- break;
- case 'T':
- set_interface_table (tm, 1 /* is_ipv6 */ ,
- 12 /* my amp goes to 12 */ );
- break;
-
- case 'u':
- create_vlan_subif (tm, 123);
- break;
-
- case 'c':
- connect_unix_tap (tm, "foo");
- break;
-
- case 'n':
- add_ip4_neighbor (tm, 1 /* is_add */ );
- add_ip6_neighbor (tm, 1 /* is_add */ );
- break;
-
- case 'N':
- add_ip4_neighbor (tm, 0 /* is_add */ );
- add_ip6_neighbor (tm, 0 /* is_add */ );
- break;
-
- case 'p':
- add_del_proxy_arp (tm, 1 /* add */ );
- break;
-
- case 'i':
- proxy_arp_intfc_enable_disable (tm, 1 /* enable */ );
- break;
-
- case 'O':
- oam_events_enable_disable (tm, 0 /* enable */ );
- break;
-
- case 'o':
- oam_events_enable_disable (tm, 1 /* enable */ );
- break;
-
- case '0':
- oam_add_del (tm, 0 /* is_add */ );
- break;
-
- case '1':
- oam_add_del (tm, 1 /* is_add */ );
- break;
-
- case 'r':
- reset_fib (tm, 0 /* is_ip6 */ );
- break;
-
- case 'R':
- reset_fib (tm, 1 /* is_ip6 */ );
- break;
-
- case 'j':
- dhcp_set_vss (tm);
- break;
-
- case 'k':
- dhcp_set_proxy (tm, 0);
- break;
-
- case 'K':
- dhcp_set_proxy (tm, 1 /*ipv6 */ );
- break;
-
- case 'v':
- set_ip_flow_hash (tm, 0 /* is_ip6 */ );
- break;
-
- case 'V':
- ip6_set_link_local_address (tm);
- break;
-
- case 'w':
- ip6_enable_disable (tm, 1 /* enable */ );
- break;
-
- case 'W':
- ip6_enable_disable (tm, 0 /* disable */ );
- break;
-
- case 'x':
- ip6nd_ra_config (tm, 0 /* is_no */ );
- break;
- case 'X':
- ip6nd_ra_config (tm, 1 /* is_no */ );
- break;
- case 'y':
- ip6nd_ra_prefix (tm, 0 /* is_no */ );
- break;
- case 'Y':
- ip6nd_ra_prefix (tm, 1 /* is_no */ );
- break;
-
- case '7':
- loop_create (tm);
- break;
-
- case 'F':
- set_flags (tm, 1 /* up_down */ );
- break;
-
- case 'f':
- set_flags (tm, 0 /* up_down */ );
- break;
-
- case '@':
- l2_xconnect (tm);
- break;
-
- case '#':
- l2_bridge (tm);
- break;
-
- case 'h':
- fformat (stdout, "q=quit,d=dump,L=link evts on,l=link evts off\n");
- fformat (stdout, "S=stats on,s=stats off\n");
- fformat (stdout, "4=add v4 route, 3=del v4 route\n");
- fformat (stdout, "6=add v6 route, 5=del v6 route\n");
- fformat (stdout, "A=add v4 intfc route, a=del v4 intfc route\n");
- fformat (stdout, "B=add v6 intfc route, b=del v6 intfc route\n");
- fformat (stdout, "z=del all intfc routes\n");
- fformat (stdout, "t=set v4 intfc table, T=set v6 intfc table\n");
- fformat (stdout, "c=connect unix tap\n");
- fformat (stdout,
- "j=set dhcpv4 and v6 link-address/option-82 params\n");
- fformat (stdout, "k=set dhcpv4 relay agent params\n");
- fformat (stdout, "K=set dhcpv6 relay agent params\n");
- fformat (stdout, "E=add l2 patch, e=del l2 patch\n");
- fformat (stdout, "V=ip6 set link-local address \n");
- fformat (stdout, "w=ip6 enable \n");
- fformat (stdout, "W=ip6 disable \n");
- fformat (stdout, "x=ip6 nd config \n");
- fformat (stdout, "X=no ip6 nd config\n");
- fformat (stdout, "y=ip6 nd prefix \n");
- fformat (stdout, "Y=no ip6 nd prefix\n");
- fformat (stdout, "@=l2 xconnect\n");
- fformat (stdout, "#=l2 bridge\n");
-
- default:
- break;
- }
-
- }
-
-done:
-
- if (tm->link_events_on)
- link_up_down_enable_disable (tm, 0 /* enable */ );
- if (tm->stats_on)
- stats_enable_disable (tm, 0 /* enable */ );
- if (tm->oam_events_on)
- oam_events_enable_disable (tm, 0 /* enable */ );
-
- disconnect_from_vpe ();
- exit (0);
-}
-
-#undef vl_api_version
-#define vl_api_version(n,v) static u32 vpe_api_version = v;
-#include <vpp/api/vpe.api.h>
-#undef vl_api_version
-
-void
-vl_client_add_api_signatures (vl_api_memclnt_create_t * mp)
-{
- /*
- * Send the main API signature in slot 0. This bit of code must
- * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
- */
- mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
-}
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vpp/api/test_ha.c b/src/vpp/api/test_ha.c
deleted file mode 100644
index 0cc1074031e..00000000000
--- a/src/vpp/api/test_ha.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- *------------------------------------------------------------------
- * api.c - message handler registration
- *
- * Copyright (c) 2010 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 <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <time.h>
-#include <fcntl.h>
-#include <string.h>
-#include <vppinfra/clib.h>
-#include <vppinfra/vec.h>
-#include <vppinfra/hash.h>
-#include <vppinfra/bitmap.h>
-#include <vppinfra/fifo.h>
-#include <vppinfra/time.h>
-#include <vppinfra/heap.h>
-#include <vppinfra/pool.h>
-#include <vppinfra/format.h>
-#include <vppinfra/error.h>
-
-#include <vnet/vnet.h>
-#include <vlib/vlib.h>
-#include <vlib/unix/unix.h>
-#include <vlibapi/api.h>
-#include <vlibmemory/api.h>
-#include <svm/svm.h>
-#include <svm/svmdb.h>
-
-#include <vpp/api/vpe_msg_enum.h>
-
-#include <vnet/ip/ip.h>
-
-#define f64_endian(a)
-#define f64_print(a,b)
-
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_printfun
-
-vl_shmem_hdr_t *shmem_hdr;
-
-typedef struct
-{
- u32 pings_sent;
- u32 pings_replied;
- volatile u32 signal_received;
-
- /* convenience */
- svm_queue_t *vl_input_queue;
- u32 my_client_index;
- svmdb_client_t *svmdb_client;
-} test_main_t;
-
-test_main_t test_main;
-
-static void vl_api_control_ping_reply_t_handler
- (vl_api_control_ping_reply_t * mp)
-{
- test_main_t *tm = &test_main;
-
- fformat (stdout, "control ping reply from pid %d\n", ntohl (mp->vpe_pid));
- tm->pings_replied++;
-}
-
-void
-vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...)
-{
- clib_warning ("BUG: vlib_cli_output called...");
-}
-
-#define foreach_api_msg \
-_(CONTROL_PING_REPLY,control_ping_reply)
-
-void
-ping (test_main_t * tm)
-{
- vl_api_control_ping_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- clib_memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_CONTROL_PING);
- mp->client_index = tm->my_client_index;
- mp->context = 0xdeadbeef;
-
- vl_msg_api_send_shmem (tm->vl_input_queue, (u8 *) & mp);
-}
-
-static void
-noop_handler (void *notused)
-{
-}
-
-int
-connect_to_vpe (char *name)
-{
- int rv = 0;
- test_main_t *tm = &test_main;
- api_main_t *am = vlibapi_get_main ();
-
- rv = vl_client_connect_to_vlib ("/vpe-api", name, 32);
- if (rv < 0)
- return rv;
-
-#define _(N,n) \
- vl_msg_api_set_handlers(VL_API_##N, #n, \
- vl_api_##n##_t_handler, \
- noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_api_msg;
-#undef _
-
- shmem_hdr = api_main.shmem_hdr;
- tm->vl_input_queue = shmem_hdr->vl_input_queue;
- tm->my_client_index = am->my_client_index;
- return 0;
-}
-
-int
-disconnect_from_vpe (void)
-{
- vl_client_disconnect_from_vlib ();
-
- return 0;
-}
-
-void
-signal_handler (int signo)
-{
- test_main_t *tm = &test_main;
-
- tm->signal_received = 1;
-}
-
-
-int
-main (int argc, char **argv)
-{
- test_main_t *tm = &test_main;
- api_main_t *am = vlibapi_get_main ();
- u32 swt_pid = 0;
- int connected = 0;
-
- signal (SIGINT, signal_handler);
-
- while (1)
- {
- if (tm->signal_received)
- break;
-
- if (am->shmem_hdr)
- swt_pid = am->shmem_hdr->vl_pid;
-
- /* If kill returns 0, the vpe-f process is alive */
- if (kill (swt_pid, 0) == 0)
- {
- /* Try to connect */
- if (connected == 0)
- {
- fformat (stdout, "Connect to VPE-f\n");
- if (connect_to_vpe ("test_ha_client") >= 0)
- {
- tm->pings_sent = 0;
- tm->pings_replied = 0;
- connected = 1;
- }
- else
- {
- fformat (stdout, "Connect failed, sleep and retry...\n");
- sleep (1);
- continue;
- }
- }
- tm->pings_sent++;
- ping (tm);
-
- sleep (1);
-
- /* havent heard back in 3 seconds, disco / reco */
- if ((tm->pings_replied + 3) <= tm->pings_sent)
- {
- fformat (stdout, "VPE-f pid %d not responding\n", swt_pid);
- swt_pid = 0;
- disconnect_from_vpe ();
- connected = 0;
- }
- }
- else
- {
- if (connected)
- {
- fformat (stdout, "VPE-f pid %d died\n", swt_pid);
- swt_pid = 0;
- disconnect_from_vpe ();
- connected = 0;
- }
- sleep (1);
- }
- }
-
- fformat (stdout, "Signal received, graceful exit\n");
- disconnect_from_vpe ();
- exit (0);
-}
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vpp/api/types.h b/src/vpp/api/types.h
index feafe8f5cb3..9864e8c38a8 100644
--- a/src/vpp/api/types.h
+++ b/src/vpp/api/types.h
@@ -21,9 +21,8 @@
#include <vnet/ip/ip_types.api_types.h>
#include <vnet/ethernet/ethernet_types.api_types.h>
-#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
+
+#include <vpp/api/vpe_types.api_types.h>
extern const vl_api_mac_address_t VL_API_ZERO_MAC_ADDRESS;
extern const vl_api_address_t VL_API_ZERO_ADDRESS;
diff --git a/src/vpp/api/vpe_all_api_h.h b/src/vpp/api/vpe_all_api_h.h
deleted file mode 100644
index 7559208d997..00000000000
--- a/src/vpp/api/vpe_all_api_h.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.
- */
-/*
- * Add to the bottom of the #include list, or elves will steal your
- * keyboard in the middle of the night!
- */
-
-/* Include the (first) vlib-api API definition layer */
-#include <vlibmemory/vl_memory_api_h.h>
-
-/* Include the current layer (third) vpp API definition layer */
-#include <vpp/api/vpe_types.api.h>
-#include <vpp/api/vpe.api.h>
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vpp/api/vpe_msg_enum.h b/src/vpp/api/vpe_msg_enum.h
deleted file mode 100644
index 4fcc1c8cd8e..00000000000
--- a/src/vpp/api/vpe_msg_enum.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.
- */
-#ifndef included_vpe_msg_enum_h
-#define included_vpe_msg_enum_h
-
-#include <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum
-{
- VL_ILLEGAL_MESSAGE_ID = 0,
-#include <vpp/api/vpe_all_api_h.h>
- VL_MSG_FIRST_AVAILABLE,
-} vl_msg_id_t;
-#undef vl_msg_id
-
-#endif /* included_vpe_msg_enum_h */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index 695c358f765..e0c7b0dbf58 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -25,7 +25,7 @@
#include <vnet/ethernet/ethernet.h>
#include <vpp/app/version.h>
#include <vpp/vnet/config.h>
-#include <vpp/api/vpe_msg_enum.h>
+#include <vlibmemory/memclnt.api_enum.h> /* To get the last static message id */
#include <limits.h>
/*
@@ -323,7 +323,7 @@ defaulted:
pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
/* Set up the plugin message ID allocator right now... */
- 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);
/* destroy temporary heap and create main one */
clib_mem_destroy ();