From patchwork Wed Oct 28 19:29:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 55711 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp136607lbr; Wed, 28 Oct 2015 12:30:13 -0700 (PDT) X-Received: by 10.140.254.193 with SMTP id z184mr25848473qhc.68.1446060613194; Wed, 28 Oct 2015 12:30:13 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k82si21221880qkl.98.2015.10.28.12.30.12; Wed, 28 Oct 2015 12:30:13 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id D3EE561FF5; Wed, 28 Oct 2015 19:30:12 +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=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 3E6C661FE4; Wed, 28 Oct 2015 19:29:29 +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 632EC61D87; Wed, 28 Oct 2015 19:29:25 +0000 (UTC) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by lists.linaro.org (Postfix) with ESMTPS id CF36F6198E for ; Wed, 28 Oct 2015 19:29:23 +0000 (UTC) Received: by wicfx6 with SMTP id fx6so210019286wic.1 for ; Wed, 28 Oct 2015 12:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=CxWq2VitU97xPBgZPUDG92DK6OIx+DOKRB+XYF1MVH8=; b=JmOwqX5tZKOm2QVTtOZwi3vtQ3y7he6WTX1tJR2MF9uiYf8XMAmNQwEYSCqnncUwwm CppT5Ly/kd5Nzw0pOXBlzW2VDKFgHR+/ic69dxDGK6h8NxQwHdExFTIH1B+pA2TKgH+k qav+UF6PhufPbOFCipCNYmIOKdJWvIX8lWw6jg606f55o02lAYHk4KI5Y8iXYosVp91g 90BoKnWW4+5q0Nq9uYIPOYI/b7THzOxikZuK+RQR4Aaj/Dl2B7I1SKg4XhFRdfR2n/hI ghBvbG95rxVPbIkp6qNqhBUrDJC90j0pcdupvv5MjTQxbd7d30mCMQbYw1JTJLiVrDcy k4xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=CxWq2VitU97xPBgZPUDG92DK6OIx+DOKRB+XYF1MVH8=; b=dx/LFu2ERsA6keC3ypCMggTN5pROByo9fI/N1gNHCuzYZxXkhzZ8eprxlaEwr9R4KB 2DEZmb6U7o/GwMUe+jZk5o/U4DIp2WBklri55ga+U++Li39TGIjOSR7tizJtvRuTXfp2 UYwPSAdSx/kPffkIU52f2U0i0iaQkeMlPTQj5uId/Zd/o+TtdKnVpQI4dMpCNO3YLHGv 76P04nRBtnLfawjXy4rNQeH5sBTxvTnycvI+4pm6E5UTqt9ZphUjAER79Sbz+Qset4Hg W5Te+YTJCL/ObB1oaIqnRQ8fWw59AWnKR7XMInIEyJxV+Z97QLQckMdVRoIF4zAmocbj ci7w== X-Gm-Message-State: ALoCoQmN8Qts93VoXt3c6FL4zBO+PbUwuYlUmO97Trz5pGFSPKF+w07NgskBB79eTcvN4y/jOfuy X-Received: by 10.194.114.135 with SMTP id jg7mr11275427wjb.11.1446060563063; Wed, 28 Oct 2015 12:29:23 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id h4sm31286154wjx.41.2015.10.28.12.29.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Oct 2015 12:29:22 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Wed, 28 Oct 2015 19:29:03 +0000 Message-Id: <1446060551-21029-2-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1446060551-21029-1-git-send-email-stuart.haslam@linaro.org> References: <1446060551-21029-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 1/9] validation: pktio: make MAC address and promiscuous mode optional 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Update the unit tests to allow for interfaces that don't have a MAC address and therefore also don't support promiscuous mode. The pktio promiscuous mode and MAC address APIs are intended to cope with the common case that an interface has a single default MAC address. The default MAC is the one to be used as the source address when originating packets from that interface, it is also what's used to filter packets when promiscuous mode is disabled. However in some cases this doesn't apply, a switch port or one end of an IPC pipe may not have a MAC address for example. The test will also now restore the state to how it was at the beginning of the test, which it didn't necessarily do previously. Signed-off-by: Stuart Haslam --- test/validation/pktio/pktio.c | 80 +++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index a746b9a..5cad67d 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -67,6 +67,11 @@ pkt_segmented_e pool_segmentation = PKT_POOL_UNSEGMENTED; odp_pool_t pool[MAX_NUM_IFACES] = {ODP_POOL_INVALID, ODP_POOL_INVALID}; +/* the default source and destination MAC addresses to be used if the + * test interface doesn't return a MAC address via odp_pktio_mac_addr() */ +static const char pktio_test_mac_src[] = {0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; +static const char pktio_test_mac_dst[] = {0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + static void set_pool_len(odp_pool_param_t *params) { switch (pool_segmentation) { @@ -91,10 +96,12 @@ static void pktio_pkt_set_macs(odp_packet_t pkt, int ret; ret = odp_pktio_mac_addr(src->id, ð->src, sizeof(eth->src)); - CU_ASSERT(ret == ODPH_ETHADDR_LEN); + if (ret <= 0) + memcpy(ð->src, pktio_test_mac_src, sizeof(eth->src)); ret = odp_pktio_mac_addr(dst->id, ð->dst, sizeof(eth->dst)); - CU_ASSERT(ret == ODPH_ETHADDR_LEN); + if (ret <= 0) + memcpy(ð->dst, pktio_test_mac_dst, sizeof(eth->dst)); } static uint32_t pktio_pkt_set_seq(odp_packet_t pkt) @@ -536,31 +543,66 @@ void pktio_test_mtu(void) void pktio_test_promisc(void) { int ret; + int enabled; odp_pktio_t pktio = create_pktio(iface_name[0], ODP_QUEUE_TYPE_SCHED, 0); CU_ASSERT_FATAL(pktio != ODP_PKTIO_INVALID); - ret = odp_pktio_promisc_mode_set(pktio, 1); - CU_ASSERT(0 == ret); + /* read the current promisuous state */ + enabled = odp_pktio_promisc_mode(pktio); + CU_ASSERT(enabled == 1 || enabled == 0 || enabled < 0); - /* Verify that promisc mode set */ - ret = odp_pktio_promisc_mode(pktio); - CU_ASSERT(1 == ret); + /* attempt to set to the same state */ + ret = odp_pktio_promisc_mode_set(pktio, enabled); + if (ret < 0) { + /* failed, that's ok, some interfaces don't support it, but + * they must set odp_errno.. */ + CU_ASSERT(0 != odp_errno()); + } else { + /* attempt to change to the other state */ + ret = odp_pktio_promisc_mode_set(pktio, !enabled); - ret = odp_pktio_promisc_mode_set(pktio, 0); - CU_ASSERT(0 == ret); + /* changed the state successfully, read back and verify */ + ret = odp_pktio_promisc_mode(pktio); + CU_ASSERT(!enabled == ret); - /* Verify that promisc mode is not set */ - ret = odp_pktio_promisc_mode(pktio); - CU_ASSERT(0 == ret); + /* change it back to original state */ + ret = odp_pktio_promisc_mode_set(pktio, enabled); + CU_ASSERT(0 == ret); + + ret = odp_pktio_promisc_mode(pktio); + CU_ASSERT(enabled == ret); + } ret = odp_pktio_close(pktio); CU_ASSERT(ret == 0); } +static void pktio_print_mac(unsigned char *mac_addr, int mac_len) +{ + int len = 0; + int i; + char mac_str[(ODP_PKTIO_MACADDR_MAXSIZE * 3) + 1]; + + if (mac_len <= 0) { + printf("none ... "); + return; + } + + for (i = 0; i < mac_len; ++i) { + len += snprintf(mac_str + len, sizeof(mac_str) - len, + "%02hhx:", mac_addr[i]); + } + + if (len) { + mac_str[len - 1] = '\0'; + printf("%s ... ", mac_str); + } +} + void pktio_test_mac(void) { - unsigned char mac_addr[ODPH_ETHADDR_LEN]; + unsigned char mac_addr[ODP_PKTIO_MACADDR_MAXSIZE]; int mac_len; int ret; odp_pktio_t pktio; @@ -568,18 +610,12 @@ void pktio_test_mac(void) pktio = create_pktio(iface_name[0], ODP_QUEUE_TYPE_SCHED, 0); CU_ASSERT_FATAL(pktio != ODP_PKTIO_INVALID); - printf("testing mac for %s\n", iface_name[0]); + printf(" MAC for %s is ", iface_name[0]); mac_len = odp_pktio_mac_addr(pktio, mac_addr, sizeof(mac_addr)); - CU_ASSERT(ODPH_ETHADDR_LEN == mac_len); - - printf(" %X:%X:%X:%X:%X:%X ", - mac_addr[0], mac_addr[1], mac_addr[2], - mac_addr[3], mac_addr[4], mac_addr[5]); + CU_ASSERT(0 == mac_len || ODP_PKTIO_MACADDR_MAXSIZE >= mac_len); - /* Fail case: wrong addr_size. Expected <0. */ - mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); - CU_ASSERT(mac_len < 0); + pktio_print_mac(mac_addr, mac_len); ret = odp_pktio_close(pktio); CU_ASSERT(0 == ret);