diff options
Diffstat (limited to 'hicn-plugin/src/faces/app')
-rw-r--r-- | hicn-plugin/src/faces/app/address_mgr.c | 20 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_app_cli.c | 88 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_cons.c | 18 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod.c | 317 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod.h | 13 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod_node.c | 91 |
6 files changed, 220 insertions, 327 deletions
diff --git a/hicn-plugin/src/faces/app/address_mgr.c b/hicn-plugin/src/faces/app/address_mgr.c index 1674379c4..2d5894ab8 100644 --- a/hicn-plugin/src/faces/app/address_mgr.c +++ b/hicn-plugin/src/faces/app/address_mgr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2017-2020 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -36,7 +36,6 @@ #include "../../infra.h" #include "../../error.h" #include "../face.h" -#include "../ip/face_ip.h" #include "../../strategy_dpo_ctx.h" #include "../../route.h" @@ -134,26 +133,25 @@ get_two_ip6_addresses (ip6_address_t * appif_addr, ip6_address_t * nh_addr) fib_pfx.fp_proto = FIB_PROTOCOL_IP6; fib_pfx.fp_len = ADDR_MGR_IP6_LEN; + + fib_index = fib_table_find (fib_pfx.fp_proto, 0); + /* At this point the face exists in the face table */ do { /* Check if the route already exist in the fib */ fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 1, appif_addr->as_u8); - fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); + fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); + //fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); if (fib_entry_index != FIB_NODE_INDEX_INVALID) { fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, nh_addr->as_u8); - fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); + fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, - FIB_SOURCE_PRIORITY_HI); + // fib_table_unlock (fib_index, fib_pfx.fp_proto, + // FIB_SOURCE_PRIORITY_HI); } if (fib_entry_index != FIB_NODE_INDEX_INVALID) { diff --git a/hicn-plugin/src/faces/app/face_app_cli.c b/hicn-plugin/src/faces/app/face_app_cli.c index 1e8eb6a5b..36f8bf3f7 100644 --- a/hicn-plugin/src/faces/app/face_app_cli.c +++ b/hicn-plugin/src/faces/app/face_app_cli.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2017-2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -18,20 +18,19 @@ #include <vlib/vlib.h> #include <vnet/ip/ip6_packet.h> -#include "../ip/face_ip.h" -#include "../ip/dpo_ip.h" +//#include "../face_dpo.h" #include "../face.h" #include "face_prod.h" #include "face_cons.h" -#define HICN_FACE_NONE 0 +#define HICN_FACE_NONE 0 #define HICN_FACE_DELETE 1 -#define HICN_FACE_ADD 2 +#define HICN_FACE_ADD 2 static clib_error_t * -hicn_face_app_cli_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_face_app_cli_set_command_fn (vlib_main_t *vm, + unformat_input_t *main_input, + vlib_cli_command_t *cmd) { vnet_main_t *vnm = vnet_get_main (); fib_prefix_t prefix; @@ -43,7 +42,6 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, int face_op = HICN_FACE_NONE; int prod = 0; - /* Get a line of input. */ unformat_input_t _line_input, *line_input = &_line_input; if (!unformat_user (main_input, unformat_line_input, line_input)) @@ -57,8 +55,8 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, { face_op = HICN_FACE_DELETE; } - else if (face_op == HICN_FACE_DELETE - && unformat (line_input, "id %d", &face_id1)) + else if (face_op == HICN_FACE_DELETE && + unformat (line_input, "id %d", &face_id1)) ; else if (unformat (line_input, "add")) { @@ -66,13 +64,12 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, } else if (face_op == HICN_FACE_ADD) { - if (unformat (line_input, "intfc %U", - unformat_vnet_sw_interface, vnm, &sw_if)) + if (unformat (line_input, "intfc %U", unformat_vnet_sw_interface, + vnm, &sw_if)) ; - else - if (unformat - (line_input, "prod prefix %U/%d", unformat_ip46_address, - &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len)) + else if (unformat (line_input, "prod prefix %U/%d", + unformat_ip46_address, &prefix.fp_addr, + IP46_TYPE_ANY, &prefix.fp_len)) { prod = 1; } @@ -82,10 +79,9 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, ; else { - return clib_error_return (0, "%s '%U'", - get_error_string - (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); + return clib_error_return ( + 0, "%s '%U'", get_error_string (HICN_ERROR_CLI_INVAL), + format_unformat_error, line_input); } } else @@ -117,20 +113,17 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, if (prod) { - prefix.fp_proto = - ip46_address_is_ip4 (&prefix. - fp_addr) ? FIB_PROTOCOL_IP4 : - FIB_PROTOCOL_IP6; - rv = - hicn_face_prod_add (&prefix, sw_if, &cs_reserved, &prod_addr, - &face_id1); + prefix.fp_proto = ip46_address_is_ip4 (&prefix.fp_addr) ? + FIB_PROTOCOL_IP4 : + FIB_PROTOCOL_IP6; + rv = hicn_face_prod_add (&prefix, sw_if, &cs_reserved, &prod_addr, + &face_id1); if (rv == HICN_ERROR_NONE) { u8 *sbuf = NULL; - sbuf = - format (sbuf, "Face id: %d, producer address %U", face_id1, - format_ip46_address, &prod_addr, - 0 /*IP46_ANY_TYPE */ ); + sbuf = format (sbuf, "Face id: %d, producer address %U", + face_id1, format_ip46_address, &prod_addr, + 0 /*IP46_ANY_TYPE */); vlib_cli_output (vm, "%s", sbuf); } else @@ -140,17 +133,16 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, } else { - rv = - hicn_face_cons_add (&cons_addr4, &cons_addr6, sw_if, &face_id1, - &face_id2); + rv = hicn_face_cons_add (&cons_addr4, &cons_addr6, sw_if, + &face_id1, &face_id2); if (rv == HICN_ERROR_NONE) { u8 *sbuf = NULL; - sbuf = - format (sbuf, - "Face id: %d, address v4 %U, face id: %d address v6 %U", - face_id1, format_ip4_address, &cons_addr4, face_id2, - format_ip6_address, &cons_addr6); + sbuf = format ( + sbuf, + "Face id: %d, address v4 %U, face id: %d address v6 %U", + face_id1, format_ip4_address, &cons_addr4, face_id2, + format_ip6_address, &cons_addr6); vlib_cli_output (vm, "%s", sbuf); } else @@ -164,7 +156,7 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, { hicn_face_t *face = hicn_dpoi_get_from_idx (face_id1); - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS) + if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) rv = hicn_face_cons_del (face_id1); else rv = hicn_face_prod_del (face_id1); @@ -182,20 +174,18 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, return clib_error_return (0, "Operation (%d) not implemented", face_op); break; } - return (rv == HICN_ERROR_NONE) ? 0 : clib_error_return (0, "%s\n", - get_error_string - (rv)); + return (rv == HICN_ERROR_NONE) ? + 0 : + clib_error_return (0, "%s\n", get_error_string (rv)); } /* cli declaration for 'cfg face' */ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (hicn_face_app_cli_set_command, static) = -{ +VLIB_CLI_COMMAND (hicn_face_app_cli_set_command, static) = { .path = "hicn face app", - .short_help = "hicn face app {add intfc <sw_if> { prod prefix <hicn_prefix> cs_size <size_in_packets>} {cons} | {del <face_id>}", + .short_help = "hicn face app {add intfc <sw_if> { prod prefix <hicn_prefix> " + "cs_size <size_in_packets>} {cons} | {del <face_id>}", .function = hicn_face_app_cli_set_command_fn, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/app/face_cons.c b/hicn-plugin/src/faces/app/face_cons.c index e51201c21..d44ba1a2b 100644 --- a/hicn-plugin/src/faces/app/face_cons.c +++ b/hicn-plugin/src/faces/app/face_cons.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2017-2020 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -57,10 +57,12 @@ hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, ip46_address_t nh_addr = to_ip46 (0, (u8 *) nh_addr4); - hicn_iface_ip_add (&if_ip, &nh_addr, swif, faceid1); + index_t adj_index = adj_nbr_find(FIB_PROTOCOL_IP4, VNET_LINK_IP4, &nh_addr, swif); + + hicn_iface_add (&nh_addr, swif, faceid1, DPO_PROTO_IP4, adj_index); hicn_face_t *face = hicn_dpoi_get_from_idx (*faceid1); - face->shared.flags |= HICN_FACE_FLAGS_APPFACE_CONS; + face->flags |= HICN_FACE_FLAGS_APPFACE_CONS; get_two_ip6_addresses (&(if_ip.ip6), nh_addr6); ip6_add_del_interface_address (vm, @@ -68,10 +70,12 @@ hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, &(if_ip.ip6), ADDR_MGR_IP6_CONS_LEN, 0 /* is_del */ ); - hicn_iface_ip_add (&if_ip, (ip46_address_t *) nh_addr6, swif, faceid2); + adj_index = adj_nbr_find(FIB_PROTOCOL_IP6, VNET_LINK_IP6, &nh_addr, swif); + + hicn_iface_add ((ip46_address_t *) nh_addr6, swif, faceid2, DPO_PROTO_IP6, adj_index); face = hicn_dpoi_get_from_idx (*faceid2); - face->shared.flags |= HICN_FACE_FLAGS_APPFACE_CONS; + face->flags |= HICN_FACE_FLAGS_APPFACE_CONS; return HICN_ERROR_NONE; } @@ -84,9 +88,9 @@ hicn_face_cons_del (hicn_face_id_t face_id) hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS) + if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) { - return hicn_face_ip_del (face_id); + return hicn_face_del (face_id); } else { diff --git a/hicn-plugin/src/faces/app/face_prod.c b/hicn-plugin/src/faces/app/face_prod.c index ae59719ce..16b6e6158 100644 --- a/hicn-plugin/src/faces/app/face_prod.c +++ b/hicn-plugin/src/faces/app/face_prod.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2017-2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -30,28 +30,23 @@ hicn_face_prod_state_t *face_state_vec; u32 *face_state_pool; static int -hicn_app_state_create (u32 swif, fib_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); u32 *swif_app; u8 found = 0; - /* *INDENT-OFF* */ - pool_foreach (swif_app, face_state_pool,{ - if (*swif_app == swif) - { - found = 1; - } - } - ); - /* *INDENT-ON* */ + pool_foreach (swif_app, face_state_pool) + if (*swif_app == swif) + { + found = 1; + } if (found) return HICN_ERROR_APPFACE_ALREADY_ENABLED; - /* Create the appif and store in the vector */ vec_validate (face_state_vec, swif); clib_memcpy (&(face_state_vec[swif].prefix), prefix, sizeof (fib_prefix_t)); @@ -63,15 +58,13 @@ hicn_app_state_create (u32 swif, fib_prefix_t * prefix) int ret = HICN_ERROR_NONE; if (ip46_address_is_ip4 (&(prefix->fp_addr))) { - ret = - vnet_feature_enable_disable ("ip4-unicast", "hicn-face-prod-input", - swif, 1, 0, 0); + ret = vnet_feature_enable_disable ("ip4-unicast", "hicn-face-prod-input", + swif, 1, 0, 0); } else { - ret = - vnet_feature_enable_disable ("ip6-unicast", "hicn-face-prod-input", - swif, 1, 0, 0); + ret = vnet_feature_enable_disable ("ip6-unicast", "hicn-face-prod-input", + swif, 1, 0, 0); } return ret == 0 ? HICN_ERROR_NONE : HICN_ERROR_APPFACE_FEATURE; @@ -87,33 +80,28 @@ hicn_app_state_del (u32 swif) u32 *swif_app = NULL; u8 found = 0; fib_prefix_t *prefix; - /* *INDENT-OFF* */ - pool_foreach (temp, face_state_pool,{ - if (*temp == swif) - { - found = 1; - swif_app = temp; - } - } - ); - /* *INDENT-ON* */ + pool_foreach (temp, face_state_pool) + if (*temp == swif) + { + found = 1; + swif_app = temp; + } - prefix = &(face_state_vec[swif].prefix); if (!found) return HICN_ERROR_APPFACE_NOT_FOUND; + prefix = &(face_state_vec[swif].prefix); + int ret = HICN_ERROR_NONE; if (ip46_address_is_ip4 (&prefix->fp_addr)) { - ret = - vnet_feature_enable_disable ("ip4-unicast", "hicn-face-prod-input", - swif, 0, 0, 0); + ret = vnet_feature_enable_disable ("ip4-unicast", "hicn-face-prod-input", + swif, 0, 0, 0); } else { - ret = - vnet_feature_enable_disable ("ip6-unicast", "hicn-face-prod-input", - swif, 0, 0, 0); + ret = vnet_feature_enable_disable ("ip6-unicast", "hicn-face-prod-input", + swif, 0, 0, 0); } pool_put (face_state_pool, swif_app); @@ -123,8 +111,8 @@ hicn_app_state_del (u32 swif) } int -hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, - ip46_address_t * prod_addr, hicn_face_id_t * faceid) +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 (); vnet_main_t *vnm = vnet_get_main (); @@ -132,7 +120,7 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, hicn_main_t *hm = &hicn_main; ip46_address_t local_app_ip; - ip46_address_t remote_app_ip; + CLIB_UNUSED (ip46_address_t remote_app_ip); u32 if_flags = 0; if (!hm->is_enabled) @@ -160,28 +148,22 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, { return HICN_ERROR_APPFACE_PROD_PREFIX_NULL; } + + u8 isv6 = ip46_address_is_ip4 (prod_addr); + index_t adj_index = + adj_nbr_find (isv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4, + isv6 ? VNET_LINK_IP6 : VNET_LINK_IP4, prod_addr, sw_if); + /* * Check if a producer face is already existing for the same prefix * and sw_if */ - if (ip46_address_is_ip4 (&prefix->fp_addr)) - { - face = - hicn_face_ip4_get (&(prefix->fp_addr.ip4), sw_if, - &hicn_face_ip_remote_hashtb); - } - else - { - face = - hicn_face_ip6_get (&(prefix->fp_addr.ip6), sw_if, - &hicn_face_ip_remote_hashtb); - if (face != NULL) - return HICN_ERROR_FACE_ALREADY_CREATED; - } + face = + hicn_face_get (&(prefix->fp_addr), sw_if, &hicn_face_hashtb, adj_index); if (face != NULL) { - if (!(face->shared.flags & HICN_FACE_FLAGS_DELETED)) + if (!(face->flags & HICN_FACE_FLAGS_DELETED)) return HICN_ERROR_FACE_ALREADY_CREATED; /* @@ -189,19 +171,17 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, * producer's prefix. */ /* It should never happens, this is a safety check. */ - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS) + if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) return HICN_ERROR_FACE_ALREADY_CREATED; /* If the face exists but is marked as deleted, undelete it */ - if (face->shared.flags & HICN_FACE_FLAGS_DELETED) + if (face->flags & HICN_FACE_FLAGS_DELETED) { /* * remove the deleted flag and retrieve the face * local addr */ - face->shared.flags &= HICN_FACE_FLAGS_DELETED; - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - local_app_ip = prod_face->ip_face.local_addr; + face->flags &= HICN_FACE_FLAGS_DELETED; } } else @@ -216,15 +196,13 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, ip4_address_t local_app_ip4; ip4_address_t remote_app_ip4; get_two_ip4_addresses (&local_app_ip4, &remote_app_ip4); - ip4_add_del_interface_address (vm, - sw_if, - &local_app_ip4, 31, 0 /* is_del */ ); - local_app_ip = to_ip46 ( /* isv6 */ 0, local_app_ip4.as_u8); - remote_app_ip = to_ip46 ( /* isv6 */ 0, remote_app_ip4.as_u8); - - ret = - hicn_face_ip_add (&local_app_ip, &remote_app_ip, sw_if, faceid, - HICN_FACE_FLAGS_APPFACE_PROD); + ip4_add_del_interface_address (vm, sw_if, &local_app_ip4, 31, + 0 /* is_del */); + local_app_ip = to_ip46 (/* isv6 */ 0, local_app_ip4.as_u8); + remote_app_ip = to_ip46 (/* isv6 */ 0, remote_app_ip4.as_u8); + + vnet_build_rewrite_for_sw_interface (vnm, sw_if, VNET_LINK_IP4, + &remote_app_ip4); } else { @@ -236,72 +214,82 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, vlib_cli_output (vm, "Setting ip address %s\n", s0); - ip6_add_del_interface_address (vm, - sw_if, - &local_app_ip6, 127, - 0 /* is_del */ ); - local_app_ip = to_ip46 ( /* isv6 */ 1, local_app_ip6.as_u8); - remote_app_ip = to_ip46 ( /* isv6 */ 1, remote_app_ip6.as_u8); - - ret = - hicn_face_ip_add (&local_app_ip, &remote_app_ip, sw_if, faceid, - HICN_FACE_FLAGS_APPFACE_PROD); + ip6_add_del_interface_address (vm, sw_if, &local_app_ip6, 127, + 0 /* is_del */); + local_app_ip = to_ip46 (/* isv6 */ 1, local_app_ip6.as_u8); + remote_app_ip = to_ip46 (/* isv6 */ 1, remote_app_ip6.as_u8); } - - face = hicn_dpoi_get_from_idx (*faceid); - - face->shared.flags |= HICN_FACE_FLAGS_APPFACE_PROD; - - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - - /* - * For the moment we keep them here although it would be good - * to create a different face for appface - */ - prod_face->policy_vft.hicn_cs_insert = hicn_cs_lru.hicn_cs_insert; - prod_face->policy_vft.hicn_cs_update = hicn_cs_lru.hicn_cs_update; - prod_face->policy_vft.hicn_cs_dequeue = hicn_cs_lru.hicn_cs_dequeue; - prod_face->policy_vft.hicn_cs_delete_get = - hicn_cs_lru.hicn_cs_delete_get; - prod_face->policy_vft.hicn_cs_trim = hicn_cs_lru.hicn_cs_trim; - prod_face->policy_vft.hicn_cs_flush = hicn_cs_lru.hicn_cs_flush; - } - if (ret == HICN_ERROR_NONE - && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == HICN_ERROR_NONE) + if (ret == HICN_ERROR_NONE) + // && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == + // HICN_ERROR_NONE) { - if (ip46_address_is_ip4(&(prefix->fp_addr))) - { - ip4_address_t mask; - ip4_preflen_to_mask (prefix->fp_len, &mask); - prefix->fp_addr.ip4.as_u32 = prefix->fp_addr.ip4.as_u32 & mask.as_u32; - prefix->fp_proto = FIB_PROTOCOL_IP4; - } + fib_route_path_t rpath = { 0 }; + fib_route_path_t *rpaths = NULL; + + if (ip46_address_is_ip4 (&(prefix->fp_addr))) + { + ip4_address_t mask; + ip4_preflen_to_mask (prefix->fp_len, &mask); + prefix->fp_addr.ip4.as_u32 = + prefix->fp_addr.ip4.as_u32 & mask.as_u32; + prefix->fp_proto = FIB_PROTOCOL_IP4; + + rpath.frp_weight = 1; + rpath.frp_sw_if_index = ~0; + rpath.frp_addr.ip4.as_u32 = remote_app_ip.ip4.as_u32; + rpath.frp_sw_if_index = sw_if; + rpath.frp_proto = DPO_PROTO_IP4; + + vec_add1 (rpaths, rpath); + } else - { - ip6_address_t mask; - ip6_preflen_to_mask (prefix->fp_len, &mask); - prefix->fp_addr.ip6.as_u64[0] = - prefix->fp_addr.ip6.as_u64[0] & mask.as_u64[0]; - prefix->fp_addr.ip6.as_u64[1] = - prefix->fp_addr.ip6.as_u64[1] & mask.as_u64[1]; - prefix->fp_proto = FIB_PROTOCOL_IP6; - } + { + ip6_address_t mask; + ip6_preflen_to_mask (prefix->fp_len, &mask); + prefix->fp_addr.ip6.as_u64[0] = + prefix->fp_addr.ip6.as_u64[0] & mask.as_u64[0]; + prefix->fp_addr.ip6.as_u64[1] = + prefix->fp_addr.ip6.as_u64[1] & mask.as_u64[1]; + prefix->fp_proto = FIB_PROTOCOL_IP6; + + rpath.frp_weight = 1; + rpath.frp_sw_if_index = ~0; + rpath.frp_addr.ip6.as_u64[0] = remote_app_ip.ip6.as_u64[0]; + rpath.frp_addr.ip6.as_u64[1] = remote_app_ip.ip6.as_u64[1]; + rpath.frp_sw_if_index = sw_if; + rpath.frp_proto = DPO_PROTO_IP6; + + vec_add1 (rpaths, rpath); + } + + u32 fib_index = fib_table_find (prefix->fp_proto, 0); + fib_table_entry_path_add2 (fib_index, prefix, FIB_SOURCE_CLI, + FIB_ENTRY_FLAG_NONE, rpaths); + hicn_route_enable (prefix); hicn_app_state_create (sw_if, prefix); - ret = hicn_route_add (faceid, 1, prefix); } + adj_index = + adj_nbr_find (isv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4, + isv6 ? VNET_LINK_IP6 : VNET_LINK_IP4, prod_addr, sw_if); + face = hicn_face_get (&local_app_ip, sw_if, &hicn_face_hashtb, + adj_index); // HICN_FACE_FLAGS_APPFACE_PROD); + + *faceid = hicn_dpoi_get_index (face); + + face->flags |= HICN_FACE_FLAGS_APPFACE_PROD; + + hicn_face_unlock_with_id (*faceid); + *prod_addr = local_app_ip; /* Cleanup in case of something went wrong. */ if (ret) { hicn_app_state_del (sw_if); - - if (*faceid != HICN_FACE_NULL) - hicn_face_ip_del (*faceid); } return ret; } @@ -314,110 +302,47 @@ hicn_face_prod_del (hicn_face_id_t face_id) hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) + if (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) { - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - /* Free the CS reserved for the face */ - hicn_main.pitcs.pcs_app_count -= prod_face->policy.max; - prod_face->policy.max = 0; - /* Remove the face from the fib */ - hicn_route_del_nhop (&(face_state_vec[face->shared.sw_if].prefix), - face_id); + hicn_route_disable (&(face_state_vec[face->sw_if].prefix)); + // hicn_route_del_nhop (&(face_state_vec[face->sw_if].prefix), + // face_id); - /* - * Delete the content in the CS before deleting the face. - * Mandatory to prevent hitting the CS and not having the lru list - * due to a early deletion of the face. - */ - vlib_main_t *vm = vlib_get_main (); - prod_face->policy_vft.hicn_cs_flush (vm, &(hicn_main.pitcs), - &(prod_face->policy)); - - int ret = hicn_face_ip_del (face_id); - return ret == - HICN_ERROR_NONE ? hicn_app_state_del (face->shared.sw_if) : ret; + // int ret = hicn_face_del (face_id); + return hicn_app_state_del (face->sw_if); + // ret == HICN_ERROR_NONE ? hicn_app_state_del (face->sw_if) : ret; } else { return HICN_ERROR_APPFACE_NOT_FOUND; } -} -int -hicn_face_prod_set_lru_max (hicn_face_id_t face_id, u32 * requested_size) -{ - int ret = HICN_ERROR_NONE; - vlib_main_t *vm = vlib_get_main (); - hicn_face_t *face; - hicn_face_prod_t *face_prod; - - if (!hicn_infra_fwdr_initialized) - { - ret = HICN_ERROR_FWD_NOT_ENABLED; - vlib_cli_output (vm, "hicn: %s\n", get_error_string (ret)); - return ret; - } - face = hicn_dpoi_get_from_idx (face_id); - face_prod = (hicn_face_prod_t *) face->data; - - if (face == NULL) - return HICN_ERROR_FACE_NOT_FOUND; - - if (*requested_size > HICN_PARAM_FACE_MAX_CS_RESERVED) - *requested_size = HICN_PARAM_FACE_MAX_CS_RESERVED; - - uint32_t available = - hicn_main.pitcs.pcs_app_max - hicn_main.pitcs.pcs_app_count; - - if (*requested_size > available) - *requested_size = available; - - face_prod->policy.max = *requested_size; - face_prod->policy.count = 0; - face_prod->policy.head = face_prod->policy.tail = 0; - - hicn_main.pitcs.pcs_app_count += *requested_size; - - return ret; + return HICN_ERROR_NONE; } u8 * -format_hicn_face_prod (u8 * s, va_list * args) +format_hicn_face_prod (u8 *s, va_list *args) { - index_t index = va_arg (*args, index_t); + CLIB_UNUSED (index_t index) = va_arg (*args, index_t); CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - hicn_face_t *face; - hicn_face_prod_t *prod_face; - - face = hicn_dpoi_get_from_idx (index); - prod_face = (hicn_face_prod_t *) face->data; - s = - format (s, " (producer face: CS size %d, data cached %d)", - prod_face->policy.max, prod_face->policy.count); + s = format (s, " (producer)"); return s; } -/* *INDENT-OFF* */ -VNET_FEATURE_INIT(hicn_prod_app_input_ip6, static)= -{ +VNET_FEATURE_INIT (hicn_prod_app_input_ip6, static) = { .arc_name = "ip6-unicast", .node_name = "hicn-face-prod-input", - .runs_before = VNET_FEATURES("ip6-inacl"), + .runs_before = VNET_FEATURES ("ip6-inacl"), }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ -VNET_FEATURE_INIT(hicn_prod_app_input_ip4, static)= -{ +VNET_FEATURE_INIT (hicn_prod_app_input_ip4, static) = { .arc_name = "ip4-unicast", .node_name = "hicn-face-prod-input", - .runs_before = VNET_FEATURES("ip4-inacl"), + .runs_before = VNET_FEATURES ("ip4-inacl"), }; -/* *INDENT-ON* */ - /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/app/face_prod.h b/hicn-plugin/src/faces/app/face_prod.h index 33e2a4199..4cb2e3fbf 100644 --- a/hicn-plugin/src/faces/app/face_prod.h +++ b/hicn-plugin/src/faces/app/face_prod.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2017-2020 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -17,7 +17,7 @@ #define _FACE_PRODUCER_H_ #include "../../cache_policies/cs_policy.h" -#include "../ip/face_ip.h" +#include "../face.h" /** * @file @@ -56,15 +56,6 @@ extern hicn_face_prod_state_t *face_state_vec; #define DEFAULT_PROBING_PORT 3784 -typedef struct __attribute__ ((packed)) hicn_face_prod_t_ -{ - hicn_face_ip_t ip_face; - - hicn_cs_policy_t policy; - hicn_cs_policy_vft_t policy_vft; - -} hicn_face_prod_t; - /** * @brief Add a new producer application face * diff --git a/hicn-plugin/src/faces/app/face_prod_node.c b/hicn-plugin/src/faces/app/face_prod_node.c index 0ef25fe94..a843a01ef 100644 --- a/hicn-plugin/src/faces/app/face_prod_node.c +++ b/hicn-plugin/src/faces/app/face_prod_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2017-2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -19,8 +19,8 @@ * @brief Application interface node * * This node runs after the device-input node and perfoms some safety checks in - * order to avoid unespected interest and data (i.e., hICN packets whose name do - * not contain the prefix associated to the application face) + * order to avoid unespected interest and data (i.e., hICN packets whose name + * do not contain the prefix associated to the application face) */ #include "face_prod.h" @@ -56,7 +56,7 @@ typedef enum vlib_node_registration_t hicn_face_prod_input_node; static __clib_unused u8 * -format_face_prod_input_trace (u8 * s, va_list * args) +format_face_prod_input_trace (u8 *s, va_list *args) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); @@ -64,13 +64,13 @@ format_face_prod_input_trace (u8 * s, va_list * args) va_arg (*args, hicn_face_prod_input_trace_t *); CLIB_UNUSED (u32 indent) = format_get_indent (s); - s = format (s, "prod-face: sw_if_index %d next-index %d", - t->sw_if_index, t->next_index); + s = format (s, "prod-face: sw_if_index %d next-index %d", t->sw_if_index, + t->next_index); return s; } static_always_inline int -match_ip4_name (u32 * name, fib_prefix_t * prefix) +match_ip4_name (u32 *name, fib_prefix_t *prefix) { u32 xor = 0; @@ -80,7 +80,7 @@ match_ip4_name (u32 * name, fib_prefix_t * prefix) } static_always_inline int -match_ip6_name (u8 * name, fib_prefix_t * prefix) +match_ip6_name (u8 *name, fib_prefix_t *prefix) { union { @@ -93,12 +93,12 @@ match_ip6_name (u8 * name, fib_prefix_t * prefix) xor_sum.as_u64[1] = ((u64 *) name)[1] & prefix->fp_addr.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]); + (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, fib_prefix_t * prefix) +hicn_face_prod_next_from_data_hdr (vlib_node_runtime_t *node, vlib_buffer_t *b, + fib_prefix_t *prefix) { u8 *ptr = vlib_buffer_get_current (b); u8 v = *ptr & 0xf0; @@ -106,21 +106,20 @@ hicn_face_prod_next_from_data_hdr (vlib_node_runtime_t * node, if (PREDICT_TRUE (v == 0x40 && ip46_address_is_ip4 (&prefix->fp_addr))) { - match_res = match_ip4_name ((u32 *) & (ptr[12]), prefix); + match_res = match_ip4_name ((u32 *) &(ptr[12]), prefix); } else if (PREDICT_TRUE (v == 0x60 && !ip46_address_is_ip4 (&prefix->fp_addr))) { - match_res = match_ip6_name (& (ptr[8]), prefix); + match_res = match_ip6_name (&(ptr[8]), prefix); } - return match_res ? HICN_FACE_PROD_NEXT_DATA_IP4 + (v == - 0x60) : - HICN_FACE_PROD_NEXT_ERROR_DROP; + return match_res ? HICN_FACE_PROD_NEXT_DATA_IP4 + (v == 0x60) : + HICN_FACE_PROD_NEXT_ERROR_DROP; } static_always_inline void -hicn_face_prod_trace_buffer (vlib_main_t * vm, vlib_node_runtime_t * node, - u32 swif, vlib_buffer_t * b, u32 next) +hicn_face_prod_trace_buffer (vlib_main_t *vm, vlib_node_runtime_t *node, + u32 swif, vlib_buffer_t *b, u32 next) { if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && (b->flags & VLIB_BUFFER_IS_TRACED))) @@ -133,9 +132,8 @@ hicn_face_prod_trace_buffer (vlib_main_t * vm, vlib_node_runtime_t * node, } static uword -hicn_face_prod_input_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn_face_prod_input_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next; hicn_face_prod_next_t next_index; @@ -192,14 +190,10 @@ hicn_face_prod_input_node_fn (vlib_main_t * vm, b2 = vlib_get_buffer (vm, bi2); b3 = vlib_get_buffer (vm, bi3); - prod_face0 = - &face_state_vec[vnet_buffer (b0)->sw_if_index[VLIB_RX]]; - prod_face1 = - &face_state_vec[vnet_buffer (b1)->sw_if_index[VLIB_RX]]; - prod_face2 = - &face_state_vec[vnet_buffer (b2)->sw_if_index[VLIB_RX]]; - prod_face3 = - &face_state_vec[vnet_buffer (b3)->sw_if_index[VLIB_RX]]; + prod_face0 = &face_state_vec[vnet_buffer (b0)->sw_if_index[VLIB_RX]]; + prod_face1 = &face_state_vec[vnet_buffer (b1)->sw_if_index[VLIB_RX]]; + prod_face2 = &face_state_vec[vnet_buffer (b2)->sw_if_index[VLIB_RX]]; + prod_face3 = &face_state_vec[vnet_buffer (b3)->sw_if_index[VLIB_RX]]; next0 = hicn_face_prod_next_from_data_hdr (node, b0, &prod_face0->prefix); @@ -212,18 +206,14 @@ hicn_face_prod_input_node_fn (vlib_main_t * vm, stats.pkts_data_count += 4; /* trace */ - hicn_face_prod_trace_buffer (vm, node, - vnet_buffer (b0)->sw_if_index[VLIB_RX], - b0, next0); - hicn_face_prod_trace_buffer (vm, node, - vnet_buffer (b1)->sw_if_index[VLIB_RX], - b1, next1); - hicn_face_prod_trace_buffer (vm, node, - vnet_buffer (b2)->sw_if_index[VLIB_RX], - b2, next2); - hicn_face_prod_trace_buffer (vm, node, - vnet_buffer (b3)->sw_if_index[VLIB_RX], - b3, next3); + hicn_face_prod_trace_buffer ( + vm, node, vnet_buffer (b0)->sw_if_index[VLIB_RX], b0, next0); + hicn_face_prod_trace_buffer ( + vm, node, vnet_buffer (b1)->sw_if_index[VLIB_RX], b1, next1); + hicn_face_prod_trace_buffer ( + vm, node, vnet_buffer (b2)->sw_if_index[VLIB_RX], b2, next2); + hicn_face_prod_trace_buffer ( + vm, node, vnet_buffer (b3)->sw_if_index[VLIB_RX], b3, next3); /* enqueue */ vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, @@ -231,7 +221,6 @@ hicn_face_prod_input_node_fn (vlib_main_t * vm, next0, next1, next2, next3); stats.pkts_processed += 4; - } while (n_left_from > 0 && n_left_to_next > 0) @@ -264,30 +253,27 @@ hicn_face_prod_input_node_fn (vlib_main_t * vm, stats.pkts_data_count++; /* trace */ - hicn_face_prod_trace_buffer (vm, node, - vnet_buffer (b0)->sw_if_index[VLIB_RX], - b0, next0); + hicn_face_prod_trace_buffer ( + vm, node, vnet_buffer (b0)->sw_if_index[VLIB_RX], b0, next0); /* enqueue */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, bi0, next0); stats.pkts_processed += 1; - } vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_PROCESSED, stats.pkts_processed); + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_PROCESSED, + stats.pkts_processed); vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_DATAS, stats.pkts_data_count); return (frame->n_vectors); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE(hicn_face_prod_input_node) = { .function = hicn_face_prod_input_node_fn, @@ -300,13 +286,12 @@ VLIB_REGISTER_NODE(hicn_face_prod_input_node) = .n_next_nodes = HICN_FACE_PROD_N_NEXT, .next_nodes = { - [HICN_FACE_PROD_NEXT_DATA_IP4] = "hicn-face-ip4-input", - [HICN_FACE_PROD_NEXT_DATA_IP6] = "hicn-face-ip6-input", + [HICN_FACE_PROD_NEXT_DATA_IP4] = "hicn4-face-input", + [HICN_FACE_PROD_NEXT_DATA_IP6] = "hicn6-face-input", [HICN_FACE_PROD_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ - + /* * fd.io coding-style-patch-verification: ON * |