diff options
Diffstat (limited to 'hicn-plugin')
-rw-r--r-- | hicn-plugin/CMakeLists.txt | 31 | ||||
-rw-r--r-- | hicn-plugin/src/cli.c | 93 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_app_cli.c | 13 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod.c | 35 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod.h | 4 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod_node.c | 24 | ||||
-rw-r--r-- | hicn-plugin/src/hicn.api | 59 | ||||
-rw-r--r-- | hicn-plugin/src/hicn_api.c | 91 | ||||
-rw-r--r-- | hicn-plugin/src/hicn_api_test.c | 154 | ||||
-rw-r--r-- | hicn-plugin/src/punt.c | 83 | ||||
-rw-r--r-- | hicn-plugin/src/punt.h | 23 | ||||
-rw-r--r-- | hicn-plugin/src/route.c | 74 | ||||
-rw-r--r-- | hicn-plugin/src/route.h | 12 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/strategy_mw_cli.c | 14 |
14 files changed, 346 insertions, 364 deletions
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) { |