From d34f73f20de8e062ab5a4af720da8b1f9637d11e Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Mon, 15 Jul 2024 17:22:01 +0900 Subject: [PATCH] ecmp load-balancing support --- common/llb_dpapi.h | 7 +++++-- kernel/llb_kern_l2fwd.c | 2 +- kernel/llb_kern_l3fwd.c | 12 ++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/common/llb_dpapi.h b/common/llb_dpapi.h index bdd28e7..7c37778 100644 --- a/common/llb_dpapi.h +++ b/common/llb_dpapi.h @@ -190,9 +190,12 @@ struct dp_rt_l2nh_act { __u16 rnh_num; }; +#define DP_MAX_ACTIVE_PATHS (4) + struct dp_rt_nh_act { - __u16 nh_num; - __u16 bd; + __u16 nh_num[DP_MAX_ACTIVE_PATHS]; + __u16 naps; + __u16 bd; __u32 tid; struct dp_rt_l2nh_act l2nh; }; diff --git a/kernel/llb_kern_l2fwd.c b/kernel/llb_kern_l2fwd.c index 88274dc..2c19edb 100644 --- a/kernel/llb_kern_l2fwd.c +++ b/kernel/llb_kern_l2fwd.c @@ -53,7 +53,7 @@ dp_do_smac_lkup(void *ctx, struct xfi *xf, void *fc) static int __always_inline dp_pipe_set_l22_tun_nh(void *ctx, struct xfi *xf, struct dp_rt_nh_act *rnh) { - xf->pm.nh_num = rnh->nh_num; + xf->pm.nh_num = rnh->nh_num[0]; /* * We do not set out_bd here. After NH lookup match is diff --git a/kernel/llb_kern_l3fwd.c b/kernel/llb_kern_l3fwd.c index 725e8b6..6e3726c 100644 --- a/kernel/llb_kern_l3fwd.c +++ b/kernel/llb_kern_l3fwd.c @@ -48,7 +48,7 @@ dp_pipe_set_l32_tun_nh(void *ctx, struct xfi *xf, struct dp_rt_nh_act *rnh) { struct dp_rt_l2nh_act *nl2; - xf->pm.nh_num = rnh->nh_num; + xf->pm.nh_num = rnh->nh_num[0]; /* * We do not set out_bd here. After NH lookup match is * found and packet tunnel insertion is done, BD is set accordingly @@ -120,7 +120,15 @@ dp_do_rtops(void *ctx, struct xfi *xf, void *fa_, struct dp_rt_tact *act) xf->pm.oport = ra->oport; } else if (act->ca.act_type == DP_SET_RT_NHNUM) { struct dp_rt_nh_act *rnh = &act->rt_nh; - xf->pm.nh_num = rnh->nh_num; + + if (rnh->naps > 1) { + int sel = dp_get_pkt_hash(ctx) % rnh->naps; + if (sel >= 0 && sel < DP_MAX_ACTIVE_PATHS) { + xf->pm.nh_num = rnh->nh_num[sel]; + } + } else { + xf->pm.nh_num = rnh->nh_num[0]; + } return dp_do_rt_fwdops(ctx, xf); } /*else if (act->ca.act_type == DP_SET_L3RT_TUN_NH) { #ifdef HAVE_DP_EXTFC