diff options
author | Alberto Compagno <acompagn+fdio@cisco.com> | 2019-08-22 09:48:32 +0200 |
---|---|---|
committer | Alberto Compagno <acompagn+fdio@cisco.com> | 2019-11-04 18:10:09 +0100 |
commit | ccf813e13eba7b5c71cc3090582f50f25ba7b721 (patch) | |
tree | 2316f2d00a2c6fa8dc5c4195386cf9554cc49726 | |
parent | 6b7f4c3f9d9d26a5aa71be8f5976956aff387e8f (diff) |
[HICN-262] Fix binary api to prevent byteswapping of ip addresses in vapi
Change-Id: If3f9a7db1e1310fdc08d1003b28e5e1d4006b61e
Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com>
39 files changed, 533 insertions, 526 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index e9f1e07de..9f4e753bb 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -46,6 +46,7 @@ endif() set(SUFFIX "") if (${LIBTRANSPORT_LIBRARIES} MATCHES ".*-memif.*") set(SUFFIX "-memif") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-unresolved-symbols=ignore-in-shared-libs") endif() set(HICN_APPS "${HICN_APPS}${SUFFIX}") diff --git a/cmake/Modules/FindVpp.cmake b/cmake/Modules/FindVpp.cmake index 7d8d16d13..d29f37339 100644 --- a/cmake/Modules/FindVpp.cmake +++ b/cmake/Modules/FindVpp.cmake @@ -46,6 +46,13 @@ find_library(VPP_LIBRARY_INFRA DOC "Find the Vpp infra library" ) +find_library(VPP_LIBRARY_VNET + NAMES vnet + HINTS ${VPP_SEARCH_PATH_LIST} + PATH_SUFFIXES lib lib64 + DOC "Find the Vpp vnet library" +) + find_library(VPP_LIBRARY_VATPLUGIN NAMES vatplugin HINTS ${VPP_SEARCH_PATH_LIST} @@ -67,7 +74,7 @@ find_library(VPP_LIBRARY_VPPAPICLIENT DOC "Find the Vpp vlib library" ) -set(VPP_LIBRARIES ${VPP_LIBRARY_MEMORYCLIENT} ${VPP_LIBRARY_SVM} ${VPP_LIBRARY_INFRA} ${VPP_LIBRARY_VATPLUGIN} ${VPP_LIBRARY_VLIB}) +set(VPP_LIBRARIES ${VPP_LIBRARY_MEMORYCLIENT} ${VPP_LIBRARY_SVM} ${VPP_LIBRARY_INFRA} ${VPP_LIBRARY_VATPLUGIN} ${VPP_LIBRARY_VLIB} ${VPP_LIBRARY_VNET}) set(VPP_INCLUDE_DIRS ${VPP_INCLUDE_DIR} ${VPP_INCLUDE_DIR}/vpp_plugins) include(FindPackageHandleStandardArgs) diff --git a/ctrl/sysrepo-plugins/CMakeLists.txt b/ctrl/sysrepo-plugins/CMakeLists.txt index 91726161f..cd7c0a16c 100644 --- a/ctrl/sysrepo-plugins/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/CMakeLists.txt @@ -33,8 +33,12 @@ set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") set(CMAKE_C_FLAGS_DEBUG "-g -O0") # add subdirectories -add_subdirectory(hicn-plugin) -add_subdirectory(hicn-light) +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) include(Packager) make_packages() 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 b40293705..4bf266ff5 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c @@ -663,16 +663,16 @@ static int hicn_route_get_cb(const char *xpath, const sr_val_t *input, 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[0],tmp,B32); - + 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[0],tmp,B64); - memcpy(&msg->payload.prefix[1],tmp+B64,B64); + 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"); @@ -681,7 +681,7 @@ static int hicn_route_get_cb(const char *xpath, const sr_val_t *input, - msg->payload.len = input[2].data.uint8_val; + msg->payload.prefix.len = input[2].data.uint8_val; vapi_msg_hicn_api_route_get_hton(msg); params_send(msg,resp); @@ -715,23 +715,23 @@ static int hicn_route_nhops_add_cb(const char *xpath, const sr_val_t *input, 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[0],tmp,4); - + 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[0],tmp,B64); - memcpy(&msg->payload.prefix[1],tmp+B64,B64); + 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.len = input[2].data.uint8_val; + msg->payload.prefix.len = input[2].data.uint8_val; msg->payload.face_ids[0] = input[3].data.uint32_val; msg->payload.face_ids[1] = input[4].data.uint32_val; msg->payload.face_ids[2] = input[5].data.uint32_val; @@ -772,7 +772,8 @@ static int hicn_route_del_cb(const char *xpath, const sr_val_t *input, 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[0],tmp,B32); + 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")){ @@ -780,8 +781,8 @@ static int hicn_route_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[0],tmp,B64); - memcpy(&msg->payload.prefix[1],tmp+B64,B64); + 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"); @@ -789,7 +790,7 @@ static int hicn_route_del_cb(const char *xpath, const sr_val_t *input, } - msg->payload.len = input[2].data.uint8_val; + msg->payload.prefix.len = input[2].data.uint8_val; vapi_msg_hicn_api_route_del_hton(msg); params_send(msg,resp); @@ -857,7 +858,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[0],tmp,B32); + 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")){ @@ -865,15 +867,15 @@ 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[0],tmp,B64); - memcpy(&msg->payload.prefix[1],tmp+B64,B64); + 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.len = input[2].data.uint8_val; + msg->payload.prefix.len = input[2].data.uint8_val; msg->payload.swif = input[3].data.uint32_val; @@ -912,7 +914,8 @@ static int hicn_route_nhops_del_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[0],tmp,B32); + 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")){ @@ -920,8 +923,8 @@ static int hicn_route_nhops_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[0],tmp,B64); - memcpy(&msg->payload.prefix[1],tmp+B64,B64); + 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"); @@ -929,7 +932,7 @@ static int hicn_route_nhops_del_cb(const char *xpath, const sr_val_t *input, } - msg->payload.len = input[2].data.uint8_val; + 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); @@ -967,7 +970,8 @@ static int hicn_punting_del_cb(const char *xpath, const sr_val_t *input, 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[0],tmp,B32); + 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")){ @@ -975,8 +979,8 @@ 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[0],tmp,B64); - memcpy(&msg->payload.prefix[1],tmp+B64,B64); + 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"); @@ -984,7 +988,7 @@ static int hicn_punting_del_cb(const char *xpath, const sr_val_t *input, } - msg->payload.len = input[2].data.uint8_val; + msg->payload.prefix.len = input[2].data.uint8_val; msg->payload.swif = input[3].data.uint32_val; vapi_msg_hicn_api_punting_del_hton(msg); @@ -1049,15 +1053,16 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, 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.local_addr[0],tmp,B32); + memcpy(&msg->payload.local_addr.un.ip4[0],tmp,B32); + msg->payload.local_addr.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.local_addr[0],tmp,B64); - memcpy(&msg->payload.local_addr[1],tmp+B64,B64); + memcpy(&msg->payload.local_addr.un.ip6[0],tmp,B128); + msg->payload.local_addr.af = ADDRESS_IP6; }else{ SRP_LOG_DBG_MSG("Invalid local IP address"); @@ -1069,7 +1074,8 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, struct sockaddr_in sa; inet_pton(AF_INET, input[2].data.string_val, &(sa.sin_addr)); unsigned char * tmp = (unsigned char *)&sa.sin_addr.s_addr; - memcpy(&msg->payload.remote_addr[0],tmp,B32); + memcpy(&msg->payload.remote_addr.un.ip4[0],tmp,B32); + msg->payload.remote_addr.af = ADDRESS_IP4; }else if(strcmp(input[3].data.string_val,"-1")){ @@ -1077,8 +1083,8 @@ static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, void *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, input[3].data.string_val, dst); unsigned char * tmp =(unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.remote_addr[0],tmp,B64); - memcpy(&msg->payload.remote_addr[1],tmp+B64,B64); + memcpy(&msg->payload.remote_addr.un.ip6[0],tmp,B128); + msg->payload.remote_addr.af = ADDRESS_IP6; }else{ SRP_LOG_DBG_MSG("Invalid local IP address"); 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 6cb5d2710..02317d5d6 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h @@ -21,6 +21,7 @@ #define MEM_ALIGN 4096 #define B32 4 #define B64 8 +#define B128 16 // Number of locks is equal to number of nodes in hicn-state // It is a coarse grain approach later can be changed to fine grained diff --git a/hicn-light/src/hicn/socket/ops_linux.c b/hicn-light/src/hicn/socket/ops_linux.c index af41f400f..96636039f 100644 --- a/hicn-light/src/hicn/socket/ops_linux.c +++ b/hicn-light/src/hicn/socket/ops_linux.c @@ -619,7 +619,7 @@ int _nl_set_ip_addr(uint32_t interface_id, ip_prefix_t *prefix) { .payload.ifa_index = interface_id}; /* Set attributes = length/type/value */ - struct rtattr ifa_address = {RTA_LENGTH(ip_address_len(&prefix->address, prefix->family)), + struct rtattr ifa_address = {RTA_LENGTH(ip_address_len(prefix->family)), IFA_ADDRESS}; struct iovec iov[] = { {&msg, sizeof(msg)}, @@ -987,13 +987,13 @@ int _nl_del_lo_route(const ip_prefix_t *prefix) { /* Set attribute = length/type/value */ uint32_t one = 1; - struct rtattr a_dst = {RTA_LENGTH(ip_address_len(&prefix->address, prefix->family)), RTA_DST}; + struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), RTA_DST}; struct rtattr a_ifid_lo = {RTA_LENGTH(sizeof(uint32_t)), RTA_OIF}; struct iovec iov[] = { {&msg, sizeof(msg)}, /* Ip address */ {&a_dst, sizeof(a_dst)}, - {(void *)&prefix->address.buffer, ip_address_len(&prefix->address, prefix->family)}, + {(void *)&prefix->address.buffer, ip_address_len(prefix->family)}, /* Interface id */ {&a_ifid_lo, sizeof(a_ifid_lo)}, {&one, sizeof(one)}}; @@ -1149,7 +1149,7 @@ int _nl_add_neigh_proxy(const ip_prefix_t *prefix, }; /* Message attributes = length/type/value */ - struct rtattr a_dst = {RTA_LENGTH(ip_address_len(&prefix->address, prefix->family)), NDA_DST}; + struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), NDA_DST}; /* Iovec describing the packets */ struct iovec iov[] = { @@ -1226,7 +1226,7 @@ int _nl_add_in_route_table(const ip_prefix_t *prefix, }; /* Message attributes = length/type/value */ - struct rtattr a_dst = {RTA_LENGTH(ip_address_len(&prefix->address, prefix->family)), RTA_DST}; + struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), RTA_DST}; struct rtattr a_oif = {RTA_LENGTH(sizeof(uint32_t)), RTA_OIF}; /* Iovec describing the packets */ @@ -1234,7 +1234,7 @@ int _nl_add_in_route_table(const ip_prefix_t *prefix, {&msg, sizeof(msg)}, /* Destination prefix / ip address */ {&a_dst, sizeof(a_dst)}, - {(void *)&prefix->address.buffer, ip_address_len(&prefix->address, prefix->family)}, + {(void *)&prefix->address.buffer, ip_address_len(prefix->family)}, /* Output interface */ {&a_oif, sizeof(a_oif)}, {(void *)&interface_id, sizeof(uint32_t)}, @@ -1328,7 +1328,7 @@ int _nl_add_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, if (prefix) { /* Message attributes = length/type/value */ - struct rtattr a_src = {RTA_LENGTH(ip_address_len(&prefix->address, prefix->family)), FRA_SRC}; + struct rtattr a_src = {RTA_LENGTH(ip_address_len(prefix->family)), FRA_SRC}; struct rtattr a_prio = {RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY}; /* Iovec describing the packets */ @@ -1336,7 +1336,7 @@ int _nl_add_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, {&msg, sizeof(msg)}, /* Source prefix / prefix */ {&a_src, sizeof(a_src)}, - {(void *)&prefix->address.buffer, ip_address_len(&prefix->address, prefix->family)}, + {(void *)&prefix->address.buffer, ip_address_len(prefix->family)}, /* Priority */ {&a_prio, sizeof(a_prio)}, {(void *)&priority, sizeof(uint32_t)}, @@ -1429,7 +1429,7 @@ int _nl_del_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, /* Message attributes = length/type/value */ if (prefix) { - struct rtattr a_src = {RTA_LENGTH(ip_address_len(&prefix->address, prefix->family)), FRA_SRC}; + struct rtattr a_src = {RTA_LENGTH(ip_address_len(prefix->family)), FRA_SRC}; struct rtattr a_prio = {RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY}; /* Iovec describing the packets */ @@ -1437,7 +1437,7 @@ int _nl_del_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, {&msg, sizeof(msg)}, /* Source prefix / prefix */ {&a_src, sizeof(a_src)}, - {(void *)&prefix->address.buffer, ip_address_len(&prefix->address, prefix->family)}, + {(void *)&prefix->address.buffer, ip_address_len(prefix->family)}, /* Priority */ {&a_prio, sizeof(a_prio)}, {(void *)&priority, sizeof(uint32_t)}, diff --git a/hicn-plugin/CMakeLists.txt b/hicn-plugin/CMakeLists.txt index 8425a5cf3..56c8055ee 100644 --- a/hicn-plugin/CMakeLists.txt +++ b/hicn-plugin/CMakeLists.txt @@ -215,42 +215,51 @@ elseif (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DCLIB_DEBUG -fPIC -fstack-protector-all) endif() -execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/hicn) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hicn) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip) # These files are missing from vpp binary distribution execute_process( COMMAND bash -c - "if [ ! -e ${CMAKE_BINARY_DIR}/vapi_json_parser.py ]; then - curl https://git.fd.io/vpp/plain/src/vpp-api/vapi/vapi_json_parser.py?h=stable/1908 -o ${CMAKE_BINARY_DIR}/vapi_json_parser.py; + "if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py ]; then + curl https://git.fd.io/vpp/plain/src/vpp-api/vapi/vapi_json_parser.py?h=stable/1908 -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py; fi;" ) execute_process( COMMAND bash -c - "if [ ! -e ${CMAKE_BINARY_DIR}/vapi_c_gen.py ]; then - curl https://git.fd.io/vpp/plain/src/vpp-api/vapi/vapi_c_gen.py?h=stable/1908 -o ${CMAKE_BINARY_DIR}/vapi_c_gen.py; + "if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ]; then + curl https://git.fd.io/vpp/plain/src/vpp-api/vapi/vapi_c_gen.py?h=stable/1908 -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py; fi;" ) execute_process( COMMAND bash -c - "if [ ! -e ${CMAKE_BINARY_DIR}/vapi_cpp_gen.py ]; then - curl https://git.fd.io/vpp/plain/src/vpp-api/vapi/vapi_cpp_gen.py?h=stable/1908 -o ${CMAKE_BINARY_DIR}/vapi_cpp_gen.py; + "if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py ]; then + curl https://git.fd.io/vpp/plain/src/vpp-api/vapi/vapi_cpp_gen.py?h=stable/1908 -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py; + fi;" +) + +execute_process( + COMMAND + bash -c + "if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api ]; then + curl https://git.fd.io/vpp/plain/src/vnet/ip/ip_types.api?h=stable/1908 -o ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api; fi;" ) add_custom_command( - COMMAND chmod +x ${CMAKE_BINARY_DIR}/vapi_json_parser.py ${CMAKE_BINARY_DIR}/vapi_c_gen.py ${CMAKE_BINARY_DIR}/vapi_cpp_gen.py + COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h - COMMAND ${VPP_HOME}/bin/vppapigen --input ${CMAKE_CURRENT_SOURCE_DIR}/src/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h + COMMAND ${VPP_HOME}/bin/vppapigen --includedir ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/src/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/hicn.api OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.json COMMAND ${VPP_HOME}/bin/vppapigen JSON --input ${CMAKE_CURRENT_SOURCE_DIR}/src/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.json OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.vapi.h - COMMAND ${CMAKE_BINARY_DIR}/vapi_c_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.json + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.json OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.vapi.hpp - COMMAND ${CMAKE_BINARY_DIR}/vapi_cpp_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.json + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.json ) include_directories(SYSTEM) diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c index bd789acad..c8d8b5bf6 100644 --- a/hicn-plugin/src/cli.c +++ b/hicn-plugin/src/cli.c @@ -21,6 +21,7 @@ #include <vnet/udp/udp.h> // port registration #include <vnet/ip/ip6_packet.h> // ip46_address_t #include <vnet/ip/format.h> +#include <vnet/fib/fib_types.h> #include "hicn.h" #include "infra.h" @@ -416,10 +417,11 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, int rv = HICN_ERROR_NONE; int addpfx = -1; - ip46_address_t prefix; + ip46_address_t address; hicn_face_id_t faceid = HICN_FACE_NULL; u32 strategy_id; u8 plen = 0; + fib_prefix_t prefix; /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; @@ -443,7 +445,7 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } else if (addpfx != -1 && unformat (line_input, "prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &address, IP46_TYPE_ANY, &plen)) {; } else if (addpfx <= 1 && unformat (line_input, "face %u", &faceid)) @@ -458,16 +460,18 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } } + fib_prefix_from_ip46_addr(&address, &prefix); + prefix.fp_len=plen; /* Check parse */ if (addpfx <= 1 - && ((ip46_address_is_zero (&prefix)) || faceid == HICN_FACE_NULL)) + && ((ip46_address_is_zero (&prefix.fp_addr)) || faceid == HICN_FACE_NULL)) { cl_err = clib_error_return (0, "Please specify prefix and a valid faceid..."); goto done; } /* Check parse */ - if ((ip46_address_is_zero (&prefix)) + if ((ip46_address_is_zero (&prefix.fp_addr)) || (addpfx == 2 && hicn_dpo_strategy_id_is_valid (strategy_id))) { cl_err = clib_error_return (0, @@ -476,18 +480,18 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } if (addpfx == 0) { - if (ip46_address_is_zero (&prefix)) + if (ip46_address_is_zero (&prefix.fp_addr)) { cl_err = clib_error_return (0, "Please specify prefix"); goto done; } if (faceid == HICN_FACE_NULL) { - rv = hicn_route_del (&prefix, plen); + rv = hicn_route_del (&prefix); } else { - rv = hicn_route_del_nhop (&prefix, plen, faceid); + rv = hicn_route_del_nhop (&prefix, faceid); } cl_err = (rv == HICN_ERROR_NONE) ? NULL : clib_error_return (0, @@ -497,10 +501,10 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } else if (addpfx == 1) { - rv = hicn_route_add (&faceid, 1, &prefix, plen); + rv = hicn_route_add (&faceid, 1, &prefix); if (rv == HICN_ERROR_ROUTE_ALREADY_EXISTS) { - rv = hicn_route_add_nhops (&faceid, 1, &prefix, plen); + rv = hicn_route_add_nhops (&faceid, 1, &prefix); } cl_err = (rv == HICN_ERROR_NONE) ? NULL : clib_error_return (0, @@ -509,7 +513,7 @@ hicn_cli_fib_set_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } else if (addpfx == 2) { - rv = hicn_route_set_strategy (&prefix, plen, strategy_id); + rv = hicn_route_set_strategy (&prefix, strategy_id); cl_err = (rv == HICN_ERROR_NONE) ? NULL : clib_error_return (0, get_error_string @@ -526,13 +530,14 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, { hicn_mgmt_punting_op_e punting_op = HICN_MGMT_PUNTING_OP_NONE; unsigned int subnet_mask = 0; - ip46_address_t prefix; + ip46_address_t address; u32 sw_if_index = ~0; int ret = 0; vnet_main_t *vnm = NULL; u8 type = HICN_PUNT_IP_TYPE; u32 src_port = 0, dst_port = 0; vnm = vnet_get_main (); + fib_prefix_t prefix; unformat_input_t _line_input, *line_input = &_line_input; if (!unformat_user (main_input, unformat_line_input, line_input)) @@ -555,7 +560,7 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } else if (unformat (line_input, "prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &subnet_mask)) + &address, IP46_TYPE_ANY, &subnet_mask)) {; } else if (unformat (line_input, "type ip")) @@ -584,14 +589,16 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, } } + fib_prefix_from_ip46_addr(&address, &prefix); + prefix.fp_len = subnet_mask; if (punting_op == HICN_MGMT_PUNTING_OP_CREATE - && (ip46_address_is_zero (&prefix) || sw_if_index == ~0)) + && (ip46_address_is_zero (&prefix.fp_addr) || sw_if_index == ~0)) { return (clib_error_return (0, "Please specify valid prefix and interface")); } else if ((punting_op == HICN_MGMT_PUNTING_OP_DELETE) && - ip46_address_is_zero (&prefix)) + ip46_address_is_zero (&prefix.fp_addr)) { return (clib_error_return (0, "Please specify valid prefix and optionally an interface")); @@ -609,7 +616,7 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, { if (src_port != 0 && dst_port != 0) ret = - hicn_punt_interest_data_for_udp (vm, &prefix, subnet_mask, + hicn_punt_interest_data_for_udp (vm, &prefix, sw_if_index, type, clib_host_to_net_u16 (src_port), @@ -623,8 +630,7 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, else { ret = - hicn_punt_interest_data_for_ip (vm, &prefix, subnet_mask, - sw_if_index, type, NO_L2); + hicn_punt_interest_data_for_ip (vm, &prefix, sw_if_index, type, NO_L2); } } break; @@ -632,7 +638,7 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, { if (sw_if_index != ~0) { - ip46_address_is_ip4 (&prefix) ? + ip46_address_is_ip4 (&prefix.fp_addr) ? hicn_punt_enable_disable_vnet_ip4_table_on_intf (vm, sw_if_index, 0) : @@ -640,14 +646,13 @@ hicn_cli_punting_command_fn (vlib_main_t * vm, unformat_input_t * main_input, sw_if_index, 0); } - else if (!(ip46_address_is_zero (&prefix))) + else if (!(ip46_address_is_zero (&prefix.fp_addr))) { - ret = ip46_address_is_ip4 (&prefix) ? - hicn_punt_remove_ip4_address (vm, &(prefix.ip4), subnet_mask, 1, + ret = ip46_address_is_ip4 (&prefix.fp_addr) ? + hicn_punt_remove_ip4_address (vm, &prefix, 1, sw_if_index, 0, NO_L2) : - hicn_punt_remove_ip6_address (vm, (ip6_address_t *) & prefix, - subnet_mask, 1, sw_if_index, 0, + hicn_punt_remove_ip6_address (vm, &prefix, 1, sw_if_index, 0, NO_L2); } } @@ -671,14 +676,15 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, { hicn_main_t *sm = &hicn_main; hicnpg_main_t *hpgm = &hicnpg_main; - ip46_address_t src_addr, hicn_name; + ip46_address_t src_addr; + fib_prefix_t prefix; vnet_main_t *vnm = vnet_get_main (); u32 sw_if_index = ~0; u16 lifetime = 4000; int rv = VNET_API_ERROR_UNIMPLEMENTED; u32 max_seq = ~0; u32 n_flows = ~0; - u32 mask = 0; + u16 mask = 0; u32 n_ifaces = 1; u32 hicn_underneath = ~0; @@ -711,8 +717,8 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, ; } else if (unformat (line_input, "name %U/%d", - unformat_ip46_address, &hicn_name, IP46_TYPE_ANY, - &mask)) + unformat_ip46_address, &prefix.fp_addr, IP46_TYPE_ANY, + &prefix.fp_len)) { ; } @@ -738,6 +744,7 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, } } hpgm->interest_lifetime = lifetime; + mask = prefix.fp_len; if (sw_if_index == ~0) { @@ -771,8 +778,9 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, * Register punting on src address generated by pg and data punting * on the name */ - if (ip46_address_is_ip4 (&src_addr) && ip46_address_is_ip4 (&hicn_name)) + if (ip46_address_is_ip4 (&src_addr) && ip46_address_is_ip4 (&prefix.fp_addr)) { + prefix.fp_proto = FIB_PROTOCOL_IP4; /* Add data node to the vpp graph */ u32 next_hit_node = vlib_node_add_next (vm, hicn_punt_glb. @@ -793,11 +801,11 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, /* Add a session to the table */ hicn_punt_add_vnetssn (&ipv4, &ipv4_src, - &hicn_name, mask, + &prefix, next_hit_node, sw_if_index, base_offset); hicn_punt_add_vnetssn (&ipv4, &ipv4_src, - &hicn_name, mask, + &prefix, next_hit_node, sw_if_index, base_offset); hicn_punt_enable_disable_vnet_ip4_table_on_intf (vm, sw_if_index, @@ -809,8 +817,9 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, } else if (!ip46_address_is_ip4 (&src_addr) - && !ip46_address_is_ip4 (&hicn_name)) + && !ip46_address_is_ip4 (&prefix.fp_addr)) { + prefix.fp_proto = FIB_PROTOCOL_IP6; /* Add node to the vpp graph */ u32 next_hit_node = vlib_node_add_next (vm, hicn_punt_glb.hicn_node_info. @@ -831,11 +840,11 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, /* Add a session to the table */ hicn_punt_add_vnetssn (&ipv6, &ipv6_src, - &hicn_name, mask, + &prefix, next_hit_node, sw_if_index, base_offset); hicn_punt_add_vnetssn (&ipv6, &ipv6_src, - &hicn_name, mask, + &prefix, next_hit_node, sw_if_index, base_offset); hicn_punt_enable_disable_vnet_ip6_table_on_intf (vm, sw_if_index, @@ -854,7 +863,7 @@ hicn_cli_pgen_client_set_command_fn (vlib_main_t * vm, hpgm->pgen_clt_src_addr = src_addr; - hpgm->pgen_clt_hicn_name = hicn_name; + hpgm->pgen_clt_hicn_name = prefix.fp_addr; hpgm->max_seq_number = max_seq; hpgm->n_flows = n_flows; hpgm->n_ifaces = n_ifaces; @@ -890,7 +899,7 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, int rv = HICN_ERROR_NONE; hicnpg_server_main_t *pg_main = &hicnpg_server_main; hicn_main_t *sm = &hicn_main; - ip46_address_t hicn_name; + fib_prefix_t prefix; u32 subnet_mask; int payload_size = 0; u32 sw_if_index = ~0; @@ -912,8 +921,8 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, hicn_underneath = 1; } if (unformat (line_input, "name %U/%d", - unformat_ip46_address, &hicn_name, IP46_TYPE_ANY, - &subnet_mask)) + unformat_ip46_address, &prefix.fp_addr, IP46_TYPE_ANY, + &prefix.fp_len)) {; } else if (unformat (line_input, "size %d", &payload_size)) @@ -940,6 +949,8 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, } } } + prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; + subnet_mask = prefix.fp_len; /* Attach our packet-gen node for ip4 udp local traffic */ if (payload_size == 0 || sw_if_index == ~0) { @@ -980,7 +991,7 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, base_offset = NO_L2; use_current_data = HICN_CLASSIFY_CURRENT_DATA_FLAG; } - if (ip46_address_is_ip4 (&hicn_name)) + if (ip46_address_is_ip4 (&prefix.fp_addr)) { /* Add node to the vpp graph */ u32 next_hit_node = vlib_node_add_next (vm, @@ -999,8 +1010,7 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, /* Add a session to the table */ hicn_punt_add_vnetssn (&ipv4, &ipv4_dst, - (ip46_address_t *) & (hicn_name.ip4), - subnet_mask, next_hit_node, sw_if_index, + &prefix, next_hit_node, sw_if_index, base_offset); hicn_punt_enable_disable_vnet_ip4_table_on_intf (vm, sw_if_index, @@ -1026,8 +1036,7 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t * vm, /* Add a session to the table */ hicn_punt_add_vnetssn (&ipv6, &ipv6_dst, - (ip46_address_t *) & (hicn_name.ip6), - subnet_mask, next_hit_node, sw_if_index, + &prefix, next_hit_node, sw_if_index, base_offset); hicn_punt_enable_disable_vnet_ip6_table_on_intf (vm, sw_if_index, diff --git a/hicn-plugin/src/faces/app/face_app_cli.c b/hicn-plugin/src/faces/app/face_app_cli.c index d55e990de..200f813cb 100644 --- a/hicn-plugin/src/faces/app/face_app_cli.c +++ b/hicn-plugin/src/faces/app/face_app_cli.c @@ -34,14 +34,14 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, vlib_cli_command_t * cmd) { vnet_main_t *vnm = vnet_get_main (); - ip46_address_t prefix; + fib_prefix_t prefix; hicn_face_id_t face_id = HICN_FACE_NULL; u32 cs_reserved = HICN_PARAM_FACE_DFT_CS_RESERVED; int ret = HICN_ERROR_NONE; int sw_if; int face_op = HICN_FACE_NONE; int prod = 0; - int len; + /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; @@ -71,7 +71,7 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, else if (unformat (line_input, "prod prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &len)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) { prod = 1; } @@ -114,14 +114,11 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, ip4_address_t cons_addr4; ip6_address_t cons_addr6; - hicn_prefix_t name_prefix = { - .name = prefix, - .len = len, - }; if (prod) { + prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; rv = - hicn_face_prod_add (&name_prefix, sw_if, &cs_reserved, + hicn_face_prod_add (&prefix, sw_if, &cs_reserved, &prod_addr, &face_id); if (rv == HICN_ERROR_NONE) { diff --git a/hicn-plugin/src/faces/app/face_prod.c b/hicn-plugin/src/faces/app/face_prod.c index bbcc7fa6e..6c12e6d33 100644 --- a/hicn-plugin/src/faces/app/face_prod.c +++ b/hicn-plugin/src/faces/app/face_prod.c @@ -29,7 +29,7 @@ hicn_face_prod_state_t *face_state_vec; u32 *face_state_pool; static int -hicn_app_state_create (u32 swif, hicn_prefix_t * prefix) +hicn_app_state_create (u32 swif, fib_prefix_t * prefix) { /* Make sure that the pool is not empty */ pool_validate_index (face_state_pool, 0); @@ -54,14 +54,14 @@ hicn_app_state_create (u32 swif, hicn_prefix_t * prefix) /* Create the appif and store in the vector */ vec_validate (face_state_vec, swif); clib_memcpy (&(face_state_vec[swif].prefix), prefix, - sizeof (hicn_prefix_t)); + sizeof (fib_prefix_t)); /* Set as busy the element in the vector */ pool_get (face_state_pool, swif_app); *swif_app = swif; int ret = HICN_ERROR_NONE; - if (ip46_address_is_ip4 (&(prefix->name))) + if (ip46_address_is_ip4 (&(prefix->fp_addr))) { ret = vnet_feature_enable_disable ("ip4-unicast", "hicn-face-prod-input", @@ -86,7 +86,7 @@ hicn_app_state_del (u32 swif) u32 *temp; u32 *swif_app = NULL; u8 found = 0; - ip46_address_t *prefix_addr; + fib_prefix_t *prefix; /* *INDENT-OFF* */ pool_foreach (temp, face_state_pool,{ if (*temp == swif) @@ -98,12 +98,12 @@ hicn_app_state_del (u32 swif) ); /* *INDENT-ON* */ - prefix_addr = &(face_state_vec[swif].prefix.name); + prefix = &(face_state_vec[swif].prefix); if (!found) return HICN_ERROR_APPFACE_NOT_FOUND; int ret = HICN_ERROR_NONE; - if (ip46_address_is_ip4 (prefix_addr)) + if (ip46_address_is_ip4 (&prefix->fp_addr)) { ret = vnet_feature_enable_disable ("ip4-unicast", "hicn-face-prod-input", @@ -123,7 +123,7 @@ hicn_app_state_del (u32 swif) } int -hicn_face_prod_add (hicn_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, +hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, ip46_address_t * prod_addr, hicn_face_id_t * faceid) { vlib_main_t *vm = vlib_get_main (); @@ -146,12 +146,12 @@ hicn_face_prod_add (hicn_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, vnet_sw_interface_set_flags (vnm, sw_if, if_flags); u8 *s0; - s0 = format (0, "Prefix %U/%u", format_ip6_address, - &prefix->name, prefix->len); + s0 = format (0, "Prefix %U", format_fib_prefix, + prefix); vlib_cli_output (vm, "Received request for %s, swif %d\n", s0, sw_if); - if (ip46_address_is_zero (&prefix->name)) + if (ip46_address_is_zero (&prefix->fp_addr)) { return HICN_ERROR_APPFACE_PROD_PREFIX_NULL; } @@ -159,16 +159,16 @@ hicn_face_prod_add (hicn_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, * Check if a producer face is already existing for the same prefix * and sw_if */ - if (ip46_address_is_ip4 (&prefix->name)) + if (ip46_address_is_ip4 (&prefix->fp_addr)) { face = - hicn_face_ip4_get (&(prefix->name.ip4), sw_if, + hicn_face_ip4_get (&(prefix->fp_addr.ip4), sw_if, &hicn_face_ip_remote_hashtb); } else { face = - hicn_face_ip6_get (&(prefix->name.ip6), sw_if, + hicn_face_ip6_get (&(prefix->fp_addr.ip6), sw_if, &hicn_face_ip_remote_hashtb); if (face != NULL) return HICN_ERROR_FACE_ALREADY_CREATED; @@ -202,7 +202,7 @@ hicn_face_prod_add (hicn_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, else { /* Otherwise create the face */ - if (ip46_address_is_ip4 (&prefix->name)) + if (ip46_address_is_ip4 (&prefix->fp_addr)) { /* * Otherwise retrieve an ip address to assign as a @@ -226,7 +226,7 @@ hicn_face_prod_add (hicn_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, ip6_address_t remote_app_ip6; get_two_ip6_addresses (&local_app_ip6, &remote_app_ip6); u8 *s0; - s0 = format (0, "Prefix %U", format_ip6_address, &local_app_ip6); + s0 = format (0, "%U", format_ip6_address, &local_app_ip6); vlib_cli_output (vm, "Setting ip address %s\n", s0); @@ -264,7 +264,7 @@ hicn_face_prod_add (hicn_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == HICN_ERROR_NONE) { hicn_app_state_create (sw_if, prefix); - ret = hicn_route_add (faceid, 1, &(prefix->name), prefix->len); + ret = hicn_route_add (faceid, 1, prefix); } *prod_addr = local_app_ip; @@ -294,8 +294,7 @@ hicn_face_prod_del (hicn_face_id_t face_id) prod_face->policy.max = 0; /* Remove the face from the fib */ - hicn_route_del_nhop (&(face_state_vec[face->shared.sw_if].prefix.name), - (face_state_vec[face->shared.sw_if].prefix.len), + hicn_route_del_nhop (&(face_state_vec[face->shared.sw_if].prefix), face_id); int ret = hicn_face_ip_del (face_id); diff --git a/hicn-plugin/src/faces/app/face_prod.h b/hicn-plugin/src/faces/app/face_prod.h index 89b74680b..74c62c3bb 100644 --- a/hicn-plugin/src/faces/app/face_prod.h +++ b/hicn-plugin/src/faces/app/face_prod.h @@ -49,7 +49,7 @@ */ typedef struct { - hicn_prefix_t prefix; + fib_prefix_t prefix; } hicn_face_prod_state_t; extern hicn_face_prod_state_t *face_state_vec; @@ -77,7 +77,7 @@ typedef struct __attribute__ ((packed)) hicn_face_prod_t_ * send data to the producer face */ int -hicn_face_prod_add (hicn_prefix_t * prefix, u32 swif, u32 * cs_reserved, +hicn_face_prod_add (fib_prefix_t * prefix, u32 swif, u32 * cs_reserved, ip46_address_t * prod_addr, hicn_face_id_t * faceid); /** diff --git a/hicn-plugin/src/faces/app/face_prod_node.c b/hicn-plugin/src/faces/app/face_prod_node.c index a9fbfa7bf..c92585624 100644 --- a/hicn-plugin/src/faces/app/face_prod_node.c +++ b/hicn-plugin/src/faces/app/face_prod_node.c @@ -70,17 +70,17 @@ format_face_prod_input_trace (u8 * s, va_list * args) } static_always_inline int -match_ip4_name (u32 * name, hicn_prefix_t * prefix) +match_ip4_name (u32 * name, fib_prefix_t * prefix) { u32 xor = 0; - xor = *name & prefix->name.ip4.data_u32; + xor = *name & prefix->fp_addr.ip4.data_u32; - return xor == prefix->name.ip4.data_u32; + return xor == prefix->fp_addr.ip4.data_u32; } static_always_inline int -match_ip6_name (u32x4 * name, hicn_prefix_t * prefix) +match_ip6_name (u32x4 * name, fib_prefix_t * prefix) { union { @@ -93,32 +93,32 @@ match_ip6_name (u32x4 * name, hicn_prefix_t * prefix) if (U32X4_ALIGNED (name)) { //SSE can't handle unaligned data xor_sum.as_u32x4 = *((u32x4 *) name) & - UNION_CAST (prefix->name.ip6.as_u64[0], u32x4); + UNION_CAST (prefix->fp_addr.ip6.as_u64[0], u32x4); } else #endif /* CLIB_HAVE_VEC128 */ { - xor_sum.as_u64[0] = ((u64 *) name)[0] & prefix->name.ip6.as_u64[0]; - xor_sum.as_u64[1] = ((u64 *) name)[1] & prefix->name.ip6.as_u64[1]; + xor_sum.as_u64[0] = ((u64 *) name)[0] & prefix->fp_addr.ip6.as_u64[0]; + xor_sum.as_u64[1] = ((u64 *) name)[1] & prefix->fp_addr.ip6.as_u64[1]; } - return (xor_sum.as_u64[0] == prefix->name.ip6.as_u64[0]) && - (xor_sum.as_u64[1] == prefix->name.ip6.as_u64[1]); + return (xor_sum.as_u64[0] == prefix->fp_addr.ip6.as_u64[0]) && + (xor_sum.as_u64[1] == prefix->fp_addr.ip6.as_u64[1]); } static_always_inline u32 hicn_face_prod_next_from_data_hdr (vlib_node_runtime_t * node, - vlib_buffer_t * b, hicn_prefix_t * prefix) + vlib_buffer_t * b, fib_prefix_t * prefix) { u8 *ptr = vlib_buffer_get_current (b); u8 v = *ptr & 0xf0; int match_res = 1; - if (PREDICT_TRUE (v == 0x40 && ip46_address_is_ip4 (&prefix->name))) + if (PREDICT_TRUE (v == 0x40 && ip46_address_is_ip4 (&prefix->fp_addr))) { match_res = match_ip4_name ((u32 *) & (ptr[12]), prefix); } - else if (PREDICT_TRUE (v == 0x60 && !ip46_address_is_ip4 (&prefix->name))) + else if (PREDICT_TRUE (v == 0x60 && !ip46_address_is_ip4 (&prefix->fp_addr))) { match_res = match_ip6_name ((u32x4 *) & (ptr[8]), prefix); } diff --git a/hicn-plugin/src/hicn.api b/hicn-plugin/src/hicn.api index da14a9faf..4f3047b0a 100644 --- a/hicn-plugin/src/hicn.api +++ b/hicn-plugin/src/hicn.api @@ -13,6 +13,9 @@ * limitations under the License. */ +option version = "5.1.0"; +import "vnet/ip/ip_types.api"; + define hicn_api_node_params_set { /* Client identifier, set from api_main.my_client_index */ @@ -157,10 +160,10 @@ define hicn_api_face_ip_add u32 context; /* IP local address */ - u64 local_addr[2]; + vl_api_address_t local_addr; /* IP remote address */ - u64 remote_addr[2]; + vl_api_address_t remote_addr; /* IPv4 local port number */ u32 swif; @@ -264,10 +267,10 @@ define hicn_api_face_ip_params_get_reply u32 faceid; /* IP local address */ - u64 local_addr[2]; + vl_api_address_t local_addr; /* IP remote address */ - u64 remote_addr[2]; + vl_api_address_t remote_addr; /* VPP interface (index) associated with the face */ u32 swif; @@ -285,13 +288,10 @@ define hicn_api_route_nhops_add u32 context; /* Prefix to be added to the FIB */ - u64 prefix[2]; - - /* Length of the prefix */ - u8 len; + vl_api_prefix_t prefix; /* A Face ID to the next hop forwarder for the specified prefix */ - u32 face_ids[7]; + u32 face_ids[5]; /* Number of face to add */ u8 n_faces; @@ -315,10 +315,7 @@ define hicn_api_route_del u32 context; /* Prefix to be added to the FIB */ - u64 prefix[2]; - - /* Length of the prefix */ - u8 len; + vl_api_prefix_t prefix; }; define hicn_api_route_del_reply @@ -339,10 +336,7 @@ define hicn_api_route_nhop_del u32 context; /* Prefix to be added to the FIB */ - u64 prefix[2]; - - /* Length of the prefix */ - u8 len; + vl_api_prefix_t prefix; /* Specific next-hop to be removed */ u32 faceid; @@ -366,10 +360,7 @@ define hicn_api_route_get u32 context; /* Route prefix */ - u64 prefix[2]; - - /* Prefix len */ - u8 len; + vl_api_prefix_t prefix; }; define hicn_api_route_get_reply @@ -402,10 +393,7 @@ define hicn_api_routes_details u32 context; /* Route prefix */ - u64 prefix[2]; - - /* Prefix len */ - u8 len; + vl_api_prefix_t prefix; /* List of faces pointing to the next hops */ u32 faceids[5]; @@ -492,10 +480,7 @@ define hicn_api_punting_add u32 context; /* Prefix to match */ - u64 prefix[2]; - - /* Subnet */ - u8 len; + vl_api_prefix_t prefix; /* Interface id */ u32 swif; @@ -519,10 +504,7 @@ define hicn_api_punting_del u32 context; /* Prefix to match */ - u64 prefix[2]; - - /* Subnet */ - u8 len; + vl_api_prefix_t prefix; /* Interface id */ u32 swif; @@ -546,10 +528,7 @@ define hicn_api_register_prod_app u64 context; /* Prefix to match */ - u64 prefix[2]; - - /* Subnet */ - u8 len; + vl_api_prefix_t prefix; /* sw_if id */ u32 swif; @@ -570,7 +549,7 @@ define hicn_api_register_prod_app_reply u32 cs_reserved; /* Prod address (ipv4 or ipv6) */ - u64 prod_addr[2]; + vl_api_address_t prod_addr; /* Return value: new Face ID, ~0 means no Face was created */ u32 faceid; @@ -597,10 +576,10 @@ define hicn_api_register_cons_app_reply i32 retval; /* Ip4 address */ - u32 src_addr4; + vl_api_address_t src_addr4; /* Ip6 address */ - u64 src_addr6[2]; + vl_api_address_t src_addr6; /* Return value: new Face ID, ~0 means no Face was created */ u32 faceid; diff --git a/hicn-plugin/src/hicn_api.c b/hicn-plugin/src/hicn_api.c index f8933206d..5f195b6da 100644 --- a/hicn-plugin/src/hicn_api.c +++ b/hicn-plugin/src/hicn_api.c @@ -22,6 +22,7 @@ #include <vlibapi/api.h> #include <vlibmemory/api.h> #include <vnet/dpo/load_balance.h> +#include <vnet/ip/ip_types_api.h> #include "hicn.h" #include "faces/ip/face_ip.h" @@ -187,14 +188,8 @@ vl_api_hicn_api_face_ip_add_t_handler (vl_api_hicn_api_face_ip_add_t * mp) hicn_face_id_t faceid = HICN_FACE_NULL; ip46_address_t local_addr; ip46_address_t remote_addr; - local_addr.as_u64[0] = - clib_net_to_host_u64 (((u64 *) (&mp->local_addr))[0]); - local_addr.as_u64[1] = - clib_net_to_host_u64 (((u64 *) (&mp->local_addr))[1]); - remote_addr.as_u64[0] = - clib_net_to_host_u64 (((u64 *) (&mp->remote_addr))[0]); - remote_addr.as_u64[1] = - clib_net_to_host_u64 (((u64 *) (&mp->remote_addr))[1]); + ip_address_decode(&mp->local_addr, &local_addr); + ip_address_decode(&mp->remote_addr, &remote_addr); u32 sw_if = clib_net_to_host_u32 (mp->swif); @@ -371,11 +366,9 @@ vl_api_hicn_api_route_nhops_add_t_handler (vl_api_hicn_api_route_nhops_add_t hicn_main_t *sm = &hicn_main; - ip46_address_t prefix; - prefix.as_u64[0] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[0]); - prefix.as_u64[1] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[1]); + fib_prefix_t prefix; + ip_prefix_decode(&mp->prefix, &prefix); - u8 len = mp->len; u8 n_faces = mp->n_faces; for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++) @@ -389,11 +382,11 @@ vl_api_hicn_api_route_nhops_add_t_handler (vl_api_hicn_api_route_nhops_add_t } if (rv == HICN_ERROR_NONE) { - rv = hicn_route_add (face_ids, n_faces, &prefix, len); + rv = hicn_route_add (face_ids, n_faces, &prefix); if (rv == HICN_ERROR_ROUTE_ALREADY_EXISTS) { - rv = hicn_route_add_nhops (face_ids, n_faces, &prefix, len); + rv = hicn_route_add_nhops (face_ids, n_faces, &prefix); } } REPLY_MACRO (VL_API_HICN_API_ROUTE_NHOPS_ADD_REPLY /* , rmp, mp, rv */ ); @@ -408,12 +401,10 @@ static void vl_api_hicn_api_route_del_t_handler hicn_main_t *sm = &hicn_main; - ip46_address_t prefix; - prefix.as_u64[0] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[0]); - prefix.as_u64[1] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[1]); - u8 len = mp->len; + fib_prefix_t prefix; + ip_prefix_decode(&mp->prefix, &prefix); - rv = hicn_route_del (&prefix, len); + rv = hicn_route_del (&prefix); REPLY_MACRO (VL_API_HICN_API_ROUTE_DEL_REPLY /* , rmp, mp, rv */ ); } @@ -426,14 +417,12 @@ static void vl_api_hicn_api_route_nhop_del_t_handler hicn_main_t *sm = &hicn_main; - ip46_address_t prefix; - prefix.as_u64[0] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[0]); - prefix.as_u64[1] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[1]); - u8 len = mp->len; + fib_prefix_t prefix; + ip_prefix_decode(&mp->prefix, &prefix); hicn_face_id_t faceid = clib_net_to_host_u32 (mp->faceid); - rv = hicn_route_del_nhop (&prefix, len, faceid); + rv = hicn_route_del_nhop (&prefix, faceid); REPLY_MACRO (VL_API_HICN_API_ROUTE_NHOP_DEL_REPLY /* , rmp, mp, rv */ ); } @@ -446,16 +435,14 @@ static void vl_api_hicn_api_route_get_t_handler hicn_main_t *sm = &hicn_main; - ip46_address_t prefix; - prefix.as_u64[0] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[0]); - prefix.as_u64[1] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[1]); - u8 len = mp->len; + fib_prefix_t prefix; + ip_prefix_decode(&mp->prefix, &prefix); const dpo_id_t *hicn_dpo_id; const hicn_dpo_vft_t *hicn_dpo_vft; hicn_dpo_ctx_t *hicn_dpo_ctx; u32 fib_index; - rv = hicn_route_get_dpo (&prefix, len, &hicn_dpo_id, &fib_index); + rv = hicn_route_get_dpo (&prefix, &hicn_dpo_id, &fib_index); /* *INDENT-OFF* */ REPLY_MACRO2 (VL_API_HICN_API_ROUTE_GET_REPLY, ( @@ -487,8 +474,7 @@ send_route_details (vl_api_registration_t * reg, mp->_vl_msg_id = htons (VL_API_HICN_API_ROUTES_DETAILS + hm->msg_id_base); mp->context = context; - clib_memcpy (&mp->prefix, &pfx->fp_addr, sizeof (ip46_address_t)); - mp->len = pfx->fp_len; + clib_memcpy (&mp->prefix, &pfx, sizeof (fib_prefix_t)); mp->nfaces = 0; const dpo_id_t *hicn_dpo_id; @@ -497,7 +483,7 @@ send_route_details (vl_api_registration_t * reg, u32 fib_index; int rv = - hicn_route_get_dpo (&pfx->fp_addr, pfx->fp_len, &hicn_dpo_id, &fib_index); + hicn_route_get_dpo (pfx, &hicn_dpo_id, &fib_index); if (rv == HICN_ERROR_NONE) { @@ -660,14 +646,12 @@ static void vl_api_hicn_api_punting_add_t_handler hicn_main_t *sm = &hicn_main; - ip46_address_t prefix; - prefix.as_u64[0] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[0]); - prefix.as_u64[1] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[1]); - u8 subnet_mask = mp->len; + fib_prefix_t prefix; + ip_prefix_decode(&mp->prefix, &prefix); u32 swif = clib_net_to_host_u32 (mp->swif); rv = - hicn_punt_interest_data_for_ip (vm, &prefix, subnet_mask, swif, 0, NO_L2); + hicn_punt_interest_data_for_ip (vm, &prefix, swif, 0, NO_L2); REPLY_MACRO (VL_API_HICN_API_PUNTING_ADD_REPLY /* , rmp, mp, rv */ ); } @@ -695,10 +679,8 @@ static void vl_api_hicn_api_register_prod_app_t_handler hicn_main_t *sm = &hicn_main; - hicn_prefix_t prefix; - prefix.name.as_u64[0] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[0]); - prefix.name.as_u64[1] = clib_net_to_host_u64 (((u64 *) (&mp->prefix))[1]); - prefix.len = mp->len; + fib_prefix_t prefix; + ip_prefix_decode(&mp->prefix, &prefix); u32 swif = clib_net_to_host_u32 (mp->swif); u32 cs_reserved = clib_net_to_host_u32 (mp->cs_reserved); u32 faceid; @@ -710,8 +692,7 @@ static void vl_api_hicn_api_register_prod_app_t_handler /* *INDENT-OFF* */ REPLY_MACRO2 (VL_API_HICN_API_REGISTER_PROD_APP_REPLY, ( { - rmp->prod_addr[0] = prod_addr.as_u64[0]; - rmp->prod_addr[1] = prod_addr.as_u64[1]; + ip_address_encode(&prod_addr, IP46_TYPE_ANY, &rmp->prod_addr); rmp->cs_reserved = clib_net_to_host_u32(cs_reserved); rmp->faceid = clib_net_to_host_u32(faceid); })); @@ -725,23 +706,19 @@ static void vl_api_hicn_api_register_cons_app_t_handler int rv = HICN_ERROR_NONE; hicn_main_t *sm = &hicn_main; - ip4_address_t src_addr4; - ip6_address_t src_addr6; - src_addr4.as_u32 = (u32) 0; - src_addr6.as_u64[0] = (u64) 0; - src_addr6.as_u64[1] = (u64) 1; + ip46_address_t src_addr4 = ip46_address_initializer; + ip46_address_t src_addr6 = ip46_address_initializer; u32 swif = clib_net_to_host_u32 (mp->swif); u32 faceid; - rv = hicn_face_cons_add (&src_addr4, &src_addr6, swif, &faceid); + rv = hicn_face_cons_add (&src_addr4.ip4, &src_addr6.ip6, swif, &faceid); /* *INDENT-OFF* */ REPLY_MACRO2 (VL_API_HICN_API_REGISTER_CONS_APP_REPLY, ( { - rmp->src_addr4 = clib_net_to_host_u32(src_addr4.as_u32); - rmp->src_addr6[0] = clib_net_to_host_u64(src_addr6.as_u64[0]); - rmp->src_addr6[1] = clib_net_to_host_u64(src_addr6.as_u64[1]); + ip_address_encode(&src_addr4, IP46_TYPE_ANY, &rmp->src_addr4); + ip_address_encode(&src_addr6, IP46_TYPE_ANY, &rmp->src_addr6); rmp->faceid = clib_net_to_host_u32(faceid); })); /* *INDENT-ON* */ @@ -820,14 +797,8 @@ hicn_face_api_entry_params_serialize (hicn_face_id_t faceid, if (face != NULL && face->shared.face_type == hicn_face_ip_type) { hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - reply->local_addr[0] = - clib_host_to_net_u64 (face_ip->local_addr.as_u64[0]); - reply->local_addr[1] = - clib_host_to_net_u64 (face_ip->local_addr.as_u64[1]); - reply->remote_addr[0] = - clib_host_to_net_u64 (face_ip->remote_addr.as_u64[0]); - reply->remote_addr[1] = - clib_host_to_net_u64 (face_ip->remote_addr.as_u64[1]); + ip_address_encode(&face_ip->local_addr, IP46_TYPE_ANY, &reply->local_addr); + ip_address_encode(&face_ip->remote_addr, IP46_TYPE_ANY, &reply->remote_addr); reply->swif = clib_host_to_net_u32 (face->shared.sw_if); reply->flags = clib_host_to_net_u32 (face->shared.flags); reply->faceid = clib_host_to_net_u32 (faceid); diff --git a/hicn-plugin/src/hicn_api_test.c b/hicn-plugin/src/hicn_api_test.c index 8cd4ece36..c29aa4a21 100644 --- a/hicn-plugin/src/hicn_api_test.c +++ b/hicn-plugin/src/hicn_api_test.c @@ -23,6 +23,7 @@ #include <vnet/ip/ip4_packet.h> #include <vnet/ip/ip6_packet.h> #include <vnet/ip/format.h> +#include <vnet/ip/ip_types_api.h> #define __plugin_msg_base hicn_test_main.msg_id_base #include <vlibapi/vat_helper_macros.h> @@ -83,6 +84,70 @@ unformat_ip46_address (unformat_input_t * input, va_list * args) return 0; } +/* static ip46_type_t */ +/* ip_address_union_decode (const vl_api_address_union_t *in, */ +/* vl_api_address_family_t af, */ +/* ip46_address_t *out) */ +/* { */ +/* ip46_type_t type; */ + +/* switch (clib_net_to_host_u32 (af)) */ +/* { */ +/* case ADDRESS_IP4: */ +/* clib_memset (out, 0, sizeof (*out)); */ +/* clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4)); */ +/* type = IP46_TYPE_IP4; */ +/* break; */ +/* case ADDRESS_IP6: */ +/* clib_memcpy (&out->ip6, &in->ip6, sizeof (out->ip6)); */ +/* type = IP46_TYPE_IP6; */ +/* break; */ +/* default: */ +/* ASSERT (!"Unkown address family in API address type"); */ +/* type = IP46_TYPE_ANY; */ +/* break; */ +/* } */ + +/* return type; */ +/* } */ + +/* static void */ +/* ip_address_union_encode (const ip46_address_t * in, */ +/* vl_api_address_family_t af, */ +/* vl_api_address_union_t * out) */ +/* { */ +/* if (ADDRESS_IP6 == clib_net_to_host_u32 (af)) */ +/* memcpy (out->ip6.address, &in->ip6, sizeof (out->ip6)); */ +/* else */ +/* memcpy (out->ip4.address, &in->ip4, sizeof (out->ip4)); */ +/* } */ + +/* ip46_type_t ip_address_decode (const vl_api_address_t *in, ip46_address_t *out) */ +/* { */ +/* return (ip_address_union_decode (&in->un, in->af, out)); */ +/* } */ + +/* void ip_address_encode (const ip46_address_t *in, ip46_type_t type, */ +/* vl_api_address_t *out) */ +/* { */ +/* switch (type) */ +/* { */ +/* case IP46_TYPE_IP4: */ +/* out->af = clib_net_to_host_u32 (ADDRESS_IP4); */ +/* break; */ +/* case IP46_TYPE_IP6: */ +/* out->af = clib_net_to_host_u32 (ADDRESS_IP6); */ +/* break; */ +/* case IP46_TYPE_ANY: */ +/* if (ip46_address_is_ip4 (in)) */ +/* out->af = clib_net_to_host_u32 (ADDRESS_IP4); */ +/* else */ +/* out->af = clib_net_to_host_u32 (ADDRESS_IP6); */ +/* break; */ +/* } */ +/* ip_address_union_encode (in, out->af, &out->un); */ +/* } */ + ///////////////////////////////////////////////////// #define HICN_FACE_NULL ~0 @@ -137,8 +202,8 @@ _(HICN_API_FACE_IP_PARAMS_GET_REPLY, hicn_api_face_ip_params_get_reply) \ _(HICN_API_ROUTE_GET_REPLY, hicn_api_route_get_reply) \ _(HICN_API_ROUTES_DETAILS, hicn_api_routes_details) \ _(HICN_API_ROUTE_DEL_REPLY, hicn_api_route_del_reply) \ -_(HICN_API_ROUTE_NHOP_DEL_REPLY, hicn_api_route_nhop_del_reply) \ -_(HICN_API_STRATEGIES_GET_REPLY, hicn_api_strategies_get_reply) \ +_(HICN_API_ROUTE_NHOP_DEL_REPLY, hicn_api_route_nhop_del_reply) \ +_(HICN_API_STRATEGIES_GET_REPLY, hicn_api_strategies_get_reply) \ _(HICN_API_STRATEGY_GET_REPLY, hicn_api_strategy_get_reply) \ _(HICN_API_REGISTER_PROD_APP_REPLY, hicn_api_register_prod_app_reply) \ _(HICN_API_REGISTER_CONS_APP_REPLY, hicn_api_register_cons_app_reply) @@ -359,10 +424,8 @@ api_hicn_api_face_ip_add (vat_main_t * vam) } /* Construct the API message */ M (HICN_API_FACE_IP_ADD, mp); - mp->local_addr[0] = clib_host_to_net_u64 (local_addr.as_u64[0]); - mp->local_addr[1] = clib_host_to_net_u64 (local_addr.as_u64[1]); - mp->remote_addr[0] = clib_host_to_net_u64 (remote_addr.as_u64[0]); - mp->remote_addr[1] = clib_host_to_net_u64 (remote_addr.as_u64[1]); + ip_address_decode (&mp->local_addr, &local_addr); + ip_address_decode (&mp->remote_addr, &remote_addr); mp->swif = clib_host_to_net_u32 (sw_if); /* send it... */ @@ -497,10 +560,8 @@ static void return; } vec_reset_length (sbuf); - local_addr.as_u64[0] = clib_net_to_host_u64 (rmp->local_addr[0]); - local_addr.as_u64[1] = clib_net_to_host_u64 (rmp->local_addr[1]); - remote_addr.as_u64[0] = clib_net_to_host_u64 (rmp->remote_addr[0]); - remote_addr.as_u64[1] = clib_net_to_host_u64 (rmp->remote_addr[1]); + ip_address_decode(&rmp->local_addr, &local_addr); + ip_address_decode(&rmp->remote_addr, &remote_addr); sbuf = format (0, "local_addr %U remote_addr %U", format_ip46_address, &local_addr, 0 /*IP46_ANY_TYPE */ , format_ip46_address, @@ -578,14 +639,13 @@ api_hicn_api_route_get (vat_main_t * vam) unformat_input_t *input = vam->input; vl_api_hicn_api_route_get_t *mp; - ip46_address_t prefix; - u8 plen; + fib_prefix_t prefix; int ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) {; } else @@ -595,16 +655,14 @@ api_hicn_api_route_get (vat_main_t * vam) } /* Check parse */ - if (((prefix.as_u64[0] == 0) && (prefix.as_u64[1] == 0)) || (plen == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0)) { clib_warning ("Please specify a valid prefix..."); return 1; } //Construct the API message M (HICN_API_ROUTE_GET, mp); - mp->prefix[0] = clib_host_to_net_u64 (((u64 *) & prefix)[0]); - mp->prefix[1] = clib_host_to_net_u64 (((u64 *) & prefix)[1]); - mp->len = plen; + ip_prefix_encode(&prefix, &mp->prefix); //send it... S (mp); @@ -701,14 +759,15 @@ static void (vl_api_hicn_api_routes_details_t * mp) { vat_main_t *vam = hicn_test_main.vat_main; - + fib_prefix_t prefix; u32 faceid; u8 *sbuf = 0; vec_reset_length (sbuf); + ip_prefix_decode(&mp->prefix, &prefix); sbuf = - format (sbuf, "Prefix: %U/%u\n", format_ip46_address, &mp->prefix, 0, - mp->len); + format (sbuf, "Prefix: %U/%u\n", format_ip46_address, &prefix.fp_addr, 0, + prefix.fp_len); sbuf = format (sbuf, "Faces: \n"); for (int i = 0; i < mp->nfaces; i++) @@ -727,8 +786,7 @@ api_hicn_api_route_nhops_add (vat_main_t * vam) unformat_input_t *input = vam->input; vl_api_hicn_api_route_nhops_add_t *mp; - ip46_address_t prefix; - u8 plen; + fib_prefix_t prefix; u32 faceid = 0; int ret; @@ -736,7 +794,7 @@ api_hicn_api_route_nhops_add (vat_main_t * vam) while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "add prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) {; } else if (unformat (input, "face %d", &faceid)) @@ -749,7 +807,7 @@ api_hicn_api_route_nhops_add (vat_main_t * vam) } /* Check parse */ - if (((prefix.as_u64[0] == 0) && (prefix.as_u64[1] == 0)) || (plen == 0) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0) || (faceid == 0)) { clib_warning ("Please specify prefix and faceid..."); @@ -757,9 +815,7 @@ api_hicn_api_route_nhops_add (vat_main_t * vam) } /* Construct the API message */ M (HICN_API_ROUTE_NHOPS_ADD, mp); - mp->prefix[0] = clib_host_to_net_u64 (((u64 *) & prefix)[0]); - mp->prefix[1] = clib_host_to_net_u64 (((u64 *) & prefix)[1]); - mp->len = plen; + ip_prefix_encode(&prefix, &mp->prefix); mp->face_ids[0] = clib_host_to_net_u32 (faceid); mp->n_faces = 1; @@ -779,14 +835,13 @@ api_hicn_api_route_del (vat_main_t * vam) unformat_input_t *input = vam->input; vl_api_hicn_api_route_del_t *mp; - ip46_address_t prefix; - u8 plen; + fib_prefix_t prefix; int ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) {; } else @@ -796,16 +851,14 @@ api_hicn_api_route_del (vat_main_t * vam) } /* Check parse */ - if (((prefix.as_u64[0] == 0) && (prefix.as_u64[1] == 0)) || (plen == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0)) { clib_warning ("Please specify prefix..."); return 1; } /* Construct the API message */ M (HICN_API_ROUTE_DEL, mp); - mp->prefix[0] = clib_host_to_net_u64 (((u64 *) & prefix)[0]); - mp->prefix[1] = clib_host_to_net_u64 (((u64 *) & prefix)[1]); - mp->len = plen; + ip_prefix_encode(&prefix, &mp->prefix); /* send it... */ S (mp); @@ -823,14 +876,13 @@ api_hicn_api_route_nhop_del (vat_main_t * vam) unformat_input_t *input = vam->input; vl_api_hicn_api_route_nhop_del_t *mp; - ip46_address_t prefix; - u8 plen; + fib_prefix_t prefix; int faceid = 0, ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "del prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) {; } else if (unformat (input, "face %d", &faceid)) @@ -843,7 +895,7 @@ api_hicn_api_route_nhop_del (vat_main_t * vam) } /* Check parse */ - if (((prefix.as_u64[0] == 0) && (prefix.as_u64[1] == 0)) || (plen == 0) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0) || (faceid == HICN_FACE_NULL)) { clib_warning ("Please specify prefix and faceid..."); @@ -851,9 +903,7 @@ api_hicn_api_route_nhop_del (vat_main_t * vam) } /* Construct the API message */ M (HICN_API_ROUTE_NHOP_DEL, mp); - mp->prefix[0] = clib_host_to_net_u64 (((u64 *) & prefix)[0]); - mp->prefix[1] = clib_host_to_net_u64 (((u64 *) & prefix)[1]); - mp->len = plen; + ip_prefix_encode(&prefix, &mp->prefix); mp->faceid = clib_host_to_net_u32 (faceid); @@ -989,15 +1039,14 @@ api_hicn_api_register_prod_app (vat_main_t * vam) { unformat_input_t *input = vam->input; vl_api_hicn_api_register_prod_app_t *mp; - ip46_address_t prefix; - int plen; + fib_prefix_t prefix; u32 swif = ~0; int ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "prefix %U/%d", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) {; } else if (unformat (input, "id %d", &swif)) @@ -1010,16 +1059,14 @@ api_hicn_api_register_prod_app (vat_main_t * vam) } /* Check parse */ - if (((prefix.as_u64[0] == 0) && (prefix.as_u64[1] == 0)) || (plen == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0)) { clib_warning ("Please specify prefix..."); return 1; } /* Construct the API message */ M (HICN_API_REGISTER_PROD_APP, mp); - mp->prefix[0] = clib_host_to_net_u64 (prefix.as_u64[0]); - mp->prefix[1] = clib_host_to_net_u64 (prefix.as_u64[1]); - mp->len = (u8) plen; + ip_prefix_encode(&prefix, &mp->prefix); mp->swif = clib_host_to_net_u32 (swif); @@ -1094,17 +1141,16 @@ static void fformat (vam->ofp, " (API call error: %d)\n", vam->retval); return; } - ip4_address_t src_addr4; - src_addr4.as_u32 = clib_net_to_host_u32 (mp->src_addr4); - ip6_address_t src_addr6; - src_addr6.as_u64[0] = clib_net_to_host_u64 (mp->src_addr6[0]); - src_addr6.as_u64[1] = clib_net_to_host_u64 (mp->src_addr6[1]); + ip46_address_t src_addr4 = ip46_address_initializer; + ip46_address_t src_addr6 = ip46_address_initializer; + ip_address_decode(&mp->src_addr4, &src_addr4); + ip_address_decode(&mp->src_addr6, &src_addr6); fformat (vam->ofp, "ip4 address %U\n" "ip6 address :%U\n" "appif id :%d\n", - format_ip4_address, &src_addr4, format_ip6_address, &src_addr6); + format_ip46_address, IP46_TYPE_ANY, &src_addr4, format_ip46_address, IP46_TYPE_ANY, &src_addr6); } /* diff --git a/hicn-plugin/src/punt.c b/hicn-plugin/src/punt.c index 68c0bafb9..fe1ca495f 100644 --- a/hicn-plugin/src/punt.c +++ b/hicn-plugin/src/punt.c @@ -25,6 +25,7 @@ #include <vnet/ip/ip4_packet.h> #include <vnet/ip/ip6_packet.h> #include <vnet/ethernet/packet.h> +#include <vnet/fib/fib_types.h> #include <vlib/global_funcs.h> #include <hicn/hicn.h> @@ -457,15 +458,15 @@ _hicn_punt_add_del_vnetssn (ip_version_t * ip, u8 punt_id, u8 mask, */ int hicn_punt_add_del_vnetssn (ip_version_t * ip, field_t * field, - ip46_address_t * v46_address, u8 mask, + fib_prefix_t * prefix, u32 next_hit_index, u32 intfc, u8 base_offset, int is_add) { - return _hicn_punt_add_del_vnetssn (ip, field->punt_id, mask, next_hit_index, + return _hicn_punt_add_del_vnetssn (ip, field->punt_id, prefix->fp_len, next_hit_index, intfc, base_offset, is_add, field, - ip46_address_is_ip4 (v46_address) ? - v46_address->ip4.as_u8 : v46_address-> - ip6.as_u8, NULL); + ip46_address_is_ip4 (&prefix->fp_addr) ? + prefix->fp_addr.ip4.as_u8 : + prefix->fp_addr.ip6.as_u8, NULL); } @@ -477,24 +478,24 @@ hicn_punt_add_del_vnetssn (ip_version_t * ip, field_t * field, */ int hicn_punt_add_del_vnetssn_udp (ip_version_t * outer, ip_version_t * inner, - field_t * field, ip46_address_t * v46_address, - u8 mask, u32 next_hit_index, u32 intfc, + field_t * field, fib_prefix_t * prefix, + u32 next_hit_index, u32 intfc, u8 base_offset, u8 protocol, u16 sport, u16 dport, int is_add) { - return _hicn_punt_add_del_vnetssn (outer, field->punt_id, mask, + return _hicn_punt_add_del_vnetssn (outer, field->punt_id, prefix->fp_len, next_hit_index, intfc, base_offset, is_add, outer->protocol_field, &protocol, outer->udp_sport, &sport, outer->udp_dport, &dport, field, - v46_address->as_u8, NULL); + prefix->fp_addr.as_u8, NULL); } -#define hicn_punt_add_vnetssn_udp(outer, inner, field, addr, mask, index, intfc, offset, protocol, sport, dport) \ - (hicn_punt_add_del_vnetssn_udp(outer, inner, field, addr, mask, index, intfc, offset, protocol, sport, dport, OP_ADD)) +#define hicn_punt_add_vnetssn_udp(outer, inner, field, prefix, index, intfc, offset, protocol, sport, dport) \ + (hicn_punt_add_del_vnetssn_udp(outer, inner, field, prefix, index, intfc, offset, protocol, sport, dport, OP_ADD)) -#define hicn_punt_del_vnetssn_udp(outer, inner, field, addr, mask, index, intfc, offset, protocol, sport, dport) \ - (hicn_punt_add_del_vnetssn_udp(outer, inner, field, addr, mask, index, intfc, offset, protocol, sport, dport, OP_DEL)) +#define hicn_punt_del_vnetssn_udp(outer, inner, field, prefix, index, intfc, offset, protocol, sport, dport) \ + (hicn_punt_add_del_vnetssn_udp(outer, inner, field, prefix, index, intfc, offset, protocol, sport, dport, OP_DEL)) /* * Enable the table on a given interface considering the table type @@ -518,24 +519,22 @@ hicn_punt_enable_disable_vnet_ip4_table_on_intf (vlib_main_t * vm, * not base_offset ??? */ int -hicn_punt_remove_ip4_address (vlib_main_t * vm, ip4_address_t * addr, - u8 mask, int skip, u32 sw_if_index, +hicn_punt_remove_ip4_address (vlib_main_t * vm, fib_prefix_t * prefix, + int skip, u32 sw_if_index, int is_enable, u8 with_l2) { vnet_classify_main_t *cm = &vnet_classify_main; vnet_classify_table_t *vnet_table = NULL; - + u8 mask = prefix->fp_len; u32 table_index = ~0; u32 base_offset = (with_l2 ? ETH_L2 : NO_L2); - ip46_address_t addr46; - ip46_address_set_ip4 (&addr46, addr); - hicn_punt_del_vnetssn (&ipv4, &ipv4_src, &addr46, mask, + hicn_punt_del_vnetssn (&ipv4, &ipv4_src, prefix, hicn_punt_glb.next_hit_data_ipv4, sw_if_index, ETH_L2); - hicn_punt_del_vnetssn (&ipv4, &ipv4_dst, &addr46, mask, + hicn_punt_del_vnetssn (&ipv4, &ipv4_dst, prefix, hicn_punt_glb.next_hit_interest_ipv4, sw_if_index, ETH_L2); @@ -560,22 +559,22 @@ hicn_punt_remove_ip4_address (vlib_main_t * vm, ip4_address_t * addr, } int -hicn_punt_remove_ip6_address (vlib_main_t * vm, ip6_address_t * addr, - u8 mask, int skip, u32 sw_if_index, +hicn_punt_remove_ip6_address (vlib_main_t * vm, fib_prefix_t * prefix, + int skip, u32 sw_if_index, int is_enable, u8 with_l2) { vnet_classify_main_t *cm = &vnet_classify_main; vnet_classify_table_t *vnet_table = NULL; - + u8 mask = prefix->fp_len; u32 table_index = ~0; u32 base_offset = (with_l2 ? ETH_L2 : NO_L2); - hicn_punt_del_vnetssn (&ipv6, &ipv6_src, (ip46_address_t *) addr, mask, + hicn_punt_del_vnetssn (&ipv6, &ipv6_src, prefix, hicn_punt_glb.next_hit_data_ipv6, sw_if_index, ETH_L2); - hicn_punt_del_vnetssn (&ipv6, &ipv6_dst, (ip46_address_t *) addr, mask, + hicn_punt_del_vnetssn (&ipv6, &ipv6_dst, prefix, hicn_punt_glb.next_hit_interest_ipv6, sw_if_index, ETH_L2); @@ -762,7 +761,7 @@ hicn_punt_init (vlib_main_t * vm) u32 hicn_punt_interest_data_for_udp (vlib_main_t * vm, - ip46_address_t * prefix, u8 mask, + fib_prefix_t * prefix, u32 swif, u8 punt_type, u16 sport, u16 dport, u8 with_l2) { @@ -773,12 +772,13 @@ hicn_punt_interest_data_for_udp (vlib_main_t * vm, with_l2 ? HICN_CLASSIFY_NO_CURRENT_DATA_FLAG : HICN_CLASSIFY_CURRENT_DATA_FLAG; u8 base_offset = with_l2 ? ETH_L2 : NO_L2; + u16 mask = prefix->fp_len; if (punt_type != HICN_PUNT_IP_TYPE && punt_type != HICN_PUNT_UDP4_TYPE && punt_type != HICN_PUNT_UDP6_TYPE) return HICN_ERROR_PUNT_INVAL; - if (ip46_address_is_ip4 (prefix)) + if (ip46_address_is_ip4 (&prefix->fp_addr)) { if (mask > IPV4_ADDR_LEN_BITS) return HICN_ERROR_PUNT_INVAL; @@ -802,13 +802,13 @@ hicn_punt_interest_data_for_udp (vlib_main_t * vm, * subnet mask */ hicn_punt_add_vnetssn_udp (&ipv44, &ipv4, &udp44_src, - prefix, mask, + prefix, hicn_punt_glb.next_hit_data_udp4, swif, base_offset, IPPROTO_UDP, sport, dport); hicn_punt_add_vnetssn_udp (&ipv44, &ipv4, &udp44_dst, - prefix, mask, + prefix, hicn_punt_glb.next_hit_interest_udp4, swif, base_offset, IPPROTO_UDP, sport, dport); @@ -836,13 +836,13 @@ hicn_punt_interest_data_for_udp (vlib_main_t * vm, * subnet mask */ hicn_punt_add_vnetssn_udp (&ipv64, &ipv4, &udp64_src, - prefix, mask, + prefix, hicn_punt_glb.next_hit_data_udp6, swif, base_offset, IPPROTO_UDP, sport, dport); hicn_punt_add_vnetssn_udp (&ipv64, &ipv4, &udp64_dst, - prefix, mask, + prefix, hicn_punt_glb.next_hit_interest_udp6, swif, base_offset, IPPROTO_UDP, sport, dport); @@ -875,11 +875,11 @@ hicn_punt_interest_data_for_udp (vlib_main_t * vm, * subnet mask */ hicn_punt_add_vnetssn_udp (&ipv46, &ipv4, &udp46_src, - prefix, mask, + prefix, hicn_punt_glb.next_hit_data_udp4, swif, base_offset, IPPROTO_UDP, sport, dport); - hicn_punt_add_vnetssn_udp (&ipv46, &ipv4, &udp46_dst, prefix, mask, + hicn_punt_add_vnetssn_udp (&ipv46, &ipv4, &udp46_dst, prefix, hicn_punt_glb.next_hit_interest_udp4, swif, base_offset, IPPROTO_UDP, sport, dport); @@ -908,11 +908,11 @@ hicn_punt_interest_data_for_udp (vlib_main_t * vm, * subnet mask */ hicn_punt_add_vnetssn_udp (&ipv66, &ipv6, &udp66_src, - prefix, mask, + prefix, hicn_punt_glb.next_hit_data_udp6, swif, base_offset, IPPROTO_UDP, sport, dport); - hicn_punt_add_vnetssn_udp (&ipv66, &ipv6, &udp66_dst, prefix, mask, + hicn_punt_add_vnetssn_udp (&ipv66, &ipv6, &udp66_dst, prefix, hicn_punt_glb.next_hit_interest_udp6, swif, base_offset, IPPROTO_UDP, sport, dport); @@ -929,7 +929,7 @@ hicn_punt_interest_data_for_udp (vlib_main_t * vm, u32 hicn_punt_interest_data_for_ip (vlib_main_t * vm, - ip46_address_t * prefix, u8 mask, + fib_prefix_t * prefix, u32 swif, u8 punt_type, u8 with_l2) { int skip = 1; @@ -939,12 +939,13 @@ hicn_punt_interest_data_for_ip (vlib_main_t * vm, with_l2 ? HICN_CLASSIFY_NO_CURRENT_DATA_FLAG : HICN_CLASSIFY_CURRENT_DATA_FLAG; u8 base_offset = with_l2 ? ETH_L2 : NO_L2; + u16 mask = prefix->fp_len; if (punt_type != HICN_PUNT_IP_TYPE && punt_type != HICN_PUNT_UDP4_TYPE && punt_type != HICN_PUNT_UDP6_TYPE) return HICN_ERROR_PUNT_INVAL; - if (ip46_address_is_ip4 (prefix)) + if (ip46_address_is_ip4 (&prefix->fp_addr)) { if (mask > IPV4_ADDR_LEN_BITS) return HICN_ERROR_PUNT_INVAL; @@ -966,11 +967,11 @@ hicn_punt_interest_data_for_ip (vlib_main_t * vm, * subnet mask */ hicn_punt_add_vnetssn (&ipv4, &ipv4_src, - prefix, mask, + prefix, hicn_punt_glb.next_hit_data_ipv4, swif, base_offset); hicn_punt_add_vnetssn (&ipv4, &ipv4_dst, - prefix, mask, + prefix, hicn_punt_glb.next_hit_interest_ipv4, swif, base_offset); @@ -1004,10 +1005,10 @@ hicn_punt_interest_data_for_ip (vlib_main_t * vm, * subnet mask */ hicn_punt_add_vnetssn (&ipv6, &ipv6_src, prefix, - mask, hicn_punt_glb.next_hit_data_ipv6, swif, + hicn_punt_glb.next_hit_data_ipv6, swif, base_offset); hicn_punt_add_vnetssn (&ipv6, &ipv6_dst, prefix, - mask, hicn_punt_glb.next_hit_interest_ipv6, + hicn_punt_glb.next_hit_interest_ipv6, swif, base_offset); hicn_punt_enable_disable_vnet_ip6_table_on_intf (vm, swif, diff --git a/hicn-plugin/src/punt.h b/hicn-plugin/src/punt.h index 3e6900064..5e1126445 100644 --- a/hicn-plugin/src/punt.h +++ b/hicn-plugin/src/punt.h @@ -17,6 +17,7 @@ #define __HICN_PUNT_H__ #include <vppinfra/error.h> +#include <vnet/fib/fib_types.h> #include <hicn/hicn.h> #define HICN_CLASSIFY_TABLE_MEMORY_SIZE (2*1024*1024) // 2MB allocated for the classification table @@ -294,17 +295,17 @@ hicn_punt_enable_disable_vnet_ip6_table_on_intf (vlib_main_t * vm, u32 sw_if_index, int is_enable); u32 hicn_punt_interest_data_for_udp (vlib_main_t * vm, - ip46_address_t * prefix, u8 mask, + fib_prefix_t * prefix, u32 swif, u8 punt_type, u16 sport, u16 dport, u8 with_l2); u32 hicn_punt_interest_data_for_ip (vlib_main_t * vm, - ip46_address_t * prefix, u8 mask, + fib_prefix_t * prefix, u32 swif, u8 type, u8 with_l2); -int hicn_punt_remove_ip6_address (vlib_main_t * vm, ip6_address_t * addr, - u8 mask, int skip, u32 swif, int is_enable, +int hicn_punt_remove_ip6_address (vlib_main_t * vm, fib_prefix_t * prefix, + int skip, u32 swif, int is_enable, u8 with_l2); -int hicn_punt_remove_ip4_address (vlib_main_t * vm, ip4_address_t * addr, - u8 mask, int skip, u32 swif, int is_enable, +int hicn_punt_remove_ip4_address (vlib_main_t * vm, fib_prefix_t * prefix, + int skip, u32 swif, int is_enable, u8 with_l2); void hicn_punt_init (vlib_main_t * vm); @@ -321,15 +322,15 @@ hicn_punt_add_del_vnettbl (ip_version_t * ip, field_t * field, u8 mask, u32 int hicn_punt_add_del_vnetssn (ip_version_t * ip, field_t * field, - ip46_address_t * v46_address, u8 mask, + fib_prefix_t * prefix, u32 next_hit_index, u32 intfc, u8 base_offset, int is_add); -#define hicn_punt_add_vnetssn(ip, field, addr, mask, index, intfc, offset) \ - (hicn_punt_add_del_vnetssn(ip, field, addr, mask, index, intfc, offset, OP_ADD)) +#define hicn_punt_add_vnetssn(ip, field, addr, index, intfc, offset) \ + (hicn_punt_add_del_vnetssn(ip, field, addr, index, intfc, offset, OP_ADD)) -#define hicn_punt_del_vnetssn(ip, field, addr, mask, index, intfc, offset) \ - (hicn_punt_add_del_vnetssn(ip, field, addr, mask, index, intfc, offset, OP_DEL)) +#define hicn_punt_del_vnetssn(ip, field, addr, index, intfc, offset) \ + (hicn_punt_add_del_vnetssn(ip, field, addr, index, intfc, offset, OP_DEL)) #endif /* // __HICN_PUNT_H__ */ diff --git a/hicn-plugin/src/route.c b/hicn-plugin/src/route.c index 11302aba4..3581fe490 100644 --- a/hicn-plugin/src/route.c +++ b/hicn-plugin/src/route.c @@ -28,29 +28,24 @@ #include "strategies/dpo_mw.h" int -hicn_route_get_dpo (const ip46_address_t * prefix, u8 plen, +hicn_route_get_dpo (const fib_prefix_t * prefix, const dpo_id_t ** hicn_dpo, u32 * fib_index) { - fib_prefix_t fib_pfx; + //fib_prefix_t fib_pfx; const dpo_id_t *load_balance_dpo_id; const dpo_id_t *former_dpo_id; int found = 0, ret = HICN_ERROR_ROUTE_NOT_FOUND; fib_node_index_t fib_entry_index; - /* At this point the face exists in the face table */ - fib_prefix_from_ip46_addr (prefix, &fib_pfx); - fib_pfx.fp_len = plen; - - /* Check if the route already exist in the fib */ /* * ASSUMPTION: we use table 0 which is the default table and it is * already existing and locked */ - *fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, + *fib_index = fib_table_find_or_create_and_lock (prefix->fp_proto, HICN_FIB_TABLE, FIB_SOURCE_PLUGIN_HI); - fib_entry_index = fib_table_lookup_exact_match (*fib_index, &fib_pfx); + fib_entry_index = fib_table_lookup_exact_match (*fib_index, prefix); if (fib_entry_index != FIB_NODE_INDEX_INVALID) { @@ -86,7 +81,7 @@ hicn_route_get_dpo (const ip46_address_t * prefix, u8 plen, * Remove the lock from the table. We keep one lock per route, not * per dpo */ - fib_table_unlock (*fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (*fib_index, prefix->fp_proto, FIB_SOURCE_PLUGIN_HI); return ret; } @@ -94,10 +89,8 @@ hicn_route_get_dpo (const ip46_address_t * prefix, u8 plen, /* Add a new route for a name prefix */ int hicn_route_add (hicn_face_id_t * face_id, u32 len, - const ip46_address_t * prefix, u8 plen) + const fib_prefix_t * prefix) { - - fib_prefix_t fib_pfx; dpo_id_t dpo = DPO_INVALID; const dpo_id_t *hicn_dpo_id; int ret = HICN_ERROR_NONE; @@ -135,15 +128,10 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, } } - ret = hicn_route_get_dpo (prefix, plen, &hicn_dpo_id, &fib_index); + ret = hicn_route_get_dpo (prefix, &hicn_dpo_id, &fib_index); if (ret == HICN_ERROR_ROUTE_NOT_FOUND) { - /* The Fib entry does not exist */ - /* At this point the face exists in the face table */ - fib_prefix_from_ip46_addr (prefix, &fib_pfx); - fib_pfx.fp_len = plen; - dpo_id_t nhops[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; for (int i = 0; i < n_face_dpo; i++) { @@ -151,7 +139,7 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, } ret = - default_dpo.hicn_dpo_create (fib_pfx.fp_proto, nhops, n_face_dpo, + default_dpo.hicn_dpo_create (prefix->fp_proto, nhops, n_face_dpo, &dpo_idx); if (ret) @@ -165,7 +153,7 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, */ dpo_set (&dpo, default_dpo.hicn_dpo_get_type (), - (ip46_address_is_ip4 (prefix) ? DPO_PROTO_IP4 : DPO_PROTO_IP6), + (ip46_address_is_ip4 (&prefix->fp_addr) ? DPO_PROTO_IP4 : DPO_PROTO_IP6), dpo_idx); /* Here is where we create the "via" like route */ @@ -176,13 +164,13 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, */ fib_node_index_t new_fib_node_index = fib_table_entry_special_dpo_add (fib_index, - &fib_pfx, + prefix, FIB_SOURCE_PLUGIN_HI, FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); /* We added a route, therefore add one lock to the table */ - fib_table_lock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_lock (fib_index, prefix->fp_proto, FIB_SOURCE_PLUGIN_HI); dpo_unlock (&dpo); ret = @@ -206,7 +194,7 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, int hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, - const ip46_address_t * prefix, u8 plen) + const fib_prefix_t * prefix) { const dpo_id_t *hicn_dpo_id; int ret = HICN_ERROR_NONE; @@ -244,7 +232,7 @@ hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, } } - ret = hicn_route_get_dpo (prefix, plen, &hicn_dpo_id, &fib_index); + ret = hicn_route_get_dpo (prefix, &hicn_dpo_id, &fib_index); if (ret == HICN_ERROR_NONE) { @@ -260,50 +248,40 @@ hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, } int -hicn_route_del (ip46_address_t * prefix, u8 plen) +hicn_route_del (fib_prefix_t * prefix) { - fib_prefix_t fib_pfx; const dpo_id_t *hicn_dpo_id; int ret = HICN_ERROR_NONE; u32 fib_index; - /* At this point the face exists in the face table */ - fib_prefix_from_ip46_addr (prefix, &fib_pfx); - fib_pfx.fp_len = plen; - /* Remove the fib entry only if the dpo is of type hicn */ - ret = hicn_route_get_dpo (prefix, plen, &hicn_dpo_id, &fib_index); + ret = hicn_route_get_dpo (prefix, &hicn_dpo_id, &fib_index); if (ret == HICN_ERROR_NONE) { - fib_table_entry_special_remove (HICN_FIB_TABLE, &fib_pfx, + fib_table_entry_special_remove (HICN_FIB_TABLE, prefix, FIB_SOURCE_PLUGIN_HI); /* * Remove the lock from the table. We keep one lock per route */ - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, prefix->fp_proto, FIB_SOURCE_PLUGIN_HI); } //Remember to remove the lock from the table when removing the entry return ret; } int -hicn_route_del_nhop (ip46_address_t * prefix, u8 plen, hicn_face_id_t face_id) +hicn_route_del_nhop (fib_prefix_t * prefix, hicn_face_id_t face_id) { - - fib_prefix_t fib_pfx; const dpo_id_t *hicn_dpo_id; int ret; u32 vft_id; const hicn_dpo_vft_t *dpo_vft; u32 fib_index; - /* At this point the face exists in the face table */ - fib_prefix_from_ip46_addr (prefix, &fib_pfx); - fib_pfx.fp_len = plen; - ret = hicn_route_get_dpo (prefix, plen, &hicn_dpo_id, &fib_index); + ret = hicn_route_get_dpo (prefix, &hicn_dpo_id, &fib_index); /* Check if the dpo is an hicn_dpo_t */ if (ret == HICN_ERROR_NONE) @@ -311,16 +289,15 @@ hicn_route_del_nhop (ip46_address_t * prefix, u8 plen, hicn_face_id_t face_id) vft_id = hicn_dpo_get_vft_id (hicn_dpo_id); dpo_vft = hicn_dpo_get_vft (vft_id); return dpo_vft->hicn_dpo_del_nh (face_id, hicn_dpo_id->dpoi_index, - &fib_pfx); + prefix); } //Remember to remove the lock from the table when removing the entry return ret; } int -hicn_route_set_strategy (ip46_address_t * prefix, u8 plen, u8 strategy_id) +hicn_route_set_strategy (fib_prefix_t * prefix, u8 strategy_id) { - fib_prefix_t fib_pfx; const dpo_id_t *hicn_dpo_id; dpo_id_t new_dpo_id = DPO_INVALID; int ret; @@ -331,11 +308,8 @@ hicn_route_set_strategy (ip46_address_t * prefix, u8 plen, u8 strategy_id) u32 fib_index; u32 old_vft_id; - /* At this point the face exists in the face table */ - fib_prefix_from_ip46_addr (prefix, &fib_pfx); - fib_pfx.fp_len = plen; - ret = hicn_route_get_dpo (prefix, plen, &hicn_dpo_id, &fib_index); + ret = hicn_route_get_dpo (prefix, &hicn_dpo_id, &fib_index); if (ret == HICN_ERROR_NONE) { @@ -358,7 +332,7 @@ hicn_route_set_strategy (ip46_address_t * prefix, u8 plen, u8 strategy_id) /* the value we got when we registered */ dpo_set (&new_dpo_id, new_dpo_vft->hicn_dpo_get_type (), - (ip46_address_is_ip4 (prefix) ? DPO_PROTO_IP4 : + (ip46_address_is_ip4 (&prefix->fp_addr) ? DPO_PROTO_IP4 : DPO_PROTO_IP6), new_hicn_dpo_idx); /* Here is where we create the "via" like route */ @@ -369,7 +343,7 @@ hicn_route_set_strategy (ip46_address_t * prefix, u8 plen, u8 strategy_id) */ fib_node_index_t new_fib_node_index = fib_table_entry_special_dpo_update (fib_index, - &fib_pfx, + prefix, FIB_SOURCE_PLUGIN_HI, FIB_ENTRY_FLAG_EXCLUSIVE, &new_dpo_id); diff --git a/hicn-plugin/src/route.h b/hicn-plugin/src/route.h index be15b9906..f6e32d8e0 100644 --- a/hicn-plugin/src/route.h +++ b/hicn-plugin/src/route.h @@ -25,7 +25,7 @@ * Retrieve the hicn dpo corresponding to a hicn prefix */ int -hicn_route_get_dpo (const ip46_address_t * prefix, u8 plen, +hicn_route_get_dpo (const fib_prefix_t * prefix, const dpo_id_t ** hicn_dpo, u32 * fib_index); /* @@ -33,24 +33,24 @@ hicn_route_get_dpo (const ip46_address_t * prefix, u8 plen, */ int hicn_route_add (hicn_face_id_t * face_id, u32 len, - const ip46_address_t * prefix, u8 plen); + const fib_prefix_t * prefix); /* * Add new next hops for a prefix route */ int hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, - const ip46_address_t * prefix, u8 plen); + const fib_prefix_t * prefix); /* Remove a route for a name prefix */ -int hicn_route_del (ip46_address_t * prefix, u8 plen); +int hicn_route_del (fib_prefix_t * prefix); /* Remove a next hop route for a name prefix */ -int hicn_route_del_nhop (ip46_address_t * prefix, u8 plen, u32 face_id); +int hicn_route_del_nhop (fib_prefix_t * prefix, u32 face_id); /* Remove a next hop route for a name prefix */ int -hicn_route_set_strategy (ip46_address_t * prefix, u8 plen, u32 strategy_id); +hicn_route_set_strategy (fib_prefix_t * prefix, u32 strategy_id); #endif /* //__HICN_ROUTE__ */ diff --git a/hicn-plugin/src/strategies/strategy_mw_cli.c b/hicn-plugin/src/strategies/strategy_mw_cli.c index 689bce470..50d4d21f0 100644 --- a/hicn-plugin/src/strategies/strategy_mw_cli.c +++ b/hicn-plugin/src/strategies/strategy_mw_cli.c @@ -32,11 +32,10 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm, { clib_error_t *cl_err = 0; int ret = HICN_ERROR_NONE; - ip46_address_t prefix; + fib_prefix_t prefix; hicn_face_id_t faceid = HICN_FACE_NULL; u32 fib_index; u32 weight = HICN_PARAM_FIB_ENTRY_NHOP_WGHT_DFLT; - u32 plen = 0; hicn_dpo_ctx_t *hicn_dpo_ctx; const dpo_id_t *hicn_dpo_id; u32 vft_id; @@ -49,7 +48,7 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm, while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "prefix %U/%u", unformat_ip46_address, - &prefix, IP46_TYPE_ANY, &plen)) + &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) ; else if (unformat (line_input, "face %u", &faceid)) ; @@ -73,18 +72,15 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm, goto done; } - if (((ip46_address_is_zero (&prefix)) || faceid == HICN_FACE_NULL)) + if (((ip46_address_is_zero (&prefix.fp_addr)) || faceid == HICN_FACE_NULL)) { cl_err = clib_error_return (0, "Please specify prefix and a valid faceid..."); goto done; } - fib_prefix_t fib_pfx; - fib_prefix_from_ip46_addr (&prefix, &fib_pfx); - fib_pfx.fp_len = plen; - - ret = hicn_route_get_dpo (&prefix, plen, &hicn_dpo_id, &fib_index); + prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; + ret = hicn_route_get_dpo (&prefix, &hicn_dpo_id, &fib_index); if (ret == HICN_ERROR_NONE) { diff --git a/lib/includes/hicn/compat.h b/lib/includes/hicn/compat.h index b31d01a0d..2796983c6 100644 --- a/lib/includes/hicn/compat.h +++ b/lib/includes/hicn/compat.h @@ -234,7 +234,7 @@ int hicn_packet_get_payload (hicn_format_t format, */ int hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * packet, - ip_prefix_t * prefix, bool is_interest); + ip_address_t * prefix, bool is_interest); /** * @brief Sets the locator of an interest / data packet @@ -246,7 +246,7 @@ int hicn_packet_get_locator (hicn_format_t format, * @return hICN error code */ int hicn_packet_set_locator (hicn_format_t format, hicn_header_t * packet, - const ip_prefix_t * prefix, + const ip_address_t * prefix, bool is_interest); /** @@ -396,9 +396,9 @@ int hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest, const hicn_name_t * name); int hicn_interest_get_locator (hicn_format_t format, const hicn_header_t * interest, - ip_prefix_t * prefix); + ip_address_t * prefix); int hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest, - const ip_prefix_t * prefix); + const ip_address_t * prefix); int hicn_interest_compare (const hicn_header_t * interest_1, const hicn_header_t * interest_2); int hicn_interest_set_lifetime (hicn_header_t * interest, u32 lifetime); @@ -425,9 +425,9 @@ int hicn_data_get_name (hicn_format_t format, const hicn_header_t * data, int hicn_data_set_name (hicn_format_t format, hicn_header_t * data, const hicn_name_t * name); int hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data, - ip_prefix_t * prefix); + ip_address_t * prefix); int hicn_data_set_locator (hicn_format_t format, hicn_header_t * data, - const ip_prefix_t * prefix); + const ip_address_t * prefix); int hicn_data_compare (const hicn_header_t * data_1, const hicn_header_t * data_2); int hicn_data_get_expiry_time (const hicn_header_t * data, u32 * expiry_time); diff --git a/lib/includes/hicn/util/ip_address.h b/lib/includes/hicn/util/ip_address.h index 542e6e4c6..e39d08585 100644 --- a/lib/includes/hicn/util/ip_address.h +++ b/lib/includes/hicn/util/ip_address.h @@ -65,12 +65,15 @@ #define DUMMY_PORT 1234 typedef union { - union { - struct in_addr as_inaddr; - u8 as_u8[4]; - u16 as_u16[2]; - u32 as_u32; - } v4; + struct { + u32 pad[3]; + union { + struct in_addr as_inaddr; + u8 as_u8[4]; + u16 as_u16[2]; + u32 as_u32; + } v4; + }; union { struct in6_addr as_in6addr; u8 as_u8[16]; @@ -121,7 +124,7 @@ extern const ip_address_t IP_ADDRESS_EMPTY; /* IP address */ int ip_address_get_family (const char * ip_address); -int ip_address_len (const ip_address_t * ip_address, int family); +int ip_address_len (int family); int ip_address_ntop (const ip_address_t * ip_address, char *dst, const size_t len, int family); int ip_address_pton (const char *ip_address_str, ip_address_t * ip_address); diff --git a/lib/src/compat.c b/lib/src/compat.c index 68f761ac0..8ec4c83e8 100644 --- a/lib/src/compat.c +++ b/lib/src/compat.c @@ -321,7 +321,7 @@ hicn_packet_get_payload (hicn_format_t format, const hicn_header_t * h, int hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h, - ip_prefix_t * prefix, bool is_interest) + ip_address_t * address, bool is_interest) { const void *locator; int is_ipv4 = (format & HFO_INET); @@ -330,28 +330,24 @@ hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h, if (is_ipv4) { locator = is_interest ? &h->v4.ip.saddr : &h->v4.ip.daddr; - prefix->family = AF_INET; - prefix->len = IPV4_ADDR_LEN_BITS; } else if (is_ipv6) { locator = is_interest ? &h->v6.ip.saddr : &h->v6.ip.daddr; - prefix->family = AF_INET6; - prefix->len = IPV6_ADDR_LEN_BITS; } else { return HICN_LIB_ERROR_NOT_IMPLEMENTED; } - memcpy (prefix->address.buffer, locator, ip_address_len(&prefix->address, prefix->family)); + memcpy (address->as_u8, locator, is_ipv4 ? IPV4_ADDR_LEN : IPV6_ADDR_LEN); return HICN_LIB_ERROR_NONE; } int hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h, - const ip_prefix_t * prefix, bool is_interest) + const ip_address_t * address, bool is_interest) { void *locator; int is_ipv4 = (format & HFO_INET); @@ -370,7 +366,7 @@ hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h, return HICN_LIB_ERROR_INVALID_PARAMETER; } - memcpy (locator, prefix->address.buffer, ip_address_len(&prefix->address, prefix->family)); + memcpy (locator, address->as_u8, is_ipv4 ? IPV4_ADDR_LEN : IPV6_ADDR_LEN); return HICN_LIB_ERROR_NONE; } @@ -953,16 +949,16 @@ hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest, int hicn_interest_get_locator (hicn_format_t format, const hicn_header_t * interest, - ip_prefix_t * prefix) + ip_address_t * address) { - return hicn_packet_get_locator (format, interest, prefix, _INTEREST); + return hicn_packet_get_locator (format, interest, address, _INTEREST); } int hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest, - const ip_prefix_t * prefix) + const ip_address_t * address) { - return hicn_packet_set_locator (format, interest, prefix, _INTEREST); + return hicn_packet_set_locator (format, interest, address, _INTEREST); } int @@ -1045,16 +1041,16 @@ hicn_data_set_name (hicn_format_t format, hicn_header_t * data, int hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data, - ip_prefix_t * prefix) + ip_address_t * address) { - return hicn_packet_get_locator (format, data, prefix, _DATA); + return hicn_packet_get_locator (format, data, address, _DATA); } int hicn_data_set_locator (hicn_format_t format, hicn_header_t * data, - const ip_prefix_t * prefix) + const ip_address_t * address) { - return hicn_packet_set_locator (format, data, prefix, _DATA); + return hicn_packet_set_locator (format, data, address, _DATA); } int diff --git a/lib/src/name.c b/lib/src/name.c index d5ee1d520..2e98a3532 100644 --- a/lib/src/name.c +++ b/lib/src/name.c @@ -96,7 +96,7 @@ hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id, } memcpy (name->buffer, prefix->address.buffer, - ip_address_len(&prefix->address, prefix->family)); + ip_address_len(prefix->family)); *(u32 *) (name->buffer + name->len) = id; return HICN_LIB_ERROR_NONE; diff --git a/lib/src/util/ip_address.c b/lib/src/util/ip_address.c index c54b1fae6..d4fbcaae6 100644 --- a/lib/src/util/ip_address.c +++ b/lib/src/util/ip_address.c @@ -77,7 +77,7 @@ ip_address_get_family (const char * ip_address) } int -ip_address_len (const ip_address_t * ip_address, int family) +ip_address_len (int family) { return (family == AF_INET6) ? IPV6_ADDR_LEN : (family == AF_INET) ? IPV4_ADDR_LEN : 0; @@ -165,7 +165,7 @@ ip_address_to_sockaddr(const ip_address_t * ip_address, int ip_address_cmp(const ip_address_t * ip1, const ip_address_t * ip2, int family) { - return memcmp(ip1, ip2, ip_address_len(ip1, family)); + return memcmp(ip1, ip2, ip_address_len(family)); } int diff --git a/libtransport/CMakeLists.txt b/libtransport/CMakeLists.txt index dc3409c6f..e90d3a2f4 100644 --- a/libtransport/CMakeLists.txt +++ b/libtransport/CMakeLists.txt @@ -138,7 +138,7 @@ list(APPEND LIBRARIES ${LIBPARC_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${HICN_LIBRARIES} - ${VPP_LIBRARY_VPPAPICLIENT} + ${VPP_LIBRARIES} ${ANDROID_LIBRARIES} ${OPENSSL_LIBRARIES} ${WINDOWS_LIBRARIES} diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/hicn/transport/core/content_object.cc index d05239372..6cbcdb29e 100644 --- a/libtransport/src/hicn/transport/core/content_object.cc +++ b/libtransport/src/hicn/transport/core/content_object.cc @@ -154,7 +154,7 @@ ContentObject &ContentObject::setPathLabel(uint32_t path_label) { return *this; } -void ContentObject::setLocator(const ip_prefix_t &ip_address) { +void ContentObject::setLocator(const ip_address_t &ip_address) { if (hicn_data_set_locator(format_, packet_start_, &ip_address) < 0) { throw errors::RuntimeException("Error setting content object locator"); } @@ -162,8 +162,8 @@ void ContentObject::setLocator(const ip_prefix_t &ip_address) { return; } -ip_prefix_t ContentObject::getLocator() const { - ip_prefix_t ip; +ip_address_t ContentObject::getLocator() const { + ip_address_t ip; if (hicn_data_get_locator(format_, packet_start_, &ip) < 0) { throw errors::RuntimeException("Error getting content object locator."); diff --git a/libtransport/src/hicn/transport/core/content_object.h b/libtransport/src/hicn/transport/core/content_object.h index ef5144c23..5af548fe4 100644 --- a/libtransport/src/hicn/transport/core/content_object.h +++ b/libtransport/src/hicn/transport/core/content_object.h @@ -60,9 +60,9 @@ class ContentObject : public Packet { ContentObject &setPathLabel(uint32_t path_label); - void setLocator(const ip_prefix_t &ip_address) override; + void setLocator(const ip_address_t &ip_address) override; - ip_prefix_t getLocator() const override; + ip_address_t getLocator() const override; void setLifetime(uint32_t lifetime) override; diff --git a/libtransport/src/hicn/transport/core/forwarder_interface.h b/libtransport/src/hicn/transport/core/forwarder_interface.h index a89ed8a3c..380ce76bd 100644 --- a/libtransport/src/hicn/transport/core/forwarder_interface.h +++ b/libtransport/src/hicn/transport/core/forwarder_interface.h @@ -49,10 +49,6 @@ class ForwarderInterface { mtu_(1500), output_interface_(""), content_store_reserved_(standard_cs_reserved) { - inet_address_.family = AF_INET; - inet_address_.len = IPV4_ADDR_LEN; - inet6_address_.family = AF_INET6; - inet6_address_.len = IPV6_ADDR_LEN; } public: @@ -135,8 +131,8 @@ class ForwarderInterface { protected: ConnectorType &connector_; - ip_prefix_t inet_address_; - ip_prefix_t inet6_address_; + ip_address_t inet_address_; + ip_address_t inet6_address_; uint16_t mtu_; std::string output_interface_; uint32_t content_store_reserved_; diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.c b/libtransport/src/hicn/transport/core/hicn_binary_api.c index 8fde516fd..9f93953ab 100644 --- a/libtransport/src/hicn/transport/core/hicn_binary_api.c +++ b/libtransport/src/hicn/transport/core/hicn_binary_api.c @@ -39,6 +39,8 @@ #include <vnet/ip/format.h> #include <vnet/ip/ip4_packet.h> #include <vnet/ip/ip6_packet.h> +#include <vnet/ip/ip_types_api.h> +#include <vnet/fib/fib_types.h> #include <vpp_plugins/hicn/error.h> #include <vpp_plugins/hicn/hicn_api.h> @@ -58,7 +60,6 @@ #undef vl_api_version #undef vl_printfun #undef vl_endianfun - ///////////////////////////////////////////////////// const char *HICN_ERROR_STRING[] = { #define _(a, b, c) c, @@ -67,6 +68,24 @@ const char *HICN_ERROR_STRING[] = { }; ///////////////////////////////////////////////////// +/*********************** Missing Symbol in vpp libraries *************************/ +u8 * +format_vl_api_address_union (u8 * s, va_list * args) +{ + const vl_api_address_union_t *addr = + va_arg (*args, vl_api_address_union_t *); + vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t); + + if (ADDRESS_IP6 == af) + s = format (s, "%U", format_ip6_address, addr->ip6); + else + s = format (s, "%U", format_ip4_address, addr->ip4); + + return s; +} + +/*********************************************************************************/ + static context_store_t context_store = { .global_pointers_map_index = 0, }; @@ -92,13 +111,14 @@ int hicn_binary_api_register_prod_app( CONTEXT_SAVE(context_store, api, mp) - mp->len = (u8)input_params->prefix->len; + fib_prefix_t prefix; + memcpy(&prefix.fp_addr.as_u64, &input_params->prefix->address.as_u64, sizeof(ip46_address_t)); + prefix.fp_len = input_params->prefix->len; + prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; + ip_prefix_encode(&prefix, &mp->prefix); mp->swif = clib_host_to_net_u32(input_params->swif); mp->cs_reserved = clib_host_to_net_u32(input_params->cs_reserved); - mp->prefix[0] = clib_host_to_net_u64(input_params->prefix->address.as_u64[0]); - mp->prefix[1] = clib_host_to_net_u64(input_params->prefix->address.as_u64[1]); - return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp); } @@ -112,8 +132,8 @@ static void vl_api_hicn_api_register_prod_app_reply_t_handler( vpp_binary_api_set_ret_value(binary_api->vpp_api, clib_net_to_host_u32(mp->retval)); params->cs_reserved = mp->cs_reserved; - params->prod_addr->address.as_u64[0] = mp->prod_addr[0]; - params->prod_addr->address.as_u64[1] = mp->prod_addr[1]; + params->prod_addr = (ip_address_t *)malloc(sizeof(ip_address_t)); + ip_address_decode(&mp->prod_addr, (ip46_address_t *)(params->prod_addr)); params->face_id = clib_net_to_host_u32(mp->faceid); vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); @@ -147,9 +167,8 @@ static void vl_api_hicn_api_register_cons_app_reply_t_handler( vpp_binary_api_set_ret_value(binary_api->vpp_api, clib_net_to_host_u32(mp->retval)); - params->src4->address.v4.as_u32 = clib_net_to_host_u32(mp->src_addr4); - params->src6->address.as_u64[0] = clib_net_to_host_u64(mp->src_addr6[0]); - params->src6->address.as_u64[1] = clib_net_to_host_u64(mp->src_addr6[1]); + ip_address_decode(&mp->src_addr4, (ip46_address_t *)params->src4); + ip_address_decode(&mp->src_addr6, (ip46_address_t *)params->src6); params->face_id = clib_host_to_net_u32(mp->faceid); vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api); @@ -165,11 +184,10 @@ int hicn_binary_api_register_route( M(HICN_API_ROUTE_NHOPS_ADD, mp); CONTEXT_SAVE(context_store, api, mp) - - mp->prefix[0] = input_params->prefix->address.as_u64[0]; - mp->prefix[1] = input_params->prefix->address.as_u64[1]; - mp->len = input_params->prefix->len; - mp->face_ids[0] = input_params->face_id; + fib_prefix_t prefix; + memcpy(&prefix.fp_addr.as_u64, &input_params->prefix->address.as_u64, sizeof(ip46_address_t)); + prefix.fp_len = input_params->prefix->len; + mp->face_ids[0] = clib_host_to_net_u32(input_params->face_id); mp->n_faces = 1; return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp); diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.h b/libtransport/src/hicn/transport/core/hicn_binary_api.h index b09b5f4a7..50590917f 100644 --- a/libtransport/src/hicn/transport/core/hicn_binary_api.h +++ b/libtransport/src/hicn/transport/core/hicn_binary_api.h @@ -40,13 +40,13 @@ typedef struct { typedef struct { uint32_t cs_reserved; - ip_prefix_t* prod_addr; + ip_address_t* prod_addr; uint32_t face_id; } hicn_producer_output_params; typedef struct { - ip_prefix_t* src4; - ip_prefix_t* src6; + ip_address_t* src4; + ip_address_t* src6; uint32_t face_id; } hicn_consumer_output_params; diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/hicn/transport/core/interest.cc index 6465053de..166632f0a 100644 --- a/libtransport/src/hicn/transport/core/interest.cc +++ b/libtransport/src/hicn/transport/core/interest.cc @@ -119,7 +119,7 @@ void Interest::setName(Name &&name) { } } -void Interest::setLocator(const ip_prefix_t &ip_address) { +void Interest::setLocator(const ip_address_t &ip_address) { if (hicn_interest_set_locator(format_, packet_start_, &ip_address) < 0) { throw errors::RuntimeException("Error setting interest locator."); } @@ -127,8 +127,8 @@ void Interest::setLocator(const ip_prefix_t &ip_address) { return; } -ip_prefix_t Interest::getLocator() const { - ip_prefix_t ip; +ip_address_t Interest::getLocator() const { + ip_address_t ip; if (hicn_interest_get_locator(format_, packet_start_, &ip) < 0) { throw errors::RuntimeException("Error getting interest locator."); diff --git a/libtransport/src/hicn/transport/core/interest.h b/libtransport/src/hicn/transport/core/interest.h index 12fd597e5..48c833a73 100644 --- a/libtransport/src/hicn/transport/core/interest.h +++ b/libtransport/src/hicn/transport/core/interest.h @@ -55,9 +55,9 @@ class Interest void setName(Name &&name) override; - void setLocator(const ip_prefix_t &ip_address) override; + void setLocator(const ip_address_t &ip_address) override; - ip_prefix_t getLocator() const override; + ip_address_t getLocator() const override; void setLifetime(uint32_t lifetime) override; diff --git a/libtransport/src/hicn/transport/core/packet.h b/libtransport/src/hicn/transport/core/packet.h index 825c4c9dd..4ec93205a 100644 --- a/libtransport/src/hicn/transport/core/packet.h +++ b/libtransport/src/hicn/transport/core/packet.h @@ -133,9 +133,9 @@ class Packet : public std::enable_shared_from_this<Packet> { void dump() const; - virtual void setLocator(const ip_prefix_t &locator) = 0; + virtual void setLocator(const ip_address_t &locator) = 0; - virtual ip_prefix_t getLocator() const = 0; + virtual ip_address_t getLocator() const = 0; void setSignatureTimestamp(const uint64_t ×tamp); diff --git a/libtransport/src/hicn/transport/core/prefix.cc b/libtransport/src/hicn/transport/core/prefix.cc index 6b87ccd1f..b7ddce73a 100644 --- a/libtransport/src/hicn/transport/core/prefix.cc +++ b/libtransport/src/hicn/transport/core/prefix.cc @@ -33,7 +33,7 @@ namespace transport { namespace core { -Prefix::Prefix() { std::memset(&ip_address_, 0, sizeof(ip_prefix_t)); } +Prefix::Prefix() { std::memset(&ip_prefix_, 0, sizeof(ip_prefix_t)); } Prefix::Prefix(const char *prefix) : Prefix(std::string(prefix)) {} @@ -66,9 +66,9 @@ Prefix::Prefix(const core::Name &content_name, uint16_t prefix_length) { throw errors::InvalidIpAddressException(); } - ip_address_ = content_name.toIpAddress(); - ip_address_.len = prefix_length; - ip_address_.family = family; + ip_prefix_ = content_name.toIpAddress(); + ip_prefix_.len = prefix_length; + ip_prefix_.family = family; } void Prefix::buildPrefix(std::string &prefix, uint16_t prefix_length, @@ -77,20 +77,20 @@ void Prefix::buildPrefix(std::string &prefix, uint16_t prefix_length, throw errors::InvalidIpAddressException(); } - int ret = inet_pton(family, prefix.c_str(), ip_address_.address.buffer); + int ret = inet_pton(family, prefix.c_str(), ip_prefix_.address.buffer); if (ret != 1) { throw errors::InvalidIpAddressException(); } - ip_address_.len = prefix_length; - ip_address_.family = family; + ip_prefix_.len = prefix_length; + ip_prefix_.family = family; } std::unique_ptr<Sockaddr> Prefix::toSockaddr() { Sockaddr *ret = nullptr; - switch (ip_address_.family) { + switch (ip_prefix_.family) { case AF_INET6: ret = (Sockaddr *)new Sockaddr6; break; @@ -101,39 +101,39 @@ std::unique_ptr<Sockaddr> Prefix::toSockaddr() { throw errors::InvalidIpAddressException(); } - if (ip_prefix_to_sockaddr(&ip_address_, ret) < 0) { + if (ip_prefix_to_sockaddr(&ip_prefix_, ret) < 0) { throw errors::InvalidIpAddressException(); } return std::unique_ptr<Sockaddr>(ret); } -uint16_t Prefix::getPrefixLength() { return ip_address_.len; } +uint16_t Prefix::getPrefixLength() { return ip_prefix_.len; } Prefix &Prefix::setPrefixLength(uint16_t prefix_length) { - ip_address_.len = prefix_length; + ip_prefix_.len = prefix_length; return *this; } -int Prefix::getAddressFamily() { return ip_address_.family; } +int Prefix::getAddressFamily() { return ip_prefix_.family; } Prefix &Prefix::setAddressFamily(int address_family) { - ip_address_.family = address_family; + ip_prefix_.family = address_family; return *this; } std::string Prefix::getNetwork() const { - if (!checkPrefixLengthAndAddressFamily(ip_address_.len, - ip_address_.family)) { + if (!checkPrefixLengthAndAddressFamily(ip_prefix_.len, + ip_prefix_.family)) { throw errors::InvalidIpAddressException(); } std::size_t size = - ip_address_.family == 4 + AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN; + ip_prefix_.family == 4 + AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN; std::string network(size, 0); - if (ip_prefix_ntop_short(&ip_address_, (char *)network.c_str(), size) < 0) { + if (ip_prefix_ntop_short(&ip_prefix_, (char *)network.c_str(), size) < 0) { throw errors::RuntimeException( "Impossible to retrieve network from ip address."); } @@ -147,7 +147,7 @@ Name Prefix::getName() const { } Prefix &Prefix::setNetwork(std::string &network) { - if (!inet_pton(AF_INET6, network.c_str(), ip_address_.address.buffer)) { + if (!inet_pton(AF_INET6, network.c_str(), ip_prefix_.address.buffer)) { throw errors::RuntimeException("The network name is not valid."); } @@ -157,16 +157,16 @@ Prefix &Prefix::setNetwork(std::string &network) { Name Prefix::makeRandomName() const { srand((unsigned int)time(nullptr)); - if (ip_address_.family == AF_INET6) { + if (ip_prefix_.family == AF_INET6) { std::default_random_engine eng((std::random_device())()); std::uniform_int_distribution<uint32_t> idis( 0, std::numeric_limits<uint32_t>::max()); uint64_t random_number = idis(eng); - uint32_t hash_size_bits = IPV6_ADDR_LEN_BITS - ip_address_.len; + uint32_t hash_size_bits = IPV6_ADDR_LEN_BITS - ip_prefix_.len; uint64_t ip_address[2]; - memcpy(ip_address, ip_address_.address.buffer, sizeof(uint64_t)); - memcpy(ip_address + 1, ip_address_.address.buffer + 8, sizeof(uint64_t)); + memcpy(ip_address, ip_prefix_.address.buffer, sizeof(uint64_t)); + memcpy(ip_address + 1, ip_prefix_.address.buffer + 8, sizeof(uint64_t)); std::string network(IPV6_ADDR_LEN * 3, 0); // Let's do the magic ;) @@ -179,7 +179,7 @@ Name Prefix::makeRandomName() const { ip_address[1] |= random_number >> (sizeof(uint64_t) * 8 - shift_size); - if (!inet_ntop(ip_address_.family, ip_address, (char *)network.c_str(), + if (!inet_ntop(ip_prefix_.family, ip_address, (char *)network.c_str(), IPV6_ADDR_LEN * 3)) { throw errors::RuntimeException( "Impossible to retrieve network from ip address."); @@ -208,7 +208,7 @@ bool Prefix::checkPrefixLengthAndAddressFamily(uint16_t prefix_length, return true; } -ip_prefix_t &Prefix::toIpAddressStruct() { return ip_address_; } +ip_prefix_t &Prefix::toIpPrefixStruct() { return ip_prefix_; } } // namespace core diff --git a/libtransport/src/hicn/transport/core/prefix.h b/libtransport/src/hicn/transport/core/prefix.h index 022e2bec2..af7c705cf 100644 --- a/libtransport/src/hicn/transport/core/prefix.h +++ b/libtransport/src/hicn/transport/core/prefix.h @@ -52,7 +52,7 @@ class Prefix { Name makeRandomName() const; - ip_prefix_t &toIpAddressStruct(); + ip_prefix_t &toIpPrefixStruct(); private: static bool checkPrefixLengthAndAddressFamily(uint16_t prefix_length, @@ -60,7 +60,7 @@ class Prefix { void buildPrefix(std::string &prefix, uint16_t prefix_length, int family); - ip_prefix_t ip_address_; + ip_prefix_t ip_prefix_; }; } // end namespace core diff --git a/libtransport/src/hicn/transport/core/raw_socket_interface.cc b/libtransport/src/hicn/transport/core/raw_socket_interface.cc index ef365fce7..bb4e083e1 100644 --- a/libtransport/src/hicn/transport/core/raw_socket_interface.cc +++ b/libtransport/src/hicn/transport/core/raw_socket_interface.cc @@ -43,9 +43,8 @@ void RawSocketInterface::connect(bool is_consumer) { // Get interface ip address struct sockaddr_in6 address = {0}; utils::retrieveInterfaceAddress(output_interface_, &address); - inet6_address_.family = address.sin6_family; - std::memcpy(inet6_address_.address.buffer, &address.sin6_addr, + std::memcpy(&inet6_address_.v6.as_u8, &address.sin6_addr, sizeof(address.sin6_addr)); connector_.connect(output_interface_, remote_mac_address_); } diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc index c8a4f9c88..598b692c9 100644 --- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc +++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc @@ -87,8 +87,8 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() { void VPPForwarderInterface::consumerConnection() { hicn_consumer_input_params input = {0}; hicn_consumer_output_params output = {0}; - ip_prefix_t ip4_address; - ip_prefix_t ip6_address; + ip_address_t ip4_address; + ip_address_t ip6_address; output.src4 = &ip4_address; output.src6 = &ip6_address; @@ -102,13 +102,9 @@ void VPPForwarderInterface::consumerConnection() { throw errors::RuntimeException(hicn_binary_api_get_error_string(ret)); } - inet_address_.family = AF_INET; - inet_address_.len = output.src4->len; - std::memcpy(inet_address_.address.buffer, output.src4->address.buffer, IPV6_ADDR_LEN); + std::memcpy(inet_address_.v4.as_u8, output.src4->as_u8, IPV4_ADDR_LEN); - inet6_address_.family = AF_INET6; - inet6_address_.len = output.src6->len; - std::memcpy(inet6_address_.address.buffer, output.src6->address.buffer, IPV6_ADDR_LEN); + std::memcpy(inet6_address_.v6.as_u8, output.src6->as_u8, IPV6_ADDR_LEN); } void VPPForwarderInterface::producerConnection() { @@ -141,10 +137,10 @@ void VPPForwarderInterface::connect(bool is_consumer) { } void VPPForwarderInterface::registerRoute(Prefix &prefix) { - auto &addr = prefix.toIpAddressStruct(); + ip_prefix_t &addr = prefix.toIpPrefixStruct(); - // Same ip address for input and outurt params - ip_prefix_t ip_address; + ip_prefix_t producer_prefix; + ip_address_t producer_locator; if (face_id_ == uint32_t(~0)) { hicn_producer_input_params input; @@ -153,8 +149,8 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) { hicn_producer_output_params output; std::memset(&output, 0, sizeof(output)); - input.prefix = &ip_address; - output.prod_addr = &ip_address; + input.prefix = &producer_prefix; + output.prod_addr = &producer_locator; // Here we have to ask to the actual connector what is the // memif_id, since this function should be called after the @@ -174,21 +170,18 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) { } if (addr.family == AF_INET6) { - inet6_address_.len = output.prod_addr->len; - inet6_address_.address.as_u64[0] = output.prod_addr->address.as_u64[0]; - inet6_address_.address.as_u64[1] = output.prod_addr->address.as_u64[1]; + inet6_address_.v6.as_u64[0] = output.prod_addr->v6.as_u64[0]; + inet6_address_.v6.as_u64[1] = output.prod_addr->v6.as_u64[1]; } else { - inet_address_.len = output.prod_addr->len; // The ipv4 is written in the last 4 bytes of the ipv6 address, so we need // to copy from the byte 12 - inet_address_.address.as_u64[0] = output.prod_addr->address.as_u64[0]; - inet_address_.address.as_u64[1] = output.prod_addr->address.as_u64[1]; + inet_address_.v4.as_u32 = output.prod_addr->v4.as_u32; } face_id_ = output.face_id; } else { hicn_producer_set_route_params params; - params.prefix = &ip_address; + params.prefix = &producer_prefix; params.prefix->address.as_u64[0] = addr.address.as_u64[0]; params.prefix->address.as_u64[1] = addr.address.as_u64[1]; params.prefix->family = addr.family == AF_INET6 ? AF_INET6 : AF_INET; diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 4e73ab2b0..3ed6f9bf3 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -47,6 +47,7 @@ endif() set(SUFFIX "") if (${LIBTRANSPORT_LIBRARIES} MATCHES ".*-memif.*") set(SUFFIX "-memif") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-unresolved-symbols=ignore-in-shared-libs") endif() set(HICN_UTILS "${HICN_UTILS}${SUFFIX}") |