From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0043.outbound.protection.outlook.com [104.47.2.43]) by dpdk.org (Postfix) with ESMTP id D2E0916E for ; Thu, 19 Oct 2017 08:56:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vJ7/2Pb2uMh90Pc0R3aGEV8u9Sz0eLx2iS4pJkwxZqs=; b=pncEl8fQ6gmOIA7iFP+xmk0f1hWaxt9H2S/NHCN5ddV/0HwTJNJBQAMDRcHUWscdYdDzjqb/jM/5oKBu999baGRIb1koIhVoiQKzjVAgqfJ/UAt0e0Gu2qpZWDLKipNrac/bFeBAvaLeGAkQFEVbzZxL9Ex5EdfQEKS+IkLeWdQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=orika@mellanox.com; Received: from localhost.localdomain (82.166.227.17) by HE1PR05MB3210.eurprd05.prod.outlook.com (2603:10a6:7:36::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Thu, 19 Oct 2017 06:56:03 +0000 From: Ori Kam To: adrien.mazarguil@6wind.com, john.mcnamara@intel.com Cc: dev@dpdk.org, orika@mellanox.com Date: Thu, 19 Oct 2017 09:55:39 +0300 Message-Id: <1508396139-27687-1-git-send-email-orika@mellanox.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [82.166.227.17] X-ClientProxiedBy: DB6PR07CA0200.eurprd07.prod.outlook.com (2603:10a6:6:42::30) To HE1PR05MB3210.eurprd05.prod.outlook.com (2603:10a6:7:36::32) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d356fbb6-3f6c-4854-ad89-08d516be776c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:HE1PR05MB3210; X-Microsoft-Exchange-Diagnostics: 1; HE1PR05MB3210; 3:lJ4pJ+7riWwHCleUFAvL1vOO4okDbYXhNnqn5NUg0WfIW08mww84K/PnYe4HdZTK/fGDTRP0FE6pKeo0J67RwO8BKA+LpJvInCUKYaA6BydMd/l79Quc9DLQW/1UirDujoS6oof9Ct3w9os+4HiHkErJZCpRj5LXvEWkZjxvmSZixnxVBOT3aaJuvYX70T1qbVpCy5D9UZ0YeBViYDaDthDrngsdC0c8BJKSIRusoOnACNdCpj5i5PhxsPPQfQDP; 25:CgUpU8pHtJQQ3JoFDVdhr4tk0ZH+6zvlfhzy82ntWG4O/sFL66y7PQMeB2KgRv4ls5Mj4nKRg+G1It3+W5NuwR1X59HUqvUTJdVpTSKGeEWj4MovzS+In9jrUkAavtPAWPHVJSuSmAMS6MHmpelBqhuWpsWHs/cxPRnmJlcpQ03LHZI3o667y6m4cGlwRdLVd1vS7Jpoz+cTraV0bK+GxtR651yYb8BAuO4s7gfcrb5nYf7iMcT/JNKS7b5dh1c+wZgG83S2md2DIynjB/KrVkRt1NKmI/yS81o1QCA0S8zKrGijRlW8Dz1w2iNAG6aybdE6sts6zz2VsekxMGgkPQ==; 31:6DaEIbfoqCS8b1C5+635CUwsvmc3TtcRLPbb7YipNmItNSr/gdyz3+v272e5sqq0WqjtKLLaPWkcGRnNkiCejG1eVcPRo3Sycv34CjnMdbsh7FexYEfUhIoWeFFzOnX9xBVRVdicSl8Qr63A1l/Ya0V4HC9o9NnGLh/78absJh16eqFQ2KkNQmsmJXAPOYw6l1lUW9sV7VbVhKiituareBVow7ZhJbBP/nkhk1O71Ls= X-MS-TrafficTypeDiagnostic: HE1PR05MB3210: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR05MB3210; 20:b/zOK2tVJEEJxrjBYrozq51kdUWl1pKawD5y4R9Ts1txDKYSS+HBJkpxy/xbhiweF38tXvn3XSBhwU32jIXfMWcq2hdSaXu0hgWvmnqhdE5GqN07x8E1Eiuddj/49+SnXuTaZBHc665J1aTKeE3+1y7Hqv27R1EaOtv43kQFsSXW9EtMAnu3QPkuZcpqx9xNLIMvM9idoecDQdHLt1ncCRoAmpTifpZ+0O2GbY5prxxCIxFYGjvdnI0pKUqcsv3KtVfhZyw3/mxcRp9YGww3m5dbk43iwb5s3p9LOud75dEck42hWNx9bF3ShYMr1ETjgpp/JHgstsEQAtmiFMDu4AfIcZrbuvAANmzJF/n4rwVDvIWpgSV+LuA3Km5P9RNdhwiz/m+L1hc8/LMZrnSpwIRLC5AjYjjIRJS4acKysOiCVVq54klPBZElB4tEma18zCWtuQRm6aKoltYjOe1K8j1s4yDqMy4P/uCpJ85V660tMH5Z7UndbTl7tp9J7nbM; 4:UNQb+BNlMfwg3QdusliO0AU7vPArfkgwsssdIU2kG9AvL35IdogWEFCv89rrBeERNnPiDa0ri04V4Vegs8CxSQbhaXiCJ5nvJskD0m7DPTODHKKBBlsU/PIMuoRJz1wZ+XIlternYthxfa/dyOuYRbcDhWyHv0fmoZjr1C2rcBxQPv5mjGioiK4XPga8jg5ODuryOyTAyjsfIG/aom5X/L/c9DQt7PkjRzvh6SdOfU6bfcbnGMT7zSzFNE9oj8hp X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR05MB3210; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR05MB3210; X-Forefront-PRVS: 0465429B7F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(39860400002)(346002)(376002)(189002)(199003)(86362001)(575784001)(16586007)(316002)(36756003)(68736007)(107886003)(6512007)(16526018)(6666003)(53936002)(5660300001)(97736004)(5003940100001)(33646002)(6116002)(3846002)(4326008)(8676002)(81166006)(81156014)(6486002)(478600001)(50986999)(101416001)(6506006)(7736002)(25786009)(305945005)(50466002)(189998001)(48376002)(105586002)(106356001)(2906002)(47776003)(50226002)(8936002)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR05MB3210; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR05MB3210; 23:/S1Yro1Lg4TdWqkwjq65SLVxJkE8jmhquqWbZ8b3x?= =?us-ascii?Q?fQ5MJA159iiv3Pv2mRrrjAjQugvkmfhx2iHLWOCt8pPevqrGgcBXL1NJVIEc?= =?us-ascii?Q?OwkyHVx8sRCKH1fto0aqk8GeTLexCJPa/QvJR32xplVGwSeWyVweSlmxxalb?= =?us-ascii?Q?RepcjGBhnajfrEawHeVfPAmrvGC7xuJdVtzf4UAk/HIeOg0ANmHq3nSp9c8y?= =?us-ascii?Q?PUhrNoJGrQ7sI40faJOG35pO2uBmo3pFFtmdd7N3dFq4ux529ahV10xsyxbD?= =?us-ascii?Q?4iFApp5T2Ku9yGEhJf4NvW+SZV84Cs+hDqbRn0ZYVAUv2KrR4tR78hBwE3TY?= =?us-ascii?Q?54uLds0/CbY7PD8gMIOancrraxl7es4fFTrSPXMMCN/yvJkGIED2airKz+Ew?= =?us-ascii?Q?cjopibH1Rl008JXfa7D2/XK+Hr1fvUYhr8R73jZLawvbsPKE6cO5oJ7vy2zE?= =?us-ascii?Q?dY3AwXvpNbHbtvI0g6TYGVMCC7DLFdpO87PjQrubWES9ai7XavL8s7USxdPC?= =?us-ascii?Q?n+WuB9n5wn5hTcTM2Xx5peArVQcKBa4Xh/HEm467FpjvD6YYSBA27E0nlYus?= =?us-ascii?Q?MXLGIS3vXWBaxhRi4ubkNyQQHkvtWbDeu1bYu4Do5aTqUo4FAq/76A95T/ux?= =?us-ascii?Q?nhu7vY/dSDj1VJIqQEnPh8ij4mWgVwNTq8fkhrTpTd+eNwzJcn+sP5zD9VF8?= =?us-ascii?Q?MD2Utvl4CePnpMiJX2d/p8WQ/IHkfg7+hseGVuHSIbae7sq1sqe+Oke5GBRQ?= =?us-ascii?Q?PPn1EZgaOL5xaVfM5I9VohPEBRYcQOTbYRd/XxreXlgNJ9BvNzeT72u0T4cy?= =?us-ascii?Q?EmGnBrW38IftcsuW55CCFJ57yEHoHeke5R27zKdWYfA+mFsEC1Pe/fRoMkeZ?= =?us-ascii?Q?qKJmABDd7d8NVW3zIWkcap5yfqKL/iRDGpNmyxHg/8T3UXLOwI4Y8IBOAtgZ?= =?us-ascii?Q?dd1tR+DiuxYQ94I3vAZ5qG5gPNWotUirC66rXwHsd1K2gGzWTZonn4SV9Dgv?= =?us-ascii?Q?0YvugrAn6ROA2fQaxZSAI4lyaBYcn6TIrxvs1upXKf0/F5Fq0766WXj09kN4?= =?us-ascii?Q?CVYtohuE/WWarBuibJyatCM0lSe+1IGrB+jmO/mFK8HbWGUgQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR05MB3210; 6:uU9jjUfjt+mgGgbGm7Gfr/9+G6GP8iUaEB5wb9RR930pK065x0ADbFpElVRsk0eHKXnZ1Pid/ngfQBbl5aCasHYXFK/3lHStTrUGSkcAhLiYvnr885iu76AJUjhyhQNDdrrugRnzZaIU624lPqt7kk5kWzf8nTtuBvUFaJ5PTxGaw3ZkbmdUHrv+du5b1rdDulsmQFv23PJNCcbL/JVQPGI/2A9rA8YQlvWT82Nc0ueXloahVU8nnYlE5NCStiPgZ3QTS4s0xXfZJY54DJbxY5PvM+UdfQnBRcir34qo60r7anGn7K/vzIeGA9DC4LBGpy9Py8fzCsZkpwUrXBolTQ==; 5:EiaiZ5OSkWNKXEwRyK6WOi1z2x6Xpfg8FIMW3Wgh592CgNDFYGehbYyERNsrjCmIpBlyd98b7sef0QnKp0j1LHAcT9J3QXsSq3PeMfsPWgDnnNpjgZ+FWrfkfnV+o27xcqLTkOHuskJgQVepRRXJVA==; 24:ju91ZwZ7Wh7pajhmd+6W1b/YytOL0dpQ4708TNxpi3kKdWKVk64B/W31mPj6/ypjUVEwWjx3Pndf5V6TT2PInECy2vmsYz9G0oHradaFlik=; 7:Uj2LGjhai3F5bggF+s35T1KFMecwGt2HeDpai4N8ixr6vTkv8vgPS6UqcKt44VfmLbhqA9ZEVSij63pRHZJ/4Q2mfs+1BB1Rf9l5hv0zHRyzxmaurrbLsBtP/3w9gEyTFoYIuu4MyKxpx9nFTo7OdiWS/8ZkNSh0QgZN8nyQ4PoDKdcTyeaQymE8zWzM/0ylkVM1jkvlJcHzmcLSgxNZBASlr22H1GwBDYz7D2SLMys= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2017 06:56:03.7563 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB3210 Subject: [dpdk-dev] [PATCH] doc: add basic howto for flow API 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: Thu, 19 Oct 2017 06:56:07 -0000 As the rte flow is a new complex module in the DPDK. In order to ease developers in to using this feature it was suggested to supply a simple howto doc. Signed-off-by: Ori Kam --- doc/guides/howto/index.rst | 1 + doc/guides/howto/rte_flow.rst | 307 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 308 insertions(+), 0 deletions(-) create mode 100644 doc/guides/howto/rte_flow.rst diff --git a/doc/guides/howto/index.rst b/doc/guides/howto/index.rst index 468939b..0a22737 100644 --- a/doc/guides/howto/index.rst +++ b/doc/guides/howto/index.rst @@ -43,3 +43,4 @@ HowTo Guides virtio_user_for_container_networking virtio_user_as_exceptional_path packet_capture_framework + rte_flow diff --git a/doc/guides/howto/rte_flow.rst b/doc/guides/howto/rte_flow.rst new file mode 100644 index 0000000..02e944c --- /dev/null +++ b/doc/guides/howto/rte_flow.rst @@ -0,0 +1,307 @@ +.. BSD LICENSE + Copyright(c) 2017 Mellanox Corporation. All rights reserved. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Mellanox Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Generic flow API - examples +=========================== + +This document function is to supply some concrete examples for programming +flow rules. + +* Detail API can be found in the following link: :ref:`Generic flow API ` . + +* Detail TestPMD command to set the flow rules can be found in the + following link: :ref:`TestPMD Flow rules ` + +Simple IPv4 drop +---------------- + +Description +~~~~~~~~~~~ + +In this example we will create a simple rule that drops packets that their IPv4 +destination equals 192.168.3.2 +This code implements the following testpmd command:: + + tpmd> flow create 0 ingress pattern eth / vlan / ipv4 dst is 192.168.3.2 / end actions drop / end + +Code +~~~~ + +.. code-block:: c + + /* create the attribute structure */ + struct rte_flow_attr attr = {.ingress = 1}; + struct rte_flow_item pattern[MAX_PATTERN_IN_FLOW]; + struct rte_flow_action actions[MAX_ACTIONS_IN_FLOW]; + struct rte_flow_item_etc eth; + struct rte_flow_item_vlan vlan; + struct rte_flow_item_ipv4 ipv4; + struct rte_flow *flow; + struct rte_flow_error error; + + /* setting the eth to pass all packets */ + pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; + pattern[0].spec = ð + + /* set the vlan to pas all packets */ + pattern[1] = RTE_FLOW_ITEM_TYPE_VLAN; + pattern[1].spec = &vlan; + + /* set the dst ipv4 packet to the required value */ + ipv4.hdr.dst_addr = htonl(0xc0a80302); + pattern[2].type = RTE_FLOW_ITEM_TYPE_IPV4; + pattern[2].spec = &ipv4; + + /* end the pattern array */ + pattern[3].type = RTE_FLOW_ITEM)TYPE_END; + + /* create the drop action */ + actions[0].type = RTE_FLOW_ACTION_TYPE_DROP; + actions[1].type = RTE_FLOW_ACTION_TYPE_END; + + /* validate and create the flow rule */ + if (!rte_flow_validate(port_id, &attr, pattern, actions, &error) + flow = rte_flow_create(port_id, &attr, pattern, actions, &error) + +Outputs sample +~~~~~~~~~~~~~~ +terminal 1: running sample app flow rule disabled:: + + ./filter-program disable + [waiting for packets] + +terminal 2: running scapy:: + + $scapy + welcome to Scapy + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.4', dst='192.168.3.1'), iface = , count 1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst='192.168.3.2'), iface = , count 1) + +terminal 1: output log:: + + received packet with src ip = 176.80.50.4 + received packet with src ip = 176.80.50.5 + +terminal 1: running sample app flow rule enabled:: + + ./filter-program enabled + [waiting for packets] + +terminal 2: running scapy:: + + $scapy + welcome to Scapy + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.4', dst='192.168.3.1'), iface = , count 1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst ='192.168.3.2'), iface = , count 1) + +terminal 1: output log:: + + received packet with src ip = 176.80.50.4 + +Range IPv4 drop +---------------- + +Description +~~~~~~~~~~~ + +In this example we will create a simple rule that drops packets that their IPv4 +destination is in the range of 192.168.3.0 to 192.168.3.255 This is done using +mask. + +This code implements the following testpmd command:: + + tpmd> flow create 0 ingress pattern eth / vlan / ipv4 dst spec 192.168.3.0 dst mask 255.255.255.0 / end actions drop / end + +Code +~~~~ + +.. code-block:: c + + struct rte_flow_attr attr = {.ingress = 1}; + struct rte_flow_item pattern[MAX_PATTERN_IN_FLOW]; + struct rte_flow_action actions[MAX_ACTIONS_IN_FLOW]; + struct rte_flow_item_etc eth; + struct rte_flow_item_vlan vlan; + struct rte_flow_item_ipv4 ipv4; + struct rte_flow_item_ipv4 ipv4_mask; + struct rte_flow *flow; + struct rte_flow_error error; + + /* setting the eth to pass all packets */ + pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; + pattern[0].spec = ð + + /* set the vlan to pas all packets */ + pattern[1] = RTE_FLOW_ITEM_TYPE_VLAN; + pattern[1].spec = &vlan; + + /* set the dst ipv4 packet to the required value */ + ipv4.hdr.dst_addr = htonl(0xc0a80300); + ipv4_mask.hdr.dst_addr = htonl(0xffffff00); + pattern[2].type = RTE_FLOW_ITEM_TYPE_IPV4; + pattern[2].spec = &ipv4; + pattern[2].mask = &ipv4_mask; + + /* end the pattern array */ + pattern[3].type = RTE_FLOW_ITEM)TYPE_END; + + /* create the drop action */ + actions[0].type = RTE_FLOW_ACTION_TYPE_DROP; + actions[1].type = RTE_FLOW_ACTION_TYPE_END; + + /* validate and create the flow rule */ + if (!rte_flow_validate(port_id, &attr, pattern, actions, &error) + flow = rte_flow_create(port_id, &attr, pattern, actions, &error) + +Outputs sample +~~~~~~~~~~~~~~ +terminal 1: running sample app flow rule disabled:: + + ./filter-program disable + [waiting for packets] + +terminal 2: running scapy:: + + $scapy + welcome to Scapy + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.4', dst='192.168.3.1'), iface = , count 1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst='192.168.3.2'), iface = , count 1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.6', dst='192.168.5.2'), iface = , count 1) + +terminal 1: output log:: + + received packet with src ip = 176.80.50.4 + received packet with src ip = 176.80.50.5 + received packet with src ip = 176.80.50.6 + +terminal 1: running sample app flow rule enabled:: + + ./filter-program enabled + [waiting for packets] + +terminal 2: running scapy:: + + $scapy + welcome to Scapy + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.4', dst='192.168.3.1'), iface = , count 1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst='192.168.3.2'), iface = , count 1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.6', dst='192.168.5.2'), iface = , count 1) + +terminal 1: output log:: + + received packet with src ip = 176.80.50.6 + +Send vlan to queue +------------------ + +Description +~~~~~~~~~~~ + +In this example we will create a rule that routes all vlan id 123 to queue 3. + +This code implements the following testpmd command:: + + tpmd> flow create 0 ingress pattern eth / vlan vid spec 123 / end actions queue index 3 / end + +Code +~~~~ + +.. code-block:: c + + struct rte_flow_attr attr = {.ingress = 1}; + struct rte_flow_item pattern[MAX_PATTERN_IN_FLOW]; + struct rte_flow_action actions[MAX_ACTIONS_IN_FLOW]; + struct rte_flow_item_etc eth; + struct rte_flow_item_vlan vlan; + struct rte_flow_action_queue queue = { .index = 3 }; + struct rte_flow *flow; + struct rte_flow_error error; + + /* setting the eth to pass all packets */ + pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; + pattern[0].spec = ð + + /* set the vlan to pas all packets */ + vlan.vid = 123; + pattern[1] = RTE_FLOW_ITEM_TYPE_VLAN; + pattern[1].spec = &vlan; + + /* end the pattern array */ + pattern[2].type = RTE_FLOW_ITEM)TYPE_END; + + /* create the drop action */ + actions[0].type = RTE_FLOW_ACTION_TYPE_QUEUE; + actions[0].conf = &queue + actions[1].type = RTE_FLOW_ACTION_TYPE_END; + + /* validate and create the flow rule */ + if (!rte_flow_validate(port_id, &attr, pattern, actions, &error) + flow = rte_flow_create(port_id, &attr, pattern, actions, &error) + +Outputs sample +~~~~~~~~~~~~~~ +terminal 1: running sample app flow rule disabled:: + + ./filter-program disable + [waiting for packets] + +terminal 2: running scapy:: + + $scapy + welcome to Scapy + >> sendp(Ether()/Dot1Q(vlan=123)/IP(src='176.80.50.4', dst='192.168.3.1'), iface = , count 1) + >> sendp(Ether()/Dot1Q(vlan=50)/IP(src='176.80.50.5', dst='192.168.3.2'), iface = , count 1) + >> sendp(Ether()/Dot1Q(vlan=123)/IP(src='176.80.50.6', dst='192.168.5.2'), iface = , count 1) + +terminal 1: output log:: + + received packet with src ip = 176.80.50.4 sent to queue 2 + received packet with src ip = 176.80.50.5 sent to queue 1 + received packet with src ip = 176.80.50.6 sent to queue 0 + +terminal 1: running sample app flow rule enabled:: + + ./filter-program enabled + [waiting for packets] + +terminal 2: running scapy:: + + $scapy + welcome to Scapy + >> sendp(Ether()/Dot1Q(vlan=123)/IP(src='176.80.50.4', dst='192.168.3.1'), iface = , count 1) + >> sendp(Ether()/Dot1Q(vlan=50)/IP(src='176.80.50.5', dst='192.168.3.2'), iface = , count 1) + >> sendp(Ether()/Dot1Q(vlan=123)/IP(src='176.80.50.6', dst='192.168.5.2'), iface = , count 1) + +terminal 1: output log:: + + received packet with src ip = 176.80.50.4 sent to queue 3 + received packet with src ip = 176.80.50.5 sent to queue 1 + received packet with src ip = 176.80.50.6 sent to queue 3 -- 1.7.1