aboutsummaryrefslogtreecommitdiffstats
path: root/src/scvpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scvpp')
-rw-r--r--src/scvpp/src/CMakeLists.txt4
-rw-r--r--src/scvpp/src/sc_vpp_comm.c47
-rw-r--r--src/scvpp/src/sc_vpp_comm.h49
-rw-r--r--src/scvpp/src/sc_vpp_interface.c252
-rw-r--r--src/scvpp/src/sc_vpp_interface.h52
-rw-r--r--src/scvpp/src/sc_vpp_ip.c222
-rw-r--r--src/scvpp/src/sc_vpp_ip.h46
7 files changed, 672 insertions, 0 deletions
diff --git a/src/scvpp/src/CMakeLists.txt b/src/scvpp/src/CMakeLists.txt
index 1a90220..c2a2c40 100644
--- a/src/scvpp/src/CMakeLists.txt
+++ b/src/scvpp/src/CMakeLists.txt
@@ -18,11 +18,15 @@ include(GNUInstallDirs)
# scvpp sources
set(SCVPP_SOURCES
sc_vpp_comm.c
+ sc_vpp_interface.c
+ sc_vpp_ip.c
)
# scvpp public headers
set(SCVPP_HEADERS
sc_vpp_comm.h
+ sc_vpp_interface.h
+ sc_vpp_ip.h
)
set(CMAKE_C_FLAGS " -g -O0 -fpic -fPIC -std=gnu99 -Wl,-rpath-link=/usr/lib")
diff --git a/src/scvpp/src/sc_vpp_comm.c b/src/scvpp/src/sc_vpp_comm.c
index 2ebdb7a..32e0303 100644
--- a/src/scvpp/src/sc_vpp_comm.c
+++ b/src/scvpp/src/sc_vpp_comm.c
@@ -14,11 +14,18 @@
*/
#include "sc_vpp_comm.h"
+#include <assert.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#define APP_NAME "sweetcomb_vpp"
#define MAX_OUTSTANDING_REQUESTS 4
#define RESPONSE_QUEUE_SIZE 2
vapi_ctx_t g_vapi_ctx_instance = NULL;
+vapi_mode_e g_vapi_mode = VAPI_MODE_NONBLOCKING;
//////////////////////////
int sc_connect_vpp()
@@ -72,4 +79,44 @@ int sc_end_with(const char* str, const char* end)
return 0;
}
+bool sc_aton(const char *cp, u8 * buf, size_t length)
+{
+ ARG_CHECK2(false, cp, buf);
+
+ struct in_addr addr;
+ int ret = inet_aton(cp, &addr);
+
+ if (0 == ret)
+ {
+ SC_LOG_DBG("error: ipv4 address %s", cp);
+ return false;
+ }
+
+ if (sizeof(addr) > length) {
+ SC_LOG_DBG_MSG("error: small buffer");
+ return false;
+ }
+
+ memcpy(buf, &addr, sizeof (addr));
+ return true;
+}
+
+char* sc_ntoa(const u8 * buf)
+{
+ ARG_CHECK(NULL, 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)
+ {
+ SC_LOG_DBG("%s: bad retval=%d", func_name, retval);
+ }
+
+ return VAPI_OK;
+}
diff --git a/src/scvpp/src/sc_vpp_comm.h b/src/scvpp/src/sc_vpp_comm.h
index 3799571..ceb3a80 100644
--- a/src/scvpp/src/sc_vpp_comm.h
+++ b/src/scvpp/src/sc_vpp_comm.h
@@ -17,6 +17,7 @@
#ifndef __SC_VPP_COMMM_H__
#define __SC_VPP_COMMM_H__
#include <vapi/vapi.h>
+#include <vapi/vapi_common.h>
#include <vapi/vpe.api.vapi.h>
DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
@@ -24,6 +25,8 @@ DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
#include <sysrepo/values.h>
#include <sysrepo/plugins.h> //for SC_LOG_DBG
+extern vapi_mode_e g_vapi_mode;
+
#define VPP_INTFC_NAME_LEN 64
#define VPP_TAPV2_NAME_LEN VPP_INTFC_NAME_LEN
#define VPP_IP4_ADDRESS_LEN 4
@@ -61,6 +64,7 @@ DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
#define SC_INVOKE_END SC_LOG_DBG("inovke %s end,with return OK.",SC_THIS_FUNC);
#define SC_INVOKE_ENDX(...) SC_LOG_DBG("inovke %s end,with %s.",SC_THIS_FUNC, ##__VA_ARGS__)
+/**********************************MACROS**********************************/
#define ARG_CHECK(retval, arg) \
do \
{ \
@@ -118,6 +122,51 @@ do { \
} \
} while(0);
+#define VAPI_RETVAL_CB(api_name) \
+static 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) \
+static 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_instance); \
+ } \
+ } \
+ while (0)
+
+#define VAPI_CALL(call_code) VAPI_CALL_MODE(call_code, g_vapi_mode)
+
+//returns true on success
+bool sc_aton(const char *cp, u8 * buf, size_t length);
+char * sc_ntoa(const u8 * buf);
+
+vapi_error_e
+vapi_retval_cb(const char* func_name, i32 retval);
+
///////////////////////////
//VPP接口
int sc_connect_vpp();
diff --git a/src/scvpp/src/sc_vpp_interface.c b/src/scvpp/src/sc_vpp_interface.c
new file mode 100644
index 0000000..333ddd7
--- /dev/null
+++ b/src/scvpp/src/sc_vpp_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 "sc_vpp_interface.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <vapi/l2.api.vapi.h>
+
+#include "sc_vpp_comm.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);
+ SC_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_instance);
+ 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_instance, mp, get_interface_id_cb, sw_interface_details_query));
+
+ if (VAPI_OK != rv) {
+ SC_LOG_DBG_MSG("vapi_sw_interface_dump");
+ return false;
+ }
+
+ if (!sw_interface_details_query->interface_found)
+ SC_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);
+ SC_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_instance);
+ assert(NULL != mp);
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx_instance, mp, get_interface_name_cb, sw_interface_details_query));
+
+ if (VAPI_OK != rv) {
+ SC_LOG_DBG_MSG("vapi_sw_interface_dump");
+ return false;
+ }
+
+ if (!sw_interface_details_query->interface_found)
+ SC_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);
+ SC_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_instance);
+ 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_instance, 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_instance);
+ 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_instance, 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_instance);
+ 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_instance, 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_instance);
+ assert(NULL != mp);
+
+ //mp->payload.mac_address =
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_create_loopback (g_vapi_ctx_instance, mp, create_loopback_cb, reply));
+
+ return rv;
+}
diff --git a/src/scvpp/src/sc_vpp_interface.h b/src/scvpp/src/sc_vpp_interface.h
new file mode 100644
index 0000000..45cc2ef
--- /dev/null
+++ b/src/scvpp/src/sc_vpp_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/scvpp/src/sc_vpp_ip.c b/src/scvpp/src/sc_vpp_ip.c
new file mode 100644
index 0000000..a09bf3a
--- /dev/null
+++ b/src/scvpp/src/sc_vpp_ip.c
@@ -0,0 +1,222 @@
+/*
+ * 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 "sc_vpp_comm.h"
+#include "sc_vpp_ip.h"
+
+#include "sc_vpp_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_instance);
+ 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 (!sc_aton(ip_address, mp->payload.address,
+ sizeof(mp->payload.address)))
+ return VAPI_EINVAL;
+
+ vapi_error_e rv;
+ VAPI_CALL(vapi_sw_interface_add_del_address (g_vapi_ctx_instance, 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_instance);
+ 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_instance, 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);
+
+ SC_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_instance, 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;
+ SC_LOG_DBG("Interface: %s, index: %d", interface_name, query.sw_interface_details.sw_if_index);
+
+ if (!sc_aton(dst_address, mp->payload.dst_address,
+ sizeof(mp->payload.dst_address)))
+ return VAPI_EINVAL;
+ if (!sc_aton(next_hop, mp->payload.next_hop_address,
+ sizeof(mp->payload.next_hop_address)))
+ return VAPI_EINVAL;
+
+ vapi_error_e rv ;
+ VAPI_CALL(vapi_ip_add_del_route(g_vapi_ctx_instance, 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, sc_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", sc_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_instance);
+ 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_instance, 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_instance);
+ 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_instance, mp, ip_table_add_del_cb, NULL));
+
+ return rv;
+}
+
+
+
+
+
+
+
diff --git a/src/scvpp/src/sc_vpp_ip.h b/src/scvpp/src/sc_vpp_ip.h
new file mode 100644
index 0000000..0940fe8
--- /dev/null
+++ b/src/scvpp/src/sc_vpp_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__ */