aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/CMakeLists.txt13
-rw-r--r--src/plugins/bapi/bapi.c104
-rw-r--r--src/plugins/bapi/bapi.h84
-rw-r--r--src/plugins/openconfig/openconfig_interfaces.c28
-rw-r--r--src/plugins/openconfig/openconfig_interfaces.h6
-rw-r--r--src/plugins/openconfig/openconfig_local_routing.c26
-rw-r--r--src/plugins/openconfig/openconfig_local_routing.h6
-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.c (renamed from src/plugins/bapi/bapi_interface.c)28
-rw-r--r--src/scvpp/src/sc_vpp_interface.h (renamed from src/plugins/bapi/bapi_interface.h)0
-rw-r--r--src/scvpp/src/sc_vpp_ip.c (renamed from src/plugins/bapi/bapi_ip.c)39
-rw-r--r--src/scvpp/src/sc_vpp_ip.h (renamed from src/plugins/bapi/bapi_ip.h)0
14 files changed, 170 insertions, 264 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 23c120f..a54ebf0 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -42,16 +42,6 @@ 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_plugins.c
@@ -64,8 +54,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} bapi)
+target_link_libraries(vpp-plugins ${SYSREPO_LIBRARIES} ${SCVPP_LIBRARIES})
# install the plugin into plugins dir
install(TARGETS vpp-plugins DESTINATION ${SR_PLUGINS_DIR})
-install(TARGETS bapi DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/src/plugins/bapi/bapi.c b/src/plugins/bapi/bapi.c
deleted file mode 100644
index 49107ff..0000000
--- a/src/plugins/bapi/bapi.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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) {
- SC_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) {
- SC_LOG_DBG_MSG("error: connecting to vlib");
- vapi_ctx_free(g_vapi_ctx);
- 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) {
- SC_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)
- {
- SC_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)
- {
- SC_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
deleted file mode 100644
index eeebe7a..0000000
--- a/src/plugins/bapi/bapi.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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_comm.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/openconfig/openconfig_interfaces.c b/src/plugins/openconfig/openconfig_interfaces.c
index df975b6..e401e07 100644
--- a/src/plugins/openconfig/openconfig_interfaces.c
+++ b/src/plugins/openconfig/openconfig_interfaces.c
@@ -17,10 +17,8 @@
#include "openconfig_interfaces.h"
#include "sys_util.h"
#include "sc_vpp_comm.h"
-
-#include "../bapi/bapi.h"
-#include "../bapi/bapi_interface.h"
-#include "../bapi/bapi_ip.h"
+#include "sc_vpp_interface.h"
+#include "sc_vpp_ip.h"
#include <assert.h>
#include <string.h>
@@ -211,7 +209,7 @@ int openconfig_interface_mod_cb(
__attribute__((unused)) sr_notif_event_t event,
__attribute__((unused)) void *private_ctx)
{
- SRP_LOG_DBG("Inerafce module subscribe: %s", module_name);
+ SRP_LOG_INF("Module subscribe: %s", module_name);
return SR_ERR_OK;
}
@@ -437,13 +435,13 @@ static vapi_error_e sysr_sw_interface_dump(sys_sw_interface_dump_ctx * dctx)
{
ARG_CHECK(VAPI_EINVAL, dctx);
- vapi_msg_sw_interface_dump *dump = vapi_alloc_sw_interface_dump(g_vapi_ctx);
+ vapi_msg_sw_interface_dump *dump = vapi_alloc_sw_interface_dump(g_vapi_ctx_instance);
vapi_error_e rv;
dump->payload.name_filter_valid = true;
strcpy((char*)dump->payload.name_filter, (const char *)dctx->sw_interface_details_query.sw_interface_details.interface_name);
- VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx, dump, sw_interface_dump_vapi_cb,
+ VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx_instance, dump, sw_interface_dump_vapi_cb,
dctx));
if (VAPI_OK != rv) {
@@ -455,7 +453,9 @@ static vapi_error_e sysr_sw_interface_dump(sys_sw_interface_dump_ctx * dctx)
int openconfig_interfaces_interfaces_interface_state_cb(
const char *xpath, sr_val_t **values,
- size_t *values_cnt, uint64_t request_id,
+ size_t *values_cnt,
+ __attribute__((unused)) uint64_t request_id,
+ __attribute__((unused)) const char *original_xpath,
__attribute__((unused)) void *private_ctx)
{
sr_xpath_ctx_t state = {0};
@@ -515,7 +515,7 @@ int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_
return rc;
}
- char * address_ip = bapi_ntoa(reply->ip);
+ char * address_ip = sc_ntoa(reply->ip);
sr_val_build_xpath(&vals[0], "%s/openconfig-if-ip:ip",
sysr_values_ctx->xpath_root);
@@ -556,7 +556,7 @@ ip_address_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
printf ("ip address dump entry:"
"\tsw_if_index[%u]"
"\tip[%s/%u]\n"
- , reply->sw_if_index, bapi_ntoa(reply->ip),
+ , reply->sw_if_index, sc_ntoa(reply->ip),
reply->prefix_length);
openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_state_vapi_cb(reply, dctx);
@@ -569,6 +569,7 @@ ip_address_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
__attribute__((unused)) uint64_t request_id,
+ __attribute__((unused)) const char *original_xpath,
__attribute__((unused)) void *private_ctx)
{
sr_xpath_ctx_t state = {0};
@@ -619,11 +620,11 @@ int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_
return SR_ERR_INVAL_ARG;
}
- vapi_msg_ip_address_dump *mp = vapi_alloc_ip_address_dump (g_vapi_ctx);
+ vapi_msg_ip_address_dump *mp = vapi_alloc_ip_address_dump (g_vapi_ctx_instance);
mp->payload.sw_if_index = query.sw_interface_details.sw_if_index;
mp->payload.is_ipv6 = 0;
- rv = vapi_ip_address_dump(g_vapi_ctx, mp, ip_address_dump_cb, &dctx);
+ rv = vapi_ip_address_dump(g_vapi_ctx_instance, mp, ip_address_dump_cb, &dctx);
if (VAPI_OK != rv)
{
SRP_LOG_ERR_MSG("VAPI call failed");
@@ -640,6 +641,7 @@ int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_
int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
__attribute__((unused)) uint64_t request_id,
+ __attribute__((unused)) const char *original_xpath,
__attribute__((unused)) void *private_ctx)
{
sr_xpath_ctx_t state = {0};
@@ -692,7 +694,7 @@ int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_state_
return SR_ERR_OK;
}
-VAPI_RETVAL_CB(sw_interface_add_del_address);
+// VAPI_RETVAL_CB(sw_interface_add_del_address);
static int oi_int_ipv4_conf(const char *interface_name,
const char *address_ip, u8 prefix_length,
diff --git a/src/plugins/openconfig/openconfig_interfaces.h b/src/plugins/openconfig/openconfig_interfaces.h
index e64b3e2..df5e31c 100644
--- a/src/plugins/openconfig/openconfig_interfaces.h
+++ b/src/plugins/openconfig/openconfig_interfaces.h
@@ -31,15 +31,15 @@ int openconfig_interfaces_interfaces_interface_config_cb(
int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx);
+ uint64_t request_id, const char *original_xpath, void *private_ctx);
int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx);
+ uint64_t request_id, const char *original_xpath, void *private_ctx);
int openconfig_interfaces_interfaces_interface_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx);
+ uint64_t request_id, const char *original_xpath, void *private_ctx);
int openconfig_interfaces_interfaces_interface_subinterfaces_subinterface_oc_ip_ipv4_oc_ip_addresses_oc_ip_address_oc_ip_config_cb(
sr_session_ctx_t *ds, const char *xpath, sr_notif_event_t event,
diff --git a/src/plugins/openconfig/openconfig_local_routing.c b/src/plugins/openconfig/openconfig_local_routing.c
index 4c3a0fd..daf39cc 100644
--- a/src/plugins/openconfig/openconfig_local_routing.c
+++ b/src/plugins/openconfig/openconfig_local_routing.c
@@ -17,10 +17,8 @@
#include "openconfig_local_routing.h"
#include "sys_util.h"
#include "sc_vpp_comm.h"
-
-#include "../bapi/bapi.h"
-#include "../bapi/bapi_interface.h"
-#include "../bapi/bapi_ip.h"
+#include "sc_vpp_interface.h"
+#include "sc_vpp_ip.h"
#include <assert.h>
#include <string.h>
@@ -420,7 +418,8 @@ bool address_prefix_init(address_prefix_t* address_prefix, char* str_prefix)
return false;
}
- return bapi_aton(str_prefix, address_prefix->address);
+ return sc_aton(str_prefix, address_prefix->address,
+ sizeof(address_prefix->address));
}
// XPATH: /openconfig-local-routing:local-routes/static-routes/static/state
@@ -443,7 +442,7 @@ int openconfig_local_routing_local_routes_static_routes_static_state_vapi_cb(
//Filling the structure
snprintf(address_prefix, sizeof(address_prefix), "%s/%u",
- bapi_ntoa(reply->address), reply->address_length);
+ sc_ntoa(reply->address), reply->address_length);
sr_val_build_xpath(&vals[0], "%s/prefix",
sysr_ip_fib_details_ctx->sysr_values_ctx.xpath_root);
@@ -482,6 +481,7 @@ ip_routing_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
int openconfig_local_routing_local_routes_static_routes_static_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
__attribute__((unused)) uint64_t request_id,
+ __attribute__((unused)) const char *original_xpath,
__attribute__((unused)) void *private_ctx)
{
sr_xpath_ctx_t state = {0};
@@ -510,9 +510,9 @@ int openconfig_local_routing_local_routes_static_routes_static_state_cb(
}
- vapi_msg_ip_fib_dump *mp = vapi_alloc_ip_fib_dump (g_vapi_ctx);
+ vapi_msg_ip_fib_dump *mp = vapi_alloc_ip_fib_dump (g_vapi_ctx_instance);
- VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx, mp, ip_routing_dump_cb, &dctx));
+ VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx_instance, mp, ip_routing_dump_cb, &dctx));
if(VAPI_OK != rv)
{
SRP_LOG_ERR_MSG("VAPI call failed");
@@ -550,7 +550,7 @@ int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_ho
sr_val_set_str_data(&vals[0], SR_STRING_T,
sysr_ip_fib_details_ctx->next_hop_index);
- strncpy(next_hop, bapi_ntoa(reply->next_hop), sizeof(next_hop));
+ strncpy(next_hop, sc_ntoa(reply->next_hop), sizeof(next_hop));
sr_val_build_xpath(&vals[1], "%s/next-hop", sysr_ip_fib_details_ctx->sysr_values_ctx.xpath_root);
sr_val_set_str_data(&vals[1], SR_STRING_T, next_hop);
@@ -683,8 +683,8 @@ int next_hop_inner(
return SR_ERR_INVAL_ARG;
}
- vapi_msg_ip_fib_dump *mp = vapi_alloc_ip_fib_dump (g_vapi_ctx);
- VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx, mp, ip_routing_next_hop_dump_cb, &dctx));
+ vapi_msg_ip_fib_dump *mp = vapi_alloc_ip_fib_dump (g_vapi_ctx_instance);
+ VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx_instance, mp, ip_routing_next_hop_dump_cb, &dctx));
if (VAPI_OK != rv)
{
SRP_LOG_ERR_MSG("VAPI call failed");
@@ -715,7 +715,7 @@ int next_hop_inner(
int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_hop_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx)
+ uint64_t request_id, const char *original_xpath, void *private_ctx)
{
return next_hop_inner(false, xpath, values, values_cnt, request_id,
private_ctx);
@@ -723,7 +723,7 @@ int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_ho
int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_hop_interface_ref_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx)
+ uint64_t request_id, const char *original_xpath, void *private_ctx)
{
return next_hop_inner(true, xpath, values, values_cnt, request_id,
private_ctx);
diff --git a/src/plugins/openconfig/openconfig_local_routing.h b/src/plugins/openconfig/openconfig_local_routing.h
index 4cde542..4cd2966 100644
--- a/src/plugins/openconfig/openconfig_local_routing.h
+++ b/src/plugins/openconfig/openconfig_local_routing.h
@@ -34,14 +34,14 @@ int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_ho
int openconfig_local_routing_local_routes_static_routes_static_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx);
+ uint64_t request_id, const char *original_xpath, void *private_ctx);
int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_hop_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx);
+ uint64_t request_id, const char *original_xpath, void *private_ctx);
int openconfig_local_routing_local_routes_static_routes_static_next_hops_next_hop_interface_ref_state_cb(
const char *xpath, sr_val_t **values, size_t *values_cnt,
- uint64_t request_id, void *private_ctx);
+ uint64_t request_id, const char *original_xpath, void *private_ctx);
#endif /* __OPENCONFIG_LOCAL_ROUTING_H__ */
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/plugins/bapi/bapi_interface.c b/src/scvpp/src/sc_vpp_interface.c
index 5e035fa..333ddd7 100644
--- a/src/plugins/bapi/bapi_interface.c
+++ b/src/scvpp/src/sc_vpp_interface.c
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#include "bapi_interface.h"
+#include "sc_vpp_interface.h"
#include <assert.h>
#include <stdbool.h>
#include <vapi/l2.api.vapi.h>
-#include "bapi.h"
+#include "sc_vpp_comm.h"
DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON
@@ -72,7 +72,7 @@ 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);
+ vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx_instance);
assert(NULL != mp);
mp->payload.name_filter_valid = true;
@@ -80,7 +80,7 @@ bool get_interface_id(sw_interface_details_query_t * sw_interface_details_query)
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));
+ 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");
@@ -129,11 +129,11 @@ bool get_interface_name(sw_interface_details_query_t * sw_interface_details_quer
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);
+ 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, mp, get_interface_name_cb, sw_interface_details_query));
+ 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");
@@ -168,7 +168,7 @@ sw_interface_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
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);
+ vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx_instance);
assert(NULL != mp);
if (NULL != interface_name)
@@ -183,7 +183,7 @@ vapi_error_e bin_api_sw_interface_dump(const char * interface_name)
}
vapi_error_e rv;
- VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx, mp, sw_interface_dump_cb, NULL));
+ VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx_instance, mp, sw_interface_dump_cb, NULL));
return rv;
}
@@ -193,14 +193,14 @@ 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);
+ 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, mp, sw_interface_set_flags_cb, NULL));
+ VAPI_CALL(vapi_sw_interface_set_flags(g_vapi_ctx_instance, mp, sw_interface_set_flags_cb, NULL));
return rv;
}
@@ -211,7 +211,7 @@ 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);
+ 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]
/*
@@ -228,7 +228,7 @@ vapi_error_e bin_api_sw_interface_set_l2_bridge(u32 bd_id, u32 rx_sw_if_index,
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,
+ VAPI_CALL(vapi_sw_interface_set_l2_bridge (g_vapi_ctx_instance, mp,
sw_interface_set_l2_bridge_cb, NULL));
return rv;
@@ -240,13 +240,13 @@ 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);
+ 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, mp, create_loopback_cb, reply));
+ VAPI_CALL(vapi_create_loopback (g_vapi_ctx_instance, mp, create_loopback_cb, reply));
return rv;
}
diff --git a/src/plugins/bapi/bapi_interface.h b/src/scvpp/src/sc_vpp_interface.h
index 45cc2ef..45cc2ef 100644
--- a/src/plugins/bapi/bapi_interface.h
+++ b/src/scvpp/src/sc_vpp_interface.h
diff --git a/src/plugins/bapi/bapi_ip.c b/src/scvpp/src/sc_vpp_ip.c
index aa8baa5..a09bf3a 100644
--- a/src/plugins/bapi/bapi_ip.c
+++ b/src/scvpp/src/sc_vpp_ip.c
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#include "bapi_ip.h"
-#include "bapi.h"
+#include "sc_vpp_comm.h"
+#include "sc_vpp_ip.h"
-#include "bapi_interface.h"
+#include "sc_vpp_interface.h"
#include <assert.h>
@@ -32,18 +32,19 @@ bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add,
ARG_CHECK(VAPI_EINVAL, ip_address);
vapi_msg_sw_interface_add_del_address *mp =
- vapi_alloc_sw_interface_add_del_address (g_vapi_ctx);
+ 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 (!bapi_aton(ip_address, mp->payload.address))
+ 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, mp, sw_interface_add_del_address_cb, NULL));
+ VAPI_CALL(vapi_sw_interface_add_del_address (g_vapi_ctx_instance, mp, sw_interface_add_del_address_cb, NULL));
return rv;
}
@@ -52,7 +53,7 @@ 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);
+ vapi_alloc_sw_interface_add_del_address (g_vapi_ctx_instance);
assert(NULL != mp);
mp->payload.sw_if_index = sw_if_index;
@@ -60,7 +61,7 @@ bin_api_sw_interface_del_all_address(u32 sw_if_index)
mp->payload.del_all = 1;
vapi_error_e rv;
- VAPI_CALL(vapi_sw_interface_add_del_address (g_vapi_ctx, mp,
+ VAPI_CALL(vapi_sw_interface_add_del_address (g_vapi_ctx_instance, mp,
sw_interface_add_del_address_cb, NULL));
return rv;
@@ -89,7 +90,7 @@ vapi_error_e bin_api_ip_add_del_route(
return VAPI_EINVAL;
}
- vapi_msg_ip_add_del_route *mp = vapi_alloc_ip_add_del_route (g_vapi_ctx, 1);
+ 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
@@ -101,13 +102,15 @@ vapi_error_e bin_api_ip_add_del_route(
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 (!bapi_aton(dst_address, mp->payload.dst_address))
+ if (!sc_aton(dst_address, mp->payload.dst_address,
+ sizeof(mp->payload.dst_address)))
return VAPI_EINVAL;
- if (!bapi_aton(next_hop, mp->payload.next_hop_address))
+ 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, mp, ip_add_del_route_cb, reply));
+ VAPI_CALL(vapi_ip_add_del_route(g_vapi_ctx_instance, mp, ip_add_del_route_cb, reply));
return rv;
}
@@ -137,7 +140,7 @@ ip_fib_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
} 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);
+ reply->table_id, sc_ntoa(reply->address), reply->address_length);
for (u32 i = 0; i < reply->count; ++i)
{
@@ -172,7 +175,7 @@ b+>│494 s = format (s, "%U", format_ip46_address,
*/
- printf("\tnext hop: %s\n", bapi_ntoa(reply->path[i].next_hop));
+ printf("\tnext hop: %s\n", sc_ntoa(reply->path[i].next_hop));
}
}
@@ -182,14 +185,14 @@ b+>│494 s = format (s, "%U", format_ip46_address,
vapi_error_e
bin_api_ip_fib_dump()
{
- vapi_msg_ip_fib_dump *mp = vapi_alloc_ip_fib_dump (g_vapi_ctx);
+ 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, mp, ip_fib_dump_cb, NULL));
+ VAPI_CALL(vapi_ip_fib_dump(g_vapi_ctx_instance, mp, ip_fib_dump_cb, NULL));
return rv;
}
@@ -199,14 +202,14 @@ 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);
+ 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, mp, ip_table_add_del_cb, NULL));
+ VAPI_CALL(vapi_ip_table_add_del(g_vapi_ctx_instance, mp, ip_table_add_del_cb, NULL));
return rv;
}
diff --git a/src/plugins/bapi/bapi_ip.h b/src/scvpp/src/sc_vpp_ip.h
index 0940fe8..0940fe8 100644
--- a/src/plugins/bapi/bapi_ip.h
+++ b/src/scvpp/src/sc_vpp_ip.h