X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Flb%2Flb_test.c;h=cc8cc58c0bec333518b36cf231b0f205673e699a;hb=3efcd0d7c;hp=8c2eaa91ce93b9c55c8cb47763c2152b08399b15;hpb=cb034b9b374927c7552e36dcbc306d8456b2a0cb;p=vpp.git diff --git a/src/plugins/lb/lb_test.c b/src/plugins/lb/lb_test.c index 8c2eaa91ce9..cc8cc58c0be 100644 --- a/src/plugins/lb/lb_test.c +++ b/src/plugins/lb/lb_test.c @@ -16,10 +16,13 @@ #include #include #include -#include + #include #include +#define __plugin_msg_base lb_test_main.msg_id_base +#include + //TODO: Move that to vat/plugin_api.c ////////////////////////// uword unformat_ip46_address (unformat_input_t * input, va_list * args) @@ -123,118 +126,328 @@ foreach_standard_reply_retval_handler; * we just generated */ #define foreach_vpe_api_reply_msg \ - _(LB_CONF_REPLY, lb_conf_reply) \ - _(LB_ADD_DEL_VIP_REPLY, lb_add_del_vip_reply) \ - _(LB_ADD_DEL_AS_REPLY, lb_add_del_as_reply) - -/* M: construct, but don't yet send a message */ -#define M(T,t) \ -do { \ - vam->result_ready = 0; \ - mp = vl_msg_api_alloc(sizeof(*mp)); \ - memcpy (mp, &mps, sizeof (*mp)); \ - mp->_vl_msg_id = ntohs (VL_API_##T + lbtm->msg_id_base); \ - mp->client_index = vam->my_client_index; \ -} while(0); - -/* S: send a message */ -#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp)) - -/* W: wait for results, with timeout */ -#define W \ -do { \ - timeout = vat_time_now (vam) + 1.0; \ - \ - while (vat_time_now (vam) < timeout) { \ - if (vam->result_ready == 1) { \ - return (vam->retval); \ - } \ - } \ - return -99; \ -} while(0); + _(LB_CONF_REPLY, lb_conf_reply) \ + _(LB_ADD_DEL_VIP_REPLY, lb_add_del_vip_reply) \ + _(LB_ADD_DEL_AS_REPLY, lb_add_del_as_reply) \ + _(LB_VIP_DETAILS, lb_vip_details) \ + _(LB_AS_DETAILS, lb_as_details) static int api_lb_conf (vat_main_t * vam) { - lb_test_main_t *lbtm = &lb_test_main; - unformat_input_t *i = vam->input; - f64 timeout; - vl_api_lb_conf_t mps, *mp; - - if (!unformat(i, "%U %U %u %u", - unformat_ip4_address, &mps.ip4_src_address, - unformat_ip6_address, mps.ip6_src_address, - &mps.sticky_buckets_per_core, - &mps.flow_timeout)) { - errmsg ("invalid arguments\n"); - return -99; + unformat_input_t *line_input = vam->input; + vl_api_lb_conf_t *mp; + u32 ip4_src_address = 0xffffffff; + ip46_address_t ip6_src_address; + u32 sticky_buckets_per_core = LB_DEFAULT_PER_CPU_STICKY_BUCKETS; + u32 flow_timeout = LB_DEFAULT_FLOW_TIMEOUT; + int ret; + + ip6_src_address.as_u64[0] = 0xffffffffffffffffL; + ip6_src_address.as_u64[1] = 0xffffffffffffffffL; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat(line_input, "ip4-src-address %U", unformat_ip4_address, &ip4_src_address)) + ; + else if (unformat(line_input, "ip6-src-address %U", unformat_ip6_address, &ip6_src_address)) + ; + else if (unformat(line_input, "buckets %d", &sticky_buckets_per_core)) + ; + else if (unformat(line_input, "timeout %d", &flow_timeout)) + ; + else { + errmsg ("invalid arguments\n"); + return -99; + } } - M(LB_CONF, lb_conf); S; W; + M(LB_CONF, mp); + clib_memcpy (&(mp->ip4_src_address), &ip4_src_address, sizeof (ip4_src_address)); + clib_memcpy (&(mp->ip6_src_address), &ip6_src_address, sizeof (ip6_src_address)); + mp->sticky_buckets_per_core = htonl (sticky_buckets_per_core); + mp->flow_timeout = htonl (flow_timeout); - /* NOTREACHED */ - return 0; + S(mp); + W (ret); + return ret; } static int api_lb_add_del_vip (vat_main_t * vam) { - lb_test_main_t *lbtm = &lb_test_main; - unformat_input_t * i = vam->input; - f64 timeout; - vl_api_lb_add_del_vip_t mps, *mp; - mps.is_del = 0; - mps.is_gre4 = 0; - - if (!unformat(i, "%U", - unformat_ip46_prefix, mps.ip_prefix, &mps.prefix_length, IP46_TYPE_ANY)) { - errmsg ("invalid prefix\n"); + unformat_input_t *line_input = vam->input; + vl_api_lb_add_del_vip_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; + 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; } - if (unformat(i, "gre4")) { - mps.is_gre4 = 1; - } else if (unformat(i, "gre6")) { - mps.is_gre4 = 0; - } else { - errmsg ("no encap\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, "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 (!unformat(i, "%d", &mps.new_flows_table_length)) { - errmsg ("no table lentgh\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 (unformat(i, "del")) { - mps.is_del = 1; - } + 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, lb_add_del_vip); S; W; - /* NOTREACHED */ - return 0; + M(LB_ADD_DEL_VIP, mp); + clib_memcpy (mp->pfx.address.un.ip6, &ip_prefix.ip6, sizeof (ip_prefix.ip6)); + 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; + + S(mp); + W (ret); + return ret; } static int api_lb_add_del_as (vat_main_t * vam) { - lb_test_main_t *lbtm = &lb_test_main; - unformat_input_t * i = vam->input; - f64 timeout; - vl_api_lb_add_del_as_t mps, *mp; - mps.is_del = 0; - - if (!unformat(i, "%U %U", - unformat_ip46_prefix, mps.vip_ip_prefix, &mps.vip_prefix_length, IP46_TYPE_ANY, - unformat_ip46_address, mps.as_address)) { - errmsg ("invalid prefix or address\n"); + + unformat_input_t *line_input = vam->input; + vl_api_lb_add_del_as_t *mp; + int ret; + ip46_address_t vip_prefix, as_addr; + u8 vip_plen; + ip46_address_t *as_array = 0; + u32 port = 0; + u8 protocol = 0; + u8 is_del = 0; + u8 is_flush = 0; + + if (!unformat(line_input, "%U", unformat_ip46_prefix, + &vip_prefix, &vip_plen, IP46_TYPE_ANY)) + { + errmsg ("lb_add_del_as: invalid vip prefix\n"); + return -99; + } + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat(line_input, "%U", unformat_ip46_address, + &as_addr, IP46_TYPE_ANY)) + { + vec_add1(as_array, as_addr); + } + else if (unformat(line_input, "del")) + { + is_del = 1; + } + else if (unformat(line_input, "flush")) + { + is_flush = 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 { + errmsg ("invalid arguments\n"); + return -99; + } + } + + if (!vec_len(as_array)) { + errmsg ("No AS address provided \n"); return -99; } - if (unformat(i, "del")) { - mps.is_del = 1; + M(LB_ADD_DEL_AS, mp); + clib_memcpy (mp->pfx.address.un.ip6, &vip_prefix.ip6, sizeof (vip_prefix.ip6)); + mp->pfx.len = vip_plen; + mp->protocol = (u8)protocol; + mp->port = htons((u16)port); + clib_memcpy (&mp->as_address, &as_addr, sizeof (as_addr)); + mp->is_del = is_del; + mp->is_flush = is_flush; + + S(mp); + W (ret); + return ret; +} + +static void vl_api_lb_vip_details_t_handler + (vl_api_lb_vip_details_t * mp) +{ + vat_main_t *vam = &vat_main; + lb_main_t *lbm = &lb_main; + u32 i = 0; + + u32 vip_count = pool_len(lbm->vips); + + print (vam->ofp, "%11d", vip_count); + + for (i=0; iofp, "%24U%14d%14d%18d", + format_ip46_address, &mp->vip.pfx.address, IP46_TYPE_ANY, + mp->vip.pfx.len, + mp->vip.protocol, + ntohs (mp->vip.port)); + } +} + +static int api_lb_vip_dump (vat_main_t * vam) +{ + vl_api_lb_vip_dump_t *mp; + int ret; + + M(LB_VIP_DUMP, mp); + + S(mp); + W (ret); + return ret; +} + +static void vl_api_lb_as_details_t_handler + (vl_api_lb_as_details_t * mp) +{ + vat_main_t *vam = &vat_main; + lb_main_t *lbm = &lb_main; + + //u32 i = 0; + + print (vam->ofp, "%11d", pool_len(lbm->ass)); +/* + for (i=0; iass); i--) + { + print (vam->ofp, "%24U%14d%14d%18d", + format_ip46_address, &mp->pfx.address, IP46_TYPE_ANY, + mp->pfx.len, + mp->pfx.protocol, + ntohs (mp->pfx.port), + ntohl(mp->app_srv), + mp->flags, + mp->in_use_; + } + */ +} + +static int api_lb_as_dump (vat_main_t * vam) +{ + + unformat_input_t *line_input = vam->input; + vl_api_lb_as_dump_t *mp; + int ret; + ip46_address_t vip_prefix, as_addr; + u8 vip_plen; + ip46_address_t *as_array = 0; + u32 port = 0; + u8 protocol = 0; + + if (!unformat(line_input, "%U", unformat_ip46_prefix, + &vip_prefix, &vip_plen, IP46_TYPE_ANY)) + { + errmsg ("lb_add_del_as: invalid vip prefix\n"); + return -99; + } + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat(line_input, "%U", unformat_ip46_address, + &as_addr, IP46_TYPE_ANY)) + { + vec_add1(as_array, as_addr); + } + 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 { + errmsg ("invalid arguments\n"); + return -99; + } } - M(LB_ADD_DEL_AS, lb_add_del_as); S; W; - /* NOTREACHED */ - return 0; + if (!vec_len(as_array)) { + errmsg ("No AS address provided \n"); + return -99; + } + + M(LB_AS_DUMP, mp); + clib_memcpy (mp->pfx.address.un.ip6, &vip_prefix.ip6, sizeof (vip_prefix.ip6)); + mp->pfx.len = vip_plen; + mp->protocol = (u8)protocol; + mp->port = htons((u16)port); + + S(mp); + W (ret); + return ret; } /* @@ -242,11 +455,21 @@ static int api_lb_add_del_as (vat_main_t * vam) * and that the data plane plugin processes */ #define foreach_vpe_api_msg \ -_(lb_conf, " ") \ -_(lb_add_del_vip, " [gre4|gre6] [del]") \ -_(lb_add_del_as, "
[del]") - -void vat_api_hookup (vat_main_t *vam) +_(lb_conf, "[ip4-src-address ] [ip6-src-address ] " \ + "[buckets ] [timeout ]") \ +_(lb_add_del_vip, " " \ + "[protocol (tcp|udp) port ] " \ + "[encap (gre6|gre4|l3dsr|nat4|nat6)] " \ + "[dscp ] " \ + "[type (nodeport|clusterip) target_port ] " \ + "[new_len ] [del]") \ +_(lb_add_del_as, " [protocol (tcp|udp) port ] " \ + "[
] [del] [flush]") \ +_(lb_vip_dump, "") \ +_(lb_as_dump, " [protocol (tcp|udp) port ]") + +static void +lb_api_hookup (vat_main_t *vam) { lb_test_main_t * lbtm = &lb_test_main; /* Hook up handlers for replies from the data plane plug-in */ @@ -272,22 +495,4 @@ void vat_api_hookup (vat_main_t *vam) #undef _ } -clib_error_t * vat_plugin_register (vat_main_t *vam) -{ - lb_test_main_t * lbtm = &lb_test_main; - - u8 * name; - - lbtm->vat_main = vam; - - /* Ask the vpp engine for the first assigned message-id */ - name = format (0, "lb_%08x%c", api_version, 0); - lbtm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); - - if (lbtm->msg_id_base != (u16) ~0) - vat_api_hookup (vam); - - vec_free(name); - - return 0; -} +VAT_PLUGIN_REGISTER(lb);