diff options
author | Nobuhiro MIKI <nmiki@yahoo-corp.jp> | 2022-09-28 15:53:17 +0900 |
---|---|---|
committer | Beno�t Ganne <bganne@cisco.com> | 2023-01-18 10:53:23 +0000 |
commit | 613e6dc0bf928def5d337312d522e1a15df87b00 (patch) | |
tree | 04e592643029774fadcbfc8f8e82df778b867df9 /src/plugins/lb/lb_test.c | |
parent | 893a0c3130e1d868c939db6dcde258da1277cf41 (diff) |
lb: add source ip based sticky load balancing
This patch adds source ip based sticky session, which is already
implemented in many hardware LBs and software LBs. Note that sticky
sessions may be reset if the hash is recalculated as ASs are added
or deleted.
Since this feature is unrelated to the other existing options, the
lb_add_del_vip API version has been upgraded to v2 and a new option
"src_ip_sticky" has been added.
Type: feature
Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
Change-Id: I3eb3680a28defbc701f28c873933ec2fb54544ab
Diffstat (limited to 'src/plugins/lb/lb_test.c')
-rw-r--r-- | src/plugins/lb/lb_test.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/plugins/lb/lb_test.c b/src/plugins/lb/lb_test.c index 80fc38e2746..f64bdd220b5 100644 --- a/src/plugins/lb/lb_test.c +++ b/src/plugins/lb/lb_test.c @@ -207,6 +207,105 @@ static int api_lb_add_del_vip (vat_main_t * vam) return ret; } +static int +api_lb_add_del_vip_v2 (vat_main_t *vam) +{ + unformat_input_t *line_input = vam->input; + vl_api_lb_add_del_vip_v2_t *mp; + int ret; + ip46_address_t ip_prefix; + u8 prefix_length = 0; + u8 protocol = 0; + u32 port = 0; + u32 encap = 0; + u32 dscp = ~0; + u32 srv_type = LB_SRV_TYPE_CLUSTERIP; + u32 target_port = 0; + u32 new_length = 1024; + u8 src_ip_sticky = 0; + int is_del = 0; + + if (!unformat (line_input, "%U", unformat_ip46_prefix, &ip_prefix, + &prefix_length, IP46_TYPE_ANY, &prefix_length)) + { + errmsg ("lb_add_del_vip: invalid vip prefix\n"); + return -99; + } + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "new_len %d", &new_length)) + ; + else if (unformat (line_input, "del")) + is_del = 1; + else if (unformat (line_input, "src_ip_sticky")) + src_ip_sticky = 1; + else if (unformat (line_input, "protocol tcp")) + { + protocol = IP_PROTOCOL_TCP; + } + else if (unformat (line_input, "protocol udp")) + { + protocol = IP_PROTOCOL_UDP; + } + else if (unformat (line_input, "port %d", &port)) + ; + else if (unformat (line_input, "encap gre4")) + encap = LB_ENCAP_TYPE_GRE4; + else if (unformat (line_input, "encap gre6")) + encap = LB_ENCAP_TYPE_GRE6; + else if (unformat (line_input, "encap l3dsr")) + encap = LB_ENCAP_TYPE_L3DSR; + else if (unformat (line_input, "encap nat4")) + encap = LB_ENCAP_TYPE_NAT4; + else if (unformat (line_input, "encap nat6")) + encap = LB_ENCAP_TYPE_NAT6; + else if (unformat (line_input, "dscp %d", &dscp)) + ; + else if (unformat (line_input, "type clusterip")) + srv_type = LB_SRV_TYPE_CLUSTERIP; + else if (unformat (line_input, "type nodeport")) + srv_type = LB_SRV_TYPE_NODEPORT; + else if (unformat (line_input, "target_port %d", &target_port)) + ; + else + { + errmsg ("invalid arguments\n"); + return -99; + } + } + + if ((encap != LB_ENCAP_TYPE_L3DSR) && (dscp != ~0)) + { + errmsg ("lb_vip_add error: should not configure dscp for none L3DSR."); + return -99; + } + + if ((encap == LB_ENCAP_TYPE_L3DSR) && (dscp >= 64)) + { + errmsg ("lb_vip_add error: dscp for L3DSR should be less than 64."); + return -99; + } + + M (LB_ADD_DEL_VIP, mp); + ip_address_encode (&ip_prefix, IP46_TYPE_ANY, &mp->pfx.address); + mp->pfx.len = prefix_length; + mp->protocol = (u8) protocol; + mp->port = htons ((u16) port); + mp->encap = (u8) encap; + mp->dscp = (u8) dscp; + mp->type = (u8) srv_type; + mp->target_port = htons ((u16) target_port); + mp->node_port = htons ((u16) target_port); + mp->new_flows_table_length = htonl (new_length); + mp->is_del = is_del; + mp->src_ip_sticky = src_ip_sticky; + + S (mp); + W (ret); + return ret; +} + static int api_lb_add_del_as (vat_main_t * vam) { |