From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f177.google.com (mail-wj0-f177.google.com [209.85.210.177]) by dpdk.org (Postfix) with ESMTP id 5A5D110C47 for ; Wed, 21 Dec 2016 15:52:31 +0100 (CET) Received: by mail-wj0-f177.google.com with SMTP id v7so204900825wjy.2 for ; Wed, 21 Dec 2016 06:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=ZrIHAROvNL45dYTAyLBQfsLgpSVKoKOwkpDizlHDt68=; b=pmQlCCPJJwQLBL0lQ7AUTP9CjQsaPCIn3TxqUQp3y/99CjbRNslV0tN+6Y8Uq9dJUJ pzbHha4Rekoce4LErjLz2vwKw913iOEXrGPPnQJa6DGu1PeApiGOwzmWzeLtzAbp8HPc bCouNbuz8lzM7dFV6UOoUWnNgFZKtsojiFuJXURHeBK4fw1l0VhJQzATmENvjU2ZhI8V GlgQxFZlDQmIvHrblNKSfeIsrI++Ym7NOpslU6uRxg7YGlLG2h9Wjt+TCyW8a+j99xSs VON35hEJhMZ+3DcKxaO1dOHd6fCXyXtx/cX4upfGWtywSCz/yEZxZdsOBOB/aI4Geexw d1ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ZrIHAROvNL45dYTAyLBQfsLgpSVKoKOwkpDizlHDt68=; b=ACmH4O1MRlE8cZw5mFB3TLZZB0OggdTqan3Q/aUdMJZ5wVu1uTBVjdW16suphrgOsp DuDybVTamHULEne7sYFHuG8eJZnzyarfPA7j/xgLE4L+ytHfp239Y6m55oQK7u+EZw8t CRA5sUk5kxSAvNC5q9mrSR47XEUDWz7EEv/+/b2iZ8+BPLvPHQU0XEwCsrR+VoqXs3GU jeSCQo8g641cJNgJ+2qJ3hcRJwbNWWbKzw6WTCFYfac8fDsKRT+Vddeep/GYCvai0WO8 O1VubMlaKnqds4l02ZrFAJwjiYYMu6GE4d8/7r9I20S+1EZkWI4fT10+fDWsJU72SCCQ k/TA== X-Gm-Message-State: AIkVDXIZh4dnVZVmiAF22xBOAeHfkHQz4/mBlySru9jWGofB12KttOmT8/e8aWkfQKeVSRjN X-Received: by 10.194.145.197 with SMTP id sw5mr4748231wjb.156.1482331950554; Wed, 21 Dec 2016 06:52:30 -0800 (PST) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id b15sm27513125wma.5.2016.12.21.06.52.29 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 21 Dec 2016 06:52:29 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Wed, 21 Dec 2016 15:51:30 +0100 Message-Id: <165156b37461936923ce5d62a13d3ba27d0f6d8c.1482331076.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 14/26] app/testpmd: add rte_flow item spec handler X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2016 14:52:31 -0000 Add parser code to fully set individual fields of pattern item specification 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 => last range. - mask: sets bit-mask affecting both spec and last from arbitrary value. Signed-off-by: Adrien Mazarguil Acked-by: Olga Shern --- app/test-pmd/cmdline_flow.c | 111 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index fb9489d..7bc1aa7 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -89,6 +89,10 @@ enum index { /* Validate/create pattern. */ PATTERN, + ITEM_PARAM_IS, + 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. */ }; /** Token argument. */ @@ -267,6 +272,15 @@ static const enum index next_list_attr[] = { ZERO, }; +__rte_unused +static const enum index item_param[] = { + ITEM_PARAM_IS, + ITEM_PARAM_SPEC, + ITEM_PARAM_LAST, + ITEM_PARAM_MASK, + ZERO, +}; + static const enum index next_item[] = { ITEM_END, ITEM_VOID, @@ -287,6 +301,8 @@ static int parse_init(struct context *, const struct token *, 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 +508,26 @@ static const struct token token_list[] = { .next = NEXT(next_item), .call = parse_vc, }, + [ITEM_PARAM_IS] = { + .name = "is", + .help = "match value perfectly (with full bit-mask)", + .call = parse_vc_spec, + }, + [ITEM_PARAM_SPEC] = { + .name = "spec", + .help = "match value according to configured bit-mask", + .call = parse_vc_spec, + }, + [ITEM_PARAM_LAST] = { + .name = "last", + .help = "specify upper bound to establish a range", + .call = parse_vc_spec, + }, + [ITEM_PARAM_MASK] = { + .name = "mask", + .help = "specify bit-mask with relevant bits set to one", + .call = parse_vc_spec, + }, [ITEM_NEXT] = { .name = "/", .help = "specify next pattern item", @@ -605,6 +641,7 @@ parse_init(struct context *ctx, const struct token *token, memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out)); ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; return len; } @@ -632,11 +669,13 @@ parse_vc(struct context *ctx, const struct token *token, out->command = ctx->curr; ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; out->args.vc.data = (uint8_t *)out + size; return len; } ctx->objdata = 0; ctx->object = &out->args.vc.attr; + ctx->objmask = NULL; switch (ctx->curr) { case GROUP: case PRIORITY: @@ -652,6 +691,7 @@ parse_vc(struct context *ctx, const struct token *token, (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), sizeof(double)); ctx->object = out->args.vc.pattern; + ctx->objmask = NULL; return len; case ACTIONS: out->args.vc.actions = @@ -660,6 +700,7 @@ parse_vc(struct context *ctx, const struct token *token, out->args.vc.pattern_n), sizeof(double)); ctx->object = out->args.vc.actions; + ctx->objmask = NULL; return len; default: if (!token->priv) @@ -682,6 +723,7 @@ parse_vc(struct context *ctx, const struct token *token, }; ++out->args.vc.pattern_n; ctx->object = item; + ctx->objmask = NULL; } else { const struct parse_action_priv *priv = token->priv; struct rte_flow_action *action = @@ -698,6 +740,7 @@ parse_vc(struct context *ctx, const struct token *token, }; ++out->args.vc.actions_n; ctx->object = action; + ctx->objmask = NULL; } memset(data, 0, data_size); out->args.vc.data = data; @@ -705,6 +748,60 @@ parse_vc(struct context *ctx, const struct token *token, return len; } +/** Parse pattern item parameter type. */ +static int +parse_vc_spec(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct buffer *out = buf; + struct rte_flow_item *item; + uint32_t data_size; + int index; + int objmask = 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_IS: + index = 0; + objmask = 1; + break; + case ITEM_PARAM_SPEC: + index = 0; + break; + case ITEM_PARAM_LAST: + index = 1; + break; + case ITEM_PARAM_MASK: + index = 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 = &out->args.vc.pattern[out->args.vc.pattern_n - 1]; + data_size = ctx->objdata / 3; /* spec, last, mask */ + /* Point to selected object. */ + ctx->object = out->args.vc.data + (data_size * index); + if (objmask) { + ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */ + item->mask = ctx->objmask; + } else + ctx->objmask = NULL; + /* Update relevant item pointer. */ + *((const void **[]){ &item->spec, &item->last, &item->mask })[index] = + ctx->object; + return len; +} + /** Parse tokens for destroy command. */ static int parse_destroy(struct context *ctx, const struct token *token, @@ -727,6 +824,7 @@ parse_destroy(struct context *ctx, const struct token *token, out->command = ctx->curr; ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; out->args.destroy.rule = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), sizeof(double)); @@ -737,6 +835,7 @@ parse_destroy(struct context *ctx, const struct token *token, return -1; ctx->objdata = 0; ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++; + ctx->objmask = NULL; return len; } @@ -762,6 +861,7 @@ parse_flush(struct context *ctx, const struct token *token, out->command = ctx->curr; ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; } return len; } @@ -788,6 +888,7 @@ parse_query(struct context *ctx, const struct token *token, out->command = ctx->curr; ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; } return len; } @@ -849,6 +950,7 @@ parse_list(struct context *ctx, const struct token *token, out->command = ctx->curr; ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; out->args.list.group = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), sizeof(double)); @@ -859,6 +961,7 @@ parse_list(struct context *ctx, const struct token *token, return -1; ctx->objdata = 0; ctx->object = out->args.list.group + out->args.list.group_n++; + ctx->objmask = NULL; return len; } @@ -891,6 +994,7 @@ parse_int(struct context *ctx, const struct token *token, return len; buf = (uint8_t *)ctx->object + arg->offset; size = arg->size; +objmask: switch (size) { case sizeof(uint8_t): *(uint8_t *)buf = u; @@ -907,6 +1011,11 @@ parse_int(struct context *ctx, const struct token *token, default: goto error; } + if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) { + u = -1; + buf = (uint8_t *)ctx->objmask + arg->offset; + goto objmask; + } return len; error: push_args(ctx, arg); @@ -927,6 +1036,7 @@ parse_port(struct context *ctx, const struct token *token, else { ctx->objdata = 0; ctx->object = out; + ctx->objmask = NULL; size = sizeof(*out); } ret = parse_int(ctx, token, str, len, out, size); @@ -1033,6 +1143,7 @@ cmd_flow_context_init(struct context *ctx) ctx->port = 0; ctx->objdata = 0; ctx->object = NULL; + ctx->objmask = NULL; } /** Parse a token (cmdline API). */ -- 2.1.4