diff options
Diffstat (limited to 'hicn-plugin/src/data_fwd_node.c')
-rw-r--r-- | hicn-plugin/src/data_fwd_node.c | 243 |
1 files changed, 118 insertions, 125 deletions
diff --git a/hicn-plugin/src/data_fwd_node.c b/hicn-plugin/src/data_fwd_node.c index c65b62454..a91439662 100644 --- a/hicn-plugin/src/data_fwd_node.c +++ b/hicn-plugin/src/data_fwd_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 2017-2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -32,29 +32,26 @@ static char *hicn_data_fwd_error_strings[] = { }; /* Declarations */ -always_inline void -drop_packet (vlib_main_t * vm, u32 bi0, - u32 * n_left_to_next, u32 * next0, u32 ** to_next, - u32 * next_index, vlib_node_runtime_t * node); +always_inline void drop_packet (vlib_main_t *vm, u32 bi0, u32 *n_left_to_next, + u32 *next0, u32 **to_next, u32 *next_index, + vlib_node_runtime_t *node); always_inline int -hicn_satisfy_faces (vlib_main_t * vm, u32 b0, - hicn_pcs_entry_t * pitp, u32 * n_left_to_next, - u32 ** to_next, u32 * next_index, - vlib_node_runtime_t * node, u8 isv6, - vl_api_hicn_api_node_stats_get_reply_t * stats); +hicn_satisfy_faces (vlib_main_t *vm, u32 b0, hicn_pcs_entry_t *pitp, + u32 *n_left_to_next, u32 **to_next, u32 *next_index, + vlib_node_runtime_t *node, u8 isv6, + vl_api_hicn_api_node_stats_get_reply_t *stats); always_inline void -clone_data_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, - hicn_pcs_entry_t * pitp, hicn_header_t * hicn0, f64 tnow, - hicn_hash_node_t * nodep, vlib_buffer_t * b0, - hicn_hash_entry_t * hash_entry, u64 name_hash, - hicn_buffer_t * hicnb, const hicn_dpo_vft_t * dpo_vft, - dpo_id_t * hicn_dpo_id, hicn_lifetime_t dmsg_lifetime); - +clone_data_to_cs (vlib_main_t *vm, hicn_pit_cs_t *pitcs, + hicn_pcs_entry_t *pitp, hicn_header_t *hicn0, f64 tnow, + hicn_hash_node_t *nodep, vlib_buffer_t *b0, + hicn_hash_entry_t *hash_entry, u64 name_hash, + hicn_buffer_t *hicnb, const hicn_dpo_vft_t *dpo_vft, + dpo_id_t *hicn_dpo_id, hicn_lifetime_t dmsg_lifetime); /* packet trace format function */ -always_inline u8 *hicn_data_fwd_format_trace (u8 * s, va_list * args); +always_inline u8 *hicn_data_fwd_format_trace (u8 *s, va_list *args); vlib_node_registration_t hicn_data_fwd_node; @@ -63,8 +60,8 @@ vlib_node_registration_t hicn_data_fwd_node; * - 1 packet at a time - ipv4/tcp ipv6/tcp */ static uword -hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn_data_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame) { u32 n_left_from, *from, *to_next; @@ -134,20 +131,22 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, pitp = hicn_pit_get_data (node0); nameptr = (u8 *) (&name); - if (PREDICT_FALSE - (ret != HICN_ERROR_NONE - || !hicn_node_compare (nameptr, namelen, node0) - || (hash_entry0->he_flags & HICN_HASH_ENTRY_FLAG_CS_ENTRY))) + if (PREDICT_FALSE ( + ret != HICN_ERROR_NONE || + !hicn_node_compare (nameptr, namelen, node0) || + (hash_entry0->he_flags & HICN_HASH_ENTRY_FLAG_CS_ENTRY))) { /* * Remove the lock acquired from * data_pcslookup node */ - dpo_id_t hicn_dpo_id0 = { dpo_vft0->hicn_dpo_get_type (), 0, 0, - dpo_ctx_id0 - }; - hicn_pcs_remove_lock (pitcs, &pitp, &node0, vm, - hash_entry0, dpo_vft0, &hicn_dpo_id0); + dpo_id_t hicn_dpo_id0 = { .dpoi_type = + dpo_vft0->hicn_dpo_get_type (), + .dpoi_proto = 0, + .dpoi_next_node = 0, + .dpoi_index = dpo_ctx_id0 }; + hicn_pcs_remove_lock (pitcs, &pitp, &node0, vm, hash_entry0, + dpo_vft0, &hicn_dpo_id0); drop_packet (vm, bi0, &n_left_to_next, &next0, &to_next, &next_index, node); @@ -163,16 +162,19 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, * not changed from the lookup. */ - if (tnow > pitp->shared.expire_time - || (hash_entry0->he_flags & HICN_HASH_ENTRY_FLAG_DELETED)) + if (tnow > pitp->shared.expire_time || + (hash_entry0->he_flags & HICN_HASH_ENTRY_FLAG_DELETED)) { - dpo_id_t hicn_dpo_id0 = - { dpo_vft0->hicn_dpo_get_type (), 0, 0, dpo_ctx_id0 }; - hicn_pcs_delete (pitcs, &pitp, &node0, vm, hash_entry0, - dpo_vft0, &hicn_dpo_id0); + dpo_id_t hicn_dpo_id0 = { .dpoi_type = + dpo_vft0->hicn_dpo_get_type (), + .dpoi_proto = 0, + .dpoi_next_node = 0, + .dpoi_index = dpo_ctx_id0 }; + hicn_pcs_delete (pitcs, &pitp, &node0, vm, hash_entry0, dpo_vft0, + &hicn_dpo_id0); - drop_packet (vm, bi0, &n_left_to_next, &next0, &to_next, - &next_index, node); + drop_packet (vm, bi0, &n_left_to_next, &next0, &to_next, + &next_index, node); stats.pit_expired_count++; if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && @@ -183,15 +185,14 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, t->pkt_type = HICN_PKT_TYPE_CONTENT; t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; t->next_index = next0; - clib_memcpy (t->packet_data, - vlib_buffer_get_current (b0), + clib_memcpy (t->packet_data, vlib_buffer_get_current (b0), sizeof (t->packet_data)); } } else { - ASSERT ((hash_entry0->he_flags & HICN_HASH_ENTRY_FLAG_DELETED) - == 0); + ASSERT ((hash_entry0->he_flags & HICN_HASH_ENTRY_FLAG_DELETED) == + 0); data_received++; /* @@ -200,18 +201,20 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, */ /* Prepare the buffer for the cloning */ - ret = hicn_satisfy_faces (vm, bi0, pitp, &n_left_to_next, - &to_next, &next_index, node, - isv6, &stats); + ret = + hicn_satisfy_faces (vm, bi0, pitp, &n_left_to_next, &to_next, + &next_index, node, isv6, &stats); - dpo_id_t hicn_dpo_id0 = { dpo_vft0->hicn_dpo_get_type (), 0, 0, - dpo_ctx_id0 - }; + dpo_id_t hicn_dpo_id0 = { .dpoi_type = + dpo_vft0->hicn_dpo_get_type (), + .dpoi_proto = 0, + .dpoi_next_node = 0, + .dpoi_index = dpo_ctx_id0 }; if (PREDICT_FALSE (ret != HICN_ERROR_NONE)) { - hicn_pcs_pit_delete (pitcs, &pitp, &node0, vm, - hash_entry0, dpo_vft0, &hicn_dpo_id0); + hicn_pcs_pit_delete (pitcs, &pitp, &node0, vm, hash_entry0, + dpo_vft0, &hicn_dpo_id0); continue; } /* @@ -234,18 +237,18 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, * Clone data packet in the content store and * convert the PIT entry into a CS entry */ - clone_data_to_cs (vm, pitcs, pitp, hicn0, tnow, node0, - b0, hash_entry0, hicnb0->name_hash, - hicnb0, dpo_vft0, &hicn_dpo_id0, - dmsg_lifetime); + clone_data_to_cs (vm, pitcs, pitp, hicn0, tnow, node0, b0, + hash_entry0, hicnb0->name_hash, hicnb0, + dpo_vft0, &hicn_dpo_id0, dmsg_lifetime); - hicn_pcs_remove_lock (pitcs, &pitp, &node0, vm, - hash_entry0, NULL, NULL); + hicn_pcs_remove_lock (pitcs, &pitp, &node0, vm, hash_entry0, + NULL, NULL); } else { /* - * If the packet is copied and not cloned, we need to free the vlib_buffer + * If the packet is copied and not cloned, we need to free + * the vlib_buffer */ if (hicnb0->flags & HICN_BUFFER_FLAGS_PKT_LESS_TWO_CL) { @@ -255,20 +258,21 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, { /* * Remove one reference as the buffer is no - * longer in any frame. The vlib_buffer will be freed when - * all its cloned vlib_buffer will be freed. + * longer in any frame. The vlib_buffer will be freed + * when all its cloned vlib_buffer will be freed. */ b0->ref_count--; } /* Delete the PIT entry */ - hicn_pcs_pit_delete (pitcs, &pitp, &node0, vm, - hash_entry0, dpo_vft0, &hicn_dpo_id0); + hicn_pcs_pit_delete (pitcs, &pitp, &node0, vm, hash_entry0, + dpo_vft0, &hicn_dpo_id0); } #else ASSERT (pitp == hicn_pit_get_data (node0)); /* - * If the packet is copied and not cloned, we need to free the vlib_buffer + * If the packet is copied and not cloned, we need to free the + * vlib_buffer */ if (hicnb0->flags & HICN_BUFFER_FLAGS_PKT_LESS_TWO_CL) { @@ -285,8 +289,8 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, } /* Delete the PIT entry */ - hicn_pcs_pit_delete (pitcs, &pitp, &node0, vm, - hash_entry0, dpo_vft0, &hicn_dpo_id0); + hicn_pcs_pit_delete (pitcs, &pitp, &node0, vm, hash_entry0, + dpo_vft0, &hicn_dpo_id0); #endif } end_processing: @@ -303,11 +307,10 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_node_increment_counter (vm, hicn_data_fwd_node.index, HICNFWD_ERROR_DATAS, stats.pkts_data_count); - - update_node_counter (vm, hicn_data_fwd_node.index, - HICNFWD_ERROR_INT_COUNT, pit_int_count); - update_node_counter (vm, hicn_data_fwd_node.index, - HICNFWD_ERROR_CS_COUNT, pit_cs_count); + update_node_counter (vm, hicn_data_fwd_node.index, HICNFWD_ERROR_INT_COUNT, + pit_int_count); + update_node_counter (vm, hicn_data_fwd_node.index, HICNFWD_ERROR_CS_COUNT, + pit_cs_count); update_node_counter (vm, hicn_data_fwd_node.index, HICNFWD_ERROR_INTEREST_AGG_ENTRY, stats.pkts_data_count / data_received); @@ -316,9 +319,8 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, } always_inline void -drop_packet (vlib_main_t * vm, u32 bi0, - u32 * n_left_to_next, u32 * next0, u32 ** to_next, - u32 * next_index, vlib_node_runtime_t * node) +drop_packet (vlib_main_t *vm, u32 bi0, u32 *n_left_to_next, u32 *next0, + u32 **to_next, u32 *next_index, vlib_node_runtime_t *node) { *next0 = HICN_DATA_FWD_NEXT_ERROR_DROP; @@ -326,23 +328,22 @@ drop_packet (vlib_main_t * vm, u32 bi0, *to_next += 1; *n_left_to_next -= 1; - vlib_validate_buffer_enqueue_x1 (vm, node, *next_index, - *to_next, *n_left_to_next, bi0, *next0); + vlib_validate_buffer_enqueue_x1 (vm, node, *next_index, *to_next, + *n_left_to_next, bi0, *next0); } always_inline int -hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, - hicn_pcs_entry_t * pitp, u32 * n_left_to_next, - u32 ** to_next, u32 * next_index, - vlib_node_runtime_t * node, u8 isv6, - vl_api_hicn_api_node_stats_get_reply_t * stats) +hicn_satisfy_faces (vlib_main_t *vm, u32 bi0, hicn_pcs_entry_t *pitp, + u32 *n_left_to_next, u32 **to_next, u32 *next_index, + vlib_node_runtime_t *node, u8 isv6, + vl_api_hicn_api_node_stats_get_reply_t *stats) { int found = 0; int ret = HICN_ERROR_NONE; u32 *clones = NULL, *header = NULL; u32 n_left_from = 0; - u32 next0 = HICN_DATA_FWD_NEXT_ERROR_DROP, next1 = - HICN_DATA_FWD_NEXT_ERROR_DROP; + u32 next0 = HICN_DATA_FWD_NEXT_ERROR_DROP, + next1 = HICN_DATA_FWD_NEXT_ERROR_DROP; word buffer_advance = CLIB_CACHE_LINE_BYTES * 2; /* @@ -363,30 +364,31 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, hicn_buffer_t *hicnb = hicn_get_buffer (b0); /* - * Mark the buffer as smaller than TWO_CL. It will be stored as is in the CS, without excluding - * the hicn_header. Cloning is not possible, it will be copied. + * Mark the buffer as smaller than TWO_CL. It will be stored as is in the CS, + * without excluding the hicn_header. Cloning is not possible, it will be + * copied. */ if (b0->current_length <= (buffer_advance + (CLIB_CACHE_LINE_BYTES * 2))) { - /* In this case the packet is copied. We don't need to add a reference as no buffer are - * chained to it. + /* In this case the packet is copied. We don't need to add a reference as + * no buffer are chained to it. */ hicnb->flags |= HICN_BUFFER_FLAGS_PKT_LESS_TWO_CL; } else { /* Add one reference to maintain the buffer in the CS. - * b0->ref_count == 0 has two meaning: it has 1 buffer or no buffer chained to it. - * vlib_buffer_clone2 add a number of reference equalt to pitp->u.pit.faces.n_faces - 1 - * as vlib_buffer_clone does. So after all the packet are forwarded the buffer stored in - * the CS will have ref_count == 0; + * b0->ref_count == 0 has two meaning: it has 1 buffer or no buffer + * chained to it. vlib_buffer_clone2 add a number of reference equalt to + * pitp->u.pit.faces.n_faces - 1 as vlib_buffer_clone does. So after all + * the packet are forwarded the buffer stored in the CS will have + * ref_count == 0; */ b0->ref_count++; } - found = n_left_from = - vlib_buffer_clone2 (vm, bi0, clones, pitp->u.pit.faces.n_faces, - buffer_advance); + found = n_left_from = vlib_buffer_clone2 ( + vm, bi0, clones, pitp->u.pit.faces.n_faces, buffer_advance); ASSERT (n_left_from == pitp->u.pit.faces.n_faces); @@ -396,7 +398,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, while (n_left_from > 0) { - //Dual loop, X2 + // Dual loop, X2 while (n_left_from >= 4 && *n_left_to_next >= 2) { vlib_buffer_t *h0, *h1; @@ -426,11 +428,11 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, clones += 2; next0 = isv6 ? HICN_DATA_FWD_NEXT_IFACE6_OUT : - HICN_DATA_FWD_NEXT_IFACE4_OUT; + HICN_DATA_FWD_NEXT_IFACE4_OUT; next1 = isv6 ? HICN_DATA_FWD_NEXT_IFACE6_OUT : - HICN_DATA_FWD_NEXT_IFACE4_OUT; + HICN_DATA_FWD_NEXT_IFACE4_OUT; - vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0; + vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0; vnet_buffer (h1)->ip.adj_index[VLIB_TX] = face1; stats->pkts_data_count += 2; @@ -443,8 +445,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, t->pkt_type = HICN_PKT_TYPE_CONTENT; t->sw_if_index = vnet_buffer (h0)->sw_if_index[VLIB_RX]; t->next_index = next0; - clib_memcpy (t->packet_data, - vlib_buffer_get_current (h0), + clib_memcpy (t->packet_data, vlib_buffer_get_current (h0), sizeof (t->packet_data)); } if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && @@ -455,16 +456,14 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, t->pkt_type = HICN_PKT_TYPE_CONTENT; t->sw_if_index = vnet_buffer (h1)->sw_if_index[VLIB_RX]; t->next_index = next1; - clib_memcpy (t->packet_data, - vlib_buffer_get_current (h1), + clib_memcpy (t->packet_data, vlib_buffer_get_current (h1), sizeof (t->packet_data)); } - vlib_validate_buffer_enqueue_x2 (vm, node, *next_index, - (*to_next), *n_left_to_next, - hi0, hi1, next0, next1); + vlib_validate_buffer_enqueue_x2 (vm, node, *next_index, (*to_next), + *n_left_to_next, hi0, hi1, next0, + next1); } - while (n_left_from > 0 && *n_left_to_next > 0) { vlib_buffer_t *h0; @@ -482,7 +481,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, clones += 1; next0 = isv6 ? HICN_DATA_FWD_NEXT_IFACE6_OUT : - HICN_DATA_FWD_NEXT_IFACE4_OUT; + HICN_DATA_FWD_NEXT_IFACE4_OUT; vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0; stats->pkts_data_count++; @@ -495,8 +494,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, t->pkt_type = HICN_PKT_TYPE_CONTENT; t->sw_if_index = vnet_buffer (h0)->sw_if_index[VLIB_RX]; t->next_index = next0; - clib_memcpy (t->packet_data, - vlib_buffer_get_current (h0), + clib_memcpy (t->packet_data, vlib_buffer_get_current (h0), sizeof (t->packet_data)); } /* @@ -507,10 +505,8 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, * Fix in case of a wrong speculation. Needed to * clone the data in the right frame */ - vlib_validate_buffer_enqueue_x1 (vm, node, *next_index, - *to_next, *n_left_to_next, - hi0, next0); - + vlib_validate_buffer_enqueue_x1 (vm, node, *next_index, *to_next, + *n_left_to_next, hi0, next0); } /* Ensure that there is space for the next clone (if any) */ @@ -528,20 +524,19 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, if (PREDICT_FALSE (!found)) { ASSERT (0); - drop_packet (vm, bi0, n_left_to_next, &next0, to_next, next_index, - node); + drop_packet (vm, bi0, n_left_to_next, &next0, to_next, next_index, node); ret = HICN_ERROR_FACE_NOT_FOUND; } return ret; } always_inline void -clone_data_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, - hicn_pcs_entry_t * pitp, hicn_header_t * hicn0, f64 tnow, - hicn_hash_node_t * nodep, vlib_buffer_t * b0, - hicn_hash_entry_t * hash_entry, u64 name_hash, - hicn_buffer_t * hicnb, const hicn_dpo_vft_t * dpo_vft, - dpo_id_t * hicn_dpo_id, hicn_lifetime_t dmsg_lifetime) +clone_data_to_cs (vlib_main_t *vm, hicn_pit_cs_t *pitcs, + hicn_pcs_entry_t *pitp, hicn_header_t *hicn0, f64 tnow, + hicn_hash_node_t *nodep, vlib_buffer_t *b0, + hicn_hash_entry_t *hash_entry, u64 name_hash, + hicn_buffer_t *hicnb, const hicn_dpo_vft_t *dpo_vft, + dpo_id_t *hicn_dpo_id, hicn_lifetime_t dmsg_lifetime) { /* * At this point we think we're safe to proceed. Store the CS buf in @@ -560,8 +555,8 @@ clone_data_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, pitp->shared.create_time = tnow; - if (dmsg_lifetime < HICN_PARAM_CS_LIFETIME_MIN - || dmsg_lifetime > HICN_PARAM_CS_LIFETIME_MAX) + if (dmsg_lifetime < HICN_PARAM_CS_LIFETIME_MIN || + dmsg_lifetime > HICN_PARAM_CS_LIFETIME_MAX) { dmsg_lifetime = HICN_PARAM_CS_LIFETIME_DFLT; } @@ -573,7 +568,7 @@ clone_data_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, /* packet trace format function */ always_inline u8 * -hicn_data_fwd_format_trace (u8 * s, va_list * args) +hicn_data_fwd_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 *); @@ -583,15 +578,14 @@ hicn_data_fwd_format_trace (u8 * s, va_list * args) s = format (s, "DATAFWD: pkt: %d, sw_if_index %d, next index %d\n", (int) t->pkt_type, t->sw_if_index, t->next_index); - s = format (s, "%U%U", format_white_space, indent, - format_ip6_header, t->packet_data, sizeof (t->packet_data)); + s = format (s, "%U%U", format_white_space, indent, format_ip6_header, + t->packet_data, sizeof (t->packet_data)); return (s); } /* * Node registration for the data forwarder node */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE(hicn_data_fwd_node) = { .function = hicn_data_node_fn, @@ -611,7 +605,6 @@ VLIB_REGISTER_NODE(hicn_data_fwd_node) = [HICN_DATA_FWD_NEXT_ERROR_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON |