diff options
Diffstat (limited to 'hicn-plugin/src/faces/ip')
-rw-r--r-- | hicn-plugin/src/faces/ip/dpo_ip.c | 90 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/dpo_ip.h | 288 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/face_ip.c | 571 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/face_ip.h | 310 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/face_ip_cli.c | 208 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/face_ip_node.c | 993 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/face_ip_node.h | 40 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/iface_ip_node.c | 919 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/iface_ip_node.h | 35 |
9 files changed, 0 insertions, 3454 deletions
diff --git a/hicn-plugin/src/faces/ip/dpo_ip.c b/hicn-plugin/src/faces/ip/dpo_ip.c deleted file mode 100644 index d05fec1a0..000000000 --- a/hicn-plugin/src/faces/ip/dpo_ip.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ - -#include "dpo_ip.h" - -mhash_t hicn_face_ip_local_hashtb; -mhash_t hicn_face_ip_remote_hashtb; -dpo_type_t hicn_face_ip_type; - -hicn_face_ip_vec_t * hicn_vec_pool; - -const static char *const hicn_face_ip4dpoi_nodes[] = { - "hicn-face-ip4-input", - "hicn-face-ip4-output", - "hicn-iface-ip4-input", - "hicn-iface-ip4-output", - NULL, -}; - -const static char *const hicn_face_ip6dpoi_nodes[] = { - "hicn-face-ip6-input", - "hicn-face-ip6-output", - "hicn-iface-ip6-input", - "hicn-iface-ip6-output", - NULL, -}; - -const static char *const *const hicn_ip_nodes[DPO_PROTO_NUM] = { - [DPO_PROTO_IP4] = hicn_face_ip4dpoi_nodes, - [DPO_PROTO_IP6] = hicn_face_ip6dpoi_nodes -}; - -const static dpo_vft_t hicn_face_ip_vft = { - .dv_lock = hicn_face_lock, - .dv_unlock = hicn_face_unlock, - .dv_format = format_hicn_face_ip, -}; - -/* Must be executed after all the strategy nodes are created */ -void -hicn_dpo_ip_module_init (void) -{ - mhash_init (&hicn_face_ip_local_hashtb, - sizeof (hicn_face_ip_input_faces_t) /* value */ , - sizeof (hicn_face_ip_key_t) /* key */ ); - mhash_init (&hicn_face_ip_remote_hashtb, - sizeof (hicn_face_id_t) /* value */ , - sizeof (hicn_face_ip_key_t) /* key */ ); - - pool_alloc(hicn_vec_pool, 100); - - /* - * How much useful is the following registration? - * So far it seems that we need it only for setting the dpo_type. - */ - hicn_face_ip_type = - dpo_register_new_type (&hicn_face_ip_vft, hicn_ip_nodes); -} - -void -hicn_dpo_ip_create_from_face (hicn_face_t * face, dpo_id_t * dpo, - u16 dpoi_next_node) -{ - hicn_face_id_t face_dpoi_id = hicn_dpoi_get_index (face); - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - dpo_set (dpo, face->shared.face_type, - ip46_address_is_ip4 (&ip_face->local_addr) ? DPO_PROTO_IP4 : - DPO_PROTO_IP6, face_dpoi_id); - dpo->dpoi_next_node = dpoi_next_node; -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/dpo_ip.h b/hicn-plugin/src/faces/ip/dpo_ip.h deleted file mode 100644 index c893c8be4..000000000 --- a/hicn-plugin/src/faces/ip/dpo_ip.h +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_DPO_IP_H__ -#define __HICN_DPO_IP_H__ - -#include <vnet/vnet.h> -#include <vnet/ip/ip4_packet.h> - -#include "face_ip.h" -#include "../face.h" - -/** - * @brief Initialize the internal structures of the dpo ip face module. - */ -void hicn_dpo_ip_module_init (void); - - -/** - * @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 local 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_dpo_ip4_lock_from_local (dpo_id_t * dpo, - u32 * in_faces_vec_id, - u8 * hicnb_flags, - const ip4_address_t * local_addr, u32 sw_if) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - hicn_face_ip_input_faces_t *in_faces_vec = - hicn_face_ip4_get_vec (local_addr, sw_if, &hicn_face_ip_local_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->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; - - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, in_faces_vec->face_id); - dpo->dpoi_next_node = ~0; - dpo_unlock (dpo); - - return HICN_ERROR_NONE; -} - -/** - * @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 local_addr: Ip v6 local 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_dpo_ip6_lock_from_local (dpo_id_t * dpo, - u32 * in_faces_vec_id, - u8 * hicnb_flags, - const ip6_address_t * local_addr, u32 sw_if) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - hicn_face_ip_input_faces_t *in_faces_vec = - hicn_face_ip6_get_vec (local_addr, sw_if, &hicn_face_ip_local_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->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; - - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP6, in_faces_vec->face_id); - dpo->dpoi_next_node = ~0; - dpo_unlock (dpo); - - return HICN_ERROR_NONE; -} - - -/** - * @brief Retrieve, or create if it doesn't exist, 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 - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not - * @param local_addr: Ip v4 local address of the face - * @param remote_addr: Ip v4 remote address of the face - * @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_dpo_ip4_add_and_lock_from_remote (dpo_id_t * dpo, - u8 * hicnb_flags, - const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u32 sw_if, u32 node_index) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - /*All (complete) faces are indexed by remote addess as well */ - hicn_face_t *face = - hicn_face_ip4_get (remote_addr, sw_if, &hicn_face_ip_remote_hashtb); - - if (face == NULL) - { - hicn_face_id_t dpoi_index; - ip46_address_t local_addr46 = to_ip46 (0, (u8 *) local_addr); - ip46_address_t remote_addr46 = to_ip46 (0, (u8 *) remote_addr); - hicn_iface_ip_add (&local_addr46, &remote_addr46, sw_if, &dpoi_index); - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); - - return; - } - - /* Code replicated on purpose */ - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - *hicnb_flags |= - (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; - - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); -} - -/** - * @brief Retrieve, or create if it doesn't exist, 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 - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not - * @param local_addr: Ip v6 local address of the face - * @param remote_addr: Ip v6 remote address of the face - * @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_dpo_ip6_add_and_lock_from_remote (dpo_id_t * dpo, - u8 * hicnb_flags, - const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u32 sw_if, u32 node_index) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - /*All (complete) faces are indexed by remote addess as well */ - hicn_face_t *face = - hicn_face_ip6_get (remote_addr, sw_if, &hicn_face_ip_remote_hashtb); - - if (face == NULL) - { - hicn_face_id_t dpoi_index; - hicn_iface_ip_add ((ip46_address_t *) local_addr, - (ip46_address_t *) remote_addr, sw_if, &dpoi_index); - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); - - return; - } - /* Code replicated on purpose */ - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - *hicnb_flags |= - (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> - HICN_FACE_FLAGS_APPFACE_PROD_BIT; - - index_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP6, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); -} - - -/* /\** */ -/* * @brief Create an ip face and its corresponding dpo. Meant to be used for the */ -/* * control plane. */ -/* * */ -/* * @param dpo: Data plane object that point to the face created. */ -/* * @param local_addr: Ip v4 local address of the face */ -/* * @param remote_addr: Ip v4 remote address of the face */ -/* * @param sw_if: software interface id of the face */ -/* * @param adj: Ip adjacency corresponding to the remote address in the face */ -/* * @param node_index: vlib edge index to use in the packet processing */ -/* * @param flags: Flags of the face */ -/* * @param face_id: Identifier for the face (dpoi_index) */ -/* * @return HICN_ERROR_FACE_ALREADY_CREATED if the face exists, otherwise HICN_ERROR_NONE */ -/* *\/ */ -/* int hicn_dpo_ip4_create (dpo_id_t * dpo, */ -/* const ip4_address_t * local_addr, */ -/* const ip4_address_t * remote_addr, */ -/* u32 sw_if, */ -/* adj_index_t adj, */ -/* u32 node_index, */ -/* hicn_face_flags_t flags, hicn_face_id_t * face_id); */ - -/* /\** */ -/* * @brief Create an ip face and its corresponding dpo. Meant to be used for the */ -/* * control plane. */ -/* * */ -/* * @param dpo: Data plane object that point to the face created. */ -/* * @param local_addr: Ip v6 local address of the face */ -/* * @param remote_addr: Ip v6 remote address of the face */ -/* * @param sw_if: software interface id of the face */ -/* * @param adj: Ip adjacency corresponding to the remote address in the face */ -/* * @param node_index: vlib edge index to use in the packet processing */ -/* * @param flags: Flags of the face */ -/* * @param face_id: Identifier for the face (dpoi_index) */ -/* * @return HICN_ERROR_FACE_ALREADY_CREATED if the face exists, otherwise HICN_ERROR_NONE */ -/* *\/ */ -/* int hicn_dpo_ip6_create (dpo_id_t * dpo, */ -/* const ip6_address_t * local_addr, */ -/* const ip6_address_t * remote_addr, */ -/* u32 sw_if, */ -/* adj_index_t adj, */ -/* u32 node_index, */ -/* hicn_face_flags_t flags, hicn_face_id_t * face_id); */ - -/** - * @brief Create a dpo from an ip face - * - * @param face Face from which to create the dpo - * @param dpoi_next_node Edge index that connects a node to the iface or face nodes - * @return the dpo - */ -void hicn_dpo_ip_create_from_face (hicn_face_t * face, dpo_id_t * dpo, - u16 dpoi_next_node); - -#endif // __HICN_DPO_IP_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip.c b/hicn-plugin/src/faces/ip/face_ip.c deleted file mode 100644 index a2fe069ed..000000000 --- a/hicn-plugin/src/faces/ip/face_ip.c +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ -#include <vnet/adj/adj_midchain.h> -#include <vnet/adj/adj.h> - -#include "face_ip.h" -#include "face_ip_node.h" -#include "dpo_ip.h" -#include "../../strategy_dpo_manager.h" -#include "../face.h" -#include "../../cache_policies/cs_lru.h" -#include "../../infra.h" -#include "../../hicn.h" -#include "../app/face_prod.h" -#include "../app/face_cons.h" - -#include "../../mapme.h" // HICN_MAPME_EVENT_* -#include "../../mapme_eventmgr.h" // hicn_mapme_eventmgr_process_node - -extern vlib_node_registration_t hicn_mapme_eventmgr_process_node; - -u32 strategy_face_ip4_vlib_edge; -u32 strategy_face_ip6_vlib_edge; - -void -hicn_face_ip_init (vlib_main_t * vm) -{ - int strategy_nodes_n = hicn_strategy_get_all_available (); - - /* Default Strategy has index 0 and it always exists */ - strategy_face_ip4_vlib_edge = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip4_output_node.index); - - strategy_face_ip6_vlib_edge = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip6_output_node.index); - /* - * Create and edge between al the other strategy nodes and the - * ip_encap nodes. - */ - for (int i = 1; i < strategy_nodes_n; i++) - { - u32 temp_index4 = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip6_output_node.index); - ASSERT (temp_index4 == strategy_face_ip4_vlib_edge); - ASSERT (temp_index6 == strategy_face_ip6_vlib_edge); - } - - u32 temp_index4 = vlib_node_add_next (vm, - hicn_interest_hitpit_node.index, - hicn_face_ip4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - hicn_interest_hitpit_node.index, - hicn_face_ip6_output_node.index); - - ASSERT (temp_index4 == strategy_face_ip4_vlib_edge); - ASSERT (temp_index6 == strategy_face_ip6_vlib_edge); - - - hicn_dpo_ip_module_init (); - - register_face_type (hicn_face_ip_type, &ip_vft, "ip"); -} - -int -hicn_face_ip_del (hicn_face_id_t face_id) -{ - hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - hicn_face_ip_key_t key; - hicn_face_ip_key_t old_key; - hicn_face_ip_key_t old_key2; - - if (ip46_address_is_ip4 (&face_ip->local_addr)) - { - hicn_face_ip4_get_key (&(face_ip->local_addr.ip4), face->shared.sw_if, - &key); - hicn_face_ip_input_faces_t *in_faces_vec = - hicn_face_ip4_get_vec (&(face_ip->local_addr.ip4), face->shared.sw_if, - &hicn_face_ip_local_hashtb); - if (in_faces_vec != NULL) - { - hicn_face_ip_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_ip_local_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]; - } - } - hicn_face_ip4_get_key (&(face_ip->remote_addr.ip4), - face->shared.sw_if, &key); - mhash_unset (&hicn_face_ip_remote_hashtb, &key, - (uword *) & old_key2); - } - } - else - { - hicn_face_ip6_get_key (&(face_ip->local_addr.ip6), face->shared.sw_if, - &key); - - hicn_face_ip_input_faces_t *in_faces_vec = - hicn_face_ip6_get_vec (&(face_ip->local_addr.ip6), face->shared.sw_if, - &hicn_face_ip_local_hashtb); - if (in_faces_vec != NULL) - { - hicn_face_ip_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 (hicn_vec_pool, vec); - mhash_unset (&hicn_face_ip_local_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]; - } - } - hicn_face_ip6_get_key (&(face_ip->remote_addr.ip6), - face->shared.sw_if, &key); - mhash_unset (&hicn_face_ip_remote_hashtb, &key, - (uword *) & old_key); - } - } - return hicn_face_del (face_id); -} - -/** - * @brief Helper for handling midchain adjacencies - */ -void -face_midchain_fixup_t (vlib_main_t * vm, - const struct ip_adjacency_t_ *adj, - vlib_buffer_t * b0, const void *data) -{ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = 0; -}; - -/** - * @brief Build a rewrite string for the face. - */ -static u8 * -face_build_rewrite_i (void) -{ - /* - * passing the adj code a NULL rewrite means 'i don't have one cos - * t'other end is unresolved'. That's not the case here. For the mpls - * tunnel there are just no bytes of encap to apply in the adj. We'll impose - * the label stack once we choose a path. So return a zero length rewrite. - */ - u8 *rewrite = NULL; - - vec_validate (rewrite, 0); - vec_reset_length (rewrite); - - return (rewrite); -} - -always_inline int -hicn_face_ip_find_adj (const ip46_address_t * remote_addr, - int sw_if, adj_index_t * adj) -{ - fib_prefix_t fib_pfx; - fib_node_index_t fib_entry_index; - fib_prefix_from_ip46_addr (remote_addr, &fib_pfx); - fib_pfx.fp_len = ip46_address_is_ip4 (remote_addr) ? 32 : 128; - vnet_link_t link_type = - ip46_address_is_ip4 (&fib_pfx.fp_addr) ? VNET_LINK_IP4 : VNET_LINK_IP6; - *adj = adj_nbr_find (fib_pfx.fp_proto, link_type, &fib_pfx.fp_addr, sw_if); - - if (*adj == ADJ_INDEX_INVALID) - { - u32 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 (fib_index, &fib_pfx); - - if (fib_entry_index == (FIB_NODE_INDEX_INVALID)) - return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND; - - *adj = fib_entry_get_adj (fib_entry_index); - ip_adjacency_t *temp = NULL; - if (*adj != ~0) - temp = adj_get (*adj); - - if (temp == NULL || temp->lookup_next_index <= IP_LOOKUP_NEXT_MIDCHAIN) - { - if (sw_if != ~0) - *adj = - adj_nbr_add_or_lock (fib_pfx.fp_proto, link_type, remote_addr, - sw_if); - else - return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND; - } - else - { - adj_nbr_midchain_update_rewrite (*adj, &face_midchain_fixup_t, NULL, - ADJ_FLAG_NONE, - face_build_rewrite_i ()); - adj_midchain_delegate_stack (*adj, fib_index, &fib_pfx); - } - } - - return HICN_ERROR_NONE; -} - -/* - * Utility that adds a new face cache entry. For the moment we assume that - * the ip_adjacency has already been set up. - */ -int -hicn_face_ip_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, - int sw_if, hicn_face_id_t * pfaceid, u8 is_app_prod) -{ - dpo_proto_t dpo_proto; - - /* Check if we found at least one ip address */ - if (ip46_address_is_zero (remote_addr)) - return HICN_ERROR_FACE_NO_GLOBAL_IP; - - hicn_face_flags_t flags = (hicn_face_flags_t) 0; - flags |= HICN_FACE_FLAGS_FACE; - - hicn_face_t *face; - if (ip46_address_is_ip4 (local_addr)) - { - face = - hicn_face_ip4_get (&(remote_addr->ip4), sw_if, - &hicn_face_ip_remote_hashtb); - - /* If remote matches the face we need to check if it is an incomplete face */ - if (face == NULL) - { - hicn_iface_ip_add (local_addr, remote_addr, sw_if, pfaceid); - face = hicn_dpoi_get_from_idx (*pfaceid); - } - else - { - *pfaceid = hicn_dpoi_get_index (face); - } - - if (!(face->shared.flags & HICN_FACE_FLAGS_IFACE)) - return HICN_ERROR_FACE_ALREADY_CREATED; - - hicn_face_ip_key_t key; - hicn_face_ip4_get_key (&(local_addr->ip4), sw_if, &key); - - hicn_face_ip_input_faces_t *in_faces = - hicn_face_ip4_get_vec (&(local_addr->ip4), sw_if, - &hicn_face_ip_local_hashtb); - - if (in_faces == NULL) - { - adj_index_t adj; - int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj); - if (ret != HICN_ERROR_NONE) - return ret; - - hicn_face_ip_input_faces_t in_faces_temp; - hicn_face_ip_vec_t *vec; - pool_get (hicn_vec_pool, vec); - *vec = vec_new (hicn_face_ip_vec_t, 0); - u32 index = vec - hicn_vec_pool; - in_faces_temp.vec_id = index; - vec_add1 (*vec, *pfaceid); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - clib_memcpy (&ip_face->local_addr, local_addr, - sizeof (ip4_address_t)); - clib_memcpy (&ip_face->remote_addr, remote_addr, - sizeof (ip4_address_t)); - face->shared.sw_if = sw_if; - face->shared.flags = flags; - face->shared.adj = adj; - - dpo_proto = DPO_PROTO_IP4; - - in_faces_temp.face_id = *pfaceid; - - mhash_set_mem (&hicn_face_ip_local_hashtb, &key, - (uword *) & in_faces_temp, 0); - } - else - { - hicn_face_ip_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; - - adj_index_t adj; - int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj); - if (ret != HICN_ERROR_NONE) - return ret; - - vec_add1 (*vec, *pfaceid); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - clib_memcpy (&ip_face->local_addr, local_addr, - sizeof (ip4_address_t)); - clib_memcpy (&ip_face->remote_addr, remote_addr, - sizeof (ip4_address_t)); - face->shared.sw_if = sw_if; - face->shared.flags = flags; - face->shared.adj = adj; - - dpo_proto = DPO_PROTO_IP4; - - mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) in_faces, - 0); - - /* 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; - } - } - } - else - { - face = - hicn_face_ip6_get (&(remote_addr->ip6), sw_if, - &hicn_face_ip_remote_hashtb); - - /* If remote matches the face is a iface */ - if (face == NULL) - { - hicn_iface_ip_add (local_addr, remote_addr, sw_if, pfaceid); - face = hicn_dpoi_get_from_idx (*pfaceid); - } - else - { - *pfaceid = hicn_dpoi_get_index (face); - } - - if (!(face->shared.flags & HICN_FACE_FLAGS_IFACE)) - return HICN_ERROR_FACE_ALREADY_CREATED; - - hicn_face_ip_key_t key; - hicn_face_ip6_get_key (&(local_addr->ip6), sw_if, &key); - - hicn_face_ip_input_faces_t *in_faces = - hicn_face_ip6_get_vec (&(local_addr->ip6), sw_if, - &hicn_face_ip_local_hashtb); - - if (in_faces == NULL) - { - adj_index_t adj; - int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj); - if (ret != HICN_ERROR_NONE) - return ret; - - hicn_face_ip_input_faces_t in_faces_temp; - hicn_face_ip_vec_t *vec; - pool_get (hicn_vec_pool, vec); - vec_alloc (*vec, 1); - u32 index = vec - hicn_vec_pool; - in_faces_temp.vec_id = index; - vec_add1 (*vec, *pfaceid); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - clib_memcpy (&ip_face->local_addr, local_addr, - sizeof (ip6_address_t)); - clib_memcpy (&ip_face->remote_addr, remote_addr, - sizeof (ip6_address_t)); - face->shared.sw_if = sw_if; - face->shared.flags = flags; - face->shared.adj = adj; - - dpo_proto = DPO_PROTO_IP6; - - in_faces_temp.face_id = *pfaceid; - - mhash_set_mem (&hicn_face_ip_local_hashtb, &key, - (uword *) & in_faces_temp, 0); - } - else - { - hicn_face_ip_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; - - adj_index_t adj; - int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj); - if (ret != HICN_ERROR_NONE) - return ret; - - vec_add1 (*vec, *pfaceid); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - clib_memcpy (&ip_face->local_addr, local_addr, - sizeof (ip6_address_t)); - clib_memcpy (&ip_face->remote_addr, remote_addr, - sizeof (ip6_address_t)); - face->shared.sw_if = sw_if; - face->shared.flags = flags; - face->shared.adj = adj; - - dpo_proto = DPO_PROTO_IP6; - - mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) in_faces, - 0); - - /* 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) - { - .prefix = 0, - .dpo = (dpo_id_t) - { - .dpoi_type = hicn_face_ip_type, - .dpoi_proto = dpo_proto, - .dpoi_next_node = 0, - .dpoi_index = *pfaceid, - } - }; - /* *INDENT-ON* */ - - return HICN_ERROR_NONE; -} - -u8 * -format_hicn_face_ip (u8 * s, va_list * args) -{ - index_t index = va_arg (*args, index_t); - CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - hicn_face_t *face; - hicn_face_ip_t *ip_face; - ip_adjacency_t *adj; - vnet_main_t *vnm = vnet_get_main (); - - face = hicn_dpoi_get_from_idx (index); - ip_face = (hicn_face_ip_t *) face->data; - - if (face->shared.flags & HICN_FACE_FLAGS_FACE) - { - ASSERT (face->shared.adj != (adj_index_t) ~ 0); - adj = adj_get (face->shared.adj); - - hicn_face_id_t face_id = hicn_dpoi_get_index (face); - s = format (s, "%U Face %d: ", format_white_space, indent, face_id); - s = format (s, "type IP local %U ", - format_ip46_address, &ip_face->local_addr, IP46_TYPE_ANY); - s = - format (s, "remote %U ", format_ip46_address, &ip_face->remote_addr, - IP46_TYPE_ANY); - s = format (s, "%U", format_vnet_link, adj->ia_link); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, sw_int); - - - if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD)) - s = format (s, " %U", format_hicn_face_prod, face_id, 0); - else if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS)) - s = format (s, " %U", format_hicn_face_cons, face_id, 0); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - else - { - hicn_face_id_t face_id = hicn_dpoi_get_index (face); - s = format (s, "%U iFace %d: ", format_white_space, indent, face_id); - s = format (s, "type IP local %U remote %U", - format_ip46_address, &ip_face->local_addr, IP46_TYPE_ANY, - format_ip46_address, &ip_face->remote_addr, IP46_TYPE_ANY); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, sw_int); - - if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD)) - s = format (s, " %U", format_hicn_face_prod, face_id, 0); - else if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS)) - s = format (s, " %U", format_hicn_face_cons, face_id, 0); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - - return s; -} - -void -hicn_face_ip_get_dpo (hicn_face_t * face, dpo_id_t * dpo) -{ - - hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - return hicn_dpo_ip_create_from_face (face, dpo, - ip46_address_is_ip4 - (&face_ip->remote_addr) ? - strategy_face_ip4_vlib_edge : - strategy_face_ip6_vlib_edge); -} - -hicn_face_vft_t ip_vft = { - .format_face = format_hicn_face_ip, - .hicn_face_del = hicn_face_ip_del, - .hicn_face_get_dpo = hicn_face_ip_get_dpo, -}; - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip.h b/hicn-plugin/src/faces/ip/face_ip.h deleted file mode 100644 index 74f3a83dc..000000000 --- a/hicn-plugin/src/faces/ip/face_ip.h +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_IP_H__ -#define __HICN_FACE_IP_H__ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> -#include "../face.h" -#include "../../cache_policies/cs_policy.h" - -/** - * @file - * - * @brief IP face - * - * A face is carried through nodes as a dpo. The face state is the object - * pointed by the dpoi_index in the dpo_id_t (see - * https://docs.fd.io/vpp/18.07/d0/d37/dpo_8h_source.html) - */ -typedef struct hicn_ip_face_t_ -{ - /** - * The headers to paint, in packet painting order - */ - /* Local address of the interface sw_if */ - ip46_address_t local_addr; - - /* Remote address of neighbor */ - ip46_address_t remote_addr; - -} hicn_face_ip_t; - -/** - * @bried vector of faces used to collect faces having the same local address - * - */ -typedef hicn_face_id_t *hicn_face_ip_vec_t; - -typedef struct hicn_ip_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 */ - /* and the application. */ - hicn_face_id_t face_id; - -} hicn_face_ip_input_faces_t; - -/** - * Hash tables that indexes a face by local address. For fast lookup when an - * data arrives. - */ -extern mhash_t hicn_face_ip_local_hashtb; - -/** - * Hash tables that indexes a face by remote address. For fast lookup when an - * interest arrives. - */ -extern mhash_t hicn_face_ip_remote_hashtb; - -/** - * Pool containing the vector of possible incoming faces. - */ -extern hicn_face_ip_vec_t *hicn_vec_pool; - -/** - * Key definition for the mhash table. An ip face is uniquely identified by ip - * address and the interface id. 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. - */ -typedef struct hicn_face_ip_key_s -{ - ip46_address_t addr; - u32 sw_if; -} hicn_face_ip_key_t; - - -extern hicn_face_type_t hicn_face_ip_type; -extern hicn_face_vft_t ip_vft; - -/** - * @brief Create the key object for the mhash. Fill in the key object with the - * expected values. - * - * @param addr Local or remote ip v6 address of the face - * @param sw_if interface associated to the face - * @param key Pointer to an allocated hicn_face_ip_key_t object - */ -always_inline void -hicn_face_ip6_get_key (const ip6_address_t * addr, - u32 sw_if, hicn_face_ip_key_t * key) -{ - key->addr.ip6 = *addr; - key->sw_if = sw_if; -} - - -/** - * @brief Create the key object for the mhash. Fill in the key object with the - * expected values. - * - * @param addr Local or remote ip v4 address of the face - * @param sw_if interface associated to the face - * @param key Pointer to an allocated hicn_face_ip_key_t object - */ -always_inline void -hicn_face_ip4_get_key (const ip4_address_t * addr, - u32 sw_if, hicn_face_ip_key_t * key) -{ - ip46_address_set_ip4 (&(key->addr), addr); - key->sw_if = sw_if; -} - -/** - * @brief Get the dpoi 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_t * -hicn_face_ip4_get (const ip4_address_t * addr, u32 sw_if, mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip4_get_key (addr, sw_if, &key); - - hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, - &key); - - return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index); -} - -/** - * @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_ip_input_faces_t * -hicn_face_ip4_get_vec (const ip4_address_t * addr, u32 sw_if, - mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip4_get_key (addr, sw_if, &key); - return (hicn_face_ip_input_faces_t *) mhash_get (hashtb, &key); -} - -/** - * @brief Get the vector of faces from the ip v6 address. Does not add any lock. - * - * @param addr Ip v6 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_ip_input_faces_t * -hicn_face_ip6_get_vec (const ip6_address_t * addr, u32 sw_if, - mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip6_get_key (addr, sw_if, &key); - return (hicn_face_ip_input_faces_t *) mhash_get (hashtb, &key); -} - -/** - * @brief Get the dpoi from the ip v6 address. Does not add any lock. - * - * @param addr Ip v6 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_t * -hicn_face_ip6_get (const ip6_address_t * addr, u32 sw_if, mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip6_get_key (addr, sw_if, &key); - - hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, - &key); - - return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index); -} - -/** - * @brief Create a new face ip. API for other modules (e.g., routing) - * - * @param local_addr Local ip v4 or v6 address of the face - * @param remote_addr Remote ip v4 or v6 address of the face - * @param sw_if interface associated to the face - * @param is_app_face Boolean to set the face as an application 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 - * @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_ip_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, - int swif, hicn_face_id_t * pfaceid, u8 is_app_prod); - -/** - * @brief Create a new incomplete face ip. (Meant to be used by the data plane) - * - * @param local_addr Local ip v4 or v6 address of the face - * @param remote_addr Remote ip v4 or v6 address of the face - * @param sw_if interface associated to the face - * @param pfaceid Pointer to return the face id - * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally - * reachable ip address, otherwise HICN_ERROR_NONE - */ -always_inline void -hicn_iface_ip_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, - int sw_if, hicn_face_id_t * pfaceid) -{ - hicn_face_t *face; - pool_get (hicn_dpoi_face_pool, face); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) (face->data); - - clib_memcpy (&(ip_face->local_addr.ip6), local_addr, - sizeof (ip6_address_t)); - clib_memcpy (&(ip_face->remote_addr.ip6), remote_addr, - sizeof (ip6_address_t)); - face->shared.sw_if = sw_if; - - face->shared.adj = ADJ_INDEX_INVALID; - face->shared.pl_id = (u16) 0; - face->shared.face_type = hicn_face_ip_type; - face->shared.flags = HICN_FACE_FLAGS_IFACE; - face->shared.locks = 1; - - hicn_face_ip_key_t key; - hicn_face_ip6_get_key (&(remote_addr->ip6), sw_if, &key); - *pfaceid = hicn_dpoi_get_index (face); - - mhash_set_mem (&hicn_face_ip_remote_hashtb, &key, (uword *) pfaceid, 0); - - for (int i = 0; i < HICN_N_COUNTER; i++) - { - vlib_validate_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], - i); - vlib_zero_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], i); - } -} - -/** - * @brief Delete an ip 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_ip_del (hicn_face_id_t face_id); - -/** - * @brief Format a IP face - * - * @param s Pointer to a previous string. If null it will be initialize - * @param args Array storing input values. Expected u32 face_id and u32 indent - * @return String with the formatted face - */ -u8 *format_hicn_face_ip (u8 * s, va_list * args); - -/** - * @brief Create a dpo from an ip face - * - * @param face Face from which to create the dpo - * @return the dpo - */ -void hicn_face_ip_get_dpo (hicn_face_t * face, dpo_id_t * dpo); - -#endif // __HICN_FACE_IP_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip_cli.c b/hicn-plugin/src/faces/ip/face_ip_cli.c deleted file mode 100644 index 4c4986f97..000000000 --- a/hicn-plugin/src/faces/ip/face_ip_cli.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ - -#include <vnet/vnet.h> -#include <vnet/dpo/dpo.h> -#include <vlib/vlib.h> - -#include "face_ip.h" -#include "dpo_ip.h" -#include "../face.h" - -#define HICN_FACE_NONE 0 -#define HICN_FACE_DELETE 1 -#define HICN_FACE_ADD 2 - -static clib_error_t * -hicn_face_ip_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 (); - ip46_address_t local_addr; - ip46_address_t remote_addr; - hicn_face_id_t face_id = HICN_FACE_NULL; - int ret = HICN_ERROR_NONE; - int sw_if; - int face_op = HICN_FACE_NONE; - - ip46_address_reset (&local_addr); - /* Get a line of input. */ - unformat_input_t _line_input, *line_input = &_line_input; - if (!unformat_user (main_input, unformat_line_input, line_input)) - { - return (0); - } - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - { - if (unformat (line_input, "id %d", &face_id)) - face_op = HICN_FACE_DELETE; - else - { - return clib_error_return (0, "missing face id"); - } - } - else if (unformat (line_input, "add")) - { - face_op = HICN_FACE_ADD; - if (unformat (line_input, "local %U", - unformat_ip46_address, &local_addr, IP46_TYPE_ANY)); - - if (unformat (line_input, "remote %U intfc %U", - unformat_ip46_address, &remote_addr, - IP46_TYPE_ANY, unformat_vnet_sw_interface, vnm, - &sw_if)); - else - { - return clib_error_return (0, "%s '%U'", - get_error_string - (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); - } - } - else - { - return clib_error_return (0, "%s '%U'", - get_error_string (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); - } - } - - if (face_id != HICN_FACE_NULL) - { - - if (!hicn_dpoi_idx_is_valid (face_id)) - { - return clib_error_return (0, "%s, face_id %d not valid", - get_error_string (ret), face_id); - } - } - - int rv; - switch (face_op) - { - case HICN_FACE_ADD: - - /* Check for presence of next hop address */ - if ((remote_addr.as_u64[0] == (u64) 0) - && (remote_addr.as_u64[1] == (u64) 0)) - { - return clib_error_return (0, "next hop address not specified"); - } - - if (ip46_address_is_zero (&local_addr)) - { - if (!vnet_sw_interface_is_valid (vnm, sw_if)) - return clib_error_return (0, "interface not valid"); - - if (ip46_address_is_ip4 (&remote_addr)) - { - ip_interface_address_t *interface_address; - ip4_address_t *addr = - ip4_interface_address_matching_destination (&ip4_main, - &remote_addr.ip4, - sw_if, - &interface_address); - - if (addr == NULL) - addr = ip4_interface_first_address (&ip4_main, - sw_if, - &interface_address); - - if (addr == NULL) - return clib_error_return (0, - "no valid ip address on interface %d", - sw_if); - - ip46_address_set_ip4 (&local_addr, addr); - } - else - { - ip_interface_address_t *interface_address; - ip6_interface_address_matching_destination (&ip6_main, - &remote_addr.ip6, - sw_if, - &interface_address); - - ip6_address_t *addr = NULL; - if (interface_address != NULL) - addr = - (ip6_address_t *) - ip_interface_address_get_address (&ip6_main.lookup_main, - interface_address); - - if (addr == NULL) - addr = ip6_interface_first_address (&ip6_main, sw_if); - - if (addr == NULL) - return clib_error_return (0, - "no valid ip address on interface %d", - sw_if); - - ip46_address_set_ip6 (&local_addr, addr); - } - } - - rv = hicn_face_ip_add (&local_addr, &remote_addr, sw_if, &face_id, 0); - - if (rv == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Face id: %d", face_id); - } - else - { - return clib_error_return (0, get_error_string (rv)); - } - break; - case HICN_FACE_DELETE: - rv = hicn_face_ip_del (face_id); - if (rv == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Face %d deleted", face_id); - } - else - { - return clib_error_return (0, get_error_string (rv)); - } - break; - default: - 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)); -} - -/* cli declaration for 'cfg face' */ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (hicn_face_ip_cli_set_command, static) = -{ - .path = "hicn face ip", - .short_help = "hicn face ip {add [local <src_address>] remote <dst_address> intfc <sw_if>} | {del id <face_id>}", - .function = hicn_face_ip_cli_set_command_fn, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip_node.c b/hicn-plugin/src/faces/ip/face_ip_node.c deleted file mode 100644 index 0eeeab6fb..000000000 --- a/hicn-plugin/src/faces/ip/face_ip_node.c +++ /dev/null @@ -1,993 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ - -#include <vnet/adj/adj.h> - -#include "face_ip.h" -#include "face_ip_node.h" -#include "dpo_ip.h" -#include "../app/face_prod.h" -#include "../../strategy_dpo_manager.h" -#include "../face.h" -#include "../../cache_policies/cs_lru.h" -#include "../../infra.h" -#include "../../hicn.h" - -/** - * @File - * - * Definition of the nodes for ip incomplete faces. - */ - -vlib_node_registration_t hicn_face_ip4_input_node; -vlib_node_registration_t hicn_face_ip4_output_node; -vlib_node_registration_t hicn_face_ip6_input_node; -vlib_node_registration_t hicn_face_ip6_output_node; - -#define ip_v4 4 -#define ip_v6 6 - -static char *hicn_face_ip4_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_face_ip6_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_ip4_input_trace_t; - -typedef enum -{ - HICN_FACE_IP4_INPUT_NEXT_DATA, - HICN_FACE_IP4_INPUT_NEXT_MAPME, - HICN_FACE_IP4_INPUT_NEXT_ERROR_DROP, - HICN_FACE_IP4_INPUT_N_NEXT, -} hicn_face_ip4_input_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_ip6_input_trace_t; - -typedef enum -{ - HICN_FACE_IP6_INPUT_NEXT_DATA, - HICN_FACE_IP6_INPUT_NEXT_MAPME, - HICN_FACE_IP6_INPUT_NEXT_ERROR_DROP, - HICN_FACE_IP6_INPUT_N_NEXT, -} hicn_face_ip6_input_next_t; - -#define NEXT_MAPME_IP4 HICN_FACE_IP4_INPUT_NEXT_MAPME -#define NEXT_MAPME_IP6 HICN_FACE_IP6_INPUT_NEXT_MAPME -#define NEXT_DATA_IP4 HICN_FACE_IP4_INPUT_NEXT_DATA -#define NEXT_DATA_IP6 HICN_FACE_IP6_INPUT_NEXT_DATA - -#define NEXT_ERROR_DROP_IP4 HICN_FACE_IP4_INPUT_NEXT_ERROR_DROP -#define NEXT_ERROR_DROP_IP6 HICN_FACE_IP6_INPUT_NEXT_ERROR_DROP - -#define IP_HEADER_4 ip4_header_t -#define IP_HEADER_6 ip6_header_t - -#define LOCK_FROM_LOCAL_IP4 hicn_dpo_ip4_lock_from_local -#define LOCK_FROM_LOCAL_IP6 hicn_dpo_ip6_lock_from_local - -#define TRACE_INPUT_PKT_IP4 hicn_face_ip4_input_trace_t -#define TRACE_INPUT_PKT_IP6 hicn_face_ip6_input_trace_t - -/* - * NOTE: Both hicn_face_ip4_input_node_fn and hicn_face_ip6_input_node_fn - * present a similar codebase. Macro are hard to debug, although the - * 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_FROM_LOCAL_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &(hicnb0->in_faces_vec_id), \ - &hicnb0->flags, \ - &(ip_hdr->dst_address), \ - vnet_buffer (b0)->sw_if_index[VLIB_RX]); \ - \ - if ( PREDICT_FALSE(ret != HICN_ERROR_NONE) ) \ - next0 = NEXT_ERROR_DROP_IP##ipv; \ - else \ - { \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * 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_FROM_LOCAL_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &(hicnb0->in_faces_vec_id), \ - &hicnb0->flags, \ - &(ip_hdr0->dst_address), \ - vnet_buffer (b0)->sw_if_index[VLIB_RX]); \ - \ - ret1 = LOCK_FROM_LOCAL_IP##ipv \ - (&(hicnb1->face_dpo_id), \ - &(hicnb1->in_faces_vec_id), \ - &hicnb1->flags, \ - &(ip_hdr1->dst_address), \ - vnet_buffer (b1)->sw_if_index[VLIB_RX]); \ - \ - if ( PREDICT_FALSE(ret0 != HICN_ERROR_NONE) ) \ - next0 = NEXT_ERROR_DROP_IP##ipv; \ - else \ - { \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * 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_dpo_id.dpoi_index \ - * 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) - - -static uword -hicn_face_ip4_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; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_input_x2 (4); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_input_x1 (4); - } - 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); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_ip4_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 *); - hicn_face_ip4_input_trace_t *t = - va_arg (*args, hicn_face_ip4_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, - format_ip4_header, t->packet_data, sizeof (t->packet_data)); - return (s); -} - - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip4_input_node) = -{ - .function = hicn_face_ip4_input_node_fn, - .name = "hicn-face-ip4-input", - .vector_size = sizeof(u32), - .format_trace = hicn_face_ip4_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip4_input_error_strings), - .error_strings = hicn_face_ip4_input_error_strings, - .n_next_nodes = HICN_FACE_IP4_INPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_FACE_IP4_INPUT_NEXT_DATA] = "hicn-data-pcslookup", - [HICN_FACE_IP4_INPUT_NEXT_MAPME] = "hicn-mapme-ack", - [HICN_FACE_IP4_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -/** - * @brief IPv6 face input node function - * @see hicn_face_ip4_input_node_fn - */ -static uword -hicn_face_ip6_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; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_input_x2 (6); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_input_x1 (6); - } - 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); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_ip6_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 *); - hicn_face_ip6_input_trace_t *t = - va_arg (*args, hicn_face_ip6_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, - format_ip6_header, t->packet_data, sizeof (t->packet_data)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip6_input_node) = -{ - .function = hicn_face_ip6_input_node_fn, - .name = "hicn-face-ip6-input", - .vector_size = sizeof(u32), - .format_trace = hicn_face_ip6_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip6_input_error_strings), - .error_strings = hicn_face_ip6_input_error_strings, - .n_next_nodes = HICN_FACE_IP6_INPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_FACE_IP6_INPUT_NEXT_DATA] = "hicn-data-pcslookup", - [HICN_FACE_IP6_INPUT_NEXT_MAPME] = "hicn-mapme-ack", - [HICN_FACE_IP6_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -/**** FACE OUTPUT *****/ - -typedef enum -{ - HICN_FACE_IP4_NEXT_ECHO_REPLY = IP4_LOOKUP_N_NEXT, - HICN_FACE_IP4_N_NEXT, -} hicn_face_ip4_next_t; - -typedef enum -{ - HICN_FACE_IP6_NEXT_ECHO_REPLY = IP6_LOOKUP_N_NEXT, - HICN_FACE_IP6_N_NEXT, -} hicn_face_ip6_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 = HICN_FACE_IP4_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 = HICN_FACE_IP6_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) -{ - - if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) && hicn_face_match_probe(b0, face, next)) - return; - - hicn_header_t *hicn = vlib_buffer_get_current (b0); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - - ip46_address_t temp_addr; - ip46_address_reset (&temp_addr); - hicn_type_t type = hicn_get_buffer (b0)->type; - hicn_ops_vft[type.l1]->rewrite_interest (type, &hicn->protocol, - &ip_face->local_addr, &temp_addr); - - int is_iface = 0; - ip_adjacency_t *adj; - if (PREDICT_FALSE (face->shared.adj == ~0)) - is_iface = 1; - else - adj = adj_get (face->shared.adj); - - /* In case the adj is not complete, we look if a better one exists, otherwise we send an arp request - * This is necessary to account for the case in which when we create a face, there isn't a /128(/32) adjacency and we match with a more general route which is in glean state - * In this case in fact, the general route will not be update upone receiving of a arp or neighbour responde, but a new /128(/32) will be created - */ - if (PREDICT_FALSE - (is_iface || adj->lookup_next_index < IP_LOOKUP_NEXT_REWRITE)) - { - fib_prefix_t fib_pfx; - fib_node_index_t fib_entry_index; - fib_prefix_from_ip46_addr (&ip_face->remote_addr, &fib_pfx); - fib_pfx.fp_len = ip46_address_is_ip4(&ip_face->remote_addr)? 32 : 128; - - u32 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 (fib_index, &fib_pfx); - - face->shared.adj = fib_entry_get_adj (fib_entry_index); - face->shared.flags &= ~HICN_FACE_FLAGS_IFACE; - face->shared.flags |= HICN_FACE_FLAGS_FACE; - - adj = adj_get (face->shared.adj); - - hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &ip_face->remote_addr, &temp_addr, - 0); - } - - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = face->shared.adj; - *next = adj->lookup_next_index; - - -} - -static char *hicn_face_ip4_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_face_ip6_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_ip4_output_trace_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_ip6_output_trace_t; - -#define TRACE_OUTPUT_PKT_IP4 hicn_face_ip4_output_trace_t -#define TRACE_OUTPUT_PKT_IP6 hicn_face_ip6_output_trace_t - -#define face_output_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = IP_LOOKUP_NEXT_DROP; \ - 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 = IP_LOOKUP_NEXT_DROP; \ - u32 next1 = IP_LOOKUP_NEXT_DROP; \ - 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) - - -static uword -hicn_face_ip4_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 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_output_x2 (4); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_output_x1 (4); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_ip4_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 *); - hicn_face_ip4_output_trace_t *t = - va_arg (*args, hicn_face_ip4_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)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip4_output_node) = -{ - .function = hicn_face_ip4_output_node_fn, - .name = "hicn-face-ip4-output", - .vector_size = sizeof(u32), - .format_trace = hicn_face_ip4_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip4_output_error_strings), - .error_strings = hicn_face_ip4_output_error_strings, - .n_next_nodes = HICN_FACE_IP4_N_NEXT, - /* Reusing the list of nodes from lookup to be compatible with arp */ - .next_nodes = - { - [IP_LOOKUP_NEXT_DROP] = "ip4-drop", - [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", - [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", - [IP_LOOKUP_NEXT_ARP] = "ip4-arp", - [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", - [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", - [IP_LOOKUP_NEXT_MCAST] = "ip4-rewrite-mcast", - [IP_LOOKUP_NEXT_BCAST] = "ip4-rewrite-bcast", - [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", - [IP_LOOKUP_NEXT_MCAST_MIDCHAIN] = "ip4-mcast-midchain", - [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", - [HICN_FACE_IP4_NEXT_ECHO_REPLY] = "hicn-face-ip4-input", - } -}; -/* *INDENT-ON* */ - - -static uword -hicn_face_ip6_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 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_output_x2 (6); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_output_x1 (6); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_ip6_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 *); - hicn_face_ip6_output_trace_t *t = - va_arg (*args, hicn_face_ip6_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)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip6_output_node) = -{ - .function = hicn_face_ip6_output_node_fn, - .name = "hicn-face-ip6-output", - .vector_size = sizeof(u32), - .format_trace = hicn_face_ip6_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip6_output_error_strings), - .error_strings = hicn_face_ip6_output_error_strings, - .n_next_nodes = HICN_FACE_IP6_N_NEXT, - /* Reusing the list of nodes from lookup to be compatible with neighbour discovery */ - .next_nodes = - { - [IP_LOOKUP_NEXT_DROP] = "ip6-drop", - [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", - [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", - [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", - [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", - [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", - [IP_LOOKUP_NEXT_BCAST] = "ip6-rewrite-bcast", - [IP_LOOKUP_NEXT_MCAST] = "ip6-rewrite-mcast", - [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", - [IP_LOOKUP_NEXT_MCAST_MIDCHAIN] = "ip6-mcast-midchain", - [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", - [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", - [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", - [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", - [HICN_FACE_IP6_NEXT_ECHO_REPLY] = "hicn-face-ip6-input" - } -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip_node.h b/hicn-plugin/src/faces/ip/face_ip_node.h deleted file mode 100644 index 000395a04..000000000 --- a/hicn-plugin/src/faces/ip/face_ip_node.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_IP_NODE_H__ -#define __HICN_FACE_IP_NODE_H__ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> - -extern vlib_node_registration_t hicn_face_ip4_input_node; -extern vlib_node_registration_t hicn_face_ip4_output_node; -extern vlib_node_registration_t hicn_face_ip6_input_node; -extern vlib_node_registration_t hicn_face_ip6_output_node; - -/** - * @brief Initialize the ip face module - */ -void hicn_face_ip_init (vlib_main_t * vm); - -#endif // __HICN_FACE_IP_NODE_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/iface_ip_node.c b/hicn-plugin/src/faces/ip/iface_ip_node.c deleted file mode 100644 index 8adef50d9..000000000 --- a/hicn-plugin/src/faces/ip/iface_ip_node.c +++ /dev/null @@ -1,919 +0,0 @@ -/* - * Copyright (c) 2017-2019 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. - */ - -#include "face_ip.h" -#include "dpo_ip.h" -#include "../../strategy_dpo_manager.h" -#include "../face.h" -#include "../../hicn.h" -#include "../../infra.h" -#include "../../cache_policies/cs_lru.h" - -/** - * @File - * - * Definition of the nodes for ip incomplete faces. - */ - -vlib_node_registration_t hicn_iface_ip4_input_node; -vlib_node_registration_t hicn_iface_ip4_output_node; -vlib_node_registration_t hicn_iface_ip6_input_node; -vlib_node_registration_t hicn_iface_ip6_output_node; - -u32 data_fwd_iface_ip4_vlib_edge; -u32 data_fwd_iface_ip6_vlib_edge; - -void -hicn_iface_ip_init (vlib_main_t * vm) -{ - u32 temp_index4 = vlib_node_add_next (vm, - hicn_interest_hitcs_node.index, - hicn_iface_ip4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - hicn_interest_hitcs_node.index, - hicn_iface_ip6_output_node.index); - - data_fwd_iface_ip4_vlib_edge = vlib_node_add_next (vm, - hicn_data_fwd_node.index, - hicn_iface_ip4_output_node.index); - - data_fwd_iface_ip6_vlib_edge = vlib_node_add_next (vm, - hicn_data_fwd_node.index, - hicn_iface_ip6_output_node.index); - - ASSERT (temp_index4 == data_fwd_iface_ip4_vlib_edge); - ASSERT (temp_index6 == data_fwd_iface_ip6_vlib_edge); -} - -static char *hicn_iface_ip4_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_iface_ip6_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} hicn_iface_ip4_input_trace_t; - -typedef enum -{ - HICN_IFACE_IP4_INPUT_NEXT_INTEREST, - HICN_IFACE_IP4_INPUT_NEXT_MAPME, - HICN_IFACE_IP4_INPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP4_INPUT_N_NEXT, -} hicn_iface_ip4_input_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} hicn_iface_ip6_input_trace_t; - -typedef enum -{ - HICN_IFACE_IP6_INPUT_NEXT_INTEREST, - HICN_IFACE_IP6_INPUT_NEXT_MAPME, - HICN_IFACE_IP6_INPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP6_INPUT_N_NEXT, -} hicn_iface_ip6_input_next_t; - -#define NEXT_MAPME_IP4 HICN_IFACE_IP4_INPUT_NEXT_MAPME -#define NEXT_MAPME_IP6 HICN_IFACE_IP6_INPUT_NEXT_MAPME - -#define NEXT_INTEREST_IP4 HICN_IFACE_IP6_INPUT_NEXT_INTEREST -#define NEXT_INTEREST_IP6 HICN_IFACE_IP6_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_IP4 hicn_dpo_ip4_add_and_lock_from_remote -#define DPO_ADD_LOCK_IP6 hicn_dpo_ip6_add_and_lock_from_remote - -#define VLIB_EDGE_IP4 data_fwd_iface_ip4_vlib_edge -#define VLIB_EDGE_IP6 data_fwd_iface_ip6_vlib_edge - -#define IP_HEADER_4 ip4_header_t -#define IP_HEADER_6 ip6_header_t - -#define TRACE_INPUT_PKT_IP4 hicn_iface_ip4_input_trace_t -#define TRACE_INPUT_PKT_IP6 hicn_iface_ip6_input_trace_t - -#define iface_input_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0, next0; \ - IP_HEADER_##ipv * ip_hdr = NULL; \ - hicn_buffer_t * hicnb0; \ - u32 swif; \ - /* 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; \ - \ - swif = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - \ - ADDRESS_IP##ipv; \ - \ - DPO_ADD_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &hicnb0->flags, \ - local_address, \ - &(ip_hdr->src_address), \ - vnet_buffer(b0)->sw_if_index[VLIB_RX], \ - VLIB_EDGE_IP##ipv); \ - \ - 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_dpo_id.dpoi_index \ - * 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; \ - IP_HEADER_##ipv * ip_hdr0 = NULL; \ - IP_HEADER_##ipv * ip_hdr1 = NULL; \ - hicn_buffer_t *hicnb0, *hicnb1; \ - u32 swif0, swif1; \ - \ - /* 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; \ - \ - swif0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - swif1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - \ - ADDRESSX2_IP##ipv; \ - \ - DPO_ADD_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &hicnb0->flags, \ - local_address0, \ - &(ip_hdr0->src_address), \ - vnet_buffer(b0)->sw_if_index[VLIB_RX], \ - VLIB_EDGE_IP##ipv); \ - \ - DPO_ADD_LOCK_IP##ipv \ - (&(hicnb1->face_dpo_id), \ - &hicnb1->flags, \ - local_address1, \ - &(ip_hdr1->src_address), \ - vnet_buffer(b1)->sw_if_index[VLIB_RX], \ - VLIB_EDGE_IP##ipv); \ - \ - 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_dpo_id.dpoi_index \ - * 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_dpo_id.dpoi_index \ - * 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 -hicn_iface_ip4_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; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_input_x2 (4); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_input_x1 (4); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_ip4_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 *); - hicn_iface_ip4_input_trace_t *t = - va_arg (*args, hicn_iface_ip4_input_trace_t *); - - 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 (hicn_iface_ip4_input_node) = -{ - .function = hicn_iface_ip4_input_node_fn, - .name = "hicn-iface-ip4-input", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip4_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip4_input_error_strings), - .error_strings = hicn_iface_ip4_input_error_strings, - .n_next_nodes = HICN_IFACE_IP4_INPUT_N_NEXT, - /* edit / add dispositions*/ - .next_nodes = - { - [HICN_IFACE_IP4_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", - [HICN_IFACE_IP4_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", - [HICN_IFACE_IP4_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -static uword -hicn_iface_ip6_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; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_input_x2 (6); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_input_x1 (6); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_ip6_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 *); - hicn_iface_ip6_input_trace_t *t = - va_arg (*args, hicn_iface_ip6_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)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip6_input_node) = -{ - .function = hicn_iface_ip6_input_node_fn, - .name = "hicn-iface-ip6-input", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip6_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip6_input_error_strings), - .error_strings = hicn_iface_ip6_input_error_strings, - .n_next_nodes = HICN_IFACE_IP6_INPUT_N_NEXT, - /* edit / add dispositions*/ - .next_nodes = - { - [HICN_IFACE_IP6_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", - [HICN_IFACE_IP6_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", - [HICN_IFACE_IP6_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) -{ - ip4_header_t *ip0; - - /* Get the pointer to the old ip and tcp header */ - ip0 = vlib_buffer_get_current (b0); - - /* Set up the ip6 header */ - /* 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 - - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ~0; - hicn_header_t *hicn = vlib_buffer_get_current (b0); - - ip46_address_t temp_addr; - ip46_address_reset (&temp_addr); - hicn_face_ip_t *iface_ip = (hicn_face_ip_t *) iface->data; - hicn_type_t type = hicn_get_buffer (b0)->type; - hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &(iface_ip->remote_addr), &(temp_addr), - iface->shared.pl_id); -} - -static inline void -hicn_rewrite_iface_data6 (vlib_main_t * vm, vlib_buffer_t * b0, - const hicn_face_t * iface) -{ - ip6_header_t *ip0; - - /* Get the pointer to the old ip and tcp header */ - /* Copy the previous ip and tcp header to the new portion of memory */ - ip0 = vlib_buffer_get_current (b0); - - /* Set up the ip6 header */ - /* IP6 lenght does not include the size of the ip6 header */ - u16 sval = (vlib_buffer_length_in_chain (vm, b0) - (sizeof (ip6_header_t))); - ip0->payload_length = clib_host_to_net_u16 (sval); - ip0->hop_limit = HICN_IP6_HOP_LIMIT; - - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ~0; - hicn_header_t *hicn = vlib_buffer_get_current (b0); - - ip46_address_t temp_addr; - ip46_address_reset (&temp_addr); - hicn_face_ip_t *iface_ip = (hicn_face_ip_t *) iface->data; - hicn_type_t type = hicn_get_buffer (b0)->type; - hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &(iface_ip->remote_addr), &(temp_addr), - iface->shared.pl_id); -} - -static char *hicn_iface_ip4_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_iface_ip6_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} hicn_iface_ip4_output_trace_t; - -typedef enum -{ - HICN_IFACE_IP4_OUTPUT_NEXT_LOOKUP, - HICN_IFACE_IP4_OUTPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP4_OUTPUT_N_NEXT, -} hicn_iface_ip4_output_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} hicn_iface_ip6_output_trace_t; - -typedef enum -{ - HICN_IFACE_IP6_OUTPUT_NEXT_LOOKUP, - HICN_IFACE_IP6_OUTPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP6_OUTPUT_N_NEXT, -} hicn_iface_ip6_output_next_t; - -#define ERROR_OUTPUT_IP4 HICN_IFACE_IP4_OUTPUT_NEXT_ERROR_DROP -#define ERROR_OUTPUT_IP6 HICN_IFACE_IP6_OUTPUT_NEXT_ERROR_DROP - -#define NEXT_DATA_LOOKUP_IP4 HICN_IFACE_IP4_OUTPUT_NEXT_LOOKUP -#define NEXT_DATA_LOOKUP_IP6 HICN_IFACE_IP6_OUTPUT_NEXT_LOOKUP - -#define HICN_REWRITE_DATA_IP4 hicn_rewrite_iface_data4 -#define HICN_REWRITE_DATA_IP6 hicn_rewrite_iface_data6 - -#define TRACE_OUTPUT_PKT_IP4 hicn_iface_ip4_output_trace_t -#define TRACE_OUTPUT_PKT_IP6 hicn_iface_ip6_output_trace_t - -#define iface_output_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = ERROR_OUTPUT_IP##ipv; \ - 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 = NEXT_DATA_LOOKUP_IP##ipv; \ - 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 = ERROR_OUTPUT_IP##ipv; \ - u32 next1 = ERROR_OUTPUT_IP##ipv; \ - 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 = NEXT_DATA_LOOKUP_IP##ipv; \ - 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 = NEXT_DATA_LOOKUP_IP##ipv; \ - 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); \ - - - -static uword -hicn_iface_ip4_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 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_output_x2 (4); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_output_x1 (4); - } - - 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); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_ip4_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 *); - hicn_iface_ip4_output_trace_t *t = - va_arg (*args, hicn_iface_ip4_output_trace_t *); - - s = - format (s, "IFACE_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)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip4_output_node) = -{ - .function = hicn_iface_ip4_output_node_fn, - .name = "hicn-iface-ip4-output", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip4_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip4_output_error_strings), - .error_strings = hicn_iface_ip4_output_error_strings, - .n_next_nodes = HICN_IFACE_IP4_OUTPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_IFACE_IP4_OUTPUT_NEXT_LOOKUP] = "ip4-lookup", - [HICN_IFACE_IP4_OUTPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - - -static uword -hicn_iface_ip6_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 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_output_x2 (6); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_output_x1 (6); - } - 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); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_ip6_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 *); - hicn_iface_ip6_output_trace_t *t = - va_arg (*args, hicn_iface_ip6_output_trace_t *); - - s = - format (s, "IFACE_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)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip6_output_node) = -{ - .function = hicn_iface_ip6_output_node_fn, - .name = "hicn-iface-ip6-output", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip6_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip6_output_error_strings), - .error_strings = hicn_iface_ip6_output_error_strings, - .n_next_nodes = HICN_IFACE_IP6_OUTPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_IFACE_IP6_OUTPUT_NEXT_LOOKUP] = "ip6-lookup", - [HICN_IFACE_IP6_OUTPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/iface_ip_node.h b/hicn-plugin/src/faces/ip/iface_ip_node.h deleted file mode 100644 index 36923f069..000000000 --- a/hicn-plugin/src/faces/ip/iface_ip_node.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_IFACE_IP_NODE_H__ -#define __HICN_IFACE_IP_NODE_H__ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> - -/** - * @brief Initialize the ip iface module - */ -void hicn_iface_ip_init (vlib_main_t * vm); - -#endif // __HICN_IFACE_IP_NODE_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ |