From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0056.outbound.protection.outlook.com [104.47.1.56]) by dpdk.org (Postfix) with ESMTP id D7FF81B9F6 for ; Wed, 25 Oct 2017 16:51:48 +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=p0Cko1c/gH77AA0aaa9Mbp+pmAEK48BLK3WnrDqSFBs=; b=P89lmVA4lLRwOjuCbqVWCgOXuihazdXRTqQzkDe5qTvY07SFSz0SXR/CJ+qeypYBPRNQTHlJ3USPj/PpSz69UlO42cH8e6+BdRS4h/ZiqylqgTL/aD6+3zDrtbM+tv5HlUwWlseN+oA95eAn2GVGIKmRiAUyUm1MORvCin2ihPE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=orika@mellanox.com; Received: from localhost.localdomain (82.166.227.17) by HE1PR05MB3211.eurprd05.prod.outlook.com (2603:10a6:7:36::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.156.4; Wed, 25 Oct 2017 14:51:45 +0000 From: Ori Kam To: adrien.mazarguil@6wind.com, john.mcnamara@intel.com Cc: dev@dpdk.org, orika@mellanox.com Date: Wed, 25 Oct 2017 17:51:16 +0300 Message-Id: <951912441431780ac656221b847d2d8e50d15dec.1508940061.git.orika@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1508396139-27687-1-git-send-email-orika@mellanox.com> References: <1508396139-27687-1-git-send-email-orika@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [82.166.227.17] X-ClientProxiedBy: VI1PR0501CA0002.eurprd05.prod.outlook.com (2603:10a6:800:92::12) To HE1PR05MB3211.eurprd05.prod.outlook.com (2603:10a6:7:36::33) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e7b3a44-0007-47e9-7907-08d51bb7e9e6 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(4534020)(4602075)(4627075)(201703031133081)(201702281549075)(2017052603199); SRVR:HE1PR05MB3211; X-Microsoft-Exchange-Diagnostics: 1; HE1PR05MB3211; 3:eG4tUVm+sydJ8igRB32aOT4xDas61hjbdBhowaEVxf6u3EmiJjIQlh5O4EoQ8TvZ0d2SabzsGz4avaWLY5uq6vLFSvj0kwb000zRiiEXchkM1q4q7af0+B+x6qTjNV0sJGzz99gWLtQpSfBO9xNAk/H1TeI+lcAC2AU0daQK4V/G9DGUbVy3/qVhfuR9mbSj9mCUqsSdD1+MySLUMpgqLydYwYaC603/PCTZO7FJCis6wrhcPwv3miQ/IV3HfUIr; 25:eHVlLq09O8WP4Hz+eAQNOcFcAUcH4c+6wG4WXdzjMsEfh1xisVLaAmn4cNdW9OU0MIZGvdE6Afdqnm4GYpVhsSyHfVp7SSE8/UnXvrjWB76UsPBxyc9n0MXWCEyrV/Lv2LjyJUW89yq2qdXtzNyzXRNGEJzBFAf+waGdb0b4QHhbEPNExqpum3xgSoH9zUdOAwbxWIW2cgPogRi7AmZTZpSyaf67iRcq+MRssTH7rcD9SoBT2rii4F8IrURmgIMvzG8hXzPDrJxHHocoAcen9aeBvxzlr2VtCWZhM11KvZ7DMd1DjOgb6uyLPbx8ggP44miRE2tbLyhRbP5Hvu7FLA==; 31:z8pkTMB+OgTT0u0CG4r7qRvNQoKf0h30WQcTsElSyo03X6BN7bNiSqKKPq03mZeQWtY3F6ufB2fMzRZvaxTe8DBJNZbs66ur1tIpzuBirqmRqbUtTd6Fq18vXbILygw9UOAiD+WzbdmkBa7ucyqfYXTjq08/rJjjJTWWpU3l+6JsjTO679JbyUDn+JiM1DKKM477D92AOKV0KzqnuPYmnbSB2FGS5uWMhOVjo2JZO4A= X-MS-TrafficTypeDiagnostic: HE1PR05MB3211: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR05MB3211; 20:WUVhOtgKFKgF3Cyu2YTvFPSBiz8ph8gSfLBhsj4GktVFtjcnWMz594iglPlBVb6pDtZR+F+0ZfZi32T58dtPeATVYWcNSXBNZoPUfgjPGJqMpbqNDSAgvQrMKdOlsnYPogURi3hh81okpCgNNgFuHb0IRtvQRmyhmGTOu99CDxRM05zkSFrAXMKVmTBgAqsMkoUG0HruN+lOFn4xNI0s3EsOIFwvypovYvwIZqHACLu2hRdIA8aU4MFTjlHD7HWGNYAEa8nsEGlqxOhVGXkTVr0xNDr7RPbESHXTPU9s/p7n+up3lrfWjdIpPDOTDgya1qFeMdIxLnUtw7fH/Q6sNeROi+yum3nsAEfDWdPjW/V5+BVC1MPS+3p4z5k02XIrADD4IpbmI0naRCRmDTtvA/lAyLZeHjBKnt6Y6OR6gLgrK7oQRrR5uTtNeb8rwbj9aZxFcekelUHwA7HpCqVfOZUz9R8AhwLtHMKTOYm06YdVSPRDTgeczkd/1MvYoFMF; 4:jifyT0ygHVwB3DTHJxt3AViTxZHhBlMePpf+0GKkpcj2UjV7fEawZrBVy3gSXtsReHbS+pZVrkn0DwbIl2Afv/aF+fmYLQAhKn+xAEcZzGnYHRLMkvoeCdNcp54p54o4r9h7rtdUiH/mJWOFgp1HsUjZ6EAuem+llX/Jr9iHmLZxvHmjVj7EN6OOx6BmPZfcK7SlKKoeuheIsOlfPR+2dTXoGe1W2D/b7Ic9LYqpp/3pBaUdeMXgGIeVr3UJPLoW 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)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(3231020)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123564025)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR05MB3211; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR05MB3211; X-Forefront-PRVS: 0471B73328 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(6009001)(376002)(346002)(189002)(199003)(189998001)(5003940100001)(575784001)(6512007)(81156014)(106356001)(6666003)(2950100002)(6486002)(7736002)(305945005)(6506006)(105586002)(118296001)(107886003)(76176999)(86362001)(50986999)(33646002)(81166006)(16526018)(53936002)(101416001)(4326008)(8936002)(36756003)(47776003)(6116002)(50226002)(3846002)(50466002)(16586007)(48376002)(8676002)(2906002)(25786009)(5660300001)(316002)(68736007)(66066001)(478600001)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR05MB3211; 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; HE1PR05MB3211; 23:p+vygsrme89pKAZAeEh4kDzcbaUSbNmCIBsk1o3Ca?= =?us-ascii?Q?BFCo37NFbrDQ9TW5MSr76BXeMhs4e+Ng1xDiE8CMwaMRO+ist1Bedhh2seIY?= =?us-ascii?Q?nJ97e6thli9noMVs1BUukXcA7z3iRgOeBebkFZMtLJ+ZprTm9VH72yjzcnEo?= =?us-ascii?Q?DvTGkCSMTH7FxL/4+dTUQcIYNFaYQFZFo1dewoC3VE1U5i5Ej/J0PvnQCQ3G?= =?us-ascii?Q?3GJyxNHoh65CighMcm8q/sWpioJhCEH1Bnxu4Z3vSMjHGWUoi61TA4p6QPfm?= =?us-ascii?Q?ci/CxDWEMSYkAVAysrIrlyY2PoY51BUS1k4iWhMlXB8mDY/AnOGQu1u3KkQA?= =?us-ascii?Q?l9rkk/jlGSbPYkzCF8KXxoVR473WjZ0O66EgOOy7CaiN9cI/2uDQ0l8mFA7c?= =?us-ascii?Q?8MiDuepY4lBQQAulrd5AIxA+fxDdnqIPQBB//sB0zUU1KKHtZf+AmSgWaRNI?= =?us-ascii?Q?/C6YiAYCx7oQI3ECHkwE1nbfUAOaWTLs8KOi85/TxKkHPbFt7V6kk6Np3Ywi?= =?us-ascii?Q?qymafXUsUgLJgPnANVDptZYWfewXY0oe/cZ636miMs9CJVBhBGXUKts52S2b?= =?us-ascii?Q?ROzxBahMaP8xGV16zdMz2hgqb4LQY0SvaTjIICrhpm6Zb7gn5lgUCzJnAYHK?= =?us-ascii?Q?FK4AA9kaq/HM+gRnnVliT9b0/sIfnzZ6CH+awPAGdGLcNS8lyACAe773MrdG?= =?us-ascii?Q?ZvNFpcNEC/SxRuVREVyKHPPV4tKqWVM7wjwedqzPcBNWs2yZMA2uL9t6bW2L?= =?us-ascii?Q?iv/RAUUFU7uTBnQN2juWpNhVEdeWWnWM0t3Ed6272D+Vrk1e5XD/2/zjYOLC?= =?us-ascii?Q?oG8LRY2YLg5dpvOX9CZmmv6K4DPnoxmKaWgTd4cNC/py3erdiIuvI7hQfOGc?= =?us-ascii?Q?n8p/6O3CWheLCJ1sDoZmFwbVah+eZh1Hjd4cAiaetkNvyP+9z80PzK7yLiiJ?= =?us-ascii?Q?cSmMfMQbk+oywz7/sfGJLigM8F7uaKxCXthYs1vxaC8W0+gvVmN/d6youv8m?= =?us-ascii?Q?GcFt/f1Yv9c7E0IBu+FLbS1/2f2W3AlJNYWyc3a4PiIvJ28EyPpXj9Kf9fnV?= =?us-ascii?Q?sG3GsxIgOQ9ZKZGvRaEEUB9ybZcD2u//0VmPNl6EQ8GOEKeOgSOATejwDGkF?= =?us-ascii?Q?sfSCdMF5jY=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR05MB3211; 6:tZB34WwLjCSvbRRdhbgGjo5+NGTQJkNmWivhp3wzf4eXcpspqIYp7vzPMhk1Hgt5kMabBj9NpeS965ibCvKiBm35JIvaOp8xV0FJT8zI1WOEathskj2ZdizPSZ5kA735FgO0nfCB0hJXZ+gzBKmkLRb3GWanMc2sIz6d+ougF+j6KpOozCF5k4WfkIyv7R8KjR9CkIT0gIFHmSD1XsHAzYdyBUVYD6V+y++euRBibSug7PHXq7gPBNmbjNvgtMwp7O9H0Fc/3VAHIj7iQjtTTwJBjmiGctKYhJRNmGKwMd6dqLnB5roaLi/1upg8NF7EkyBRND4QdeC/qQJEQ8EtyA==; 5:6kq0p6WmdKFFmKMGD+E+ITGjgXYFW7lnENhrKoHfdFexs+jz3y2z+X/WBbGpxUUZnnKopR9vMjGrl/7jua2gqqVc2E8MWP7wpfC9H/IDsgMGWdMkS6h5rusynBU4qCRZaH6JPdCmk3vGXkVwuW113g==; 24:AN6GJTRcxv8/bXd7Ih/YajtLNobeFTSj9B9a/oyumVz/pezW92Ok4mWQnTOwpjrw/f6m0ZjAobA4X9jvhQW06fh02Edu//bQen5gu3t2aMc=; 7:TLl+nDf1BBJ1386NRjs2SAbnJ7FV5eCPycR2aPVWOv2La1Rpsi1iK86ioj7Q6+YZJM+4JzmiWQqC4Ps/sdSZO1Qz30SgU+QyJ3GjTEaKzVr7emz/WlELk2o9jXgbi1kXL+gFhaLoP1oJqssMVNUNKhjaAtFXZyj1Q7U85ydusrM8aWHhyKBudKolmL3FAXU0X9dOHvamfxN8jeWx9FMN0e6NaSFpzlpka3+wTXgCrmg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2017 14:51:45.1203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e7b3a44-0007-47e9-7907-08d51bb7e9e6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB3211 Subject: [dpdk-dev] [PATCH v2] 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: Wed, 25 Oct 2017 14:51:49 -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 --- v2: * Wrap log lines for readability. * Fix typo. * Small grammar changes. doc/guides/howto/index.rst | 1 + doc/guides/howto/rte_flow.rst | 333 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 334 insertions(+) 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..9028264 --- /dev/null +++ b/doc/guides/howto/rte_flow.rst @@ -0,0 +1,333 @@ +.. 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 demonstrates some concrete examples for programming flow rules +with the ``rte_flow`` APIs. + +* Detail of the rte_flow APIs can be found in the following link: + :ref:`Generic flow API ` . + +* Details of the TestPMD commands 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 whose IPv4 +destination equals 192.168.3.2. This code is equivalent to the following +testpmd command (wrapped for clarity):: + + 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) + +Output +~~~~~~ + +Terminal 1: running sample app with the 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='some interface', count=1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst='192.168.3.2'), \ + iface='some interface', 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 the 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='some interface', count=1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst ='192.168.3.2'), \ + iface='some interface', 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 whose IPv4 +destination is in the range 192.168.3.0 to 192.168.3.255. This is done using +a mask. + +This code is equivalent to the following testpmd command (wrapped for +clarity):: + + 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) + +Output +~~~~~~ + +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='some interface', count=1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst='192.168.3.2'), \ + iface='some interface', count=1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.6', dst='192.168.5.2'), \ + iface='some interface', 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='some interface', count=1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.5', dst='192.168.3.2'), \ + iface='some interface', count=1) + >> sendp(Ether()/Dot1Q()/IP(src='176.80.50.6', dst='192.168.5.2'), \ + iface='some interface', 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 is equivalent to the following testpmd command (wrapped for +clarity):: + + 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) + +Output +~~~~~~ + +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='some interface', count=1) + >> sendp(Ether()/Dot1Q(vlan=50)/IP(src='176.80.50.5', dst='192.168.3.2'), \ + iface='some interface', count=1) + >> sendp(Ether()/Dot1Q(vlan=123)/IP(src='176.80.50.6', dst='192.168.5.2'), \ + iface='some interface', 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='some interface', count=1) + >> sendp(Ether()/Dot1Q(vlan=50)/IP(src='176.80.50.5', dst='192.168.3.2'), \ + iface='some interface', count=1) + >> sendp(Ether()/Dot1Q(vlan=123)/IP(src='176.80.50.6', dst='192.168.5.2'), \ + iface='some interface', 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.8.3.1