From patchwork Tue Mar 28 11:03:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 96133 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp264331obc; Tue, 28 Mar 2017 04:05:16 -0700 (PDT) X-Received: by 10.200.33.210 with SMTP id 18mr25235791qtz.159.1490699116598; Tue, 28 Mar 2017 04:05:16 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z22si3154797qkg.134.2017.03.28.04.05.16; Tue, 28 Mar 2017 04:05:16 -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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 36B64635DC; Tue, 28 Mar 2017 11:05:16 +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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 459E762F0C; Tue, 28 Mar 2017 11:04:37 +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 ACA0362F0C; Tue, 28 Mar 2017 11:04:28 +0000 (UTC) Received: from mail-wr0-f177.google.com (mail-wr0-f177.google.com [209.85.128.177]) by lists.linaro.org (Postfix) with ESMTPS id B770560A50 for ; Tue, 28 Mar 2017 11:03:42 +0000 (UTC) Received: by mail-wr0-f177.google.com with SMTP id w11so81860908wrc.3 for ; Tue, 28 Mar 2017 04:03:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j+Fso7sysVSkz5wdr6OJ8Ur0/T9NdrlgjUm2rEGiboE=; b=HmIOkTyETkmqfy6E3YEhXy50kE/MzM2PGFau3+C9w7n/za+Vbhi564io7phfj7xAor UXXKwRS6EGInHLRtrWXVj/C0eumaJQvtQvRHcQFh9bTiC6YD+1z5/aFo/huUnB5l2emd SUxz6ZRfl8fO1XZ0LJmMR7O0DWTuO/+gq5TEdShw2dCLFHm65G9WxqkxM1U0Gjsob/PS 8FldYaVjB6BETtLj75frDTDFW30GsqnV9sFNHxoxZ7OmhdRFM3mG3P3UOHpB+k/n/BAS 2//dL10a0lRPJ+ZNJXd6CxBbn8Qx40c/gtKOp98FGGg9h/B/Boki7odXvaeQwYQTK2rG Rb1w== X-Gm-Message-State: AFeK/H1d6QdNxRrpdlA/bL2vaYhnlSfVCA4FTJxRFD3Yx+MECP1onJaSWzzBL06vlxSkj6e6juA= X-Received: by 10.28.1.68 with SMTP id 65mr13814464wmb.63.1490699020227; Tue, 28 Mar 2017 04:03:40 -0700 (PDT) Received: from localhost.localdomain ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id i133sm3141080wmg.26.2017.03.28.04.03.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Mar 2017 04:03:39 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Tue, 28 Mar 2017 14:03:23 +0300 Message-Id: <1490699007-18335-2-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490699007-18335-1-git-send-email-bogdan.pricope@linaro.org> References: <1490699007-18335-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCHv5 1/5] test: generator: compose sending packets from reference packet plus differences 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" Signed-off-by: Bogdan Pricope --- example/generator/odp_generator.c | 130 +++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 17 deletions(-) -- 1.9.1 diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 8062d87..816db88 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -170,21 +170,20 @@ static int scan_ip(char *buf, unsigned int *paddr) } /** - * set up an udp packet + * set up an udp packet reference * * @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_pool_t pool) +static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool) { odp_packet_t pkt; char *buf; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_udphdr_t *udp; - unsigned short seq; pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); @@ -200,8 +199,10 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) memcpy((char *)eth->src.addr, args->appl.srcmac.addr, ODPH_ETHADDR_LEN); memcpy((char *)eth->dst.addr, args->appl.dstmac.addr, ODPH_ETHADDR_LEN); eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4); + /* ip */ odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN); + odp_packet_has_ipv4_set(pkt, 1); ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip); ip->src_addr = odp_cpu_to_be_32(args->appl.srcip); @@ -209,12 +210,13 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN); ip->proto = ODPH_IPPROTO_UDP; - seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF; - ip->id = odp_cpu_to_be_16(seq); + ip->id = 0; + ip->ttl = 64; ip->chksum = 0; - odph_ipv4_csum_update(pkt); + /* udp */ odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); + odp_packet_has_udp_set(pkt, 1); udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); udp->src_port = 0; udp->dst_port = 0; @@ -226,27 +228,60 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool) } /** - * Set up an icmp packet + * set up an udp packet + * + * @param pool Buffer pool to create packet in + * @param pkt_ref Reference UDP packet + * + * @return Handle of created packet + * @retval ODP_PACKET_INVALID Packet could not be created + */ +static odp_packet_t pack_udp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) +{ + 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 = odph_chksum(ip, ODPH_IPV4HDR_LEN); + + return pkt; +} + +/** + * Set up an icmp packet reference * * @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_pool_t pool) +static odp_packet_t setup_icmp_pkt_ref(odp_pool_t pool) { odp_packet_t pkt; char *buf; odph_ethhdr_t *eth; odph_ipv4hdr_t *ip; odph_icmphdr_t *icmp; - struct timeval tval; - uint8_t *tval_d; - unsigned short seq; args->appl.payload = 56; pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_ICMPHDR_LEN + - ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); if (pkt == ODP_PACKET_INVALID) return pkt; @@ -265,18 +300,62 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool) ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip); ip->src_addr = odp_cpu_to_be_32(args->appl.srcip); ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN; + ip->ttl = 64; ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_ICMPHDR_LEN + ODPH_IPV4HDR_LEN); ip->proto = ODPH_IPPROTO_ICMP; - seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff; - ip->id = odp_cpu_to_be_16(seq); + ip->id = 0; ip->chksum = 0; - odph_ipv4_csum_update(pkt); + /* icmp */ icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); icmp->type = ICMP_ECHO; icmp->code = 0; icmp->un.echo.id = 0; + icmp->un.echo.sequence = 0; + icmp->chksum = 0; + + return pkt; +} + +/** + * Set up an icmp packet + * + * @param pool Buffer pool to create packet in + * @param pkt_ref Reference ICMP packet + * + * @return Handle of created packet + * @retval ODP_PACKET_INVALID Packet could not be created + */ +static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref) +{ + odp_packet_t pkt; + char *buf; + odph_ipv4hdr_t *ip; + odph_icmphdr_t *icmp; + struct timeval tval; + 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 = odph_chksum(ip, ODPH_IPV4HDR_LEN); + + /* icmp */ + icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); icmp->un.echo.sequence = ip->id; tval_d = (uint8_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ICMPHDR_LEN); @@ -357,6 +436,7 @@ static int gen_send_thread(void *arg) thread_args_t *thr_args; odp_pktout_queue_t pktout; odp_packet_t pkt; + odp_packet_t pkt_ref = ODP_PACKET_INVALID; thr = odp_thread_id(); thr_args = arg; @@ -373,6 +453,21 @@ static int gen_send_thread(void *arg) return -1; } + if (args->appl.mode == APPL_MODE_UDP) { + pkt_ref = setup_udp_pkt_ref(thr_args->pool); + } else if (args->appl.mode == APPL_MODE_PING) { + pkt_ref = setup_icmp_pkt_ref(thr_args->pool); + } 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); + return -1; + } + printf(" [%02i] created mode: SEND\n", thr); odp_barrier_wait(&barrier); @@ -386,9 +481,9 @@ static int gen_send_thread(void *arg) pkt = ODP_PACKET_INVALID; if (args->appl.mode == APPL_MODE_UDP) - pkt = pack_udp_pkt(thr_args->pool); + pkt = pack_udp_pkt(thr_args->pool, pkt_ref); else if (args->appl.mode == APPL_MODE_PING) - pkt = pack_icmp_pkt(thr_args->pool); + pkt = pack_icmp_pkt(thr_args->pool, pkt_ref); if (pkt == ODP_PACKET_INVALID) { /* Thread gives up as soon as it sees the pool empty. @@ -440,6 +535,7 @@ static int gen_send_thread(void *arg) args->appl.timeout--; } } + odp_packet_free(pkt_ref); return 0; }