From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f178.google.com (mail-wj0-f178.google.com [209.85.210.178]) by dpdk.org (Postfix) with ESMTP id A6E87FA81 for ; Mon, 19 Dec 2016 18:50:11 +0100 (CET) Received: by mail-wj0-f178.google.com with SMTP id xy5so155498808wjc.0 for ; Mon, 19 Dec 2016 09:50:11 -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=YhHiPXlEi8jr8f1tsGjWtvyXhNAiPGx7kp2Ku5cF230=; b=Kqt9ygWJrwaOAQfvDg3Q7Djvabe5Hzkua958HYLmD7SGfxoyiZsZGnONhsJUEgNX1w 5q+mVZEfPpS1ij+1YIu2HUARbkLOLOXsmebRI4TlNDPYDN4O87RVEB6haOKGLUgsYer1 fSuGJcqLvA/ffGax++5646auaPpXveNo3MdLP3Q5Q6XvRJLAhLD6rb88zg+i+NlmCuFl so9xvji/E2vmCEFo5gcOq5Yj8JWUG0dXZgJE8Bisxaqv8mKCSbasPLjZ2XRIKZUTufyh lP8/LCYAsdQOp+fjY7dLC24RbbUPtdr75kXJ1HQ+aIw/2VhTa1PdpD6q2qXeubZrWydj PA6w== 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=YhHiPXlEi8jr8f1tsGjWtvyXhNAiPGx7kp2Ku5cF230=; b=Fy3O5Q87k8IGo+zXQ8hKakXq8sSZfzYX5IwNl01pTOOsexOIirgEoONm0lwEcRk4la 0dYgmI6jh2PfyWaL1o4MxdFw8kLxkpW+n0Bhequ3KM6WygiDk/tGEbgYFGsANjMEAQ// z7g530/OVE/k3CB9AT/lJ4RzoXgGGArvafv1XoCNHz4uvCfJyNPvZzDx/DGlL+cd34eW DwOFyfmKXmwd5mGa+eFrq3dKKmkXoKY24pOjNkF2bGr+Qh40D14gUb1IePtdkbZRqRYE fpvsUdl9TG9WsKWITT+ne+/Jk92KsCYKSXSSyKtlKvsqtqrHXSmwZ4U3vvuw9+AV1d6k RoYw== X-Gm-Message-State: AKaTC00fPZwbbCsaG88RBfZRGoFr3DbbOGRdGHJJnWjmaB1BKhs/EI2Py3HFbe2/yOnRYkGQ X-Received: by 10.194.161.65 with SMTP id xq1mr14861775wjb.104.1482169810820; Mon, 19 Dec 2016 09:50:10 -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 l74sm18222116wmg.2.2016.12.19.09.50.09 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 19 Dec 2016 09:50:10 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Mon, 19 Dec 2016 18:49:10 +0100 Message-Id: <0ba9fab34721a7e3dae16d132a1fbb7c1a98f993.1482168851.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 20/25] app/testpmd: add items eth/vlan to flow 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: Mon, 19 Dec 2016 17:50:11 -0000 These pattern items match basic Ethernet headers (source, destination and type) and related 802.1Q/ad VLAN headers. Signed-off-by: Adrien Mazarguil Acked-by: Olga Shern --- app/test-pmd/cmdline_flow.c | 126 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index dafb07f..53709fe 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include "testpmd.h" @@ -59,6 +60,7 @@ enum index { PREFIX, BOOLEAN, STRING, + MAC_ADDR, RULE_ID, PORT_ID, GROUP_ID, @@ -114,6 +116,13 @@ enum index { ITEM_RAW_OFFSET, ITEM_RAW_LIMIT, ITEM_RAW_PATTERN, + ITEM_ETH, + ITEM_ETH_DST, + ITEM_ETH_SRC, + ITEM_ETH_TYPE, + ITEM_VLAN, + ITEM_VLAN_TPID, + ITEM_VLAN_TCI, /* Validate/create actions. */ ACTIONS, @@ -238,6 +247,14 @@ struct token { .size = (sz), \ }) +/** Same as ARGS_ENTRY() using network byte ordering. */ +#define ARGS_ENTRY_HTON(s, f) \ + (&(const struct arg){ \ + .hton = 1, \ + .offset = offsetof(s, f), \ + .size = sizeof(((s *)0)->f), \ + }) + /** Parser output buffer layout expected by cmd_flow_parsed(). */ struct buffer { enum index command; /**< Flow command. */ @@ -329,6 +346,8 @@ static const enum index next_item[] = { ITEM_VF, ITEM_PORT, ITEM_RAW, + ITEM_ETH, + ITEM_VLAN, ZERO, }; @@ -360,6 +379,21 @@ static const enum index item_raw[] = { ZERO, }; +static const enum index item_eth[] = { + ITEM_ETH_DST, + ITEM_ETH_SRC, + ITEM_ETH_TYPE, + ITEM_NEXT, + ZERO, +}; + +static const enum index item_vlan[] = { + ITEM_VLAN_TPID, + ITEM_VLAN_TCI, + ITEM_NEXT, + ZERO, +}; + static const enum index next_action[] = { ACTION_END, ACTION_VOID, @@ -402,6 +436,9 @@ static int parse_boolean(struct context *, const struct token *, static int parse_string(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_mac_addr(struct context *, const struct token *, + const char *, unsigned int, + void *, unsigned int); static int parse_port(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -465,6 +502,13 @@ static const struct token token_list[] = { .call = parse_string, .comp = comp_none, }, + [MAC_ADDR] = { + .name = "{MAC address}", + .type = "MAC-48", + .help = "standard MAC address notation", + .call = parse_mac_addr, + .comp = comp_none, + }, [RULE_ID] = { .name = "{rule id}", .type = "RULE ID", @@ -755,6 +799,50 @@ static const struct token token_list[] = { pattern, ITEM_RAW_PATTERN_SIZE)), }, + [ITEM_ETH] = { + .name = "eth", + .help = "match Ethernet header", + .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)), + .next = NEXT(item_eth), + .call = parse_vc, + }, + [ITEM_ETH_DST] = { + .name = "dst", + .help = "destination MAC", + .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param), + .args = ARGS(ARGS_ENTRY(struct rte_flow_item_eth, dst)), + }, + [ITEM_ETH_SRC] = { + .name = "src", + .help = "source MAC", + .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param), + .args = ARGS(ARGS_ENTRY(struct rte_flow_item_eth, src)), + }, + [ITEM_ETH_TYPE] = { + .name = "type", + .help = "EtherType", + .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param), + .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)), + }, + [ITEM_VLAN] = { + .name = "vlan", + .help = "match 802.1Q/ad VLAN tag", + .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)), + .next = NEXT(item_vlan), + .call = parse_vc, + }, + [ITEM_VLAN_TPID] = { + .name = "tpid", + .help = "tag protocol identifier", + .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param), + .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tpid)), + }, + [ITEM_VLAN_TCI] = { + .name = "tci", + .help = "tag control information", + .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param), + .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)), + }, /* Validate/create actions. */ [ACTIONS] = { .name = "actions", @@ -1388,6 +1476,44 @@ parse_string(struct context *ctx, const struct token *token, return -1; } +/** + * Parse a MAC address. + * + * Last argument (ctx->args) is retrieved to determine storage size and + * location. + */ +static int +parse_mac_addr(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + const struct arg *arg = pop_args(ctx); + struct ether_addr tmp; + int ret; + + (void)token; + /* Argument is expected. */ + if (!arg) + return -1; + size = arg->size; + /* Bit-mask fill is not supported. */ + if (arg->mask || size != sizeof(tmp)) + goto error; + ret = cmdline_parse_etheraddr(NULL, str, &tmp, size); + if (ret < 0 || (unsigned int)ret != len) + goto error; + if (!ctx->object) + return len; + buf = (uint8_t *)ctx->object + arg->offset; + memcpy(buf, &tmp, size); + if (ctx->objmask) + memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size); + return len; +error: + push_args(ctx, arg); + return -1; +} + /** Boolean values (even indices stand for false). */ static const char *const boolean_name[] = { "0", "1", -- 2.1.4