diff options
Diffstat (limited to 'hicn-plugin/src/faces')
-rw-r--r-- | hicn-plugin/src/faces/app/address_mgr.c | 69 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/address_mgr.h | 10 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_app_cli.c | 86 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_cons.c | 36 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_cons.h | 27 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod.c | 269 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod.h | 36 | ||||
-rw-r--r-- | hicn-plugin/src/faces/app/face_prod_node.c | 216 | ||||
-rw-r--r-- | hicn-plugin/src/faces/face.c | 223 | ||||
-rw-r--r-- | hicn-plugin/src/faces/face.h | 592 | ||||
-rw-r--r-- | hicn-plugin/src/faces/face_cli.c | 184 | ||||
-rw-r--r-- | hicn-plugin/src/faces/face_flags.h | 40 | ||||
-rw-r--r-- | hicn-plugin/src/faces/face_node.c | 1017 | ||||
-rw-r--r-- | hicn-plugin/src/faces/face_node.h | 8 | ||||
-rw-r--r-- | hicn-plugin/src/faces/iface_node.c | 1056 | ||||
-rw-r--r-- | hicn-plugin/src/faces/iface_node.h | 33 | ||||
-rw-r--r-- | hicn-plugin/src/faces/inlines.h | 29 |
17 files changed, 1959 insertions, 1972 deletions
diff --git a/hicn-plugin/src/faces/app/address_mgr.c b/hicn-plugin/src/faces/app/address_mgr.c index 2d5894ab8..44729fd69 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-2020 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -14,7 +14,7 @@ */ /* - * Copyright (c) 2017-2019 by cisco systems inc. All rights reserved. + * Copyright (c) 2021 by cisco systems inc. All rights reserved. * */ @@ -24,17 +24,18 @@ #include <vnet/ip/ip6_packet.h> #include <vnet/ip/ip4.h> //ip4_add_del_ip_address #include <vnet/ip/ip6.h> //ip6_add_del_ip_address -#include <vnet/fib/fib_types.h> //FIB_PROTOCOL_IP4/6, FIB_NODE_INDEX_INVALID -#include <vnet/fib/fib_entry.h> //FIB_SOURCE_PRIORITY_HI +#include <vnet/fib/fib_types.h> //FIB_PROTOCOL_IP4/6, FIB_NODE_INDEX_INVALID +#include <vnet/fib/fib_entry.h> //FIB_SOURCE_PRIORITY_HI #include <vnet/fib/fib_table.h> #include <vppinfra/format.h> -#include <vnet/interface.h> //appif_flags -#include <vnet/interface_funcs.h> //vnet_sw_interface_set_flags +#include <vnet/interface.h> //appif_flags +#include <vnet/interface_funcs.h> //vnet_sw_interface_set_flags + +#include <vpp_plugins/hicn/error.h> #include "address_mgr.h" #include "../../hicn.h" #include "../../infra.h" -#include "../../error.h" #include "../face.h" #include "../../strategy_dpo_ctx.h" #include "../../route.h" @@ -48,7 +49,7 @@ typedef struct address_mgr_main_s address_mgr_main_t address_mgr_main; static void -increment_v4_address (ip4_address_t * a, u32 val) +increment_v4_address (ip4_address_t *a, u32 val) { u32 v; @@ -57,7 +58,7 @@ increment_v4_address (ip4_address_t * a, u32 val) } static void -increment_v6_address (ip6_address_t * a, u64 val) +increment_v6_address (ip6_address_t *a, u64 val) { u64 v; @@ -66,7 +67,7 @@ increment_v6_address (ip6_address_t * a, u64 val) } void -get_two_ip4_addresses (ip4_address_t * appif_addr, ip4_address_t * nh_addr) +get_two_ip4_addresses (ip4_address_t *appif_addr, ip4_address_t *nh_addr) { /* We want two consecutives address that fall into a /31 mask */ if (address_mgr_main.next_ip4_local_addr.as_u8[3] & 0x01) @@ -85,20 +86,17 @@ get_two_ip4_addresses (ip4_address_t * appif_addr, ip4_address_t * nh_addr) do { /* Check if the route already exist in the fib */ - fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, 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_pfx.fp_addr = to_ip46 (/* is_v6 */ 0, 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); 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_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); } @@ -115,7 +113,7 @@ get_two_ip4_addresses (ip4_address_t * appif_addr, ip4_address_t * nh_addr) } void -get_two_ip6_addresses (ip6_address_t * appif_addr, ip6_address_t * nh_addr) +get_two_ip6_addresses (ip6_address_t *appif_addr, ip6_address_t *nh_addr) { /* We want two consecutives address that fall into a /127 mask */ @@ -126,7 +124,6 @@ get_two_ip6_addresses (ip6_address_t * appif_addr, ip6_address_t * nh_addr) increment_v6_address (&(address_mgr_main.next_ip6_local_addr), 1); *nh_addr = address_mgr_main.next_ip6_local_addr; - fib_prefix_t fib_pfx; fib_node_index_t fib_entry_index = FIB_NODE_INDEX_INVALID; u32 fib_index; @@ -140,18 +137,18 @@ get_two_ip6_addresses (ip6_address_t * appif_addr, ip6_address_t * nh_addr) do { /* Check if the route already exist in the fib */ - fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 1, appif_addr->as_u8); + fib_pfx.fp_addr = to_ip46 (/* is_v6 */ 1, appif_addr->as_u8); 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_pfx.fp_addr = to_ip46 (/* is_v6 */ 0, nh_addr->as_u8); - 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_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); + // fib_table_unlock (fib_index, fib_pfx.fp_proto, + // FIB_SOURCE_PRIORITY_HI); } if (fib_entry_index != FIB_NODE_INDEX_INVALID) { @@ -179,10 +176,9 @@ get_ip4_address () do { /* Check if the route already exist in the fib */ - fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, prefix->as_u8); - fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); + fib_pfx.fp_addr = to_ip46 (/* is_v6 */ 0, prefix->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); increment_v4_address (prefix, 1); @@ -206,10 +202,9 @@ get_ip6_address () do { /* Check if the route already exist in the fib */ - fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 1, prefix->as_u8); - fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); + fib_pfx.fp_addr = to_ip46 (/* is_v6 */ 1, prefix->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); increment_v6_address (prefix, 1); diff --git a/hicn-plugin/src/faces/app/address_mgr.h b/hicn-plugin/src/faces/app/address_mgr.h index 99450dcdd..32545f8ca 100644 --- a/hicn-plugin/src/faces/app/address_mgr.h +++ b/hicn-plugin/src/faces/app/address_mgr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -25,9 +25,9 @@ * an interface. */ -#define ADDR_MGR_IP4_LEN 32 +#define ADDR_MGR_IP4_LEN 32 #define ADDR_MGR_IP4_CONS_LEN 31 -#define ADDR_MGR_IP6_LEN 128 +#define ADDR_MGR_IP6_LEN 128 #define ADDR_MGR_IP6_CONS_LEN 127 /** @@ -36,7 +36,7 @@ * @param addr1 first ip address with the least significant bit set to 0 * @param addr2 second ip address with the least significant bit set to 1 */ -void get_two_ip4_addresses (ip4_address_t * addr1, ip4_address_t * addr2); +void get_two_ip4_addresses (ip4_address_t *addr1, ip4_address_t *addr2); /** * @brief Get two consecutive IP v6 addresses from the same /126 subnet @@ -44,7 +44,7 @@ void get_two_ip4_addresses (ip4_address_t * addr1, ip4_address_t * addr2); * @param addr1 first ip address with the least significant bit set to 0 * @param addr2 second ip address with the least significant bit set to 1 */ -void get_two_ip6_addresses (ip6_address_t * addr1, ip6_address_t * addr2); +void get_two_ip6_addresses (ip6_address_t *addr1, ip6_address_t *addr2); /** * @brief Get one IP v4 address diff --git a/hicn-plugin/src/faces/app/face_app_cli.c b/hicn-plugin/src/faces/app/face_app_cli.c index 1aa27adc7..50e6ae71b 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-2020 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -17,20 +17,21 @@ #include <vnet/dpo/dpo.h> #include <vlib/vlib.h> #include <vnet/ip/ip6_packet.h> +#include <vnet/ip/format.h> -//#include "../face_dpo.h" +#include "../../params.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; @@ -42,7 +43,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)) @@ -56,8 +56,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")) { @@ -65,13 +65,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; } @@ -81,10 +80,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 @@ -116,20 +114,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 @@ -139,17 +134,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 @@ -181,20 +175,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 d44ba1a2b..edb03387d 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-2020 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -22,9 +22,8 @@ #include "../../infra.h" int -hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, - u32 swif, hicn_face_id_t * faceid1, - hicn_face_id_t * faceid2) +hicn_face_cons_add (ip4_address_t *nh_addr4, ip6_address_t *nh_addr6, u32 swif, + hicn_face_id_t *faceid1, hicn_face_id_t *faceid2) { /* Create the corresponding appif if */ /* Retrieve a valid local ip address to assign to the appif */ @@ -49,32 +48,33 @@ hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, if_flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP; vnet_sw_interface_set_flags (vnm, swif, if_flags); +#if 0 get_two_ip4_addresses (&(if_ip.ip4), nh_addr4); - ip4_add_del_interface_address (vm, - swif, - &(if_ip.ip4), - ADDR_MGR_IP4_CONS_LEN, 0 /* is_del */ ); + ip4_add_del_interface_address (vm, swif, &(if_ip.ip4), ADDR_MGR_IP4_CONS_LEN, + 0 /* is_del */); ip46_address_t nh_addr = to_ip46 (0, (u8 *) nh_addr4); - index_t adj_index = adj_nbr_find(FIB_PROTOCOL_IP4, VNET_LINK_IP4, &nh_addr, swif); + 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->flags |= HICN_FACE_FLAGS_APPFACE_CONS; +#endif get_two_ip6_addresses (&(if_ip.ip6), nh_addr6); - ip6_add_del_interface_address (vm, - swif, - &(if_ip.ip6), - ADDR_MGR_IP6_CONS_LEN, 0 /* is_del */ ); + ip6_add_del_interface_address (vm, swif, &(if_ip.ip6), ADDR_MGR_IP6_CONS_LEN, + 0 /* is_del */); - adj_index = adj_nbr_find(FIB_PROTOCOL_IP6, VNET_LINK_IP6, &nh_addr, swif); + ip46_address_t nh_addr = to_ip46 (0, (u8 *) nh_addr6); + index_t 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); + hicn_iface_add ((ip46_address_t *) nh_addr6, swif, faceid2, adj_index, 0); - face = hicn_dpoi_get_from_idx (*faceid2); + hicn_face_t *face = hicn_dpoi_get_from_idx (*faceid2); face->flags |= HICN_FACE_FLAGS_APPFACE_CONS; return HICN_ERROR_NONE; @@ -90,7 +90,7 @@ hicn_face_cons_del (hicn_face_id_t face_id) if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) { - return hicn_face_del (face_id); + return hicn_face_unlock_with_id (face_id); } else { @@ -99,7 +99,7 @@ hicn_face_cons_del (hicn_face_id_t face_id) } u8 * -format_hicn_face_cons (u8 * s, va_list * args) +format_hicn_face_cons (u8 *s, va_list *args) { CLIB_UNUSED (index_t index) = va_arg (*args, index_t); CLIB_UNUSED (u32 indent) = va_arg (*args, u32); diff --git a/hicn-plugin/src/faces/app/face_cons.h b/hicn-plugin/src/faces/app/face_cons.h index 5f8f5dde8..9df6f773f 100644 --- a/hicn-plugin/src/faces/app/face_cons.h +++ b/hicn-plugin/src/faces/app/face_cons.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -28,8 +28,8 @@ * consumer application (co-located with the forwarder) that acts as a * consumer. The interface used by the consumer application face is * assumed to be reserved only for hICN traffic (e.g., dedicated memif that - * connects the applictation to the forwarder). Only one application face can be - * assigned to an interface. + * connects the applictation to the forwarder). Only one application face can + * be assigned to an interface. * * In the vlib graph a consumer application face directly connect the * device-input node to the hicn-vface-ip node. @@ -38,17 +38,17 @@ /** * @brief Add a new consumer application face * - * The method creates the internal ip face and set the ip address to the interface. - * @param nh_addr4 ipv4 address to assign to interface used by the application to - * send interest to the consumer face - * @param nh_addr6 ipv6 address to assign to interface used by the application to - * send interest to the consumer face + * The method creates the internal ip face and set the ip address to the + * interface. + * @param nh_addr4 ipv4 address to assign to interface used by the application + * to send interest to the consumer face + * @param nh_addr6 ipv6 address to assign to interface used by the application + * to send interest to the consumer face * @param swif interface associated to the face */ -int -hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, - u32 swif, hicn_face_id_t * faceid1, - hicn_face_id_t * faceid2); +int hicn_face_cons_add (ip4_address_t *nh_addr4, ip6_address_t *nh_addr6, + u32 swif, hicn_face_id_t *faceid1, + hicn_face_id_t *faceid2); /** * @brief Delete an existing consumer application face @@ -64,8 +64,7 @@ int hicn_face_cons_del (hicn_face_id_t face_id); * @param args Array storing input values. Expected u32 face_id and u32 indent * @return String with the formatted face */ -u8 *format_hicn_face_cons (u8 * s, va_list * args); - +u8 *format_hicn_face_cons (u8 *s, va_list *args); #endif /* _FACE_CONSUMER_H_ */ diff --git a/hicn-plugin/src/faces/app/face_prod.c b/hicn-plugin/src/faces/app/face_prod.c index 645154325..5d0fa727b 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-2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2023 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,6 +17,7 @@ #include <vlib/vlib.h> #include <vnet/vnet.h> #include <vnet/interface_funcs.h> +#include <vppinfra/pool.h> #include "face_prod.h" #include "address_mgr.h" @@ -24,36 +25,30 @@ #include "../../route.h" #include "../../cache_policies/cs_lru.h" +#define INITIAL_POOL_SIZE 16 hicn_face_prod_state_t *face_state_vec; /* used to check if an interface is already in the vector */ u32 *face_state_pool; static int -hicn_app_state_create (u32 swif, fib_prefix_t * prefix) +hicn_app_state_create (u32 swif, index_t adj_index, 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); + face_state_vec[swif].adj_index = adj_index; clib_memcpy (&(face_state_vec[swif].prefix), prefix, sizeof (fib_prefix_t)); /* Set as busy the element in the vector */ @@ -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; @@ -80,23 +73,16 @@ hicn_app_state_create (u32 swif, fib_prefix_t * prefix) static int hicn_app_state_del (u32 swif) { - /* Make sure that the pool is not empty */ - pool_validate_index (face_state_pool, 0); - u32 *temp; 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; + } if (!found) return HICN_ERROR_APPFACE_NOT_FOUND; @@ -106,15 +92,13 @@ hicn_app_state_del (u32 swif) 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); @@ -124,16 +108,16 @@ 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 (); hicn_main_t *hm = &hicn_main; - ip46_address_t local_app_ip; - CLIB_UNUSED(ip46_address_t remote_app_ip); + ip46_address_t local_app_ip = { .as_u64 = { 0, 0 } }; + CLIB_UNUSED (ip46_address_t remote_app_ip); u32 if_flags = 0; if (!hm->is_enabled) @@ -152,25 +136,28 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, if_flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP; vnet_sw_interface_set_flags (vnm, sw_if, if_flags); +#ifdef HICN_DDEBUG u8 *s0; s0 = format (0, "Prefix %U", format_fib_prefix, prefix); - - vlib_cli_output (vm, "Received request for %s, swif %d\n", s0, sw_if); + HICN_DEBUG ("Received request for %s, swif %d\n", s0, sw_if); +#endif if (ip46_address_is_zero (&prefix->fp_addr)) { 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); + 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 */ - face = hicn_face_get (&(prefix->fp_addr), sw_if, - &hicn_face_hashtb, adj_index); + face = + hicn_face_get (&(prefix->fp_addr), sw_if, &hicn_face_hashtb, adj_index); if (face != NULL) { @@ -207,13 +194,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); + 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); + vnet_build_rewrite_for_sw_interface (vnm, sw_if, VNET_LINK_IP4, + &remote_app_ip4); } else { @@ -225,80 +212,90 @@ 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); + 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); } } if (ret == HICN_ERROR_NONE) - // && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == HICN_ERROR_NONE) + // && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == + // HICN_ERROR_NONE) { - 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); - } + 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; - - 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); - } + { + 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); + fib_table_entry_path_add2 (fib_index, prefix, FIB_SOURCE_API, + FIB_ENTRY_FLAG_NONE, rpaths); + + HICN_DEBUG ("Calling hicn enable for producer face"); + + hicn_face_id_t *vec_faces = NULL; + fib_node_index_t hicn_fib_node_index; + hicn_route_enable (prefix, &hicn_fib_node_index, &vec_faces); + if (vec_faces != NULL) + vec_free (vec_faces); - hicn_route_enable(prefix); - hicn_app_state_create (sw_if, prefix); + adj_index = + adj_nbr_find (isv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4, + isv6 ? VNET_LINK_IP6 : VNET_LINK_IP4, prod_addr, sw_if); + + hicn_app_state_create (sw_if, adj_index, 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); + face = hicn_face_get (&local_app_ip, sw_if, &hicn_face_hashtb, adj_index); + assert (face); *faceid = hicn_dpoi_get_index (face); face->flags |= HICN_FACE_FLAGS_APPFACE_PROD; - hicn_face_unlock_with_id(*faceid); + hicn_face_unlock_with_id (*faceid); *prod_addr = local_app_ip; /* Cleanup in case of something went wrong. */ if (ret) { + HICN_ERROR ("Somethig went wrong while adding producer face. Cleanup."); hicn_app_state_del (sw_if); } return ret; @@ -314,17 +311,32 @@ hicn_face_prod_del (hicn_face_id_t face_id) if (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) { - /* Remove the face from the fib */ - hicn_route_disable(&(face_state_vec[face->sw_if].prefix)); - //hicn_route_del_nhop (&(face_state_vec[face->sw_if].prefix), - // face_id); - - //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; + /* Remove the face from the hicn fib */ + fib_prefix_t *prefix = &(face_state_vec[face->sw_if].prefix); + HICN_DEBUG ("Calling hicn_route_disable from hicn_face_prod_del"); + int ret = hicn_route_disable (prefix); + if (ret) + { + vlib_main_t *vm = vlib_get_main (); + vlib_cli_output (vm, "Error disabling route: %s", + get_error_string (ret)); + } + /* Also remove it from main fib, as we sre the owners of this prefix */ + u32 fib_index = fib_table_find (prefix->fp_proto, 0); + fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API); + ret = hicn_app_state_del (face->sw_if); + if (ret) + { + vlib_main_t *vm = vlib_get_main (); + vlib_cli_output (vm, "Error deelting app state: %s", + get_error_string (ret)); + } } else { + vlib_main_t *vm = vlib_get_main (); + vlib_cli_output (vm, "APPFACE not found.", + get_error_string (HICN_ERROR_APPFACE_NOT_FOUND)); return HICN_ERROR_APPFACE_NOT_FOUND; } @@ -332,35 +344,34 @@ hicn_face_prod_del (hicn_face_id_t face_id) } u8 * -format_hicn_face_prod (u8 * s, va_list * args) +format_hicn_face_prod (u8 *s, va_list *args) { CLIB_UNUSED (index_t index) = va_arg (*args, index_t); CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - s = - format (s, " (producer)"); + s = format (s, " (producer)"); return s; } -/* *INDENT-OFF* */ -VNET_FEATURE_INIT(hicn_prod_app_input_ip6, static)= +void +hicn_face_prod_init () { + /* Make sure that the pool is not empty */ + pool_alloc (face_state_pool, INITIAL_POOL_SIZE); +} + +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 4cb2e3fbf..46bdf7c24 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-2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2023 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: @@ -25,12 +25,12 @@ * @brief Producer application face. * * A producer application face is built upon an ip face and identify a local - * producer application (co-located with the forwarder) that acts as a producer. In the - * current design an application face is either a face towards a consumer face - * or towards a producer. The interface used by the producer application face is - * assumed to be reserved only for hICN traffic (e.g., dedicated memif that - * connects the applictation to the forwarder). Only one application face can be - * assigned to an interface. + * producer application (co-located with the forwarder) that acts as a + * producer. In the current design an application face is either a face towards + * a consumer face or towards a producer. The interface used by the producer + * application face is assumed to be reserved only for hICN traffic (e.g., + * dedicated memif that connects the applictation to the forwarder). Only one + * application face can be assigned to an interface. * * To each producer application face it is assigned a portion of the CS. Every * data arriving to a producer application will be stored in the portion of the @@ -38,18 +38,19 @@ * face. Available eviction faces are list in the /cache_policy folder. * * In the vlib graph a producer application face is directly connected to the - * device-input node (with the node hicn-face-prod-input) and passes every packet to - * the hicn-face-ip node. + * device-input node (with the node hicn-face-prod-input) and passes every + * packet to the hicn-face-ip node. */ /** - * @brief Producer application face state that refer to the hICN producer socket - * created by the application. + * @brief Producer application face state that refer to the hICN producer + * socket created by the application. * */ typedef struct { fib_prefix_t prefix; + index_t adj_index; } hicn_face_prod_state_t; extern hicn_face_prod_state_t *face_state_vec; @@ -69,9 +70,8 @@ extern hicn_face_prod_state_t *face_state_vec; * @param prod_addr address to assign to interface used by the appliction to * send data to the producer face */ -int -hicn_face_prod_add (fib_prefix_t * prefix, u32 swif, u32 * cs_reserved, - ip46_address_t * prod_addr, hicn_face_id_t * faceid); +int hicn_face_prod_add (fib_prefix_t *prefix, u32 swif, u32 *cs_reserved, + ip46_address_t *prod_addr, hicn_face_id_t *faceid); /** * @brief Delete an existing application face @@ -85,7 +85,7 @@ int hicn_face_prod_del (hicn_face_id_t faceid); * * @param face_id Id of the producer application face */ -int hicn_face_prod_set_lru_max (hicn_face_id_t face_id, u32 * requested_size); +int hicn_face_prod_set_lru_max (hicn_face_id_t face_id, u32 *requested_size); /** * @brief Format an application producer face @@ -94,8 +94,12 @@ int hicn_face_prod_set_lru_max (hicn_face_id_t face_id, u32 * requested_size); * @param args Array storing input values. Expected u32 face_id and u32 indent * @return String with the formatted face */ -u8 *format_hicn_face_prod (u8 * s, va_list * args); +u8 *format_hicn_face_prod (u8 *s, va_list *args); +/** + * @brief Init the producer face module + */ +void hicn_face_prod_init (); #endif /* _FACE_PROD_H_ */ diff --git a/hicn-plugin/src/faces/app/face_prod_node.c b/hicn-plugin/src/faces/app/face_prod_node.c index 80c3e124c..93e80d1ac 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-2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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,13 +19,13 @@ * @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" -#include "../../hicn_api.h" #include "../../mgmt.h" +#include "../../parser.h" static __clib_unused char *face_prod_input_error_strings[] = { #define _(sym, string) string, @@ -43,12 +43,12 @@ typedef struct { u32 next_index; u32 sw_if_index; + hicn_error_t error; } hicn_face_prod_input_trace_t; typedef enum { - HICN_FACE_PROD_NEXT_DATA_IP4, - HICN_FACE_PROD_NEXT_DATA_IP6, + HICN_FACE_PROD_NEXT_PCS, HICN_FACE_PROD_NEXT_ERROR_DROP, HICN_FACE_PROD_N_NEXT, } hicn_face_prod_next_t; @@ -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,16 @@ 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); + + if (t->error != HICN_ERROR_NONE) + s = format (s, " error %s", get_error_string (t->error)); return s; } static_always_inline int -match_ip4_name (u32 * name, fib_prefix_t * prefix) +match_ip4_name (u32 *name, const fib_prefix_t *prefix) { u32 xor = 0; @@ -80,7 +83,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, const fib_prefix_t *prefix) { union { @@ -93,34 +96,51 @@ 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_main_t *vm, vlib_buffer_t *b) { - u8 *ptr = vlib_buffer_get_current (b); - u8 v = *ptr & 0xf0; + u8 is_v6; int match_res = 1; + int ret = 0; + hicn_name_t name; + hicn_face_prod_state_t *prod_face = NULL; - if (PREDICT_TRUE (v == 0x40 && ip46_address_is_ip4 (&prefix->fp_addr))) + // 1 - ensure the packet is hicn and its format is correct + ret = hicn_data_parse_pkt (b, vlib_buffer_length_in_chain (vm, b)); + if (PREDICT_FALSE (ret)) { - match_res = match_ip4_name ((u32 *) & (ptr[12]), prefix); + return HICN_FACE_PROD_NEXT_ERROR_DROP; } - else if (PREDICT_TRUE (v == 0x60 && !ip46_address_is_ip4 (&prefix->fp_addr))) + + // 2 - make sure the packet refers to a valid producer app state and + // retrieve app state information + prod_face = &face_state_vec[vnet_buffer (b)->sw_if_index[VLIB_RX]]; + vnet_buffer (b)->ip.adj_index[VLIB_RX] = prod_face->adj_index; + + // 3 - make sure the address in the packet belongs to the producer prefix + // of this face + const fib_prefix_t *prefix = &prod_face->prefix; + is_v6 = hicn_buffer_is_v6 (b); + hicn_packet_get_name (&hicn_get_buffer (b)->pkbuf, &name); + if (PREDICT_TRUE (!is_v6 && ip46_address_is_ip4 (&prefix->fp_addr))) { - match_res = match_ip6_name (& (ptr[8]), prefix); + match_res = match_ip4_name (&name.prefix.v4.as_u32, prefix); + } + else if (PREDICT_TRUE (is_v6 && !ip46_address_is_ip4 (&prefix->fp_addr))) + { + match_res = match_ip6_name (name.prefix.v6.as_u8, prefix); } - return match_res ? HICN_FACE_PROD_NEXT_DATA_IP4 + (v == - 0x60) : - HICN_FACE_PROD_NEXT_ERROR_DROP; + // 4 - if match found, forward data to next hicn node + return match_res ? HICN_FACE_PROD_NEXT_PCS : 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,13 +153,13 @@ 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; vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; + u32 thread_index = vm->thread_index; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; @@ -153,23 +173,30 @@ hicn_face_prod_input_node_fn (vlib_main_t * vm, while (n_left_from >= 8 && n_left_to_next >= 4) { vlib_buffer_t *b0, *b1, *b2, *b3; + hicn_buffer_t *hicnb0, *hicnb1, *hicnb2, *hicnb3; u32 bi0, bi1, bi2, bi3; - hicn_face_prod_state_t *prod_face0 = NULL; - hicn_face_prod_state_t *prod_face1 = NULL; - hicn_face_prod_state_t *prod_face2 = NULL; - hicn_face_prod_state_t *prod_face3 = NULL; u32 next0, next1, next2, next3; + // Prefetch next iteration { vlib_buffer_t *b4, *b5, *b6, *b7; b4 = vlib_get_buffer (vm, from[4]); b5 = vlib_get_buffer (vm, from[5]); b6 = vlib_get_buffer (vm, from[6]); b7 = vlib_get_buffer (vm, from[7]); - CLIB_PREFETCH (b4, CLIB_CACHE_LINE_BYTES, STORE); - CLIB_PREFETCH (b5, CLIB_CACHE_LINE_BYTES, STORE); - CLIB_PREFETCH (b6, CLIB_CACHE_LINE_BYTES, STORE); - CLIB_PREFETCH (b7, CLIB_CACHE_LINE_BYTES, STORE); + CLIB_PREFETCH (b4, 2 * CLIB_CACHE_LINE_BYTES, WRITE); + CLIB_PREFETCH (b5, 2 * CLIB_CACHE_LINE_BYTES, WRITE); + CLIB_PREFETCH (b6, 2 * CLIB_CACHE_LINE_BYTES, WRITE); + CLIB_PREFETCH (b7, 2 * CLIB_CACHE_LINE_BYTES, WRITE); + + CLIB_PREFETCH (vlib_buffer_get_current (b4), + 2 * CLIB_CACHE_LINE_BYTES, WRITE); + CLIB_PREFETCH (vlib_buffer_get_current (b5), + 2 * CLIB_CACHE_LINE_BYTES, WRITE); + CLIB_PREFETCH (vlib_buffer_get_current (b6), + 2 * CLIB_CACHE_LINE_BYTES, WRITE); + CLIB_PREFETCH (vlib_buffer_get_current (b7), + 2 * CLIB_CACHE_LINE_BYTES, WRITE); } bi0 = from[0]; @@ -192,53 +219,71 @@ 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]]; - - next0 = - hicn_face_prod_next_from_data_hdr (node, b0, &prod_face0->prefix); - next1 = - hicn_face_prod_next_from_data_hdr (node, b1, &prod_face1->prefix); - next2 = - hicn_face_prod_next_from_data_hdr (node, b2, &prod_face2->prefix); - next3 = - hicn_face_prod_next_from_data_hdr (node, b3, &prod_face3->prefix); + hicnb0 = hicn_get_buffer (b0); + hicnb1 = hicn_get_buffer (b1); + hicnb2 = hicn_get_buffer (b2); + hicnb3 = hicn_get_buffer (b3); + + hicnb0->flags = HICN_FACE_FLAGS_DEFAULT; + hicnb1->flags = HICN_FACE_FLAGS_DEFAULT; + hicnb2->flags = HICN_FACE_FLAGS_DEFAULT; + hicnb3->flags = HICN_FACE_FLAGS_DEFAULT; + + // parse packets and get next node + next0 = hicn_face_prod_next_from_data_hdr (vm, b0); + next1 = hicn_face_prod_next_from_data_hdr (vm, b1); + next2 = hicn_face_prod_next_from_data_hdr (vm, b2); + next3 = hicn_face_prod_next_from_data_hdr (vm, b3); 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); - - /* enqueue */ + // counters + vlib_increment_combined_counter ( + &counters[hicnb0->face_id * HICN_N_COUNTER], thread_index, + HICN_FACE_COUNTERS_DATA_RX, 1, + vlib_buffer_length_in_chain (vm, b0)); + stats.pkts_data_count += 1; + + vlib_increment_combined_counter ( + &counters[hicnb1->face_id * HICN_N_COUNTER], thread_index, + HICN_FACE_COUNTERS_DATA_RX, 1, + vlib_buffer_length_in_chain (vm, b0)); + stats.pkts_data_count += 1; + + vlib_increment_combined_counter ( + &counters[hicnb2->face_id * HICN_N_COUNTER], thread_index, + HICN_FACE_COUNTERS_DATA_RX, 1, + vlib_buffer_length_in_chain (vm, b0)); + stats.pkts_data_count += 1; + + vlib_increment_combined_counter ( + &counters[hicnb3->face_id * HICN_N_COUNTER], thread_index, + HICN_FACE_COUNTERS_DATA_RX, 1, + vlib_buffer_length_in_chain (vm, b0)); + stats.pkts_data_count += 1; + + // 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); + + // enqueue vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, n_left_to_next, bi0, bi1, bi2, bi3, next0, next1, next2, next3); stats.pkts_processed += 4; - } while (n_left_from > 0 && n_left_to_next > 0) { vlib_buffer_t *b0; - u32 bi0, swif; - hicn_face_prod_state_t *prod_face = NULL; + hicn_buffer_t *hicnb0; + u32 bi0; u32 next0; if (n_left_from > 1) @@ -256,38 +301,41 @@ hicn_face_prod_input_node_fn (vlib_main_t * vm, n_left_to_next -= 1; b0 = vlib_get_buffer (vm, bi0); - swif = vnet_buffer (b0)->sw_if_index[VLIB_RX]; - prod_face = &face_state_vec[swif]; + hicnb0 = hicn_get_buffer (b0); + hicnb0->flags = HICN_FACE_FLAGS_DEFAULT; - next0 = - hicn_face_prod_next_from_data_hdr (node, b0, &prod_face->prefix); + next0 = hicn_face_prod_next_from_data_hdr (vm, b0); stats.pkts_data_count++; + // counters + vlib_increment_combined_counter ( + &counters[hicnb0->face_id * HICN_N_COUNTER], thread_index, + HICN_FACE_COUNTERS_DATA_RX, 1, + vlib_buffer_length_in_chain (vm, b0)); + stats.pkts_data_count += 1; + /* 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,12 +348,10 @@ VLIB_REGISTER_NODE(hicn_face_prod_input_node) = .n_next_nodes = HICN_FACE_PROD_N_NEXT, .next_nodes = { - [HICN_FACE_PROD_NEXT_DATA_IP4] = "hicn4-face-input", - [HICN_FACE_PROD_NEXT_DATA_IP6] = "hicn6-face-input", + [HICN_FACE_PROD_NEXT_PCS] = "hicn-data-pcslookup", [HICN_FACE_PROD_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/face.c b/hicn-plugin/src/faces/face.c index b495d18b0..ce3001ac7 100644 --- a/hicn-plugin/src/faces/face.c +++ b/hicn-plugin/src/faces/face.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2023 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: @@ -15,6 +15,7 @@ #include <vnet/fib/fib_entry_track.h> #include "face.h" +#include "app/face_prod.h" #include "../hicn.h" #include "../params.h" #include "../error.h" @@ -24,6 +25,7 @@ dpo_id_t *face_dpo_vec; hicn_face_vft_t *face_vft_vec; char **face_type_names_vec; +u8 pl_index = 1; hicn_face_t *hicn_dpoi_face_pool; @@ -36,49 +38,42 @@ dpo_type_t hicn_face_type; fib_node_type_t hicn_face_fib_node_type; const char *HICN_FACE_CTRX_STRING[] = { -#define _(a,b,c) c, +#define _(a, b, c) c, foreach_hicn_face_counter #undef _ }; u8 * -face_show (u8 * s, int face_id, u32 indent) +face_show (u8 *s, int face_id, u32 indent) { s = format (s, "%U Faces:\n", format_white_space, indent); indent += 4; int i; vec_foreach_index (i, face_dpo_vec) - { - s = - format (s, "%U", face_vft_vec[i].format_face, - face_dpo_vec[face_id].dpoi_index, indent); - } + { + s = format (s, "%U", face_vft_vec[i].format_face, + face_dpo_vec[face_id].dpoi_index, indent); + } return (s); - } -mhash_t hicn_face_vec_hashtb; mhash_t hicn_face_hashtb; -hicn_face_vec_t *hicn_vec_pool; - const static char *const hicn_face6_nodes[] = { - "hicn6-face-output", // this is the name you give your node in VLIB_REGISTER_NODE - "hicn6-iface-output", // this is the name you give your node in VLIB_REGISTER_NODE + "hicn6-face-output", // this is the name you give your node in + // VLIB_REGISTER_NODE NULL, }; const static char *const hicn_face4_nodes[] = { - "hicn4-face-output", // this is the name you give your node in VLIB_REGISTER_NODE - "hicn4-iface-output", // this is the name you give your node in VLIB_REGISTER_NODE + "hicn4-face-output", // this is the name you give your node in + // VLIB_REGISTER_NODE NULL, }; - const static char *const *const hicn_face_nodes[DPO_PROTO_NUM] = { - [DPO_PROTO_IP4] = hicn_face4_nodes, - [DPO_PROTO_IP6] = hicn_face6_nodes + [DPO_PROTO_IP4] = hicn_face4_nodes, [DPO_PROTO_IP6] = hicn_face6_nodes }; const static dpo_vft_t hicn_face_dpo_vft = { @@ -98,19 +93,19 @@ hicn_face_node_get (fib_node_index_t index) } static void -hicn_face_last_lock_gone (fib_node_t * node) +hicn_face_last_lock_gone (fib_node_t *node) { } static hicn_face_t * -hicn_face_from_fib_node (fib_node_t * node) +hicn_face_from_fib_node (fib_node_t *node) { return ((hicn_face_t *) (((char *) node) - STRUCT_OFFSET_OF (hicn_face_t, fib_node))); } static fib_node_back_walk_rc_t -hicn_face_back_walk_notify (fib_node_t * node, fib_node_back_walk_ctx_t * ctx) +hicn_face_back_walk_notify (fib_node_t *node, fib_node_back_walk_ctx_t *ctx) { hicn_face_t *face = hicn_face_from_fib_node (node); @@ -133,7 +128,8 @@ hicn_face_back_walk_notify (fib_node_t * node, fib_node_back_walk_ctx_t * ctx) /* } */ /* else */ /* { */ - /* dpo_stack(hicn_face_type, face->dpo.dpoi_proto, &face->dpo, dpo); */ + /* dpo_stack(hicn_face_type, face->dpo.dpoi_proto, &face->dpo, dpo); + */ /* } */ /* } */ @@ -145,7 +141,6 @@ hicn_face_show_memory (void) { } - static const fib_node_vft_t hicn_face_fib_node_vft = { .fnv_get = hicn_face_node_get, .fnv_last_lock = hicn_face_last_lock_gone, @@ -155,39 +150,36 @@ static const fib_node_vft_t hicn_face_fib_node_vft = { // Make this more flexible for future types face void -hicn_face_module_init (vlib_main_t * vm) +hicn_face_module_init (vlib_main_t *vm) { - pool_validate (hicn_dpoi_face_pool); pool_alloc (hicn_dpoi_face_pool, 1024); - counters = - vec_new (vlib_combined_counter_main_t, - HICN_PARAM_FACES_MAX * HICN_N_COUNTER); + counters = vec_new (vlib_combined_counter_main_t, + HICN_PARAM_FACES_MAX * HICN_N_COUNTER); - mhash_init (&hicn_face_vec_hashtb, - sizeof (hicn_face_input_faces_t) /* value */ , - sizeof (hicn_face_key_t) /* key */ ); - mhash_init (&hicn_face_hashtb, sizeof (hicn_face_id_t) /* value */ , - sizeof (hicn_face_key_t) /* key */ ); - - pool_alloc (hicn_vec_pool, 100); + mhash_init (&hicn_face_hashtb, sizeof (hicn_face_id_t) /* value */, + sizeof (hicn_face_key_t) /* key */); /* * How much useful is the following registration? * So far it seems that we need it only for setting the dpo_type. */ - hicn_face_type = - dpo_register_new_type (&hicn_face_dpo_vft, hicn_face_nodes); + hicn_face_type = dpo_register_new_type (&hicn_face_dpo_vft, hicn_face_nodes); /* - * We register a new node type to get informed when the adjacency corresponding - * to a face is updated + * We register a new node type to get informed when the adjacency + * corresponding to a face is updated */ hicn_face_fib_node_type = - fib_node_register_new_type (&hicn_face_fib_node_vft); + fib_node_register_new_type ("hicn_face_fib_node", &hicn_face_fib_node_vft); + + /* + * Init producer face module + */ + hicn_face_prod_init (); } u8 * -format_hicn_face (u8 * s, va_list * args) +format_hicn_face (u8 *s, va_list *args) { index_t index = va_arg (*args, index_t); u32 indent = va_arg (*args, u32); @@ -211,9 +203,8 @@ format_hicn_face (u8 * s, va_list * args) if ((face->flags & HICN_FACE_FLAGS_DELETED)) s = format (s, " (deleted)"); - s = format (s, "\n%U%U", - format_white_space, indent + 2, - format_dpo_id, &face->dpo, indent + 3); + s = format (s, "\n%U%U", format_white_space, indent + 2, format_dpo_id, + &face->dpo, indent + 3); } else { @@ -235,9 +226,8 @@ format_hicn_face (u8 * s, va_list * args) return s; } - u8 * -format_hicn_face_all (u8 * s, int n, ...) +format_hicn_face_all (u8 *s, int n, ...) { va_list ap; va_start (ap, n); @@ -247,12 +237,11 @@ format_hicn_face_all (u8 * s, int n, ...) hicn_face_t *face; - /* *INDENT-OFF* */ - pool_foreach ( face, hicn_dpoi_face_pool, - { - s = format(s, "%U\n", format_hicn_face, hicn_dpoi_get_index(face), indent); - }); - /* *INDENT-ON* */ + pool_foreach (face, hicn_dpoi_face_pool) + { + s = format (s, "%U\n", format_hicn_face, hicn_dpoi_get_index (face), + indent); + } return s; } @@ -260,47 +249,11 @@ format_hicn_face_all (u8 * s, int n, ...) int hicn_face_del (hicn_face_id_t face_id) { - hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - hicn_face_key_t key; - hicn_face_key_t old_key; - hicn_face_key_t old_key2; - - hicn_face_get_key (&(face->nat_addr), face->sw_if, &(face->dpo), &key); - hicn_face_input_faces_t *in_faces_vec = - hicn_face_get_vec (&(face->nat_addr), - &hicn_face_vec_hashtb); - if (in_faces_vec != NULL) - { - hicn_face_vec_t *vec = - pool_elt_at_index (hicn_vec_pool, in_faces_vec->vec_id); - u32 index_face = vec_search (*vec, face_id); - vec_del1 (*vec, index_face); - - if (vec_len (*vec) == 0) - { - pool_put_index (hicn_vec_pool, in_faces_vec->vec_id); - mhash_unset (&hicn_face_vec_hashtb, &key, (uword *) & old_key); - vec_free (*vec); - } - else - { - /* Check if the face we are deleting is the preferred one. */ - /* If so, repleace with another. */ - if (in_faces_vec->face_id == face_id) - { - in_faces_vec->face_id = (*vec)[0]; - } - } - - mhash_unset (&hicn_face_hashtb, &key, (uword *) & old_key2); - } - int ret = HICN_ERROR_NONE; if (hicn_dpoi_idx_is_valid (face_id)) { hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - face->locks--; if (face->locks == 0) pool_put_index (hicn_dpoi_face_pool, face_id); else @@ -309,15 +262,16 @@ hicn_face_del (hicn_face_id_t face_id) else ret = HICN_ERROR_FACE_NOT_FOUND; - return ret; } static void -hicn_iface_to_face (hicn_face_t * face, const dpo_id_t * dpo) +hicn_iface_to_face (hicn_face_t *face, const dpo_id_t *dpo, + dpo_proto_t dpo_proto) { - dpo_stack (hicn_face_type, dpo->dpoi_proto, &face->dpo, dpo); + dpo_stack (hicn_face_type, dpo_proto, &face->dpo, dpo); + face->dpo.dpoi_proto = dpo_proto; face->flags &= ~HICN_FACE_FLAGS_IFACE; face->flags |= HICN_FACE_FLAGS_FACE; @@ -326,7 +280,7 @@ hicn_iface_to_face (hicn_face_t * face, const dpo_id_t * dpo) fib_node_init (&face->fib_node, hicn_face_fib_node_type); fib_node_lock (&face->fib_node); - if (dpo->dpoi_type != DPO_ADJACENCY_MIDCHAIN || + if (dpo->dpoi_type != DPO_ADJACENCY_MIDCHAIN && dpo->dpoi_type != DPO_ADJACENCY_MCAST_MIDCHAIN) { ip_adjacency_t *adj = adj_get (dpo->dpoi_index); @@ -337,15 +291,11 @@ hicn_iface_to_face (hicn_face_t * face, const dpo_id_t * dpo) { fib_prefix_from_ip46_addr (nh, &prefix); - u32 fib_index = - fib_table_find (prefix.fp_proto, HICN_FIB_TABLE); + u32 fib_index = fib_table_find (prefix.fp_proto, HICN_FIB_TABLE); - face->fib_entry_index = fib_entry_track (fib_index, - &prefix, - hicn_face_fib_node_type, - hicn_dpoi_get_index - (face), - &face->fib_sibling); + face->fib_entry_index = fib_entry_track ( + fib_index, &prefix, hicn_face_fib_node_type, + hicn_dpoi_get_index (face), &face->fib_sibling); } } } @@ -356,13 +306,10 @@ hicn_iface_to_face (hicn_face_t * face, const dpo_id_t * dpo) * the ip_adjacency has already been set up. */ int -hicn_face_add (const dpo_id_t * dpo_nh, ip46_address_t * nat_address, - int sw_if, hicn_face_id_t * pfaceid, u8 is_app_prod) +hicn_face_add (const dpo_id_t *dpo_nh, ip46_address_t *nat_address, int sw_if, + hicn_face_id_t *pfaceid, dpo_proto_t dpo_proto) { - hicn_face_flags_t flags = (hicn_face_flags_t) 0; - flags |= HICN_FACE_FLAGS_FACE; - hicn_face_t *face; face = @@ -384,9 +331,7 @@ hicn_face_add (const dpo_id_t * dpo_nh, ip46_address_t * nat_address, if (face == NULL) { - - hicn_iface_add (nat_address, sw_if, pfaceid, dpo_nh->dpoi_proto, - dpo_nh->dpoi_index); + hicn_iface_add (nat_address, sw_if, pfaceid, dpo_nh->dpoi_index, 0); face = hicn_dpoi_get_from_idx (*pfaceid); mhash_set_mem (&hicn_face_hashtb, &key, (uword *) pfaceid, 0); @@ -401,71 +346,21 @@ hicn_face_add (const dpo_id_t * dpo_nh, ip46_address_t * nat_address, mhash_set_mem (&hicn_face_hashtb, &key, (uword *) pfaceid, 0); } - hicn_iface_to_face (face, dpo_nh); + hicn_iface_to_face (face, dpo_nh, dpo_proto); temp_dpo.dpoi_index = ~0; - hicn_face_input_faces_t *in_faces = - hicn_face_get_vec (nat_address, &hicn_face_vec_hashtb); - - if (in_faces == NULL) - { - hicn_face_input_faces_t in_faces_temp; - hicn_face_vec_t *vec; - pool_get (hicn_vec_pool, vec); - *vec = vec_new (hicn_face_id_t, 0); - u32 index = vec - hicn_vec_pool; - in_faces_temp.vec_id = index; - vec_add1 (*vec, *pfaceid); - - in_faces_temp.face_id = *pfaceid; - - hicn_face_get_key (nat_address, 0, &temp_dpo, &key); - - mhash_set_mem (&hicn_face_vec_hashtb, &key, - (uword *) & in_faces_temp, 0); - } - else - { - hicn_face_vec_t *vec = - pool_elt_at_index (hicn_vec_pool, in_faces->vec_id); - - /* */ - if (vec_search (*vec, *pfaceid) != ~0) - return HICN_ERROR_FACE_ALREADY_CREATED; - - vec_add1 (*vec, *pfaceid); - - hicn_iface_to_face (face, dpo_nh); - - hicn_face_get_key (nat_address, 0, &temp_dpo, &key); - - mhash_set_mem (&hicn_face_vec_hashtb, &key, (uword *) in_faces, 0); + retx_t *retx = vlib_process_signal_event_data ( + vlib_get_main (), hicn_mapme_eventmgr_process_node.index, + HICN_MAPME_EVENT_FACE_ADD, 1, sizeof (retx_t)); - /* If the face is an application producer face, we set it as the preferred incoming face. */ - /* This is required to handle the CS separation, and the push api in a lightway */ - if (is_app_prod) - { - in_faces->face_id = *pfaceid; - } - } - - retx_t *retx = vlib_process_signal_event_data (vlib_get_main (), - hicn_mapme_eventmgr_process_node. - index, - HICN_MAPME_EVENT_FACE_ADD, 1, - sizeof (retx_t)); - - /* *INDENT-OFF* */ - *retx = (retx_t) { + *retx = (retx_t){ .face_id = *pfaceid, }; - /* *INDENT-ON* */ return HICN_ERROR_NONE; } - /* * fd.io coding-style-patch-verification: ON * diff --git a/hicn-plugin/src/faces/face.h b/hicn-plugin/src/faces/face.h index 234c3fcc2..43900dd4e 100644 --- a/hicn-plugin/src/faces/face.h +++ b/hicn-plugin/src/faces/face.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -25,8 +25,12 @@ #include <vppinfra/bihash_8_8.h> #include <vnet/adj/adj_midchain.h> +#include <vpp_plugins/hicn/error.h> + +#include "face_flags.h" +#include "../hicn_buffer_flags.h" +#include "../hicn_logging.h" -#include "../error.h" typedef u8 hicn_face_flags_t; typedef index_t hicn_face_id_t; @@ -35,39 +39,40 @@ typedef index_t hicn_face_id_t; * * This file implements a general face type. The purpose of a face is to * carry the needed information to forward interest and data packets to the - * next node in the network. There are two type of faces: complete faces (in short - * faces), and incomplete faces (in short ifaces). + * next node in the network. There are two type of faces: complete faces (in + * short faces), and incomplete faces (in short ifaces). * * A face that does not contain the indication of the adjacency is an - * incomplete face (iface), otherwise it is considered to be complete. Ifaces are - * used to forward data back to the previous hICN hop from which we received an - * interest, while faces are used to forward interest packets to the next hicn node. - * Faces and ifaces are created at two different points in time. Faces are created - * when a route is added, while ifaces are created when an interest is received. - * In details, faces and ifaces carry the following information: - * - nat_addr: the ip address to perform src nat or dst nat on interest and data packets, respectively; + * incomplete face (iface), otherwise it is considered to be complete. Ifaces + * are used to forward data back to the previous hICN hop from which we + * received an interest, while faces are used to forward interest packets to + * the next hicn node. Faces and ifaces are created at two different points in + * time. Faces are created when a route is added, while ifaces are created when + * an interest is received. In details, faces and ifaces carry the following + * information: + * - nat_addr: the ip address to perform src nat or dst nat on interest and + * data packets, respectively; * - pl_id: the path label - * - locks: the number of entities using this face. When 0 the face can be deallocated - * - dpo: the dpo that identifies the next node in the vlib graph for processing the vlib - * buffer. The dpo contains the dpo.dpoi_next field that points to the next node - * in the vlib graph and the dpo.dpoi_index which is an index to adj used by the next node - * to perform the l2 rewrite. In case of ifaces, it is likely we don't know the - * adjacency when creting the face. In this case, the next node in the vlib graph - * will be the node that performs a lookup in the fib. Only in case of udp tunnels, - * which are bidirectional tunnel we know that the incoming tunnel is also the outgoing - * one, therefore in this case we store the tunnel in the dpo.dpoi_index fields. For - * all the other tunnels (which are most likely unidirectional), the source address of - * the interest will be used to retrieve the outgoing tunnel when sending the corresponding - * data back. + * - locks: the number of entities using this face. When 0 the face can be + * deallocated + * - dpo: the dpo that identifies the next node in the vlib graph for + * processing the vlib buffer. The dpo contains the dpo.dpoi_next field that + * points to the next node in the vlib graph and the dpo.dpoi_index which is an + * index to adj used by the next node to perform the l2 rewrite. In case of + * ifaces, it is likely we don't know the adjacency when creting the face. In + * this case, the next node in the vlib graph will be the node that performs a + * lookup in the fib. Only in case of udp tunnels, which are bidirectional + * tunnel we know that the incoming tunnel is also the outgoing one, therefore + * in this case we store the tunnel in the dpo.dpoi_index fields. For all the + * other tunnels (which are most likely unidirectional), the source address of + * the interest will be used to retrieve the outgoing tunnel when sending the + * corresponding data back. * - sw_if: the incoming interface of the interest - * - fib_node, fib_entry_index and fib_sibling are information used to be notified of - * changes in the adjacency pointed by the dpo. + * - fib_node, fib_entry_index and fib_sibling are information used to be + * notified of changes in the adjacency pointed by the dpo. * - * We maintain two hash tables to retrieve faces and ifaces. In particular one hash table which - * index faces and ifaces for nat_address, sw_if and dpo. This is used to retrieve existing faces - * or ifaces when an interest is received and when an new face is created. A second hash table that - * indexes vectors of faces for nat_address and sw_if. This is used to retrieve a list of possible - * incoming faces when a data is received. + * We maintain one hash tables to retrieve faces and ifaces, which indexes + * faces and ifaces for nat_address, sw_if and dpo. */ /** @@ -82,7 +87,7 @@ typedef struct __attribute__ ((packed)) hicn_face_s hicn_face_flags_t flags; /* Align the upcoming fields */ - u8 align; + u8 iface_next; /* Path label (2B) */ u16 pl_id; @@ -91,7 +96,8 @@ typedef struct __attribute__ ((packed)) hicn_face_s u32 locks; /* Dpo for the adjacency (8B) */ - union { + union + { dpo_id_t dpo; u64 align_dpo; }; @@ -112,75 +118,39 @@ typedef struct __attribute__ ((packed)) hicn_face_s /* Pool of faces */ extern hicn_face_t *hicn_dpoi_face_pool; -/* Flags */ -/* A face is complete and it stores all the information. A iface lacks of the - adj index, therefore sending a packet through a iface require a lookup in - the FIB. */ -#define HICN_FACE_FLAGS_DEFAULT 0x00 -#define HICN_FACE_FLAGS_FACE 0x01 -#define HICN_FACE_FLAGS_IFACE 0x02 -#define HICN_FACE_FLAGS_APPFACE_PROD 0x04 /* Currently only IP face can be appface */ -#define HICN_FACE_FLAGS_APPFACE_CONS 0x08 /* Currently only IP face can be appface */ -#define HICN_FACE_FLAGS_DELETED 0x10 - #define HICN_FACE_NULL (hicn_face_id_t) ~0 -#define HICN_FACE_FLAGS_APPFACE_PROD_BIT 2 -#define HICN_FACE_FLAGS_APPFACE_CONS_BIT 3 - - -#define HICN_BUFFER_FLAGS_DEFAULT 0x00 -#define HICN_BUFFER_FLAGS_FACE_IS_APP 0x01 - -STATIC_ASSERT ((1 << HICN_FACE_FLAGS_APPFACE_PROD_BIT) == - HICN_FACE_FLAGS_APPFACE_PROD, - "HICN_FACE_FLAGS_APPFACE_PROD_BIT and HICN_FACE_FLAGS_APPFACE_PROD must correspond"); - -STATIC_ASSERT ((1 << HICN_FACE_FLAGS_APPFACE_CONS_BIT) == - HICN_FACE_FLAGS_APPFACE_CONS, - "HICN_FACE_FLAGS_APPFACE_CONS_BIT and HICN_FACE_FLAGS_APPFACE_CONS must correspond"); - -STATIC_ASSERT ((HICN_FACE_FLAGS_APPFACE_PROD >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT) == - HICN_BUFFER_FLAGS_FACE_IS_APP, - "hicn buffer app flag does not correspond to HICN_FACE_FLAGS_APPFACE_PROD"); - -STATIC_ASSERT ((HICN_FACE_FLAGS_APPFACE_CONS >> - HICN_FACE_FLAGS_APPFACE_CONS_BIT) == - HICN_BUFFER_FLAGS_FACE_IS_APP, - "hicn buffer app flag does not correspond to HICN_FACE_FLAGS_APPFACE_PROD"); - /** * @brief Definition of the virtual functin table for an hICN FACE DPO. */ typedef struct hicn_face_vft_s { - u8 *(*format_face) (u8 * s, va_list * args); + u8 *(*format_face) (u8 *s, va_list *args); /**< Format an hICN face dpo*/ int (*hicn_face_del) (hicn_face_id_t face_id); - void (*hicn_face_get_dpo) (hicn_face_t * face, dpo_id_t * dpo); + void (*hicn_face_get_dpo) (hicn_face_t *face, dpo_id_t *dpo); } hicn_face_vft_t; -#define foreach_hicn_face_counter \ - _(INTEREST_RX, 0, "Interest rx") \ - _(INTEREST_TX, 1, "Interest tx") \ - _(DATA_RX, 2, "Data rx") \ - _(DATA_TX, 3, "Data tx") \ +#define foreach_hicn_face_counter \ + _ (INTEREST_RX, 0, "Interest rx") \ + _ (INTEREST_TX, 1, "Interest tx") \ + _ (DATA_RX, 2, "Data rx") \ + _ (DATA_TX, 3, "Data tx") typedef enum { -#define _(a,b,c) HICN_FACE_COUNTERS_##a = (b), +#define _(a, b, c) HICN_FACE_COUNTERS_##a = (b), foreach_hicn_face_counter #undef _ - HICN_N_COUNTER + HICN_N_COUNTER } hicn_face_counters_t; extern mhash_t hicn_face_hashtb; extern const char *HICN_FACE_CTRX_STRING[]; -#define get_face_counter_string(ctrxno) (char *)(HICN_FACE_CTRX_STRING[ctrxno]) - +#define get_face_counter_string(ctrxno) \ + (char *) (HICN_FACE_CTRX_STRING[ctrxno]) /* Vector maintaining a dpo per face */ extern dpo_id_t *face_dpo_vec; @@ -189,6 +159,9 @@ extern hicn_face_vft_t *face_vft_vec; /* Vector holding the set of face names */ extern char **face_type_names_vec; +/* Pathlabel counter */ +extern u8 pl_index; + /* First face type registered in the sytem.*/ extern dpo_type_t first_type; @@ -202,7 +175,7 @@ extern vlib_combined_counter_main_t *counters; * @return face id */ always_inline hicn_face_id_t -hicn_dpoi_get_index (hicn_face_t * face_dpoi) +hicn_dpoi_get_index (hicn_face_t *face_dpoi) { return face_dpoi - hicn_dpoi_face_pool; } @@ -217,7 +190,7 @@ hicn_dpoi_get_index (hicn_face_t * face_dpoi) always_inline hicn_face_t * hicn_dpoi_get_from_idx_safe (hicn_face_id_t dpoi_index) { - if (!pool_is_free_index(hicn_dpoi_face_pool, dpoi_index)) + if (!pool_is_free_index (hicn_dpoi_face_pool, dpoi_index)) return (hicn_face_t *) pool_elt_at_index (hicn_dpoi_face_pool, dpoi_index); else return NULL; @@ -241,10 +214,18 @@ hicn_dpoi_get_from_idx (hicn_face_id_t dpoi_index) always_inline int hicn_dpoi_idx_is_valid (hicn_face_id_t face_id) { - return pool_len (hicn_dpoi_face_pool) > face_id - && !pool_is_free_index (hicn_dpoi_face_pool, face_id); + return pool_len (hicn_dpoi_face_pool) > face_id && + !pool_is_free_index (hicn_dpoi_face_pool, face_id); } +/** + * @brief Delete a face + * + * @param face_id Id of the face to delete + * @return HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise + * HICN_ERROR_NONE + */ +int hicn_face_del (hicn_face_id_t face_id); /** * @brief Add a lock to the face dpo @@ -264,12 +245,24 @@ hicn_face_lock_with_id (hicn_face_id_t face_id) * * @param dpo Pointer to the face dpo */ -always_inline void +always_inline int hicn_face_unlock_with_id (hicn_face_id_t face_id) { hicn_face_t *face; face = hicn_dpoi_get_from_idx (face_id); - face->locks--; + + if (face->locks > 0) + { + face->locks--; + + if (face->locks == 0) + { + HICN_DEBUG ("Deleting face %d", face_id); + return hicn_face_del (face_id); + } + } + + return HICN_ERROR_NONE; } /** @@ -278,32 +271,31 @@ hicn_face_unlock_with_id (hicn_face_id_t face_id) * @param dpo Pointer to the face dpo */ always_inline void -hicn_face_lock (dpo_id_t * dpo) +hicn_face_lock (dpo_id_t *dpo) { - hicn_face_lock_with_id(dpo->dpoi_index); + hicn_face_lock_with_id (dpo->dpoi_index); } /** - * @brief Remove a lock to the face through its dpo. Deallocate the face id locks == 0 + * @brief Remove a lock to the face through its dpo. Deallocate the face id + * locks == 0 * * @param dpo Pointer to the face dpo */ always_inline void -hicn_face_unlock (dpo_id_t * dpo) +hicn_face_unlock (dpo_id_t *dpo) { hicn_face_unlock_with_id (dpo->dpoi_index); } - /** * @brief Init the internal structures of the face module * * Must be called before processing any packet */ -void hicn_face_module_init (vlib_main_t * vm); - -u8 * format_hicn_face (u8 * s, va_list * args); +void hicn_face_module_init (vlib_main_t *vm); +u8 *format_hicn_face (u8 *s, va_list *args); /** * @brief Format all the existing faces @@ -312,16 +304,7 @@ u8 * format_hicn_face (u8 * s, va_list * args); * @param n Number of input parameters * @return String with the faces formatted */ -u8 *format_hicn_face_all (u8 * s, int n, ...); - -/** - * @brief Delete a face - * - * @param face_id Id of the face to delete - * @return HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise - * HICN_ERROR_NONE - */ -int hicn_face_del (hicn_face_id_t face_id); +u8 *format_hicn_face_all (u8 *s, int n, ...); /** * @bried vector of faces used to collect faces having the same local address @@ -334,34 +317,25 @@ typedef struct hicn_input_faces_s_ /* Vector of all possible input faces */ u32 vec_id; - /* Preferred face. If an prod_app face is in the vector it will be the preferred one. */ - /* It's not possible to have multiple prod_app face in the same vector, they would have */ - /* the same local address. Every prod_app face is a point-to-point face between the forwarder */ + /* Preferred face. If an prod_app face is in the vector it will be the + * preferred one. */ + /* It's not possible to have multiple prod_app face in the same vector, they + * would have */ + /* the same local address. Every prod_app face is a point-to-point face + * between the forwarder */ /* and the application. */ hicn_face_id_t face_id; } hicn_face_input_faces_t; /** - * Pool containing the vector of possible incoming faces. - */ -extern hicn_face_vec_t *hicn_vec_pool; - -/** - * Hash tables that indexes a face by remote address. For fast lookup when an - * interest arrives. - */ -extern mhash_t hicn_face_vec_hashtb; - - -/** * Key definition for the mhash table. An face is uniquely identified by ip - * address, the interface id and a dpo pointing to the next node in the vlib graph. - * The ip address can correspond to the remote ip address of the next hicn hop, - * or to the local address of the receiving interface. The former is used to - * retrieve the incoming face when an interest is received, the latter when - * the arring packet is a data. If the face is a regular face - * In case of iface, the following structure can be filled in different ways: + * address, the interface id and a dpo pointing to the next node in the vlib + * graph. The ip address can correspond to the remote ip address of the next + * hicn hop, or to the local address of the receiving interface. The former is + * used to retrieve the incoming face when an interest is received, the latter + * when the arring packet is a data. If the face is a regular face In case of + * iface, the following structure can be filled in different ways: * - dpo equal to DPO_INVALID when the iface is a regular hICN iface * - in case of udp_tunnel dpo = * { @@ -377,7 +351,8 @@ extern mhash_t hicn_face_vec_hashtb; typedef struct __attribute__ ((packed)) hicn_face_key_s { ip46_address_t addr; - union { + union + { dpo_id_t dpo; u64 align_dpo; }; @@ -393,8 +368,8 @@ typedef struct __attribute__ ((packed)) hicn_face_key_s * @param key Pointer to an allocated hicn_face_ip_key_t object */ always_inline void -hicn_face_get_key (const ip46_address_t * addr, - u32 sw_if, const dpo_id_t * dpo, hicn_face_key_t * key) +hicn_face_get_key (const ip46_address_t *addr, u32 sw_if, const dpo_id_t *dpo, + hicn_face_key_t *key) { key->dpo = *dpo; key->addr = *addr; @@ -405,13 +380,15 @@ hicn_face_get_key (const ip46_address_t * addr, * @brief Get the face obj from the nat address. Does not add any lock. * * @param addr Ip v4 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. + * @param sw_if Software interface id used to create the key for the hash + * table. * @param hashtb Hash table (remote or local) where to perform the lookup. * * @result Pointer to the face. */ always_inline hicn_face_t * -hicn_face_get (const ip46_address_t * addr, u32 sw_if, mhash_t * hashtb, index_t adj_index) +hicn_face_get (const ip46_address_t *addr, u32 sw_if, mhash_t *hashtb, + index_t adj_index) { hicn_face_key_t key; @@ -421,12 +398,11 @@ hicn_face_get (const ip46_address_t * addr, u32 sw_if, mhash_t * hashtb, index_t hicn_face_get_key (addr, sw_if, &dpo, &key); - hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, - &key); + hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, &key); - if ( dpoi_index != NULL) + if (dpoi_index != NULL && hicn_dpoi_idx_is_valid (*dpoi_index)) { - hicn_face_lock_with_id(*dpoi_index); + hicn_face_lock_with_id (*dpoi_index); return hicn_dpoi_get_from_idx (*dpoi_index); } @@ -434,27 +410,29 @@ hicn_face_get (const ip46_address_t * addr, u32 sw_if, mhash_t * hashtb, index_t } /** - * @brief Get the face obj from the nat address and the dpo. Does not add any lock. + * @brief Get the face obj from the nat address and the dpo. Does not add any + * lock. * * @param addr Ip v4 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. + * @param sw_if Software interface id used to create the key for the hash + * table. * @param hashtb Hash table (remote or local) where to perform the lookup. * * @result Pointer to the face. */ always_inline hicn_face_t * -hicn_face_get_with_dpo (const ip46_address_t * addr, u32 sw_if, const dpo_id_t * dpo, mhash_t * hashtb) +hicn_face_get_with_dpo (const ip46_address_t *addr, u32 sw_if, + const dpo_id_t *dpo, mhash_t *hashtb) { hicn_face_key_t key; hicn_face_get_key (addr, sw_if, dpo, &key); - hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, - &key); + hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, &key); - if ( dpoi_index != NULL) + if (dpoi_index != NULL && hicn_dpoi_idx_is_valid (*dpoi_index)) { - hicn_face_lock_with_id(*dpoi_index); + hicn_face_lock_with_id (*dpoi_index); return hicn_dpoi_get_from_idx (*dpoi_index); } @@ -462,27 +440,6 @@ hicn_face_get_with_dpo (const ip46_address_t * addr, u32 sw_if, const dpo_id_t * } /** - * @brief Get the vector of faces from the ip v4 address. Does not add any lock. - * - * @param addr Ip v4 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. - * @param hashtb Hash table (remote or local) where to perform the lookup. - * - * @result Pointer to the face. - */ -always_inline hicn_face_input_faces_t * -hicn_face_get_vec (const ip46_address_t * addr, - mhash_t * hashtb) -{ - hicn_face_key_t key; - - dpo_id_t dpo = DPO_INVALID; - - hicn_face_get_key (addr, 0, &dpo, &key); - return (hicn_face_input_faces_t *) mhash_get (hashtb, &key); -} - -/** * @brief Create a new face ip. API for other modules (e.g., routing) * * @param dpo_nh dpo contained in the face that points to the next node in @@ -490,15 +447,13 @@ hicn_face_get_vec (const ip46_address_t * addr, * @param nat_addr nat ip v4 or v6 address of the face * @param sw_if interface associated to the face * @param pfaceid Pointer to return the face id - * @param is_app_prod if HICN_FACE_FLAGS_APPFACE_PROD the face is a local application face, all other values are ignored + * @param is_app_prod if HICN_FACE_FLAGS_APPFACE_PROD the face is a local + * application face, all other values are ignored * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally * reachable ip address, otherwise HICN_ERROR_NONE */ -int hicn_face_add (const dpo_id_t * dpo_nh, - ip46_address_t * nat_address, - int sw_if, - hicn_face_id_t * pfaceid, - u8 is_app_prod); +int hicn_face_add (const dpo_id_t *dpo_nh, ip46_address_t *nat_address, + int sw_if, hicn_face_id_t *pfaceid, dpo_proto_t dpo_proto); /** * @brief Create a new incomplete face ip. (Meant to be used by the data plane) @@ -511,27 +466,28 @@ int hicn_face_add (const dpo_id_t * dpo_nh, * reachable ip address, otherwise HICN_ERROR_NONE */ always_inline void -hicn_iface_add (ip46_address_t * nat_address, int sw_if, - hicn_face_id_t * pfaceid, dpo_proto_t proto, - u32 adj_index) +hicn_iface_add (const ip46_address_t *nat_address, int sw_if, + hicn_face_id_t *pfaceid, u32 adj_index, u8 flags) { hicn_face_t *face; pool_get (hicn_dpoi_face_pool, face); - clib_memcpy (&(face->nat_addr), nat_address, - sizeof (ip46_address_t)); + clib_memcpy (&(face->nat_addr), nat_address, sizeof (ip46_address_t)); face->sw_if = sw_if; - face->dpo.dpoi_type = DPO_FIRST; - face->dpo.dpoi_proto = DPO_PROTO_NONE; + face->dpo = (dpo_id_t) DPO_INVALID; face->dpo.dpoi_index = adj_index; - face->dpo.dpoi_next_node = 0; - face->pl_id = (u16) 0; - face->flags = HICN_FACE_FLAGS_IFACE; - face->locks = 1; hicn_face_key_t key; hicn_face_get_key (nat_address, sw_if, &face->dpo, &key); + + face->iface_next = 1; + + face->pl_id = pl_index++; + face->flags = HICN_FACE_FLAGS_IFACE; + face->flags |= flags; + face->locks = 1; + *pfaceid = hicn_dpoi_get_index (face); mhash_set_mem (&hicn_face_hashtb, &key, (uword *) pfaceid, 0); @@ -544,97 +500,50 @@ hicn_iface_add (ip46_address_t * nat_address, int sw_if, } } -/**** Helpers to manipulate faces and ifaces from the face/iface input nodes ****/ +/**** Helpers to manipulate faces and ifaces from the face/iface input nodes + * ****/ /** - * @brief Retrieve a vector of faces from the ip4 local address and returns its index. - * - * @param vec: Result of the lookup. If no face exists for the local address vec = NULL - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not - * @param local_addr: Ip v4 nat address of the face - * @param sw_if: software interface id of the face - * - * @result HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise HICN_ERROR_NONE. + * @brief Call back to get the adj of the tunnel */ -always_inline int -hicn_face_ip4_lock (hicn_face_id_t * face_id, - u32 * in_faces_vec_id, - u8 * hicnb_flags, - const ip4_address_t * nat_addr) +static adj_walk_rc_t +hicn4_iface_adj_walk_cb (adj_index_t ai, void *ctx) { - ip46_address_t ip_address = {0}; - ip46_address_set_ip4(&ip_address, nat_addr); - hicn_face_input_faces_t *in_faces_vec = - hicn_face_get_vec (&ip_address, &hicn_face_vec_hashtb); - - if (PREDICT_FALSE (in_faces_vec == NULL)) - return HICN_ERROR_FACE_NOT_FOUND; - *in_faces_vec_id = in_faces_vec->vec_id; - hicn_face_t *face = hicn_dpoi_get_from_idx (in_faces_vec->face_id); + hicn_face_t *face = (hicn_face_t *) ctx; - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - *hicnb_flags |= - (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; + dpo_set (&face->dpo, DPO_ADJACENCY_MIDCHAIN, DPO_PROTO_IP4, ai); + adj_nbr_midchain_stack (ai, &face->dpo); - *face_id = in_faces_vec->face_id; - - return HICN_ERROR_NONE; + return (ADJ_WALK_RC_CONTINUE); } -/** - * @brief Retrieve a face from the ip6 local address and returns its dpo. This - * method adds a lock on the face state. - * - * @param dpo: Result of the lookup. If the face doesn't exist dpo = NULL - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not - * @param nat_addr: Ip v6 nat address of the face - * @param sw_if: software interface id of the face - * - * @result HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise HICN_ERROR_NONE. - */ always_inline int -hicn_face_ip6_lock (hicn_face_id_t * face_id, - u32 * in_faces_vec_id, - u8 * hicnb_flags, - const ip6_address_t * nat_addr) +hicn_face_ip4_find (hicn_face_id_t *index, u8 *hicnb_flags, + const ip4_address_t *nat_addr, u32 sw_if, u32 adj_index, + u32 node_index) { - hicn_face_input_faces_t *in_faces_vec = - hicn_face_get_vec ((ip46_address_t *)nat_addr, &hicn_face_vec_hashtb); - - if (PREDICT_FALSE (in_faces_vec == NULL)) - return HICN_ERROR_FACE_NOT_FOUND; - - *in_faces_vec_id = in_faces_vec->vec_id; - hicn_face_t *face = hicn_dpoi_get_from_idx (in_faces_vec->face_id); - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - *hicnb_flags |= - (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; - - *face_id = in_faces_vec->face_id; + int ret = HICN_ERROR_FACE_NOT_FOUND; + hicn_face_id_t face_id; - return HICN_ERROR_NONE; -} + /*All (complete) faces are indexed by remote addess as well */ + /* if the face exists, it adds a lock */ + hicn_face_t *face = hicn_face_get ((const ip46_address_t *) nat_addr, sw_if, + &hicn_face_hashtb, adj_index); -/** - * @brief Call back to get the adj of the tunnel - */ -static adj_walk_rc_t -hicn4_iface_adj_walk_cb (adj_index_t ai, - void *ctx) -{ + if (face != NULL) + { + /* unlock the face. We don't take a lock on each interest we receive */ + face_id = hicn_dpoi_get_index (face); + hicn_face_unlock_with_id (face_id); - hicn_face_t *face = (hicn_face_t *)ctx; + *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; + *index = face_id; - dpo_set(&face->dpo, DPO_ADJACENCY_MIDCHAIN, DPO_PROTO_IP4, ai); - adj_nbr_midchain_stack(ai, &face->dpo); + ret = HICN_ERROR_FACE_ALREADY_CREATED; + } - return (ADJ_WALK_RC_CONTINUE); + return ret; } /** @@ -648,83 +557,95 @@ hicn4_iface_adj_walk_cb (adj_index_t ai, * @param sw_if: software interface id of the face * @param node_index: vlib edge index to use in the packet processing */ -always_inline void -hicn_iface_ip4_add_and_lock (hicn_face_id_t * index, - u8 * hicnb_flags, - const ip4_address_t * nat_addr, - u32 sw_if, u32 adj_index, u32 node_index) +always_inline int +hicn_face_ip4_add_and_lock (hicn_face_id_t *index, u8 *hicnb_flags, + const ip4_address_t *nat_addr, u32 sw_if, + u32 adj_index, u32 node_index) { - /*All (complete) faces are indexed by remote addess as well */ + int ret = HICN_ERROR_NONE; + hicn_face_t *face = NULL; - ip46_address_t ip_address = {0}; - ip46_address_set_ip4(&ip_address, nat_addr); + ret = hicn_face_ip4_find (index, hicnb_flags, nat_addr, sw_if, adj_index, + node_index); - /* if the face exists, it adds a lock */ - hicn_face_t *face = - hicn_face_get (&ip_address, sw_if, &hicn_face_hashtb, adj_index); - - if (face == NULL) + if (ret == HICN_ERROR_FACE_NOT_FOUND) { + ip46_address_t ip_address = { 0 }; + ip46_address_set_ip4 (&ip_address, nat_addr); + hicn_face_id_t idx; - hicn_iface_add (&ip_address, sw_if, &idx, DPO_PROTO_IP4, adj_index); + u8 face_flags = *hicnb_flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL ? + HICN_FACE_FLAGS_UDP4 : + *hicnb_flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL ? + HICN_FACE_FLAGS_UDP6 : + 0; - face = hicn_dpoi_get_from_idx(idx); + hicn_iface_add (&ip_address, sw_if, &idx, adj_index, face_flags); - face->dpo.dpoi_type = DPO_FIRST; - face->dpo.dpoi_proto = DPO_PROTO_IP4; - face->dpo.dpoi_index = adj_index; - face->dpo.dpoi_next_node = node_index; + face = hicn_dpoi_get_from_idx (idx); + + face->iface_next = node_index; /* if (nat_addr->as_u32 == 0) */ /* { */ - adj_nbr_walk(face->sw_if, - FIB_PROTOCOL_IP4, - hicn4_iface_adj_walk_cb, - face); - /* } */ + adj_nbr_walk (face->sw_if, FIB_PROTOCOL_IP4, hicn4_iface_adj_walk_cb, + face); + /* } */ *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; + *hicnb_flags |= HICN_BUFFER_FLAGS_NEW_FACE; *index = idx; - return; - } - else - { - /* unlock the face. We don't take a lock on each interest we receive */ - hicn_face_id_t face_id = hicn_dpoi_get_index(face); - hicn_face_unlock_with_id(face_id); } - /* Code replicated on purpose */ - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - *hicnb_flags |= - (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; - - *index = hicn_dpoi_get_index (face); + return ret; } /** * @brief Call back to get the adj of the tunnel */ static adj_walk_rc_t -hicn6_iface_adj_walk_cb (adj_index_t ai, - void *ctx) +hicn6_iface_adj_walk_cb (adj_index_t ai, void *ctx) { - hicn_face_t *face = (hicn_face_t *)ctx; + hicn_face_t *face = (hicn_face_t *) ctx; - ip_adjacency_t *adj = adj_get(ai); + ip_adjacency_t *adj = adj_get (ai); if ((adj->lookup_next_index == IP_LOOKUP_NEXT_MIDCHAIN) || (adj->lookup_next_index == IP_LOOKUP_NEXT_MCAST_MIDCHAIN)) { - dpo_set(&face->dpo, DPO_ADJACENCY_MIDCHAIN, adj->ia_nh_proto, ai); - adj_nbr_midchain_stack(ai, &face->dpo); + dpo_set (&face->dpo, DPO_ADJACENCY_MIDCHAIN, + (dpo_proto_t) adj->ia_nh_proto, ai); + adj_nbr_midchain_stack (ai, &face->dpo); } return (ADJ_WALK_RC_CONTINUE); } +always_inline int +hicn_face_ip6_find (hicn_face_id_t *index, u8 *hicnb_flags, + const ip6_address_t *nat_addr, u32 sw_if, u32 adj_index, + u32 node_index) +{ + int ret = HICN_ERROR_FACE_NOT_FOUND; + hicn_face_id_t face_id; + + hicn_face_t *face = hicn_face_get ((const ip46_address_t *) nat_addr, sw_if, + &hicn_face_hashtb, adj_index); + + if (face != NULL) + { + /* unlock the face. We don't take a lock on each interest we receive */ + face_id = hicn_dpoi_get_index (face); + hicn_face_unlock_with_id (face_id); + *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; + *index = face_id; + + ret = HICN_ERROR_FACE_ALREADY_CREATED; + } + + return ret; +} /** * @brief Retrieve, or create if it doesn't exist, a face from the ip6 local @@ -737,54 +658,59 @@ hicn6_iface_adj_walk_cb (adj_index_t ai, * @param sw_if: software interface id of the face * @param node_index: vlib edge index to use in the packet processing */ -always_inline void -hicn_iface_ip6_add_and_lock (hicn_face_id_t * index, - u8 * hicnb_flags, - const ip6_address_t * nat_addr, - u32 sw_if, u32 adj_index, u32 node_index) +always_inline int +hicn_face_ip6_add_and_lock (hicn_face_id_t *index, u8 *hicnb_flags, + const ip6_address_t *nat_addr, u32 sw_if, + u32 adj_index, u32 node_index) { - /*All (complete) faces are indexed by remote addess as well */ - /* if the face exists, it adds a lock */ - hicn_face_t *face = - hicn_face_get ((ip46_address_t *)nat_addr, sw_if, &hicn_face_hashtb, adj_index); + int ret = HICN_ERROR_NONE; + hicn_face_t *face = NULL; + + ret = hicn_face_ip6_find (index, hicnb_flags, nat_addr, sw_if, adj_index, + node_index); - if (face == NULL) + if (ret == HICN_ERROR_FACE_NOT_FOUND) { + ip46_address_t ip_address = { 0 }; + ip46_address_set_ip6 (&ip_address, nat_addr); hicn_face_id_t idx; - hicn_iface_add ((ip46_address_t *) nat_addr, sw_if, &idx, DPO_PROTO_IP6, adj_index); + u8 face_flags = *hicnb_flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL ? + HICN_FACE_FLAGS_UDP4 : + *hicnb_flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL ? + HICN_FACE_FLAGS_UDP6 : + 0; - face = hicn_dpoi_get_from_idx(idx); + hicn_iface_add ((const ip46_address_t *) nat_addr, sw_if, &idx, + adj_index, face_flags); - face->dpo.dpoi_type = DPO_FIRST; - face->dpo.dpoi_proto = DPO_PROTO_IP6; - face->dpo.dpoi_index = adj_index; - face->dpo.dpoi_next_node = node_index; + face = hicn_dpoi_get_from_idx (idx); + face->iface_next = node_index; - adj_nbr_walk(face->sw_if, - FIB_PROTOCOL_IP6, - hicn6_iface_adj_walk_cb, - face); - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; + adj_nbr_walk (face->sw_if, FIB_PROTOCOL_IP6, hicn6_iface_adj_walk_cb, + face); + *hicnb_flags = HICN_BUFFER_FLAGS_NEW_FACE; *index = idx; - - return; - } - else - { - /* unlock the face. We don't take a lock on each interest we receive */ - hicn_face_id_t face_id = hicn_dpoi_get_index(face); - hicn_face_unlock_with_id(face_id); } - /* Code replicated on purpose */ - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - *hicnb_flags |= - (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; + return ret; +} + +/** + * @brief Check if a face is an application face + * + * @param face_id: The id of the face + * @return 1 if application face, 0 otherwise + */ +always_inline int +hicn_face_is_local (hicn_face_id_t face_id) +{ + hicn_face_t *face; + face = hicn_dpoi_get_from_idx (face_id); + ASSERT (face != NULL); - *index = hicn_dpoi_get_index (face); + return face->flags & HICN_FACE_FLAGS_APPFACE_PROD || + face->flags & HICN_FACE_FLAGS_APPFACE_CONS; } #endif // __HICN_FACE_H__ diff --git a/hicn-plugin/src/faces/face_cli.c b/hicn-plugin/src/faces/face_cli.c index e9e516cc6..1c1501478 100644 --- a/hicn-plugin/src/faces/face_cli.c +++ b/hicn-plugin/src/faces/face_cli.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2023 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,9 +19,8 @@ #include "../error.h" static clib_error_t * -hicn_face_cli_show_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) +hicn_face_cli_show_command_fn (vlib_main_t *vm, unformat_input_t *main_input, + vlib_cli_command_t *cmd) { hicn_face_id_t face_id = HICN_FACE_NULL; @@ -46,9 +45,8 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, deleted = 1; else { - return clib_error_return (0, "%s", - get_error_string - (HICN_ERROR_CLI_INVAL)); + return clib_error_return ( + 0, "%s", get_error_string (HICN_ERROR_CLI_INVAL)); } } @@ -56,48 +54,43 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, { int idx = 0; vec_foreach_index (idx, face_type_names_vec) - { - if (!strcmp (face_type_names_vec[idx], face_type_name)) - found = idx; - } + { + if (!strcmp (face_type_names_vec[idx], face_type_name)) + found = idx; + } if (found == ~0) return (clib_error_return (0, "Face type unknown")); } - } if (face_id != HICN_FACE_NULL) { if (!hicn_dpoi_idx_is_valid (face_id)) - return clib_error_return (0, "%s", - get_error_string - (HICN_ERROR_FACE_NOT_FOUND)); + return clib_error_return ( + 0, "%s", get_error_string (HICN_ERROR_FACE_NOT_FOUND)); hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - vlib_cli_output (vm, "%U\n", format_hicn_face, face_id, 0 /*indent */ ); + vlib_cli_output (vm, "%U\n", format_hicn_face, face_id, 0 /*indent */); u32 indent = 3; for (int i = 0; i < HICN_N_COUNTER; i++) { - vlib_get_combined_counter (&counters - [hicn_dpoi_get_index (face) * - HICN_N_COUNTER], i, &v); - s = - format (s, "%U%s", format_white_space, indent, - HICN_FACE_CTRX_STRING[i]); + vlib_get_combined_counter ( + &counters[hicn_dpoi_get_index (face) * HICN_N_COUNTER], i, &v); + s = format (s, "%U%s", format_white_space, indent, + HICN_FACE_CTRX_STRING[i]); if (n) - _vec_len (n) = 0; + vec_set_len (n, 0); n = format (n, "packets"); - s = - format (s, "%U%-16v%16Ld", format_white_space, - 30 - strlen (HICN_FACE_CTRX_STRING[i]), n, v.packets); + s = format (s, "%U%-16v%16Ld", format_white_space, + 30 - strlen (HICN_FACE_CTRX_STRING[i]), n, v.packets); - _vec_len (n) = 0; + vec_set_len (n, 0); n = format (n, "bytes"); - s = format (s, "\n%U%-16v%16Ld\n", - format_white_space, indent + 30, n, v.bytes); + s = format (s, "\n%U%-16v%16Ld\n", format_white_space, indent + 30, + n, v.bytes); } vlib_cli_output (vm, "%s\n", s); } @@ -106,69 +99,79 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, if (found != ~0) { hicn_face_t *face; - /* *INDENT-OFF* */ - pool_foreach(face, hicn_dpoi_face_pool, - { - if (!((face->flags & HICN_FACE_FLAGS_DELETED) && !deleted)) - { - if (face->flags) - { - vlib_cli_output(vm, "%U\n", format_hicn_face, hicn_dpoi_get_index(face), 0); - u8 * s = 0; - u32 indent = 3; - - for (int i = 0; i < HICN_N_COUNTER; i++) - { - vlib_get_combined_counter (&counters[hicn_dpoi_get_index(face) * HICN_N_COUNTER], i, &v); - s = format (s, "%U%s",format_white_space, indent, HICN_FACE_CTRX_STRING[i]); - - if (n) - _vec_len (n) = 0; - n = format (n, "packets"); - s = format (s, "%U%-16v%16Ld", format_white_space, 30-strlen(HICN_FACE_CTRX_STRING[i]), n, v.packets); - - _vec_len (n) = 0; - n = format (n, "bytes"); - s = format (s, "\n%U%-16v%16Ld\n", - format_white_space, indent+30, n, v.bytes); - } - vlib_cli_output (vm, "%s\n", s); - } - } - }); - /* *INDENT-ON* */ + pool_foreach (face, hicn_dpoi_face_pool) + { + if (!((face->flags & HICN_FACE_FLAGS_DELETED) && !deleted)) + { + if (face->flags) + { + vlib_cli_output (vm, "%U\n", format_hicn_face, + hicn_dpoi_get_index (face), 0); + u8 *s = 0; + u32 indent = 3; + + for (int i = 0; i < HICN_N_COUNTER; i++) + { + vlib_get_combined_counter ( + &counters[hicn_dpoi_get_index (face) * + HICN_N_COUNTER], + i, &v); + s = format (s, "%U%s", format_white_space, indent, + HICN_FACE_CTRX_STRING[i]); + + if (n) + vec_set_len (n, 0); + n = format (n, "packets"); + s = format (s, "%U%-16v%16Ld", format_white_space, + 30 - strlen (HICN_FACE_CTRX_STRING[i]), + n, v.packets); + + vec_set_len (n, 0); + n = format (n, "bytes"); + s = + format (s, "\n%U%-16v%16Ld\n", format_white_space, + indent + 30, n, v.bytes); + } + vlib_cli_output (vm, "%s\n", s); + } + } + } } else { hicn_face_t *face; - /* *INDENT-OFF* */ - pool_foreach(face, hicn_dpoi_face_pool, - { - if (!((face->flags & HICN_FACE_FLAGS_DELETED) && !deleted)) - { - vlib_cli_output(vm, "%U\n", format_hicn_face, hicn_dpoi_get_index(face), 0); - u32 indent = 3; - u8 * s = 0; - - for (int i = 0; i < HICN_N_COUNTER; i++) - { - vlib_get_combined_counter (&counters[hicn_dpoi_get_index(face) * HICN_N_COUNTER], i, &v); - s = format (s, "%U%s",format_white_space, indent, HICN_FACE_CTRX_STRING[i]); - - if (n) - _vec_len (n) = 0; - n = format (n, "packets"); - s = format (s, "%U%-16v%16Ld", format_white_space, 30-strlen(HICN_FACE_CTRX_STRING[i]), n, v.packets); - - _vec_len (n) = 0; - n = format (n, "bytes"); - s = format (s, "\n%U%-16v%16Ld\n", - format_white_space, indent+30, n, v.bytes); - } - vlib_cli_output (vm, "%s\n", s); - } - }); - /* *INDENT-ON* */ + pool_foreach (face, hicn_dpoi_face_pool) + { + if (!((face->flags & HICN_FACE_FLAGS_DELETED) && !deleted)) + { + vlib_cli_output (vm, "%U\n", format_hicn_face, + hicn_dpoi_get_index (face), 0); + u32 indent = 3; + u8 *s = 0; + + for (int i = 0; i < HICN_N_COUNTER; i++) + { + vlib_get_combined_counter ( + &counters[hicn_dpoi_get_index (face) * HICN_N_COUNTER], + i, &v); + s = format (s, "%U%s", format_white_space, indent, + HICN_FACE_CTRX_STRING[i]); + + if (n) + vec_set_len (n, 0); + n = format (n, "packets"); + s = format (s, "%U%-16v%16Ld", format_white_space, + 30 - strlen (HICN_FACE_CTRX_STRING[i]), n, + v.packets); + + vec_set_len (n, 0); + n = format (n, "bytes"); + s = format (s, "\n%U%-16v%16Ld\n", format_white_space, + indent + 30, n, v.bytes); + } + vlib_cli_output (vm, "%s\n", s); + } + } } } @@ -176,14 +179,11 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, } /* cli declaration for 'show faces' */ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (hicn_face_cli_show_command, static) = -{ +VLIB_CLI_COMMAND (hicn_face_cli_show_command, static) = { .path = "hicn face show", .short_help = "hicn face show [<face_id>]", .function = hicn_face_cli_show_command_fn, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/face_flags.h b/hicn-plugin/src/faces/face_flags.h new file mode 100644 index 000000000..880d3b558 --- /dev/null +++ b/hicn-plugin/src/faces/face_flags.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __HICN_FACE_FLAGS_H__ +#define __HICN_FACE_FLAGS_H__ + +/* Flags */ +/* A face is complete and it stores all the information. A iface lacks of the + adj index, therefore sending a packet through a iface require a lookup in + the FIB. */ +#define foreach_face_flag \ + _ (0, FACE, "face") \ + _ (1, IFACE, "iface") \ + _ (2, APPFACE_PROD, "face is producer face") \ + _ (3, APPFACE_CONS, "face is consumer face") \ + _ (4, DELETED, "face is deleted") \ + _ (5, UDP4, "face is udp4") \ + _ (6, UDP6, "face is udp6") + +enum +{ + HICN_FACE_FLAGS_DEFAULT = 0, +#define _(a, b, c) HICN_FACE_FLAGS_##b = (1 << a), + foreach_face_flag +#undef _ +}; + +#endif /* __HICN_FACE_FLAGS_H__ */
\ No newline at end of file diff --git a/hicn-plugin/src/faces/face_node.c b/hicn-plugin/src/faces/face_node.c index 48d97ad51..2cfb9c7dc 100644 --- a/hicn-plugin/src/faces/face_node.c +++ b/hicn-plugin/src/faces/face_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -23,6 +23,10 @@ #include "../cache_policies/cs_lru.h" #include "../infra.h" #include "../hicn.h" +#include "../parser.h" + +#include <hicn/error.h> +#include <hicn/util/ip_address.h> /** * @File @@ -56,9 +60,9 @@ typedef struct u32 next_index; u32 sw_if_index; u8 pkt_type; + hicn_error_t error; u8 packet_data[60]; -} -hicn4_face_input_trace_t; +} hicn4_face_input_trace_t; typedef enum { @@ -74,9 +78,9 @@ typedef struct u32 next_index; u32 sw_if_index; u8 pkt_type; + hicn_error_t error; u8 packet_data[60]; -} -hicn6_face_input_trace_t; +} hicn6_face_input_trace_t; typedef enum { @@ -88,6 +92,7 @@ typedef enum #define NEXT_MAPME_IP4 HICN4_FACE_INPUT_NEXT_MAPME #define NEXT_MAPME_IP6 HICN6_FACE_INPUT_NEXT_MAPME + #define NEXT_DATA_IP4 HICN4_FACE_INPUT_NEXT_DATA #define NEXT_DATA_IP6 HICN6_FACE_INPUT_NEXT_DATA @@ -97,9 +102,6 @@ typedef enum #define IP_HEADER_4 ip4_header_t #define IP_HEADER_6 ip6_header_t -#define LOCK_DPO_FACE_IP4 hicn_face_ip4_lock -#define LOCK_DPO_FACE_IP6 hicn_face_ip6_lock - #define TRACE_INPUT_PKT_IP4 hicn4_face_input_trace_t #define TRACE_INPUT_PKT_IP6 hicn6_face_input_trace_t @@ -109,202 +111,287 @@ typedef enum * followind code is pretty straighforward and most of the complexity is in * functions that can be easily debug. */ -#define face_input_x1(ipv) \ - do{ \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = NEXT_ERROR_DROP_IP##ipv; \ - IP_HEADER_##ipv * ip_hdr = NULL; \ - hicn_buffer_t * hicnb0; \ - int ret; \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, 2*CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - hicnb0 = hicn_get_buffer(b0); \ - ip_hdr = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - \ - u8 is_icmp = ip_hdr->protocol == IPPROTO_ICMPV##ipv; \ - \ - next0 = is_icmp*NEXT_MAPME_IP##ipv + \ - (1-is_icmp)*NEXT_DATA_IP##ipv; \ - \ - ret = LOCK_DPO_FACE_IP##ipv \ - (&(hicnb0->face_id), \ - &(hicnb0->in_faces_vec_id), \ - &hicnb0->flags, \ - &(ip_hdr->dst_address)); \ - \ - if ( PREDICT_FALSE(ret != HICN_ERROR_NONE) ) \ - next0 = NEXT_ERROR_DROP_IP##ipv; \ - else \ - { \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_id \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_DATA_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - stats.pkts_data_count += 1; \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - }while(0) - - -#define face_input_x2(ipv) \ - do{ \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0 = NEXT_ERROR_DROP_IP##ipv; \ - u32 next1 = NEXT_ERROR_DROP_IP##ipv; \ - IP_HEADER_##ipv * ip_hdr0 = NULL; \ - IP_HEADER_##ipv * ip_hdr1 = NULL; \ - hicn_buffer_t * hicnb0; \ - hicn_buffer_t * hicnb1; \ - int ret0, ret1; \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, 2*CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, 2*CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - hicnb0 = hicn_get_buffer(b0); \ - hicnb1 = hicn_get_buffer(b1); \ - ip_hdr0 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - ip_hdr1 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b1); \ - \ - u8 is_icmp0 = ip_hdr0->protocol == IPPROTO_ICMPV##ipv; \ - u8 is_icmp1 = ip_hdr1->protocol == IPPROTO_ICMPV##ipv; \ - \ - next0 = is_icmp0*NEXT_MAPME_IP##ipv + \ - (1-is_icmp0)*NEXT_DATA_IP##ipv; \ - \ - next1 = is_icmp1*NEXT_MAPME_IP##ipv + \ - (1-is_icmp1)*NEXT_DATA_IP##ipv; \ - \ - \ - ret0 = LOCK_DPO_FACE_IP##ipv \ - (&(hicnb0->face_id), \ - &(hicnb0->in_faces_vec_id), \ - &hicnb0->flags, \ - &(ip_hdr0->dst_address)); \ - \ - ret1 = LOCK_DPO_FACE_IP##ipv \ - (&(hicnb1->face_id), \ - &(hicnb1->in_faces_vec_id), \ - &hicnb1->flags, \ - &(ip_hdr1->dst_address)); \ - \ - if ( PREDICT_FALSE(ret0 != HICN_ERROR_NONE) ) \ - next0 = NEXT_ERROR_DROP_IP##ipv; \ - else \ - { \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_id \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_DATA_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - stats.pkts_data_count += 1; \ - } \ - \ - if ( PREDICT_FALSE(ret1 != HICN_ERROR_NONE) ) \ - next1 = NEXT_ERROR_DROP_IP##ipv; \ - else \ - { \ - vlib_increment_combined_counter ( \ - &counters[hicnb1->face_id \ - * HICN_N_COUNTER], thread_index,\ - HICN_FACE_COUNTERS_DATA_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - stats.pkts_data_count += 1; \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - }while(0) - +#define face_input_x1(ipv) \ + do \ + { \ + vlib_buffer_t *b0; \ + u32 bi0, sw_if0; \ + u32 next0 = NEXT_ERROR_DROP_IP##ipv; \ + u8 is_mapme0; \ + IP_HEADER_##ipv *ip_hdr = NULL; \ + hicn_buffer_t *hicnb0; \ + int from_tunnel0; \ + int ret0 = HICN_ERROR_NONE; \ + /* Prefetch for next iteration. */ \ + if (n_left_from > 1) \ + { \ + vlib_buffer_t *b1; \ + b1 = vlib_get_buffer (vm, from[1]); \ + CLIB_PREFETCH (b1, 2 * CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES, LOAD); \ + } \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + from += 1; \ + n_left_from -= 1; \ + to_next[0] = bi0; \ + to_next += 1; \ + n_left_to_next -= 1; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + hicnb0 = hicn_get_buffer (b0); \ + ip_hdr = (IP_HEADER_##ipv *) vlib_buffer_get_current (b0); \ + \ + /* Parse packet and cache useful info in opaque2 */ \ + ret0 = hicn_data_parse_pkt (b0, vlib_buffer_length_in_chain (vm, b0)); \ + is_mapme0 = hicn_packet_get_type (&hicn_get_buffer (b0)->pkbuf) == \ + HICN_PACKET_TYPE_MAPME; \ + \ + ret0 = (ret0 == HICN_ERROR_NONE) || \ + (ret0 == HICN_ERROR_PARSER_MAPME_PACKET); \ + \ + /* If parsing is ok, send packet to next node */ \ + if (PREDICT_FALSE (!ret0)) \ + { \ + next0 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + else \ + { \ + next0 = is_mapme0 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme0) * NEXT_DATA_IP##ipv; \ + from_tunnel0 = \ + (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL || \ + hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) > 0; \ + sw_if0 = \ + (from_tunnel0) * ~0 + \ + (1 - from_tunnel0) * vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + ret0 = hicn_face_ip##ipv##_find ( \ + &hicnb0->face_id, &hicnb0->flags, &ip_hdr->dst_address, sw_if0, \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX], \ + /* Should not be used */ ~0); \ + /* Make sure the face is not created here */ \ + if (PREDICT_FALSE (ret0 == HICN_ERROR_FACE_NOT_FOUND)) \ + { \ + next0 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + } \ + \ + vlib_increment_combined_counter ( \ + &counters[hicnb0->face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_DATA_RX, 1, vlib_buffer_length_in_chain (vm, b0)); \ + stats.pkts_data_count += 1; \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_INPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + t->error = ret0; \ + t->next_index = next0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, next0); \ + } \ + while (0) + +#define face_input_x2(ipv) \ + do \ + { \ + vlib_buffer_t *b0, *b1; \ + u32 bi0, bi1, sw_if0, sw_if1; \ + u32 next0 = NEXT_ERROR_DROP_IP##ipv; \ + u32 next1 = NEXT_ERROR_DROP_IP##ipv; \ + u8 is_mapme0, is_mapme1; \ + IP_HEADER_##ipv *ip_hdr0 = NULL; \ + IP_HEADER_##ipv *ip_hdr1 = NULL; \ + hicn_buffer_t *hicnb0; \ + hicn_buffer_t *hicnb1; \ + int from_tunnel0, from_tunnel1; \ + int ret0, ret1; \ + /* Prefetch for next iteration. */ \ + { \ + vlib_buffer_t *b2, *b3; \ + b2 = vlib_get_buffer (vm, from[2]); \ + b3 = vlib_get_buffer (vm, from[3]); \ + CLIB_PREFETCH (b2, 2 * CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b3, 2 * CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES, LOAD); \ + CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES, LOAD); \ + } \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + bi1 = from[1]; \ + from += 2; \ + n_left_from -= 2; \ + to_next[0] = bi0; \ + to_next[1] = bi1; \ + to_next += 2; \ + n_left_to_next -= 2; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + b1 = vlib_get_buffer (vm, bi1); \ + hicnb0 = hicn_get_buffer (b0); \ + hicnb1 = hicn_get_buffer (b1); \ + ip_hdr0 = (IP_HEADER_##ipv *) vlib_buffer_get_current (b0); \ + ip_hdr1 = (IP_HEADER_##ipv *) vlib_buffer_get_current (b1); \ + \ + /* Parse packet and cache useful info in opaque2 */ \ + ret0 = hicn_data_parse_pkt (b0, vlib_buffer_length_in_chain (vm, b0)); \ + ret1 = hicn_data_parse_pkt (b1, vlib_buffer_length_in_chain (vm, b1)); \ + is_mapme0 = hicn_packet_get_type (&hicn_get_buffer (b0)->pkbuf) == \ + HICN_PACKET_TYPE_MAPME; \ + is_mapme1 = hicn_packet_get_type (&hicn_get_buffer (b1)->pkbuf) == \ + HICN_PACKET_TYPE_MAPME; \ + ret0 = (ret0 == HICN_ERROR_NONE) || \ + (ret0 == HICN_ERROR_PARSER_MAPME_PACKET); \ + ret1 = (ret1 == HICN_ERROR_NONE) || \ + (ret1 == HICN_ERROR_PARSER_MAPME_PACKET); \ + if (PREDICT_TRUE (ret0 && ret1)) \ + { \ + next0 = is_mapme0 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme0) * NEXT_DATA_IP##ipv; \ + \ + next1 = is_mapme1 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme1) * NEXT_DATA_IP##ipv; \ + \ + from_tunnel0 = \ + (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL || \ + hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) > 0; \ + sw_if0 = \ + (from_tunnel0) * ~0 + \ + (1 - from_tunnel0) * vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + ret0 = hicn_face_ip##ipv##_find ( \ + &hicnb0->face_id, &hicnb0->flags, &ip_hdr0->dst_address, sw_if0, \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX], \ + /* Should not be used */ ~0); \ + /* Make sure the face is not created here */ \ + if (PREDICT_FALSE (ret0 == HICN_ERROR_FACE_NOT_FOUND)) \ + { \ + next0 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + \ + from_tunnel1 = \ + (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL || \ + hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) > 0; \ + sw_if1 = \ + (from_tunnel1) * ~0 + \ + (1 - from_tunnel1) * vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + ret1 = hicn_face_ip##ipv##_find ( \ + &hicnb1->face_id, &hicnb1->flags, &ip_hdr1->dst_address, sw_if1, \ + vnet_buffer (b1)->ip.adj_index[VLIB_RX], \ + /* Should not be used */ ~0); \ + /* Make sure the face is not created here */ \ + if (PREDICT_FALSE (ret1 == HICN_ERROR_FACE_NOT_FOUND)) \ + { \ + next1 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + } \ + else if (ret0 && !ret1) \ + { \ + next1 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + from_tunnel0 = \ + (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL || \ + hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) > 0; \ + sw_if0 = \ + (from_tunnel0) * ~0 + \ + (1 - from_tunnel0) * vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + ret0 = hicn_face_ip##ipv##_find ( \ + &hicnb0->face_id, &hicnb0->flags, &ip_hdr0->dst_address, sw_if0, \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX], \ + /* Should not be used */ ~0); \ + /* Make sure the face is not created here */ \ + if (PREDICT_FALSE (ret0 == HICN_ERROR_FACE_NOT_FOUND)) \ + { \ + next0 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + else \ + { \ + next0 = is_mapme0 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme0) * NEXT_DATA_IP##ipv; \ + } \ + } \ + else if (!ret0 && ret1) \ + { \ + next0 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + from_tunnel1 = \ + (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL || \ + hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) > 0; \ + sw_if1 = \ + (from_tunnel1) * ~0 + \ + (1 - from_tunnel1) * vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + ret1 = hicn_face_ip##ipv##_find ( \ + &hicnb1->face_id, &hicnb1->flags, &ip_hdr1->dst_address, sw_if1, \ + vnet_buffer (b1)->ip.adj_index[VLIB_RX], \ + /* Should not be used */ ~0); \ + /* Make sure the face is not created here */ \ + if (PREDICT_FALSE (ret1 == HICN_ERROR_FACE_NOT_FOUND)) \ + { \ + next1 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + else \ + { \ + next1 = is_mapme1 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme1) * NEXT_DATA_IP##ipv; \ + } \ + } \ + else \ + { \ + next0 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + next1 = HICN##ipv##_FACE_INPUT_NEXT_ERROR_DROP; \ + } \ + \ + vlib_increment_combined_counter ( \ + &counters[hicnb0->face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_DATA_RX, 1, vlib_buffer_length_in_chain (vm, b0)); \ + stats.pkts_data_count += 1; \ + \ + vlib_increment_combined_counter ( \ + &counters[hicnb1->face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_DATA_RX, 1, vlib_buffer_length_in_chain (vm, b1)); \ + stats.pkts_data_count += 1; \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_INPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + t->error = ret0; \ + t->next_index = next0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b1->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_INPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b1, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + t->error = ret1; \ + t->next_index = next1; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b1), \ + sizeof (t->packet_data)); \ + } \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, bi1, next0, \ + next1); \ + } \ + while (0) static uword -hicn4_face_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn4_face_input_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; @@ -333,20 +420,19 @@ hicn4_face_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_DATAS, + stats.pkts_data_count); return (frame->n_vectors); } /* packet trace format function */ static u8 * -hicn4_face_input_format_trace (u8 * s, va_list * args) +hicn4_face_input_format_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 *); - hicn4_face_input_trace_t *t = - va_arg (*args, hicn4_face_input_trace_t *); + hicn4_face_input_trace_t *t = va_arg (*args, hicn4_face_input_trace_t *); s = format (s, "FACE_IP4_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", (int) t->pkt_type, t->sw_if_index, t->next_index, @@ -354,11 +440,9 @@ hicn4_face_input_format_trace (u8 * s, va_list * args) return (s); } - /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE(hicn4_face_input_node) = { .function = hicn4_face_input_node_fn, @@ -377,15 +461,14 @@ VLIB_REGISTER_NODE(hicn4_face_input_node) = [HICN4_FACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ /** * @brief IPv6 face input node function * @see hicn6_face_input_node_fn */ static uword -hicn6_face_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn6_face_input_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; @@ -414,20 +497,19 @@ hicn6_face_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_DATAS, + stats.pkts_data_count); return (frame->n_vectors); } /* packet trace format function */ static u8 * -hicn6_face_input_format_trace (u8 * s, va_list * args) +hicn6_face_input_format_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 *); - hicn6_face_input_trace_t *t = - va_arg (*args, hicn6_face_input_trace_t *); + hicn6_face_input_trace_t *t = va_arg (*args, hicn6_face_input_trace_t *); s = format (s, "FACE_IP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", (int) t->pkt_type, t->sw_if_index, t->next_index, @@ -438,7 +520,6 @@ hicn6_face_input_format_trace (u8 * s, va_list * args) /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE(hicn6_face_input_node) = { .function = hicn6_face_input_node_fn, @@ -457,12 +538,12 @@ VLIB_REGISTER_NODE(hicn6_face_input_node) = [HICN6_FACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ /**** FACE OUTPUT *****/ typedef enum { + HICN4_FACE_OUTPUT_NEXT_ERROR_DROP, HICN4_FACE_OUTPUT_NEXT_ECHO_REPLY, HICN4_FACE_OUTPUT_NEXT_UDP4_ENCAP, HICN4_FACE_OUTPUT_NEXT_UDP6_ENCAP, @@ -471,109 +552,39 @@ typedef enum typedef enum { + HICN6_FACE_OUTPUT_NEXT_ERROR_DROP, HICN6_FACE_OUTPUT_NEXT_ECHO_REPLY, HICN6_FACE_OUTPUT_NEXT_UDP4_ENCAP, HICN6_FACE_OUTPUT_NEXT_UDP6_ENCAP, HICN6_FACE_OUTPUT_N_NEXT, } hicn6_face_output_next_t; -/* static_always_inline void */ -/* hicn_reply_probe_v4 (vlib_buffer_t * b, hicn_face_t * face) */ -/* { */ -/* hicn_header_t *h0 = vlib_buffer_get_current (b); */ -/* hicn_face_ip_t * face_ip = (hicn_face_ip_t *)(&face->data); */ -/* h0->v4.ip.saddr = h0->v4.ip.daddr; */ -/* h0->v4.ip.daddr = face_ip->local_addr.ip4; */ -/* vnet_buffer (b)->sw_if_index[VLIB_RX] = face->shared.sw_if; */ - -/* u16 * dst_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip4_header_t) + sizeof(u16)); */ -/* u16 dst_port = *dst_port_ptr; */ -/* u16 * src_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip4_header_t)); */ - -/* *dst_port_ptr = *src_port_ptr; */ -/* *src_port_ptr = dst_port; */ - -/* hicn_type_t type = hicn_get_buffer (b)->type; */ -/* hicn_ops_vft[type.l1]->set_lifetime (type, &h0->protocol, 0); */ -/* } */ - -/* static_always_inline void */ -/* hicn_reply_probe_v6 (vlib_buffer_t * b, hicn_face_t * face) */ -/* { */ -/* hicn_header_t *h0 = vlib_buffer_get_current (b); */ -/* hicn_face_ip_t * face_ip = (hicn_face_ip_t *)(&face->data); */ -/* h0->v6.ip.saddr = h0->v6.ip.daddr; */ -/* h0->v6.ip.daddr = face_ip->local_addr.ip6; */ -/* vnet_buffer (b)->sw_if_index[VLIB_RX] = face->shared.sw_if; */ - -/* u16 * dst_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip6_header_t) + sizeof(u16)); */ -/* u16 dst_port = *dst_port_ptr; */ -/* u16 * src_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip6_header_t)); */ - -/* *dst_port_ptr = *src_port_ptr; */ -/* *src_port_ptr = dst_port; */ - -/* hicn_type_t type = hicn_get_buffer (b)->type; */ -/* hicn_ops_vft[type.l1]->set_lifetime (type, &h0->protocol, 0); */ - -/* } */ - -/* static_always_inline u32 */ -/* hicn_face_match_probe (vlib_buffer_t * b, hicn_face_t * face, u32 * next) */ -/* { */ - -/* u8 *ptr = vlib_buffer_get_current (b); */ -/* u8 v = *ptr & 0xf0; */ -/* u8 res = 0; */ - -/* if ( v == 0x40 ) */ -/* { */ -/* u16 * dst_port = (u16 *)(ptr + sizeof(ip4_header_t) + sizeof(u16)); */ -/* if (*dst_port == clib_net_to_host_u16(DEFAULT_PROBING_PORT)) */ -/* { */ -/* hicn_reply_probe_v6(b, face); */ -/* *next = HICN4_FACE_NEXT_ECHO_REPLY; */ -/* res = 1; */ -/* } */ -/* } */ -/* else if ( v == 0x60 ) */ -/* { */ -/* u16 * dst_port = (u16 *)(ptr + sizeof(ip6_header_t) + sizeof(u16)); */ -/* if (*dst_port == clib_net_to_host_u16(DEFAULT_PROBING_PORT)) */ -/* { */ -/* hicn_reply_probe_v6(b, face); */ -/* *next = HICN6_FACE_NEXT_ECHO_REPLY; */ -/* res = 1; */ -/* } */ -/* } */ -/* return res; */ -/* } */ - - static inline void -hicn_face_rewrite_interest (vlib_main_t * vm, vlib_buffer_t * b0, - hicn_face_t * face, u32 * next) +hicn_face_rewrite_interest (vlib_main_t *vm, vlib_buffer_t *b0, + hicn_face_t *face, u32 *next) { - /* if ((face->flags & HICN_FACE_FLAGS_APPFACE_PROD) && hicn_face_match_probe(b0, face, next)) */ + /* if ((face->flags & HICN_FACE_FLAGS_APPFACE_PROD) && + * hicn_face_match_probe(b0, face, next)) */ /* return; */ - hicn_header_t *hicn = vlib_buffer_get_current (b0); + hicn_packet_buffer_t *pkbuf = &hicn_get_buffer (b0)->pkbuf; - //hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; + u8 is_v4 = ip46_address_is_ip4 (&face->nat_addr) && + !ip6_address_is_loopback (&face->nat_addr.ip6); - ip46_address_t temp_addr; - ip46_address_reset (&temp_addr); - hicn_type_t type = hicn_get_buffer (b0)->type; - int ret = hicn_ops_vft[type.l1]->rewrite_interest (type, &hicn->protocol, - &face->nat_addr, &temp_addr); + // hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; + hicn_ip_address_t temp_addr; + ip46_address_reset (&(temp_addr.as_ip46)); + hicn_ip_address_t *face_nat_addr = (hicn_ip_address_t *) &face->nat_addr; + int ret = hicn_interest_rewrite (pkbuf, face_nat_addr, &temp_addr); if (ret == HICN_LIB_ERROR_REWRITE_CKSUM_REQUIRED) { - ensure_offload_flags(b0, ip46_address_is_ip4(&face->nat_addr)); + ensure_offload_flags (b0, is_v4); } - ASSERT(face->flags & HICN_FACE_FLAGS_FACE); + ASSERT (face->flags & HICN_FACE_FLAGS_FACE); vnet_buffer (b0)->ip.adj_index[VLIB_TX] = face->dpo.dpoi_index; *next = face->dpo.dpoi_next_node; @@ -591,193 +602,184 @@ static char *hicn6_face_output_error_strings[] = { #undef _ }; - /* Trace context struct */ typedef struct { u32 next_index; + u32 next_node; u32 sw_if_index; u8 pkt_type; u8 packet_data[60]; -} -hicn4_face_output_trace_t; +} hicn4_face_output_trace_t; /* Trace context struct */ typedef struct { u32 next_index; + u32 next_node; u32 sw_if_index; u8 pkt_type; u8 packet_data[60]; -} -hicn6_face_output_trace_t; +} hicn6_face_output_trace_t; #define TRACE_OUTPUT_PKT_IP4 hicn4_face_output_trace_t #define TRACE_OUTPUT_PKT_IP6 hicn6_face_output_trace_t -#define face_output_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = ~0; \ - hicn_face_t * face; \ - \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , STORE); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - \ - hicn_face_id_t face_id = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - face = \ - hicn_dpoi_get_from_idx (face_id); \ - \ - if (PREDICT_TRUE(face != NULL)) \ - { \ - hicn_face_rewrite_interest \ - (vm, b0, face, &next0); \ - stats.pkts_interest_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_INTEREST_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - }while(0) - -#define face_output_x2(ipv) \ - do { \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0 = ~0; \ - u32 next1 = ~0; \ - hicn_face_t *face0, *face1; \ - \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , STORE); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , STORE); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - \ - hicn_face_id_t face_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - hicn_face_id_t face_id1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ - face0 = \ - hicn_dpoi_get_from_idx (face_id0); \ - face1 = \ - hicn_dpoi_get_from_idx (face_id1); \ - \ - if (PREDICT_TRUE(face0 != NULL)) \ - { \ - hicn_face_rewrite_interest \ - (vm, b0, face0, &next0); \ - stats.pkts_interest_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id0 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_INTEREST_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if (PREDICT_TRUE(face1 != NULL)) \ - { \ - hicn_face_rewrite_interest \ - (vm, b1, face1, &next1); \ - stats.pkts_interest_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id1 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_INTEREST_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - }while(0) - +#define face_output_x1(ipv) \ + do \ + { \ + vlib_buffer_t *b0; \ + u32 bi0; \ + u32 next0 = HICN##ipv##_FACE_OUTPUT_NEXT_ERROR_DROP; \ + hicn_face_t *face = NULL; \ + \ + /* Prefetch for next iteration. */ \ + if (n_left_from > 1) \ + { \ + vlib_buffer_t *b1; \ + b1 = vlib_get_buffer (vm, from[1]); \ + CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES, STORE); \ + } \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + from += 1; \ + n_left_from -= 1; \ + to_next[0] = bi0; \ + to_next += 1; \ + n_left_to_next -= 1; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + \ + hicn_face_id_t face_id = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ + if (PREDICT_TRUE (hicn_dpoi_idx_is_valid (face_id))) \ + face = hicn_dpoi_get_from_idx (face_id); \ + \ + if (PREDICT_TRUE (face != NULL) && face->flags & HICN_FACE_FLAGS_FACE) \ + { \ + hicn_face_rewrite_interest (vm, b0, face, &next0); \ + stats.pkts_interest_count += 1; \ + vlib_increment_combined_counter ( \ + &counters[face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_TX, 1, \ + vlib_buffer_length_in_chain (vm, b0)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_OUTPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + t->next_index = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ + t->next_node = next0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, next0); \ + } \ + while (0) + +#define face_output_x2(ipv) \ + do \ + { \ + vlib_buffer_t *b0, *b1; \ + u32 bi0, bi1; \ + u32 next0 = HICN##ipv##_FACE_OUTPUT_NEXT_ERROR_DROP; \ + u32 next1 = HICN##ipv##_FACE_OUTPUT_NEXT_ERROR_DROP; \ + hicn_face_t *face0 = NULL, *face1 = NULL; \ + \ + /* Prefetch for next iteration. */ \ + { \ + vlib_buffer_t *b2, *b3; \ + b2 = vlib_get_buffer (vm, from[2]); \ + b3 = vlib_get_buffer (vm, from[3]); \ + CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES, STORE); \ + } \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + bi1 = from[1]; \ + from += 2; \ + n_left_from -= 2; \ + to_next[0] = bi0; \ + to_next[1] = bi1; \ + to_next += 2; \ + n_left_to_next -= 2; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + b1 = vlib_get_buffer (vm, bi1); \ + \ + hicn_face_id_t face_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ + hicn_face_id_t face_id1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ + if (PREDICT_TRUE (hicn_dpoi_idx_is_valid (face_id0))) \ + face0 = hicn_dpoi_get_from_idx (face_id0); \ + if (PREDICT_TRUE (hicn_dpoi_idx_is_valid (face_id1))) \ + face1 = hicn_dpoi_get_from_idx (face_id1); \ + \ + if (PREDICT_TRUE (face0 != NULL) && \ + face0->flags & HICN_FACE_FLAGS_FACE) \ + { \ + hicn_face_rewrite_interest (vm, b0, face0, &next0); \ + stats.pkts_interest_count += 1; \ + vlib_increment_combined_counter ( \ + &counters[face_id0 * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_TX, 1, \ + vlib_buffer_length_in_chain (vm, b0)); \ + } \ + \ + if (PREDICT_TRUE (face1 != NULL) && \ + face1->flags & HICN_FACE_FLAGS_FACE) \ + { \ + hicn_face_rewrite_interest (vm, b1, face1, &next1); \ + stats.pkts_interest_count += 1; \ + vlib_increment_combined_counter ( \ + &counters[face_id1 * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_TX, 1, \ + vlib_buffer_length_in_chain (vm, b1)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_OUTPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + t->next_index = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ + t->next_node = next0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b1->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_OUTPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b1, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + t->next_index = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ + t->next_node = next1; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b1), \ + sizeof (t->packet_data)); \ + } \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, bi1, next0, \ + next1); \ + } \ + while (0) static uword -hicn4_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn4_face_output_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; @@ -806,8 +808,7 @@ hicn4_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_INTERESTS, stats.pkts_interest_count); return (frame->n_vectors); @@ -815,48 +816,37 @@ hicn4_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* packet trace format function */ static u8 * -hicn4_face_output_format_trace (u8 * s, va_list * args) +hicn4_face_output_format_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 *); - hicn4_face_output_trace_t *t = - va_arg (*args, hicn4_face_output_trace_t *); + hicn4_face_output_trace_t *t = va_arg (*args, hicn4_face_output_trace_t *); - s = - format (s, "FACE_IP4_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - format_ip4_header, t->packet_data, sizeof (t->packet_data)); + s = format (s, + "FACE_IP4_OUTPUT: pkt: %d, sw_if_index %d, next index %d, next " + "node: %d\n%U", + (int) t->pkt_type, t->sw_if_index, t->next_index, t->next_node, + format_ip4_header, t->packet_data, sizeof (t->packet_data)); return (s); } /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn4_face_output_node) = -{ +VLIB_REGISTER_NODE (hicn4_face_output_node) = { .function = hicn4_face_output_node_fn, .name = "hicn4-face-output", - .vector_size = sizeof(u32), + .vector_size = sizeof (u32), .format_trace = hicn4_face_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn4_face_output_error_strings), + .n_errors = ARRAY_LEN (hicn4_face_output_error_strings), .error_strings = hicn4_face_output_error_strings, - .n_next_nodes = HICN4_FACE_OUTPUT_N_NEXT, - /* Reusing the list of nodes from lookup to be compatible with arp */ - .next_nodes = - { - [HICN4_FACE_OUTPUT_NEXT_ECHO_REPLY] = "hicn4-face-input", - [HICN4_FACE_OUTPUT_NEXT_UDP4_ENCAP] = "udp4-encap", - [HICN4_FACE_OUTPUT_NEXT_UDP6_ENCAP] = "udp6-encap" - } + .sibling_of = "ip4-lookup", }; -/* *INDENT-ON* */ - static uword -hicn6_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn6_face_output_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; @@ -885,8 +875,7 @@ hicn6_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_INTERESTS, stats.pkts_interest_count); return (frame->n_vectors); @@ -894,43 +883,33 @@ hicn6_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* packet trace format function */ static u8 * -hicn6_face_output_format_trace (u8 * s, va_list * args) +hicn6_face_output_format_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 *); - hicn6_face_output_trace_t *t = - va_arg (*args, hicn6_face_output_trace_t *); + hicn6_face_output_trace_t *t = va_arg (*args, hicn6_face_output_trace_t *); - s = - format (s, "FACE_IP6_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - format_ip6_header, t->packet_data, sizeof (t->packet_data)); + s = format (s, + "FACE_IP6_OUTPUT: pkt: %d, sw_if_index %d, next index %d, next " + "node: %d\n%U", + (int) t->pkt_type, t->sw_if_index, t->next_index, t->next_node, + format_ip6_header, t->packet_data, sizeof (t->packet_data)); return (s); } /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn6_face_output_node) = -{ +VLIB_REGISTER_NODE (hicn6_face_output_node) = { .function = hicn6_face_output_node_fn, .name = "hicn6-face-output", - .vector_size = sizeof(u32), + .vector_size = sizeof (u32), .format_trace = hicn6_face_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn6_face_output_error_strings), + .n_errors = ARRAY_LEN (hicn6_face_output_error_strings), .error_strings = hicn6_face_output_error_strings, - .n_next_nodes = HICN6_FACE_OUTPUT_N_NEXT, - /* Reusing the list of nodes from lookup to be compatible with neighbour discovery */ - .next_nodes = - { - [HICN6_FACE_OUTPUT_NEXT_ECHO_REPLY] = "hicn6-face-input", - [HICN6_FACE_OUTPUT_NEXT_UDP4_ENCAP] = "udp4-encap", - [HICN6_FACE_OUTPUT_NEXT_UDP6_ENCAP] = "udp6-encap" - } + .sibling_of = "ip6-lookup", }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/face_node.h b/hicn-plugin/src/faces/face_node.h index f5a8bf5ae..70daa1393 100644 --- a/hicn-plugin/src/faces/face_node.h +++ b/hicn-plugin/src/faces/face_node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Cisco and/or its affiliates. + * Copyright (c) 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: @@ -31,9 +31,9 @@ * The following node to the input face nodes is the hicn-data-pcslookup. * Output face nodes follow the strategy and the hicn-interest-hitpit nodes and * they perform the src nat on each interest packet. The node following the - * output face nodes depends on the adjacency type. In case of ip, the following - * node is the ip-rewrite, in case of tunnels the next node is the one implementing - * the tunnel encapsulation (udp-encap, mpls, etc). + * output face nodes depends on the adjacency type. In case of ip, the + * following node is the ip-rewrite, in case of tunnels the next node is the + * one implementing the tunnel encapsulation (udp-encap, mpls, etc). */ extern vlib_node_registration_t hicn4_face_input_node; diff --git a/hicn-plugin/src/faces/iface_node.c b/hicn-plugin/src/faces/iface_node.c index a4fd1885c..8b74c6c25 100644 --- a/hicn-plugin/src/faces/iface_node.c +++ b/hicn-plugin/src/faces/iface_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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,6 +19,11 @@ #include "../hicn.h" #include "../infra.h" #include "../cache_policies/cs_lru.h" +#include "../parser.h" +#include "iface_node.h" + +#include <hicn/error.h> +#include <hicn/util/ip_address.h> /** * @File @@ -52,12 +57,14 @@ typedef struct u32 next_index; u32 sw_if_index; u8 pkt_type; + hicn_error_t error; u8 packet_data[60]; } hicn4_iface_input_trace_t; typedef enum { HICN4_IFACE_INPUT_NEXT_INTEREST, + HICN4_IFACE_INPUT_NEXT_INTEREST_MANIFEST, HICN4_IFACE_INPUT_NEXT_MAPME, HICN4_IFACE_INPUT_NEXT_ERROR_DROP, HICN4_IFACE_INPUT_N_NEXT, @@ -69,12 +76,14 @@ typedef struct u32 next_index; u32 sw_if_index; u8 pkt_type; + hicn_error_t error; u8 packet_data[60]; } hicn6_iface_input_trace_t; typedef enum { HICN6_IFACE_INPUT_NEXT_INTEREST, + HICN6_IFACE_INPUT_NEXT_INTEREST_MANIFEST, HICN6_IFACE_INPUT_NEXT_MAPME, HICN6_IFACE_INPUT_NEXT_ERROR_DROP, HICN6_IFACE_INPUT_N_NEXT, @@ -86,21 +95,8 @@ typedef enum #define NEXT_INTEREST_IP4 HICN4_IFACE_INPUT_NEXT_INTEREST #define NEXT_INTEREST_IP6 HICN6_IFACE_INPUT_NEXT_INTEREST -#define ADDRESS_IP4 ip_interface_address_t *ia = 0;ip4_address_t *local_address = ip4_interface_first_address(&ip4_main, swif, &ia) -#define ADDRESS_IP6 ip6_address_t *local_address = ip6_interface_first_address(&ip6_main, swif) - -#define ADDRESSX2_IP4 ip_interface_address_t *ia0, *ia1; ia0 = ia1 = 0; \ - ip4_address_t *local_address0 = ip4_interface_first_address(&ip4_main, swif0, &ia0); \ - ip4_address_t *local_address1 = ip4_interface_first_address(&ip4_main, swif1, &ia1); - -#define ADDRESSX2_IP6 ip6_address_t *local_address0 = ip6_interface_first_address(&ip6_main, swif0); \ - ip6_address_t *local_address1 = ip6_interface_first_address(&ip6_main, swif1); - -#define DPO_ADD_LOCK_IFACE_IP4 hicn_iface_ip4_add_and_lock -#define DPO_ADD_LOCK_IFACE_IP6 hicn_iface_ip6_add_and_lock - -//#define VLIB_EDGE_IP4 data_fwd_iface_ip4_vlib_edge -//#define VLIB_EDGE_IP6 data_fwd_iface_ip6_vlib_edge +#define DPO_ADD_LOCK_FACE_IP4 hicn_face_ip4_add_and_lock +#define DPO_ADD_LOCK_FACE_IP6 hicn_face_ip6_add_and_lock #define IP_HEADER_4 ip4_header_t #define IP_HEADER_6 ip6_header_t @@ -122,7 +118,6 @@ static char *hicn6_iface_output_error_strings[] = { #undef _ }; - /* Trace context struct */ typedef struct { @@ -132,14 +127,6 @@ typedef struct u8 packet_data[60]; } hicn4_iface_output_trace_t; -typedef enum -{ - HICN4_IFACE_OUTPUT_NEXT_LOOKUP, - HICN4_IFACE_OUTPUT_NEXT_UDP4_ENCAP, - HICN4_IFACE_OUTPUT_NEXT_UDP6_ENCAP, - HICN4_IFACE_OUTPUT_N_NEXT, -} hicn4_iface_output_next_t; - /* Trace context struct */ typedef struct { @@ -149,14 +136,6 @@ typedef struct u8 packet_data[60]; } hicn6_iface_output_trace_t; -typedef enum -{ - HICN6_IFACE_OUTPUT_NEXT_LOOKUP, - HICN6_IFACE_OUTPUT_NEXT_UDP4_ENCAP, - HICN6_IFACE_OUTPUT_NEXT_UDP6_ENCAP, - HICN6_IFACE_OUTPUT_N_NEXT, -} hicn6_iface_output_next_t; - //#define ERROR_OUTPUT_IP4 HICN4_IFACE_OUTPUT_NEXT_ERROR_DROP //#define ERROR_OUTPUT_IP6 HICN6_IFACE_OUTPUT_NEXT_ERROR_DROP @@ -166,6 +145,9 @@ typedef enum #define NEXT_UDP_ENCAP_IP4 HICN4_IFACE_OUTPUT_NEXT_UDP4_ENCAP #define NEXT_UDP_ENCAP_IP6 HICN6_IFACE_OUTPUT_NEXT_UDP6_ENCAP +#define NEXT_PG4 HICN4_IFACE_OUTPUT_NEXT_PG +#define NEXT_PG6 HICN6_IFACE_OUTPUT_NEXT_PG + #define HICN_REWRITE_DATA_IP4 hicn_rewrite_iface_data4 #define HICN_REWRITE_DATA_IP6 hicn_rewrite_iface_data6 @@ -174,207 +156,328 @@ typedef enum // NODES IMPLEMENTATIONS -#define iface_input_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0, next0, next_iface0; \ - IP_HEADER_##ipv * ip_hdr = NULL; \ - hicn_buffer_t * hicnb0; \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, 2*CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - hicnb0 = hicn_get_buffer(b0); \ - ip_hdr = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - \ - stats.pkts_interest_count += 1; \ - \ - u8 is_icmp = ip_hdr->protocol == IPPROTO_ICMPV##ipv; \ - \ - next0 = is_icmp*NEXT_MAPME_IP##ipv + \ - (1-is_icmp)*NEXT_INTEREST_IP##ipv; \ - \ - next_iface0 = NEXT_DATA_LOOKUP_IP##ipv; \ - \ - if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL) \ - next_iface0 = NEXT_UDP_ENCAP_IP4; \ - else if(hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) \ - next_iface0 = NEXT_UDP_ENCAP_IP6; \ - \ - DPO_ADD_LOCK_IFACE_IP##ipv \ - (&(hicnb0->face_id), \ - &hicnb0->flags, \ - &(ip_hdr->src_address), \ - vnet_buffer(b0)->sw_if_index[VLIB_RX], \ - vnet_buffer(b0)->ip.adj_index[VLIB_RX], \ - next_iface0); \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - \ - } \ - \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_id \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - }while(0) - - -#define iface_input_x2(ipv) \ - do { \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1, next0, next1, next_iface0, next_iface1; \ - IP_HEADER_##ipv * ip_hdr0 = NULL; \ - IP_HEADER_##ipv * ip_hdr1 = NULL; \ - hicn_buffer_t *hicnb0, *hicnb1; \ - \ - /* Prefetch for next iteration. */ \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, 2*CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, 2*CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - hicnb0 = hicn_get_buffer(b0); \ - hicnb1 = hicn_get_buffer(b1); \ - ip_hdr0 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - ip_hdr1 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b1); \ - \ - stats.pkts_interest_count += 2; \ - \ - u8 is_icmp0 = ip_hdr0->protocol == IPPROTO_ICMPV##ipv; \ - u8 is_icmp1 = ip_hdr1->protocol == IPPROTO_ICMPV##ipv; \ - \ - next0 = is_icmp0*NEXT_MAPME_IP##ipv + \ - (1-is_icmp0)*NEXT_INTEREST_IP##ipv; \ - \ - next1 = is_icmp1*NEXT_MAPME_IP##ipv + \ - (1-is_icmp1)*NEXT_INTEREST_IP##ipv; \ - \ - next_iface0 = NEXT_DATA_LOOKUP_IP##ipv; \ - \ - if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL) \ - next_iface0 = NEXT_UDP_ENCAP_IP4; \ - else if(hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) \ - next_iface0 = NEXT_UDP_ENCAP_IP6; \ - \ - next_iface1 = NEXT_DATA_LOOKUP_IP##ipv; \ - \ - if (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL) \ - next_iface1 = NEXT_UDP_ENCAP_IP4; \ - else if(hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL) \ - next_iface1 = NEXT_UDP_ENCAP_IP6; \ - \ - DPO_ADD_LOCK_IFACE_IP##ipv \ - (&(hicnb0->face_id), \ - &hicnb0->flags, \ - &(ip_hdr0->src_address), \ - vnet_buffer(b0)->sw_if_index[VLIB_RX], \ - vnet_buffer(b0)->ip.adj_index[VLIB_RX], \ - next_iface0); \ - \ - DPO_ADD_LOCK_IFACE_IP##ipv \ - (&(hicnb1->face_id), \ - &hicnb1->flags, \ - &(ip_hdr1->src_address), \ - vnet_buffer(b1)->sw_if_index[VLIB_RX], \ - vnet_buffer(b1)->ip.adj_index[VLIB_RX], \ - next_iface1); \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1), \ - sizeof (t->packet_data)); \ - } \ - \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_id \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - \ - vlib_increment_combined_counter ( \ - &counters[hicnb1->face_id \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - }while(0) +#define iface_input_x1(ipv) \ + do \ + { \ + vlib_buffer_t *b0; \ + u32 bi0, next0, next_iface0, sw_if0 = ~0; \ + IP_HEADER_##ipv *ip_hdr = NULL; \ + hicn_buffer_t *hicnb0; \ + int ret0 = HICN_ERROR_NONE; \ + u8 is_mapme0, is_manifest0; \ + /* Prefetch for next iteration. */ \ + if (n_left_from > 1) \ + { \ + vlib_buffer_t *b1; \ + b1 = vlib_get_buffer (vm, from[1]); \ + CLIB_PREFETCH (b1, 2 * CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES, LOAD); \ + } \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + from += 1; \ + n_left_from -= 1; \ + to_next[0] = bi0; \ + to_next += 1; \ + n_left_to_next -= 1; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + hicnb0 = hicn_get_buffer (b0); \ + ip_hdr = (IP_HEADER_##ipv *) vlib_buffer_get_current (b0); \ + \ + /* Parse packet and cache useful info in opaque2 */ \ + ret0 = \ + hicn_interest_parse_pkt (b0, vlib_buffer_length_in_chain (vm, b0)); \ + is_mapme0 = hicn_packet_get_type (&hicn_get_buffer (b0)->pkbuf) == \ + HICN_PACKET_TYPE_MAPME; \ + is_manifest0 = hicnb0->payload_type == HPT_MANIFEST; \ + ret0 = (ret0 == HICN_ERROR_NONE) || \ + (ret0 == HICN_ERROR_PARSER_MAPME_PACKET); \ + if (PREDICT_FALSE (!ret0)) \ + { \ + next0 = HICN##ipv##_IFACE_INPUT_NEXT_ERROR_DROP; \ + } \ + else \ + { \ + next0 = is_mapme0 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme0) * (NEXT_INTEREST_IP##ipv + is_manifest0); \ + \ + next_iface0 = NEXT_DATA_LOOKUP_IP##ipv; \ + sw_if0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + \ + if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL && \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX] != ADJ_INDEX_INVALID) \ + { \ + next_iface0 = NEXT_UDP_ENCAP_IP4; \ + sw_if0 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL && \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX] != \ + ADJ_INDEX_INVALID) \ + { \ + next_iface0 = NEXT_UDP_ENCAP_IP6; \ + sw_if0 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_PG) \ + { \ + next_iface0 = NEXT_PG##ipv; \ + } \ + \ + DPO_ADD_LOCK_FACE_IP##ipv ( \ + &(hicnb0->face_id), &hicnb0->flags, &(ip_hdr->src_address), \ + sw_if0, vnet_buffer (b0)->ip.adj_index[VLIB_RX], next_iface0); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_INPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = sw_if0; \ + t->next_index = next0; \ + t->error = ret0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + vlib_increment_combined_counter ( \ + &counters[hicnb0->face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_RX, 1, \ + vlib_buffer_length_in_chain (vm, b0)); \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, next0); \ + } \ + while (0) + +#define iface_input_x2(ipv) \ + do \ + { \ + vlib_buffer_t *b0, *b1; \ + u32 bi0, bi1, next0, next1; \ + u32 next_iface0, next_iface1, sw_if0 = ~0, sw_if1 = ~0; \ + u8 is_mapme0, is_mapme1, is_manifest0, is_manifest1; \ + IP_HEADER_##ipv *ip_hdr0 = NULL; \ + IP_HEADER_##ipv *ip_hdr1 = NULL; \ + int ret0 = HICN_ERROR_NONE, ret1 = HICN_ERROR_NONE; \ + hicn_buffer_t *hicnb0, *hicnb1; \ + \ + /* Prefetch for next iteration. */ \ + vlib_buffer_t *b2, *b3; \ + b2 = vlib_get_buffer (vm, from[2]); \ + b3 = vlib_get_buffer (vm, from[3]); \ + CLIB_PREFETCH (b2, 2 * CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b3, 2 * CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES, LOAD); \ + CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES, LOAD); \ + \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + bi1 = from[1]; \ + from += 2; \ + n_left_from -= 2; \ + to_next[0] = bi0; \ + to_next[1] = bi1; \ + to_next += 2; \ + n_left_to_next -= 2; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + b1 = vlib_get_buffer (vm, bi1); \ + hicnb0 = hicn_get_buffer (b0); \ + hicnb1 = hicn_get_buffer (b1); \ + ip_hdr0 = (IP_HEADER_##ipv *) vlib_buffer_get_current (b0); \ + ip_hdr1 = (IP_HEADER_##ipv *) vlib_buffer_get_current (b1); \ + \ + stats.pkts_interest_count += 2; \ + \ + /* Parse packet and cache useful info in opaque2 */ \ + ret0 = \ + hicn_interest_parse_pkt (b0, vlib_buffer_length_in_chain (vm, b0)); \ + ret1 = \ + hicn_interest_parse_pkt (b1, vlib_buffer_length_in_chain (vm, b1)); \ + is_mapme0 = hicn_packet_get_type (&hicn_get_buffer (b0)->pkbuf) == \ + HICN_PACKET_TYPE_MAPME; \ + is_mapme1 = hicn_packet_get_type (&hicn_get_buffer (b1)->pkbuf) == \ + HICN_PACKET_TYPE_MAPME; \ + is_manifest0 = hicnb0->payload_type == HPT_MANIFEST; \ + is_manifest1 = hicnb1->payload_type == HPT_MANIFEST; \ + ret0 = (ret0 == HICN_ERROR_NONE) || \ + (ret0 == HICN_ERROR_PARSER_MAPME_PACKET); \ + ret1 = (ret1 == HICN_ERROR_NONE) || \ + (ret1 == HICN_ERROR_PARSER_MAPME_PACKET); \ + \ + if (PREDICT_TRUE (ret0 && ret1)) \ + { \ + next0 = is_mapme0 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme0) * (NEXT_INTEREST_IP##ipv + is_manifest0); \ + \ + next1 = is_mapme1 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme1) * (NEXT_INTEREST_IP##ipv + is_manifest1); \ + \ + next_iface0 = NEXT_DATA_LOOKUP_IP##ipv; \ + sw_if0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + \ + if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL && \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX] != ADJ_INDEX_INVALID) \ + { \ + next_iface0 = NEXT_UDP_ENCAP_IP4; \ + sw_if0 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL && \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX] != \ + ADJ_INDEX_INVALID) \ + { \ + next_iface0 = NEXT_UDP_ENCAP_IP6; \ + sw_if0 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_PG) \ + { \ + next_iface0 = NEXT_PG##ipv; \ + } \ + \ + next_iface1 = NEXT_DATA_LOOKUP_IP##ipv; \ + sw_if1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + \ + if (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL && \ + vnet_buffer (b1)->ip.adj_index[VLIB_RX] != ADJ_INDEX_INVALID) \ + { \ + next_iface1 = NEXT_UDP_ENCAP_IP4; \ + sw_if1 = ~0; \ + } \ + else if (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL && \ + vnet_buffer (b1)->ip.adj_index[VLIB_RX] != \ + ADJ_INDEX_INVALID) \ + { \ + next_iface1 = NEXT_UDP_ENCAP_IP6; \ + sw_if1 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_PG) \ + { \ + next_iface1 = NEXT_PG##ipv; \ + } \ + \ + DPO_ADD_LOCK_FACE_IP##ipv ( \ + &(hicnb0->face_id), &hicnb0->flags, &(ip_hdr0->src_address), \ + sw_if0, vnet_buffer (b0)->ip.adj_index[VLIB_RX], next_iface0); \ + \ + DPO_ADD_LOCK_FACE_IP##ipv ( \ + &(hicnb1->face_id), &hicnb1->flags, &(ip_hdr1->src_address), \ + sw_if1, vnet_buffer (b1)->ip.adj_index[VLIB_RX], next_iface1); \ + } \ + else if (ret0 && !ret1) \ + { \ + next1 = HICN##ipv##_IFACE_INPUT_NEXT_ERROR_DROP; \ + next0 = is_mapme0 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme0) * NEXT_INTEREST_IP##ipv; \ + next_iface0 = NEXT_DATA_LOOKUP_IP##ipv; \ + sw_if0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + \ + if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL && \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX] != ADJ_INDEX_INVALID) \ + { \ + next_iface0 = NEXT_UDP_ENCAP_IP4; \ + sw_if0 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL && \ + vnet_buffer (b0)->ip.adj_index[VLIB_RX] != \ + ADJ_INDEX_INVALID) \ + { \ + next_iface0 = NEXT_UDP_ENCAP_IP6; \ + sw_if0 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_PG) \ + { \ + next_iface0 = NEXT_PG##ipv; \ + } \ + \ + DPO_ADD_LOCK_FACE_IP##ipv ( \ + &(hicnb0->face_id), &hicnb0->flags, &(ip_hdr0->src_address), \ + sw_if0, vnet_buffer (b0)->ip.adj_index[VLIB_RX], next_iface0); \ + } \ + else if (!ret0 && ret1) \ + { \ + next0 = HICN##ipv##_IFACE_INPUT_NEXT_ERROR_DROP; \ + next_iface1 = NEXT_DATA_LOOKUP_IP##ipv; \ + sw_if1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + next1 = is_mapme1 * NEXT_MAPME_IP##ipv + \ + (1 - is_mapme1) * NEXT_INTEREST_IP##ipv; \ + \ + if (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP4_TUNNEL && \ + vnet_buffer (b1)->ip.adj_index[VLIB_RX] != ADJ_INDEX_INVALID) \ + { \ + next_iface1 = NEXT_UDP_ENCAP_IP4; \ + sw_if1 = ~0; \ + } \ + else if (hicnb1->flags & HICN_BUFFER_FLAGS_FROM_UDP6_TUNNEL && \ + vnet_buffer (b1)->ip.adj_index[VLIB_RX] != \ + ADJ_INDEX_INVALID) \ + { \ + next_iface1 = NEXT_UDP_ENCAP_IP6; \ + sw_if1 = ~0; \ + } \ + else if (hicnb0->flags & HICN_BUFFER_FLAGS_FROM_PG) \ + { \ + next_iface1 = NEXT_PG##ipv; \ + } \ + \ + DPO_ADD_LOCK_FACE_IP##ipv ( \ + &(hicnb1->face_id), &hicnb1->flags, &(ip_hdr1->src_address), \ + sw_if1, vnet_buffer (b1)->ip.adj_index[VLIB_RX], next_iface1); \ + } \ + else \ + { \ + next0 = HICN##ipv##_IFACE_INPUT_NEXT_ERROR_DROP; \ + next1 = HICN##ipv##_IFACE_INPUT_NEXT_ERROR_DROP; \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_INPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = sw_if0; \ + t->next_index = next0; \ + t->error = ret0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b1->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_INPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b1, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = sw_if1; \ + t->next_index = next1; \ + t->error = ret1; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b1), \ + sizeof (t->packet_data)); \ + } \ + \ + vlib_increment_combined_counter ( \ + &counters[hicnb0->face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_RX, 1, \ + vlib_buffer_length_in_chain (vm, b0)); \ + \ + vlib_increment_combined_counter ( \ + &counters[hicnb1->face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_RX, 1, \ + vlib_buffer_length_in_chain (vm, b1)); \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, bi1, next0, \ + next1); \ + } \ + while (0) static uword -hicn4_iface_input_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn4_iface_input_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; @@ -403,8 +506,7 @@ hicn4_iface_input_node_fn (vlib_main_t * vm, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_INTERESTS, stats.pkts_interest_count); return (frame->n_vectors); @@ -412,24 +514,29 @@ hicn4_iface_input_node_fn (vlib_main_t * vm, /* packet trace format function */ static u8 * -hicn4_iface_input_format_trace (u8 * s, va_list * args) +hicn4_iface_input_format_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 *); - hicn4_iface_input_trace_t *t = - va_arg (*args, hicn4_iface_input_trace_t *); + hicn4_iface_input_trace_t *t = va_arg (*args, hicn4_iface_input_trace_t *); + + s = format (s, "IFACE_IP4_INPUT: pkt: %d, sw_if_index %d, next index %d", + (int) t->pkt_type, t->sw_if_index, t->next_index); + + if (t->error) + { + s = format (s, " drop reason: %s", get_error_string (t->error)); + } + + s = format (s, "\n%U", format_ip4_header, t->packet_data, + sizeof (t->packet_data)); - s = - format (s, "IFACE_IP4_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - format_ip4_header, t->packet_data, sizeof (t->packet_data)); return (s); } /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (hicn4_iface_input_node) = { .function = hicn4_iface_input_node_fn, @@ -444,16 +551,15 @@ VLIB_REGISTER_NODE (hicn4_iface_input_node) = .next_nodes = { [HICN4_IFACE_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", + [HICN4_IFACE_INPUT_NEXT_INTEREST_MANIFEST] = "hicn-interest-manifest-pcslookup", [HICN4_IFACE_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", [HICN4_IFACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ static uword -hicn6_iface_input_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn6_iface_input_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; @@ -483,8 +589,7 @@ hicn6_iface_input_node_fn (vlib_main_t * vm, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_INTERESTS, stats.pkts_interest_count); return (frame->n_vectors); @@ -492,24 +597,21 @@ hicn6_iface_input_node_fn (vlib_main_t * vm, /* packet trace format function */ static u8 * -hicn6_iface_input_format_trace (u8 * s, va_list * args) +hicn6_iface_input_format_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 *); - hicn6_iface_input_trace_t *t = - va_arg (*args, hicn6_iface_input_trace_t *); + hicn6_iface_input_trace_t *t = va_arg (*args, hicn6_iface_input_trace_t *); - s = - format (s, "IFACE_IP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - format_ip6_header, t->packet_data, sizeof (t->packet_data)); + s = format (s, "IFACE_IP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", + (int) t->pkt_type, t->sw_if_index, t->next_index, + format_ip6_header, t->packet_data, sizeof (t->packet_data)); return (s); } /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (hicn6_iface_input_node) = { .function = hicn6_iface_input_node_fn, @@ -524,20 +626,20 @@ VLIB_REGISTER_NODE (hicn6_iface_input_node) = .next_nodes = { [HICN6_IFACE_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", + [HICN6_IFACE_INPUT_NEXT_INTEREST_MANIFEST] = "hicn-interest-manifest-pcslookup", [HICN6_IFACE_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", [HICN6_IFACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ - /**** IFACE OUTPUT *****/ static inline void -hicn_rewrite_iface_data4 (vlib_main_t * vm, vlib_buffer_t * b0, - const hicn_face_t * iface, u32 * next) +hicn_rewrite_iface_data4 (vlib_main_t *vm, vlib_buffer_t *b0, + const hicn_face_t *iface, u32 *next) { ip4_header_t *ip0; + int ret = HICN_ERROR_NONE; /* Get the pointer to the old ip and tcp header */ ip0 = vlib_buffer_get_current (b0); @@ -546,29 +648,36 @@ hicn_rewrite_iface_data4 (vlib_main_t * vm, vlib_buffer_t * b0, /* IP4 lenght contains the size of the ip4 header too */ u16 sval = (vlib_buffer_length_in_chain (vm, b0)); ip0->length = clib_host_to_net_u16 (sval); - ip0->ttl = 254; // FIXME TTL + ip0->ttl = 254; // FIXME TTL vnet_buffer (b0)->ip.adj_index[VLIB_TX] = iface->dpo.dpoi_index; - *next = iface->dpo.dpoi_next_node; - hicn_header_t *hicn = vlib_buffer_get_current (b0); - - ip46_address_t temp_addr; - ip46_address_reset (&temp_addr); - hicn_type_t type = hicn_get_buffer (b0)->type; - int ret = hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &(iface->nat_addr), &(temp_addr), - iface->pl_id); + *next = iface->iface_next; + + hicn_packet_buffer_t *pkbuf = &hicn_get_buffer (b0)->pkbuf; + + hicn_ip_address_t temp_addr; + ip46_address_reset (&(temp_addr.as_ip46)); + + hicn_ip_address_t *iface_nat_addr = (hicn_ip_address_t *) &(iface->nat_addr); + + u8 flags = hicn_get_buffer (b0)->flags; + u8 reset_pl = flags & HICN_BUFFER_FLAGS_FROM_CS; + + ret = hicn_data_rewrite (pkbuf, iface_nat_addr, &(temp_addr), iface->pl_id, + reset_pl); + if (ret == HICN_LIB_ERROR_REWRITE_CKSUM_REQUIRED) { - ensure_offload_flags(b0, 1 /* is_v4 */); + ensure_offload_flags (b0, 1 /* is_v4 */); } } static inline void -hicn_rewrite_iface_data6 (vlib_main_t * vm, vlib_buffer_t * b0, - const hicn_face_t * iface, u32 * next) +hicn_rewrite_iface_data6 (vlib_main_t *vm, vlib_buffer_t *b0, + const hicn_face_t *iface, u32 *next) { ip6_header_t *ip0; + int ret = HICN_ERROR_NONE; /* Get the pointer to the old ip and tcp header */ /* Copy the previous ip and tcp header to the new portion of memory */ @@ -581,190 +690,178 @@ hicn_rewrite_iface_data6 (vlib_main_t * vm, vlib_buffer_t * b0, ip0->hop_limit = HICN_IP6_HOP_LIMIT; vnet_buffer (b0)->ip.adj_index[VLIB_TX] = iface->dpo.dpoi_index; - *next = iface->dpo.dpoi_next_node; + *next = iface->iface_next; - hicn_header_t *hicn = vlib_buffer_get_current (b0); + hicn_packet_buffer_t *pkbuf = &hicn_get_buffer (b0)->pkbuf; - ip46_address_t temp_addr; - ip46_address_reset (&temp_addr); - hicn_type_t type = hicn_get_buffer (b0)->type; - int ret = hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &(iface->nat_addr), &(temp_addr), - iface->pl_id); + hicn_ip_address_t temp_addr; + ip46_address_reset (&(temp_addr.as_ip46)); + + hicn_ip_address_t *iface_nat_addr = (hicn_ip_address_t *) &(iface->nat_addr); + u8 flags = hicn_get_buffer (b0)->flags; + u8 reset_pl = flags & HICN_BUFFER_FLAGS_FROM_CS; + + ret = hicn_data_rewrite (pkbuf, iface_nat_addr, &(temp_addr), iface->pl_id, + reset_pl); if (ret == HICN_LIB_ERROR_REWRITE_CKSUM_REQUIRED) { - ensure_offload_flags(b0, 0 /* is_v4 */); + ensure_offload_flags (b0, 0 /* is_v4 */); } } -#define iface_output_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = next_index; \ - hicn_face_t * face; \ - \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , STORE); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - \ - hicn_face_id_t face_id = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - face = \ - hicn_dpoi_get_from_idx (face_id); \ - \ - if (PREDICT_TRUE(face != NULL)) \ - { \ - HICN_REWRITE_DATA_IP##ipv \ - (vm, b0, face, &next0); \ - stats.pkts_data_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_DATA_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0));\ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - }while(0); \ - - -#define iface_output_x2(ipv) \ - do { \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0 = next_index; \ - u32 next1 = next_index; \ - hicn_face_t *face0, *face1; \ - \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , STORE); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , STORE); \ - } \ - \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - \ - hicn_face_id_t face_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - hicn_face_id_t face_id1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ - face0 = \ - hicn_dpoi_get_from_idx (face_id0); \ - face1 = \ - hicn_dpoi_get_from_idx (face_id1); \ - \ - if (PREDICT_TRUE(face0 != NULL)) \ - { \ - HICN_REWRITE_DATA_IP##ipv \ - (vm, b0, face0, &next0); \ - stats.pkts_data_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id0 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_DATA_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0));\ - } \ - \ - if (PREDICT_TRUE(face1 != NULL)) \ - { \ - HICN_REWRITE_DATA_IP##ipv \ - (vm, b1, face1, &next1); \ - stats.pkts_data_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id1 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_DATA_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_IP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - }while(0); \ - - +#define iface_output_x1(ipv) \ + do \ + { \ + vlib_buffer_t *b0; \ + u32 bi0; \ + u32 next0 = next_index; \ + hicn_face_t *face = NULL; \ + \ + /* Prefetch for next iteration. */ \ + if (n_left_from > 1) \ + { \ + vlib_buffer_t *b1; \ + b1 = vlib_get_buffer (vm, from[1]); \ + CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES, STORE); \ + } \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + from += 1; \ + n_left_from -= 1; \ + to_next[0] = bi0; \ + to_next += 1; \ + n_left_to_next -= 1; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + \ + hicn_face_id_t face_id = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ + if (PREDICT_TRUE (hicn_dpoi_idx_is_valid (face_id))) \ + face = hicn_dpoi_get_from_idx (face_id); \ + \ + if (PREDICT_TRUE (face != NULL)) \ + { \ + HICN_REWRITE_DATA_IP##ipv (vm, b0, face, &next0); \ + stats.pkts_data_count += 1; \ + vlib_increment_combined_counter ( \ + &counters[face_id * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_DATA_TX, 1, \ + vlib_buffer_length_in_chain (vm, b0)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_OUTPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + t->next_index = next0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, next0); \ + } \ + while (0); + +#define iface_output_x2(ipv) \ + do \ + { \ + vlib_buffer_t *b0, *b1; \ + u32 bi0, bi1; \ + u32 next0 = next_index; \ + u32 next1 = next_index; \ + hicn_face_t *face0 = NULL, *face1 = NULL; \ + \ + /* Prefetch for next iteration. */ \ + { \ + vlib_buffer_t *b2, *b3; \ + b2 = vlib_get_buffer (vm, from[2]); \ + b3 = vlib_get_buffer (vm, from[3]); \ + CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES, STORE); \ + CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES, STORE); \ + } \ + \ + /* Dequeue a packet buffer */ \ + bi0 = from[0]; \ + bi1 = from[1]; \ + from += 2; \ + n_left_from -= 2; \ + to_next[0] = bi0; \ + to_next[1] = bi1; \ + to_next += 2; \ + n_left_to_next -= 2; \ + \ + b0 = vlib_get_buffer (vm, bi0); \ + b1 = vlib_get_buffer (vm, bi1); \ + \ + hicn_face_id_t face_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ + hicn_face_id_t face_id1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ + if (PREDICT_TRUE (hicn_dpoi_idx_is_valid (face_id0))) \ + face0 = hicn_dpoi_get_from_idx (face_id0); \ + if (PREDICT_TRUE (hicn_dpoi_idx_is_valid (face_id1))) \ + face1 = hicn_dpoi_get_from_idx (face_id1); \ + \ + if (PREDICT_TRUE (face0 != NULL)) \ + { \ + HICN_REWRITE_DATA_IP##ipv (vm, b0, face0, &next0); \ + stats.pkts_data_count += 1; \ + vlib_increment_combined_counter ( \ + &counters[face_id0 * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_DATA_TX, 1, \ + vlib_buffer_length_in_chain (vm, b0)); \ + } \ + \ + if (PREDICT_TRUE (face1 != NULL)) \ + { \ + HICN_REWRITE_DATA_IP##ipv (vm, b1, face1, &next1); \ + stats.pkts_data_count += 1; \ + vlib_increment_combined_counter ( \ + &counters[face_id1 * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_DATA_TX, 1, \ + vlib_buffer_length_in_chain (vm, b1)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b0->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_OUTPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b0, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ + t->next_index = next0; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b0), \ + sizeof (t->packet_data)); \ + } \ + \ + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ + (b1->flags & VLIB_BUFFER_IS_TRACED))) \ + { \ + TRACE_OUTPUT_PKT_IP##ipv *t = \ + vlib_add_trace (vm, node, b1, sizeof (*t)); \ + t->pkt_type = HICN_PACKET_TYPE_INTEREST; \ + t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ + t->next_index = next1; \ + clib_memcpy_fast (t->packet_data, vlib_buffer_get_current (b1), \ + sizeof (t->packet_data)); \ + } \ + \ + /* Verify speculative enqueue, maybe switch current next frame */ \ + vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, \ + n_left_to_next, bi0, bi1, next0, \ + next1); \ + } \ + while (0); static uword -hicn4_iface_output_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn4_iface_output_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; @@ -772,7 +869,7 @@ hicn4_iface_output_node_fn (vlib_main_t * vm, from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; - next_index = node->cached_next_index; + next_index = HICN4_IFACE_OUTPUT_NEXT_DROP; while (n_left_from > 0) { @@ -792,20 +889,19 @@ hicn4_iface_output_node_fn (vlib_main_t * vm, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_DATAS, + stats.pkts_data_count); return (frame->n_vectors); } /* packet trace format function */ static u8 * -hicn4_iface_output_format_trace (u8 * s, va_list * args) +hicn4_iface_output_format_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 *); - hicn4_iface_output_trace_t *t = - va_arg (*args, hicn4_iface_output_trace_t *); + hicn4_iface_output_trace_t *t = va_arg (*args, hicn4_iface_output_trace_t *); s = format (s, "IFACE_IP4_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -817,32 +913,26 @@ hicn4_iface_output_format_trace (u8 * s, va_list * args) /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn4_iface_output_node) = -{ +VLIB_REGISTER_NODE (hicn4_iface_output_node) = { .function = hicn4_iface_output_node_fn, .name = "hicn4-iface-output", - .vector_size = sizeof (u32), + .vector_size = sizeof (u32), .format_trace = hicn4_iface_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = ARRAY_LEN (hicn4_iface_output_error_strings), .error_strings = hicn4_iface_output_error_strings, .n_next_nodes = HICN4_IFACE_OUTPUT_N_NEXT, /* edit / add dispositions here */ - .next_nodes = - { - [HICN4_IFACE_OUTPUT_NEXT_LOOKUP] = "ip4-lookup", - [HICN4_IFACE_OUTPUT_NEXT_UDP4_ENCAP] = "udp4-encap", - [HICN4_IFACE_OUTPUT_NEXT_UDP6_ENCAP] = "udp6-encap" - }, + .next_nodes = { [HICN4_IFACE_OUTPUT_NEXT_DROP] = "error-drop", + [HICN4_IFACE_OUTPUT_NEXT_LOOKUP] = "ip4-lookup", + [HICN4_IFACE_OUTPUT_NEXT_UDP4_ENCAP] = "udp4-encap", + [HICN4_IFACE_OUTPUT_NEXT_UDP6_ENCAP] = "udp6-encap", + [HICN4_IFACE_OUTPUT_NEXT_PG] = "hicnpg-data" }, }; -/* *INDENT-ON* */ - static uword -hicn6_iface_output_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn6_iface_output_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next, next_index; vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; @@ -850,7 +940,7 @@ hicn6_iface_output_node_fn (vlib_main_t * vm, from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; - next_index = node->cached_next_index; + next_index = HICN6_IFACE_OUTPUT_NEXT_DROP; while (n_left_from > 0) { @@ -869,20 +959,19 @@ hicn6_iface_output_node_fn (vlib_main_t * vm, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); + vlib_node_increment_counter (vm, node->node_index, HICNFWD_ERROR_DATAS, + stats.pkts_data_count); return (frame->n_vectors); } /* packet trace format function */ static u8 * -hicn6_iface_output_format_trace (u8 * s, va_list * args) +hicn6_iface_output_format_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 *); - hicn6_iface_output_trace_t *t = - va_arg (*args, hicn6_iface_output_trace_t *); + hicn6_iface_output_trace_t *t = va_arg (*args, hicn6_iface_output_trace_t *); s = format (s, "IFACE_IP6_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -894,27 +983,22 @@ hicn6_iface_output_format_trace (u8 * s, va_list * args) /* * Node registration for the interest forwarder node */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn6_iface_output_node) = -{ +VLIB_REGISTER_NODE (hicn6_iface_output_node) = { .function = hicn6_iface_output_node_fn, .name = "hicn6-iface-output", - .vector_size = sizeof (u32), + .vector_size = sizeof (u32), .format_trace = hicn6_iface_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = ARRAY_LEN (hicn6_iface_output_error_strings), .error_strings = hicn6_iface_output_error_strings, .n_next_nodes = HICN6_IFACE_OUTPUT_N_NEXT, /* edit / add dispositions here */ - .next_nodes = - { - [HICN6_IFACE_OUTPUT_NEXT_LOOKUP] = "ip6-lookup", - [HICN6_IFACE_OUTPUT_NEXT_UDP4_ENCAP] = "udp4-encap", - [HICN6_IFACE_OUTPUT_NEXT_UDP6_ENCAP] = "udp6-encap" - - }, + .next_nodes = { [HICN6_IFACE_OUTPUT_NEXT_DROP] = "error-drop", + [HICN6_IFACE_OUTPUT_NEXT_LOOKUP] = "ip6-lookup", + [HICN6_IFACE_OUTPUT_NEXT_UDP4_ENCAP] = "udp4-encap", + [HICN6_IFACE_OUTPUT_NEXT_UDP6_ENCAP] = "udp6-encap", + [HICN6_IFACE_OUTPUT_NEXT_PG] = "hicnpg-data" }, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/iface_node.h b/hicn-plugin/src/faces/iface_node.h index 1a7c4291b..d580c9e31 100644 --- a/hicn-plugin/src/faces/iface_node.h +++ b/hicn-plugin/src/faces/iface_node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Cisco and/or its affiliates. + * Copyright (c) 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,18 +30,37 @@ * is to create (or retrieve if already existing) the list incoming face * for each the interest packet. * The following node to the input iface nodes is the hicn-interest-pcslookup. - * Output iface nodes follow the hicn-data-fwd and the hicn-interest-hitcs nodes and - * they perform the dst nat on each data packet. The node following the - * output face nodes depends on the adjacency type. In case of ip, the following - * node is the ip4/6-lookup, in case of tunnels the next node is the one implementing - * the tunnel encapsulation (udp-encap, mpls, etc). + * Output iface nodes follow the hicn-data-fwd and the hicn-interest-hitcs + * nodes and they perform the dst nat on each data packet. The node following + * the output face nodes depends on the adjacency type. In case of ip, the + * following node is the ip4/6-lookup, in case of tunnels the next node is the + * one implementing the tunnel encapsulation (udp-encap, mpls, etc). */ +typedef enum +{ + HICN4_IFACE_OUTPUT_NEXT_DROP, + HICN4_IFACE_OUTPUT_NEXT_LOOKUP, + HICN4_IFACE_OUTPUT_NEXT_UDP4_ENCAP, + HICN4_IFACE_OUTPUT_NEXT_UDP6_ENCAP, + HICN4_IFACE_OUTPUT_NEXT_PG, + HICN4_IFACE_OUTPUT_N_NEXT, +} hicn4_iface_output_next_t; + +typedef enum +{ + HICN6_IFACE_OUTPUT_NEXT_DROP, + HICN6_IFACE_OUTPUT_NEXT_LOOKUP, + HICN6_IFACE_OUTPUT_NEXT_UDP4_ENCAP, + HICN6_IFACE_OUTPUT_NEXT_UDP6_ENCAP, + HICN6_IFACE_OUTPUT_NEXT_PG, + HICN6_IFACE_OUTPUT_N_NEXT, +} hicn6_iface_output_next_t; /** * @brief Initialize the ip iface module */ -void hicn_iface_init (vlib_main_t * vm); +void hicn_iface_init (vlib_main_t *vm); #endif // __HICN_IFACE_IP_NODE_H__ diff --git a/hicn-plugin/src/faces/inlines.h b/hicn-plugin/src/faces/inlines.h index bfe56c8e6..ad9e26b62 100644 --- a/hicn-plugin/src/faces/inlines.h +++ b/hicn-plugin/src/faces/inlines.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Cisco and/or its affiliates. + * Copyright (c) 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,24 +19,21 @@ #include <vlib/buffer.h> always_inline void -ensure_offload_flags (vlib_buffer_t * b, int is_v4) +ensure_offload_flags (vlib_buffer_t *b, int is_v4) { - b->flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; - b->flags |= is_v4 * VNET_BUFFER_F_OFFLOAD_IP_CKSUM; - size_t l3_header_size = is_v4 * sizeof(ip4_header_t) + (!is_v4) * sizeof(ip6_header_t); + vnet_buffer_offload_flags_set (b, VNET_BUFFER_OFFLOAD_F_TCP_CKSUM); + vnet_buffer_offload_flags_set (b, is_v4 * VNET_BUFFER_OFFLOAD_F_IP_CKSUM); + + size_t l3_header_size = + is_v4 * sizeof (ip4_header_t) + (!is_v4) * sizeof (ip6_header_t); /* Make sure l3_hdr_offset and l4_hdr_offset are set */ - if (!(b->flags & VNET_BUFFER_F_L3_HDR_OFFSET_VALID)) - { - b->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID; - vnet_buffer(b)->l3_hdr_offset = b->current_data; - } - if (!(b->flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID)) - { - b->flags |= VNET_BUFFER_F_L4_HDR_OFFSET_VALID; - vnet_buffer(b)->l4_hdr_offset = - vnet_buffer(b)->l3_hdr_offset + l3_header_size; - } + b->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID; + vnet_buffer (b)->l3_hdr_offset = b->current_data; + + b->flags |= VNET_BUFFER_F_L4_HDR_OFFSET_VALID; + vnet_buffer (b)->l4_hdr_offset = + vnet_buffer (b)->l3_hdr_offset + l3_header_size; } #endif /* __HICN_FACE_INLINES_H__ */
\ No newline at end of file |