From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50048.outbound.protection.outlook.com [40.107.5.48]) by dpdk.org (Postfix) with ESMTP id BF7BA1B450 for ; Mon, 22 Oct 2018 19:38:47 +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:X-MS-Exchange-SenderADCheck; bh=SXTXgwkKenfCtWLf9HD0dECFSDiN80F2+J0jup0NSi0=; b=S7NVwDqT57ITmsLeyDy4xyDyu59OXeTCHU0uVhsNExSWDfcBXpbeawxQgLqyKtKKrPYyAG5gCQIOissAV8cwL5k5FPgflAciiWzzyciWozfq+khF7xxqH6hgyX9w+ISOoMgGWjG+HKF1b+lcZLLEKkUEPiENp213sCA9rIvboYs= Received: from mellanox.com (37.142.13.130) by AM4PR05MB3426.eurprd05.prod.outlook.com (2603:10a6:205:6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.30; Mon, 22 Oct 2018 17:38:44 +0000 From: Ori Kam To: wenzhuo.lu@intel.com, jingjing.wu@intel.com, bernard.iremonger@intel.com, arybchenko@solarflare.com, ferruh.yigit@intel.com, stephen@networkplumber.org, adrien.mazarguil@6wind.com Cc: dev@dpdk.org, dekelp@mellanox.com, thomas@monjalon.net, nelio.laranjeiro@6wind.com, yskoh@mellanox.com, orika@mellanox.com, shahafs@mellanox.com Date: Mon, 22 Oct 2018 17:38:10 +0000 Message-Id: <1540229891-112870-3-git-send-email-orika@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1540229891-112870-1-git-send-email-orika@mellanox.com> References: <1539796072-111646-1-git-send-email-orika@mellanox.com> <1540229891-112870-1-git-send-email-orika@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: CWLP265CA0300.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:5d::24) To AM4PR05MB3426.eurprd05.prod.outlook.com (2603:10a6:205:6::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4745687f-fa42-4592-ad9f-08d638453791 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB3426; X-Microsoft-Exchange-Diagnostics: 1; AM4PR05MB3426; 3:YBihmQCg0nlfRptiGq6RsfDAoXgzZ8t+AwmEcfsYwiu9nPnF1xvjX1UVXUJGGHixGjsNtY7/+swPYBh8MyZlCkNg8bnUIcapQhV4qZNXN3lXwQaOxr9VePDpXkD3iSmAR+jsQaOfuwxlGPQFkMzF7Ut+VM8uzGMZo3fOBNkQhDyjCaJAISLiURZSz54q0Sp+WgAz9pJz81sCoq/fEIlXPWleqPVRrh6vaUMEuufJBHwsHwZxK7IqH/LCz8pBus8j; 25:fa6S6uIqyVTd0RU/I0qRGN1RGLvza2njiWb6pP+FwJZP2DgT+sNWY0F5QUrwnjh1f2r6yc1EI4v7+JDLw32t0eVWFssZkoN0XWeM1BjNbYXJhJ0OjCPPiuHPXrj04oxRHMyvpgKKDIqrX+2GtpF1nlk8XjdajyNUXGIBGQOqkn+E0dFFcaNQb8lMASCOmkEu5wR+wH39FAa9oZteqr/6mKhBcFPrGMCEn/x5QeWlnu9bj0ThI8UdEdBjCZScxcjCOqHdlpL3rtU057XyFoeTL9NGzKJmXFiNTmN0XSD2XDyVjHnyiVeuuK2sv8PBcp4WZNkiG1n+7Mtn2T6siQfxiA==; 31:32WF5RH9DPiwO3+emcJlZK9OOMU91rx9Txgxm4FUpTjrPlHky+1ouWQHwMqlHosCNjbEWBJzt+9ROSY9mn2gsr04p93/7A9NQBoMbjXfIhUeOQkXRbkn4QOcslXPuQuca9QOcCFCaCdDsrfVxFXRwOT8uUawDOylLR6siav485ldLVCcD5jNKzv3ag+Hze/vn7m0uPeDtJBndBRqsagWuI6om1Jwo/ykwnx4m6BsgNY= X-MS-TrafficTypeDiagnostic: AM4PR05MB3426: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM4PR05MB3426; 20:igEdGIacnEjuEsNEH7Dch9iZTttRkmXJ8/FZAC2n/H6xwLEzKGBz6MUcMB8/z2Ar/jihiRd9dZCZH4ipy7/rnQqkafTGocCPaXnotREHk7jjyTUwoq0nejwreJwlQuAX8SWQF3YQyzzziUqaIFH/y8k7W0kXFnl2WJil+FmTUBMKuCWhr8c+LrtAwrcuwD2I7HaSmEqhWFm+Sh+r+Fokh9RfMm0Alk3uRs9wFbao1JaBfanIzfpRPjPnBGQYM7/grQeXtgmHYoFrONnky8ObR5RPqcq+w9icXOaWCF5vOOyXwdHduU6Gf/C7ki0v0OcTHUgwnvF6i2XQEc1U0JceOB0TdrIAjh1kBD/Br/takO0g2ySWSvquitIPrARm69nzbQjG7pVfLk0h59zBiSlnQ5sK2rgn29JlhH4NdCQiC932yd85uha0ylgQ8HrK65fPBmIa1r0sH85f5nMJo1E+N8xw8fNrki2Y4I8Poe03chh8rZQxQV3JN/AOpEFKNfuN; 4:Np4uTsOGgPjJwv/vZf3pZhmH/UY8sXLiqUJzPWXNn+HSoxslZ6F+ghtwooHz1m9Yd4cnT0L1GMsG43z/DZiHxuwPseChOqYpFdNiaPp9kYLZwFy82EbRkQA0fY/PPMnITWRjn9IO+sF6OiYSgKfA1p3uyHMIgEX/R/pO/i3iwoz0aM1NwGcLwEZk2PUPNCTfHgZYdl9SRfW42DAkov7sh0a7YWS2hwypZ11ruEPuGFgfs57pxvBegOn9XMkqcRyKs7IY5rC9ACMoaw84Lx0KeuLMXa1UL7zOc4bcqyHNs40xg+k8pAGmVkXpdEcE8HoR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231355)(944501410)(52105095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:AM4PR05MB3426; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB3426; X-Forefront-PRVS: 08331F819E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(136003)(366004)(39860400002)(396003)(189003)(199004)(97736004)(478600001)(186003)(386003)(5660300001)(106356001)(6346003)(4326008)(66066001)(81166006)(81156014)(16586007)(105586002)(7416002)(26005)(53936002)(55016002)(8886007)(48376002)(4720700003)(53946003)(4744004)(68736007)(33026002)(50466002)(3846002)(7696005)(2906002)(14444005)(51416003)(486006)(107886003)(16526019)(36756003)(50226002)(6666004)(8676002)(316002)(446003)(52116002)(76176011)(8936002)(956004)(21086003)(69596002)(305945005)(7736002)(6116002)(25786009)(476003)(2616005)(47776003)(11346002)(86362001)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3426; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=orika@mellanox.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR05MB3426; 23:mthDA6J05oi0MrWxFfk6bk7WAJWaJibC1a+crgKAC?= =?us-ascii?Q?A03aZcykP+xdTJa2kFkOTjqXismhno5wEdw3PfiTZOBz0vNI2Akfm4Xix64m?= =?us-ascii?Q?99FPWpbq8Xm4u/ghCTNre+BEFC0qU5pIGH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o0Dpyd4/FfZCbO1wiEHUtoIMCYbzybHE6dw6TbOFVjSrYteG6GouSu7gIuBKgRGNaYGpXq1PI7qKgqQmwd+UGpzMJ/7+sSKYnzkA1pac4yxp4dnmn4qS2L8xsFYpLp3yUxzmTw3AugkirJZHWHcXXmuSWdW6ktabVG4XsGG4J87jQFiemLS/rwRZ89x8VKAOxPd20gLQgRjceOCgsAf8JvCLiSLEwoLWPbixe570Jt5oB9BzjCaManOGb++6FrInhqOUCGzdBd+LLq/0SAaeHgcagZRI1coi1wO8AKlMKVg==; 5:xAe/SYl8rNGyYV/QDRpV0q6POslvUYh/vVHRl4fF/jxgrtmCEiJJPuuiGmihJWon3UjJ2Iw3nyWAvKaQSghZ7kaYkn9SeahHz+6uZyf3w7+XJfz88m1SABwylsrE7m2+3q9LpDiL3jiZw4kE0KlxaDE8sbETKVEEH1TdbZMUR6s=; 7:Rz5hAhDcIobAdSoKsHkt4Z5SV0C10iUfHlk5Sm6efN5PXoh0xlDFU/FHxf/VW/SDNqu7G8rYz4SG9/pq97ng0Lsk3KzuLl71HERLKPWnx4lklccCMwEnsrJ1QIraHoBpmQaYsnpyz0lBJNo4ZzdQ2EfcMynpDvAA+BNI3JB7/T0cevzCkY53nQ+hxOOzVyIO8XsVVyIceCP59jHq7SgpjbHTsQ2zJ2QVbzO1xpVLD8SSR7oU350xNbhVMGxPMLuy SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2018 17:38:44.1366 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4745687f-fa42-4592-ad9f-08d638453791 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3426 Subject: [dpdk-dev] [PATCH v6 2/3] app/testpmd: add MPLSoUDP encapsulation 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, 22 Oct 2018 17:38:48 -0000 MPLSoUDP is an example for L3 tunnel encapsulation. L3 tunnel type is a tunnel that is missing the layer 2 header of the inner packet. Example for MPLSoUDP tunnel: ETH / IPV4 / UDP / MPLS / IP / L4..L7 In order to encapsulate such a tunnel there is a need to remove L2 of the inner packet and encap the remaining tunnel, this is done by applying 2 rte flow commands l2_decap followed by mplsoudp_encap. Both commands must appear in the same flow, and from the point of the packet it both actions are applyed at the same time. (There is no part where a packet doesn't have L2 header). Decapsulating such a tunnel works the other way, first we need to decap the outer tunnel header and then apply the new L2. So the commands will be mplsoudp_decap / l2_encap Due to the complex encapsulation of MPLSoUDP and L2 flow actions and based on the fact testpmd does not allocate memory, this patch adds a new command in testpmd to initialise a global structurs containing the necessary information to make the outer layer of the packet. This same global structures will then be used by the flow commands in testpmd when the action mplsoudp_encap, mplsoudp_decap, l2_encap, l2_decap, will be parsed, at this point, the conversion into such action becomes trivial. The l2_encap and l2_decap actions can also be used for other L3 tunnel types. Signed-off-by: Ori Kam --- v6: * fix compilation error. --- app/test-pmd/cmdline.c | 410 ++++++++++++++++++++++++++++ app/test-pmd/cmdline_flow.c | 380 ++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 40 +++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 175 ++++++++++++ 4 files changed, 1005 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 3b469ac..e807dbb 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -15282,6 +15282,408 @@ static void cmd_set_nvgre_parsed(void *parsed_result, }, }; +/** Set L2 encapsulation details */ +struct cmd_set_l2_encap_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t l2_encap; + cmdline_fixed_string_t pos_token; + cmdline_fixed_string_t ip_version; + uint32_t vlan_present:1; + uint16_t tci; + struct ether_addr eth_src; + struct ether_addr eth_dst; +}; + +cmdline_parse_token_string_t cmd_set_l2_encap_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set"); +cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap"); +cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, + "l2_encap-with-vlan"); +cmdline_parse_token_string_t cmd_set_l2_encap_ip_version = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, + "ip-version"); +cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version, + "ipv4#ipv6"); +cmdline_parse_token_string_t cmd_set_l2_encap_vlan = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, + "vlan-tci"); +cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16); +cmdline_parse_token_string_t cmd_set_l2_encap_eth_src = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, + "eth-src"); +cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value = + TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src); +cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token, + "eth-dst"); +cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value = + TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst); + +static void cmd_set_l2_encap_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_l2_encap_result *res = parsed_result; + + if (strcmp(res->l2_encap, "l2_encap") == 0) + l2_encap_conf.select_vlan = 0; + else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0) + l2_encap_conf.select_vlan = 1; + if (strcmp(res->ip_version, "ipv4") == 0) + l2_encap_conf.select_ipv4 = 1; + else if (strcmp(res->ip_version, "ipv6") == 0) + l2_encap_conf.select_ipv4 = 0; + else + return; + if (l2_encap_conf.select_vlan) + l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); + rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes, + ETHER_ADDR_LEN); + rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes, + ETHER_ADDR_LEN); +} + +cmdline_parse_inst_t cmd_set_l2_encap = { + .f = cmd_set_l2_encap_parsed, + .data = NULL, + .help_str = "set l2_encap ip-version ipv4|ipv6" + " eth-src eth-dst ", + .tokens = { + (void *)&cmd_set_l2_encap_set, + (void *)&cmd_set_l2_encap_l2_encap, + (void *)&cmd_set_l2_encap_ip_version, + (void *)&cmd_set_l2_encap_ip_version_value, + (void *)&cmd_set_l2_encap_eth_src, + (void *)&cmd_set_l2_encap_eth_src_value, + (void *)&cmd_set_l2_encap_eth_dst, + (void *)&cmd_set_l2_encap_eth_dst_value, + NULL, + }, +}; + +cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = { + .f = cmd_set_l2_encap_parsed, + .data = NULL, + .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6" + " vlan-tci eth-src eth-dst ", + .tokens = { + (void *)&cmd_set_l2_encap_set, + (void *)&cmd_set_l2_encap_l2_encap_with_vlan, + (void *)&cmd_set_l2_encap_ip_version, + (void *)&cmd_set_l2_encap_ip_version_value, + (void *)&cmd_set_l2_encap_vlan, + (void *)&cmd_set_l2_encap_vlan_value, + (void *)&cmd_set_l2_encap_eth_src, + (void *)&cmd_set_l2_encap_eth_src_value, + (void *)&cmd_set_l2_encap_eth_dst, + (void *)&cmd_set_l2_encap_eth_dst_value, + NULL, + }, +}; + +/** Set L2 decapsulation details */ +struct cmd_set_l2_decap_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t l2_decap; + cmdline_fixed_string_t pos_token; + uint32_t vlan_present:1; +}; + +cmdline_parse_token_string_t cmd_set_l2_decap_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set"); +cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap, + "l2_decap"); +cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan = + TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap, + "l2_decap-with-vlan"); + +static void cmd_set_l2_decap_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_l2_decap_result *res = parsed_result; + + if (strcmp(res->l2_decap, "l2_decap") == 0) + l2_decap_conf.select_vlan = 0; + else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0) + l2_decap_conf.select_vlan = 1; +} + +cmdline_parse_inst_t cmd_set_l2_decap = { + .f = cmd_set_l2_decap_parsed, + .data = NULL, + .help_str = "set l2_decap", + .tokens = { + (void *)&cmd_set_l2_decap_set, + (void *)&cmd_set_l2_decap_l2_decap, + NULL, + }, +}; + +cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = { + .f = cmd_set_l2_decap_parsed, + .data = NULL, + .help_str = "set l2_decap-with-vlan", + .tokens = { + (void *)&cmd_set_l2_decap_set, + (void *)&cmd_set_l2_decap_l2_decap_with_vlan, + NULL, + }, +}; + +/** Set MPLSoUDP encapsulation details */ +struct cmd_set_mplsoudp_encap_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t mplsoudp; + cmdline_fixed_string_t pos_token; + cmdline_fixed_string_t ip_version; + uint32_t vlan_present:1; + uint32_t label; + uint16_t udp_src; + uint16_t udp_dst; + cmdline_ipaddr_t ip_src; + cmdline_ipaddr_t ip_dst; + uint16_t tci; + struct ether_addr eth_src; + struct ether_addr eth_dst; +}; + +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set, + "set"); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp, + "mplsoudp_encap"); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + mplsoudp, "mplsoudp_encap-with-vlan"); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "ip-version"); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + ip_version, "ipv4#ipv6"); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "label"); +cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label, + UINT32); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "udp-src"); +cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src, + UINT16); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "udp-dst"); +cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst, + UINT16); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "ip-src"); +cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value = + TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "ip-dst"); +cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value = + TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "vlan-tci"); +cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value = + TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci, + UINT16); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "eth-src"); +cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value = + TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + eth_src); +cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst = + TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + pos_token, "eth-dst"); +cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value = + TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, + eth_dst); + +static void cmd_set_mplsoudp_encap_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_mplsoudp_encap_result *res = parsed_result; + union { + uint32_t mplsoudp_label; + uint8_t label[3]; + } id = { + .mplsoudp_label = + rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff), + }; + + if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0) + mplsoudp_encap_conf.select_vlan = 0; + else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0) + mplsoudp_encap_conf.select_vlan = 1; + if (strcmp(res->ip_version, "ipv4") == 0) + mplsoudp_encap_conf.select_ipv4 = 1; + else if (strcmp(res->ip_version, "ipv6") == 0) + mplsoudp_encap_conf.select_ipv4 = 0; + else + return; + rte_memcpy(mplsoudp_encap_conf.label, &id.label[1], 3); + mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src); + mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst); + if (mplsoudp_encap_conf.select_ipv4) { + IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src); + IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst); + } else { + IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src); + IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst); + } + if (mplsoudp_encap_conf.select_vlan) + mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci); + rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes, + ETHER_ADDR_LEN); + rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes, + ETHER_ADDR_LEN); +} + +cmdline_parse_inst_t cmd_set_mplsoudp_encap = { + .f = cmd_set_mplsoudp_encap_parsed, + .data = NULL, + .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label