diff options
author | 2017-04-07 16:51:27 +0100 | |
---|---|---|
committer | 2017-04-14 10:30:57 +0100 | |
commit | 9fa82a63e47e4ee274c54af366e6fce055a0cbab (patch) | |
tree | 6479ef920d62a7d772e029766da113eb1e7b3228 /examples | |
parent | 4e3cb26150547b8b4105c795e282a1564e7f6e86 (diff) |
* Add siphash file for calculating the sequence number.
* l4fwd app changed to include new command line parameters
hash and secret key for hash calculation.
* Changed l4fwd library to integrate siphash support for
calculating the sequence number.
Change-Id: I29c60836c8b17a118d76b619fd79398fac200f67
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/l4fwd/README | 5 | ||||
-rw-r--r-- | examples/l4fwd/lcore.h | 7 | ||||
-rw-r--r-- | examples/l4fwd/parse.c | 49 |
3 files changed, 58 insertions, 3 deletions
diff --git a/examples/l4fwd/README b/examples/l4fwd/README index 658fe3a..a232537 100644 --- a/examples/l4fwd/README +++ b/examples/l4fwd/README @@ -130,6 +130,11 @@ -L | --listen /* open TCP streams in server mode (listen). */ \ -a | --enable-arp /* enable arp responses (request not supported) */ \ -v | --verbose /* different level of verbose mode */ \ + -H | --hash <string> /* hash algorithm i.e. siphash or jhash to be */ \ + /* used to generate the sequence number. */ \ + -K | --seckey <string> /* 16 character long secret key used by */ \ + /* hash algorithms to generate the */ \ + /* sequence number. */ \ <port0_params> <port1_params> ... <portN_params> Note that: options -U and -T cannot be used together. diff --git a/examples/l4fwd/lcore.h b/examples/l4fwd/lcore.h index d88e434..11cc239 100644 --- a/examples/l4fwd/lcore.h +++ b/examples/l4fwd/lcore.h @@ -16,6 +16,8 @@ #ifndef LCORE_H_ #define LCORE_H_ +#include <rte_random.h> + #include "dpdk_legacy.h" /* @@ -64,6 +66,11 @@ create_context(struct netbe_lcore *lc, const struct tle_ctx_param *ctx_prm) cprm.lookup4_data = lc; cprm.lookup6 = lpm6_dst_lookup; cprm.lookup6_data = lc; + if (cprm.secret_key.u64[0] == 0 && + cprm.secret_key.u64[1] == 0) { + cprm.secret_key.u64[0] = rte_rand(); + cprm.secret_key.u64[1] = rte_rand(); + } frag_cycles = (rte_get_tsc_hz() + MS_PER_S - 1) / MS_PER_S * FRAG_TTL; diff --git a/examples/l4fwd/parse.c b/examples/l4fwd/parse.c index 6593221..ac11517 100644 --- a/examples/l4fwd/parse.c +++ b/examples/l4fwd/parse.c @@ -13,6 +13,9 @@ * limitations under the License. */ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> #include "netbe.h" #include "parse.h" @@ -61,6 +64,12 @@ static const struct { #define OPT_SHORT_LISTEN 'L' #define OPT_LONG_LISTEN "listen" +#define OPT_SHORT_HASH 'H' +#define OPT_LONG_HASH "hash" + +#define OPT_SHORT_SEC_KEY 'K' +#define OPT_LONG_SEC_KEY "seckey" + #define OPT_SHORT_VERBOSE 'v' #define OPT_LONG_VERBOSE "verbose" @@ -75,6 +84,8 @@ static const struct option long_opt[] = { {OPT_LONG_STREAMS, 1, 0, OPT_SHORT_STREAMS}, {OPT_LONG_UDP, 0, 0, OPT_SHORT_UDP}, {OPT_LONG_TCP, 0, 0, OPT_SHORT_TCP}, + {OPT_LONG_HASH, 1, 0, OPT_SHORT_HASH}, + {OPT_LONG_SEC_KEY, 1, 0, OPT_SHORT_SEC_KEY}, {OPT_LONG_LISTEN, 0, 0, OPT_SHORT_LISTEN}, {OPT_LONG_VERBOSE, 1, 0, OPT_SHORT_VERBOSE}, {NULL, 0, 0, 0} @@ -709,6 +720,17 @@ netfe_parse_cfg(const char *fname, struct netfe_lcore_prm *lp) return rc; } +static uint32_t +parse_hash_alg(const char *val) +{ + if (strcmp(val, "jhash") == 0) + return TLE_JHASH; + else if (strcmp(val, "siphash") == 0) + return TLE_SIPHASH; + else + return TLE_HASH_NUM; +} + int parse_app_options(int argc, char **argv, struct netbe_cfg *cfg, struct tle_ctx_param *ctx_prm, @@ -722,8 +744,8 @@ parse_app_options(int argc, char **argv, struct netbe_cfg *cfg, optind = 0; optarg = NULL; - while ((opt = getopt_long(argc, argv, "aB:LPR:S:TUb:f:s:v:", long_opt, - &opt_idx)) != EOF) { + while ((opt = getopt_long(argc, argv, "aB:LPR:S:TUb:f:s:v:H:K:", + long_opt, &opt_idx)) != EOF) { if (opt == OPT_SHORT_ARP) { cfg->arp = 1; } else if (opt == OPT_SHORT_SBULK) { @@ -778,7 +800,28 @@ parse_app_options(int argc, char **argv, struct netbe_cfg *cfg, } else if (opt == OPT_SHORT_LISTEN) { listen = 1; cfg->server = 1; - } else { + } else if (opt == OPT_SHORT_HASH) { + ctx_prm->hash_alg = parse_hash_alg(optarg); + if (ctx_prm->hash_alg >= TLE_HASH_NUM) { + rte_exit(EXIT_FAILURE, + "%s: invalid hash algorithm %s " + "for option: \'%c\'\n", + __func__, optarg, opt); + } + } else if (opt == OPT_SHORT_SEC_KEY) { + n = strlen(optarg); + if (n != sizeof(ctx_prm->secret_key)) { + rte_exit(EXIT_FAILURE, + "%s: invalid length %s " + "for option \'%c\' " + "must be 16 characters long\n", + __func__, optarg, opt); + } + memcpy(&ctx_prm->secret_key, optarg, + sizeof(ctx_prm->secret_key)); + } + + else { rte_exit(EXIT_FAILURE, "%s: unknown option: \'%c\'\n", __func__, opt); |