From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f170.google.com (mail-wj0-f170.google.com [209.85.210.170]) by dpdk.org (Postfix) with ESMTP id 1375410C81 for ; Wed, 21 Dec 2016 15:52:29 +0100 (CET) Received: by mail-wj0-f170.google.com with SMTP id tk12so205735858wjb.3 for ; Wed, 21 Dec 2016 06:52:29 -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=Ri9aK0V+guT/GtrKxMeXppDEvWIUJPW8KgCVEbnSzoc=; b=iUsVYMIHIqga9h6ujmWBS8OiybNy7TX6XLvGeAme+tavF0wr7wVnPA4OpI6b5AUGk9 VVjX6iHWsGm5+GG0goIvu6uvWABJEoZtj0mCUfw7Zc8AdE8ACmzuBIhpQd4TGbyP8tzB nufKCEx3FQcA3q1+tS5QOSd6k87Uv4OxknMhBr4D3oOhjvu9wZ08tgnOZYa+POAtj7e1 TuV3KvgtQ+u2cOPrIuO26nT0EzIYTuM4Sa7jBpzwM82SmiAfqCYHVxjMaC7w33cLBMnw PVqZNawf2uF8YrV4p8mjR9ctBlciGa0IkOn7kYpcsXl0bV7U5fvQydS3iJLT4dtvFiTq Jrbg== 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=Ri9aK0V+guT/GtrKxMeXppDEvWIUJPW8KgCVEbnSzoc=; b=SB4eB5vyJ9N/1eHXGXuSQEcRrPYTyqQWEK8VTCIxXSJV7NTBa5O59SR6KDwtPk2Iit E/lU2qhCQIi22d4j9EPLydk335KgAr2lCc59rHASgFLrV0ub6WVCvwEMH44/Ra9ss4C6 yWNtDP6bbgFDhLPQ9Rmgd5y+08Z4Z364zM2dAA8uV5Lb1HW9x7dBTP4zpkZ+Wlfu5ACW aTn+5Z7svD2nPBZrQF77OiyYsjczY/bPB+7XMtlRiijRTmufZ5GSjJnBhHVaX9yHYlsp y2di168JvVJQrG2F6mZ6OfcL01/KxMucU5Rvss2vOu00DlYhG9r4/7/uPqKzSzHFuZbP bAWg== X-Gm-Message-State: AIkVDXLsAzING7/p+Vrr3+8QrH4xGbMhl8Y3xWTN5824AAFeHaOejtfrPNhFeSoTg74/lR0m X-Received: by 10.194.37.6 with SMTP id u6mr5221593wjj.20.1482331948491; Wed, 21 Dec 2016 06:52:28 -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 14sm27565524wmk.1.2016.12.21.06.52.27 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 21 Dec 2016 06:52:27 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Wed, 21 Dec 2016 15:51:29 +0100 Message-Id: <7dd982b57ca75f588ae6978a39788ab72cdb985e.1482331076.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v5 13/26] app/testpmd: add flow query command 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:29 -0000 Syntax: flow query {port_id} {rule_id} {action} Query a specific action of an existing flow rule. Signed-off-by: Adrien Mazarguil Acked-by: Olga Shern --- app/test-pmd/cmdline.c | 3 + app/test-pmd/cmdline_flow.c | 121 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 23f4b48..f768b6b 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -831,6 +831,9 @@ static void cmd_help_long_parsed(void *parsed_result, "flow flush {port_id}\n" " Destroy all flow rules.\n\n" + "flow query {port_id} {rule_id} {action}\n" + " Query an existing flow rule.\n\n" + "flow list {port_id} [group {group_id}] [...]\n" " List existing flow rules sorted by priority," " filtered by group identifiers.\n\n" diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index dc68685..fb9489d 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -69,11 +69,15 @@ enum index { CREATE, DESTROY, FLUSH, + QUERY, LIST, /* Destroy arguments. */ DESTROY_RULE, + /* Query arguments. */ + QUERY_ACTION, + /* List arguments. */ LIST_GROUP, @@ -208,6 +212,10 @@ struct buffer { uint32_t rule_n; } destroy; /**< Destroy arguments. */ struct { + uint32_t rule; + enum rte_flow_action_type action; + } query; /**< Query arguments. */ + struct { uint32_t *group; uint32_t group_n; } list; /**< List arguments. */ @@ -285,6 +293,12 @@ static int parse_destroy(struct context *, const struct token *, static int parse_flush(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_query(struct context *, const struct token *, + const char *, unsigned int, + void *, unsigned int); +static int parse_action(struct context *, const struct token *, + const char *, unsigned int, + void *, unsigned int); static int parse_list(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -296,6 +310,8 @@ static int parse_port(struct context *, const struct token *, void *, unsigned int); static int comp_none(struct context *, const struct token *, unsigned int, char *, unsigned int); +static int comp_action(struct context *, const struct token *, + unsigned int, char *, unsigned int); static int comp_port(struct context *, const struct token *, unsigned int, char *, unsigned int); static int comp_rule_id(struct context *, const struct token *, @@ -367,7 +383,8 @@ static const struct token token_list[] = { CREATE, DESTROY, FLUSH, - LIST)), + LIST, + QUERY)), .call = parse_init, }, /* Sub-level commands. */ @@ -399,6 +416,17 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct buffer, port)), .call = parse_flush, }, + [QUERY] = { + .name = "query", + .help = "query an existing flow rule", + .next = NEXT(NEXT_ENTRY(QUERY_ACTION), + NEXT_ENTRY(RULE_ID), + NEXT_ENTRY(PORT_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action), + ARGS_ENTRY(struct buffer, args.query.rule), + ARGS_ENTRY(struct buffer, port)), + .call = parse_query, + }, [LIST] = { .name = "list", .help = "list existing flow rules", @@ -414,6 +442,14 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)), .call = parse_destroy, }, + /* Query arguments. */ + [QUERY_ACTION] = { + .name = "{action}", + .type = "ACTION", + .help = "action to query, must be part of the rule", + .call = parse_action, + .comp = comp_action, + }, /* List arguments. */ [LIST_GROUP] = { .name = "group", @@ -730,6 +766,67 @@ parse_flush(struct context *ctx, const struct token *token, return len; } +/** Parse tokens for query command. */ +static int +parse_query(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct buffer *out = buf; + + /* Token name must match. */ + if (parse_default(ctx, token, str, len, NULL, 0) < 0) + return -1; + /* Nothing else to do if there is no buffer. */ + if (!out) + return len; + if (!out->command) { + if (ctx->curr != QUERY) + return -1; + if (sizeof(*out) > size) + return -1; + out->command = ctx->curr; + ctx->objdata = 0; + ctx->object = out; + } + return len; +} + +/** Parse action names. */ +static int +parse_action(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct buffer *out = buf; + const struct arg *arg = pop_args(ctx); + unsigned int i; + + (void)size; + /* Argument is expected. */ + if (!arg) + return -1; + /* Parse action name. */ + for (i = 0; next_action[i]; ++i) { + const struct parse_action_priv *priv; + + token = &token_list[next_action[i]]; + if (strncmp(token->name, str, len)) + continue; + priv = token->priv; + if (!priv) + goto error; + if (out) + memcpy((uint8_t *)ctx->object + arg->offset, + &priv->type, + arg->size); + return len; + } +error: + push_args(ctx, arg); + return -1; +} + /** Parse tokens for list command. */ static int parse_list(struct context *ctx, const struct token *token, @@ -853,6 +950,24 @@ comp_none(struct context *ctx, const struct token *token, return 0; } +/** Complete action names. */ +static int +comp_action(struct context *ctx, const struct token *token, + unsigned int ent, char *buf, unsigned int size) +{ + unsigned int i; + + (void)ctx; + (void)token; + for (i = 0; next_action[i]; ++i) + if (buf && i == ent) + return snprintf(buf, size, "%s", + token_list[next_action[i]].name); + if (buf) + return -1; + return i; +} + /** Complete available ports. */ static int comp_port(struct context *ctx, const struct token *token, @@ -1155,6 +1270,10 @@ cmd_flow_parsed(const struct buffer *in) case FLUSH: port_flow_flush(in->port); break; + case QUERY: + port_flow_query(in->port, in->args.query.rule, + in->args.query.action); + break; case LIST: port_flow_list(in->port, in->args.list.group_n, in->args.list.group); -- 2.1.4