From patchwork Thu Apr 2 11:07:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 46722 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B5B58216D1 for ; Thu, 2 Apr 2015 11:08:31 +0000 (UTC) Received: by lbcne10 with SMTP id ne10sf9442343lbc.1 for ; Thu, 02 Apr 2015 04:08:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=gg+AyVUP6Uzo2m5aagE9LhLcwUUcrIzkrzy66yN+v/Q=; b=eNCHEdX//Fg+fTnLPCX/K1OegHTRbmGhivR80Ofr3AgVWfVyoTPy5UEZBEM2GDvZQO hmCnoRTSFREA7l+w+6d/6p6f86KSHok3nKElKFmaJVDdXSGcuofgTDguRvdhkTxSblaG V2ZIs0SShG+1WlAhr6RnYNFYGUOQNvXu4BJU+KX/+CXd7upEEmp1UKDfSbGMR9zbRyqc ZL5hYXf5+MMGU7GUTDCSPqIZHTyEovyA5gQg67+CYXM9lldwcRs5FpxytgjeszLBDQrl Knqz25XZM6QBVyQtUnbq9ZznHnm31Zzs9W85DdCFDUOdlN2k7Lxj6P4gKHY+p0fVLEHK q/RQ== X-Gm-Message-State: ALoCoQl7rlP2g4Ixn7+xI8dxR7glhGxpLXD2/7YTVgwcJdGwWSiAdXqWlY4BcwL6qcbL67NuEKnB X-Received: by 10.112.138.233 with SMTP id qt9mr4553483lbb.2.1427972910639; Thu, 02 Apr 2015 04:08:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.7 with SMTP id o7ls195350lao.52.gmail; Thu, 02 Apr 2015 04:08:30 -0700 (PDT) X-Received: by 10.112.89.71 with SMTP id bm7mr40378581lbb.20.1427972910405; Thu, 02 Apr 2015 04:08:30 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id f4si3979966lbc.56.2015.04.02.04.08.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Apr 2015 04:08:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by labe2 with SMTP id e2so57475892lab.3 for ; Thu, 02 Apr 2015 04:08:30 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr40392508lba.19.1427972910026; Thu, 02 Apr 2015 04:08:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp1259737lbq; Thu, 2 Apr 2015 04:08:29 -0700 (PDT) X-Received: by 10.55.27.198 with SMTP id m67mr95991298qkh.11.1427972909015; Thu, 02 Apr 2015 04:08:29 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w99si4650766qge.15.2015.04.02.04.08.28; Thu, 02 Apr 2015 04:08:28 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id ECA0665085; Thu, 2 Apr 2015 11:08:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id F3B5E65087; Thu, 2 Apr 2015 11:08:08 +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 DFBFF6507E; Thu, 2 Apr 2015 11:08:03 +0000 (UTC) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by lists.linaro.org (Postfix) with ESMTPS id 5C3CA6507E for ; Thu, 2 Apr 2015 11:08:02 +0000 (UTC) Received: by widdi4 with SMTP id di4so74791909wid.0 for ; Thu, 02 Apr 2015 04:08:01 -0700 (PDT) X-Received: by 10.180.74.230 with SMTP id x6mr23556325wiv.58.1427972881616; Thu, 02 Apr 2015 04:08:01 -0700 (PDT) Received: from e106441.cambridge.arm.com ([2001:41d0:a:3cb4::1]) by mx.google.com with ESMTPSA id u16sm6772551wjr.5.2015.04.02.04.08.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Apr 2015 04:08:00 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Thu, 2 Apr 2015 12:07:40 +0100 Message-Id: <1427972861-14593-2-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1427972861-14593-1-git-send-email-stuart.haslam@linaro.org> References: <1427972861-14593-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/3] validation: pktio: support arbitrary length packets X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stuart.haslam@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Rework the way test packets are generated in order to allow generating and verifying arbitrary length packets. Signed-off-by: Stuart Haslam --- test/validation/odp_pktio.c | 140 ++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 82 deletions(-) diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c index 5ea45e4..a078efe 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -14,11 +14,10 @@ #include #define PKT_BUF_NUM 32 -#define PKT_BUF_SIZE 1856 -#define PKT_BUF_JUMBO_SIZE (9*1024) -#define PKT_BUF_JUMBO_MAX_PAYLOAD (PKT_BUF_JUMBO_SIZE -\ - (ODPH_UDPHDR_LEN +\ - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN)) +#define PKT_BUF_SIZE (9*1024) +#define PKT_LEN_NORMAL 64 +#define PKT_LEN_JUMBO (PKT_BUF_SIZE - ODPH_ETHHDR_LEN - \ + ODPH_IPV4HDR_LEN - ODPH_UDPHDR_LEN) #define MAX_NUM_IFACES 2 #define TEST_SEQ_INVALID ((uint32_t)~0) #define TEST_SEQ_MAGIC 0x92749451 @@ -37,20 +36,19 @@ typedef struct { odp_queue_t inq; } pktio_info_t; +/** magic number and sequence at start of UDP payload */ typedef struct ODP_PACKED { uint32be_t magic; uint32be_t seq; } pkt_head_t; -/** structure of test packet UDP payload */ +/** magic number at end of UDP payload */ typedef struct ODP_PACKED { - pkt_head_t head; - char data[PKT_BUF_JUMBO_MAX_PAYLOAD - sizeof(pkt_head_t) - - sizeof(uint32be_t)]; - uint32be_t magic2; -} pkt_test_data_t; + uint32be_t magic; +} pkt_tail_t; -static int test_jumbo; +/** size of transmitted packets */ +static uint32_t packet_len = PKT_LEN_NORMAL; /** default packet pool */ odp_pool_t default_pkt_pool = ODP_POOL_INVALID; @@ -72,87 +70,76 @@ static void pktio_pkt_set_macs(odp_packet_t pkt, CU_ASSERT(ret == ODPH_ETHADDR_LEN); } -static uint32_t pkt_payload_len(void) -{ - return test_jumbo ? sizeof(pkt_test_data_t) : sizeof(pkt_head_t); -} - -static int pktio_pkt_set_seq(odp_packet_t pkt) +static uint32_t pktio_pkt_set_seq(odp_packet_t pkt) { static uint32_t tstseq; - size_t l4_off; - pkt_test_data_t *data; - uint32_t len = pkt_payload_len(); - + size_t off; + pkt_head_t head; + pkt_tail_t tail; - l4_off = odp_packet_l4_offset(pkt); - if (!l4_off) { + off = odp_packet_l4_offset(pkt); + if (off == ODP_PACKET_OFFSET_INVALID) { CU_FAIL("packet L4 offset not set"); - return -1; + return TEST_SEQ_INVALID; } - data = calloc(1, len); - CU_ASSERT_FATAL(data != NULL); + head.magic = TEST_SEQ_MAGIC; + head.seq = tstseq; - data->head.magic = TEST_SEQ_MAGIC; - if (test_jumbo) - data->magic2 = TEST_SEQ_MAGIC; - data->head.seq = tstseq; + off += ODPH_UDPHDR_LEN; + if (odp_packet_copydata_in(pkt, off, sizeof(head), &head) != 0) + return TEST_SEQ_INVALID; + + tail.magic = TEST_SEQ_MAGIC; + off = odp_packet_len(pkt) - sizeof(pkt_tail_t); + if (odp_packet_copydata_in(pkt, off, sizeof(tail), &tail) != 0) + return TEST_SEQ_INVALID; - odp_packet_copydata_in(pkt, l4_off+ODPH_UDPHDR_LEN, - len, data); - free(data); tstseq++; - return 0; + return head.seq; } static uint32_t pktio_pkt_seq(odp_packet_t pkt) { - size_t l4_off; + size_t off; uint32_t seq = TEST_SEQ_INVALID; - pkt_test_data_t *data; - uint32_t len = pkt_payload_len(); + pkt_head_t head; + pkt_tail_t tail; - l4_off = odp_packet_l4_offset(pkt); - if (l4_off == ODP_PACKET_OFFSET_INVALID) + off = odp_packet_l4_offset(pkt); + if (off == ODP_PACKET_OFFSET_INVALID) return TEST_SEQ_INVALID; - data = calloc(1, len); - CU_ASSERT_FATAL(data != NULL); + off += ODPH_UDPHDR_LEN; + if (odp_packet_copydata_out(pkt, off, sizeof(head), &head) != 0) + return TEST_SEQ_INVALID; - odp_packet_copydata_out(pkt, l4_off+ODPH_UDPHDR_LEN, - len, data); + if (head.magic != TEST_SEQ_MAGIC) + return TEST_SEQ_INVALID; - if (data->head.magic == TEST_SEQ_MAGIC) { - if (test_jumbo && data->magic2 != TEST_SEQ_MAGIC) { - free(data); + if (odp_packet_len(pkt) == packet_len) { + off = packet_len - sizeof(tail); + if (odp_packet_copydata_out(pkt, off, sizeof(tail), &tail) != 0) return TEST_SEQ_INVALID; - } - seq = data->head.seq; + + if (tail.magic == TEST_SEQ_MAGIC) + seq = head.seq; } - free(data); return seq; } -static odp_packet_t pktio_create_packet(void) +static uint32_t pktio_init_packet(odp_packet_t pkt) { - odp_packet_t pkt; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_udphdr_t *udp; char *buf; uint16_t seq; - size_t payload_len = pkt_payload_len(); uint8_t mac[ODPH_ETHADDR_LEN] = {0}; + int pkt_len = odp_packet_len(pkt); - pkt = odp_packet_alloc(default_pkt_pool, payload_len + ODPH_UDPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); - if (pkt == ODP_PACKET_INVALID) { - CU_FAIL("failed to allocate packet buffer"); - return ODP_PACKET_INVALID; - } buf = odp_packet_data(pkt); /* Ethernet */ @@ -168,8 +155,7 @@ static odp_packet_t pktio_create_packet(void) ip->dst_addr = odp_cpu_to_be_32(0); ip->src_addr = odp_cpu_to_be_32(0); ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN; - ip->tot_len = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN + - ODPH_IPV4HDR_LEN); + ip->tot_len = odp_cpu_to_be_16(pkt_len - ODPH_ETHHDR_LEN); ip->ttl = 128; ip->proto = ODPH_IPPROTO_UDP; seq = odp_atomic_fetch_inc_u32(&ip_seq); @@ -182,15 +168,11 @@ static odp_packet_t pktio_create_packet(void) udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); udp->src_port = odp_cpu_to_be_16(0); udp->dst_port = odp_cpu_to_be_16(0); - udp->length = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN); + udp->length = odp_cpu_to_be_16(pkt_len - + ODPH_ETHHDR_LEN - ODPH_IPV4HDR_LEN); udp->chksum = 0; - if (pktio_pkt_set_seq(pkt) != 0) { - odp_packet_free(pkt); - return ODP_PACKET_INVALID; - } - - return pkt; + return pktio_pkt_set_seq(pkt); } static int pktio_fixup_checksums(odp_packet_t pkt) @@ -224,8 +206,8 @@ static int default_pool_create(void) return -1; memset(¶ms, 0, sizeof(params)); - params.pkt.seg_len = PKT_BUF_JUMBO_SIZE; - params.pkt.len = PKT_BUF_JUMBO_SIZE; + params.pkt.seg_len = PKT_BUF_SIZE; + params.pkt.len = PKT_BUF_SIZE; params.pkt.num = PKT_BUF_NUM; params.type = ODP_POOL_PACKET; @@ -245,14 +227,8 @@ static odp_pktio_t create_pktio(const char *iface) odp_pool_param_t params; memset(¶ms, 0, sizeof(params)); - if (test_jumbo) { - params.pkt.seg_len = PKT_BUF_JUMBO_SIZE; - params.pkt.len = PKT_BUF_JUMBO_SIZE; - - } else { - params.pkt.seg_len = PKT_BUF_SIZE; - params.pkt.len = PKT_BUF_SIZE; - } + params.pkt.seg_len = PKT_BUF_SIZE; + params.pkt.len = PKT_BUF_SIZE; params.pkt.num = PKT_BUF_NUM; params.type = ODP_POOL_PACKET; @@ -393,11 +369,11 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b, /* generate test packets to send */ for (i = 0; i < num_pkts; ++i) { - tx_pkt[i] = pktio_create_packet(); + tx_pkt[i] = odp_packet_alloc(default_pkt_pool, packet_len); if (tx_pkt[i] == ODP_PACKET_INVALID) break; - tx_seq[i] = pktio_pkt_seq(tx_pkt[i]); + tx_seq[i] = pktio_init_packet(tx_pkt[i]); if (tx_seq[i] == TEST_SEQ_INVALID) break; @@ -500,9 +476,9 @@ static void test_odp_pktio_sched_multi(void) static void test_odp_pktio_jumbo(void) { - test_jumbo = 1; + packet_len = PKT_LEN_JUMBO; test_odp_pktio_sched_multi(); - test_jumbo = 0; + packet_len = PKT_LEN_NORMAL; } static void test_odp_pktio_mtu(void)