From patchwork Tue Aug 8 11:00:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 109608 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp3912961obb; Tue, 8 Aug 2017 04:01:31 -0700 (PDT) X-Received: by 10.55.214.215 with SMTP id p84mr4605195qkl.5.1502190091477; Tue, 08 Aug 2017 04:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502190091; cv=none; d=google.com; s=arc-20160816; b=YRBPlvEieaDyFCmvrYfM1xoFJwcJ04OEXgQFQFSRxURlJoXrXi3KRbOu7bxP3cbRnE lMwMdSiuHRnlp10KXL1/aBCN4r45DdzjEMxACOlBrelKCpL70OQTpT0Non5ivdxj3nQ1 2FMj2p5yGN/aoLej5FOt8pizSk3CjciJ5cc/KqteiWAjfaxAgZ6AYCiQ9VXcUx3Qs3A9 Gf6A1fK6CiLMKp7DnDx/3uNsxDwqQ9x8+4bhQY9qDLZ91Q6V0IXthcXu9L3babSYs7ZI SxJnbs0kiHVrojL8DbL1o64rqvYzuilSD9wJjsAoyl3x6IHQyU+wEQTP1pMwz/ClSGwe dE8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Boc8Bz1n9WDlckcWOEJHDxFpuFV8dpQ+e/TIPWG/X7g=; b=bEew4H/oRYnzg40aHI8FRkmluaEd+rtsoD6fk8ROrMAPoMFSBiiBJ7p9Thbw0CCngE T6bkRfKjraq0KCvUG/sRbb9KbAGMGqRyqdxB1Ia+pIO/LAeyLIKc3/d6Sm38WDiPJlUm wFVb2PTPzmpCkbQdHk6Aa31jj1V8YhfhPpnJPlOsdU+b5wlo2wklUXP7pq3i/41VWVn+ ioUw7+9m0eOWlbemFbE0p6eEG+XS01wjBek4PVQwJGMme59FWyUyiDcdUo7VOnqP0QC7 /bV/ZrgTXqsmrzN6jA7toqQ0Bc7MX+Lpkuj1nsab/TA+KggEP6rFtZnPAAtFhZWxucsO m2Ig== ARC-Authentication-Results: i=1; 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j4si900062qkf.485.2017.08.08.04.01.31; Tue, 08 Aug 2017 04:01:31 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 2197360BF7; Tue, 8 Aug 2017 11:01:31 +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=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 67FC660A02; Tue, 8 Aug 2017 11:01:05 +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 98AC260726; Tue, 8 Aug 2017 11:00:58 +0000 (UTC) Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [37.140.190.181]) by lists.linaro.org (Postfix) with ESMTPS id 9A9926013B for ; Tue, 8 Aug 2017 11:00:56 +0000 (UTC) Received: from mxback14g.mail.yandex.net (mxback14g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:93]) by forward101o.mail.yandex.net (Yandex) with ESMTP id F16041342AAB for ; Tue, 8 Aug 2017 14:00:52 +0300 (MSK) Received: from smtp2j.mail.yandex.net (smtp2j.mail.yandex.net [2a02:6b8:0:801::ac]) by mxback14g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 7gQvLmlthW-0q0K74qB; Tue, 08 Aug 2017 14:00:52 +0300 Received: by smtp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id otSZtRbdrQ-0qjiJ3d0; Tue, 08 Aug 2017 14:00:52 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 8 Aug 2017 14:00:37 +0300 Message-Id: <1502190037-3074-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502190037-3074-1-git-send-email-odpbot@yandex.ru> References: <1502190037-3074-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 118 Subject: [lng-odp] [PATCH v1 1/1] example: generator : use packet reference API to generate udp and icmp traffic 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: Bogdan Pricope Signed-off-by: Bogdan Pricope --- /** Email created from pull request 118 (bogdanPricope:pktref_generator_pr) ** https://github.com/Linaro/odp/pull/118 ** Patch: https://github.com/Linaro/odp/pull/118.patch ** Base sha: e76b25aa5cafbf96133fcbd83b856090b0e95f33 ** Merge commit sha: a2a1459eb2047f247e54c2e3476a178c29384326 **/ example/generator/odp_generator.c | 165 +++++++++++++++++++++++--------------- 1 file changed, 100 insertions(+), 65 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 9336cec1..f3ec43be 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -136,6 +136,7 @@ static void millisleep(uint32_t ms, uint64_t ticks = odp_timer_ns_to_tick(tp, 1000000ULL * ms); odp_event_t ev = odp_timeout_to_event(tmo); int rc = odp_timer_set_rel(tim, ticks, &ev); + if (rc != ODP_TIMER_SUCCESS) EXAMPLE_ABORT("odp_timer_set_rel() failed\n"); /* Spin waiting for timeout event */ @@ -186,12 +187,76 @@ static int scan_ip(char *buf, unsigned int *paddr) } /** + * Setup array of reference packets + * + * @param pool Packet pool + * @param pkt_ref_array Packet array + * @param pkt_ref_array_size Packet array size + * @param setup_ref Packet setup function + * @return 0 success, -1 failed +*/ +static int setup_pkt_ref_array(odp_pool_t pool, + odp_packet_t *pkt_ref_array, + int pkt_ref_array_size, + odp_packet_t (*setup_ref)(odp_pool_t)) +{ + int i; + + for (i = 0; i < pkt_ref_array_size; i++) { + pkt_ref_array[i] = (*setup_ref)(pool); + if (pkt_ref_array[i] == ODP_PACKET_INVALID) + break; + } + + if (i < pkt_ref_array_size) { + odp_packet_free_multi(pkt_ref_array, i); + return -1; + } + return 0; +} + +/** + * Setup array of packets + * + * @param pkt_ref_array Reference packet array + * @param pkt_array Packet array + * @param pkt_array_size Packet array size + * @param setup_pkt Packet setup function + * @return 0 success, -1 failed +*/ +static int setup_pkt_array(odp_packet_t *pkt_ref_array, + odp_packet_t *pkt_array, + int pkt_array_size, + int (*setup_pkt)(odp_packet_t)) +{ + int i; + + for (i = 0; i < pkt_array_size; i++) { + if ((*setup_pkt)(pkt_ref_array[i])) + break; + + pkt_array[i] = odp_packet_ref_static(pkt_ref_array[i]); + if (pkt_array[i] == ODP_PACKET_INVALID) + break; + } + if (i < pkt_array_size) { + if (i) + odp_packet_free_multi(pkt_array, i - 1); + + return -1; + } + return 0; +} + +/** * set up an udp packet reference * * @param pool Buffer pool to create packet in * - * @return Handle of created packet + * + * @retval Handle of created packet * @retval ODP_PACKET_INVALID Packet could not be created + * */ static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool) { @@ -246,37 +311,27 @@ static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool) /** * set up an udp packet * - * @param pool Buffer pool to create packet in - * @param pkt_ref Reference UDP packet + * @param pkt Reference UDP packet * - * @return Handle of created packet - * @retval ODP_PACKET_INVALID Packet could not be created + * @return Success/Failed + * @retval 0 on success, -1 on fail */ -static odp_packet_t pack_udp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) +static int setup_udp_pkt(odp_packet_t pkt) { - odp_packet_t pkt; char *buf; odph_ipv4hdr_t *ip; unsigned short seq; - pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_UDPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); - - if (pkt == ODP_PACKET_INVALID) - return pkt; - buf = (char *)odp_packet_data(pkt); - odp_memcpy(buf, odp_packet_data(pkt_ref), - args->appl.payload + ODPH_UDPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); /*Update IP ID and checksum*/ ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF; ip->id = odp_cpu_to_be_16(seq); + ip->chksum = 0; ip->chksum = odph_chksum(ip, ODPH_IPV4HDR_LEN); - return pkt; + return 0; } /** @@ -337,15 +392,13 @@ static odp_packet_t setup_icmp_pkt_ref(odp_pool_t pool) /** * Set up an icmp packet * - * @param pool Buffer pool to create packet in - * @param pkt_ref Reference ICMP packet + * @param pkt Reference ICMP packet * - * @return Handle of created packet - * @retval ODP_PACKET_INVALID Packet could not be created + * @return Success/Failed + * @retval 0 on success, -1 on fail */ -static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) +static int setup_icmp_pkt(odp_packet_t pkt) { - odp_packet_t pkt; char *buf; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; @@ -353,21 +406,13 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) uint8_t *tval_d; unsigned short seq; - pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_ICMPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); - - if (pkt == ODP_PACKET_INVALID) - return pkt; - buf = (char *)odp_packet_data(pkt); - odp_memcpy(buf, odp_packet_data(pkt_ref), - args->appl.payload + ODPH_ICMPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); /* ip */ ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff; ip->id = odp_cpu_to_be_16(seq); + ip->chksum = 0; ip->chksum = odph_chksum(ip, ODPH_IPV4HDR_LEN); /* icmp */ @@ -382,7 +427,7 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) icmp->chksum = 0; icmp->chksum = odph_chksum(icmp, args->appl.payload + ODPH_ICMPHDR_LEN); - return pkt; + return 0; } /** @@ -479,33 +524,40 @@ static int create_pktio(const char *dev, odp_pool_t pool, static int gen_send_thread(void *arg) { int thr; - int ret, i; + int ret = 0; thread_args_t *thr_args; odp_pktout_queue_t pktout; + odp_packet_t pkt_ref_array[MAX_UDP_TX_BURST]; odp_packet_t pkt_array[MAX_UDP_TX_BURST]; int pkt_array_size; int burst_start, burst_size; - odp_packet_t pkt_ref = ODP_PACKET_INVALID; + odp_packet_t (*setup_pkt_ref)(odp_pool_t) = NULL; + int (*setup_pkt)(odp_packet_t) = NULL; thr = odp_thread_id(); thr_args = arg; pktout = thr_args->pktout; + /* Create reference packets*/ if (args->appl.mode == APPL_MODE_UDP) { - pkt_ref = setup_udp_pkt_ref(thr_args->pool); pkt_array_size = args->appl.udp_tx_burst; + setup_pkt_ref = setup_udp_pkt_ref; + setup_pkt = setup_udp_pkt; } else if (args->appl.mode == APPL_MODE_PING) { - pkt_ref = setup_icmp_pkt_ref(thr_args->pool); pkt_array_size = 1; + setup_pkt_ref = setup_icmp_pkt_ref; + setup_pkt = setup_icmp_pkt; } else { EXAMPLE_ERR(" [%02i] Error: invalid processing mode %d\n", thr, args->appl.mode); return -1; } - if (pkt_ref == ODP_PACKET_INVALID) { - EXAMPLE_ERR(" [%2i] Error: reference packet creation failed\n", - thr); + + if (setup_pkt_ref_array(thr_args->pool, pkt_ref_array, + pkt_array_size, setup_pkt_ref)) { + EXAMPLE_ERR("[%02i] Error: failed to create" + " reference packets\n", thr); return -1; } @@ -519,30 +571,15 @@ static int gen_send_thread(void *arg) (unsigned int)args->appl.number) break; - if (args->appl.mode == APPL_MODE_UDP) { - for (i = 0; i < pkt_array_size; i++) { - pkt_array[i] = pack_udp_pkt(thr_args->pool, - pkt_ref); - if (!odp_packet_is_valid(pkt_array[i])) - break; - } - if (i != pkt_array_size) { - EXAMPLE_ERR(" [%2i] alloc_multi failed\n", - thr); - odp_packet_free_multi(pkt_array, i); - break; - } - } else if (args->appl.mode == APPL_MODE_PING) { - pkt_array[0] = pack_icmp_pkt(thr_args->pool, pkt_ref); - if (!odp_packet_is_valid(pkt_array[0])) { - EXAMPLE_ERR(" [%2i] alloc_single failed\n", - thr); - break; - } - } else { + /* Setup TX burst*/ + if (setup_pkt_array(pkt_ref_array, pkt_array, + pkt_array_size, setup_pkt)) { + EXAMPLE_ERR("[%02i] Error: failed to setup packets\n", + thr); break; } + /* Send TX burst*/ for (burst_start = 0, burst_size = pkt_array_size;;) { ret = odp_pktout_send(pktout, &pkt_array[burst_start], burst_size); @@ -572,7 +609,6 @@ static int gen_send_thread(void *arg) thr_args->tim, thr_args->tq, thr_args->tmo_ev); - } } @@ -590,7 +626,8 @@ static int gen_send_thread(void *arg) args->appl.timeout--; } } - odp_packet_free(pkt_ref); + + odp_packet_free_multi(pkt_ref_array, pkt_array_size); return 0; } @@ -1084,7 +1121,6 @@ int main(int argc, char *argv[]) odph_odpthreads_create(&thread_tbl[i], &thd_mask, &thr_params); cpu = odp_cpumask_next(&cpumask, cpu); - } } @@ -1132,7 +1168,6 @@ int main(int argc, char *argv[]) return 0; } - /** * Parse and store the command line arguments *