From patchwork Tue Nov 11 04:03:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 40549 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 13172244B6 for ; Tue, 11 Nov 2014 04:08:31 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf4922037lbj.3 for ; Mon, 10 Nov 2014 20:08:29 -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:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=fURU/RYwfCpxoacknf8LzDidXUzKsQ5aAsZ5NubZMM0=; b=MyaYf3b5N7eTJoCYBrztdgeHA13pgghFSlbLk7P9mYf9EEJ4DVAuCARJ/dPgc8BhxN 7DA+vbx67+NubMh8Pd5EPjFzvmw18EFq1Fed+PGij5mksjT2+ZsBBYb3Wtma2rw7ib30 F+nREXjVKcEswGTFXMhKPplB/2Ton32qC8fTN+P8Oh8SJ4QZGY+t4lIyEXStMHGOmhDz QQWLiQW55CHv2tIXAYmPXhNllXHzOtfAzORmPpVqeCRkrC+tPw7ZMOHBqt3+1OKihFKG 10gLZ164l8EAZHmspbJ2NlPyzEea+VDaI8yOl8DFNsh4xnaz8ChxAGDEdcLNx/niHWl1 ai5A== X-Gm-Message-State: ALoCoQnycEZRtWZq6weQCv1M0RjHmat8478U4FCiIi4cYWBbUSfQaIJg+7EZHl4zRyqu6reo/GPP X-Received: by 10.181.8.194 with SMTP id dm2mr4811217wid.2.1415678909932; Mon, 10 Nov 2014 20:08:29 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.72 with SMTP id b8ls227374laf.2.gmail; Mon, 10 Nov 2014 20:08:29 -0800 (PST) X-Received: by 10.152.207.71 with SMTP id lu7mr7052297lac.81.1415678909572; Mon, 10 Nov 2014 20:08:29 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id lk6si29888159lac.74.2014.11.10.20.08.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 20:08:29 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so7103075lbv.12 for ; Mon, 10 Nov 2014 20:08:29 -0800 (PST) X-Received: by 10.112.45.228 with SMTP id q4mr34125257lbm.35.1415678909397; Mon, 10 Nov 2014 20:08:29 -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.184.201 with SMTP id ew9csp200027lbc; Mon, 10 Nov 2014 20:08:28 -0800 (PST) X-Received: by 10.224.75.2 with SMTP id w2mr46546042qaj.86.1415678908133; Mon, 10 Nov 2014 20:08:28 -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 a2si34930740qam.18.2014.11.10.20.08.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 10 Nov 2014 20:08:28 -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 1Xo2kk-0003Th-Fv; Tue, 11 Nov 2014 04:08:26 +0000 Received: from mail-oi0-f45.google.com ([209.85.218.45]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xo2gF-00038c-2G for lng-odp@lists.linaro.org; Tue, 11 Nov 2014 04:03:47 +0000 Received: by mail-oi0-f45.google.com with SMTP id v63so6474088oia.4 for ; Mon, 10 Nov 2014 20:03:41 -0800 (PST) X-Received: by 10.182.92.234 with SMTP id cp10mr9091obb.53.1415678621188; Mon, 10 Nov 2014 20:03:41 -0800 (PST) Received: from localhost.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by mx.google.com with ESMTPSA id ln10sm7905136obc.24.2014.11.10.20.03.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 20:03:40 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 10 Nov 2014 22:03:09 -0600 Message-Id: <1415678595-31405-5-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415678595-31405-1-git-send-email-bill.fischofer@linaro.org> References: <1415678595-31405-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH ODP v1.0 Buffer/Packet APIs 3/9] Modifications to example programs to work with v1.0 buffer/packet APIs 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: bill.fischofer@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.217.181 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 Signed-off-by: Bill Fischofer --- example/generator/odp_generator.c | 69 +++++++++------------- example/ipsec/odp_ipsec.c | 120 +++++++++++--------------------------- example/ipsec/odp_ipsec_stream.c | 25 ++++---- example/l2fwd/odp_l2fwd.c | 22 +++---- example/odp_example/odp_example.c | 18 ++---- example/packet/odp_pktio.c | 28 ++++----- example/timer/odp_timer_test.c | 20 +++---- 7 files changed, 107 insertions(+), 195 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index ffa5e62..efa418f 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -168,24 +167,24 @@ static int scan_mac(char *in, odph_ethaddr_t *des) * * @param obuf packet buffer */ -static void pack_udp_pkt(odp_buffer_t obuf) +static void pack_udp_pkt(odp_packet_t pkt) { char *buf; - int max; - odp_packet_t pkt; + odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_udphdr_t *udp; unsigned short seq; + size_t seglen; + + buf = odp_packet_push_tail_and_map(pkt, args->appl.payload + + ODPH_UDPHDR_LEN + + ODPH_IPV4HDR_LEN + + ODPH_ETHHDR_LEN, &seglen); - buf = odp_buffer_addr(obuf); if (buf == NULL) return; - max = odp_buffer_size(obuf); - if (max <= 0) - return; - pkt = odp_packet_from_buffer(obuf); /* ether */ odp_packet_set_l2_offset(pkt, 0); eth = (odph_ethhdr_t *)buf; @@ -213,8 +212,7 @@ 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); + } /** @@ -222,27 +220,27 @@ static void pack_udp_pkt(odp_buffer_t obuf) * * @param obuf packet buffer */ -static void pack_icmp_pkt(odp_buffer_t obuf) +static void pack_icmp_pkt(odp_packet_t pkt) { char *buf; - int max; - odp_packet_t pkt; + odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; struct timeval tval; uint8_t *tval_d; unsigned short seq; + size_t seglen; - buf = odp_buffer_addr(obuf); + buf = odp_packet_push_tail_and_map(pkt, args->appl.payload + + ODPH_ICMPHDR_LEN + + ODPH_IPV4HDR_LEN + + ODPH_ETHHDR_LEN, &seglen); if (buf == NULL) return; - max = odp_buffer_size(obuf); - if (max <= 0) - return; args->appl.payload = 56; - pkt = odp_packet_from_buffer(obuf); + /* ether */ odp_packet_set_l2_offset(pkt, 0); eth = (odph_ethhdr_t *)buf; @@ -277,9 +275,6 @@ static void pack_icmp_pkt(odp_buffer_t obuf) icmp->chksum = 0; 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); } /** @@ -295,7 +290,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 buf; thr = odp_thread_id(); thr_args = arg; @@ -316,8 +311,8 @@ 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)) { + buf = odp_packet_alloc(thr_args->pool); + if (!odp_packet_is_valid(buf)) { ODP_ERR(" [%2i] alloc_single failed\n", thr); return NULL; } @@ -493,13 +488,13 @@ static void *gen_recv_thread(void *arg) pkt = odp_packet_from_buffer(buf); /* Drop packets with errors */ if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); + odp_packet_free(pkt); continue; } print_pkts(thr, &pkt, 1); - odph_packet_free(pkt); + odp_packet_free(pkt); } return arg; @@ -512,11 +507,11 @@ int main(int argc, char *argv[]) odph_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_buffer_pool_t pool; int num_workers; - void *pool_base; int i; int first_core; int core_count; odp_shm_t shm; + odp_buffer_pool_param_t params; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -579,20 +574,14 @@ int main(int argc, char *argv[]) printf("First core: %i\n\n", first_core); /* Create packet pool */ - shm = odp_shm_reserve("shm_packet_pool", - SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); - if (pool_base == NULL) { - ODP_ERR("Error: packet pool mem alloc failed.\n"); - exit(EXIT_FAILURE); - } + params.buf_size = SHM_PKT_POOL_BUF_SIZE; + params.buf_num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; + params.buf_type = ODP_BUFFER_TYPE_PACKET; + params.buf_opts = ODP_BUFFER_OPTS_UNSEGMENTED; + + pool = odp_buffer_pool_create("packet_pool", ¶ms, NULL); - pool = odp_buffer_pool_create("packet_pool", pool_base, - SHM_PKT_POOL_SIZE, - SHM_PKT_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_PACKET); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index da6c48e..3b39be2 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -154,8 +153,6 @@ typedef struct { #define SHM_CTX_POOL_BUF_COUNT (SHM_PKT_POOL_BUF_COUNT + SHM_OUT_POOL_BUF_COUNT) #define SHM_CTX_POOL_SIZE (SHM_CTX_POOL_BUF_COUNT * SHM_CTX_POOL_BUF_SIZE) -static odp_buffer_pool_t ctx_pool = ODP_BUFFER_POOL_INVALID; - /** * Get per packet processing context from packet buffer * @@ -166,33 +163,7 @@ static odp_buffer_pool_t ctx_pool = ODP_BUFFER_POOL_INVALID; static pkt_ctx_t *get_pkt_ctx_from_pkt(odp_packet_t pkt) { - return (pkt_ctx_t *)odp_packet_get_ctx(pkt); -} - -/** - * Allocate per packet processing context and associate it with - * packet buffer - * - * @param pkt Packet - * - * @return pointer to context area - */ -static -pkt_ctx_t *alloc_pkt_ctx(odp_packet_t pkt) -{ - odp_buffer_t ctx_buf = odp_buffer_alloc(ctx_pool); - pkt_ctx_t *ctx; - - /* There should always be enough contexts */ - if (odp_unlikely(ODP_BUFFER_INVALID == ctx_buf)) - abort(); - - ctx = odp_buffer_addr(ctx_buf); - memset(ctx, 0, sizeof(*ctx)); - ctx->buffer = ctx_buf; - odp_packet_set_ctx(pkt, ctx); - - return ctx; + return (pkt_ctx_t *)odp_packet_udata_addr(pkt); } /** @@ -365,8 +336,7 @@ static void ipsec_init_pre(void) { odp_queue_param_t qparam; - void *pool_base; - odp_shm_t shm; + odp_buffer_pool_param_t params; /* * Create queues @@ -399,16 +369,12 @@ void ipsec_init_pre(void) } /* Create output buffer pool */ - shm = odp_shm_reserve("shm_out_pool", - SHM_OUT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + params.buf_num = SHM_OUT_POOL_BUF_COUNT; + params.buf_size = SHM_OUT_POOL_BUF_SIZE; + params.buf_type = ODP_BUFFER_TYPE_PACKET; + params.buf_opts = ODP_BUFFER_OPTS_UNSEGMENTED; - pool_base = odp_shm_addr(shm); - - out_pool = odp_buffer_pool_create("out_pool", pool_base, - SHM_OUT_POOL_SIZE, - SHM_OUT_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_PACKET); + out_pool = odp_buffer_pool_create("out_pool", ¶ms, NULL); if (ODP_BUFFER_POOL_INVALID == out_pool) { ODP_ERR("Error: message pool create failed.\n"); @@ -637,13 +603,15 @@ pkt_disposition_e do_input_verify(odp_packet_t pkt, pkt_ctx_t *ctx ODP_UNUSED) static pkt_disposition_e do_route_fwd_db(odp_packet_t pkt, pkt_ctx_t *ctx) { - odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + size_t seglen; + odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &seglen); fwd_db_entry_t *entry; entry = find_fwd_db_entry(odp_be_to_cpu_32(ip->dst_addr)); if (entry) { - odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2(pkt); + odph_ethhdr_t *eth = + (odph_ethhdr_t *)odp_packet_l2_map(pkt, &seglen); memcpy(ð->dst, entry->dst_mac, ODPH_ETHADDR_LEN); memcpy(ð->src, entry->src_mac, ODPH_ETHADDR_LEN); @@ -673,8 +641,9 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt, pkt_ctx_t *ctx, bool *skip) { + size_t seglen; uint8_t *buf = odp_packet_addr(pkt); - odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &seglen); int hdr_len; odph_ahhdr_t *ah = NULL; odph_esphdr_t *esp = NULL; @@ -759,6 +728,7 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt, odp_crypto_compl_status_t cipher_rc; odp_crypto_compl_status_t auth_rc; odph_ipv4hdr_t *ip; + size_t seglen; int hdr_len = ctx->ipsec.hdr_len; int trl_len = 0; @@ -769,7 +739,7 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt, return PKT_DROP; if (!is_crypto_compl_status_ok(&auth_rc)) return PKT_DROP; - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &seglen); /* * Finish auth @@ -803,11 +773,11 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt, ip->chksum = 0; odph_ipv4_csum_update(pkt); - /* Correct the packet length and move payload into position */ - odp_packet_set_len(pkt, odp_packet_get_len(pkt) - (hdr_len + trl_len)); + /* Move payload into position and correct the packet length */ memmove(ipv4_data_p(ip), ipv4_data_p(ip) + hdr_len, odp_be_to_cpu_16(ip->tot_len)); + odp_packet_pull_tail(pkt, hdr_len + trl_len); /* Fall through to next state */ return PKT_CONTINUE; @@ -833,8 +803,9 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt, pkt_ctx_t *ctx, bool *skip) { + size_t seglen; uint8_t *buf = odp_packet_addr(pkt); - odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &seglen); uint16_t ip_data_len = ipv4_data_len(ip); uint8_t *ip_data = ipv4_data_p(ip); ipsec_cache_entry_t *entry; @@ -921,7 +892,7 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt, /* Set IPv4 length before authentication */ ipv4_adjust_len(ip, hdr_len + trl_len); - odp_packet_set_len(pkt, odp_packet_get_len(pkt) + (hdr_len + trl_len)); + odp_packet_push_tail(pkt, hdr_len + trl_len); /* Save remaining context */ ctx->ipsec.hdr_len = hdr_len; @@ -995,6 +966,7 @@ pkt_disposition_e do_ipsec_out_finish(odp_packet_t pkt, odp_crypto_compl_status_t cipher_rc; odp_crypto_compl_status_t auth_rc; odph_ipv4hdr_t *ip; + size_t seglen; /* Check crypto result */ event = odp_packet_to_buffer(pkt); @@ -1003,7 +975,7 @@ pkt_disposition_e do_ipsec_out_finish(odp_packet_t pkt, return PKT_DROP; if (!is_crypto_compl_status_ok(&auth_rc)) return PKT_DROP; - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &seglen); /* Finalize the IPv4 header */ ip->ttl = ctx->ipsec.ip_ttl; @@ -1057,7 +1029,7 @@ void *pktio_thread(void *arg ODP_UNUSED) /* Determine new work versus completion or sequence number */ if ((completionq != dispatchq) && (seqnumq != dispatchq)) { - ctx = alloc_pkt_ctx(pkt); + ctx = get_pkt_ctx_from_pkt(pkt); ctx->state = PKT_STATE_INPUT_VERIFY; } else { ctx = get_pkt_ctx_from_pkt(pkt); @@ -1144,7 +1116,7 @@ void *pktio_thread(void *arg ODP_UNUSED) /* Check for drop */ if (PKT_DROP == rc) - odph_packet_free(pkt); + odp_packet_free(pkt); /* Print packet counts every once in a while */ if (PKT_DONE == rc) { @@ -1167,12 +1139,13 @@ main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; int num_workers; - void *pool_base; int i; int first_core; int core_count; int stream_count; odp_shm_t shm; + odp_buffer_pool_param_t params; + odp_buffer_pool_init_t init_params; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -1232,47 +1205,22 @@ main(int argc, char *argv[]) printf("First core: %i\n\n", first_core); /* Create packet buffer pool */ - shm = odp_shm_reserve("shm_packet_pool", - SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); + params.buf_num = SHM_PKT_POOL_BUF_COUNT; + params.buf_size = SHM_PKT_POOL_BUF_SIZE; + params.buf_type = ODP_BUFFER_TYPE_PACKET; + params.buf_opts = ODP_BUFFER_OPTS_UNSEGMENTED; - pool_base = odp_shm_addr(shm); + init_params.udata_size = sizeof(pkt_ctx_t); + init_params.buf_init = NULL; + init_params.buf_init_arg = NULL; - if (NULL == pool_base) { - ODP_ERR("Error: packet pool mem alloc failed.\n"); - exit(EXIT_FAILURE); - } + pkt_pool = odp_buffer_pool_create("packet_pool", ¶ms, &init_params); - pkt_pool = odp_buffer_pool_create("packet_pool", pool_base, - SHM_PKT_POOL_SIZE, - SHM_PKT_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_PACKET); if (ODP_BUFFER_POOL_INVALID == pkt_pool) { ODP_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); } - /* Create context buffer pool */ - shm = odp_shm_reserve("shm_ctx_pool", - SHM_CTX_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - - pool_base = odp_shm_addr(shm); - - if (NULL == pool_base) { - ODP_ERR("Error: context pool mem alloc failed.\n"); - exit(EXIT_FAILURE); - } - - ctx_pool = odp_buffer_pool_create("ctx_pool", pool_base, - SHM_CTX_POOL_SIZE, - SHM_CTX_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_RAW); - if (ODP_BUFFER_POOL_INVALID == ctx_pool) { - ODP_ERR("Error: context pool create failed.\n"); - exit(EXIT_FAILURE); - } - /* Populate our IPsec cache */ printf("Using %s mode for crypto API\n\n", (CRYPTO_API_SYNC == args->appl.mode) ? "SYNC" : diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c index fa9aba8..309cf70 100644 --- a/example/ipsec/odp_ipsec_stream.c +++ b/example/ipsec/odp_ipsec_stream.c @@ -14,7 +14,6 @@ #include -#include #include #include #include @@ -173,7 +172,6 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, odp_buffer_pool_t pkt_pool) { ipsec_cache_entry_t *entry = stream->input.entry; - odp_buffer_t bfr; odp_packet_t pkt; uint8_t *base; uint8_t *data; @@ -184,18 +182,19 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, odph_icmphdr_t *icmp; stream_pkt_hdr_t *test; uint i; + size_t seglen; - /* Get buffer */ - bfr = odp_buffer_alloc(pkt_pool); - if (ODP_BUFFER_INVALID == bfr) + /* Get packet */ + pkt = odp_packet_alloc(pkt_pool); + if (ODP_PACKET_INVALID == pkt) return ODP_PACKET_INVALID; - pkt = odp_packet_from_buffer(bfr); - odp_packet_init(pkt); - base = odp_packet_data(pkt); - data = odp_packet_data(pkt); + + base = odp_packet_map(pkt, &seglen); + data = base; /* Ethernet */ odp_packet_set_inflag_eth(pkt, 1); + odp_packet_set_inflag_l2(pkt, 1); odp_packet_set_l2_offset(pkt, data - base); eth = (odph_ethhdr_t *)data; data += sizeof(*eth); @@ -251,6 +250,7 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, /* ICMP header so we can see it on wireshark */ icmp = (odph_icmphdr_t *)data; data += sizeof(*icmp); + icmp->type = ICMP_ECHO; icmp->code = 0; icmp->un.echo.id = odp_cpu_to_be_16(0x1234); @@ -303,7 +303,7 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, /* Since ESP can pad we can now fix IP length */ ip->tot_len = odp_cpu_to_be_16(data - (uint8_t *)ip); - odp_packet_set_len(pkt, data - base); + odp_packet_push_tail(pkt, data - base); /* Close AH if specified */ if (ah) { @@ -344,9 +344,10 @@ bool verify_ipv4_packet(stream_db_entry_t *stream, int hdr_len; odph_icmphdr_t *icmp; stream_pkt_hdr_t *test; + size_t seglen; /* Basic IPv4 verify (add checksum verification) */ - data = odp_packet_l3(pkt); + data = odp_packet_l3_map(pkt, &seglen); ip = (odph_ipv4hdr_t *)data; data += sizeof(*ip); if (0x45 != ip->ver_ihl) @@ -546,7 +547,7 @@ bool verify_stream_db_outputs(void) good = verify_ipv4_packet(stream, pkt); if (good) stream->verified++; - odph_packet_free(pkt); + odp_packet_free(pkt); } } diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index 57037cd..c43ef86 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -311,12 +310,12 @@ int main(int argc, char *argv[]) { odph_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_buffer_pool_t pool; - void *pool_base; int i; int first_core; int core_count; odp_pktio_t pktio; odp_shm_t shm; + odp_buffer_pool_param_t params; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -380,20 +379,13 @@ int main(int argc, char *argv[]) printf("First core: %i\n\n", first_core); /* Create packet pool */ - shm = odp_shm_reserve("shm_packet_pool", - SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); + params.buf_num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; + params.buf_size = SHM_PKT_POOL_BUF_SIZE; + params.buf_type = ODP_BUFFER_TYPE_PACKET; + params.buf_opts = ODP_BUFFER_OPTS_UNSEGMENTED; - if (pool_base == NULL) { - ODP_ERR("Error: packet pool mem alloc failed.\n"); - exit(EXIT_FAILURE); - } + pool = odp_buffer_pool_create("packet_pool", ¶ms, NULL); - pool = odp_buffer_pool_create("packet_pool", pool_base, - SHM_PKT_POOL_SIZE, - SHM_PKT_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_PACKET); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); @@ -480,7 +472,7 @@ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len) pkt = pkt_tbl[i]; if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); /* Drop */ + odp_packet_free(pkt); /* Drop */ pkt_cnt--; } else if (odp_unlikely(i != j++)) { pkt_tbl[j-1] = pkt; diff --git a/example/odp_example/odp_example.c b/example/odp_example/odp_example.c index d0ec977..3c31999 100644 --- a/example/odp_example/odp_example.c +++ b/example/odp_example/odp_example.c @@ -949,13 +949,13 @@ int main(int argc, char *argv[]) test_args_t args; int num_workers; odp_buffer_pool_t pool; - void *pool_base; odp_queue_t queue; int i, j; int prios; int first_core; odp_shm_t shm; test_globals_t *globals; + odp_buffer_pool_param_t params; printf("\nODP example starts\n\n"); @@ -1037,19 +1037,13 @@ int main(int argc, char *argv[]) /* * Create message pool */ - shm = odp_shm_reserve("msg_pool", - MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); + params.buf_num = MSG_POOL_SIZE/sizeof(test_message_t); + params.buf_size = sizeof(test_message_t); + params.buf_type = ODP_BUFFER_TYPE_RAW; + params.buf_opts = ODP_BUFFER_OPTS_NONE; - if (pool_base == NULL) { - ODP_ERR("Shared memory reserve failed.\n"); - return -1; - } - - pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, - sizeof(test_message_t), - ODP_CACHE_LINE_SIZE, ODP_BUFFER_TYPE_RAW); + pool = odp_buffer_pool_create("msg_pool", ¶ms, NULL); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Pool create failed.\n"); diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 2cf3f0d..64161f2 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -292,11 +291,11 @@ int main(int argc, char *argv[]) odph_linux_pthread_t thread_tbl[MAX_WORKERS]; odp_buffer_pool_t pool; int num_workers; - void *pool_base; int i; int first_core; int core_count; odp_shm_t shm; + odp_buffer_pool_param_t params; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -350,20 +349,13 @@ int main(int argc, char *argv[]) printf("First core: %i\n\n", first_core); /* Create packet pool */ - shm = odp_shm_reserve("shm_packet_pool", - SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); + params.buf_num = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; + params.buf_size = SHM_PKT_POOL_BUF_SIZE; + params.buf_type = ODP_BUFFER_TYPE_PACKET; + params.buf_opts = ODP_BUFFER_OPTS_UNSEGMENTED; - if (pool_base == NULL) { - ODP_ERR("Error: packet pool mem alloc failed.\n"); - exit(EXIT_FAILURE); - } + pool = odp_buffer_pool_create("packet_pool", ¶ms, NULL); - pool = odp_buffer_pool_create("packet_pool", pool_base, - SHM_PKT_POOL_SIZE, - SHM_PKT_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_PACKET); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Error: packet pool create failed.\n"); exit(EXIT_FAILURE); @@ -427,7 +419,7 @@ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len) pkt = pkt_tbl[i]; if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); /* Drop */ + odp_packet_free(pkt); /* Drop */ pkt_cnt--; } else if (odp_unlikely(i != j++)) { pkt_tbl[j-1] = pkt; @@ -452,11 +444,12 @@ static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len) odph_ipv4hdr_t *ip; uint32be_t ip_tmp_addr; /* tmp ip addr */ unsigned i; + size_t seglen; for (i = 0; i < len; ++i) { pkt = pkt_tbl[i]; if (odp_packet_inflag_eth(pkt)) { - eth = (odph_ethhdr_t *)odp_packet_l2(pkt); + eth = (odph_ethhdr_t *)odp_packet_l2_map(pkt, &seglen); tmp_addr = eth->dst; eth->dst = eth->src; @@ -464,7 +457,8 @@ static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len) if (odp_packet_inflag_ipv4(pkt)) { /* IPv4 */ - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *) + odp_packet_l3_map(pkt, &seglen); ip_tmp_addr = ip->src_addr; ip->src_addr = ip->dst_addr; diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c index 78b2ae2..c0fcf49 100644 --- a/example/timer/odp_timer_test.c +++ b/example/timer/odp_timer_test.c @@ -242,12 +242,11 @@ int main(int argc, char *argv[]) test_args_t args; int num_workers; odp_buffer_pool_t pool; - void *pool_base; odp_queue_t queue; int first_core; uint64_t cycles, ns; odp_queue_param_t param; - odp_shm_t shm; + odp_buffer_pool_param_t params; printf("\nODP timer example starts\n"); @@ -306,17 +305,12 @@ int main(int argc, char *argv[]) printf("period: %i usec\n", args.period_us); printf("timeouts: %i\n", args.tmo_count); - /* - * Create message pool - */ - shm = odp_shm_reserve("msg_pool", - MSG_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); - - pool = odp_buffer_pool_create("msg_pool", pool_base, MSG_POOL_SIZE, - 0, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_TIMEOUT); + params.buf_num = 1024; + params.buf_size = 0; + params.buf_type = ODP_BUFFER_TYPE_TIMEOUT; + params.buf_opts = ODP_BUFFER_OPTS_NONE; + + pool = odp_buffer_pool_create("msg_pool", ¶ms, NULL); if (pool == ODP_BUFFER_POOL_INVALID) { ODP_ERR("Pool create failed.\n");