From patchwork Tue Feb 28 03:22:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Forrest Shi X-Patchwork-Id: 94601 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1163304qgi; Mon, 27 Feb 2017 20:47:16 -0800 (PST) X-Received: by 10.237.43.69 with SMTP id p63mr477582qtd.68.1488257236739; Mon, 27 Feb 2017 20:47:16 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 26si565804qku.316.2017.02.27.20.47.16; Mon, 27 Feb 2017 20:47:16 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 09A1D60940; Tue, 28 Feb 2017 04:47:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id F0F72607E6; Tue, 28 Feb 2017 04:46:12 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 916B763631; Tue, 28 Feb 2017 04:45:49 +0000 (UTC) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0122.outbound.protection.outlook.com [104.47.34.122]) by lists.linaro.org (Postfix) with ESMTPS id 7362363631 for ; Tue, 28 Feb 2017 04:39:52 +0000 (UTC) Received: from BLUPR0301CA0002.namprd03.prod.outlook.com (10.162.113.140) by BN1PR03MB108.namprd03.prod.outlook.com (10.255.201.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Tue, 28 Feb 2017 04:39:50 +0000 Received: from BY2FFO11FD009.protection.gbl (2a01:111:f400:7c0c::161) by BLUPR0301CA0002.outlook.office365.com (2a01:111:e400:5259::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12 via Frontend Transport; Tue, 28 Feb 2017 04:39:49 +0000 Received-SPF: Neutral (protection.outlook.com: 192.88.168.50 is neither permitted nor denied by domain of freescale.com) Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD009.mail.protection.outlook.com (10.1.14.73) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.933.11 via Frontend Transport; Tue, 28 Feb 2017 04:39:49 +0000 Received: from localhost (rock.ap.freescale.net [10.193.20.106]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v1S4dknT010051; Mon, 27 Feb 2017 21:39:47 -0700 From: To: Date: Tue, 28 Feb 2017 11:22:17 +0800 Message-ID: <1488252137-14939-2-git-send-email-forrest.shi@linaro.org> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1488252137-14939-1-git-send-email-forrest.shi@linaro.org> References: <1488252137-14939-1-git-send-email-forrest.shi@linaro.org> X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(7916002)(39840400002)(39860400002)(39410400002)(39850400002)(39450400003)(2980300002)(199003)(189002)(9170700003)(105586002)(53936002)(57986006)(6666003)(47776003)(76506005)(2950100002)(76176999)(38730400002)(6916009)(42882006)(50986999)(5890100001)(110136004)(92566002)(2351001)(5003940100001)(33646002)(626004)(36756003)(106466001)(5660300001)(53946003)(305945005)(48376002)(50466002)(8676002)(50226002)(8936002)(77096006)(104016004)(81166006)(54906002)(189998001)(356003)(8656002)(2876002)(2906002)(4326007)(579004)(559001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN1PR03MB108; H:tx30smr01.am.freescale.net; FPR:; SPF:Neutral; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD009; 1:cnuupFa5kpXQaPvmYiJ1rZEaVdk9HVeV6GozMpnxfQy7qx7ibOHl8eGvqjFUgrpDvive4FXEQnrFz5SmXOyZkcL2667A+6XmOILREs+laooyw/keCwqhacV8ZaVhKSaGtUJwVnR9jK96XRqJRGyoeyjVsuFIkww0QyKNl+IZefCZ1H5xSniqbtD3gCLUFqv2Eod2ojaHwRqshGx78L6gqltu6YT6OjN7OppNOWyibnLciKrJrMh0FrFO3qY1rDoeDEJaa/eiX6UWDNtlWHTgfXds25NYJ2LzJRGMwq4P6MixUEAonharCtymhZLvQeGjDh3QZsiSIDnOux4Q2ttJR/Vk9OHoLIOI/5L744cegVNaYiGAwLJxPc4XdGcKzjCkTCxWameLs8eDQOU9wmasZht757/CvaNolmpQLQq4oLbwYIoKIui3r2G1/KxpOQEngoIsPa806rEtnZ/yEu4psGjrMnRDRGDLroJbB1ED7RH019n8ocXVsvh4CqO734LIm6FwGDJ5pEyr4twFdxim2bxm5RirdikcgbvrQIkktghrkqRAufm8yvLBMdfvz1yj+ZY7Gc/GfGx0CuZx6G3j9oa4bJt3h0zqw/XyaZrjjHk= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 0fd6a41e-d2fe-4705-072c-08d45f93d444 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN1PR03MB108; X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB108; 3:bohxj4JtoIjbQpCQm2r2XUdvQeGM+lO9o3bpWQiXua1HsjAgNVJc4gi2pOStGQ9hjVJHcdx6PUIYT0LSZRoWNDO2ZtZgqrvWBbwz9FM8vqRJV7PpDhJ0HGC5PFKy7/mzwVi2Q8nXt3rALsu8wsbBlxCC6ih0WmLIIhVNJh2bPvzO15la++Jlz/m5OMx5/U5DNBmRJo2/Ir+a8pAbfrkQhX59j+aq1U3NPFMgru7IMl6ChgY4nFYXIpjNuu+ocjmXBQybbjIZorAK099OypHwBvCVPMcIy7Sca/goAxmm/2OfxmOghKbz9xDVEcH84w7NtifC+pGT42yWBM7MjOa838hl/bycmnCv1fkwAalO5LK5SttqjXmXyUpUpUAcPhKk; 25:nsuRCfeSdpXH0yY/fMHhLo2Cfgxvmu95Hn+hwshkIyQPKaGlWWbrKQ8P3cQNpu19p6puYgHcWlu/7S5QLVITR0lC46F2GScnULLNz2nWLEQx+V3fURFDGEdXEo/ZtdYSUdqjJ7PYzvofQQADjWUofaHaQ+wmDm07DhUqHyMZ8beFcbygOO/2VRtGIc9eX1KtsZPGc5RwOq4CJkTCszwww2Q0vEPaMDGzjGNrVs01rvsM4tJw+3a6tkPGxiaoZV2xQwfuwQcGmtC/FMlUvj/v4/uVu5W8bxowmbMMReMq6qnCkacDJXlrVwpNKTi2npAXwVTXMhD/Al+gI81SU4XLM3G1wL8yVDUSnnbERhTJDnGb2ZflMDfmmPeA1ZK6NFWyNHUnZIuVWbU2GBZDL4PfsKNDYbR7z9h1Ygw9kjghDIVHbjaFVBtv/mzoiHOmKMn5h0easlkGz5ETjIJGAGzAdA== X-LD-Processed: 710a03f5-10f6-4d38-9ff4-a80b81da590d,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB108; 31:0K17k5nTBr4mRM6b7pGgulDKc3CNXJmSAQTPWZ7qncBgYRtHwtPGROkqz9WmuQ7tcZcC4w+fpLsv2wwz/nXiseS6fsABq9bqJODH4piYIeTn61xlQH1oe80pedVZihzszb//DRWM2Ha6w8kzdHzJTEP8u2YhoCpAr6UJP1H55xt0YSPOASX7qLqsQ4pfXRxHGVQ72ta956ebN4dv0sOpRPOfFYc/GKaNvLFaHQBvs16gpTiBnKdCbefF4xf0wxwupZgaVOBkifxbe8AJPy3NlA==; 20:VMfC9+3LicB9nJPcWNSTI8PyKQK66sLxthyFS7zAPPaZr8cNutJprnd1kVjCGpXvRZ2yqqm8+n77LKJsnpkimxZTUbIMfES/DLH4PalNB3fS7rSmKWodTOs39gWZX7AAKwZ8e5HC8wJz2+PbZd4qlv6sGUWgswdoLlIQH4SLsQyWYaKx9BQ14dhrhJO9QV3r6N0xrU9PK0k9ZAljucDbgv7ZcnA8NyulVqk+0T+Wx/ezIA+kHYbQJa9sEmz1Wj+pcUjy663496D8MGHUBOiBx35dShoknRUyMwixsgI5hXwaOoel2gPsB6D4DmmEE1qLQxJWsURJB8BJjqw7L45Zb3aEHoEOfZTcUEJOyGiRFB+t70Ee3BOaZ/fLPMH3yS5jnbrVjPiUEs85teW1qPjup+jBC9VhHRhBwgvIyg2ROXnNmInTw8/aqMZ+Cbc9UYM0y7Bc4ZHl/h7MZwwqNmG0W0l+CM+l9zUmIgXSU3NsXpcAdRxRMdzp2/ao04vW70eHTEcM3nPfbQOSMRFgv239aS3izAnfXKRYWVBVfYyf03XxygCnkOqqqPK0Ehz8ux3FomPvMh9JFe/z6Mgui4a20LnQmfq5e57i5/nFMYZW5mk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(13015025)(13017025)(13024025)(13023025)(8121501046)(5005006)(13018025)(3002001)(10201501046)(6055026)(6041248)(20161123558025)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148); SRVR:BN1PR03MB108; BCL:0; PCL:0; RULEID:; SRVR:BN1PR03MB108; X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB108; 4:z8nGOMy6sVmLfXlwEOAaE0S6D+18QqH77FpDXVt53I3xkdcsA3q5zw0Z5hl1mlAbc36bHi+Rl/CYBoTtkndbg256Q1PWH2tqHGgCNFFi6bH5cwO6omvMp1M9d3PRGfJ+WIe7tdxvHu0WJKm2Ddyy0qf7Jqo/hDZT3Da5m9vnjBhFVvckbBsJVkYFQtsvcprvNgnpAEM/ohAElwqNXz6rpOipZm9YXeBsHJbPrroOfFt5lyxp+QAqSTCBMPdZDAs2SGL4QxqM47U7cD0pmXsb8LWDIWp7TLeI8A2/4vp7PJy8fQDDFaFCf0n9jvVcHWIbsYAmo23Q4tnXPNmH3A78m06KK2MpiAz0p1YK/SnFHPPhw/zebNTTITDVtoWyjD7mg5S1UJh1e9sTT4MnqimcXv8OAq6H/9Hl4QXcMITAoz9nv/WHukLA5KytXr9KhsTBZtxgGBVXi0+P7v00FREj012f89huajIG9IdRbZSEAA8MSXrf45+SRZkZUzGUCQxPLlTR2otfH04fKGAIyLQJnp9/cfZsF2z+ERf+vlppXfHDkoN4mITBmSBMPG+/ga8RV78+BXIFYgdKuYgO/FtJJ4B2lb6SW/8HAyyWv057hKQR/XCADkZfzpsCINLm0SCQXURPKUdMlUNlHdBShRLRjpDnKmcPXGEkpxcUIHUMD0hn+JHAhIy0oW3heaAXOh1cFq+W/neFGllga4Xi1SSSsA== X-Forefront-PRVS: 0232B30BBC X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR03MB108; 23:5YziH8uOzrFZxE09AW+vLiB/uPqLryM3RqVLeLOSE6?= czKJBc0RoiphvsDgX7+/0yYjXT36yWwDFXatGiwmrFhrxJr1E28Uxcl1nUe0s98dZrgmWKg6yxVIAlGO9XD+PQ+ype+0QR6DDcLj8sgMm6iB32El8ejtUqKaQPmNAjFKTxHyAfR0i/H/WX5fX5MJypQZIios8c9V34gbxqJGDT0XgnE41H0DtxXxXn9BoPL/gAJNDF4bh/LhdkbfO9Q+0Hh8uWytfiBuBTfNH0lbSy1I4LLPXE3wGdQVay/nbPPU6m3h+W/b4KnqQK8rDLSBjh3ddUH31U9gtJ3fNchh+Gcz7vktvQuFMCIPJYfGiH34i9qX7U3QTHxwb1BKB7SxK36V1YTE/HEZKBjr/2vibNCmx+jnUVaabOCjZSbzUWevsCWRST46yB5tfl0Qi6xU43VKQ0+MIukbQPE6ewKHXzpgI+vyjlZZ34cp19Ze0QaGT8LD/qgPrmAB+thahv/ki2msFOyL1j9vR35w4gE+ZTF2hD/zY+XlO4FK09Y5vA6u7bqe80Sqb3XmOnoKeWvP7SEdQFyxho87SwWjoXyUh/otmjDIRS8Wyy8Qd7gYigpnnHaGV4hFarbzljq1xGeVnTjzVepjdjRvWzEksVSCa77NVtl2iCmkrO0fUPQrWaJyhLNqd+ZQKD6R/kGbeJaunb9a7/l4PuON85JDB9wc3Czb9h8A57zlDePPxKJAEtRxBO26NT80Xb5l74DdIRDqMJeRipGXJwrh8H9JqNzS6m2ruFVAT3JZobmiGR9tYbk6en7n/h8XcMAQvKXECZCCz5a6hbTBTNC3na2IUCP/Pn04SocyqgEosWppysXEP4RNFFFd/fwhxst2pCLPABdFDWEZ4pN/00dRKkfcdv3Vr4Fq4mbheWuq3pBVxRiqyDUytGND/OkkZ6hqk/RxYiHa9mcTorNvnY6w25RtO4htv1/4WCuEbJxEvtLdhJXfrRJ3Tf/ts5kKti56OKCdodFx9DNnQfSKzw9e+GTNtz5OJvu2RlqTmj8X4Z/LK+2KmSItyVrCkt3ekysu2XlsBPJbLP19oNsQGyxUc6Hd9bvZornki3tXMF0sOss6txHIqrRsKwSglSvTmUZklJxvn2FGHlQLoVAncod8pmn+4ATJ8Mcokls5R2WVFpamjKt0mIwKsaf97mFPpMU0K4vF6LwxXzl76UHywjvUypeUySG3hp3z3buNUwJoLEVtqiDH3C5C8n9V+3jhjaKwKk+CyVZVr6 X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB108; 6:TNx+IY6MbRzwXB+5ystx3375qYGSKkJ9hqTru6174VEnva7lwD81ja66vVh6pXJZ7eiVlryWGW6epZhpjqorUPubOr0IMW7t1yTAGXQ/j7DPpK9XVJrFFMsOw9rWlQ8PoD5xY3PREhK5Urn1boBoSr5JkD9gahbSHbT5DgEljK02NlteYfpSv5vQW9HN25qnOe5EVto3/MjPLZnOIpCnusw49GDtFFpc3OquEP5OrdDCC49/B80nKNy3Xk+herQGqMogMIKqeoTiKRlc0wIvEDEyOy5JJ/hneNP3lrDLGuQj+wgMEDtH91Tht63Cw/rX1B1hNPGOVmekkdX+/CD36Z5mWtnVkiW+0/jm4dXVj9PcZLEv9QImwxososSZmmKqekr/F1tg/vpFBXseeF7zu907JHtqKIl3IjcHr+volxU=; 5:fZlyn4a3X1opzuko1NFw/CsMOYasQm23E1jyLIvfI6TwocOLGvO155zSqq0zix4XN+ouPGSKR6n81+N972NV7RkzpgdVqd7oF75Gcq7bV868PM+ovm1JTG0kQEi48iIvmjXCgkio3mvswu0OrJ+gfA==; 24:l+r0WJxbrvmZZY/DoM/i2EI203yk4rYyBdT3oKAb0x7FShDTIzSU56983dWrDE6Do0ko7nnbGbTzond1c1sUGSVsfOcposvfGPXtNnuOycU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN1PR03MB108; 7:gpfvqfhdxZG7t7ZB10ohLHoMTBu5OreIyCg5ySp/vQ/2H1n2fWIMFuGFIzRXPgLL4IyuOWx4x76+6qdi9oIkPWUqLywFpnPDZlPXPUDA1yJ1+Vb5LhzFn8dvDpwMtYJlYN9VZZ0CSD/boQ330WxxiPcDVUUK8V2Cbl41EbAqmGY2V6yXAnmyTb/9QPz787bocsgLS2IG4zkfgSsaVR9+cq5ATqgSWKrn5r5JoldQ4x15LabhitKhnp2HFYa9B0bzY7vaMGSc7qWmO9l7TqULXgGigh2rJAxowsEWJB4JtRzNtuOaEpEM8A+JPLB2edwWsDW9nGJo0N7aAbOwliFSAQ== X-OriginatorOrg: freescale.onmicrosoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2017 04:39:49.0113 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR03MB108 Cc: xuelin.shi@nxp.com Subject: [lng-odp] [PATCH 2/2 v3] example: introducing multi-threaded traffic management case X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Xuelin Shi introduce a new example of traffic management with following features: - multiple TM threads: one TM thread for each pktio - for small system less than 4 cores, only one TM thread created. - receiving packets from multiple pktios other than generating packets - identifying TM user by ip with individual class of service - print the user service while starting the program - print the packets counts every 10 seconds for each user Signed-off-by: Xuelin Shi --- v3: fix copyright string, add test and termination path (Maxim) v2: rebased to latest code example/Makefile.am | 3 +- example/m4/configure.m4 | 1 + example/traffic_mgmt_multi/.gitignore | 3 + example/traffic_mgmt_multi/Makefile.am | 18 + example/traffic_mgmt_multi/odp_traffic_mgmt.c | 877 +++++++++++++++++++++ example/traffic_mgmt_multi/odp_traffic_mgmt.h | 55 ++ example/traffic_mgmt_multi/odp_traffic_pktio.c | 824 +++++++++++++++++++ .../traffic_mgmt_multi/traffic_mgmt_multi_run.sh | 29 + example/traffic_mgmt_multi/udp64.pcap | Bin 0 -> 7624 bytes platform/linux-generic/odp_traffic_mngr.c | 2 +- 10 files changed, 1810 insertions(+), 2 deletions(-) create mode 100644 example/traffic_mgmt_multi/.gitignore create mode 100644 example/traffic_mgmt_multi/Makefile.am create mode 100644 example/traffic_mgmt_multi/odp_traffic_mgmt.c create mode 100644 example/traffic_mgmt_multi/odp_traffic_mgmt.h create mode 100644 example/traffic_mgmt_multi/odp_traffic_pktio.c create mode 100755 example/traffic_mgmt_multi/traffic_mgmt_multi_run.sh create mode 100644 example/traffic_mgmt_multi/udp64.pcap -- 1.8.3.1 diff --git a/example/Makefile.am b/example/Makefile.am index dfc07b6..9e21989 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -8,4 +8,5 @@ SUBDIRS = classifier \ switch \ time \ timer \ - traffic_mgmt + traffic_mgmt \ + traffic_mgmt_multi diff --git a/example/m4/configure.m4 b/example/m4/configure.m4 index 620db04..3bf48bd 100644 --- a/example/m4/configure.m4 +++ b/example/m4/configure.m4 @@ -21,4 +21,5 @@ AC_CONFIG_FILES([example/classifier/Makefile example/time/Makefile example/timer/Makefile example/traffic_mgmt/Makefile + example/traffic_mgmt_multi/Makefile example/Makefile]) diff --git a/example/traffic_mgmt_multi/.gitignore b/example/traffic_mgmt_multi/.gitignore new file mode 100644 index 0000000..d8f5468 --- /dev/null +++ b/example/traffic_mgmt_multi/.gitignore @@ -0,0 +1,3 @@ +odp_traffic_mgmt +*.log +*.trs diff --git a/example/traffic_mgmt_multi/Makefile.am b/example/traffic_mgmt_multi/Makefile.am new file mode 100644 index 0000000..a9a3561 --- /dev/null +++ b/example/traffic_mgmt_multi/Makefile.am @@ -0,0 +1,18 @@ +include $(top_srcdir)/example/Makefile.inc + +bin_PROGRAMS = odp_traffic_mgmt$(EXEEXT) +odp_traffic_mgmt_LDFLAGS = $(AM_LDFLAGS) -static +odp_traffic_mgmt_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/example -I${top_srcdir}/test + +noinst_HEADERS = $(top_srcdir)/example/example_debug.h \ + $(top_srcdir)/example/traffic_mgmt_multi/odp_traffic_mgmt.h + +dist_odp_traffic_mgmt_SOURCES = odp_traffic_mgmt.c odp_traffic_pktio.c + +if test_example +if HAVE_PCAP +TESTS = traffic_mgmt_multi_run.sh +endif +endif + +EXTRA_DIST = traffic_mgmt_multi_run.sh udp64.pcap diff --git a/example/traffic_mgmt_multi/odp_traffic_mgmt.c b/example/traffic_mgmt_multi/odp_traffic_mgmt.c new file mode 100644 index 0000000..b8539b8 --- /dev/null +++ b/example/traffic_mgmt_multi/odp_traffic_mgmt.c @@ -0,0 +1,877 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "odp_traffic_mgmt.h" + +#define TM_USER_IP_START 0x0A000001 +#define NUM_SVC_CLASSES 4 +#define USERS_PER_SVC_CLASS 2 +#define APPS_PER_USER 1 +#define TM_QUEUES_PER_APP 1 +#define NUM_USERS (USERS_PER_SVC_CLASS * NUM_SVC_CLASSES) +#define NUM_TM_QUEUES (NUM_USERS * APPS_PER_USER * TM_QUEUES_PER_APP) +#define TM_QUEUES_PER_USER (TM_QUEUES_PER_APP * APPS_PER_USER) +#define TM_QUEUES_PER_CLASS (USERS_PER_SVC_CLASS * TM_QUEUES_PER_USER) +#define MAX_NODES_PER_LEVEL (NUM_USERS * APPS_PER_USER) + +#define MAX_NB_PKTIO 32 +#define MAX_NB_USERS (NUM_USERS * APPS_PER_USER * MAX_NB_PKTIO) + +#define KBPS 1000 +#define MBPS 1000000 +#define PERCENT(percent) (100 * percent) + +#define FALSE 0 +#define TRUE 1 + +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#define RANDOM_BUF_LEN 1024 + +typedef struct { + odp_tm_shaper_params_t shaper_params; + odp_tm_threshold_params_t threshold_params; + odp_tm_wred_params_t wred_params[ODP_NUM_PACKET_COLORS]; +} profile_params_set_t; + +typedef struct { + odp_tm_shaper_t shaper_profile; + odp_tm_threshold_t threshold_profile; + odp_tm_wred_t wred_profiles[ODP_NUM_PACKET_COLORS]; +} profile_set_t; + +static profile_params_set_t COMPANY_PROFILE_PARAMS = { + .shaper_params = { + .commit_bps = 50 * MBPS, .commit_burst = 1000000, + .peak_bps = 0, .peak_burst = 0, + .dual_rate = FALSE, .shaper_len_adjust = 20 + }, + + .threshold_params = { + .max_pkts = 100000, .enable_max_pkts = TRUE, + .max_bytes = 10000000, .enable_max_bytes = TRUE + }, + + .wred_params = { + [ODP_PACKET_GREEN ... ODP_PACKET_YELLOW] = { + .min_threshold = PERCENT(70), + .med_threshold = PERCENT(90), + .med_drop_prob = PERCENT(80), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + + [ODP_PACKET_RED] = { + .min_threshold = PERCENT(40), + .med_threshold = PERCENT(70), + .med_drop_prob = PERCENT(70), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + } +}; + +static profile_params_set_t COS0_PROFILE_PARAMS = { + .shaper_params = { + .commit_bps = 1 * MBPS, .commit_burst = 100000, + .peak_bps = 4 * MBPS, .peak_burst = 200000, + .dual_rate = FALSE, .shaper_len_adjust = 20 + }, + + .threshold_params = { + .max_pkts = 10000, .enable_max_pkts = TRUE, + .max_bytes = 1000000, .enable_max_bytes = TRUE + }, + + .wred_params = { + [ODP_PACKET_GREEN ... ODP_PACKET_YELLOW] = { + .min_threshold = PERCENT(80), + .med_threshold = PERCENT(90), + .med_drop_prob = PERCENT(50), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + + [ODP_PACKET_RED] = { + .min_threshold = PERCENT(60), + .med_threshold = PERCENT(80), + .med_drop_prob = PERCENT(70), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + } +}; + +static profile_params_set_t COS1_PROFILE_PARAMS = { + .shaper_params = { + .commit_bps = 500 * KBPS, .commit_burst = 50000, + .peak_bps = 1500 * KBPS, .peak_burst = 150000, + .dual_rate = FALSE, .shaper_len_adjust = 20 + }, + + .threshold_params = { + .max_pkts = 5000, .enable_max_pkts = TRUE, + .max_bytes = 500000, .enable_max_bytes = TRUE + }, + + .wred_params = { + [ODP_PACKET_GREEN ... ODP_PACKET_YELLOW] = { + .min_threshold = PERCENT(40), + .med_threshold = PERCENT(90), + .med_drop_prob = PERCENT(70), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + + [ODP_PACKET_RED] = { + .min_threshold = PERCENT(50), + .med_threshold = PERCENT(80), + .med_drop_prob = PERCENT(80), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + } +}; + +static profile_params_set_t COS2_PROFILE_PARAMS = { + .shaper_params = { + .commit_bps = 200 * KBPS, .commit_burst = 20000, + .peak_bps = 400 * KBPS, .peak_burst = 40000, + .dual_rate = FALSE, .shaper_len_adjust = 20 + }, + + .threshold_params = { + .max_pkts = 1000, .enable_max_pkts = FALSE, + .max_bytes = 100000, .enable_max_bytes = FALSE + }, + + .wred_params = { + [ODP_PACKET_GREEN ... ODP_PACKET_YELLOW] = { + .min_threshold = PERCENT(50), + .med_threshold = PERCENT(80), + .med_drop_prob = PERCENT(70), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + + [ODP_PACKET_RED] = { + .min_threshold = PERCENT(40), + .med_threshold = PERCENT(70), + .med_drop_prob = PERCENT(80), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + } +}; + +static profile_params_set_t COS3_PROFILE_PARAMS = { + .shaper_params = { + .commit_bps = 100 * KBPS, .commit_burst = 5000, + .peak_bps = 0, .peak_burst = 0, + .dual_rate = FALSE, .shaper_len_adjust = 20 + }, + + .threshold_params = { + .max_pkts = 400, .enable_max_pkts = FALSE, + .max_bytes = 60000, .enable_max_bytes = FALSE + }, + + .wred_params = { + [ODP_PACKET_GREEN ... ODP_PACKET_YELLOW] = { + .min_threshold = PERCENT(40), + .med_threshold = PERCENT(70), + .med_drop_prob = PERCENT(80), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + + [ODP_PACKET_RED] = { + .min_threshold = PERCENT(30), + .med_threshold = PERCENT(60), + .med_drop_prob = PERCENT(80), + .max_drop_prob = PERCENT(100), + .enable_wred = TRUE, + .use_byte_fullness = FALSE, + }, + } +}; + +static profile_set_t COS_PROFILE_SETS[NUM_SVC_CLASSES]; +static profile_set_t USER_PROFILE_SETS[NUM_SVC_CLASSES]; +static profile_set_t APP_PROFILE_SETS[NUM_SVC_CLASSES][APPS_PER_USER]; + +static uint8_t random_buf[RANDOM_BUF_LEN]; +static uint32_t next_rand_byte; +odp_atomic_u64_t atomic_pkts_into_tm; +odp_atomic_u64_t atomic_pkts_from_tm; + +typedef struct { + struct { + odp_atomic_u64_t tm_pkts_in; + odp_atomic_u64_t tm_bytes_in; + odp_atomic_u64_t tm_pkts_out; + odp_atomic_u64_t tm_bytes_out; + } s; /* statistics info for each user of tm */ + uint64_t max_pkts_limit; /* max packets allowed for this user */ + uint64_t max_bytes_limit; /* max bytes allowed for this user */ + odp_bool_t enable_pkts_limit; /* max packets limit is valid */ + odp_bool_t enable_bytes_limit; /* max bytes limit is valid */ + uint32_t ipaddr; /* user ipaddr */ + int svc; /* service class */ + struct tm_cfg_port_s *tmp; /* coming from which port */ +} tm_user_t; + +/* tm config and profile for each interface */ +typedef struct tm_cfg_port_s { + int port_id; + profile_set_t port_profile; + odp_tm_t odp_tm; + uint32_t next_queue_nums[NUM_SVC_CLASSES]; + odp_tm_queue_t queue_num_tbls[NUM_SVC_CLASSES][TM_QUEUES_PER_CLASS + 1]; +} tm_port_config_t; + +/* statistics value info, used for param pass */ +typedef struct { + uint64_t pkts_in; + uint64_t pkts_out; + uint64_t bytes_in; + uint64_t bytes_out; +} stat_info_t; + +static tm_user_t tm_users[MAX_NB_USERS]; +static int nb_tm_users; +static tm_port_config_t tm_port_profiles[MAX_NB_PKTIO]; +static int nb_tm_odp; + +static profile_params_set_t *cos_profile_params[NUM_SVC_CLASSES] = { + &COS0_PROFILE_PARAMS, + &COS1_PROFILE_PARAMS, + &COS2_PROFILE_PARAMS, + &COS3_PROFILE_PARAMS +}; + +static void tester_egress_fcn(odp_packet_t odp_pkt); + +/* Returns the number of errors encountered. */ + +static uint32_t create_profile_set(profile_params_set_t *profile_params_set, + profile_set_t *profile_set, + const char *base_name, + uint32_t name_idx, + uint32_t shaper_scale, + uint32_t threshold_scale) +{ + odp_tm_threshold_params_t threshold_params, *thresholds; + odp_tm_shaper_params_t shaper_params, *shaper; + odp_tm_wred_params_t wred_params, *wred; + uint32_t err_cnt, color; + char name[64], wred_name[64]; + + err_cnt = 0; + if (name_idx == 0) + snprintf(name, sizeof(name), "%s", base_name); + else + snprintf(name, sizeof(name), "%s-%u", base_name, name_idx); + + odp_tm_shaper_params_init(&shaper_params); + shaper = &profile_params_set->shaper_params; + shaper_params.commit_bps = shaper->commit_bps * shaper_scale; + shaper_params.peak_bps = shaper->peak_bps * shaper_scale; + shaper_params.commit_burst = shaper->commit_burst * shaper_scale; + shaper_params.peak_burst = shaper->peak_burst * shaper_scale; + shaper_params.dual_rate = shaper->dual_rate; + shaper_params.shaper_len_adjust = shaper->shaper_len_adjust; + profile_set->shaper_profile = odp_tm_shaper_create(name, + &shaper_params); + if (profile_set->shaper_profile == ODP_TM_INVALID) + err_cnt++; + + odp_tm_threshold_params_init(&threshold_params); + thresholds = &profile_params_set->threshold_params; + threshold_params.max_pkts = thresholds->max_pkts * threshold_scale; + threshold_params.max_bytes = thresholds->max_bytes * threshold_scale; + threshold_params.enable_max_pkts = thresholds->enable_max_pkts; + threshold_params.enable_max_bytes = thresholds->enable_max_bytes; + profile_set->threshold_profile = + odp_tm_threshold_create(name, &threshold_params); + + if (profile_set->threshold_profile == ODP_TM_INVALID) + err_cnt++; + + for (color = 0; color < ODP_NUM_PACKET_COLORS; color++) { + snprintf(wred_name, sizeof(wred_name), "%s-%u", name, color); + + odp_tm_wred_params_init(&wred_params); + wred = &profile_params_set->wred_params[color]; + wred_params.min_threshold = wred->min_threshold; + wred_params.med_threshold = wred->med_threshold; + wred_params.med_drop_prob = wred->med_drop_prob; + wred_params.max_drop_prob = wred->max_drop_prob; + wred_params.enable_wred = wred->enable_wred; + wred_params.use_byte_fullness = wred->use_byte_fullness; + profile_set->wred_profiles[color] = + odp_tm_wred_create(wred_name, &wred_params); + if (profile_set->wred_profiles[color] == ODP_TM_INVALID) + err_cnt++; + } + + return err_cnt; +} + +static uint32_t init_profile_sets(void) +{ + uint32_t class_shaper_scale, class_threshold_scale, user_shaper_scale; + uint32_t user_threshold_scale, err_cnt, app_idx; + + class_shaper_scale = 1; + class_threshold_scale = 1; + user_shaper_scale = 1; + user_threshold_scale = 1; + err_cnt = 0; + + err_cnt += create_profile_set(&COS0_PROFILE_PARAMS, + &COS_PROFILE_SETS[0], "ServiceClass0", 0, + class_shaper_scale, + class_threshold_scale); + err_cnt += create_profile_set(&COS1_PROFILE_PARAMS, + &COS_PROFILE_SETS[1], "ServiceClass1", 0, + class_shaper_scale, + class_threshold_scale); + err_cnt += create_profile_set(&COS2_PROFILE_PARAMS, + &COS_PROFILE_SETS[2], "ServiceClass2", 0, + class_shaper_scale, + class_threshold_scale); + err_cnt += create_profile_set(&COS3_PROFILE_PARAMS, + &COS_PROFILE_SETS[3], "ServiceClass3", 0, + class_shaper_scale, + class_threshold_scale); + + err_cnt += create_profile_set(&COS0_PROFILE_PARAMS, + &USER_PROFILE_SETS[0], "UserSvc0", 0, + user_shaper_scale, user_threshold_scale); + err_cnt += create_profile_set(&COS1_PROFILE_PARAMS, + &USER_PROFILE_SETS[1], "UserSvc1", 0, + user_shaper_scale, user_threshold_scale); + err_cnt += create_profile_set(&COS2_PROFILE_PARAMS, + &USER_PROFILE_SETS[2], "UserSvc2", 0, + user_shaper_scale, user_threshold_scale); + err_cnt += create_profile_set(&COS3_PROFILE_PARAMS, + &USER_PROFILE_SETS[3], "UserSvc3", 0, + user_shaper_scale, user_threshold_scale); + + for (app_idx = 0; app_idx < APPS_PER_USER; app_idx++) { + err_cnt += create_profile_set(&COS0_PROFILE_PARAMS, + &APP_PROFILE_SETS[0][app_idx], + "AppSvc0", app_idx + 1, 1, 1); + err_cnt += create_profile_set(&COS1_PROFILE_PARAMS, + &APP_PROFILE_SETS[1][app_idx], + "AppSvc1", app_idx + 1, 1, 1); + err_cnt += create_profile_set(&COS2_PROFILE_PARAMS, + &APP_PROFILE_SETS[2][app_idx], + "AppSvc2", app_idx + 1, 1, 1); + err_cnt += create_profile_set(&COS3_PROFILE_PARAMS, + &APP_PROFILE_SETS[3][app_idx], + "AppSvc3", app_idx + 1, 1, 1); + } + + return err_cnt; +} + +static int config_example_user(tm_port_config_t *tmp, + odp_tm_node_t cos_tm_node, + uint8_t svc_class, + uint32_t user_num) +{ + odp_tm_t odp_tm_test; + odp_tm_queue_params_t tm_queue_params; + odp_tm_node_params_t tm_node_params; + odp_tm_queue_t tm_queue; + odp_tm_node_t user_tm_node; + profile_set_t *profile_set; + uint32_t app_idx, queue_idx, qnum; + char user_name[64]; + int rc, numq = 0; + + odp_tm_test = tmp->odp_tm; + profile_set = &USER_PROFILE_SETS[svc_class]; + + odp_tm_node_params_init(&tm_node_params); + tm_node_params.max_fanin = 64; + tm_node_params.shaper_profile = profile_set->shaper_profile; + tm_node_params.threshold_profile = profile_set->threshold_profile; + tm_node_params.wred_profile[ODP_PACKET_GREEN] = + profile_set->wred_profiles[0]; + tm_node_params.wred_profile[ODP_PACKET_YELLOW] = + profile_set->wred_profiles[1]; + tm_node_params.wred_profile[ODP_PACKET_RED] = + profile_set->wred_profiles[2]; + tm_node_params.level = 2; + + snprintf(user_name, sizeof(user_name), "port%d-sub%u", + tmp->port_id, user_num); + user_tm_node = odp_tm_node_create(odp_tm_test, user_name, + &tm_node_params); + odp_tm_node_connect(user_tm_node, cos_tm_node); + + for (app_idx = 0; app_idx < APPS_PER_USER; app_idx++) { + profile_set = &APP_PROFILE_SETS[svc_class][app_idx]; + for (queue_idx = 0; queue_idx < TM_QUEUES_PER_APP; + queue_idx++) { + odp_tm_queue_params_init(&tm_queue_params); + tm_queue_params.shaper_profile = + profile_set->shaper_profile; + tm_queue_params.threshold_profile = + profile_set->threshold_profile; + tm_queue_params.priority = svc_class; + + tm_queue_params.wred_profile[ODP_PACKET_GREEN] = + profile_set->wred_profiles[ODP_PACKET_GREEN]; + tm_queue_params.wred_profile[ODP_PACKET_YELLOW] = + profile_set->wred_profiles[ODP_PACKET_YELLOW]; + tm_queue_params.wred_profile[ODP_PACKET_RED] = + profile_set->wred_profiles[ODP_PACKET_RED]; + + tm_queue = odp_tm_queue_create(odp_tm_test, + &tm_queue_params); + rc = odp_tm_queue_connect(tm_queue, user_tm_node); + if (rc < 0) + return rc; + + numq++; + qnum = tmp->next_queue_nums[svc_class]; + tmp->next_queue_nums[svc_class]++; + tmp->queue_num_tbls[svc_class][qnum + 1] = tm_queue; + } + } + + return 0; +} + +static int config_company_node(const char *company_name, tm_port_config_t *tmp) +{ + profile_params_set_t *param; + odp_tm_node_params_t tm_node_params; + profile_set_t *profile_set; + odp_tm_node_t company_tm_node, cos_tm_node; + odp_tm_t odp_tm_test; + uint32_t cos_idx, user_idx; + char cos_node_name[64]; + + profile_set = &tmp->port_profile; + odp_tm_node_params_init(&tm_node_params); + tm_node_params.max_fanin = 64; + tm_node_params.shaper_profile = profile_set->shaper_profile; + tm_node_params.threshold_profile = profile_set->threshold_profile; + tm_node_params.wred_profile[ODP_PACKET_GREEN] = + profile_set->wred_profiles[0]; + tm_node_params.wred_profile[ODP_PACKET_YELLOW] = + profile_set->wred_profiles[1]; + tm_node_params.wred_profile[ODP_PACKET_RED] = + profile_set->wred_profiles[2]; + tm_node_params.level = 0; + + odp_tm_test = tmp->odp_tm; + company_tm_node = odp_tm_node_create(odp_tm_test, company_name, + &tm_node_params); + + for (cos_idx = 0; cos_idx < NUM_SVC_CLASSES; cos_idx++) { + odp_tm_node_params_init(&tm_node_params); + profile_set = &COS_PROFILE_SETS[cos_idx]; + tm_node_params.max_fanin = 64; + tm_node_params.shaper_profile = profile_set->shaper_profile; + tm_node_params.threshold_profile = + profile_set->threshold_profile; + tm_node_params.level = 1; + + tm_node_params.wred_profile[ODP_PACKET_GREEN] = + profile_set->wred_profiles[ODP_PACKET_GREEN]; + tm_node_params.wred_profile[ODP_PACKET_YELLOW] = + profile_set->wred_profiles[ODP_PACKET_YELLOW]; + tm_node_params.wred_profile[ODP_PACKET_RED] = + profile_set->wred_profiles[ODP_PACKET_RED]; + + snprintf(cos_node_name, sizeof(cos_node_name), "%s-Class-%u", + company_name, cos_idx); + cos_tm_node = odp_tm_node_create(odp_tm_test, cos_node_name, + &tm_node_params); + odp_tm_node_connect(cos_tm_node, company_tm_node); + + param = cos_profile_params[cos_idx]; + for (user_idx = 0; user_idx < USERS_PER_SVC_CLASS; user_idx++) { + tm_user_t *u; + + config_example_user(tmp, cos_tm_node, cos_idx, + cos_idx * 256 + user_idx); + u = &tm_users[nb_tm_users]; + u->svc = cos_idx; + u->ipaddr = TM_USER_IP_START + nb_tm_users; + + u->max_bytes_limit = param->threshold_params.max_bytes; + u->max_pkts_limit = param->threshold_params.max_pkts; + u->tmp = tmp; + + if (param->threshold_params.enable_max_pkts) + u->enable_pkts_limit = TRUE; + + if (param->threshold_params.enable_max_bytes) + u->enable_bytes_limit = TRUE; + nb_tm_users++; + } + } + + odp_tm_node_connect(company_tm_node, ODP_TM_ROOT); + + return 0; +} + +static int create_and_config_tm(int nb_pktio) +{ + odp_tm_level_requirements_t *per_level; + odp_tm_requirements_t requirements; + odp_tm_egress_t egress; + uint32_t level, err_cnt; + int i; + char tm_name[64]; + + err_cnt = init_profile_sets(); + if (err_cnt != 0) { + printf("%s init_profile_sets encountered %u errors\n", + __func__, err_cnt); + + return 0; + } + + odp_tm_requirements_init(&requirements); + odp_tm_egress_init(&egress); + + requirements.max_tm_queues = 10 * NUM_TM_QUEUES; + requirements.num_levels = 3; + requirements.tm_queue_shaper_needed = true; + requirements.tm_queue_wred_needed = true; + + for (level = 0; level < 3; level++) { + per_level = &requirements.per_level[level]; + per_level->max_num_tm_nodes = MAX_NODES_PER_LEVEL; + per_level->max_fanin_per_node = 64; + per_level->max_priority = 3; + per_level->min_weight = 1; + per_level->max_weight = 255; + per_level->tm_node_shaper_needed = true; + per_level->tm_node_wred_needed = true; + per_level->tm_node_dual_slope_needed = true; + per_level->fair_queuing_needed = true; + per_level->weights_needed = true; + } + + egress.egress_kind = ODP_TM_EGRESS_FN; + egress.egress_fcn = tester_egress_fcn; + + for (i = 0; i < nb_pktio; i++) { + tm_port_config_t *tmp; + + tmp = &tm_port_profiles[i]; + tmp->port_id = i; + snprintf(tm_name, 64, "TM-test-%d", i); + tmp->odp_tm = odp_tm_create(tm_name, &requirements, &egress); + if (tmp->odp_tm == ODP_TM_INVALID) + break; + + snprintf(tm_name, 64, "PortPorfiles-%d", i); + if (create_profile_set(&COMPANY_PROFILE_PARAMS, + &tmp->port_profile, tm_name, 0, 1, 1)) + break; + + snprintf(tm_name, 64, "TestPort-%d", i); + config_company_node(tm_name, tmp); + } + nb_tm_odp = i; + + return i; +} + +static uint32_t random_8(void) +{ + uint32_t rand8; + + if (RANDOM_BUF_LEN <= next_rand_byte) { + odp_random_data(random_buf, RANDOM_BUF_LEN, 1); + next_rand_byte = 0; + } + + rand8 = random_buf[next_rand_byte++]; + + return rand8; +} + +static uint32_t random_16(void) +{ + uint8_t byte1, byte2; + + if ((RANDOM_BUF_LEN - 1) <= next_rand_byte) { + odp_random_data(random_buf, RANDOM_BUF_LEN, 1); + next_rand_byte = 0; + } + + byte1 = random_buf[next_rand_byte++]; + byte2 = random_buf[next_rand_byte++]; + return (((uint16_t)byte1) << 8) | ((uint16_t)byte2); +} + +static inline uint32_t pkt_to_user(odp_packet_t pkt) +{ + odph_ipv4hdr_t *ip; + uint32_t idx; + + ip = odp_packet_l3_ptr(pkt, NULL); + idx = odp_be_to_cpu_32(ip->src_addr) - TM_USER_IP_START; + + return idx & (nb_tm_users - 1); +} + +/** + * find the packet from which user and eligible for which service. + * this should be a lookup table implementation. Here for simplicity, + * only check last byte of ip src addr to classify the users. + */ +static inline uint32_t pkt_service_class(odp_packet_t pkt) +{ + uint32_t idx; + tm_user_t *u; + + idx = pkt_to_user(pkt); + u = &tm_users[idx]; + + return u->svc; +} + +void tester_egress_fcn(odp_packet_t odp_pkt) +{ + tm_user_t *u; + uint32_t idx = pkt_to_user(odp_pkt); + + odp_atomic_inc_u64(&atomic_pkts_from_tm); + u = &tm_users[idx]; + odp_atomic_inc_u64(&u->s.tm_pkts_out); + odp_atomic_add_u64(&u->s.tm_bytes_out, odp_packet_len(odp_pkt)); + + /* not forwarding, need to free, otherwise packet pool will be full */ + odp_packet_free(odp_pkt); +} + +int tm_send_packet(odp_packet_t pkt) +{ + uint8_t rand8a, rand8b, pkt_color, drop_eligible; + uint32_t svc_class, queue_num, idx; + uint64_t bytes_in; + int rc; + tm_user_t *u; + odp_tm_queue_t tm_queue; + + idx = pkt_to_user(pkt); + u = &tm_users[idx]; + if (u->enable_pkts_limit && + u->max_pkts_limit <= odp_atomic_load_u64(&u->s.tm_pkts_in)) + return -1; + + bytes_in = odp_atomic_load_u64(&u->s.tm_bytes_in); + if (u->enable_bytes_limit && + u->max_bytes_limit <= bytes_in + odp_packet_len(pkt)) + return -1; + + rand8a = random_8(); + rand8b = random_8(); + pkt_color = (rand8a < 224) ? 0 : ((rand8a < 248) ? 1 : 2); + drop_eligible = (rand8b < 240) ? 1 : 0; + odp_packet_color_set(pkt, pkt_color); + odp_packet_drop_eligible_set(pkt, drop_eligible); + odp_packet_shaper_len_adjust_set(pkt, 24); + + svc_class = pkt_service_class(pkt); + queue_num = random_16() & (TM_QUEUES_PER_CLASS - 1); + tm_queue = u->tmp->queue_num_tbls[svc_class][queue_num + 1]; + rc = odp_tm_enq(tm_queue, pkt); + if (rc > 0) { + odp_atomic_inc_u64(&atomic_pkts_into_tm); + odp_atomic_inc_u64(&u->s.tm_pkts_in); + odp_atomic_add_u64(&u->s.tm_bytes_in, odp_packet_len(pkt)); + } + + return rc; +} + +int tm_config_and_init(int nb_pktio) +{ + int i, rc; + tm_user_t *u; + + if (NUM_USERS < NUM_SVC_CLASSES * USERS_PER_SVC_CLASS || + MAX_NB_PKTIO < nb_pktio) + return 0; + + odp_atomic_init_u64(&atomic_pkts_into_tm, 0); + odp_atomic_init_u64(&atomic_pkts_from_tm, 0); + + for (i = 0; i < MAX_NB_USERS; i++) { + u = &tm_users[i]; + odp_atomic_init_u64(&u->s.tm_pkts_in, 0); + odp_atomic_init_u64(&u->s.tm_pkts_out, 0); + odp_atomic_init_u64(&u->s.tm_bytes_in, 0); + odp_atomic_init_u64(&u->s.tm_bytes_out, 0); + } + + rc = create_and_config_tm(nb_pktio); + if (!rc) { + odp_random_data(random_buf, RANDOM_BUF_LEN, 1); + next_rand_byte = 0; + } + + return rc; +} + +static void tm_print_stat_impl(int interval, stat_info_t *prev) +{ + int i; + + printf("\nTM toal pkts_in=%" PRIu64 ", pkts_out=%" PRIu64 "\n", + odp_atomic_load_u64(&atomic_pkts_into_tm), + odp_atomic_load_u64(&atomic_pkts_from_tm)); + + printf("----------------------\n"); + for (i = 0; i < nb_tm_users; i++) { + uint64_t bps; + tm_user_t *u; + stat_info_t si, *prev_si; + + u = &tm_users[i]; + prev_si = &prev[i]; + si.pkts_in = odp_atomic_load_u64(&u->s.tm_pkts_in); + si.pkts_out = odp_atomic_load_u64(&u->s.tm_pkts_out); + si.bytes_in = odp_atomic_load_u64(&u->s.tm_bytes_in); + si.bytes_out = odp_atomic_load_u64(&u->s.tm_bytes_out); + bps = (si.bytes_out - prev_si->bytes_out) * 8 / interval; + *prev_si = si; + + printf("user %d: pkts_in=%" PRIu64 ", pkts_out=%" PRIu64 + ", bytes_in=%" PRIu64 ", bytes_out=%" PRIu64 + ", bps=%" PRIu64 "\n", i, si.pkts_in, si.pkts_out, + si.bytes_in, si.bytes_out, bps); + } + + printf("\n"); +} + +void tm_print_stat(int duration, int interval) +{ + int i; + int elapsed = 0; + int loop_forever = (duration == 0); + stat_info_t prev[MAX_NB_USERS]; + + for (i = 0; i < nb_tm_users; i++) { + tm_user_t *u; + stat_info_t *si; + + u = &tm_users[i]; + si = &prev[i]; + si->pkts_in = odp_atomic_load_u64(&u->s.tm_pkts_in); + si->pkts_out = odp_atomic_load_u64(&u->s.tm_pkts_out); + si->bytes_in = odp_atomic_load_u64(&u->s.tm_bytes_in); + si->bytes_out = odp_atomic_load_u64(&u->s.tm_bytes_out); + } + + do { + sleep(interval); + tm_print_stat_impl(interval, &prev[0]); + elapsed += interval; + } while (loop_forever || (elapsed < duration)); +} + +void tm_print_user_cos(void) +{ + int i; + char buf[80]; + + printf("\nClass Of Service\n" + "----------------------\n"); + + for (i = 0; i < NUM_SVC_CLASSES; i++) { + profile_params_set_t *p; + char *b = buf; + int n; + + p = cos_profile_params[i]; + snprintf(buf, 32, "COS%d:", i); + printf("%-12s%-16scommit bps=%" PRIu64 ", burst=%d\n", + buf, "shaper: ", p->shaper_params.commit_bps, + p->shaper_params.commit_burst); + printf("%-28speak bps=%" PRIu64 ", burst=%d\n", "", + p->shaper_params.peak_bps, + p->shaper_params.peak_burst); + + n = snprintf(buf, 80, "%-12s%-16s", "", "threshold: "); + b = buf + n; + if (p->threshold_params.enable_max_pkts) { + n = snprintf(b, 80, "max pkts=%" PRIu64, + p->threshold_params.max_pkts); + b += n; + } + if (p->threshold_params.enable_max_bytes) { + n = snprintf(b, 80, ", bytes=%" PRIu64, + p->threshold_params.max_bytes); + b += n; + } + printf("%s\n", buf); + } + printf("\nTM Users\n" + "--%6s----%6s--------%3s--\n", "userid", "ipaddr", "cos"); + for (i = 0; i < nb_tm_users; i++) { + uint8_t *p; + tm_user_t *u; + + u = &tm_users[i]; + p = (uint8_t *)&u->ipaddr; + snprintf(buf, 16, "%d.%d.%d.%d", p[3], p[2], p[1], p[0]); + printf("%6d %10s %8d\n", i, buf, u->svc); + } + printf("\n"); +} + +int tm_system_destroy(void) +{ + int i; + + for (i = 0; i < nb_tm_odp; i++) { + tm_port_config_t *tmp; + + tmp = &tm_port_profiles[i]; + if (tmp->odp_tm != ODP_TM_INVALID) + odp_tm_destroy(tmp->odp_tm); + } + + return 0; +} diff --git a/example/traffic_mgmt_multi/odp_traffic_mgmt.h b/example/traffic_mgmt_multi/odp_traffic_mgmt.h new file mode 100644 index 0000000..5eac4d4 --- /dev/null +++ b/example/traffic_mgmt_multi/odp_traffic_mgmt.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TRAFFIC_MODULE_H_ +#define _ODP_TRAFFIC_MODULE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Config and initialize the tm system. + * + * @param nb_pktio number of pktios for the tm + * @return 0 if success else -1 + */ +int tm_config_and_init(int nb_pktio); + +/** + * destroy all the tm_system(s) on termination + * + * @return 0 if success else -1 + */ +int tm_system_destroy(void); + +/** + * Print tm user stastics for each interval seconds + * + * @param duration how many seconds this function will run + * @param interval how many seconds for each print + */ +void tm_print_stat(int duration, int interval); + +/** + * Print tm service information for a user + */ +void tm_print_user_cos(void); + +/** + * Send packets to traffic management system + * + * @param pkt the packet will be sent + * + * @return 1 if success else <= 0 + */ +int tm_send_packet(odp_packet_t pkt); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/example/traffic_mgmt_multi/odp_traffic_pktio.c b/example/traffic_mgmt_multi/odp_traffic_pktio.c new file mode 100644 index 0000000..78ad4b3 --- /dev/null +++ b/example/traffic_mgmt_multi/odp_traffic_pktio.c @@ -0,0 +1,824 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * @example odp_traffic_mgmt.c + */ + +/** enable strtok */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "odp_traffic_mgmt.h" + +/** @def MAX_WORKERS + * @brief Maximum number of worker threads + */ +#define MAX_WORKERS 32 + +/** @def SHM_PKT_POOL_SIZE + * @brief Size of the shared memory block + */ +#define SHM_PKT_POOL_SIZE 8192 + +/** @def SHM_PKT_POOL_BUF_SIZE + * @brief Buffer size of the packet pool buffer + */ +#define SHM_PKT_POOL_BUF_SIZE 1856 + +/** @def MAX_PKT_BURST + * @brief Maximum number of packet in a burst + */ +#define MAX_PKT_BURST 32 + +/** Maximum number of pktio queues per interface */ +#define MAX_QUEUES 32 + +/** Maximum number of pktio interfaces */ +#define MAX_PKTIOS 8 + +/** Default seconds to run */ +#define DEFAULT_RUN_SECONDS 60 + +/** Get rid of path in filename - only for unix-type paths using '/' */ +#define NO_PATH(file_name) (strrchr((file_name), '/') ? \ + strrchr((file_name), '/') + 1 : (file_name)) +/** + * Parsed command line application arguments + */ +typedef struct { + int cpu_count; + int duration; /**< Number of seconds to run */ + int if_count; /**< Number of interfaces to be used */ + int num_workers; /**< Number of worker threads */ + char **if_names; /**< Array of pointers to interface names */ + char *if_str; /**< Storage for interface names */ + int error_check; /**< Check packet errors */ +} appl_args_t; + +static int exit_threads; /**< Break workers loop if set to 1 */ + +static const odp_init_t ODP_INIT_PARAMS = { + .log_fn = odp_override_log, + .abort_fn = odp_override_abort +}; + +/** + * Statistics + */ +typedef union { + struct { + /** Number of packets received */ + odp_atomic_u64_t packets; + odp_atomic_u64_t bytes; + /** Packets dropped due to receive error */ + odp_atomic_u64_t rx_drops; + odp_atomic_u64_t rx_drop_bytes; + /** Packets dropped due to enqueue traffic management error */ + odp_atomic_u64_t tm_drops; + odp_atomic_u64_t tm_drop_bytes; + } s; + + uint8_t padding[ODP_CACHE_LINE_SIZE]; +} stats_t ODP_ALIGNED_CACHE; + +/** + * Thread specific arguments + */ +typedef struct thread_args_t { + uint64_t pkts; + + int thr_idx; + int num_pktio; + + struct { + odp_pktio_t rx_pktio; + odp_pktin_queue_t pktin; + odp_queue_t rx_queue; + int rx_idx; + int rx_queue_idx; + } pktio[MAX_PKTIOS]; +} thread_args_t; + +/** + * Grouping of all global data + */ +typedef struct { + /** Application (parsed) arguments */ + appl_args_t appl; + /** Thread specific arguments */ + thread_args_t thread[MAX_WORKERS]; + + /** Table of pktio handles */ + struct { + odp_pktio_t pktio; + odp_pktin_queue_t pktin[MAX_QUEUES]; + odp_queue_t rx_q[MAX_QUEUES]; + int num_rx_thr; + int num_rx_queue; + int next_rx_queue; + } pktios[MAX_PKTIOS]; +} args_t; + +/** Global pointer to args */ +static args_t *gbl_args; +/** Global barrier to synchronize main and workers */ +static odp_barrier_t barrier; + +/** + * Drop packets which input parsing marked as containing errors. + * + * Frees packets with error and modifies pkt_tbl[] to only contain packets with + * no detected errors. + * + * @param pkt_tbl Array of packets + * @param num Number of packets in pkt_tbl[] + * + * @return Number of packets dropped + */ +static inline int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned num) +{ + odp_packet_t pkt; + unsigned dropped = 0; + unsigned i, j; + + for (i = 0, j = 0; i < num; ++i) { + pkt = pkt_tbl[i]; + + if (odp_unlikely(odp_packet_has_error(pkt))) { + odp_packet_free(pkt); /* Drop */ + dropped++; + } else if (odp_unlikely(i != j++)) { + pkt_tbl[j - 1] = pkt; + } + } + + return dropped; +} + +/** + * Packet IO worker thread accessing IO resources directly + * + * @param arg thread arguments of type 'thread_args_t *' + */ +static int run_worker_direct_mode(void *arg) +{ + int thr; + int pkts, i; + odp_packet_t pkt_tbl[MAX_PKT_BURST]; + int num_pktio; + odp_pktin_queue_t pktin; + int pktio = 0; + thread_args_t *thr_args = arg; + + thr = odp_thread_id(); + + num_pktio = thr_args->num_pktio; + pktin = thr_args->pktio[pktio].pktin; + + printf("[%02i] num pktios %i, PKTIN_DIRECT\n", thr, num_pktio); + + /* Loop packets */ + while (!exit_threads) { + if (num_pktio > 1) { + pktin = thr_args->pktio[pktio].pktin; + pktio++; + if (pktio == num_pktio) + pktio = 0; + } + + pkts = odp_pktin_recv(pktin, pkt_tbl, MAX_PKT_BURST); + if (odp_unlikely(pkts <= 0)) + continue; + + if (gbl_args->appl.error_check) { + int rx_drops; + + /* Drop packets with errors */ + rx_drops = drop_err_pkts(pkt_tbl, pkts); + + if (odp_unlikely(rx_drops)) { + if (pkts == rx_drops) + continue; + + pkts -= rx_drops; + } + } + + for (i = 0; i < pkts; i++) { + /* try to send packets to Traffic Management System */ + if (tm_send_packet(pkt_tbl[i]) <= 0) + odp_packet_free(pkt_tbl[i]); + } + } + + /* Make sure that latest stat writes are visible to other threads */ + odp_mb_full(); + + return 0; +} + +/** + * Create a pktio handle, optionally associating a default input queue. + * + * @param dev Name of device to open + * @param index Pktio index + * @param pool Pool to associate with device for packet RX/TX + * + * @retval 0 on success + * @retval -1 on failure + */ +static int create_pktio(const char *dev, int idx, int num_rx, odp_pool_t pool) +{ + odp_pktio_t pktio; + odp_pktio_param_t pktio_param; + odp_pktio_capability_t capa; + odp_pktin_queue_param_t pktin_param; + odp_pktio_op_mode_t mode_rx; + + odp_pktio_param_init(&pktio_param); + + pktio = odp_pktio_open(dev, pool, &pktio_param); + if (pktio == ODP_PKTIO_INVALID) { + LOG_ERR("Error: failed to open %s\n", dev); + return -1; + } + + printf("created pktio %" PRIu64 " (%s)\n", + odp_pktio_to_u64(pktio), dev); + + if (odp_pktio_capability(pktio, &capa)) { + LOG_ERR("Error: capability query failed %s\n", dev); + return -1; + } + + odp_pktin_queue_param_init(&pktin_param); + + mode_rx = ODP_PKTIO_OP_MT_UNSAFE; + + if (num_rx > (int)capa.max_input_queues) { + printf("Sharing %i input queues between %i workers\n", + capa.max_input_queues, num_rx); + num_rx = capa.max_input_queues; + mode_rx = ODP_PKTIO_OP_MT; + } + + pktin_param.hash_enable = 1; + pktin_param.hash_proto.proto.ipv4_udp = 1; + pktin_param.num_queues = num_rx; + pktin_param.op_mode = mode_rx; + + if (odp_pktin_queue_config(pktio, &pktin_param)) { + LOG_ERR("Error: input queue config failed %s\n", dev); + return -1; + } + + if (odp_pktin_queue(pktio, gbl_args->pktios[idx].pktin, + num_rx) != num_rx) { + LOG_ERR("Error: pktin queue query failed %s\n", dev); + return -1; + } + + printf("created %i input on (%s)\n", num_rx, dev); + + gbl_args->pktios[idx].num_rx_queue = num_rx; + gbl_args->pktios[idx].pktio = pktio; + + return 0; +} + +/* + * Bind worker threads to interfaces and calculate number of queues needed + * + * less workers (N) than interfaces (M) + * - assign each worker to process every Nth interface + * - workers process inequal number of interfaces, when M is not divisible by N + * - needs only single queue per interface + * otherwise + * - assign an interface to every Mth worker + * - interfaces are processed by inequal number of workers, when N is not + * divisible by M + * - tries to configure a queue per worker per interface + * - shares queues, if interface capability does not allows a queue per worker + */ +static void bind_workers(void) +{ + int if_count, num_workers; + int rx_idx, thr, pktio; + thread_args_t *thr_args; + + if_count = gbl_args->appl.if_count; + num_workers = gbl_args->appl.num_workers; + + if (if_count > num_workers) { + thr = 0; + + for (rx_idx = 0; rx_idx < if_count; rx_idx++) { + thr_args = &gbl_args->thread[thr]; + pktio = thr_args->num_pktio; + thr_args->pktio[pktio].rx_idx = rx_idx; + thr_args->num_pktio++; + + gbl_args->pktios[rx_idx].num_rx_thr++; + + thr++; + if (thr >= num_workers) + thr = 0; + } + } else { + rx_idx = 0; + + for (thr = 0; thr < num_workers; thr++) { + thr_args = &gbl_args->thread[thr]; + pktio = thr_args->num_pktio; + thr_args->pktio[pktio].rx_idx = rx_idx; + thr_args->num_pktio++; + + gbl_args->pktios[rx_idx].num_rx_thr++; + + rx_idx++; + if (rx_idx >= if_count) + rx_idx = 0; + } + } +} + +/* + * Bind queues to threads and fill in missing thread arguments (handles) + */ +static void bind_queues(void) +{ + int num_workers; + int thr, pktio; + + num_workers = gbl_args->appl.num_workers; + + for (thr = 0; thr < num_workers; thr++) { + int rx_idx; + thread_args_t *thr_args = &gbl_args->thread[thr]; + int num = thr_args->num_pktio; + + for (pktio = 0; pktio < num; pktio++) { + int rx_queue; + + rx_idx = thr_args->pktio[pktio].rx_idx; + rx_queue = gbl_args->pktios[rx_idx].next_rx_queue; + + thr_args->pktio[pktio].rx_queue_idx = rx_queue; + thr_args->pktio[pktio].pktin = + gbl_args->pktios[rx_idx].pktin[rx_queue]; + thr_args->pktio[pktio].rx_queue = + gbl_args->pktios[rx_idx].rx_q[rx_queue]; + thr_args->pktio[pktio].rx_pktio = + gbl_args->pktios[rx_idx].pktio; + + rx_queue++; + + if (rx_queue >= gbl_args->pktios[rx_idx].num_rx_queue) + rx_queue = 0; + + gbl_args->pktios[rx_idx].next_rx_queue = rx_queue; + } + } +} + +/** + * Prinf usage information + */ +static void usage(char *progname) +{ + printf("\n" + "OpenDataPlane traffic management application.\n" + "\n" + "Usage: %s OPTIONS\n" + " E.g. %s -i eth0,eth1 -c 2\n" + " In the above example,\n" + " two threads will be used for receiving pkts from eth0 and eth1\n" + "\n" + "Mandatory OPTIONS:\n" + " -i, --interface Eth interfaces (comma-separated, no spaces)\n" + " Interface count min 1, max %i\n" + "\n" + "Optional OPTIONS:\n" + " -c, --count CPU count.\n" + " -t, --time seconds to run.\n" + " -e, --error_check 0: Don't check packet errors (default)\n" + " 1: Check packet errors\n" + " -h, --help Display help and exit.\n\n" + "\n", NO_PATH(progname), NO_PATH(progname), MAX_PKTIOS + ); +} + +/** + * Parse and store the command line arguments + * + * @param argc argument count + * @param argv[] argument vector + * @param appl_args Store application arguments here + */ +static void parse_args(int argc, char *argv[], appl_args_t *appl_args) +{ + int opt; + int long_index; + char *token; + size_t len; + int i; + static const struct option longopts[] = { + {"count", required_argument, NULL, 'c'}, + {"time", required_argument, NULL, 't'}, + {"interface", required_argument, NULL, 'i'}, + {"error_check", required_argument, NULL, 'e'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + static const char *shortopts = "+c:t:i:e:h"; + + /* let helper collect its own arguments (e.g. --odph_proc) */ + odph_parse_options(argc, argv, shortopts, longopts); + + appl_args->error_check = 0; /* don't check packet errors by default */ + + opterr = 0; /* do not issue errors on helper options */ + + while (1) { + opt = getopt_long(argc, argv, shortopts, longopts, &long_index); + + if (opt == -1) + break; /* No more options */ + + switch (opt) { + case 'c': + appl_args->cpu_count = atoi(optarg); + break; + case 't': + appl_args->duration = atoi(optarg); + break; + case 'i': + len = strlen(optarg); + if (len == 0) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + len += 1; /* add room for '\0' */ + + appl_args->if_str = malloc(len); + if (appl_args->if_str == NULL) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + + /* count the number of tokens separated by ',' */ + strcpy(appl_args->if_str, optarg); + for (token = strtok(appl_args->if_str, ","), i = 0; + token != NULL; + token = strtok(NULL, ","), i++) + ; + + appl_args->if_count = i; + + if (appl_args->if_count < 1 || + appl_args->if_count > MAX_PKTIOS) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + + /* allocate storage for the if names */ + appl_args->if_names = + calloc(appl_args->if_count, sizeof(char *)); + + /* store the if names (reset names string) */ + strcpy(appl_args->if_str, optarg); + for (token = strtok(appl_args->if_str, ","), i = 0; + token != NULL; token = strtok(NULL, ","), i++) { + appl_args->if_names[i] = token; + } + break; + case 'e': + appl_args->error_check = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + break; + default: + break; + } + } + + if (appl_args->if_count == 0) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + + optind = 1; /* reset 'extern optind' from the getopt lib */ +} + +/** + * Print system and application info + */ +static void print_info(char *progname, appl_args_t *appl_args) +{ + int i; + + printf("\n" + "ODP system info\n" + "---------------\n" + "ODP API version: %s\n" + "ODP impl name: %s\n" + "CPU model: %s\n" + "CPU freq (hz): %" PRIu64 "\n" + "Cache line size: %i\n" + "CPU count: %i\n" + "\n", + odp_version_api_str(), odp_version_impl_name(), + odp_cpu_model_str(), odp_cpu_hz_max(), + odp_sys_cache_line_size(), odp_cpu_count()); + + printf("Running ODP appl: \"%s\"\n" + "-----------------\n" + "IF-count: %i\n" + "Using IFs: ", + progname, appl_args->if_count); + for (i = 0; i < appl_args->if_count; ++i) + printf(" %s", appl_args->if_names[i]); + printf("\n" + "Mode: PKTIN_DIRECT"); + + printf("\n\n"); + fflush(NULL); +} + +static void gbl_args_init(args_t *args) +{ + int pktio, queue; + + memset(args, 0, sizeof(args_t)); + + for (pktio = 0; pktio < MAX_PKTIOS; pktio++) { + args->pktios[pktio].pktio = ODP_PKTIO_INVALID; + + for (queue = 0; queue < MAX_QUEUES; queue++) + args->pktios[pktio].rx_q[queue] = ODP_QUEUE_INVALID; + } +} + +static void signal_handler(int signal) +{ + size_t num_stack_frames; + const char *signal_name; + void *bt_array[128]; + + switch (signal) { + case SIGILL: + signal_name = "SIGILL"; break; + case SIGFPE: + signal_name = "SIGFPE"; break; + case SIGSEGV: + signal_name = "SIGSEGV"; break; + case SIGTERM: + signal_name = "SIGTERM"; break; + case SIGBUS: + signal_name = "SIGBUS"; break; + default: + signal_name = "UNKNOWN"; break; + } + + num_stack_frames = backtrace(bt_array, 100); + printf("Received signal=%u (%s) exiting.", signal, signal_name); + backtrace_symbols_fd(bt_array, num_stack_frames, fileno(stderr)); + fflush(NULL); + sync(); + abort(); +} + +int main(int argc, char *argv[]) +{ + odph_odpthread_t thread_tbl[MAX_WORKERS]; + odp_pool_t pool; + int i; + int cpu; + int num_workers; + odp_shm_t shm; + odp_cpumask_t cpumask; + char cpumaskstr[ODP_CPUMASK_STR_SIZE]; + odp_pool_param_t params; + int ret; + int if_count; + int duration; + int (*thr_run_func)(void *); + odp_instance_t instance; + struct sigaction signal_action; + + memset(&signal_action, 0, sizeof(signal_action)); + signal_action.sa_handler = signal_handler; + sigfillset(&signal_action.sa_mask); + sigaction(SIGILL, &signal_action, NULL); + sigaction(SIGFPE, &signal_action, NULL); + sigaction(SIGSEGV, &signal_action, NULL); + sigaction(SIGTERM, &signal_action, NULL); + sigaction(SIGBUS, &signal_action, NULL); + + /* Init ODP before calling anything else */ + if (odp_init_global(&instance, NULL, NULL)) { + LOG_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Init this thread */ + if (odp_init_local(instance, ODP_THREAD_CONTROL)) { + LOG_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Reserve memory for args from shared mem */ + shm = odp_shm_reserve("shm_args", sizeof(args_t), + ODP_CACHE_LINE_SIZE, 0); + gbl_args = odp_shm_addr(shm); + + if (gbl_args == NULL) { + LOG_ERR("Error: shared mem alloc failed.\n"); + exit(EXIT_FAILURE); + } + gbl_args_init(gbl_args); + + /* Parse and store the application arguments */ + parse_args(argc, argv, &gbl_args->appl); + + /* Print both system and application information */ + print_info(NO_PATH(argv[0]), &gbl_args->appl); + + /* Default to system CPU count unless user specified */ + num_workers = MAX_WORKERS; + if (gbl_args->appl.cpu_count) + num_workers = gbl_args->appl.cpu_count; + + /* Get default worker cpumask */ + num_workers = odp_cpumask_default_worker(&cpumask, num_workers); + (void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr)); + + gbl_args->appl.num_workers = num_workers; + + for (i = 0; i < num_workers; i++) + gbl_args->thread[i].thr_idx = i; + + if_count = gbl_args->appl.if_count; + + printf("num worker threads: %i\n", num_workers); + printf("first CPU: %i\n", odp_cpumask_first(&cpumask)); + printf("cpu mask: %s\n", cpumaskstr); + + /* Create packet pool */ + odp_pool_param_init(¶ms); + params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.num = SHM_PKT_POOL_SIZE; + params.type = ODP_POOL_PACKET; + + pool = odp_pool_create("packet pool", ¶ms); + + if (pool == ODP_POOL_INVALID) { + LOG_ERR("Error: packet pool create failed.\n"); + exit(EXIT_FAILURE); + } + odp_pool_print(pool); + + bind_workers(); + + for (i = 0; i < if_count; ++i) { + const char *dev = gbl_args->appl.if_names[i]; + int num_rx; + + /* A queue per assigned worker */ + num_rx = gbl_args->pktios[i].num_rx_thr; + + if (create_pktio(dev, i, num_rx, pool)) + exit(EXIT_FAILURE); + } + + gbl_args->pktios[i].pktio = ODP_PKTIO_INVALID; + + bind_queues(); + + if (!tm_config_and_init(if_count)) { + LOG_ERR("Error: tm system initialization failed.\n"); + exit(EXIT_FAILURE); + } + tm_print_user_cos(); + + memset(thread_tbl, 0, sizeof(thread_tbl)); + + odp_barrier_init(&barrier, num_workers + 1); + + thr_run_func = run_worker_direct_mode; + + /* Create worker threads */ + cpu = odp_cpumask_first(&cpumask); + for (i = 0; i < num_workers; ++i) { + odp_cpumask_t thd_mask; + odph_odpthread_params_t thr_params; + + memset(&thr_params, 0, sizeof(thr_params)); + thr_params.start = thr_run_func; + thr_params.arg = &gbl_args->thread[i]; + thr_params.thr_type = ODP_THREAD_WORKER; + thr_params.instance = instance; + + odp_cpumask_zero(&thd_mask); + odp_cpumask_set(&thd_mask, cpu); + odph_odpthreads_create(&thread_tbl[i], &thd_mask, + &thr_params); + cpu = odp_cpumask_next(&cpumask, cpu); + } + + /* Start packet receive and transmit */ + for (i = 0; i < if_count; ++i) { + odp_pktio_t pktio; + uint8_t mac[ODPH_ETHADDR_LEN]; + char buf[32]; + const char *dev; + + pktio = gbl_args->pktios[i].pktio; + ret = odp_pktio_start(pktio); + if (ret) { + LOG_ERR("Error: unable to start %s\n", + gbl_args->appl.if_names[i]); + exit(EXIT_FAILURE); + } else { + dev = gbl_args->appl.if_names[i]; + odp_pktio_mac_addr(pktio, mac, ODPH_ETHADDR_LEN); + sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + printf("start pktio: %s, mac %s\n", dev, buf); + } + } + + /* Print packets count every 10 seconds */ + duration = gbl_args->appl.duration; + if (duration < 10) + duration = DEFAULT_RUN_SECONDS; + tm_print_stat(duration, 10); + exit_threads = 1; + + /* Master thread waits for other threads to exit */ + for (i = 0; i < num_workers; ++i) + odph_odpthreads_join(&thread_tbl[i]); + + free(gbl_args->appl.if_names); + free(gbl_args->appl.if_str); + + ret = tm_system_destroy(); + if (ret) { + LOG_ERR("Error to destroy tm system!\n"); + exit(EXIT_FAILURE); + } + + ret = odp_pool_destroy(pool); + if (ret) { + LOG_ERR("Error to destroy pool!\n"); + exit(EXIT_FAILURE); + } + + ret = odp_shm_free(shm); + if (ret) { + LOG_ERR("Error to free share memory!\n"); + exit(EXIT_FAILURE); + } + + ret = odp_term_local(); + if (ret) { + LOG_ERR("Error to terminate odp local!\n"); + exit(EXIT_FAILURE); + } + + ret = odp_term_global(instance); + if (ret) { + LOG_ERR("Error to terminate odp global\n"); + exit(EXIT_FAILURE); + } + + printf("Exit: %d\n\n", ret); + return ret; +} diff --git a/example/traffic_mgmt_multi/traffic_mgmt_multi_run.sh b/example/traffic_mgmt_multi/traffic_mgmt_multi_run.sh new file mode 100755 index 0000000..79e6102 --- /dev/null +++ b/example/traffic_mgmt_multi/traffic_mgmt_multi_run.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# Copyright (c) 2017, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +RESULT_STR="user 0: pkts_in=100, pkts_out=100" +PCAP_IN=`find . ${TEST_DIR} $(dirname $0) -name udp64.pcap -print -quit` +PCAP_OUT="pcapout.pcap" +PCAP_IN_SIZE=`stat -c %s ${PCAP_IN}` +echo "using PCAP_IN = ${PCAP_IN}, PCAP_OUT = ${PCAP_OUT}" + +./odp_traffic_mgmt -i pcap:in=${PCAP_IN},pcap:out=${PCAP_OUT} -t 20 > \ + /tmp/odp_traffic_mgmt_multi.log +STATUS=$? +grep "${RESULT_STR}" /tmp/odp_traffic_mgmt_multi.log +GREP_STATUS=$? +rm -f ${PCAP_OUT} + +if [ ${STATUS} -ne 0 ] || [ ${GREP_STATUS} -ne 0 ]; then + echo "Error: status ${STATUS}, expect ${RESULT_STR}" + exit 1 +fi + +echo "Pass: status ${STATUS}, ${RESULT_STR}" + +exit 0 diff --git a/example/traffic_mgmt_multi/udp64.pcap b/example/traffic_mgmt_multi/udp64.pcap new file mode 100644 index 0000000000000000000000000000000000000000..45f9d6e6341a331125e1e3e49ab8ad1e71b20712 GIT binary patch literal 7624 zcmca|c+)~A1{MYw_+QV!zzF1AIDRVZQX4OW4Ui4OOdthJV3Lu8!IgnQ52VaNFl`SP zPy-M%&2gOL#31#rG%+bTB{eNQBQq;ICpRy@ps;AvtkLiqO%tPeXtbOdEel8Mj?wyY zv^_D}W*Ti5GK{vPNBat+eXG&_<7gilID#