From patchwork Fri Jan 22 18:48:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 60176 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp26761lbb; Fri, 22 Jan 2016 10:49:07 -0800 (PST) X-Received: by 10.50.64.146 with SMTP id o18mr4792956igs.51.1453488547326; Fri, 22 Jan 2016 10:49:07 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d8si6770509igc.23.2016.01.22.10.49.06; Fri, 22 Jan 2016 10:49:07 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 948B46197B; Fri, 22 Jan 2016 18:49:06 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=LdPnA3ZN; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 5D7D161904; Fri, 22 Jan 2016 18:48:27 +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 756DE618F0; Fri, 22 Jan 2016 18:48:23 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by lists.linaro.org (Postfix) with ESMTPS id 04BD0618E0 for ; Fri, 22 Jan 2016 18:48:22 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id n5so146317117wmn.0 for ; Fri, 22 Jan 2016 10:48:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=IVF48cKcOpQ+zkWo3h1Rex5Zq4HTrEBVkxrxCeEJdws=; b=LdPnA3ZNt34SRSuqj2RDZoeZ4frnbGDxOZNTXpxkS7AP4gekg7fetEQuHDfgVff0JR Br/5IMbSum1fzOdYAW1iFyZgmr932L7E1PG2ti5OfD6zK46e98yD+iRO8yaFJoU0v2j2 Bd8B/1cubgJAbrllCajCFB9ucqZM6gtrkyrW4= 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=IVF48cKcOpQ+zkWo3h1Rex5Zq4HTrEBVkxrxCeEJdws=; b=S4rewZEoFcZaCqOkfXDGdDB6Lrd8KaYOAxV8iAs0UE8WG53zCOSYQ7qlEk5g+rvKq7 y7s36T0BB5iXgf0itif69/pEenDdFc+yDvvxSEvyUncU/P1In8CsNpxIZgOkckOpuoUc ufTZs/9aEK94+lkyWplQkR0KQog21zMBYYGip8p86IOS64j86WdZdvDTKLWKMVm31LuM yGLjMF/zkc/1wXvXrVESLPHBf0LDtmECf0bP5q6BIOtmEJ+WPwxEXdTg1VT4H5UdA1bg tGCoHVMmgZLc47pkIVtDipEj/hpgpGRzH7EbG3VUJjeX5XVbo6am1d/OmcyvnztTrlye VRug== X-Gm-Message-State: AG10YOTMCvHELKeU5eMjofgJ483oZDXyQ61uxLWVWAWWOeNnmBl2eBxzPBdnZFPHpnn2Zzunk9U= X-Received: by 10.28.176.131 with SMTP id z125mr5426733wme.5.1453488501089; Fri, 22 Jan 2016 10:48:21 -0800 (PST) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::1]) by smtp.gmail.com with ESMTPSA id p9sm7085262wjy.41.2016.01.22.10.48.20 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 10:48:20 -0800 (PST) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Fri, 22 Jan 2016 18:48:02 +0000 Message-Id: <1453488486-12176-2-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1453488486-12176-1-git-send-email-stuart.haslam@linaro.org> References: <1453488486-12176-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 1/5] 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 5923969..55e5471 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -79,6 +79,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, 0x08}; + static void set_pool_len(odp_pool_param_t *params) { switch (pool_segmentation) { @@ -103,10 +108,12 @@ static void pktio_pkt_set_macs(odp_packet_t pkt, int ret; ret = odp_pktio_mac_addr(src, ð->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, ð->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) @@ -610,32 +617,67 @@ void pktio_test_mtu(void) void pktio_test_promisc(void) { int ret; + int enabled; odp_pktio_t pktio = create_pktio(0, ODP_PKTIN_MODE_SCHED, ODP_PKTOUT_MODE_SEND); 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; @@ -644,18 +686,12 @@ void pktio_test_mac(void) ODP_PKTOUT_MODE_SEND); 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);