From be1150733c8e1aa05757a6021005e0d4dbca83b4 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Fri, 20 Dec 2024 02:32:35 -0800 Subject: [PATCH] nsim: fix output feature node Interface tx nodes want frames with scalar data populated by output nodes. This is not supported by nsim output feature. To avoid reimplementing output node logic and/or future incompatibilities, recirculate buffers through interface output after tagging. Type: fix Signed-off-by: Florin Coras Change-Id: Ib8865798d8e7dc0d2f34b3e13ce29b683e490ceb --- src/plugins/nsim/node.c | 30 +++++++++++++++++++++++++++--- src/plugins/nsim/nsim.c | 6 ++---- src/plugins/nsim/nsim.h | 7 +++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/plugins/nsim/node.c b/src/plugins/nsim/node.c index a8ba909ab07..8b73339c4d8 100644 --- a/src/plugins/nsim/node.c +++ b/src/plugins/nsim/node.c @@ -135,20 +135,36 @@ nsim_buffer_fwd_lookup (nsim_main_t * nsm, vlib_buffer_t * b, } } +#define NSIM_PKT_TAG 0xfefabeba + always_inline void nsim_dispatch_buffer (vlib_main_t * vm, vlib_node_runtime_t * node, nsim_main_t * nsm, nsim_wheel_t * wp, vlib_buffer_t * b, u32 bi, nsim_node_ctx_t * ctx, u8 is_cross_connect, u8 is_trace) { + if (vnet_buffer (b)->ip.flow_hash == NSIM_PKT_TAG) + { + u32 next; + vnet_get_config_data (&ctx->fcm->config_main, &b->current_config_index, + &next, 0); + + ctx->fwd[0] = bi; + ctx->fwd_nexts[0] = next; + ctx->fwd += 1; + ctx->fwd_nexts += 1; + + goto trace; + } + if (PREDICT_TRUE (!(ctx->action[0] & NSIM_ACTION_DROP))) { if (PREDICT_FALSE (ctx->action[0] & NSIM_ACTION_REORDER)) { u32 next; - ctx->reord[0] = bi; vnet_get_config_data (&ctx->fcm->config_main, &b->current_config_index, &next, 0); + ctx->reord[0] = bi; ctx->reord_nexts[0] = next; ctx->reord += 1; ctx->reord_nexts += 1; @@ -163,11 +179,12 @@ nsim_dispatch_buffer (vlib_main_t * vm, vlib_node_runtime_t * node, ep->tx_time = ctx->expires; ep->rx_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + ep->tx_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX]; nsim_buffer_fwd_lookup (nsm, b, &ep->output_next_index, is_cross_connect); - ep->tx_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX]; ep->buffer_index = bi; ctx->n_buffered += 1; + vnet_buffer (b)->ip.flow_hash = NSIM_PKT_TAG; } else { @@ -193,7 +210,8 @@ nsim_inline (vlib_main_t * vm, u32 n_left_from, *from, drops[VLIB_FRAME_SIZE], reorders[VLIB_FRAME_SIZE]; nsim_wheel_t *wp = nsm->wheel_by_thread[vm->thread_index]; vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; - u16 reorders_nexts[VLIB_FRAME_SIZE]; + u16 reorders_nexts[VLIB_FRAME_SIZE], fwds_nexts[VLIB_FRAME_SIZE]; + u32 fwds[VLIB_FRAME_SIZE]; u8 actions[VLIB_FRAME_SIZE]; nsim_node_ctx_t ctx; @@ -211,6 +229,8 @@ nsim_inline (vlib_main_t * vm, ctx.drop = drops; ctx.reord = reorders; ctx.reord_nexts = reorders_nexts; + ctx.fwd = fwds; + ctx.fwd_nexts = fwds_nexts; ctx.action = actions; ctx.expires = vlib_time_now (vm) + nsm->delay; @@ -283,6 +303,10 @@ slow_path: vlib_node_increment_counter (vm, node->node_index, NSIM_ERROR_REORDERED, n_reordered); } + if (ctx.fwd > fwds) + { + vlib_buffer_enqueue_to_next (vm, node, fwds, fwds_nexts, ctx.fwd - fwds); + } vlib_node_increment_counter (vm, node->node_index, NSIM_ERROR_BUFFERED, ctx.n_buffered); return frame->n_vectors; diff --git a/src/plugins/nsim/nsim.c b/src/plugins/nsim/nsim.c index 1c5b26bbaaa..6339ecf0990 100644 --- a/src/plugins/nsim/nsim.c +++ b/src/plugins/nsim/nsim.c @@ -116,10 +116,8 @@ nsim_output_feature_enable_disable (nsim_main_t * nsm, u32 sw_if_index, hw = vnet_get_hw_interface (nsm->vnet_main, sw_if_index); vec_validate_init_empty (nsm->output_next_index_by_sw_if_index, sw_if_index, ~0); - /* Note: use the tx node, this pkt has already visited the output node... */ - nsm->output_next_index_by_sw_if_index[sw_if_index] = - vlib_node_add_next (nsm->vlib_main, nsim_input_node.index, - hw->tx_node_index); + nsm->output_next_index_by_sw_if_index[sw_if_index] = vlib_node_add_next ( + nsm->vlib_main, nsim_input_node.index, hw->output_node_index); vnet_feature_enable_disable ("interface-output", "nsim-output-feature", sw_if_index, enable_disable, 0, 0); diff --git a/src/plugins/nsim/nsim.h b/src/plugins/nsim/nsim.h index b35a1c685de..2f2cdf8b9c8 100644 --- a/src/plugins/nsim/nsim.h +++ b/src/plugins/nsim/nsim.h @@ -54,9 +54,12 @@ typedef struct nsim_node_ctx u32 *drop; u32 *reord; u16 *reord_nexts; + u32 *fwd; + u16 *fwd_nexts; u8 *action; - u64 n_buffered; - u64 n_loss; + u32 n_buffered; + u32 n_loss; + u32 n_reordered; } nsim_node_ctx_t; #define foreach_nsm_action \ -- 2.16.6