aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/CMakeLists.txt11
-rw-r--r--src/plugins/bapi/bapi.c103
-rw-r--r--src/plugins/bapi/bapi.h84
-rw-r--r--src/plugins/bapi/bapi_interface.c252
-rw-r--r--src/plugins/bapi/bapi_interface.h52
-rw-r--r--src/plugins/bapi/bapi_ip.c219
-rw-r--r--src/plugins/bapi/bapi_ip.h46
7 files changed, 766 insertions, 1 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 840a890..8f248c5 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -31,6 +31,15 @@ if (NOT SR_PLUGINS_DIR)
message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SR_PLUGINS_DIR manually.")
endif()
+set(BAPI_SRC
+ ./bapi/bapi.c
+ ./bapi/bapi_interface.c
+ ./bapi/bapi_ip.c
+ )
+add_library(bapi SHARED ${BAPI_SRC})
+target_include_directories(bapi PUBLIC ${VPP_INCLUDE_DIRS} ./bapi)
+target_link_libraries(bapi ${VPP_LIBRARIES})
+
# plugins sources
set(PLUGINS_SOURCES
sc_interface.c
@@ -44,7 +53,7 @@ set(PLUGINS_SOURCES
# build the source code into shared library
add_library(vpp-plugins SHARED ${PLUGINS_SOURCES})
-target_link_libraries(vpp-plugins ${SYSREPO_LIBRARIES} ${SCVPP_LIBRARIES})
+target_link_libraries(vpp-plugins ${SYSREPO_LIBRARIES} ${SCVPP_LIBRARIES} bapi)
# install the plugin into plugins dir
install(TARGETS vpp-plugins DESTINATION ${SR_PLUGINS_DIR})
diff --git a/src/plugins/bapi/bapi.c b/src/plugins/bapi/bapi.c
new file mode 100644
index 0000000..74a9121
--- /dev/null
+++ b/src/plugins/bapi/bapi.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2018 PANTHEON.tech.
+ *
+ * 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 "bapi.h"
+
+#include <assert.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+DEFINE_VAPI_MSG_IDS_VPE_API_JSON
+
+static char *api_prefix = NULL;
+static const int max_outstanding_requests = 64;
+static const int response_queue_size = 32;
+
+vapi_ctx_t g_vapi_ctx;
+vapi_mode_e g_vapi_mode = VAPI_MODE_NONBLOCKING;
+
+///
+/// Connect to binary api.
+///
+vapi_error_e bin_api_connect(const char *client_name, vapi_mode_e vapi_mode) {
+ vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx);
+ if (VAPI_OK != rv) {
+ SRP_LOG_DBG_MSG("cannot allocate context");
+ return rv;
+ }
+
+ rv = vapi_connect (g_vapi_ctx, client_name, api_prefix, max_outstanding_requests,
+ response_queue_size, vapi_mode, true);
+
+ if (VAPI_OK != rv) {
+ SRP_LOG_DBG_MSG("error: connecting to vlib");
+ return rv;
+ }
+
+ return rv;
+}
+
+///
+/// Disconnect from binary api.
+///
+vapi_error_e bin_api_disconnect(void) {
+ vapi_error_e rv = vapi_disconnect (g_vapi_ctx);
+ if (VAPI_OK != rv) {
+ SRP_LOG_DBG("error: (rc:%d)", rv);
+ //return rv;
+ }
+
+ vapi_ctx_free (g_vapi_ctx);
+
+ return rv;
+}
+
+bool bapi_aton(const char *cp, u8 * buf)
+{
+ ARG_CHECK2(false, cp, buf);
+
+ struct in_addr addr;
+ int ret = inet_aton(cp, &addr);
+
+ if (0 == ret)
+ {
+ SRP_LOG_DBG("error: ipv4 address %s", cp);
+ return false;
+ }
+
+ memcpy(buf, &addr, sizeof (addr));
+ return true;
+}
+
+char* bapi_ntoa(u8 * buf)
+{
+ struct in_addr addr;
+ memcpy(&addr, buf, sizeof(addr));
+ return inet_ntoa(addr);
+}
+
+vapi_error_e
+vapi_retval_cb(const char* func_name, i32 retval)
+{
+ if (retval)
+ {
+ SRP_LOG_DBG("%s: bad retval=%d", func_name, retval);
+ }
+
+ return VAPI_OK;
+}
diff --git a/src/plugins/bapi/bapi.h b/src/plugins/bapi/bapi.h
new file mode 100644
index 0000000..7ed12db
--- /dev/null
+++ b/src/plugins/bapi/bapi.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2018 PANTHEON.tech.
+ *
+ * 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 __BAPI_H__
+#define __BAPI_H__
+
+
+#include "sc_vpp_operation.h"
+#include <vapi/vapi.h>
+#include <vapi/vapi_common.h>
+#include <vapi/vpe.api.vapi.h>
+
+/**********************************GLOBALS**********************************/
+extern vapi_ctx_t g_vapi_ctx;
+extern vapi_mode_e g_vapi_mode;
+
+/**********************************MACROS**********************************/
+#define VAPI_RETVAL_CB(api_name) \
+vapi_error_e \
+api_name##_cb (vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, \
+ vapi_payload_##api_name##_reply * reply) \
+{ \
+ return vapi_retval_cb(__FUNCTION__, reply->retval); \
+}
+
+#define VAPI_COPY_CB(api_name) \
+vapi_error_e \
+api_name##_cb (vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, \
+ vapi_payload_##api_name##_reply * reply) \
+{ \
+ if (caller_ctx) \
+ { \
+ vapi_payload_##api_name##_reply * passed = (vapi_payload_##api_name##_reply *)caller_ctx; \
+ *passed = *reply; \
+ } \
+ return VAPI_OK; \
+}\
+
+#define VAPI_CALL_MODE(call_code, vapi_mode) \
+ do \
+ { \
+ if (VAPI_MODE_BLOCKING == (vapi_mode)) \
+ { \
+ rv = call_code; \
+ } \
+ else \
+ { \
+ while (VAPI_EAGAIN == (rv = call_code)); \
+ rv = vapi_dispatch (g_vapi_ctx); \
+ } \
+ } \
+ while (0)
+
+#define VAPI_CALL(call_code) VAPI_CALL_MODE(call_code, g_vapi_mode)
+
+
+/**********************************FUNCTIONS**********************************/
+extern vapi_error_e bin_api_connect(const char *client_name, vapi_mode_e mode);
+extern vapi_error_e bin_api_disconnect(void);
+
+
+//returns true on success
+bool bapi_aton(const char *cp, u8 * buf);
+char * bapi_ntoa(u8 * buf);
+
+vapi_error_e
+vapi_retval_cb(const char* func_name, i32 retval);
+
+
+#endif //__BAPI_H__
diff --git a/src/plugins/bapi/bapi_interface.c b/src/plugins/bapi/bapi_interface.c
new file mode 100644
index 0000000..76cd206
--- /dev/null
+++ b/src/plugins/bapi/bapi_interface.c
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2018 PANTHEON.tech.
+ *
+ * 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 "bapi_interface.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <vapi/l2.api.vapi.h>
+
+#include "bapi.h"
+
+DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON
+
+void sw_interface_details_query_set_name(sw_interface_details_query_t * query,
+ const char * interface_name)
+{
+ assert(query && interface_name);
+
+ memset(query, 0, sizeof(*query));
+
+ strncpy((char*) query->sw_interface_details.interface_name, interface_name,
+ sizeof(query->sw_interface_details.interface_name));
+}
+
+static vapi_error_e
+get_interface_id_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
+ vapi_payload_sw_interface_details * reply)
+{
+ sw_interface_details_query_t *dctx = callback_ctx;
+ assert(dctx);
+
+ if (!dctx->interface_found)
+ {
+ if (is_last)
+ {
+ assert(NULL == reply);
+ }
+ else
+ {
+ assert(NULL != reply);
+ SRP_LOG_DBG("Interface dump entry: [%u]: %s\n", reply->sw_if_index,
+ reply->interface_name);
+
+ if (0 == strcmp((const char*)dctx->sw_interface_details.interface_name,
+ (const char*)reply->interface_name))
+ {
+ dctx->interface_found = true;
+ dctx->sw_interface_details = *reply;
+ }
+ }
+ }
+
+ return VAPI_OK;
+}
+
+bool get_interface_id(sw_interface_details_query_t * sw_interface_details_query)
+{
+ ARG_CHECK(false, sw_interface_details_query);
+ sw_interface_details_query->interface_found = false;
+
+ vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx);
+ assert(NULL != mp);
+
+ mp->payload.name_filter_valid = true;
+ memcpy(mp->payload.name_filter, sw_interface_details_query->sw_interface_details.interface_name,
+ sizeof(mp->payload.name_filter));
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx, mp, get_interface_id_cb, sw_interface_details_query));
+
+ if (VAPI_OK != rv) {
+ SRP_LOG_DBG_MSG("vapi_sw_interface_dump");
+ return false;
+ }
+
+ if (!sw_interface_details_query->interface_found)
+ SRP_LOG_ERR("interface name %s: Can't find index",
+ sw_interface_details_query->sw_interface_details.interface_name);
+
+ return sw_interface_details_query->interface_found;
+}
+
+static vapi_error_e
+get_interface_name_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
+ vapi_payload_sw_interface_details * reply)
+{
+ sw_interface_details_query_t *dctx = callback_ctx;
+ assert(dctx);
+
+ if (!dctx->interface_found)
+ {
+ if (is_last)
+ {
+ assert(NULL == reply);
+ }
+ else
+ {
+ assert(reply && dctx);
+ SRP_LOG_DBG("Interface dump entry: [%u]: %s\n", reply->sw_if_index, reply->interface_name);
+
+ if (dctx->sw_interface_details.sw_if_index == reply->sw_if_index)
+ {
+ dctx->interface_found = true;
+ dctx->sw_interface_details = *reply;
+ }
+ }
+ }
+
+ return VAPI_OK;
+}
+
+bool get_interface_name(sw_interface_details_query_t * sw_interface_details_query)
+{
+ ARG_CHECK(false, sw_interface_details_query);
+ sw_interface_details_query->interface_found = false;
+
+ vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx);
+ assert(NULL != mp);
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx, mp, get_interface_name_cb, sw_interface_details_query));
+
+ if (VAPI_OK != rv) {
+ SRP_LOG_DBG_MSG("vapi_sw_interface_dump");
+ return false;
+ }
+
+ if (!sw_interface_details_query->interface_found)
+ SRP_LOG_ERR("interface index %u: Can't find name",
+ sw_interface_details_query->sw_interface_details.sw_if_index);
+
+ return sw_interface_details_query->interface_found;
+}
+
+static vapi_error_e
+sw_interface_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
+ vapi_payload_sw_interface_details * reply)
+{
+ if (is_last)
+ {
+ assert (NULL == reply);
+ }
+ else
+ {
+ assert (NULL != reply);
+ SRP_LOG_DBG("Interface dump entry: [%u]: %s\n", reply->sw_if_index,
+ reply->interface_name);
+ }
+
+ return VAPI_OK;
+}
+
+vapi_error_e bin_api_sw_interface_dump(const char * interface_name)
+{
+ vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx);
+ assert(NULL != mp);
+
+ if (NULL != interface_name)
+ {
+ mp->payload.name_filter_valid = true;
+ strncpy((char *)mp->payload.name_filter, interface_name, sizeof(mp->payload.name_filter));
+ }
+ else
+ {
+ mp->payload.name_filter_valid = false;
+ memset(mp->payload.name_filter, 0, sizeof (mp->payload.name_filter));
+ }
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx, mp, sw_interface_dump_cb, NULL));
+
+ return rv;
+}
+
+
+VAPI_RETVAL_CB(sw_interface_set_flags);
+
+vapi_error_e bin_api_sw_interface_set_flags(uint32_t if_index, uint8_t up)
+{
+ vapi_msg_sw_interface_set_flags *mp = vapi_alloc_sw_interface_set_flags (g_vapi_ctx);
+ assert(NULL != mp);
+
+ mp->payload.sw_if_index = if_index;
+ mp->payload.admin_up_down = up;
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_set_flags(g_vapi_ctx, mp, sw_interface_set_flags_cb, NULL));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(sw_interface_set_l2_bridge);
+
+vapi_error_e bin_api_sw_interface_set_l2_bridge(u32 bd_id, u32 rx_sw_if_index,
+ bool enable)
+{
+ vapi_msg_sw_interface_set_l2_bridge *mp =
+ vapi_alloc_sw_interface_set_l2_bridge (g_vapi_ctx);
+ assert(NULL != mp);
+ //set interface l2 bridge <interface> <bridge-domain-id> [bvi|uu-fwd] [shg]
+ /*
+ typedef struct __attribute__ ((__packed__)) {
+ u32 rx_sw_if_index;
+ u32 bd_id;
+ vapi_enum_l2_port_type port_type;
+ u8 shg;
+ u8 enable;
+ } vapi_payload_sw_interface_set_l2_bridge;
+ */
+ mp->payload.enable = enable;
+ mp->payload.bd_id = bd_id;
+ mp->payload.rx_sw_if_index = rx_sw_if_index;
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_set_l2_bridge (g_vapi_ctx, mp,
+ sw_interface_set_l2_bridge_cb, NULL));
+
+ return rv;
+}
+
+VAPI_COPY_CB(create_loopback)
+
+vapi_error_e bin_api_create_loopback(vapi_payload_create_loopback_reply *reply)
+{
+ ARG_CHECK(VAPI_EINVAL, reply);
+
+ vapi_msg_create_loopback *mp = vapi_alloc_create_loopback (g_vapi_ctx);
+ assert(NULL != mp);
+
+ //mp->payload.mac_address =
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_create_loopback (g_vapi_ctx, mp, create_loopback_cb, reply));
+
+ return rv;
+}
diff --git a/src/plugins/bapi/bapi_interface.h b/src/plugins/bapi/bapi_interface.h
new file mode 100644
index 0000000..45cc2ef
--- /dev/null
+++ b/src/plugins/bapi/bapi_interface.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018 PANTHEON.tech.
+ *
+ * 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 __BAPI_INTERFACE_H__
+#define __BAPI_INTERFACE_H__
+
+
+#include <vapi/interface.api.vapi.h>
+
+
+typedef struct {
+ bool interface_found;
+ vapi_payload_sw_interface_details sw_interface_details;
+} sw_interface_details_query_t;
+
+extern void sw_interface_details_query_set_name(sw_interface_details_query_t * query,
+ const char * interface_name);
+
+//input - sw_interface_details_query shall contain interface_name
+extern bool get_interface_id(sw_interface_details_query_t * sw_interface_details_query);
+
+//input - sw_interface_details_query shall contain sw_if_index
+extern bool get_interface_name(sw_interface_details_query_t * sw_interface_details_query);
+
+
+
+extern vapi_error_e bin_api_sw_interface_dump(const char * interface_name);
+
+extern vapi_error_e bin_api_sw_interface_set_flags(u32 if_index, u8 up);
+
+extern vapi_error_e bin_api_sw_interface_set_l2_bridge(u32 bd_id,
+ u32 rx_sw_if_index,
+ bool enable);
+
+extern vapi_error_e bin_api_create_loopback(
+ vapi_payload_create_loopback_reply *reply);
+
+
+#endif /* __BAPI_INTERFACE_H__ */
diff --git a/src/plugins/bapi/bapi_ip.c b/src/plugins/bapi/bapi_ip.c
new file mode 100644
index 0000000..6e4f530
--- /dev/null
+++ b/src/plugins/bapi/bapi_ip.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2018 PANTHEON.tech.
+ *
+ * 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 "bapi_ip.h"
+#include "bapi.h"
+
+#include "bapi_interface.h"
+
+#include <assert.h>
+
+DEFINE_VAPI_MSG_IDS_IP_API_JSON
+
+VAPI_RETVAL_CB(sw_interface_add_del_address);
+
+vapi_error_e
+bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add,
+ const char * ip_address, u8 address_length)
+{
+ ARG_CHECK(VAPI_EINVAL, ip_address);
+
+ vapi_msg_sw_interface_add_del_address *mp =
+ vapi_alloc_sw_interface_add_del_address (g_vapi_ctx);
+ assert(NULL != mp);
+
+ mp->payload.sw_if_index = sw_if_index;
+ mp->payload.is_add = is_add;
+ mp->payload.is_ipv6 = 0;
+ mp->payload.address_length = address_length;
+ if (!bapi_aton(ip_address, mp->payload.address))
+ return VAPI_EINVAL;
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_add_del_address (g_vapi_ctx, mp, sw_interface_add_del_address_cb, NULL));
+
+ return rv;
+}
+
+vapi_error_e
+bin_api_sw_interface_del_all_address(u32 sw_if_index)
+{
+ vapi_msg_sw_interface_add_del_address *mp =
+ vapi_alloc_sw_interface_add_del_address (g_vapi_ctx);
+ assert(NULL != mp);
+
+ mp->payload.sw_if_index = sw_if_index;
+ mp->payload.is_add = 0;
+ mp->payload.del_all = 1;
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_add_del_address (g_vapi_ctx, mp,
+ sw_interface_add_del_address_cb, NULL));
+
+ return rv;
+}
+
+VAPI_COPY_CB(ip_add_del_route)
+
+vapi_error_e bin_api_ip_add_del_route(
+ vapi_payload_ip_add_del_route_reply * reply,
+ const char* dst_address,
+ uint8_t dst_address_length,
+ const char* next_hop,
+ uint8_t is_add,
+ uint32_t table_id,
+ const char *interface_name)
+{
+ ARG_CHECK4(VAPI_EINVAL, reply, dst_address, next_hop, interface_name);
+
+ SRP_LOG_DBG("Interface: %s", interface_name);
+
+ sw_interface_details_query_t query = {0};
+ sw_interface_details_query_set_name(&query, interface_name);
+
+ if (!get_interface_id(&query))
+ {
+ return VAPI_EINVAL;
+ }
+
+ vapi_msg_ip_add_del_route *mp = vapi_alloc_ip_add_del_route (g_vapi_ctx, 1);
+ assert(NULL != mp);
+
+ //ip route add 2.2.2.2/24 via 5.5.5.5
+ //show ip fib table 0 2.2.2.0/24 detail
+
+ mp->payload.is_add = is_add;
+ mp->payload.dst_address_length = dst_address_length;
+ mp->payload.table_id = table_id;
+ mp->payload.next_hop_sw_if_index = query.sw_interface_details.sw_if_index;
+ SRP_LOG_DBG("Interface: %s, index: %d", interface_name, query.sw_interface_details.sw_if_index);
+
+ if (!bapi_aton(dst_address, mp->payload.dst_address))
+ return VAPI_EINVAL;
+ if (!bapi_aton(next_hop, mp->payload.next_hop_address))
+ return VAPI_EINVAL;
+
+ vapi_error_e rv ;
+ VAPI_CALL(vapi_ip_add_del_route(g_vapi_ctx, mp, ip_add_del_route_cb, reply));
+
+ return rv;
+}
+
+static vapi_error_e
+ip_fib_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
+ vapi_payload_ip_fib_details * reply)
+{
+ if (is_last)
+ {
+ assert (NULL == reply);
+ }
+ else
+ {
+ assert (NULL != reply);
+
+ /*
+ typedef struct __attribute__ ((__packed__)) {
+ u32 table_id;
+ u8 table_name[64];
+ u8 address_length;
+ u8 address[4];
+ u32 count;
+ u32 stats_index;
+ vapi_type_fib_path path[0];
+ } vapi_payload_ip_fib_details;
+ */
+ printf ("ip_fib_dump_cb table %u details: network %s/%u\n",
+ reply->table_id, bapi_ntoa(reply->address), reply->address_length);
+
+ for (u32 i = 0; i < reply->count; ++i)
+ {
+ /*
+ typedef struct __attribute__((__packed__)) {
+ u32 sw_if_index;
+ u32 table_id;
+ u8 weight;
+ u8 preference;
+ u8 is_local;
+ u8 is_drop;
+ u8 is_udp_encap;
+ u8 is_unreach;
+ u8 is_prohibit;
+ u8 is_resolve_host;
+ u8 is_resolve_attached;
+ u8 is_dvr;
+ u8 is_source_lookup;
+ u8 afi;
+ u8 next_hop[16];
+ u32 next_hop_id;
+ u32 rpf_id;
+ u32 via_label;
+ u8 n_labels;
+ vapi_type_fib_mpls_label label_stack[16];
+ } vapi_type_fib_path;
+
+ │493 case FIB_PATH_TYPE_ATTACHED_NEXT_HOP: │
+b+>│494 s = format (s, "%U", format_ip46_address, │
+ │495 &path->attached_next_hop.fp_nh, │
+ │496 IP46_TYPE_ANY);
+
+ */
+
+ printf("\tnext hop: %s\n", bapi_ntoa(reply->path[i].next_hop));
+ }
+ }
+
+ return VAPI_OK;
+}
+
+vapi_error_e
+bin_api_ip_fib_dump()
+{
+ vapi_msg_ip_fib_dump *mp = vapi_alloc_ip_fib_dump (g_vapi_ctx);
+ assert(NULL != mp);
+
+ //ip route add 2.2.2.2/24 via 5.5.5.5
+ //show ip fib table 0 2.2.2.0/24 detail
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx, mp, ip_fib_dump_cb, NULL));
+
+ return rv;
+}
+
+VAPI_RETVAL_CB(ip_table_add_del)
+
+vapi_error_e
+bin_api_table_add_del(u8 is_add, u32 table_id)
+{
+ vapi_msg_ip_table_add_del *mp = vapi_alloc_ip_table_add_del(g_vapi_ctx);
+ assert(NULL != mp);
+
+ mp->payload.is_add = is_add;
+ mp->payload.table_id = table_id;
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_ip_table_add_del(g_vapi_ctx, mp, ip_table_add_del_cb, NULL));
+
+ return rv;
+}
+
+
+
+
+
+
+
diff --git a/src/plugins/bapi/bapi_ip.h b/src/plugins/bapi/bapi_ip.h
new file mode 100644
index 0000000..0940fe8
--- /dev/null
+++ b/src/plugins/bapi/bapi_ip.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018 PANTHEON.tech.
+ *
+ * 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 __BAPI_IP_H__
+#define __BAPI_IP_H__
+
+#include <vapi/interface.api.vapi.h>
+#include <vapi/ip.api.vapi.h>
+
+
+extern vapi_error_e bin_api_sw_interface_add_del_address(
+ u32 sw_if_index,
+ bool is_add,
+ const char * ip_address,
+ u8 address_length);
+
+extern vapi_error_e bin_api_sw_interface_del_all_address(u32 sw_if_index);
+
+//ip_add_del_route
+extern vapi_error_e bin_api_ip_add_del_route(
+ vapi_payload_ip_add_del_route_reply * reply,
+ const char* dst_address,
+ u8 dst_address_length,
+ const char* next_address,
+ u8 is_add,
+ u32 table_id,
+ const char *interface);
+
+extern vapi_error_e bin_api_ip_fib_dump();
+extern vapi_error_e bin_api_table_add_del(u8 is_add, u32 table_id);
+
+#endif /* __BAPI_IP_H__ */