From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 65B3247122; Sun, 28 Dec 2025 19:46:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4DF4740653; Sun, 28 Dec 2025 19:45:52 +0100 (CET) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mails.dpdk.org (Postfix) with ESMTP id 60061402E8 for ; Sun, 28 Dec 2025 19:45:46 +0100 (CET) Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-430f3ef2d37so6646854f8f.3 for ; Sun, 28 Dec 2025 10:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1766947546; x=1767552346; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w3fJaT/SSBLh+NEimCXqyX/PMjT8ge34el/C578d1Bc=; b=Vi4Mgn85O875P8lL1wkvloXT3IzAepD62pUDOPkpgx8QlZEygGghHY5oufcCyGCWQn LpHPyh+xPHxOgayD/mP19Q8JqMge4reqNYVJsy2vzT4iEYONDHXcEyrVYuuGj72zPfdL 4uqSazD+9VvUc5ExHWmGmjQQUh4nHjLdx2IPxxqFAueeZ6OsW89CRClhjhYgOARuphaD N3u+IoRXdPQSyJzhS8SdzSnULFjUDlnbtWdDj4hATvPSM6RZhvwBeMQ5gttE1kmTWGUV tlhucyxOW5qJoqalW4z/f/ftKAd/1k8kzkUR4lw2MllZgCsKEALroXot4S6bJAZbmSTO OGRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766947546; x=1767552346; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=w3fJaT/SSBLh+NEimCXqyX/PMjT8ge34el/C578d1Bc=; b=DzEB8QSx9xMwovi4JgMopl4jEuTELL/5WHzBJ0aZS93XkP8OB585rdnqc9AJxB/+aU bxwqqjukG7H0GvX30MBh/tLeAP56H6U4uWEEmAGRrh2GdB6oBKDcUU3H4HDHjdXCC/ye C0RrN7/oTYJHPIvyTq/FS566FYsMlrK1EMGCVZhoLfzgxre5TV+GHWAPZ3ipNRh2IHNv a7js92QqGU9dagJdHzS1jZ6j+KAQxFa5EJ9me1XWNFkCtxrWAYUSstlSZAxtj8ewgHct +xRhyai09tRW2AuvSOlnDU+mIkMdfm5Mm5SCeVqpRQ0DCKZNDSX2t7fvGs07+tuhzJ6v qXnA== X-Gm-Message-State: AOJu0YyetSmb0Q8cbnaLI0K6gV8s4i9kHNV82745+0pLjuJhzXxyzx+6 6wPbicAdMMVwe7Loke5UxhwAm3gmPqC0HZsN21ozKHTfftR8wjdpBdfRp+QWAkbOedm4Sf1M5dh EtIc01lI= X-Gm-Gg: AY/fxX7WgzWs8QACuwsldiBBHqrT1e4jGKe+bX6nsatA9qZWJ2BMv2zjsboBvI8JVXI S63C5hZ81NIYXDjlc2ldtsWy0NticMccEkTwrwek5WQ+URpzgean/m92MMKijWkkGw5GwHEltLE QhgchL18VCNk1MN2XAlpa3JTlZtM+f5LwypcbZWWGkTwKtQGZENI/euxc3aOHF2x7Nrtd8l9uDM VBQmgbe7pEEh58EKvw6RDZ33Sv51JSJAtecubKU6qk9JtKvkhz4SUg5u3KyZEHDZbL3RloG07no G+RzHwYteC6jue0vl9uzImDEC4+QFSUxGlrgeF4CyLFOpTuucP2HX8rla1AvvjHWenc0vPkiR38 b130IPZH+JKcjisTf2zK+KlGe6JgwinSuE60AwAjPQ7Ia5+V1I029Ko1GGbEFXK+ChrqyTXf9IO MGseHf38huaSE02EfYOCTb4E6a86JwdzOe9uAQ89ew0KmwrRW8rQ== X-Google-Smtp-Source: AGHT+IHkzgBG+9CazmWsrJc373erYMjchWMrqdz44gBtbTEhHNXe6R4/jIKc/DI0suFOnBqMua0RsA== X-Received: by 2002:a05:6000:200e:b0:430:fcf5:4937 with SMTP id ffacd0b85a97d-4324e4c3e1emr32594538f8f.7.1766947545599; Sun, 28 Dec 2025 10:45:45 -0800 (PST) Received: from phoenix.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4324eaa2bdfsm59150275f8f.32.2025.12.28.10.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Dec 2025 10:45:45 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH 4/7] test: vary size of packets in pcapng test Date: Sun, 28 Dec 2025 10:40:17 -0800 Message-ID: <20251228184300.541639-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251228184300.541639-1-stephen@networkplumber.org> References: <20251228184300.541639-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In order exercise more logic in pcapng, vary the size of the packets. Signed-off-by: Stephen Hemminger --- app/test/test_pcapng.c | 94 +++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 29 deletions(-) diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c index f2b49c31c7..5010355df5 100644 --- a/app/test/test_pcapng.c +++ b/app/test/test_pcapng.c @@ -28,10 +28,9 @@ #define TOTAL_PACKETS 4096 #define MAX_BURST 64 #define MAX_GAP_US 100000 -#define DUMMY_MBUF_NUM 3 +#define DUMMY_MBUF_NUM 2 static struct rte_mempool *mp; -static const uint32_t pkt_len = 200; static uint16_t port_id; static const char null_dev[] = "net_null0"; @@ -41,13 +40,36 @@ struct dummy_mbuf { uint8_t buf[DUMMY_MBUF_NUM][RTE_MBUF_DEFAULT_BUF_SIZE]; }; +#define MAX_DATA_SIZE (RTE_MBUF_DEFAULT_BUF_SIZE - RTE_PKTMBUF_HEADROOM) + +/* RFC 864 chargen pattern used for comment testing */ +#define FILL_LINE_LENGTH 72 +#define FILL_START 0x21 /* ! */ +#define FILL_END 0x7e /* ~ */ +#define FILL_RANGE (FILL_END - FILL_START) + static void -dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len, - uint32_t data_len) +fill_mbuf(struct rte_mbuf *mb) { - uint32_t i; - uint8_t *db; + unsigned int len = rte_pktmbuf_tailroom(mb); + char *buf = rte_pktmbuf_append(mb, len); + unsigned int n = 0; + + while (n < len - 1) { + char ch = FILL_START + (n % FILL_LINE_LENGTH) % FILL_RANGE; + for (unsigned int i = 0; i < FILL_LINE_LENGTH && n < len - 1; i++) { + buf[n++] = ch; + if (++ch == FILL_END) + ch = FILL_START; + } + if (n < len - 1) + buf[n++] = '\n'; + } +} +static void +dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len) +{ mb->buf_addr = buf; rte_mbuf_iova_set(mb, (uintptr_t)buf); mb->buf_len = buf_len; @@ -57,15 +79,11 @@ dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len, mb->pool = (void *)buf; rte_pktmbuf_reset(mb); - db = (uint8_t *)rte_pktmbuf_append(mb, data_len); - - for (i = 0; i != data_len; i++) - db[i] = i; } /* Make an IP packet consisting of chain of one packets */ static void -mbuf1_prepare(struct dummy_mbuf *dm, uint32_t plen) +mbuf1_prepare(struct dummy_mbuf *dm) { struct { struct rte_ether_hdr eth; @@ -84,32 +102,47 @@ mbuf1_prepare(struct dummy_mbuf *dm, uint32_t plen) .dst_addr = rte_cpu_to_be_32(RTE_IPV4_BROADCAST), }, .udp = { + .src_port = rte_cpu_to_be_16(19), /* Chargen port */ .dst_port = rte_cpu_to_be_16(9), /* Discard port */ }, }; memset(dm, 0, sizeof(*dm)); - dummy_mbuf_prep(&dm->mb[0], dm->buf[0], sizeof(dm->buf[0]), plen); + dummy_mbuf_prep(&dm->mb[0], dm->buf[0], sizeof(dm->buf[0])); + dummy_mbuf_prep(&dm->mb[1], dm->buf[1], sizeof(dm->buf[1])); rte_eth_random_addr(pkt.eth.src_addr.addr_bytes); - plen -= sizeof(struct rte_ether_hdr); + memcpy(rte_pktmbuf_append(&dm->mb[0], sizeof(pkt)), &pkt, sizeof(pkt)); + + fill_mbuf(&dm->mb[1]); + rte_pktmbuf_chain(&dm->mb[0], &dm->mb[1]); + + rte_mbuf_sanity_check(&dm->mb[0], 1); + rte_mbuf_sanity_check(&dm->mb[1], 0); +} - pkt.ip.total_length = rte_cpu_to_be_16(plen); - pkt.ip.hdr_checksum = rte_ipv4_cksum(&pkt.ip); +static void +mbuf1_resize(struct dummy_mbuf *dm, uint16_t len) +{ + struct { + struct rte_ether_hdr eth; + struct rte_ipv4_hdr ip; + struct rte_udp_hdr udp; + } *pkt = rte_pktmbuf_mtod(&dm->mb[0], void *); - plen -= sizeof(struct rte_ipv4_hdr); - pkt.udp.src_port = rte_rand(); - pkt.udp.dgram_len = rte_cpu_to_be_16(plen); + dm->mb[1].data_len = len; + dm->mb[0].pkt_len = dm->mb[0].data_len + dm->mb[1].data_len; - memcpy(rte_pktmbuf_mtod(dm->mb, void *), &pkt, sizeof(pkt)); + len += sizeof(struct rte_udp_hdr); + pkt->udp.dgram_len = rte_cpu_to_be_16(len); - /* Idea here is to create mbuf chain big enough that after mbuf deep copy they won't be - * compressed into single mbuf to properly test store of chained mbufs - */ - dummy_mbuf_prep(&dm->mb[1], dm->buf[1], sizeof(dm->buf[1]), pkt_len); - dummy_mbuf_prep(&dm->mb[2], dm->buf[2], sizeof(dm->buf[2]), pkt_len); - rte_pktmbuf_chain(&dm->mb[0], &dm->mb[1]); - rte_pktmbuf_chain(&dm->mb[0], &dm->mb[2]); + len += sizeof(struct rte_ipv4_hdr); + pkt->ip.total_length = rte_cpu_to_be_16(len); + pkt->ip.hdr_checksum = 0; + pkt->ip.hdr_checksum = rte_ipv4_cksum(&pkt->ip); + + rte_mbuf_sanity_check(&dm->mb[0], 1); + rte_mbuf_sanity_check(&dm->mb[1], 0); } static int @@ -125,7 +158,8 @@ test_setup(void) /* Make a pool for cloned packets */ mp = rte_pktmbuf_pool_create_by_ops("pcapng_test_pool", - MAX_BURST * 32, 0, 0, rte_pcapng_mbuf_size(pkt_len), + MAX_BURST * 32, 0, 0, + rte_pcapng_mbuf_size(MAX_DATA_SIZE), SOCKET_ID_ANY, "ring_mp_sc"); if (mp == NULL) { fprintf(stderr, "Cannot create mempool\n"); @@ -156,8 +190,7 @@ fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets) "Lockless and fearless — that’s how we roll in userspace." }; - /* make a dummy packet */ - mbuf1_prepare(&mbfs, pkt_len); + mbuf1_prepare(&mbfs); orig = &mbfs.mb[0]; for (count = 0; count < num_packets; count += burst_size) { @@ -174,6 +207,9 @@ fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets) if ((count + i) % 42 == 0) comment = examples[rte_rand_max(RTE_DIM(examples))]; + /* Vary the size of the packets */ + mbuf1_resize(&mbfs, rte_rand_max(MAX_DATA_SIZE)); + mc = rte_pcapng_copy(port_id, 0, orig, mp, rte_pktmbuf_pkt_len(orig), RTE_PCAPNG_DIRECTION_IN, comment); if (mc == NULL) { -- 2.51.0