X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest-fib%2Fmain.c;h=830c32cc444ad5ee72f8a28d59cdb9de7b573dfd;hb=08dfff78f200bb9f077b0006ef05ab59dbc40ac8;hp=7fd342092f53ab074b393c1a6dceee774459db93;hpb=d19034ae63e95978c6017d18db1924f515f93cc7;p=dpdk.git diff --git a/app/test-fib/main.c b/app/test-fib/main.c index 7fd342092f..830c32cc44 100644 --- a/app/test-fib/main.c +++ b/app/test-fib/main.c @@ -2,14 +2,10 @@ * Copyright(c) 2019 Intel Corporation */ -#include #include #include -#include -#include -#include -#include #include +#include #include #include @@ -103,6 +99,7 @@ static struct { uint8_t ent_sz; uint8_t rnd_lookup_ips_ratio; uint8_t print_fract; + uint8_t lookup_fn; } config = { .routes_file = NULL, .lookup_ips_file = NULL, @@ -114,7 +111,8 @@ static struct { .tbl8 = DEFAULT_LPM_TBL8, .ent_sz = 4, .rnd_lookup_ips_ratio = 0, - .print_fract = 10 + .print_fract = 10, + .lookup_fn = 0 }; struct rt_rule_4 { @@ -443,6 +441,32 @@ gen_rnd_lookup_tbl(int af) } } +static int +_inet_net_pton(int af, char *prefix, void *addr) +{ + const char *dlm = "/"; + char *s, *sp; + int ret, depth; + unsigned int max_depth; + + if ((prefix == NULL) || (addr == NULL)) + return -EINVAL; + + s = strtok_r(prefix, dlm, &sp); + if (s == NULL) + return -EINVAL; + + ret = inet_pton(af, s, addr); + if (ret != 1) + return -errno; + + s = strtok_r(NULL, dlm, &sp); + max_depth = (af == AF_INET) ? 32 : 128; + GET_CB_FIELD(s, depth, 0, max_depth, 0); + + return depth; +} + static int parse_rt_4(FILE *f) { @@ -463,8 +487,7 @@ parse_rt_4(FILE *f) s = NULL; } - ret = inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr, - sizeof(rt[j].addr)); + ret = _inet_net_pton(AF_INET, in[RT_PREFIX], &rt[j].addr); if (ret == -1) return -errno; @@ -478,30 +501,6 @@ parse_rt_4(FILE *f) return 0; } -static int -__inet_net_pton6(char *prefix, uint8_t *addr) -{ - const char *dlm = "/"; - char *s, *sp; - int ret, depth; - - if ((prefix == NULL) || (addr == NULL)) - return -EINVAL; - - s = strtok_r(prefix, dlm, &sp); - if (s == NULL) - return -EINVAL; - - ret = inet_pton(AF_INET6, s, addr); - if (ret != 1) - return -errno; - - s = strtok_r(NULL, dlm, &sp); - GET_CB_FIELD(s, depth, 0, 128, 0); - - return depth; -} - static int parse_rt_6(FILE *f) { @@ -522,7 +521,7 @@ parse_rt_6(FILE *f) s = NULL; } - ret = __inet_net_pton6(in[RT_PREFIX], rt[j].addr); + ret = _inet_net_pton(AF_INET6, in[RT_PREFIX], rt[j].addr); if (ret < 0) return ret; @@ -546,6 +545,8 @@ parse_lookup(FILE *f, int af) while (fgets(line, sizeof(line), f) != NULL) { s = strtok(line, " \t\n"); + if (s == NULL) + return -EINVAL; ret = inet_pton(af, s, &tbl[i]); if (ret != 1) return -EINVAL; @@ -623,15 +624,15 @@ print_usage(void) "(if -f is not specified)>]\n" "[-r ]\n" - "[-c ]\n" + "[-c ]\n" "[-6 ]\n" "[-s ]\n" "[-a ]\n" - "[-b ]\n\tavailible options for ipv4\n" + "[-b ]\n\tavailable options for ipv4\n" "\t\trib - RIB based FIB\n" "\t\tdir - DIR24_8 based FIB\n" - "\tavailible options for ipv6:\n" + "\tavailable options for ipv6:\n" "\t\trib - RIB based FIB\n" "\t\ttrie - TRIE based FIB\n" "defaults are: dir for ipv4 and trie for ipv6\n" @@ -639,7 +640,11 @@ print_usage(void) "1/2/4/8 (default 4)>]\n" "[-g ]\n" "[-w ]\n" - "[-u ]\n", + "[-u ]\n" + "[-v ]\n", config.prgname); } @@ -682,7 +687,7 @@ parse_opts(int argc, char **argv) int opt; char *endptr; - while ((opt = getopt(argc, argv, "f:t:n:d:l:r:c6ab:e:g:w:u:s")) != + while ((opt = getopt(argc, argv, "f:t:n:d:l:r:c6ab:e:g:w:u:sv:")) != -1) { switch (opt) { case 'f': @@ -706,6 +711,10 @@ parse_opts(int argc, char **argv) print_usage(); rte_exit(-EINVAL, "Invalid option -n\n"); } + + if (config.nb_routes < config.print_fract) + config.print_fract = config.nb_routes; + break; case 'd': distrib_string = optarg; @@ -770,6 +779,23 @@ parse_opts(int argc, char **argv) rte_exit(-EINVAL, "Invalid option -g\n"); } break; + case 'v': + if ((strcmp(optarg, "s1") == 0) || + (strcmp(optarg, "s") == 0)) { + config.lookup_fn = 1; + break; + } else if (strcmp(optarg, "v") == 0) { + config.lookup_fn = 2; + break; + } else if (strcmp(optarg, "s2") == 0) { + config.lookup_fn = 3; + break; + } else if (strcmp(optarg, "s3") == 0) { + config.lookup_fn = 4; + break; + } + print_usage(); + rte_exit(-EINVAL, "Invalid option -v %s\n", optarg); default: print_usage(); rte_exit(-EINVAL, "Invalid options\n"); @@ -835,6 +861,7 @@ run_v4(void) conf.type = get_fib_type(); conf.default_nh = def_nh; conf.max_routes = config.nb_routes * 2; + conf.rib_ext_sz = 0; if (conf.type == RTE_FIB_DIR24_8) { conf.dir24_8.nh_sz = __builtin_ctz(config.ent_sz); conf.dir24_8.num_tbl8 = RTE_MIN(config.tbl8, @@ -847,6 +874,27 @@ run_v4(void) return -rte_errno; } + if (config.lookup_fn != 0) { + if (config.lookup_fn == 1) + ret = rte_fib_select_lookup(fib, + RTE_FIB_LOOKUP_DIR24_8_SCALAR_MACRO); + else if (config.lookup_fn == 2) + ret = rte_fib_select_lookup(fib, + RTE_FIB_LOOKUP_DIR24_8_VECTOR_AVX512); + else if (config.lookup_fn == 3) + ret = rte_fib_select_lookup(fib, + RTE_FIB_LOOKUP_DIR24_8_SCALAR_INLINE); + else if (config.lookup_fn == 4) + ret = rte_fib_select_lookup(fib, + RTE_FIB_LOOKUP_DIR24_8_SCALAR_UNI); + else + ret = -EINVAL; + if (ret != 0) { + printf("Can not init lookup function\n"); + return ret; + } + } + for (k = config.print_fract, i = 0; k > 0; k--) { start = rte_rdtsc_precise(); for (j = 0; j < (config.nb_routes - i) / k; j++) { @@ -1014,6 +1062,7 @@ run_v6(void) conf.type = get_fib_type(); conf.default_nh = def_nh; conf.max_routes = config.nb_routes * 2; + conf.rib_ext_sz = 0; if (conf.type == RTE_FIB6_TRIE) { conf.trie.nh_sz = __builtin_ctz(config.ent_sz); conf.trie.num_tbl8 = RTE_MIN(config.tbl8, @@ -1026,6 +1075,21 @@ run_v6(void) return -rte_errno; } + if (config.lookup_fn != 0) { + if (config.lookup_fn == 1) + ret = rte_fib6_select_lookup(fib, + RTE_FIB6_LOOKUP_TRIE_SCALAR); + else if (config.lookup_fn == 2) + ret = rte_fib6_select_lookup(fib, + RTE_FIB6_LOOKUP_TRIE_VECTOR_AVX512); + else + ret = -EINVAL; + if (ret != 0) { + printf("Can not init lookup function\n"); + return ret; + } + } + for (k = config.print_fract, i = 0; k > 0; k--) { start = rte_rdtsc_precise(); for (j = 0; j < (config.nb_routes - i) / k; j++) { @@ -1182,6 +1246,10 @@ main(int argc, char **argv) config.nb_routes = 0; while (fgets(line, sizeof(line), fr) != NULL) config.nb_routes++; + + if (config.nb_routes < config.print_fract) + config.print_fract = config.nb_routes; + rewind(fr); }