diff options
-rw-r--r-- | cmake/Modules/BuildMacros.cmake | 11 | ||||
-rw-r--r-- | cmake/Modules/FindSysrepo.cmake | 2 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/AUTHORS | 5 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/CMakeLists.txt | 42 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c | 13 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h | 22 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c | 54 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt | 61 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c | 19 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c | 9 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h | 73 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c | 124 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c | 1304 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h | 59 | ||||
-rw-r--r-- | ctrl/sysrepo-plugins/yang/hicn/hicn.yang | 85 |
15 files changed, 808 insertions, 1075 deletions
diff --git a/cmake/Modules/BuildMacros.cmake b/cmake/Modules/BuildMacros.cmake index 85789a08a..ed767dbcc 100644 --- a/cmake/Modules/BuildMacros.cmake +++ b/cmake/Modules/BuildMacros.cmake @@ -73,7 +73,7 @@ macro(build_library lib) cmake_parse_arguments(ARG "SHARED;STATIC;NO_DEV" "COMPONENT;" - "SOURCES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS;INCLUDE_DIRS;DEFINITIONS;INSTALL_ROOT_DIR" + "SOURCES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS;INCLUDE_DIRS;DEFINITIONS;INSTALL_ROOT_DIR;INSTALL_FULL_PATH_DIR" ${ARGN} ) @@ -145,11 +145,17 @@ macro(build_library lib) ) endif() + set(INSTALL_LIB_PATH ${CMAKE_INSTALL_LIBDIR}) + + if (ARG_INSTALL_FULL_PATH_DIR) + set(INSTALL_LIB_PATH ${ARG_INSTALL_FULL_PATH_DIR}) + endif() + install( TARGETS ${library} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${INSTALL_LIB_PATH} COMPONENT ${ARG_COMPONENT} ) @@ -160,7 +166,6 @@ macro(build_library lib) # install headers if(ARG_INSTALL_HEADERS) - if (NOT ARG_INSTALL_ROOT_DIR) set(ARG_INSTALL_ROOT_DIR "hicn") endif() diff --git a/cmake/Modules/FindSysrepo.cmake b/cmake/Modules/FindSysrepo.cmake index 4228ef93a..1c389e480 100644 --- a/cmake/Modules/FindSysrepo.cmake +++ b/cmake/Modules/FindSysrepo.cmake @@ -43,4 +43,4 @@ set(SYSREPO_INCLUDE_DIRS ${SYSREPO_INCLUDE_DIR} ${SYSREPO_INCLUDE_MAIN_DIR}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Sysrepo DEFAULT_MSG SYSREPO_LIBRARIES SYSREPO_INCLUDE_DIRS) -mark_as_advanced(SYSREPO_LIBRARY SYSREPO_INCLUDE_DIR SYSREPO_INCLUDE_MAIN_DIR)
\ No newline at end of file +mark_as_advanced(SYSREPO_LIBRARY SYSREPO_INCLUDE_DIR SYSREPO_INCLUDE_MAIN_DIR) diff --git a/ctrl/sysrepo-plugins/AUTHORS b/ctrl/sysrepo-plugins/AUTHORS new file mode 100644 index 000000000..35097a36c --- /dev/null +++ b/ctrl/sysrepo-plugins/AUTHORS @@ -0,0 +1,5 @@ +hicn sysrepo plugin authors are listed below: + + Masoud Hemmatpour <mhemmatp@cisco.com> + Alberto Compagno <acompagn@cisco.com> + Luca Muscariello <lumuscar@cisco.com> diff --git a/ctrl/sysrepo-plugins/CMakeLists.txt b/ctrl/sysrepo-plugins/CMakeLists.txt index 93434b9c6..13a601bf0 100644 --- a/ctrl/sysrepo-plugins/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/CMakeLists.txt @@ -16,29 +16,37 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(hicn_sysrepo_plugin) -include(GNUInstallDirs) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/Modules" ) -# set default build type if not specified by user -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) +include(GNUInstallDirs) +include(BuildMacros) + +find_package(PkgConfig) +find_package(Sysrepo) + +if (NOT SRPD_PLUGINS_PATH) + if (PKG_CONFIG_FOUND) + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SRPD_PLUGINS_PATH" "libsysrepo" OUTPUT_VARIABLE SRPD_PLUGINS_PATH) + string(STRIP ${SRPD_PLUGINS_PATH} SRPD_PLUGINS_PATH) + endif() +endif() +if (NOT SRPD_PLUGINS_PATH) + message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SRPD_PLUGINS_PATH manually.") endif() -string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) -# set compiler options -set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99") -set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") -set(CMAKE_C_FLAGS_DEBUG "-g -O0") +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + find_package_wrapper(VPP REQUIRED) + find_package_wrapper(HicnPlugin REQUIRED) + add_subdirectory(hicn-plugin) +else() + if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + list(APPEND DEPENDENCIES + hicn_plugin) + add_subdirectory(hicn-plugin) + endif () +endif() # add subdirectories -if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - add_subdirectory(hicn-plugin) -endif () -if (BUILD_HICNLIGHT AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - add_subdirectory(hicn-light) -endif () include(Packaging) diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c index ae436a8ad..6cfc0b52b 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c @@ -27,7 +27,6 @@ sr_subscription_ctx_t *subscription = NULL; volatile int exit_application = 0; int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { - HICN_INVOKE_BEGIN sr_subscription_ctx_t *subscription = NULL; int rc = SR_ERR_OK; rc = hicn_connect_light(); @@ -36,24 +35,20 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { return SR_ERR_INTERNAL; } - // HICN subscribe hicn_subscribe_events(session, &subscription); /* set subscription as our private context */ *private_ctx = subscription; - HICN_INVOKE_END; return SR_ERR_OK; } void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx) { - HICN_INVOKE_BEGIN; /* subscription was set as our private context */ - sr_unsubscribe(session, private_ctx); + sr_unsubscribe(private_ctx); HICN_LOG_DBG_MSG("hicn light unload plugin ok."); hicn_disconnect_light(); HICN_LOG_DBG_MSG("hicn light disconnect ok."); - HICN_INVOKE_END; } static void sigint_handler(int signum) { exit_application = 1; } @@ -75,14 +70,14 @@ int main(int argc, char **argv) { } /* connect to sysrepo */ - rc = sr_connect("cpe_application", SR_CONN_DEFAULT, &connection); + rc = sr_connect(SR_CONN_DEFAULT, &connection); if (SR_ERR_OK != rc) { fprintf(stderr, "Error by sr_connect: %s\n", sr_strerror(rc)); goto cleanup; } /* start session */ - rc = sr_session_start(connection, SR_DS_STARTUP, SR_SESS_DEFAULT, &session); + rc = sr_session_start(connection, SR_DS_STARTUP, &session); if (SR_ERR_OK != rc) { fprintf(stderr, "Error by sr_session_start: %s\n", sr_strerror(rc)); goto cleanup; @@ -107,7 +102,7 @@ int main(int argc, char **argv) { cleanup: if (NULL != subscription) { - sr_unsubscribe(session, subscription); + sr_unsubscribe(subscription); } if (NULL != session) { sr_session_stop(session); diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h index 100023564..ca67cf0b7 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h @@ -16,7 +16,6 @@ #ifndef __HICN_LIGHT_COMMM_H__ #define __HICN_LIGHT_COMMM_H__ #include <sysrepo.h> -#include <sysrepo/plugins.h> #include <sysrepo/values.h> @@ -30,27 +29,6 @@ #endif #endif -#ifndef _NOLOG -#define HICN_LOG_DBG SRP_LOG_DBG -#define HICN_LOG_ERR SRP_LOG_ERR -#define HICN_LOG_DBG_MSG SRP_LOG_DBG_MSG -#define HICN_LOG_ERR_MSG SRP_LOG_ERR_MSG -#else -#define HICN_LOG_DBG // printf -#define HICN_LOG_DBG // SRP_LOG_DBG -#define HICN_LOG_ERR // SRP_LOG_ERR -#define HICN_LOG_DBG_MSG // SRP_LOG_DBG_MSG -#define HICN_LOG_ERR_MSG // SRP_LOG_ERR_MSG -#endif - -//Here it is the definition - -#define HICN_INVOKE_BEGIN HICN_LOG_DBG("inovke %s bein.", HICN_THIS_FUNC); -#define HICN_INVOKE_END \ - HICN_LOG_DBG("inovke %s end,with return OK.", HICN_THIS_FUNC); -#define HICN_INVOKE_ENDX(...) \ - HICN_LOG_DBG("inovke %s end,with %s.", HICN_THIS_FUNC, ##__VA_ARGS__) - #define ARG_CHECK(retval, arg) \ do { \ if (NULL == (arg)) { \ diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c index 6f8ece08c..47e07d196 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c @@ -28,11 +28,10 @@ /** * @brief API to add hicn face ip in hicn-light. */ -static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn face ip add received successfully"); + SRP_LOG_DBGMSG("hicn face ip add received successfully"); hc_face_t face; if(strcmp(input[0].data.string_val,"-1")){ @@ -51,7 +50,7 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, face.face.local_addr.v6.as_in6addr = *dst; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } @@ -72,12 +71,11 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, face.face.remote_addr.v6.as_in6addr = *dst; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } - // strncpy(face.face.hicn.netdevice.name,"ens39"); // Can we work only with Idx number ? face.face.netdevice.index = input[4].data.uint32_val; // This is the idx number of interface @@ -88,34 +86,29 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, int rc; rc = hc_face_create(hsocket, &face); if (rc > 0) { - SRP_LOG_DBG_MSG("Face added successfully"); + SRP_LOG_DBGMSG("Face added successfully"); return SR_ERR_OK; } - SRP_LOG_DBG_MSG("Operation Failed"); + SRP_LOG_DBGMSG("Operation Failed"); return SR_ERR_OPERATION_FAILED; } /** * @brief API to del hicn face ip in vpp. */ -static int hicn_face_ip_del_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_face_ip_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn face ip del received successfully"); + SRP_LOG_DBGMSG("hicn face ip del received successfully"); face_t * face=NULL; - // msg->payload.faceid = input[0].data.uint16_val; - //lookup(face); + face_free(face); - // if(!resp->payload.retval){ - // SRP_LOG_DBG_MSG("Successfully Done"); - // return SR_ERR_OK; - // } - SRP_LOG_DBG_MSG("Operation Failed"); + + SRP_LOG_DBGMSG("Operation Failed"); return SR_ERR_OPERATION_FAILED; } @@ -124,9 +117,8 @@ static int hicn_face_ip_del_cb(const char *xpath, const sr_val_t *input, /** * @brief API to del hicn face ip in vpp. */ -static int hicn_route_add_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_route_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { /* @@ -169,34 +161,34 @@ int hicn_subscribe_events(sr_session_ctx_t *session, int rc; rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); + session, 100,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription stat-get\n"); + SRP_LOG_DBGMSG("Problem in subscription stat-get\n"); goto error; } rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); + session, 100,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription face-ip-del\n"); + SRP_LOG_DBGMSG("Problem in subscription face-ip-del\n"); goto error; } rc = sr_rpc_subscribe(session, "/hicn:route-nhops-add", - hicn_route_add_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + hicn_route_add_cb, session, 100,SR_SUBSCR_CTX_REUSE, subscription); if (rc!= SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription route-nhops-add\n"); + SRP_LOG_DBGMSG("Problem in subscription route-nhops-add\n"); goto error; } - SRP_LOG_INF_MSG("hicn light initialized successfully."); + SRP_LOG_DBGMSG("hicn light initialized successfully."); return SR_ERR_OK; error: - SRP_LOG_ERR_MSG("Error by initialization of the hicn plugin."); + SRP_LOG_ERRMSG("Error by initialization of the hicn plugin."); sr_plugin_cleanup_cb(session, hsocket); return rc; diff --git a/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt index 37590ee4c..34dbdb817 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt @@ -12,40 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -# set compiler options -set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99") -set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") -set(CMAKE_C_FLAGS_DEBUG "-g -O0") - cmake_minimum_required(VERSION 2.8) -project(sysrepo-vpp-plugins) # Cmake find modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/Modules" -"${CMAKE_CURRENT_LIST_DIR}/../../../cmake/Modules" +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../cmake/Modules" + "${CMAKE_CURRENT_LIST_DIR}/../cmake/Modules" ) -find_package(VPP) -find_package(PkgConfig) -find_package(HicnPlugin) -find_package(Sysrepo) - -#pkg_check_modules(SYSREPO libsysrepo) - -# get sysrepo plugins directory from pkgconfig -if (NOT SR_PLUGINS_DIR) - if (PKG_CONFIG_FOUND) - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SR_PLUGINS_DIR" "libsysrepo" OUTPUT_VARIABLE SR_PLUGINS_DIR) - string(STRIP ${SR_PLUGINS_DIR} SR_PLUGINS_DIR) - endif() -endif() -if (NOT SR_PLUGINS_DIR) - message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SR_PLUGINS_DIR manually.") -endif() - # plugins sources -set(PLUGINS_SOURCES +set(SOURCE_FILES plugin/ietf/ietf_interface.c plugin/model/hicn_model.c plugin/model/tlock.c @@ -53,15 +28,21 @@ set(PLUGINS_SOURCES plugin/hicn_plugin.c ) -# build the source code into shared library -add_library(hicn SHARED ${PLUGINS_SOURCES}) -target_include_directories(hicn PUBLIC ${VPP_INCLUDE_DIRS} ${HICNPLUGIN_INCLUDE_DIRS}) -target_link_libraries(hicn ${SYSREPO_LIBRARIES} ${VPP_LIBRARIES}) - -#set_target_properties(hicn -# PROPERTIES -# LINKER_LANGUAGE C -# INSTALL_RPATH ${VPP_HOME}/lib) - -# install the plugin into plugins dir -install(TARGETS hicn DESTINATION ${SR_PLUGINS_DIR} COMPONENT hicn_sysrepo_plugin) +list(APPEND SYSREPO_PLUGIN_INCLUDE_DIRS + ${VPP_INCLUDE_DIRS} + ${HICNPLUGIN_INCLUDE_DIRS}) + +list(APPEND LIBRARIES + ${SYSREPO_LIBRARIES} + ${VPP_LIBRARIES}) + +build_library(sysrepohicn + SHARED + SOURCES ${SOURCE_FILES} + LINK_LIBRARIES ${LIBRARIES} + DEPENDS ${DEPENDENCIES} + COMPONENT hicn_sysrepo_plugin + INCLUDE_DIRS ${SYSREPO_PLUGIN_INCLUDE_DIRS} + INSTALL_FULL_PATH_DIR ${SRPD_PLUGINS_PATH} + DEFINITIONS ${COMPILER_DEFINITIONS} +) diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c index 262e98553..5072c3d6c 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c @@ -27,12 +27,11 @@ sr_subscription_ctx_t *subscription = NULL; volatile int exit_application = 0; int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { - HICN_INVOKE_BEGIN; + sr_subscription_ctx_t *subscription = NULL; int rc = SR_ERR_OK; rc = hicn_connect_vpp(); if (SR_ERR_OK != rc) { - HICN_LOG_ERR("vpp connect error , with return %d.", rc); return SR_ERR_INTERNAL; } @@ -40,24 +39,20 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { hicn_subscribe_events(session, &subscription); // IETF subscribe - ietf_subscribe_events(session, &subscription); + // ietf_subscribe_events(session, &subscription); /* set subscription as our private context */ *private_ctx = subscription; - HICN_INVOKE_END; + return SR_ERR_OK; } void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx) { - HICN_INVOKE_BEGIN; /* subscription was set as our private context */ - sr_unsubscribe(session, private_ctx); - HICN_LOG_DBG_MSG("hicn pligin unload plugin ok."); + sr_unsubscribe(private_ctx); hicn_disconnect_vpp(); - HICN_LOG_DBG_MSG("hicn plugin disconnect vpp ok."); - HICN_INVOKE_END; } static void sigint_handler(int signum) { exit_application = 1; } @@ -78,14 +73,14 @@ int main(int argc, char **argv) { } /* connect to sysrepo */ - rc = sr_connect("cpe_application", SR_CONN_DEFAULT, &connection); + rc = sr_connect(SR_CONN_DEFAULT, &connection); if (SR_ERR_OK != rc) { fprintf(stderr, "Error by sr_connect: %s\n", sr_strerror(rc)); goto cleanup; } /* start session */ - rc = sr_session_start(connection, SR_DS_STARTUP, SR_SESS_DEFAULT, &session); + rc = sr_session_start(connection, SR_DS_STARTUP, &session); if (SR_ERR_OK != rc) { fprintf(stderr, "Error by sr_session_start: %s\n", sr_strerror(rc)); goto cleanup; @@ -110,7 +105,7 @@ int main(int argc, char **argv) { cleanup: if (NULL != subscription) { - sr_unsubscribe(session, subscription); + sr_unsubscribe(subscription); } if (NULL != session) { sr_session_stop(session); diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c index f044c5b1b..e028d7840 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c @@ -28,22 +28,21 @@ vapi_ctx_t g_vapi_ctx_instance=NULL; int hicn_connect_vpp() { - HICN_INVOKE_BEGIN; + if (g_vapi_ctx_instance == NULL) { vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx_instance); rv = vapi_connect(g_vapi_ctx_instance, APP_NAME, NULL, MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE, VAPI_MODE_BLOCKING, true); if (rv != VAPI_OK) { - HICN_LOG_ERR("*connect %s faild,with return %d", APP_NAME, rv); + SRP_LOG_DBGMSG("Error connection"); vapi_ctx_free(g_vapi_ctx_instance); return -1; } - HICN_LOG_DBG("*connected %s ok", APP_NAME); + SRP_LOG_DBGMSG("*connected ok"); } else { - HICN_LOG_DBG("connection %s keeping", APP_NAME); + SRP_LOG_DBGMSG("connection keeping"); } - HICN_INVOKE_END; return 0; } diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h index fd71dbaf2..720bd6835 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h @@ -16,7 +16,6 @@ #ifndef __HICN_VPP_COMMM_H__ #define __HICN_VPP_COMMM_H__ #include <sysrepo.h> -#include <sysrepo/plugins.h> //for HICN_LOG_DBG #include <sysrepo/values.h> #include <vapi/vapi.h> @@ -28,20 +27,6 @@ #endif #endif -#ifndef _NOLOG -#define HICN_LOG_DBG SRP_LOG_DBG -#define HICN_LOG_ERR SRP_LOG_ERR -#define HICN_LOG_DBG_MSG SRP_LOG_DBG_MSG -#define HICN_LOG_ERR_MSG SRP_LOG_ERR_MSG -#else -#define HICN_LOG_DBG // printf -#define HICN_LOG_DBG // SRP_LOG_DBG -#define HICN_LOG_ERR // SRP_LOG_ERR -#define HICN_LOG_DBG_MSG // SRP_LOG_DBG_MSG -#define HICN_LOG_ERR_MSG // SRP_LOG_ERR_MSG -#endif - - // ctx vpp connect extern vapi_ctx_t g_vapi_ctx_instance; @@ -50,16 +35,11 @@ extern vapi_ctx_t g_vapi_ctx_instance; #define VPP_INTFC_NAME_LEN 64 #define VPP_MAC_ADDRESS_LEN 8 #define VPP_IP6_ADDRESS_LEN 16 -#define HICN_INVOKE_BEGIN HICN_LOG_DBG("inovke %s bein.", HICN_THIS_FUNC); -#define HICN_INVOKE_END \ - HICN_LOG_DBG("inovke %s end,with return OK.", HICN_THIS_FUNC); -#define HICN_INVOKE_ENDX(...) \ - HICN_LOG_DBG("inovke %s end,with %s.", HICN_THIS_FUNC, ##__VA_ARGS__) #define ARG_CHECK(retval, arg) \ do { \ if (NULL == (arg)) { \ - HICN_LOG_ERR_MSG(#arg ":NULL pointer passed."); \ + SRP_LOG_DBGMSG("NULL pointer passed."); \ return (retval); \ } \ } while (0) @@ -70,59 +50,16 @@ extern vapi_ctx_t g_vapi_ctx_instance; ARG_CHECK(retval, arg1); \ ARG_CHECK(retval, arg2) -#define ARG_CHECK6(retval, arg1, arg2, arg3, arg4, arg5, arg6) \ +#define ARG_CHECK7(retval, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ ARG_CHECK(retval, arg1); \ ARG_CHECK(retval, arg2); \ ARG_CHECK(retval, arg3); \ ARG_CHECK(retval, arg4); \ ARG_CHECK(retval, arg5); \ - ARG_CHECK(retval, arg6) - - -/** - * when use tihs must fist DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON - */ -#define HICN_VPP_VAPI_RECV \ - do { \ - size_t size; \ - int recv_vapimsgid = -1; \ - vapi_recv(g_vapi_ctx_instance, (void *)&resp, &size, 0, 0); \ - recv_vapimsgid = vapi_lookup_vapi_msg_id_t( \ - g_vapi_ctx_instance, ntohs(resp->header._vl_msg_id)); \ - if (recv_vapimsgid <= vapi_msg_id_get_next_index_reply || \ - recv_vapimsgid >= vapi_get_message_count()) { \ - HICN_LOG_DBG("***recv error msgid[%d] not in [0-%d) ,try again!***\n", \ - recv_vapimsgid, vapi_get_message_count()); \ - } else { \ - HICN_LOG_DBG("recv msgid [%d]\n", recv_vapimsgid); \ - break; \ - } \ - } while (1); - -#define HICN_REGISTER_RPC_EVT_HANDLER(rpc_evt_handle) \ - do { \ - sr_error_t rc = rpc_evt_handle(session, &subscription); \ - if (SR_ERR_OK != rc) { \ - HICN_LOG_ERR("load plugin failed: %s", sr_strerror(rc)); \ - sr_unsubscribe(session, subscription); \ - HICN_INVOKE_ENDX(sr_strerror(rc)); \ - return rc; \ - } \ - } while (0); - - -// define the error list -typedef enum { - HICN_OK = 0, /* Success */ - HICN_EINVAL, /* Invalid value encountered */ - HICN_EAGAIN, /* Operation would block */ - HICN_ENOTSUP, /* Operation not supported */ - HICN_ENOMEM, /* Out of memory */ - HICN_NOT_FOUND, /* Required element can not be found */ -} hicn_error_e; - + ARG_CHECK(retval, arg6); \ + ARG_CHECK(retval, arg7) int hicn_connect_vpp(); int hicn_disconnect_vpp(); -#endif //__HICN_VPP_COMMM_H__
\ No newline at end of file +#endif //__HICN_VPP_COMMM_H__ diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c index 0498527cb..b3d31ff80 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c @@ -19,7 +19,6 @@ #include <arpa/inet.h> #include <sysrepo.h> -#include <sysrepo/plugins.h> #include <sysrepo/values.h> #include <sysrepo/xpath.h> #include <vnet/interface.h> @@ -117,30 +116,57 @@ interface_enable_disable(const char *if_name, bool enable) uint32_t if_index = ~0; int rc = 0; - SRP_LOG_DBG("%s interface '%s'", enable ? "Enabling" : "Disabling", if_name); /* get interface index */ rc = ietf_interface_name2index(if_name, &if_index); if (0 != rc) { - SRP_LOG_ERR("Invalid interface name: %s", if_name); + SRP_LOG_ERRMSG("Invalid interface name"); return SR_ERR_INVAL_ARG; } /* enable/disable interface */ rc = ietf_setInterfaceFlags(if_index, (uint8_t)enable); if (0 != rc) { - SRP_LOG_ERR("Error by processing of the sw_interface_set_flags request, rc=%d", rc); + SRP_LOG_ERRMSG("Error by processing of the sw_interface_set_flags request"); return SR_ERR_OPERATION_FAILED; } else { return SR_ERR_OK; } } + +vapi_error_e call_sw_interface_add_del_address(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_sw_interface_add_del_address_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + +vapi_error_e call_sw_interface_set_flags(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_sw_interface_set_flags_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + + + /** * @brief Callback to be called by any config change of "/ietf-interfaces:interfaces/interface/enabled" leaf. */ static int -ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *xpath, sr_notif_event_t event, void *private_ctx) +ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, + uint32_t request_id, void *private_data) { char *if_name = NULL; sr_change_iter_t *iter = NULL; @@ -151,15 +177,14 @@ ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *xpath, s int rc = SR_ERR_OK, op_rc = SR_ERR_OK; /* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, SR_EV_ABORT */ - if (SR_EV_APPLY == event) { + if (SR_EV_DONE == event) { return SR_ERR_OK; } - SRP_LOG_DBG("'%s' modified, event=%d", xpath, event); /* get changes iterator */ rc = sr_get_changes_iter(session, xpath, &iter); if (SR_ERR_OK != rc) { - SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc)); + SRP_LOG_ERRMSG("Unable to retrieve change iterator"); return rc; } @@ -167,7 +192,7 @@ ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *xpath, s while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && (SR_ERR_OK == (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { - SRP_LOG_DBG("A change detected in '%s', op=%d", new_val ? new_val->xpath : old_val->xpath, op); + SRP_LOG_DBGMSG("A change detected"); if_name = sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, "interface", "name", &xpath_ctx); switch (op) { case SR_OP_CREATED: @@ -201,19 +226,17 @@ interface_ipv46_config_add_remove(const char *if_name, uint8_t *addr, uint8_t pr uint32_t if_index = ~0; int rc = 0; - SRP_LOG_DBG("%s IP config on interface '%s'.", add ? "Adding" : "Removing", if_name); - /* get interface index */ rc = ietf_interface_name2index(if_name, &if_index); if (0 != rc) { - SRP_LOG_ERR("Invalid interface name: %s", if_name); + SRP_LOG_ERRMSG("Invalid interface name"); return SR_ERR_INVAL_ARG; } /* add del addr */ rc = ietf_interface_add_del_addr(if_index, (uint8_t)add, (uint8_t)is_ipv6, 0, prefix, addr); if (0 != rc) { - SRP_LOG_ERR("Error by processing of the sw_interface_set_flags request, rc=%d", rc); + SRP_LOG_ERRMSG("Error by processing of the sw_interface_set_flags request"); return SR_ERR_OPERATION_FAILED; } else { return SR_ERR_OK; @@ -333,17 +356,12 @@ i32 ietf_interface_add_del_addr( u32 sw_if_index, u8 is_add, u8 is_ipv6, u8 del_ msg->payload.del_all = del_all; msg->payload.address_length = address_length; memcpy(msg->payload.address, address, VPP_IP6_ADDRESS_LEN); - vapi_msg_sw_interface_add_del_address_hton (msg); - - vapi_send (g_vapi_ctx_instance, msg); - - vapi_msg_sw_interface_add_del_address_reply *resp; - HICN_VPP_VAPI_RECV; + if(vapi_sw_interface_add_del_address(g_vapi_ctx_instance,msg,call_sw_interface_add_del_address,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); + return SR_ERR_OPERATION_FAILED; + } - vapi_msg_sw_interface_add_del_address_reply_hton(resp); - ret = resp->payload.retval; - vapi_msg_free (g_vapi_ctx_instance, resp); return ret; } @@ -353,17 +371,13 @@ i32 ietf_setInterfaceFlags(u32 sw_if_index, u8 admin_up_down) vapi_msg_sw_interface_set_flags *msg = vapi_alloc_sw_interface_set_flags(g_vapi_ctx_instance); msg->payload.sw_if_index = sw_if_index; msg->payload.admin_up_down = admin_up_down; - vapi_msg_sw_interface_set_flags_hton (msg); - - vapi_send (g_vapi_ctx_instance, msg); - vapi_msg_sw_interface_set_flags_reply *resp; + if(vapi_sw_interface_set_flags(g_vapi_ctx_instance,msg,call_sw_interface_set_flags,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); + return SR_ERR_OPERATION_FAILED; + } - HICN_VPP_VAPI_RECV; - vapi_msg_sw_interface_set_flags_reply_ntoh(resp); - ret = resp->payload.retval; - vapi_msg_free (g_vapi_ctx_instance, resp); return ret; } @@ -381,7 +395,7 @@ interface_ipv46_config_modify(sr_session_ctx_t *session, const char *if_name, uint8_t prefix = 0; int rc = SR_ERR_OK; - SRP_LOG_DBG("Updating IP config on interface '%s'.", if_name); + SRP_LOG_DBGMSG("Updating IP config on interface"); /* get old config to be deleted */ if (SR_UINT8_T == old_val->type) { @@ -398,7 +412,7 @@ interface_ipv46_config_modify(sr_session_ctx_t *session, const char *if_name, /* delete old IP config */ rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, false /* remove */); if (SR_ERR_OK != rc) { - SRP_LOG_ERR("Unable to remove old IP address config, rc=%d", rc); + SRP_LOG_ERRMSG("Unable to remove old IP address config"); return rc; } @@ -412,7 +426,7 @@ interface_ipv46_config_modify(sr_session_ctx_t *session, const char *if_name, /* set new IP config */ rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, true /* add */); if (SR_ERR_OK != rc) { - SRP_LOG_ERR("Unable to remove old IP address config, rc=%d", rc); + SRP_LOG_ERRMSG("Unable to remove old IP address config"); return rc; } @@ -424,7 +438,8 @@ interface_ipv46_config_modify(sr_session_ctx_t *session, const char *if_name, * or "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address". */ static int -ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *xpath, sr_notif_event_t event, void *private_ctx) +ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, + uint32_t request_id, void *private_data) { sr_change_iter_t *iter = NULL; sr_change_oper_t op = SR_OP_CREATED; @@ -438,10 +453,9 @@ ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *xp int rc = SR_ERR_OK, op_rc = SR_ERR_OK; /* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, SR_EV_ABORT */ - if (SR_EV_APPLY == event) { + if (SR_EV_DONE == event) { return SR_ERR_OK; } - SRP_LOG_DBG("'%s' modified, event=%d", xpath, event); /* check whether we are handling ipv4 or ipv6 config */ node_name = sr_xpath_node_idx((char*)xpath, 2, &xpath_ctx); @@ -453,7 +467,7 @@ ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *xp /* get changes iterator */ rc = sr_get_changes_iter(session, xpath, &iter); if (SR_ERR_OK != rc) { - SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc)); + // SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc)); return rc; } @@ -461,7 +475,6 @@ ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *xp while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && (SR_ERR_OK == (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { - SRP_LOG_DBG("A change detected in '%s', op=%d", new_val ? new_val->xpath : old_val->xpath, op); if_name = strdup(sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, "interface", "name", &xpath_ctx)); sr_xpath_recover(&xpath_ctx); @@ -529,10 +542,9 @@ ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *xp * Does not provide any functionality, needed just to cover not supported config leaves. */ static int -ietf_interface_change_cb(sr_session_ctx_t *session, const char *xpath, sr_notif_event_t event, void *private_ctx) +ietf_interface_change_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, + uint32_t request_id, void *private_data) { - SRP_LOG_DBG("'%s' modified, event=%d", xpath, event); - return SR_ERR_OK; } @@ -541,41 +553,41 @@ int ietf_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription){ int rc = SR_ERR_OK; - SRP_LOG_DBG_MSG("Subscriging ietf."); + SRP_LOG_DBGMSG("Subscriging ietf."); // - rc = sr_subtree_change_subscribe(session, "/ietf-interfaces:interfaces/interface", ietf_interface_change_cb, + rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface", ietf_interface_change_cb, NULL, - 0, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_EV_ENABLED, subscription); + 0, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /ietf-interfaces:interfaces/interface\n"); + SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface\n"); goto error; } - rc = sr_subtree_change_subscribe(session, "/ietf-interfaces:interfaces/interface/enabled", ietf_interface_enable_disable_cb, + rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface/enabled", ietf_interface_enable_disable_cb, NULL, - 100, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_EV_ENABLED, subscription); + 100, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /ietf-interfaces:interfaces/interface/enabled\n"); + SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface/enabled\n"); goto error; } - rc = sr_subtree_change_subscribe(session, "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address", ietf_interface_ipv46_address_change_cb, + rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address", ietf_interface_ipv46_address_change_cb, NULL, - 99, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_EV_ENABLED, subscription); + 99, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address\n"); + SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address\n"); goto error; } - rc = sr_subtree_change_subscribe(session, "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address", ietf_interface_ipv46_address_change_cb, + rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address", ietf_interface_ipv46_address_change_cb, NULL, - 98, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_EV_ENABLED, subscription); + 98, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address\n"); + SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address\n"); goto error; } @@ -588,10 +600,10 @@ int ietf_subscribe_events(sr_session_ctx_t *session, }*/ - SRP_LOG_INF_MSG("ietf initialized successfully."); + SRP_LOG_INFMSG("ietf initialized successfully."); return SR_ERR_OK; error: - SRP_LOG_ERR_MSG("Error by initialization of the ietf."); + SRP_LOG_ERRMSG("Error by initialization of the ietf."); return rc; } diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c index bb8c5e828..305512af3 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c @@ -27,7 +27,6 @@ #include <sched.h> /* Hicn headers */ -#include <vapi/hicn.api.vapi.h> #include <hicn/util/ip_address.h> #include "../hicn_plugin.h" #include "../hicn_vpp_comm.h" @@ -46,9 +45,9 @@ volatile hicn_strategies_t * hicn_strategies =NULL; volatile hicn_route_t * hicn_route = NULL; volatile hicn_face_ip_params_t * hicn_face_ip_params = NULL; volatile hicn_faces_t * hicn_faces = NULL; -//volatile hicn_face_stat_t * hicn_face_stat=NULL; -struct hicn_faces_s * current = NULL; -//volatile hicn_state_face_t * hicn_state_face=NULL; +volatile hicn_routes_t * hicn_routes = NULL; +struct hicn_faces_s * fcurrent = NULL; +struct hicn_routes_s * rcurrent = NULL; static int init_buffer(void){ @@ -67,13 +66,17 @@ static int init_buffer(void){ hicn_faces = memalign(MEM_ALIGN, sizeof(hicn_faces_t) ); hicn_faces->next=memalign(MEM_ALIGN, sizeof(struct hicn_faces_s)); - current=hicn_faces->next; + fcurrent=hicn_faces->next; + + + hicn_routes = memalign(MEM_ALIGN, sizeof(hicn_routes_t) ); + hicn_routes->next=memalign(MEM_ALIGN, sizeof(struct hicn_routes_s)); + rcurrent=hicn_routes->next; -// hicn_state_face = memalign(MEM_ALIGN, sizeof(hicn_state_face_t) ); -// memset((hicn_state_face_t *) hicn_state_face, 0, sizeof(hicn_state_face_t)); int retval=-1; - ARG_CHECK6(retval, hicn_state, hicn_strategy, hicn_strategies, hicn_route, current, hicn_faces); + ARG_CHECK7(retval, hicn_state, hicn_strategy, hicn_strategies, hicn_route, fcurrent, hicn_faces, hicn_routes); + hicn_routes->nroute=0; hicn_faces->nface=0; retval=0; @@ -83,145 +86,403 @@ static int init_buffer(void){ static int init_face_pool(struct hicn_faces_s * head){ - ARG_CHECK(HICN_EINVAL, head); for(int i=0; i<MAX_FACE_POOL; i++){ head->next=memalign(MEM_ALIGN, sizeof(struct hicn_faces_s)); head=head->next; - SRP_LOG_DBG_MSG("Allocated\n"); } + SRP_LOG_DBGMSG("Face memory pool allocated\n"); head->next=NULL; - return HICN_OK; + return 0; + +} + + +static int init_route_pool(struct hicn_routes_s * head){ + + for(int i=0; i<MAX_ROUTE_POOL; i++){ + head->next=memalign(MEM_ALIGN, sizeof(struct hicn_routes_s)); + head=head->next; + } + SRP_LOG_DBGMSG("Route memory pool allocated\n"); + head->next=NULL; + return 0; + +} + +/* VAPI CALLBACKS */ + +vapi_error_e call_hicn_api_strategy_get(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_node_params_set_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + +vapi_error_e call_hicn_api_strategies_get(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_strategies_get_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; } -static inline void state_cache(vapi_msg_hicn_api_node_stats_get_reply * resp){ - hicn_state->pkts_processed = resp->payload.pkts_processed; - hicn_state->pkts_interest_count = resp->payload.pkts_interest_count; - hicn_state->pkts_data_count = resp->payload.pkts_data_count; - hicn_state->pkts_from_cache_count = resp->payload.pkts_from_cache_count; - hicn_state->pkts_no_pit_count = resp->payload.pkts_no_pit_count; - hicn_state->pit_expired_count = resp->payload.pit_expired_count; - hicn_state->cs_expired_count = resp->payload.cs_expired_count; - hicn_state->cs_lru_count = resp->payload.cs_lru_count; - hicn_state->pkts_drop_no_buf = resp->payload.pkts_drop_no_buf; - hicn_state->interests_aggregated = resp->payload.interests_aggregated; - hicn_state->interests_retx = resp->payload.interests_retx; - hicn_state->pit_entries_count = resp->payload.pit_entries_count; - hicn_state->cs_entries_count = resp->payload.cs_entries_count; - hicn_state->cs_entries_ntw_count = resp->payload.cs_entries_ntw_count; - SRP_LOG_DBG_MSG("state cached"); +vapi_error_e call_hicn_api_route_get_hton(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_strategies_get_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; } -static inline void state_update(sr_val_t * vals ){ +vapi_error_e call_hicn_api_route_nhops_add(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_route_nhops_add_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + +vapi_error_e call_hicn_api_route_del(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_route_del_reply *reply){ + +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + +vapi_error_e call_hicn_api_face_ip_params_get(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_face_ip_params_get_reply *reply){ +if(!reply->retval){ + if (callback_ctx!=NULL){ + struct hicn_faces_s * tmp; + tmp = (struct hicn_faces_s *) callback_ctx; + tmp->face.intfc = reply->swif; + } + return VAPI_OK; + }else + return VAPI_EUSER; +} + + +vapi_error_e call_hicn_api_punting_add(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_punting_add_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + + +vapi_error_e call_hicn_api_route_nhop_del(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_route_nhop_del_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + + +vapi_error_e call_hicn_api_punting_del(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_punting_del_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + + +vapi_error_e call_hicn_api_face_ip_del(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_face_ip_del_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + + +vapi_error_e call_hicn_api_face_ip_add(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_face_ip_add_reply *reply){ +if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; + +} + +vapi_error_e call_vapi_hicn_api_node_stats_get(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_node_stats_get_reply *reply){ + + +if(!reply->retval){ + hicn_state->pkts_processed = reply->pkts_processed; + hicn_state->pkts_interest_count = reply->pkts_interest_count; + hicn_state->pkts_data_count = reply->pkts_data_count; + hicn_state->pkts_from_cache_count = reply->pkts_from_cache_count; + hicn_state->pkts_no_pit_count = reply->pkts_no_pit_count; + hicn_state->pit_expired_count = reply->pit_expired_count; + hicn_state->cs_expired_count = reply->cs_expired_count; + hicn_state->cs_lru_count = reply->cs_lru_count; + hicn_state->pkts_drop_no_buf = reply->pkts_drop_no_buf; + hicn_state->interests_aggregated = reply->interests_aggregated; + hicn_state->interests_retx = reply->interests_retx; + hicn_state->pit_entries_count = reply->pit_entries_count; + hicn_state->cs_entries_count = reply->cs_entries_count; + hicn_state->cs_entries_ntw_count = reply->cs_entries_ntw_count; + return VAPI_OK; + }else + return VAPI_EUSER; +} + +vapi_error_e call_hicn_api_node_params_set(struct vapi_ctx_s *ctx, + void *callback_ctx, + vapi_error_e rv, + bool is_last, + vapi_payload_hicn_api_node_params_set_reply *reply){ + if(!reply->retval){ + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + }else + return VAPI_EUSER; +} + +static inline void state_update(sr_val_t * vals, struct lyd_node **parent, sr_session_ctx_t *session){ + char buf[20]; + //struct ly_ctx *ly_ctx = sr_get_context(sr_session_get_connection(session)); sr_val_set_xpath(&vals[0], "/hicn:hicn-state/states/pkts_processed"); vals[0].type = SR_UINT64_T; vals[0].data.uint64_val = hicn_state->pkts_processed; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pkts_processed); + * parent = lyd_new_path(NULL, sr_get_context(sr_session_get_connection(session)), vals[0].xpath, buf, 0, 0); sr_val_set_xpath(&vals[1], "/hicn:hicn-state/states/pkts_interest_count"); vals[1].type = SR_UINT64_T; vals[1].data.uint64_val = hicn_state->pkts_interest_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pkts_interest_count ); + lyd_new_path(*parent, NULL, vals[1].xpath, buf, 0, 0); sr_val_set_xpath(&vals[2], "/hicn:hicn-state/states/pkts_data_count"); vals[2].type = SR_UINT64_T; vals[2].data.uint64_val = hicn_state->pkts_data_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pkts_data_count ); + lyd_new_path(*parent, NULL, vals[2].xpath, buf, 0, 0); sr_val_set_xpath(&vals[3], "/hicn:hicn-state/states/pkts_from_cache_count"); vals[3].type = SR_UINT64_T; vals[3].data.uint64_val = hicn_state->pkts_from_cache_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pkts_from_cache_count ); + lyd_new_path(*parent, NULL, vals[3].xpath, buf, 0, 0); sr_val_set_xpath(&vals[4], "/hicn:hicn-state/states/pkts_no_pit_count"); vals[4].type = SR_UINT64_T; vals[4].data.uint64_val = hicn_state->pkts_no_pit_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pkts_no_pit_count ); + lyd_new_path(*parent, NULL, vals[4].xpath, buf, 0, 0); sr_val_set_xpath(&vals[5], "/hicn:hicn-state/states/pit_expired_count"); vals[5].type = SR_UINT64_T; vals[5].data.uint64_val = hicn_state->pit_expired_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pit_expired_count ); + lyd_new_path(*parent, NULL, vals[5].xpath, buf, 0, 0); sr_val_set_xpath(&vals[6], "/hicn:hicn-state/states/cs_expired_count"); vals[6].type = SR_UINT64_T; vals[6].data.uint64_val = hicn_state->cs_expired_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->cs_expired_count ); + lyd_new_path(*parent, NULL, vals[6].xpath, buf, 0, 0); sr_val_set_xpath(&vals[7], "/hicn:hicn-state/states/cs_lru_count"); vals[7].type = SR_UINT64_T; vals[7].data.uint64_val = hicn_state->cs_lru_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->cs_lru_count ); + lyd_new_path(*parent, NULL, vals[7].xpath, buf, 0, 0); sr_val_set_xpath(&vals[8], "/hicn:hicn-state/states/pkts_drop_no_buf"); vals[8].type = SR_UINT64_T; vals[8].data.uint64_val = hicn_state->pkts_drop_no_buf; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pkts_drop_no_buf ); + lyd_new_path(*parent, NULL, vals[8].xpath, buf, 0, 0); sr_val_set_xpath(&vals[9], "/hicn:hicn-state/states/interests_aggregated"); vals[9].type = SR_UINT64_T; vals[9].data.uint64_val = hicn_state->interests_aggregated; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->interests_aggregated ); + lyd_new_path(*parent, NULL, vals[9].xpath, buf, 0, 0); sr_val_set_xpath(&vals[10], "/hicn:hicn-state/states/interests_retx"); vals[10].type = SR_UINT64_T; vals[10].data.uint64_val = hicn_state->interests_retx; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->interests_retx ); + lyd_new_path(*parent, NULL, vals[10].xpath, buf, 0, 0); sr_val_set_xpath(&vals[11], "/hicn:hicn-state/states/interests_hash_collision"); vals[11].type = SR_UINT64_T; vals[11].data.uint64_val = hicn_state->interests_hash_collision; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->interests_hash_collision ); + lyd_new_path(*parent, NULL, vals[11].xpath, buf, 0, 0); sr_val_set_xpath(&vals[12], "/hicn:hicn-state/states/pit_entries_count"); vals[12].type = SR_UINT64_T; vals[12].data.uint64_val = hicn_state->pit_entries_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->pit_entries_count ); + lyd_new_path(*parent, NULL, vals[12].xpath, buf, 0, 0); sr_val_set_xpath(&vals[13], "/hicn:hicn-state/states/cs_entries_count"); vals[13].type = SR_UINT64_T; vals[13].data.uint64_val = hicn_state->cs_entries_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->cs_entries_count ); + lyd_new_path(*parent, NULL, vals[13].xpath, buf, 0, 0); sr_val_set_xpath(&vals[14], "/hicn:hicn-state/states/cs_entries_ntw_count"); vals[14].type = SR_UINT64_T; vals[14].data.uint64_val = hicn_state->cs_entries_ntw_count; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, hicn_state->cs_entries_ntw_count ); + lyd_new_path(*parent, NULL, vals[14].xpath, buf, 0, 0); + } -static inline void strategies_update(sr_val_t * vals ){ - sr_val_set_xpath(&vals[0], "/hicn:hicn-state/strategies/n_strategies"); - vals[0].type = SR_UINT8_T; - vals[0].data.uint8_val = hicn_strategies->n_strategies; +static inline int routes_update(sr_val_t * vals, uint32_t nleaves, struct lyd_node **parent, sr_session_ctx_t *session){ - sr_val_set_xpath(&vals[1], "/hicn:hicn-state/strategies/strategy_id"); - vals[1].type = SR_UINT32_T; - vals[1].data.uint32_val = hicn_strategies->strategy_id[0]; -} + struct hicn_routes_s * temp = hicn_routes->next; + char buf[20]; + int route =0; + for(int count=0; count<nleaves; count++){ + + sr_val_build_xpath(&vals[route], "%s[routeid='%d']/prefix", "/hicn:hicn-state/routes/route", + temp->route.route_id); + vals[route].type = SR_STRING_T; + + memset(buf, 0x00, 20); + if (temp->route.prefix.address.af==ADDRESS_IP4){ + struct sockaddr_in sa; + memcpy(&sa.sin_addr.s_addr,temp->route.prefix.address.un.ip4,INET_ADDRSTRLEN); + inet_ntop(AF_INET, &(sa.sin_addr), buf, INET_ADDRSTRLEN); + vals[route].data.string_val = buf; + }else{ + struct sockaddr_in6 sa; + memcpy(&sa.sin6_addr,temp->route.prefix.address.un.ip6,INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, &(sa.sin6_addr), buf, INET6_ADDRSTRLEN); + vals[route].data.string_val = buf; + } + + + lyd_new_path(*parent, NULL, vals[route].xpath, buf, 0, 0); + + + route++; + + sr_val_build_xpath(&vals[route], "%s[routeid='%d']/strategy_id", "/hicn:hicn-state/routes/route", + temp->route.route_id); + vals[route].type = SR_UINT32_T; + vals[route].data.uint32_val = temp->route.strategy_id; + memset(buf, 0x00, 20); + sprintf( buf, "%d", temp->route.strategy_id); + lyd_new_path(*parent, NULL, vals[route].xpath, buf, 0, 0); + + route++; -static inline void route_update(sr_val_t * vals ){ - sr_val_set_xpath(&vals[0], "/hicn:hicn-state/routes/faceids"); - vals[0].type = SR_UINT16_T; - vals[0].data.uint32_val = hicn_route->faceids[0]; + temp=temp->next; + +} - sr_val_set_xpath(&vals[1], "/hicn:hicn-state/routes/strategy_id"); - vals[1].type = SR_UINT32_T; - vals[1].data.uint32_val = hicn_route->strategy_id; + SRP_LOG_DBGMSG("Routes state updated \n"); + return SR_ERR_OK; } -static inline int faces_update(sr_val_t * vals, uint32_t nleaves){ +static inline int faces_update(sr_val_t * vals, uint32_t nleaves, struct lyd_node **parent, sr_session_ctx_t *session){ struct hicn_faces_s * temp = hicn_faces->next; + char buf[20]; int face =0; + for(int count=0; count<nleaves; count++){ // This part must be removed once the faceid is provided by the dump msg vapi_msg_hicn_api_face_ip_params_get *msg; - vapi_msg_hicn_api_face_ip_params_get_reply *resp; msg = vapi_alloc_hicn_api_face_ip_params_get(g_vapi_ctx_instance); + + msg->payload.faceid = temp->face.faceid; - vapi_msg_hicn_api_face_ip_params_get_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_face_ip_params_get_reply_ntoh(resp); - if(!resp->payload.retval){ - SRP_LOG_DBG("faceid(%d)-->intfc(%d)", temp->face.faceid, resp->payload.swif); - temp->face.intfc= resp->payload.swif; - } + if(vapi_hicn_api_face_ip_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_params_get, (void *)temp)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); + return SR_ERR_OPERATION_FAILED; + } sr_val_build_xpath(&vals[face], "%s[faceid='%d']/intfc", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT32_T; vals[face].data.uint32_val = temp->face.intfc; + memset(buf, 0x00, 20); + sprintf( buf,"%u", temp->face.intfc); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); face++; @@ -231,484 +492,204 @@ static inline int faces_update(sr_val_t * vals, uint32_t nleaves){ temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.irx_packets; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.irx_packets); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); face++; + + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/irx_bytes", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.irx_bytes; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.irx_bytes); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); face++; + + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/itx_packets", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.itx_packets; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.itx_packets); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); face++; + + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/itx_bytes", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.itx_bytes; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.itx_bytes); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); + face++; + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/drx_packets", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.drx_packets; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.drx_packets); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); + face++; + + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/drx_bytes", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; - vals[face].data.uint64_val = temp->face.drx_bytes; + vals[face].data.uint64_val = temp->face.drx_bytes; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.drx_packets); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); + face++; + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/dtx_packets", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.dtx_packets; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.dtx_packets); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); face++; + sr_val_build_xpath(&vals[face], "%s[faceid='%d']/dtx_bytes", "/hicn:hicn-state/faces/face", temp->face.faceid); vals[face].type = SR_UINT64_T; vals[face].data.uint64_val = temp->face.dtx_bytes; + memset(buf, 0x00, 20); + sprintf( buf, "%" PRIu64, temp->face.dtx_bytes); + lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0); - face++; - SRP_LOG_DBG(" **********************face is: %d-%d-%d ****************\n",temp->face.dtx_bytes,temp->face.drx_bytes,temp->face.faceid); - - printf("%" PRId64 "\n", temp->face.drx_bytes); + face++; temp=temp->next; } - SRP_LOG_DBG_MSG("Faces state updated \n"); + SRP_LOG_DBGMSG("Faces state updated \n"); return SR_ERR_OK; } -static int hicn_state_states_cb(const char *xpath, sr_val_t **values, - size_t *values_cnt, uint64_t request_id, - const char *original_xpath, void *private_ctx) { +static int hicn_state_states_cb(sr_session_ctx_t *session, const char *module_name, const char *path, const char *request_xpath, + uint32_t request_id, struct lyd_node **parent, void *private_data) { sr_val_t *vals; int rc; enum locks_name state; state=lstate; - SRP_LOG_DBG("Requesting state data for '%s'", xpath); + SRP_LOG_DBGMSG("Requesting state data"); - if (!sr_xpath_node_name_eq(xpath, "states")) { - *values = NULL; - *values_cnt = 0; - return SR_ERR_OK; - } rc = sr_new_values(NSTATE_LEAVES, &vals); if (SR_ERR_OK != rc) { return rc; } - SRP_LOG_DBG("Requesting state data for '%s'", xpath); + tlock(state); - state_update(vals); + state_update(vals,parent,session); tunlock(state); - *values = vals; - *values_cnt = NSTATE_LEAVES; return SR_ERR_OK; } -static int hicn_state_strategies_cb(const char *xpath, sr_val_t **values, - size_t *values_cnt, uint64_t request_id, - const char *original_xpath, void *private_ctx) { - sr_val_t *vals; - int rc; - enum locks_name strategies; - strategies=lstrategies; - - - - if (! sr_xpath_node_name_eq(xpath, "strategies")) { - SRP_LOG_DBG_MSG("Requesting state is not for strategies"); - *values = NULL; - *values_cnt = 0; - return SR_ERR_OK; - } - - - rc = sr_new_values(NSTRATEGIES_LEAVES, &vals); - if (SR_ERR_OK != rc) { - return rc; - } - - SRP_LOG_DBG("Requesting state data for '%s'", xpath); - tlock(strategies); - strategies_update(vals); - tunlock(strategies); - - *values = vals; - *values_cnt = NSTRATEGIES_LEAVES; - return SR_ERR_OK; - - } - - -static int hicn_state_route_cb(const char *xpath, sr_val_t **values, - size_t *values_cnt, uint64_t request_id, - const char *original_xpath, void *private_ctx) { +static int hicn_state_route_cb(sr_session_ctx_t *session, const char *module_name, const char *path, const char *request_xpath, + uint32_t request_id, struct lyd_node **parent, void *private_data) { sr_val_t *vals; int rc; enum locks_name route; route=lroute; + uint32_t NROUTE_NODES = hicn_routes->nroute * ROUTES_CHILDREN; - if (! sr_xpath_node_name_eq(xpath, "routes")) { - SRP_LOG_DBG_MSG("Requesting state is not for routes"); - *values = NULL; - *values_cnt = 0; - return SR_ERR_OK; - } - rc = sr_new_values(NROUTE_LEAVES, &vals); + rc = sr_new_values(NROUTE_NODES, &vals); if (SR_ERR_OK != rc) { return rc; } - SRP_LOG_DBG("Requesting state data for '%s'", xpath); tlock(route); - route_update(vals); + routes_update(vals,NROUTE_NODES/ROUTES_CHILDREN, parent, session); tunlock(route); - *values = vals; - *values_cnt = NROUTE_LEAVES; + return SR_ERR_OK; } - static int hicn_state_faces_cb(const char *xpath, sr_val_t **values, - size_t *values_cnt, uint64_t request_id, - const char *original_xpath, void *private_ctx) { + static int hicn_state_faces_cb(sr_session_ctx_t *session, const char *module_name, const char *path, const char *request_xpath, + uint32_t request_id, struct lyd_node **parent, void *private_data) { + + sr_val_t *vals; int rc; enum locks_name faces; faces=lfaces; uint32_t NFACES_NODES = hicn_faces->nface * FACES_CHILDREN; - if (! sr_xpath_node_name_eq(xpath, "faces")) { - SRP_LOG_DBG_MSG("Requesting state is not for faces"); - *values = NULL; - *values_cnt = 0; - return SR_ERR_OK; - } - - // We should only consider the number of leaves not the head of list(faceid) rc = sr_new_values(NFACES_NODES, &vals); if (SR_ERR_OK != rc) { return rc; } - SRP_LOG_DBG("Requesting state data for '%s'", xpath); - tlock(faces); - SRP_LOG_DBG("**********NFACES-LEAVES '%d' *********", NFACES_NODES); - faces_update(vals, NFACES_NODES/FACES_CHILDREN); + faces_update(vals, NFACES_NODES/FACES_CHILDREN, parent, session); tunlock(faces); - //hicn_faces->nface=0; - *values = vals; - *values_cnt = NFACES_NODES; - return SR_ERR_OK; - } - -/** -* @brief Callback to be called by any config change of "/hicn:/" leaf. -*/ -static int hicn_node_params_set_cb(sr_session_ctx_t *session, const char *xpath, - sr_notif_event_t event, void *private_ctx) { - sr_change_iter_t *iter = NULL; - sr_change_oper_t op = SR_OP_CREATED; - sr_val_t *old_val = NULL; - sr_val_t *new_val = NULL; - sr_xpath_ctx_t xpath_ctx = { - 0, - }; - int rc = SR_ERR_OK, op_rc = SR_ERR_OK; - // no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, - // SR_EV_ABORT - if (SR_EV_APPLY == event) { - return SR_ERR_OK; - } - - // get changes iterator - rc = sr_get_changes_iter(session, xpath, &iter); - if (SR_ERR_OK != rc) { - SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc)); - return rc; - } - - vapi_msg_hicn_api_node_params_set *msg; - vapi_msg_hicn_api_node_params_set_reply *resp = NULL; - msg = vapi_alloc_hicn_api_node_params_set(g_vapi_ctx_instance); - SRP_LOG_DBG("H:recv msgid [%d]\n", msg->header._vl_msg_id); \ - - // iterate over all changes - while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && - (SR_ERR_OK == - (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { - if (!strcmp(new_val->xpath, "/hicn:hicn-conf/params/enable_disable")) { - SRP_LOG_DBG("A change detected in '%s', op=%d", - new_val ? new_val->xpath : old_val->xpath, - new_val->data.bool_val); - msg->payload.enable_disable = new_val->data.bool_val; - } else if (!strcmp(new_val->xpath, "/hicn:hicn-conf/params/pit_max_size")) { - SRP_LOG_DBG("A change detected in '%s', op=%d", - new_val ? new_val->xpath : old_val->xpath, - new_val->data.int32_val); - msg->payload.pit_max_size = new_val->data.int32_val; - } else if (!strcmp(new_val->xpath, "/hicn:hicn-conf/params/cs_max_size")) { - SRP_LOG_DBG("A change detected in '%s', op=%d", - new_val ? new_val->xpath : old_val->xpath, - new_val->data.int32_val); - msg->payload.cs_max_size = new_val->data.int32_val; - } else if (!strcmp(new_val->xpath, - "/hicn:hicn-conf/params/cs_reserved_app")) { - SRP_LOG_DBG("A change detected in '%s', op=%d", - new_val ? new_val->xpath : old_val->xpath, - new_val->data.int32_val); - msg->payload.cs_reserved_app = new_val->data.int32_val; - } else if (!strcmp(new_val->xpath, - "/hicn:hicn-conf/params/pit_max_lifetime_sec")) { - SRP_LOG_DBG("A change detected in '%s', op=%d", - new_val ? new_val->xpath : old_val->xpath, - new_val->data.decimal64_val); - msg->payload.pit_max_lifetime_sec = new_val->data.decimal64_val; - } - - switch (op) { - case SR_OP_CREATED: - case SR_OP_MODIFIED: - op_rc = SR_ERR_OK; // OK - break; - case SR_OP_DELETED: - op_rc = SR_ERR_OPERATION_FAILED; // ERROR - break; - default: - break; - } - sr_xpath_recover(&xpath_ctx); - if (SR_ERR_INVAL_ARG == op_rc) { - sr_set_error(session, "You are not allowed to change the schema.", - new_val ? new_val->xpath : old_val->xpath); - } - sr_free_val(old_val); - sr_free_val(new_val); - } - - vapi_msg_hicn_api_node_params_set_hton(msg); - - params_send(msg, resp); - - vapi_msg_hicn_api_node_params_set_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - sr_free_change_iter(iter); - return SR_ERR_OK; - } - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; -} - -/** -* @brief API to get hicn param in vpp. -*/ -static int hicn_node_params_get_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { - - SRP_LOG_DBG_MSG("hicn node parameter received successfully"); - vapi_msg_hicn_api_node_params_get *msg; - vapi_msg_hicn_api_node_params_get_reply *resp; - - msg = vapi_alloc_hicn_api_node_params_get(g_vapi_ctx_instance); - - - - - vapi_msg_hicn_api_node_params_get_hton(msg); - params_send(msg, resp); - vapi_msg_hicn_api_node_params_get_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; -} - -/** -* @brief API to get hicn stat in vpp. -*/ -static int hicn_node_stat_get_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { - - SRP_LOG_DBG_MSG("hicn status received successfully"); - vapi_msg_hicn_api_node_stats_get *msg; - vapi_msg_hicn_api_node_stats_get_reply *resp; - enum locks_name state; - state=lstate; - msg = vapi_alloc_hicn_api_node_stats_get(g_vapi_ctx_instance); - - vapi_msg_hicn_api_node_stats_get_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_node_stats_get_reply_ntoh(resp); - - if(resp->payload.retval){ - SRP_LOG_DBG_MSG("Error updating state"); - return SR_ERR_OPERATION_FAILED; - } - tlock(state); - - state_cache(resp); - - tunlock(state); return SR_ERR_OK; -} - -/** -* @brief API to get hicn strategy in vpp. -*/ -static int hicn_strategy_get_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { - - SRP_LOG_DBG_MSG("hicn strategy receive successfully"); - vapi_msg_hicn_api_strategy_get *msg; - vapi_msg_hicn_api_strategy_get_reply *resp; - - msg = vapi_alloc_hicn_api_strategy_get(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); - - msg->payload.strategy_id = input[0].data.uint32_val; - - vapi_msg_hicn_api_strategy_get_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_strategy_get_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; } - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; -} - /** * @brief API to get hicn strategies in vpp. */ -static int hicn_strategies_get_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { - - SRP_LOG_DBG_MSG("hicn strategies received successfully"); - vapi_msg_hicn_api_strategies_get *msg; - vapi_msg_hicn_api_strategies_get_reply *resp; - - msg = vapi_alloc_hicn_api_strategies_get(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); +static int hicn_strategies_get_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { +SRP_LOG_DBGMSG("hicn strategies received successfully"); +vapi_msg_hicn_api_strategies_get *msg; - vapi_msg_hicn_api_strategies_get_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_strategies_get_reply_ntoh(resp); +msg = vapi_alloc_hicn_api_strategies_get(g_vapi_ctx_instance); - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; +if (vapi_hicn_api_strategies_get(g_vapi_ctx_instance, msg, call_hicn_api_strategies_get, NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); + return SR_ERR_OPERATION_FAILED; } +return SR_ERR_OK; -/** -* @brief API to get hicn route in vpp. -*/ -static int hicn_route_get_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { - - SRP_LOG_DBG_MSG("hicn route receive successfully"); - vapi_msg_hicn_api_route_get *msg; - vapi_msg_hicn_api_route_get_reply *resp; - - msg = vapi_alloc_hicn_api_route_get(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); - - - if(strcmp(input[0].data.string_val,"-1")){ - - struct sockaddr_in sa; - inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); - unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&msg->payload.prefix.address.un.ip4[0],tmp,B32); - msg->payload.prefix.address.af = ADDRESS_IP4; - - }else if(strcmp(input[1].data.string_val,"-1")){ - - void *dst = malloc(sizeof(struct in6_addr)); - inet_pton(AF_INET6, input[1].data.string_val, dst); - unsigned char * tmp = (unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.prefix.address.un.ip6[0],tmp,B128); - msg->payload.prefix.address.af = ADDRESS_IP6; - - }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); - return SR_ERR_OPERATION_FAILED; - } - - - - msg->payload.prefix.len = input[2].data.uint8_val; - - vapi_msg_hicn_api_route_get_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_route_get_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; } /** * @brief API to add hicn route nhops in vpp. */ -static int hicn_route_nhops_add_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_route_nhops_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn route nhops add received successfully"); + SRP_LOG_DBGMSG("hicn route nhops add received successfully"); vapi_msg_hicn_api_route_nhops_add *msg; - vapi_msg_hicn_api_route_nhops_add_reply *resp; msg = vapi_alloc_hicn_api_route_nhops_add(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); if(strcmp(input[0].data.string_val,"-1")){ @@ -727,7 +708,7 @@ static int hicn_route_nhops_add_cb(const char *xpath, const sr_val_t *input, msg->payload.prefix.address.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } @@ -741,29 +722,22 @@ static int hicn_route_nhops_add_cb(const char *xpath, const sr_val_t *input, msg->payload.face_ids[6] = input[9].data.uint32_val; msg->payload.n_faces = input[10].data.uint8_val; - vapi_msg_hicn_api_route_nhops_add_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_route_nhops_add_reply_ntoh(resp); - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - SRP_LOG_DBG_MSG("Operation failed"); +if(vapi_hicn_api_route_nhops_add(g_vapi_ctx_instance,msg,call_hicn_api_route_nhops_add,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } +return SR_ERR_OK; +} /** * @brief API to del hicn route in vpp. */ -static int hicn_route_del_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_route_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn route del received successfully"); + SRP_LOG_DBGMSG("hicn route del received successfully"); vapi_msg_hicn_api_route_del *msg; - vapi_msg_hicn_api_route_del_reply *resp; msg = vapi_alloc_hicn_api_route_del(g_vapi_ctx_instance); @@ -785,72 +759,54 @@ static int hicn_route_del_cb(const char *xpath, const sr_val_t *input, msg->payload.prefix.address.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } msg->payload.prefix.len = input[2].data.uint8_val; - vapi_msg_hicn_api_route_del_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_route_del_reply_ntoh(resp); - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - SRP_LOG_DBG_MSG("Operation failed"); +if(vapi_hicn_api_route_del(g_vapi_ctx_instance,msg,call_hicn_api_route_del,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } +return SR_ERR_OK; +} /** * @brief API to get face ip params in hicn in vpp. */ -static int hicn_face_ip_params_get_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_face_ip_params_get_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn face ip params get received successfully"); + SRP_LOG_DBGMSG("hicn face ip params get received successfully"); vapi_msg_hicn_api_face_ip_params_get *msg; - vapi_msg_hicn_api_face_ip_params_get_reply *resp; msg = vapi_alloc_hicn_api_face_ip_params_get(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); msg->payload.faceid = input[0].data.uint32_val; - vapi_msg_hicn_api_face_ip_params_get_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_face_ip_params_get_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG("faceid(%d)-->intfc(%d)",input[0].data.uint32_val, resp->payload.swif); - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - SRP_LOG_DBG_MSG("Operation failed"); +if (vapi_hicn_api_face_ip_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_params_get,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; - +} +return SR_ERR_OK; } /** * @brief API to get face ip params in hicn in vpp. */ -static int hicn_punting_add_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_punting_add_ip_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn punting add received successfully"); + SRP_LOG_DBGMSG("hicn punting add received successfully"); // allocate memory msg and resp vapi_msg_hicn_api_punting_add *msg; - vapi_msg_hicn_api_punting_add_reply *resp; msg = vapi_alloc_hicn_api_punting_add(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); + msg->payload.type=IP_PUNT; if(strcmp(input[0].data.string_val,"-1")){ @@ -858,8 +814,8 @@ static int hicn_punting_add_cb(const char *xpath, const sr_val_t *input, // store this IP address in sa: inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&msg->payload.prefix.address.un.ip4[0],tmp,B32); - msg->payload.prefix.address.af = ADDRESS_IP4; + memcpy(&msg->payload.rule.ip.prefix.address.un.ip4[0],tmp,B32); + msg->payload.rule.ip.prefix.address.af = ADDRESS_IP4; }else if(strcmp(input[1].data.string_val,"-1")){ @@ -867,45 +823,36 @@ static int hicn_punting_add_cb(const char *xpath, const sr_val_t *input, void *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, input[1].data.string_val, dst); unsigned char * tmp =(unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.prefix.address.un.ip6[0],tmp,B128); - msg->payload.prefix.address.af = ADDRESS_IP6; + memcpy(&msg->payload.rule.ip.prefix.address.un.ip6[0],tmp,B128); + msg->payload.rule.ip.prefix.address.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } - msg->payload.prefix.len = input[2].data.uint8_val; - msg->payload.swif = input[3].data.uint32_val; - + msg->payload.rule.ip.prefix.len = input[2].data.uint8_val; + msg->payload.rule.ip.swif = input[3].data.uint32_val; - vapi_msg_hicn_api_punting_add_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_punting_add_reply_ntoh(resp); - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - SRP_LOG_DBG_MSG("Operation failed"); +if (vapi_hicn_api_punting_add(g_vapi_ctx_instance, msg, call_hicn_api_punting_add, NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } +return SR_ERR_OK; +} /** * @brief API to del hicn route nhops in vpp. */ -static int hicn_route_nhops_del_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_route_nhops_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn route nhop del received successfully"); - // allocate memory msg and resp + SRP_LOG_DBGMSG("hicn route nhop del received successfully"); + // allocate memory msg vapi_msg_hicn_api_route_nhop_del *msg; - vapi_msg_hicn_api_route_nhop_del_reply *resp; msg = vapi_alloc_hicn_api_route_nhop_del(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); if(strcmp(input[0].data.string_val,"-1")){ @@ -927,7 +874,7 @@ static int hicn_route_nhops_del_cb(const char *xpath, const sr_val_t *input, msg->payload.prefix.address.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } @@ -935,43 +882,35 @@ static int hicn_route_nhops_del_cb(const char *xpath, const sr_val_t *input, msg->payload.prefix.len = input[2].data.uint8_val; msg->payload.faceid = input[3].data.uint32_val; - vapi_msg_hicn_api_route_nhop_del_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_route_nhop_del_reply_ntoh(resp); - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - - - SRP_LOG_DBG_MSG("Operation failed"); +if (vapi_hicn_api_route_nhop_del(g_vapi_ctx_instance, msg, call_hicn_api_route_nhop_del,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } +return SR_ERR_OK; +} /** * @brief API to del hicn punting in vpp. */ -static int hicn_punting_del_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_punting_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn punting del received successfully"); - // allocate memory msg and resp + SRP_LOG_DBGMSG("hicn punting del received successfully"); + // allocate memory msg vapi_msg_hicn_api_punting_del *msg; - vapi_msg_hicn_api_punting_del_reply *resp; msg = vapi_alloc_hicn_api_punting_del(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); + msg->payload.type=IP_PUNT; if(strcmp(input[0].data.string_val,"-1")){ struct sockaddr_in sa; inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&msg->payload.prefix.address.un.ip4[0],tmp,B32); - msg->payload.prefix.address.af = ADDRESS_IP4; + memcpy(&msg->payload.rule.ip.prefix.address.un.ip4[0],tmp,B32); + msg->payload.rule.ip.prefix.address.af = ADDRESS_IP4; }else if(strcmp(input[1].data.string_val,"-1")){ @@ -979,76 +918,60 @@ static int hicn_punting_del_cb(const char *xpath, const sr_val_t *input, void *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, input[1].data.string_val, dst); unsigned char * tmp = (unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.prefix.address.un.ip6[0],tmp,B128); - msg->payload.prefix.address.af = ADDRESS_IP6; + memcpy(&msg->payload.rule.ip.prefix.address.un.ip6[0],tmp,B128); + msg->payload.rule.ip.prefix.address.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } - msg->payload.prefix.len = input[2].data.uint8_val; - msg->payload.swif = input[3].data.uint32_val; + msg->payload.rule.ip.prefix.len = input[2].data.uint8_val; + msg->payload.rule.ip.swif = input[3].data.uint32_val; - vapi_msg_hicn_api_punting_del_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_punting_del_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } +if (vapi_hicn_api_punting_del(g_vapi_ctx_instance, msg, call_hicn_api_punting_del,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); + return SR_ERR_OPERATION_FAILED; +} +return SR_ERR_OK; - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; } /** * @brief API to del hicn face ip in vpp. */ -static int hicn_face_ip_del_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_face_ip_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn face ip del received successfully"); - // allocate memory msg and resp + SRP_LOG_DBGMSG("hicn face ip del received successfully"); + // allocate memory msg vapi_msg_hicn_api_face_ip_del *msg; - vapi_msg_hicn_api_face_ip_del_reply *resp; msg = vapi_alloc_hicn_api_face_ip_del(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); msg->payload.faceid = input[0].data.uint32_val; - vapi_msg_hicn_api_face_ip_del_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_face_ip_del_reply_ntoh(resp); - - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } - SRP_LOG_DBG_MSG("Operation failed"); +if(vapi_hicn_api_face_ip_del(g_vapi_ctx_instance,msg, call_hicn_api_face_ip_del,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } +return SR_ERR_OK; +} /** * @brief API to del hicn face ip in vpp. */ -static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { +static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - SRP_LOG_DBG_MSG("hicn face ip add received successfully"); + SRP_LOG_DBGMSG("hicn face ip add received successfully"); vapi_msg_hicn_api_face_ip_add *msg; - vapi_msg_hicn_api_face_ip_add_reply *resp; msg = vapi_alloc_hicn_api_face_ip_add(g_vapi_ctx_instance); - SRP_LOG_DBG("msg id:%d",msg->header._vl_msg_id); if(strcmp(input[0].data.string_val,"-1")){ struct sockaddr_in sa; inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); @@ -1065,7 +988,7 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, msg->payload.face.local_addr.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } @@ -1087,27 +1010,57 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, msg->payload.face.remote_addr.af = ADDRESS_IP6; }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); + SRP_LOG_DBGMSG("Invalid local IP address"); return SR_ERR_OPERATION_FAILED; } - msg->payload.swif = input[4].data.uint32_val; // This is the idx number of interface + msg->payload.face.swif = input[4].data.uint32_val; // This is the idx number of interface - vapi_msg_hicn_api_face_ip_add_hton(msg); - params_send(msg,resp); - vapi_msg_hicn_api_face_ip_add_reply_ntoh(resp); +if(vapi_hicn_api_face_ip_add(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_add,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG("Operation failed"); + return SR_ERR_OPERATION_FAILED; +} +return SR_ERR_OK; +} - if(!resp->payload.retval){ - SRP_LOG_DBG_MSG("Successfully done"); - return SR_ERR_OK; - } + vapi_error_e +hicn_api_routes_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, + vapi_error_e rv, bool is_last, + vapi_payload_hicn_api_routes_details *reply) +{ + + static int counter = 0; + + tlock(lroute); + if (reply!=NULL){ + rcurrent->route.route_id = counter; + rcurrent->route.prefix = reply->prefix; + rcurrent->route.nfaces = reply->nfaces; + rcurrent->route.strategy_id = reply->strategy_id; + for(int cnt=0;cnt<rcurrent->route.nfaces;cnt++) + rcurrent->route.faceids[cnt] = rcurrent->route.faceids[cnt]; + + counter++; + rcurrent = rcurrent->next; + + SRP_LOG_DBG("nfaces %d", reply->nfaces); + SRP_LOG_DBG("strategy_id %d", reply->strategy_id); + + }else + { + SRP_LOG_DBGMSG("---------Routes------- \n"); + hicn_routes->nroute=counter; + counter=0; + rcurrent=hicn_routes->next; + } + tunlock(lroute); + return SR_ERR_OK; - SRP_LOG_DBG_MSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; } + static vapi_error_e hicn_api_face_stats_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, @@ -1115,69 +1068,38 @@ hicn_api_face_stats_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, { static int counter = 0; -/* - UNUSED(ctx); UNUSED(rv); UNUSED(is_last); - //struct elt **stackp; - ARG_CHECK2(VAPI_EINVAL, callback_ctx, reply); - stackp = (struct elt**) callback_ctx; - SRP_LOG_DBG("reply: %d:%d:%d", reply->faceid,reply->dtx_packets,reply->irx_packets); - - vapi_payload_hicn_api_face_stats_details *passed; - ARG_CHECK2(VAPI_EINVAL, callback_ctx, reply); - passed = (vapi_payload_hicn_api_face_stats_details *) callback_ctx; - *passed = *reply; - SRP_LOG_DBG("reply %d", reply->faceid);*/ tlock(lfaces); if (reply!=NULL){ - current->face.faceid = reply->faceid; - current->face.intfc = 1; - current->face.irx_packets = reply->irx_packets; - current->face.irx_bytes = reply->irx_bytes; - current->face.itx_packets = reply->itx_packets; - current->face.itx_bytes = reply->itx_bytes; - current->face.drx_packets = reply->drx_packets; - current->face.drx_bytes = reply->drx_bytes; - current->face.dtx_packets = reply->dtx_packets; - current->face.dtx_bytes = reply->dtx_bytes; - //hicn_faces->nface++; // Increment the number of faces + fcurrent->face.faceid = reply->faceid; + fcurrent->face.intfc = 1; + fcurrent->face.irx_packets = reply->irx_packets; + fcurrent->face.irx_bytes = reply->irx_bytes; + fcurrent->face.itx_packets = reply->itx_packets; + fcurrent->face.itx_bytes = reply->itx_bytes; + fcurrent->face.drx_packets = reply->drx_packets; + fcurrent->face.drx_bytes = reply->drx_bytes; + fcurrent->face.dtx_packets = reply->dtx_packets; + fcurrent->face.dtx_bytes = reply->dtx_bytes; counter++; - current = current->next; - //current->next = memalign(MEM_ALIGN, sizeof(hicn_faces_t)); - SRP_LOG_DBG_MSG("---------Face------- \n"); - SRP_LOG_DBG("reply %d", reply->faceid); - SRP_LOG_DBG("reply %d", reply->drx_bytes); - SRP_LOG_DBG("reply %d", reply->dtx_bytes); + fcurrent = fcurrent->next; + SRP_LOG_DBG("faceid %d", reply->faceid); + SRP_LOG_DBG("drxB %d", reply->drx_bytes); + SRP_LOG_DBG("dtxB %d", reply->dtx_bytes); }else { + SRP_LOG_DBGMSG("---------Faces------- \n"); hicn_faces->nface=counter; counter=0; - current=hicn_faces->next; + fcurrent=hicn_faces->next; } tunlock(lfaces); return SR_ERR_OK; } /** -* @brief API to del hicn face state details in vpp. -*/ - -static int hicn_face_stats_details_cb(const char *xpath, const sr_val_t *input, - const size_t input_cnt, sr_val_t **output, - size_t *output_cnt, void *private_ctx) { - //struct elt* stack=NULL ; - SRP_LOG_DBG_MSG("hicn face state details received successfully"); - vapi_payload_hicn_api_face_stats_details resp={0}; - vapi_msg_hicn_api_face_stats_dump *msg; - msg = vapi_alloc_hicn_api_face_stats_dump(g_vapi_ctx_instance); - vapi_hicn_api_face_stats_dump(g_vapi_ctx_instance, msg, hicn_api_face_stats_dump_cb, &resp); - return SR_ERR_OK; -} - - -/** * @brief Thread to update the state */ static void *state_thread(void *arg) { @@ -1191,46 +1113,42 @@ static void *state_thread(void *arg) { // pin the thread to a core if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset)) { - SRP_LOG_DBG_MSG("Thread pining failed\n"); + SRP_LOG_DBGMSG("Thread pining failed\n"); exit(1); } vapi_msg_hicn_api_node_stats_get *msg=NULL; - vapi_msg_hicn_api_node_stats_get_reply *resp=NULL; enum locks_name state; state=lstate; while(true){ + // dump faces + vapi_msg_hicn_api_face_stats_dump *fmsg; + fmsg = vapi_alloc_hicn_api_face_stats_dump(g_vapi_ctx_instance); + vapi_hicn_api_face_stats_dump(g_vapi_ctx_instance, fmsg, hicn_api_face_stats_dump_cb, fcurrent); + + // dump routes + vapi_msg_hicn_api_routes_dump *rmsg; + rmsg = vapi_alloc_hicn_api_routes_dump(g_vapi_ctx_instance); + vapi_hicn_api_routes_dump(g_vapi_ctx_instance, rmsg, hicn_api_routes_dump_cb, rcurrent); + + + msg = vapi_alloc_hicn_api_node_stats_get(g_vapi_ctx_instance); - vapi_msg_hicn_api_node_stats_get_hton(msg); - if (VAPI_OK != vapi_send(g_vapi_ctx_instance, msg)) { - SRP_LOG_DBG_MSG("Sending msg to VPP failed"); - // Here I should think about a recovery method - return NULL; - } - HICN_VPP_VAPI_RECV; + tlock(state); - vapi_msg_hicn_api_node_stats_get_reply_ntoh(resp); + if(vapi_hicn_api_node_stats_get(g_vapi_ctx_instance,msg,call_vapi_hicn_api_node_stats_get,NULL)!=VAPI_OK){ + SRP_LOG_DBGMSG(" State operation failed"); + } - if(resp->payload.retval){ - SRP_LOG_DBG_MSG("Error updating state"); - // Here I should think about a recovery method - return NULL; - } - //vapi_payload_hicn_api_face_stats_details resp_dump={0}; - vapi_msg_hicn_api_face_stats_dump *msg; - msg = vapi_alloc_hicn_api_face_stats_dump(g_vapi_ctx_instance); - vapi_hicn_api_face_stats_dump(g_vapi_ctx_instance, msg, hicn_api_face_stats_dump_cb, current); + tunlock(state); + sleep(1); - tlock(state); - state_cache(resp); - SRP_LOG_DBG_MSG("state updated"); - tunlock(state); - sleep(1); + SRP_LOG_DBGMSG("state cached"); } return NULL; @@ -1242,15 +1160,16 @@ static void *state_thread(void *arg) { int hicn_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription) { int rc = SR_ERR_OK; - SRP_LOG_DBG_MSG("Subscriging hicn."); + SRP_LOG_DBGMSG("Subscriging hicn."); + // Create state thread observation pthread_t state_tid; rc = pthread_create((pthread_t *)&state_tid, NULL, state_thread, NULL); if (rc != 0) { - SRP_LOG_DBG_MSG("Error making hicn state thread"); + SRP_LOG_DBGMSG("Error making hicn state thread"); return SR_ERR_OPERATION_FAILED; } - SRP_LOG_DBG_MSG("State thread created successfully."); + SRP_LOG_DBGMSG("State thread created successfully."); //Initializing the locks for (int i=0; i<NLOCKS; i++) @@ -1259,191 +1178,148 @@ int hicn_subscribe_events(sr_session_ctx_t *session, //Initializing the buffer rc=init_buffer(); if(rc!= SR_ERR_OK){ - SRP_LOG_DBG_MSG("Problem in initializing the buffers\n"); + SRP_LOG_DBGMSG("Problem in initializing the buffers\n"); goto error; } - SRP_LOG_DBG_MSG("buffer initialized successfully."); - + SRP_LOG_DBGMSG("buffer initialized successfully."); - rc=init_face_pool(current); - if(rc!= SR_ERR_OK){ - SRP_LOG_DBG_MSG("Problem in initializing the face pool\n"); + rc=init_face_pool(fcurrent); + if(rc){ + SRP_LOG_DBGMSG("Problem in initializing the pools\n"); goto error; } - SRP_LOG_DBG_MSG("face pool created successfully."); - - - // node state subscriptions - - rc = sr_rpc_subscribe(session, "/hicn:node-params-get", hicn_node_params_get_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription node-params-get\n"); - goto error; + rc=init_route_pool(rcurrent); + if(rc){ + SRP_LOG_DBGMSG("Problem in initializing the pools\n"); + goto error; } - // node state subscriptions + SRP_LOG_DBGMSG("pools created successfully."); - rc = sr_rpc_subscribe(session, "/hicn:node-stat-get", hicn_node_stat_get_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription stat-get\n"); - goto error; - } - // strategies subscriptions +/* + // subscripe for edit-config + rc = sr_module_change_subscribe( + session, "hicn","/hicn:hicn-conf", hicn_node_params_set_cb, g_vapi_ctx_instance, + 0, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); + if (SR_ERR_OK != rc) { + //SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-conf\n"); + perror("Problem in subscription /hicn:hicn-conf\n"); + goto error; + } +*/ - rc = sr_rpc_subscribe(session, "/hicn:strategy-get", hicn_strategy_get_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription strategy-get\n"); - goto error; - } + // strategies subscriptions rc = sr_rpc_subscribe(session, "/hicn:strategies-get", - hicn_strategies_get_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + hicn_strategies_get_cb, session, 98,SR_SUBSCR_CTX_REUSE, subscription); if (rc!= SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription strategies-get\n"); + SRP_LOG_DBGMSG("Problem in subscription strategies-get\n"); goto error; } - // route subscriptions - - rc = sr_rpc_subscribe(session, "/hicn:route-get", hicn_route_get_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription route-get\n"); - goto error; - } - - rc = sr_rpc_subscribe(session, "/hicn:route-del", hicn_route_del_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription route-del\n"); - goto error; - } - - // route nhops subscriptions rc = sr_rpc_subscribe(session, "/hicn:route-nhops-add", - hicn_route_nhops_add_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + hicn_route_nhops_add_cb, session, 95,SR_SUBSCR_CTX_REUSE, subscription); if (rc!= SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription route-nhops-add\n"); + SRP_LOG_DBGMSG("Problem in subscription route-nhops-add\n"); goto error; } rc = sr_rpc_subscribe(session, "/hicn:route-nhops-del", - hicn_route_nhops_del_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + hicn_route_nhops_del_cb, session, 94,SR_SUBSCR_CTX_REUSE, subscription); if (rc!= SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription route-nhops-del\n"); + SRP_LOG_DBGMSG("Problem in subscription route-nhops-del\n"); goto error; } + rc = sr_rpc_subscribe(session, "/hicn:route-del", hicn_route_del_cb, + session, 96,SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG("Problem in subscription route-del\n"); + goto error; + } // face ip subscriptions rc = sr_rpc_subscribe(session, "/hicn:face-ip-params-get", - hicn_face_ip_params_get_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + hicn_face_ip_params_get_cb, session, 93,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription face-ip-params-get\n"); + SRP_LOG_DBGMSG("Problem in subscription face-ip-params-get\n"); goto error; } rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); + session, 92,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription face-ip-add\n"); + SRP_LOG_DBGMSG("Problem in subscription face-ip-add\n"); goto error; } rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); + session, 91,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription face-ip-del\n"); + SRP_LOG_DBGMSG("Problem in subscription face-ip-del\n"); goto error; } // punting subscriptions - rc = sr_rpc_subscribe(session, "/hicn:punting-add", hicn_punting_add_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); + rc = sr_rpc_subscribe(session, "/hicn:punting-add-ip", hicn_punting_add_ip_cb, + session, 90,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription punting-add\n"); + SRP_LOG_DBGMSG("Problem in subscription punting-add\n"); goto error; } rc = sr_rpc_subscribe(session, "/hicn:punting-del", hicn_punting_del_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); + session, 89,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription punting-del\n"); - goto error; - } - - - rc = sr_rpc_subscribe(session, "/hicn:face-stats-details", hicn_face_stats_details_cb, - session, SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription face-stats-details\n"); - goto error; - } - - // subscripe for edit-config - rc = sr_subtree_change_subscribe( - session, "/hicn:hicn-conf", hicn_node_params_set_cb, g_vapi_ctx_instance, - 0, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_EV_ENABLED, subscription); - if (SR_ERR_OK != rc) { - SRP_LOG_DBG_MSG("Problem in subscription /hicn:hicn-conf\n"); + SRP_LOG_DBGMSG("Problem in subscription punting-del\n"); goto error; } // subscribe as hicn state data provider - rc = sr_dp_get_items_subscribe(session, "/hicn:hicn-state/states", - hicn_state_states_cb, NULL, SR_SUBSCR_CTX_REUSE, - subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /hicn:hicn-state/states\n"); - goto error; - } - rc = sr_dp_get_items_subscribe(session, "/hicn:hicn-state/strategies", - hicn_state_strategies_cb, NULL, SR_SUBSCR_CTX_REUSE, + rc = sr_oper_get_items_subscribe(session, "hicn","/hicn:hicn-state/states", + hicn_state_states_cb, NULL, SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /hicn:hicn-state/strategies\n"); + SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-state/states\n"); goto error; } - rc = sr_dp_get_items_subscribe(session, "/hicn:hicn-state/routes", + rc = sr_oper_get_items_subscribe(session, "hicn","/hicn:hicn-state/routes", hicn_state_route_cb, NULL, SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /hicn:hicn-state/routes\n"); + SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-state/routes\n"); goto error; } - rc = sr_dp_get_items_subscribe(session, "/hicn:hicn-state/faces", + rc = sr_oper_get_items_subscribe(session, "hicn","/hicn:hicn-state/faces", hicn_state_faces_cb, NULL, SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /hicn:hicn-state/faces\n"); + SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-state/faces\n"); goto error; } - SRP_LOG_INF_MSG("hicn plugin initialized successfully."); + SRP_LOG_DBGMSG("hicn plugin initialized successfully.\n"); return SR_ERR_OK; error: - SRP_LOG_ERR_MSG("Error by initialization of the hicn plugin."); + SRP_LOG_ERRMSG("Error by initialization of the hicn plugin."); sr_plugin_cleanup_cb(session, &g_vapi_ctx_instance); return rc; } diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h index 02317d5d6..9c5d9df9a 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h @@ -17,6 +17,7 @@ #define __IETF_HICN_H__ #include "../hicn_vpp_comm.h" +#include <vapi/hicn.api.vapi.h> #define MEM_ALIGN 4096 #define B32 4 @@ -35,19 +36,11 @@ enum locks_name {lstate, lstrategy, lstrategies, lroute, lfaces}; #define NSTATE_LEAVES 15 #define NSTRATEGY_LEAVES 1 #define NSTRATEGIES_LEAVES 2 -#define NROUTE_LEAVES 2 #define MAX_FACE_POOL 100 -#define FACES_CHILDREN 9 /*this is the number of children of each leave*/ +#define MAX_ROUTE_POOL 100 - -#define params_send( msg , resp ) \ -{ \ - if (VAPI_OK != vapi_send(g_vapi_ctx_instance, (msg))) { \ - SRP_LOG_DBG_MSG("Sending msg to VPP failed"); \ - return SR_ERR_OPERATION_FAILED; \ - } \ - HICN_VPP_VAPI_RECV; \ -}; +#define FACES_CHILDREN 9 /*this is the number of children of each leave in face except the key*/ +#define ROUTES_CHILDREN 2 /*this is the number of children of each leave in face except the key*/ typedef struct __attribute__ ((__packed__)) { @@ -110,6 +103,14 @@ typedef struct __attribute__ ((__packed__)) { uint64_t dtx_bytes; } hicn_face_inf_t; +typedef struct __attribute__ ((__packed__)) { + u32 route_id; + vapi_type_prefix prefix; + u32 faceids[5]; + u8 nfaces; + u32 strategy_id; +} hicn_route_inf_t; + struct hicn_faces_s{ hicn_face_inf_t face; @@ -121,34 +122,16 @@ typedef struct __attribute__ ((__packed__)) { struct hicn_faces_s * next; } hicn_faces_t; -// typedef struct __attribute__ ((__packed__)) { -// int32_t retval; -// uint32_t faceid; -// uint64_t irx_packets; -// uint64_t irx_bytes; -// uint64_t itx_packets; -// uint64_t itx_bytes; -// uint64_t drx_packets; -// uint64_t drx_bytes; -// uint64_t dtx_packets; -// uint64_t dtx_bytes; -// } hicn_face_stat_t; - -// typedef struct __attribute__ ((__packed__)) { - -// int32_t retval; -// uint32_t faceid; -// uint64_t irx_packets; -// uint64_t irx_bytes; -// uint64_t itx_packets; -// uint64_t itx_bytes; -// uint64_t drx_packets; -// uint64_t drx_bytes; -// uint64_t dtx_packets; -// uint64_t dtx_bytes; - -// } hicn_state_face_t; +struct hicn_routes_s{ + hicn_route_inf_t route; + struct hicn_routes_s * next; +}; + +typedef struct __attribute__ ((__packed__)) { + uint32_t nroute; + struct hicn_routes_s * next; +} hicn_routes_t; int hicn_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription); diff --git a/ctrl/sysrepo-plugins/yang/hicn/hicn.yang b/ctrl/sysrepo-plugins/yang/hicn/hicn.yang index 484fec6f0..d53cd8aa0 100644 --- a/ctrl/sysrepo-plugins/yang/hicn/hicn.yang +++ b/ctrl/sysrepo-plugins/yang/hicn/hicn.yang @@ -2,12 +2,12 @@ module hicn { namespace "urn:sysrepo:hicn"; prefix hcn; -revision 2019-05-7 { +/* new data types and grouping definition to forward the remote request toward hicn controler--to-->hicn */ + +revision 2019-10-29{ description "Initial revision."; } -/* new data types and grouping definition to forward the remote request toward hicn controler--to-->hicn */ - typedef float { type decimal64 { fraction-digits 2; @@ -41,20 +41,8 @@ leaf cs_reserved_app { default -1; } -leaf pit_dflt_lifetime_sec { - description "Default PIT entry lifetime, otherwise -1 to assign default value."; - type float; - default -1; - } - leaf pit_max_lifetime_sec { - description "Upper bound on PIT entry lifetime, otherwise -1 to assign default value."; - type float; - default -1; - } - -leaf pit_min_lifetime_sec { - description "Upper bound on PIT entry lifetime, otherwise -1 to assign default value ."; + description "Default PIT entry lifetime, otherwise -1 to assign default value."; type float; default -1; } @@ -209,7 +197,7 @@ leaf len { } } -grouping punting_add { +grouping punting_add_ip { leaf ip4 { description "ip4 to be added to the FIB."; @@ -405,16 +393,22 @@ grouping strategy-reply { grouping route-reply { - leaf faceids { - description "Enable / disable ICN forwarder in VPP."; - type uint32; - - } + list route{ + key routeid; + leaf routeid { + description "the unique key for each item."; + type uint32; + } + leaf prefix { + description "IP address."; + type string; - leaf strategy_id { + } + leaf strategy_id { description "compile-time plugin features."; type uint32; - } + } + } } grouping strategies-reply { @@ -429,37 +423,25 @@ grouping strategies-reply { } -/* Hicn configuration */ - -container hicn-conf { - description "config data container for the hicn-vpp."; - container params{ - uses params; - } -} - /* Hicn operational data */ container hicn-state { + config false; description "operational data container for the hicn."; - + container faces{ + uses face-stats-reply; + } container states{ uses states-reply; } container routes{ uses route-reply; } - container strategies{ - uses strategies-reply; - } - container faces{ - uses face-stats-reply; - } - } + /* RPC Definitions */ @@ -479,17 +461,6 @@ rpc node-stat-get { description "Operation to get hicn status in vpp."; } - -rpc strategy-get { - description "Operation to get hicn strategy."; - input { - leaf strategy_id { - description "Upper bound on PIT entry lifetime, otherwise -1 to assign default value ."; - type uint32; - } - } -} - rpc strategies-get { description "Operation to get hicn strategies."; } @@ -549,23 +520,19 @@ rpc face-ip-del { } } -rpc punting-add { +rpc punting-add-ip { description "Operation to add hicn punt."; input { - uses punting_add; + uses punting_add_ip; } } rpc punting-del { description "Operation to del hicn punt."; input { - uses punting_add; /* It uses the same payload as the add*/ + uses punting_add_ip; /* It uses the same payload as the add*/ } } -rpc face-stats-details { - description "Operation to take stat per face."; -} - } |