From: Jingjing Wu <jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: dev-VfR2kkLFssw@public.gmane.org
Subject: [PATCH v2 3/3] testpmd: Commands to test ctrl_pkt filter
Date: Wed, 22 Oct 2014 16:19:37 +0800 [thread overview]
Message-ID: <1413965977-15165-4-git-send-email-jingjing.wu@intel.com> (raw)
In-Reply-To: <1413965977-15165-1-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Add commands to test control packet filter
- add/delete control packet filter
Signed-off-by: Jingjing Wu <jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
app/test-pmd/cmdline.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 149 insertions(+)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 0b972f9..78a73ac 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -660,6 +660,11 @@ static void cmd_help_long_parsed(void *parsed_result,
"get_flex_filter (port_id) index (idx)\n"
" get info of a flex filter.\n\n"
+
+ "ctrl_pkt_filter (port_id) (add|del)"
+ " mac_addr (mac_address) ethertype (ether_type)"
+ " (none|options) queue (queue_id)\n"
+ " Add/Del a control packet filter.\n\n"
);
}
}
@@ -7414,6 +7419,149 @@ cmdline_parse_inst_t cmd_get_flex_filter = {
NULL,
},
};
+/* *** Filters Control *** */
+
+/* *** deal with control packet filter *** */
+struct cmd_ctrl_pkt_filter_result {
+ cmdline_fixed_string_t filter;
+ uint8_t port_id;
+ cmdline_fixed_string_t ops;
+ cmdline_fixed_string_t mac_addr;
+ struct ether_addr mac_addr_value;
+ cmdline_fixed_string_t ethertype;
+ uint16_t ethertype_value;
+ cmdline_fixed_string_t options;
+ cmdline_fixed_string_t queue;
+ uint16_t queue_id;
+};
+
+cmdline_parse_token_string_t cmd_ctrl_pkt_filter_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ filter, "ctrl_pkt_filter");
+cmdline_parse_token_num_t cmd_ctrl_pkt_filter_port_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ port_id, UINT8);
+cmdline_parse_token_string_t cmd_ctrl_pkt_filter_ops =
+ TOKEN_STRING_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ ops, "add#del");
+cmdline_parse_token_string_t cmd_ctrl_pkt_filter_mac_addr =
+ TOKEN_STRING_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ mac_addr, "mac_addr");
+cmdline_parse_token_etheraddr_t cmd_ctrl_pkt_filter_mac_addr_value =
+ TOKEN_ETHERADDR_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ mac_addr_value);
+cmdline_parse_token_string_t cmd_ctrl_pkt_filter_ethertype =
+ TOKEN_STRING_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ ethertype, "ethertype");
+cmdline_parse_token_num_t cmd_ctrl_pkt_filter_ethertype_value =
+ TOKEN_NUM_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ ethertype_value, UINT16);
+cmdline_parse_token_string_t cmd_ctrl_pkt_filter_options =
+ TOKEN_STRING_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ options, NULL);
+cmdline_parse_token_string_t cmd_ctrl_pkt_filter_queue =
+ TOKEN_STRING_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ queue, "queue");
+cmdline_parse_token_num_t cmd_ctrl_pkt_filter_queue_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_ctrl_pkt_filter_result,
+ queue_id, UINT16);
+
+static inline int
+parse_ctrl_pkt_filter_options(const char *q_arg,
+ uint16_t *flags)
+{
+#define MAX_NUM_OPTIONS 3
+ char s[256];
+ char *str_fld[MAX_NUM_OPTIONS];
+ int i;
+ int num_options = -1;
+ unsigned size;
+
+ *flags = 0;
+ if (!strcmp(q_arg, "none"))
+ return 0;
+
+ size = strnlen(q_arg, sizeof(s));
+ snprintf(s, sizeof(s), "%.*s", size, q_arg);
+ num_options = rte_strsplit(s, sizeof(s), str_fld, MAX_NUM_OPTIONS, '-');
+ /* multi-options are combined by - */
+ if (num_options < 0 || num_options > MAX_NUM_OPTIONS)
+ return -1;
+ for (i = 0; i < num_options; i++) {
+ if (!strcmp(str_fld[i], "tx"))
+ *flags |= RTE_CONTROL_PACKET_FLAGS_TX;
+ if (!strcmp(str_fld[i], "mac_ignr"))
+ *flags |= RTE_CONTROL_PACKET_FLAGS_IGNORE_MAC;
+ if (!strcmp(str_fld[i], "drop"))
+ *flags |= RTE_CONTROL_PACKET_FLAGS_DROP;
+ }
+ return num_options;
+}
+
+static void
+cmd_ctrl_pkt_filter_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_ctrl_pkt_filter_result *res = parsed_result;
+ struct rte_ctrl_pkt_filter filter;
+ int ret = 0;
+
+ ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_CTRL_PKT);
+ if (ret < 0) {
+ printf("control packet filter is not supported on port %u.\n",
+ res->port_id);
+ return;
+ }
+
+ memset(&filter, 0, sizeof(filter));
+
+ (void)rte_memcpy(&filter.mac_addr, &res->mac_addr_value,
+ sizeof(struct ether_addr));
+ filter.ether_type = res->ethertype_value;
+
+ ret = parse_ctrl_pkt_filter_options(res->options, &filter.flags);
+ if (ret < 0) {
+ printf("options input is invalid.\n");
+ return;
+ }
+ if (!(filter.flags & RTE_CONTROL_PACKET_FLAGS_DROP)) {
+ filter.flags |= RTE_CONTROL_PACKET_FLAGS_TO_QUEUE;
+ filter.queue = res->queue_id;
+ }
+ if (!strcmp(res->ops, "add"))
+ ret = rte_eth_dev_filter_ctrl(res->port_id,
+ RTE_ETH_FILTER_CTRL_PKT,
+ RTE_ETH_FILTER_ADD,
+ &filter);
+ else
+ ret = rte_eth_dev_filter_ctrl(res->port_id,
+ RTE_ETH_FILTER_CTRL_PKT,
+ RTE_ETH_FILTER_DELETE,
+ &filter);
+ if (ret < 0)
+ printf("control packet filter programming error: (%s)\n",
+ strerror(-ret));
+}
+
+cmdline_parse_inst_t cmd_ctrl_pkt_filter = {
+ .f = cmd_ctrl_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "add or delete a control packet filter entry",
+ .tokens = {
+ (void *)&cmd_ctrl_pkt_filter_filter,
+ (void *)&cmd_ctrl_pkt_filter_port_id,
+ (void *)&cmd_ctrl_pkt_filter_ops,
+ (void *)&cmd_ctrl_pkt_filter_mac_addr,
+ (void *)&cmd_ctrl_pkt_filter_mac_addr_value,
+ (void *)&cmd_ctrl_pkt_filter_ethertype,
+ (void *)&cmd_ctrl_pkt_filter_ethertype_value,
+ (void *)&cmd_ctrl_pkt_filter_options,
+ (void *)&cmd_ctrl_pkt_filter_queue,
+ (void *)&cmd_ctrl_pkt_filter_queue_id,
+ NULL,
+ },
+};
/* ******************************************************************************** */
@@ -7541,6 +7689,7 @@ cmdline_parse_ctx_t main_ctx[] = {
(cmdline_parse_inst_t *)&cmd_add_flex_filter,
(cmdline_parse_inst_t *)&cmd_remove_flex_filter,
(cmdline_parse_inst_t *)&cmd_get_flex_filter,
+ (cmdline_parse_inst_t *)&cmd_ctrl_pkt_filter,
NULL,
};
--
1.8.1.4
next prev parent reply other threads:[~2014-10-22 8:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 6:59 [PATCH 0/4] support control packet filter on Fortville Jingjing Wu
[not found] ` <1411628369-29532-1-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-09-25 6:59 ` [PATCH 1/4] lib/librte_ether: new filter APIs definition Jingjing Wu
[not found] ` <1411628369-29532-2-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-10-09 15:34 ` De Lara Guarch, Pablo
[not found] ` <E115CCD9D858EF4F90C690B0DCB4D8972262A7B0-kPTMFJFq+rEMvF1YICWikbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-10 1:19 ` Wu, Jingjing
2014-10-10 3:34 ` Wu, Jingjing
[not found] ` <9BB6961774997848B5B42BEC655768F8B06167-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-10 7:28 ` De Lara Guarch, Pablo
[not found] ` <E115CCD9D858EF4F90C690B0DCB4D8972262AA29-kPTMFJFq+rEMvF1YICWikbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-16 15:11 ` Thomas Monjalon
2014-09-25 6:59 ` [PATCH 2/4] lib/librte_ether: define CTRL_PKT filter type and its structure Jingjing Wu
2014-09-25 6:59 ` [PATCH 3/4] i40e: ctrl_pkt filter implementation in i40e pmd driver Jingjing Wu
2014-09-25 6:59 ` [PATCH 4/4] app/test-pmd: add commands for control packet filter Jingjing Wu
2014-09-25 7:54 ` [PATCH 0/4] support control packet filter on Fortville Zhang, Helin
2014-10-11 7:23 ` Chen, Jing D
2014-10-11 7:23 ` Liu, Jijiang
2014-10-11 7:53 ` Zhang, Helin
2014-10-22 8:19 ` [PATCH v2 0/3] support control packet filter on fortville Jingjing Wu
[not found] ` <1413965977-15165-1-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-10-22 8:19 ` [PATCH v2 1/3] ethdev: define ctrl_pkt filter type and its structure Jingjing Wu
[not found] ` <1413965977-15165-2-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-10-30 22:47 ` Thomas Monjalon
2014-10-31 7:05 ` Wu, Jingjing
[not found] ` <9BB6961774997848B5B42BEC655768F8B26609-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-10-31 8:44 ` Thomas Monjalon
2014-11-13 5:44 ` Wu, Jingjing
[not found] ` <9BB6961774997848B5B42BEC655768F8B47F69-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-11-13 8:41 ` Thomas Monjalon
2014-11-13 9:00 ` Wu, Jingjing
2014-10-22 8:19 ` [PATCH v2 2/3] i40e: ctrl_pkt filter implementation in i40e pmd driver Jingjing Wu
2014-10-22 8:19 ` Jingjing Wu [this message]
2014-11-13 12:49 ` [PATCH v3 0/2] support ethertype filter on fortville Jingjing Wu
[not found] ` <1415882995-8697-1-git-send-email-jingjing.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2014-11-13 12:49 ` [PATCH v3 1/2] ethdev: new structure of Ethertype Filter for filter_ctrl api Jingjing Wu
2014-11-27 5:21 ` Qiu, Michael
2014-11-13 12:49 ` [PATCH v3 2/2] i40e: implement operation to add/delete an ethertype filter Jingjing Wu
2014-11-18 13:46 ` [PATCH v3 0/2] support ethertype filter on fortville Liu, Jijiang
[not found] ` <1ED644BD7E0A5F4091CF203DAFB8E4CC01D9BE50-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-11-26 22:24 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1413965977-15165-4-git-send-email-jingjing.wu@intel.com \
--to=jingjing.wu-ral2jqcrhueavxtiumwx3w@public.gmane.org \
--cc=dev-VfR2kkLFssw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.