From patchwork Wed Nov 16 16:23:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 17033 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id A74486CB9; Wed, 16 Nov 2016 17:25:21 +0100 (CET) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by dpdk.org (Postfix) with ESMTP id B962A5681 for ; Wed, 16 Nov 2016 17:24:26 +0100 (CET) Received: by mail-wm0-f53.google.com with SMTP id a197so249919213wmd.0 for ; Wed, 16 Nov 2016 08:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gNRUiH/MQe2XS/Ap5TtMJumKOqrC/MEIvOKTMEayRT0=; b=uqsyDmJG0H6TidjufyzOoze9dT6zdXAXGh67OoeuZwld7mBzm8jsOAahknSUTXhixU 4SKsiONKaTTmvbYYAbifw26z83yC6TUS2NBvSvVQK5jr0fVqRHnq9ymldyhqDYfKIOsb 0XqRikfRQpdlv8iO+UW9V9JNceG9lLfpsmmPZZ0RBNcI3QboO9Ti7SiiL9QPUAfWERox rboqEIwh7MqST+nfTMWPEQdJfADf53v0k17GAGjKwiA1keIoqtBo7rVy9L2VV6MaY7CA 3gYdrkeRDrg6K8J2AfIx1TljUX12aaTh6DFNFieCenSNOzpccG+kiTRxRMRO238Oh1y6 QlHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gNRUiH/MQe2XS/Ap5TtMJumKOqrC/MEIvOKTMEayRT0=; b=C+kUspQCTFS8DF98Uv+Rh3sZMOc6+CMli81ZV+s2MHScZpxPfVKpaUOl1yKIB0FvE8 RH1o6JiXZFhnKd2RZVdz4LWB+cLE1gvoJ6wk2bx86ArxFHUJOBt5886H8K5guL6eagk9 q5122uepL7arsUEU9RqnzGKo+JocEmHUADNVwaunamVKYkLnUgTX/sKmhJAEvneM9+gA /K26a07WArQfbr/0jHa0bZ6yVM+qUQ9mcovtgLhLQ+i91M4FDQD1dwjXz7jxtW9IFyDJ SIlZlZ9vp4jXW9Lc0/ItELPGuyiN5exUrfTcBMAOBtbyQmQFOEswzqobVpNBkK8IbrSD 2jdg== X-Gm-Message-State: ABUngvfqoUvCn51LQyMbgbXEftk7286mbBmi1/fzymXIiEzOK9y0HnXxOvmdyiVH0VE/D6j1 X-Received: by 10.194.248.233 with SMTP id yp9mr2560161wjc.228.1479313465926; Wed, 16 Nov 2016 08:24:25 -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 a13sm10987253wma.18.2016.11.16.08.24.24 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 16 Nov 2016 08:24:24 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Cc: Thomas Monjalon , Pablo de Lara , Olivier Matz Date: Wed, 16 Nov 2016 17:23:35 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 09/22] app/testpmd: add flow destroy command X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Syntax: flow destroy {port_id} rule {rule_id} [...] Destroy a given set of flow rules associated with a port. Signed-off-by: Adrien Mazarguil --- app/test-pmd/cmdline.c | 3 ++ app/test-pmd/cmdline_flow.c | 106 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 9f124fc..20a64b6 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -811,6 +811,9 @@ static void cmd_help_long_parsed(void *parsed_result, " (select|add)\n" " Set the input set for FDir.\n\n" + "flow destroy {port_id} rule {rule_id} [...]\n" + " Destroy specific flow rules.\n\n" + "flow flush {port_id}\n" " Destroy all flow rules.\n\n" diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 414bacc..5a8980c 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -56,6 +56,7 @@ enum index { /* Common tokens. */ INTEGER, UNSIGNED, + RULE_ID, PORT_ID, GROUP_ID, @@ -63,9 +64,13 @@ enum index { FLOW, /* Sub-level commands. */ + DESTROY, FLUSH, LIST, + /* Destroy arguments. */ + DESTROY_RULE, + /* List arguments. */ LIST_GROUP, }; @@ -165,12 +170,22 @@ struct buffer { uint16_t port; /**< Affected port ID. */ union { struct { + uint32_t *rule; + uint32_t rule_n; + } destroy; /**< Destroy arguments. */ + struct { uint32_t *group; uint32_t group_n; } list; /**< List arguments. */ } args; /**< Command arguments. */ }; +static const enum index next_destroy_attr[] = { + DESTROY_RULE, + END, + 0, +}; + static const enum index next_list_attr[] = { LIST_GROUP, END, @@ -180,6 +195,9 @@ static const enum index next_list_attr[] = { static int parse_init(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); static int parse_flush(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -196,6 +214,8 @@ static int comp_none(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 *, + unsigned int, char *, unsigned int); /** Token definitions. */ static const struct token token_list[] = { @@ -225,6 +245,13 @@ static const struct token token_list[] = { .call = parse_int, .comp = comp_none, }, + [RULE_ID] = { + .name = "{rule id}", + .type = "RULE ID", + .help = "rule identifier", + .call = parse_int, + .comp = comp_rule_id, + }, [PORT_ID] = { .name = "{port_id}", .type = "PORT ID", @@ -245,11 +272,19 @@ static const struct token token_list[] = { .type = "{command} {port_id} [{arg} [...]]", .help = "manage ingress/egress flow rules", .next = NEXT(NEXT_ENTRY - (FLUSH, + (DESTROY, + FLUSH, LIST)), .call = parse_init, }, /* Sub-level commands. */ + [DESTROY] = { + .name = "destroy", + .help = "destroy specific flow rules", + .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, port)), + .call = parse_destroy, + }, [FLUSH] = { .name = "flush", .help = "destroy all flow rules", @@ -264,6 +299,14 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct buffer, port)), .call = parse_list, }, + /* Destroy arguments. */ + [DESTROY_RULE] = { + .name = "rule", + .help = "specify a rule identifier", + .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)), + .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)), + .call = parse_destroy, + }, /* List arguments. */ [LIST_GROUP] = { .name = "group", @@ -329,6 +372,39 @@ parse_init(struct context *ctx, const struct token *token, return len; } +/** Parse tokens for destroy command. */ +static int +parse_destroy(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 != DESTROY) + return -1; + if (sizeof(*out) > size) + return -1; + out->command = ctx->curr; + ctx->object = out; + out->args.destroy.rule = + (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), + sizeof(double)); + return len; + } + if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) + + sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size) + return -1; + ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++; + return len; +} + /** Parse tokens for flush command. */ static int parse_flush(struct context *ctx, const struct token *token, @@ -494,6 +570,30 @@ comp_port(struct context *ctx, const struct token *token, return i; } +/** Complete available rule IDs. */ +static int +comp_rule_id(struct context *ctx, const struct token *token, + unsigned int ent, char *buf, unsigned int size) +{ + unsigned int i = 0; + struct rte_port *port; + struct port_flow *pf; + + (void)token; + if (port_id_is_invalid(ctx->port, DISABLED_WARN) || + ctx->port == (uint16_t)RTE_PORT_ALL) + return -1; + port = &ports[ctx->port]; + for (pf = port->flow_list; pf != NULL; pf = pf->next) { + if (buf && i == ent) + return snprintf(buf, size, "%u", pf->id); + ++i; + } + if (buf) + return -1; + return i; +} + /** Internal context. */ static struct context cmd_flow_context; @@ -736,6 +836,10 @@ static void cmd_flow_parsed(const struct buffer *in) { switch (in->command) { + case DESTROY: + port_flow_destroy(in->port, in->args.destroy.rule_n, + in->args.destroy.rule); + break; case FLUSH: port_flow_flush(in->port); break;