From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Pei, Yulong" Subject: Re: [PATCH 12/22] app/testpmd: add rte_flow item spec handler Date: Fri, 16 Dec 2016 03:01:15 +0000 Message-ID: <188971FCDA171749BED5DA74ABF3E6F03B6625B9@shsmsx102.ccr.corp.intel.com> References: <2d37e8ee1c613557e94acef94e381b72b2a535ce.1479309720.git.adrien.mazarguil@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: Thomas Monjalon , "De Lara Guarch, Pablo" , Olivier Matz , "Xing, Beilei" To: Adrien Mazarguil , "dev@dpdk.org" Return-path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 72ECE2C0A for ; Fri, 16 Dec 2016 04:01:19 +0100 (CET) In-Reply-To: <2d37e8ee1c613557e94acef94e381b72b2a535ce.1479309720.git.adrien.mazarguil@6wind.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Adrien, I try to setup the following rule, but it seems that after set 'spec' para= m, can not set 'mask' param, is it an issue here or am I wrong to use it ? testpmd> flow create 0 ingress pattern eth dst spec 00:00:00:00:09:00 dst [TOKEN]: destination MAC src [TOKEN]: source MAC type [TOKEN]: EtherType / [TOKEN]: specify next pattern item Best Regards Yulong Pei -----Original Message----- From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Adrien Mazarguil Sent: Thursday, November 17, 2016 12:24 AM To: dev@dpdk.org Cc: Thomas Monjalon ; De Lara Guarch, Pablo ; Olivier Matz Subject: [dpdk-dev] [PATCH 12/22] app/testpmd: add rte_flow item spec handl= er Add parser code to fully set individual fields of pattern item specificatio= n structures, using the following operators: - fix: sets field and applies full bit-mask for perfect matching. - spec: sets field without modifying its bit-mask. - last: sets upper value of the spec =3D> last range. - mask: sets bit-mask affecting both spec and last from arbitrary value. Signed-off-by: Adrien Mazarguil --- app/test-pmd/cmdline_flow.c | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c inde= x e70e8e2..790b4b8 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -89,6 +89,10 @@ enum index { =20 /* Validate/create pattern. */ PATTERN, + ITEM_PARAM_FIX, + ITEM_PARAM_SPEC, + ITEM_PARAM_LAST, + ITEM_PARAM_MASK, ITEM_NEXT, ITEM_END, ITEM_VOID, @@ -121,6 +125,7 @@ struct context { uint16_t port; /**< Current port ID (for completions). */ uint32_t objdata; /**< Object-specific data. */ void *object; /**< Address of current object for relative offsets. */ + void *objmask; /**< Object a full mask must be written to. */ }; =20 /** Token argument. */ @@ -267,6 +272,14 @@ static const enum index next_list_attr[] =3D { 0, }; =20 +static const enum index item_param[] =3D { + ITEM_PARAM_FIX, + ITEM_PARAM_SPEC, + ITEM_PARAM_LAST, + ITEM_PARAM_MASK, + 0, +}; + static const enum index next_item[] =3D { ITEM_END, ITEM_VOID, @@ -287,6 +300,8 @@ static int parse_init(struct context *, const struct to= ken *, static int parse_vc(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_vc_spec(struct context *, const struct token *, + const char *, unsigned int, void *, unsigned int); static int parse_destroy(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -492,6 +507,26 @@ static const struct token token_list[] =3D { .next =3D NEXT(next_item), .call =3D parse_vc, }, + [ITEM_PARAM_FIX] =3D { + .name =3D "fix", + .help =3D "match value perfectly (with full bit-mask)", + .call =3D parse_vc_spec, + }, + [ITEM_PARAM_SPEC] =3D { + .name =3D "spec", + .help =3D "match value according to configured bit-mask", + .call =3D parse_vc_spec, + }, + [ITEM_PARAM_LAST] =3D { + .name =3D "last", + .help =3D "specify upper bound to establish a range", + .call =3D parse_vc_spec, + }, + [ITEM_PARAM_MASK] =3D { + .name =3D "mask", + .help =3D "specify bit-mask with relevant bits set to one", + .call =3D parse_vc_spec, + }, [ITEM_NEXT] =3D { .name =3D "/", .help =3D "specify next pattern item", @@ -605,6 +640,7 @@ parse_init(struct context *ctx, const struct token *tok= en, memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out)); ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; return len; } =20 @@ -632,11 +668,13 @@ parse_vc(struct context *ctx, const struct token *tok= en, out->command =3D ctx->curr; ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; out->args.vc.data =3D (uint8_t *)out + size; return len; } ctx->objdata =3D 0; ctx->object =3D &out->args.vc.attr; + ctx->objmask =3D NULL; switch (ctx->curr) { case GROUP: case PRIORITY: @@ -652,6 +690,7 @@ parse_vc(struct context *ctx, const struct token *token= , (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), sizeof(double)); ctx->object =3D out->args.vc.pattern; + ctx->objmask =3D NULL; return len; case ACTIONS: out->args.vc.actions =3D @@ -660,6 +699,7 @@ parse_vc(struct context *ctx, const struct token *token= , out->args.vc.pattern_n), sizeof(double)); ctx->object =3D out->args.vc.actions; + ctx->objmask =3D NULL; return len; default: if (!token->priv) @@ -682,6 +722,7 @@ parse_vc(struct context *ctx, const struct token *token= , }; ++out->args.vc.pattern_n; ctx->object =3D item; + ctx->objmask =3D NULL; } else { const struct parse_action_priv *priv =3D token->priv; struct rte_flow_action *action =3D @@ -698,6 +739,7 @@ parse_vc(struct context *ctx, const struct token *token= , }; ++out->args.vc.actions_n; ctx->object =3D action; + ctx->objmask =3D NULL; } memset(data, 0, data_size); out->args.vc.data =3D data; @@ -705,6 +747,60 @@ parse_vc(struct context *ctx, const struct token *toke= n, return len; } =20 +/** Parse pattern item parameter type. */ static int=20 +parse_vc_spec(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct buffer *out =3D buf; + struct rte_flow_item *item; + uint32_t data_size; + int index; + int objmask =3D 0; + + (void)size; + /* Token name must match. */ + if (parse_default(ctx, token, str, len, NULL, 0) < 0) + return -1; + /* Parse parameter types. */ + switch (ctx->curr) { + case ITEM_PARAM_FIX: + index =3D 0; + objmask =3D 1; + break; + case ITEM_PARAM_SPEC: + index =3D 0; + break; + case ITEM_PARAM_LAST: + index =3D 1; + break; + case ITEM_PARAM_MASK: + index =3D 2; + break; + default: + return -1; + } + /* Nothing else to do if there is no buffer. */ + if (!out) + return len; + if (!out->args.vc.pattern_n) + return -1; + item =3D &out->args.vc.pattern[out->args.vc.pattern_n - 1]; + data_size =3D ctx->objdata / 3; /* spec, last, mask */ + /* Point to selected object. */ + ctx->object =3D out->args.vc.data + (data_size * index); + if (objmask) { + ctx->objmask =3D out->args.vc.data + (data_size * 2); /* mask */ + item->mask =3D ctx->objmask; + } else + ctx->objmask =3D NULL; + /* Update relevant item pointer. */ + *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =3D + ctx->object; + return len; +} + /** Parse tokens for destroy command. */ static int parse_destroy(struct= context *ctx, const struct token *token, @@ -727,6 +823,7 @@ parse_destroy= (struct context *ctx, const struct token *token, out->command =3D ctx->curr; ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; out->args.destroy.rule =3D (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), sizeof(double)); @@ -737,6 +834,7 @@ parse_destroy(struct context *ctx, const struct token *= token, return -1; ctx->objdata =3D 0; ctx->object =3D out->args.destroy.rule + out->args.destroy.rule_n++; + ctx->objmask =3D NULL; return len; } =20 @@ -762,6 +860,7 @@ parse_flush(struct context *ctx, const struct token *to= ken, out->command =3D ctx->curr; ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; } return len; } @@ -788,6 +887,7 @@ parse_query(struct context *ctx, const struct token *to= ken, out->command =3D ctx->curr; ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; } return len; } @@ -849,6 +949,7 @@ parse_list(struct context *ctx, const struct token *tok= en, out->command =3D ctx->curr; ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; out->args.list.group =3D (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), sizeof(double)); @@ -859,6 +960,7 @@ parse_list(struct context *ctx, const struct token *tok= en, return -1; ctx->objdata =3D 0; ctx->object =3D out->args.list.group + out->args.list.group_n++; + ctx->objmask =3D NULL; return len; } =20 @@ -891,6 +993,7 @@ parse_int(struct context *ctx, const struct token *toke= n, return len; buf =3D (uint8_t *)ctx->object + arg->offset; size =3D arg->size; +objmask: switch (size) { case sizeof(uint8_t): *(uint8_t *)buf =3D u; @@ -907,6 +1010,11 @@ parse_int(struct context *ctx, const struct token *to= ken, default: goto error; } + if (ctx->objmask && buf !=3D (uint8_t *)ctx->objmask + arg->offset) { + u =3D -1; + buf =3D (uint8_t *)ctx->objmask + arg->offset; + goto objmask; + } return len; error: push_args(ctx, arg); @@ -927,6 +1035,7 @@ parse_port(struct context *ctx, const struct token *to= ken, else { ctx->objdata =3D 0; ctx->object =3D out; + ctx->objmask =3D NULL; size =3D sizeof(*out); } ret =3D parse_int(ctx, token, str, len, out, size); @@ -1033,6 +1142,7 @@= cmd_flow_context_init(struct context *ctx) ctx->port =3D 0; ctx->objdata =3D 0; ctx->object =3D NULL; + ctx->objmask =3D NULL; } =20 /** Parse a token (cmdline API). */ -- 2.1.4