summaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
Diffstat (limited to 'vnet')
-rw-r--r--vnet/Makefile.am13
-rw-r--r--vnet/vnet/bfd/bfd.api205
-rw-r--r--vnet/vnet/bfd/bfd_api.c262
-rw-r--r--vnet/vnet/vnet_all_api_h.h1
4 files changed, 477 insertions, 4 deletions
diff --git a/vnet/Makefile.am b/vnet/Makefile.am
index 37798c9c3bb..592acc8f645 100644
--- a/vnet/Makefile.am
+++ b/vnet/Makefile.am
@@ -41,7 +41,9 @@ BUILT_SOURCES = \
vnet/vxlan/vxlan.api.h \
vnet/vxlan/vxlan.api.json \
vnet/vxlan-gpe/vxlan_gpe.api.h \
- vnet/vxlan-gpe/vxlan_gpe.api.json
+ vnet/vxlan-gpe/vxlan_gpe.api.json \
+ vnet/bfd/bfd.api.h \
+ vnet/bfd/bfd.api.json
libvnet_la_SOURCES =
libvnetplugin_la_SOURCES =
@@ -373,13 +375,15 @@ nobase_include_HEADERS += \
vnet/bfd/bfd_protocol.h \
vnet/bfd/bfd_main.h \
vnet/bfd/bfd_api.h \
- vnet/bfd/bfd_udp.h
+ vnet/bfd/bfd_udp.h \
+ vnet/bfd/bfd.api.h
libvnet_la_SOURCES += \
vnet/bfd/bfd_api.h \
vnet/bfd/bfd_udp.c \
vnet/bfd/bfd_main.c \
- vnet/bfd/bfd_protocol.c
+ vnet/bfd/bfd_protocol.c \
+ vnet/bfd/bfd_api.c
########################################
# Layer 3 protocol: IPSec
@@ -973,7 +977,8 @@ api_DATA = \
vnet/span/span.api.json \
vnet/unix/tap.api.json \
vnet/vxlan/vxlan.api.json \
- vnet/vxlan-gpe/vxlan_gpe.api.json
+ vnet/vxlan-gpe/vxlan_gpe.api.json \
+ vnet/bfd/bfd.api.json
# The actual %.api.h rule is in .../build-data/packages/suffix-rules.mk
# and requires a symbolic link at the top of the vnet source tree
diff --git a/vnet/vnet/bfd/bfd.api b/vnet/vnet/bfd/bfd.api
new file mode 100644
index 00000000000..5798ee698ce
--- /dev/null
+++ b/vnet/vnet/bfd/bfd.api
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2015-2016 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.
+ */
+
+/** \brief Configure BFD feature
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param slow_timer - slow timer (seconds)
+ @param min_tx - desired min tx interval
+ @param min_rx - desired min rx interval
+ @param detect_mult - desired detection multiplier
+*/
+define bfd_set_config {
+ u32 client_index;
+ u32 context;
+ u32 slow_timer;
+ u32 min_tx;
+ u32 min_rx;
+ u8 detect_mult;
+};
+
+/** \brief Configure BFD feature response
+ @param context - sender context, to match reply w/ request
+ @param retval - return code for the request
+*/
+define bfd_set_config_reply {
+ u32 context;
+ i32 retval;
+};
+
+/** \brief Get BFD configuration
+*/
+define bfd_get_config {
+ u32 client_index;
+ u32 context;
+};
+
+/** \brief Get BFD configuration response
+ @param context - sender context, to match reply w/ request
+ @param retval - return code for the request
+ @param slow_timer - slow timer (seconds)
+ @param min_tx - desired min tx interval
+ @param min_rx - desired min rx interval
+ @param detect_mult - desired detection multiplier
+*/
+define bfd_get_config_reply {
+ u32 client_index;
+ u32 context;
+ u32 slow_timer;
+ u32 min_tx;
+ u32 min_rx;
+ u8 detect_mult;
+};
+
+/** \brief Add UDP BFD session on interface
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param sw_if_index - sw index of the interface
+ @param desired_min_tx - desired min transmit interval (microseconds)
+ @param required_min_rx - required min receive interval (microseconds)
+ @param detect_mult - detect multiplier (# of packets missed between connection goes down)
+ @param local_addr - local address
+ @param peer_addr - peer address
+ @param is_ipv6 - local_addr, peer_addr are IPv6 if non-zero, otherwise IPv4
+*/
+define bfd_udp_add {
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+ u32 desired_min_tx;
+ u32 required_min_rx;
+ u8 local_addr[16];
+ u8 peer_addr[16];
+ u8 is_ipv6;
+ u8 detect_mult;
+};
+
+/** \brief Add UDP BFD session response
+ @param context - sender context, to match reply w/ request
+ @param retval - return code for the request
+ @param bs_index - index of the session created
+*/
+define bfd_udp_add_reply {
+ u32 context;
+ i32 retval;
+ u32 bs_index;
+};
+
+/** \brief Delete UDP BFD session on interface
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param sw_if_index - sw index of the interface
+ @param local_addr - local address
+ @param peer_addr - peer address
+ @param is_ipv6 - local_addr, peer_addr are IPv6 if non-zero, otherwise IPv4
+*/
+define bfd_udp_del {
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+ u8 local_addr[16];
+ u8 peer_addr[16];
+ u8 is_ipv6;
+};
+
+/** \brief Delete UDP BFD session response
+ @param context - sender context, to match reply w/ request
+ @param retval - return code for the request
+*/
+define bfd_udp_del_reply {
+ u32 context;
+ i32 retval;
+};
+
+/** \brief Get all BFD sessions
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+*/
+define bfd_udp_session_dump {
+ u32 client_index;
+ u32 context;
+};
+
+/** \brief BFD session details structure
+ @param context - sender context, to match reply w/ request
+ @param bs_index - index of the session
+ @param sw_if_index - sw index of the interface
+ @param local_addr - local address
+ @param peer_addr - peer address
+ @param is_ipv6 - local_addr, peer_addr are IPv6 if non-zero, otherwise IPv4
+ @param state - session state
+*/
+define bfd_udp_session_details {
+ u32 context;
+ u32 bs_index;
+ u32 sw_if_index;
+ u8 local_addr[16];
+ u8 peer_addr[16];
+ u8 is_ipv6;
+ u8 state;
+};
+
+/** \brief Set flags of BFD session
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param bs_index - index of the bfd session to set flags on
+ @param admin_up_down - set the admin state, 1 = up, 0 = down
+*/
+define bfd_session_set_flags {
+ u32 client_index;
+ u32 context;
+ u32 bs_index;
+ u8 admin_up_down;
+};
+
+/** \brief Reply to bfd_session_set_flags
+ @param context - sender context which was passed in the request
+ @param retval - return code of the set flags request
+*/
+define bfd_session_set_flags_reply
+{
+ u32 context;
+ i32 retval;
+};
+
+/** \brief Register for BFD events
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param enable_disable - 1 => register for events, 0 => cancel registration
+ @param pid - sender's pid
+*/
+define want_bfd_events
+{
+ u32 client_index;
+ u32 context;
+ u32 enable_disable;
+ u32 pid;
+};
+
+/** \brief Reply for BFD events registration
+ @param context - returned sender context, to match reply w/ request
+ @param retval - return code
+*/
+define want_bfd_events_reply
+{
+ u32 context;
+ i32 retval;
+};
+
+/*
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/bfd/bfd_api.c b/vnet/vnet/bfd/bfd_api.c
new file mode 100644
index 00000000000..126cf29a801
--- /dev/null
+++ b/vnet/vnet/bfd/bfd_api.c
@@ -0,0 +1,262 @@
+/*
+ *------------------------------------------------------------------
+ * bfd_api.c - bfd api
+ *
+ * Copyright (c) 2016 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 <vnet/vnet.h>
+#include <vlibmemory/api.h>
+
+#include <vnet/interface.h>
+#include <vnet/api_errno.h>
+#include <vnet/bfd/bfd_main.h>
+#include <vnet/bfd/bfd_api.h>
+
+#include <vnet/vnet_msg_enum.h>
+
+#define vl_typedefs /* define message structures */
+#include <vnet/vnet_all_api_h.h>
+#undef vl_typedefs
+
+#define vl_endianfun /* define message structures */
+#include <vnet/vnet_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 <vnet/vnet_all_api_h.h>
+#undef vl_printfun
+
+#include <vlibapi/api_helper_macros.h>
+
+#define foreach_vpe_api_msg \
+_(BFD_UDP_ADD, bfd_udp_add) \
+_(BFD_UDP_DEL, bfd_udp_del) \
+_(BFD_UDP_SESSION_DUMP, bfd_udp_session_dump) \
+_(BFD_SESSION_SET_FLAGS, bfd_session_set_flags) \
+_(WANT_BFD_EVENTS, want_bfd_events)
+
+pub_sub_handler (bfd_events, BFD_EVENTS);
+
+static void
+vl_api_bfd_udp_add_t_handler (vl_api_bfd_udp_add_t * mp)
+{
+ vl_api_bfd_udp_add_reply_t *rmp;
+ int rv;
+
+ VALIDATE_SW_IF_INDEX (mp);
+
+ ip46_address_t local_addr;
+ memset (&local_addr, 0, sizeof (local_addr));
+ ip46_address_t peer_addr;
+ memset (&peer_addr, 0, sizeof (peer_addr));
+ if (mp->is_ipv6)
+ {
+ clib_memcpy (&local_addr.ip6, mp->local_addr, sizeof (local_addr.ip6));
+ clib_memcpy (&peer_addr.ip6, mp->peer_addr, sizeof (peer_addr.ip6));
+ }
+ else
+ {
+ clib_memcpy (&local_addr.ip4, mp->local_addr, sizeof (local_addr.ip4));
+ clib_memcpy (&peer_addr.ip4, mp->peer_addr, sizeof (peer_addr.ip4));
+ }
+
+ rv = bfd_udp_add_session (clib_net_to_host_u32 (mp->sw_if_index),
+ clib_net_to_host_u32 (mp->desired_min_tx),
+ clib_net_to_host_u32 (mp->required_min_rx),
+ mp->detect_mult, &local_addr, &peer_addr);
+
+ BAD_SW_IF_INDEX_LABEL;
+ REPLY_MACRO (VL_API_BFD_UDP_ADD_REPLY);
+}
+
+static void
+vl_api_bfd_udp_del_t_handler (vl_api_bfd_udp_del_t * mp)
+{
+ vl_api_bfd_udp_del_reply_t *rmp;
+ int rv;
+
+ VALIDATE_SW_IF_INDEX (mp);
+
+ ip46_address_t local_addr;
+ memset (&local_addr, 0, sizeof (local_addr));
+ ip46_address_t peer_addr;
+ memset (&peer_addr, 0, sizeof (peer_addr));
+ if (mp->is_ipv6)
+ {
+ clib_memcpy (&local_addr.ip6, mp->local_addr, sizeof (local_addr.ip6));
+ clib_memcpy (&peer_addr.ip6, mp->peer_addr, sizeof (peer_addr.ip6));
+ }
+ else
+ {
+ clib_memcpy (&local_addr.ip4, mp->local_addr, sizeof (local_addr.ip4));
+ clib_memcpy (&peer_addr.ip4, mp->peer_addr, sizeof (peer_addr.ip4));
+ }
+
+ rv =
+ bfd_udp_del_session (clib_net_to_host_u32 (mp->sw_if_index), &local_addr,
+ &peer_addr);
+
+ BAD_SW_IF_INDEX_LABEL;
+ REPLY_MACRO (VL_API_BFD_UDP_DEL_REPLY);
+}
+
+void
+send_bfd_udp_session_details (unix_shared_memory_queue_t * q, u32 context,
+ bfd_session_t * bs)
+{
+ if (bs->transport != BFD_TRANSPORT_UDP4 &&
+ bs->transport != BFD_TRANSPORT_UDP6)
+ {
+ return;
+ }
+
+ vl_api_bfd_udp_session_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
+ memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs (VL_API_BFD_UDP_SESSION_DETAILS);
+ mp->context = context;
+ mp->bs_index = clib_host_to_net_u32 (bs->bs_idx);
+ mp->state = bs->local_state;
+ bfd_udp_session_t *bus = &bs->udp;
+ bfd_udp_key_t *key = &bus->key;
+ mp->sw_if_index = clib_host_to_net_u32 (key->sw_if_index);
+ mp->is_ipv6 = !(ip46_address_is_ip4 (&key->local_addr));
+ if (mp->is_ipv6)
+ {
+ clib_memcpy (mp->local_addr, &key->local_addr,
+ sizeof (key->local_addr));
+ clib_memcpy (mp->peer_addr, &key->peer_addr, sizeof (key->peer_addr));
+ }
+ else
+ {
+ clib_memcpy (mp->local_addr, key->local_addr.ip4.data,
+ sizeof (key->local_addr.ip4.data));
+ clib_memcpy (mp->peer_addr, key->peer_addr.ip4.data,
+ sizeof (key->peer_addr.ip4.data));
+ }
+
+ vl_msg_api_send_shmem (q, (u8 *) & mp);
+}
+
+void
+bfd_event (bfd_main_t * bm, bfd_session_t * bs)
+{
+ vpe_api_main_t *vam = &vpe_api_main;
+ vpe_client_registration_t *reg;
+ unix_shared_memory_queue_t *q;
+ /* *INDENT-OFF* */
+ pool_foreach (reg, vam->bfd_events_registrations, ({
+ q = vl_api_client_index_to_input_queue (reg->client_index);
+ if (q)
+ {
+ switch (bs->transport)
+ {
+ case BFD_TRANSPORT_UDP4:
+ /* fallthrough */
+ case BFD_TRANSPORT_UDP6:
+ send_bfd_udp_session_details (q, 0, bs);
+ }
+ }
+ }));
+ /* *INDENT-ON* */
+}
+
+static void
+vl_api_bfd_udp_session_dump_t_handler (vl_api_bfd_udp_session_dump_t * mp)
+{
+ unix_shared_memory_queue_t *q;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+
+ if (q == 0)
+ return;
+
+ bfd_session_t *bs = NULL;
+ /* *INDENT-OFF* */
+ pool_foreach (bs, bfd_main.sessions, ({
+ if (bs->transport == BFD_TRANSPORT_UDP4 ||
+ bs->transport == BFD_TRANSPORT_UDP6)
+ send_bfd_udp_session_details (q, mp->context, bs);
+ }));
+ /* *INDENT-ON* */
+}
+
+static void
+vl_api_bfd_session_set_flags_t_handler (vl_api_bfd_session_set_flags_t * mp)
+{
+ vl_api_bfd_session_set_flags_reply_t *rmp;
+ int rv;
+
+ rv =
+ bfd_session_set_flags (clib_net_to_host_u32 (mp->bs_index),
+ mp->admin_up_down);
+
+ REPLY_MACRO (VL_API_BFD_SESSION_SET_FLAGS_REPLY);
+}
+
+
+/*
+ * bfd_api_hookup
+ * Add vpe's API message handlers to the table.
+ * vlib has alread mapped shared memory and
+ * added the client registration handlers.
+ * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
+ */
+#define vl_msg_name_crc_list
+#include <vnet/vnet_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_bfd;
+#undef _
+}
+
+static clib_error_t *
+bfd_api_hookup (vlib_main_t * vm)
+{
+ api_main_t *am = &api_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 _
+
+ /*
+ * Set up the (msg_name, crc, message-id) table
+ */
+ setup_message_id_table (am);
+
+ return 0;
+}
+
+VLIB_API_INIT_FUNCTION (bfd_api_hookup);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/vnet/vnet/vnet_all_api_h.h b/vnet/vnet/vnet_all_api_h.h
index 7acbf2897ce..88f14a1164a 100644
--- a/vnet/vnet/vnet_all_api_h.h
+++ b/vnet/vnet/vnet_all_api_h.h
@@ -42,6 +42,7 @@
#include <vnet/unix/tap.api.h>
#include <vnet/vxlan/vxlan.api.h>
#include <vnet/vxlan-gpe/vxlan_gpe.api.h>
+#include <vnet/bfd/bfd.api.h>
/*
* fd.io coding-style-patch-verification: ON