From patchwork Tue Dec 16 12:30:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42330 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B9CB22456A for ; Tue, 16 Dec 2014 12:32:05 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf8556078wgg.0 for ; Tue, 16 Dec 2014 04:32:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state: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=Y5jaNam0pAXoDf/xhdPhCPH90zR+iYMXmDqAE6eZZqw=; b=ew+9IL3PTe0aPKe5U1cqRi000j9VA7qOb52QRg5YvkyiuumlDTpyy4NE3qYSW+Kuy6 UHsV9lN9sFa0z023bzA+A30rWKoi/JXMKBskJM+9weP7oroP7Qtt1JvuT1MCVIGjxr22 EdqEqI+I9ptUWbMtAzgUISnGKN2IDB3TTCY3Lo3wnbONJwsDKtwTnx2wBqSokgsP/iQz 82KJ6wdc9vwzvjoNP4MjcHs1GGjbb5TnbohOe3dyGaxhA9XOpTZp4WkwIwFDeHspnBBP dG32CN4cl9DkkQ78n7Sf+fqvlHXo4QXasekD0ol5M9MwHQx2nPwZ+LjBeHe0Zyg21v/a qZYA== X-Gm-Message-State: ALoCoQntm7AperfngH+1eGEx74MWnrZCdlg0SNzte2vKC9IvEo5JMoG0CWtmn5jqomMaqD2yW6Pt X-Received: by 10.180.24.35 with SMTP id r3mr425303wif.0.1418733125014; Tue, 16 Dec 2014 04:32:05 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.65 with SMTP id kw1ls886847lac.70.gmail; Tue, 16 Dec 2014 04:32:04 -0800 (PST) X-Received: by 10.112.134.134 with SMTP id pk6mr35787542lbb.14.1418733124845; Tue, 16 Dec 2014 04:32:04 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id k1si622819lah.94.2014.12.16.04.32.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:32:04 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id pn19so11354477lab.9 for ; Tue, 16 Dec 2014 04:32:04 -0800 (PST) X-Received: by 10.112.219.37 with SMTP id pl5mr32685658lbc.25.1418733124744; Tue, 16 Dec 2014 04:32:04 -0800 (PST) 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.142.69 with SMTP id ru5csp1020089lbb; Tue, 16 Dec 2014 04:32:04 -0800 (PST) X-Received: by 10.140.41.169 with SMTP id z38mr25551890qgz.56.1418733120496; Tue, 16 Dec 2014 04:32:00 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id t64si601727qgt.111.2014.12.16.04.31.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:32:00 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rID-0006dm-Mg; Tue, 16 Dec 2014 12:31:57 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rHP-0006Ul-M1 for lng-odp@lists.linaro.org; Tue, 16 Dec 2014 12:31:07 +0000 Received: by mail-la0-f50.google.com with SMTP id pn19so11033712lab.23 for ; Tue, 16 Dec 2014 04:31:02 -0800 (PST) X-Received: by 10.152.6.166 with SMTP id c6mr35326513laa.20.1418733061898; Tue, 16 Dec 2014 04:31:01 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id eg2sm169516lbb.29.2014.12.16.04.31.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 04:31:01 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 16 Dec 2014 14:30:40 +0200 Message-Id: <1418733042-18047-8-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418733042-18047-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418733042-18047-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 7/9] example: generator: use odp_packet_alloc() API X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: taras.kondratiuk@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.50 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 From: Bill Fischofer Signed-off-by: Bill Fischofer Signed-off-by: Taras Kondratiuk --- example/generator/odp_generator.c | 81 +++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index aec2275..d4bea92 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -168,26 +168,28 @@ static int scan_mac(char *in, odph_ethaddr_t *des) /** * set up an udp packet * - * @param obuf packet buffer -*/ -static void pack_udp_pkt(odp_buffer_t obuf) + * @param pool Buffer pool to create packet in + * + * @return Handle of created packet + * @retval ODP_PACKET_INVALID Packet could not be created + */ +static odp_packet_t pack_udp_pkt(odp_buffer_pool_t pool) { - char *buf; - int max; odp_packet_t pkt; + char *buf; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_udphdr_t *udp; unsigned short seq; - buf = odp_buffer_addr(obuf); - if (buf == NULL) - return; - max = odp_buffer_size(obuf); - if (max <= 0) - return; + 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 = odp_packet_data(pkt); - pkt = odp_packet_from_buffer(obuf); /* ether */ odp_packet_l2_offset_set(pkt, 0); eth = (odph_ethhdr_t *)buf; @@ -215,20 +217,22 @@ static void pack_udp_pkt(odp_buffer_t obuf) udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN); udp->chksum = 0; udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt)); - odp_packet_set_len(pkt, args->appl.payload + ODPH_UDPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + + return pkt; } /** * Set up an icmp packet * - * @param obuf packet buffer -*/ -static void pack_icmp_pkt(odp_buffer_t obuf) + * @param pool Buffer pool to create packet in + * + * @return Handle of created packet + * @retval ODP_PACKET_INVALID Packet could not be created + */ +static odp_packet_t pack_icmp_pkt(odp_buffer_pool_t pool) { - char *buf; - int max; odp_packet_t pkt; + char *buf; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; @@ -236,15 +240,15 @@ static void pack_icmp_pkt(odp_buffer_t obuf) uint8_t *tval_d; unsigned short seq; - buf = odp_buffer_addr(obuf); - if (buf == NULL) - return; - max = odp_buffer_size(obuf); - if (max <= 0) - return; - args->appl.payload = 56; - pkt = odp_packet_from_buffer(obuf); + 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 = odp_packet_data(pkt); + /* ether */ odp_packet_l2_offset_set(pkt, 0); eth = (odph_ethhdr_t *)buf; @@ -280,8 +284,7 @@ static void pack_icmp_pkt(odp_buffer_t obuf) icmp->chksum = odp_chksum(icmp, args->appl.payload + ODPH_ICMPHDR_LEN); - odp_packet_set_len(pkt, args->appl.payload + ODPH_ICMPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + return pkt; } /** @@ -297,7 +300,7 @@ static void *gen_send_thread(void *arg) thread_args_t *thr_args; odp_queue_t outq_def; - odp_buffer_t buf; + odp_packet_t pkt; thr = odp_thread_id(); thr_args = arg; @@ -318,18 +321,20 @@ static void *gen_send_thread(void *arg) printf(" [%02i] created mode: SEND\n", thr); for (;;) { int err; - buf = odp_buffer_alloc(thr_args->pool); - if (!odp_buffer_is_valid(buf)) { - EXAMPLE_ERR(" [%2i] alloc_single failed\n", thr); - return NULL; - } if (args->appl.mode == APPL_MODE_UDP) - pack_udp_pkt(buf); + pkt = pack_udp_pkt(thr_args->pool); else if (args->appl.mode == APPL_MODE_PING) - pack_icmp_pkt(buf); + pkt = pack_icmp_pkt(thr_args->pool); + else + pkt = ODP_PACKET_INVALID; + + if (!odp_packet_is_valid(pkt)) { + EXAMPLE_ERR(" [%2i] alloc_single failed\n", thr); + return NULL; + } - err = odp_queue_enq(outq_def, buf); + err = odp_queue_enq(outq_def, odp_packet_to_buffer(pkt)); if (err != 0) { EXAMPLE_ERR(" [%02i] send pkt err!\n", thr); return NULL;