get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/98969/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 98969,
    "url": "https://patches.dpdk.org/api/patches/98969/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210916001416.39998-10-stephen@networkplumber.org/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20210916001416.39998-10-stephen@networkplumber.org>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210916001416.39998-10-stephen@networkplumber.org",
    "date": "2021-09-16T00:14:13",
    "name": "[v9,09/12] test: add a test for pcapng library",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "d3cc5deecb5803ba8beae5972ed4783797329db8",
    "submitter": {
        "id": 27,
        "url": "https://patches.dpdk.org/api/people/27/?format=api",
        "name": "Stephen Hemminger",
        "email": "stephen@networkplumber.org"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210916001416.39998-10-stephen@networkplumber.org/mbox/",
    "series": [
        {
            "id": 18954,
            "url": "https://patches.dpdk.org/api/series/18954/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=18954",
            "date": "2021-09-16T00:14:04",
            "name": "Packet capture framework enhancements",
            "version": 9,
            "mbox": "https://patches.dpdk.org/series/18954/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/98969/comments/",
    "check": "warning",
    "checks": "https://patches.dpdk.org/api/patches/98969/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 04194A0C41;\n\tThu, 16 Sep 2021 02:15:11 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 1599341135;\n\tThu, 16 Sep 2021 02:14:38 +0200 (CEST)",
            "from mail-pf1-f177.google.com (mail-pf1-f177.google.com\n [209.85.210.177])\n by mails.dpdk.org (Postfix) with ESMTP id BBAFD410E7\n for <dev@dpdk.org>; Thu, 16 Sep 2021 02:14:30 +0200 (CEST)",
            "by mail-pf1-f177.google.com with SMTP id e16so4270403pfc.6\n for <dev@dpdk.org>; Wed, 15 Sep 2021 17:14:30 -0700 (PDT)",
            "from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123])\n by smtp.gmail.com with ESMTPSA id 26sm1082252pgx.72.2021.09.15.17.14.28\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 15 Sep 2021 17:14:29 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20150623.gappssmtp.com; s=20150623;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=Q2NOBlor7Xu78uPRLGk6Zx4v8PDqdst9LH9aEOBam2o=;\n b=Bagd/St9V/FhqO9pFBh29Mbwenxr806fO2ZkZ1mo3HBPOSvwe2Cf659J5mKg6souTT\n D/RGzXYNdofA+/Dv/khdDCgOwyPm+iQuR4+/qDXjYOB2uU8mAcaeLs9TnSenXMuqJvHj\n ac2bqjtDMNp/+L4o9KS0PpviEtlx4qyHSG5psmkIK9Ipd1ruxEmeKZ9byh0lM1MBBz/T\n o/dHPqOtnXQuDzRMwq6s6YXvPpP6qTwJGDwFBrUw6mkrq5/Xblg0uCFskru4VHsfmmZe\n hh2Z4/UurFSfuqx7C637OIFyXAKoGtAAbHVvIP7OqbfDzxckfw7A/hRjqa6iKQCeOv9g\n bNHg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20210112;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=Q2NOBlor7Xu78uPRLGk6Zx4v8PDqdst9LH9aEOBam2o=;\n b=GmdI/jnZdj67ih3lFKPpAgRHj+SnGLDJQWQHQD8CN0Yk+TUNf0/tfJBPh6Du1oiWt0\n A0CE1deo83yAOMoarKEV2M17g2XFxCzMKocyId1/br25hddqSTjbpy8hsjdhDfub09vn\n ZIQaDxVjg2hSOw9vbL1zacDWDBG2CgzAfjaTWX3ejd2deZeSe0RT/SRKv6BRAosWrcoI\n fu1wT9R4D3jRfhH5C52+DyMqCfLBT53+CVSXbNMyYOiFeuriqViKxxA1nBliFKRCtiYW\n 8q6DkIMEEIUaxku/CiEFQMnDlnWUhFZLnT3fKTXTcE5Wb/pd0t8XaNgnXC/2tsSKrvDr\n AV3g==",
        "X-Gm-Message-State": "AOAM533uP4YG8RTVp9qHKJiq5jpcQqHErJCa9xJw12dMagBu8Gr9gB7B\n snDnw8OYCKoyRFFwRKsduTCJvd81rlOVTA==",
        "X-Google-Smtp-Source": "\n ABdhPJxx04B+ZXopQ23hQNbsfngvzWcB/E8W+FrhtincfbL34VvNW+htXiGDU5b5Ss0qmt5pq6hsaA==",
        "X-Received": "by 2002:a63:5f08:: with SMTP id t8mr2283625pgb.353.1631751269523;\n Wed, 15 Sep 2021 17:14:29 -0700 (PDT)",
        "From": "Stephen Hemminger <stephen@networkplumber.org>",
        "To": "dev@dpdk.org",
        "Cc": "Stephen Hemminger <stephen@networkplumber.org>",
        "Date": "Wed, 15 Sep 2021 17:14:13 -0700",
        "Message-Id": "<20210916001416.39998-10-stephen@networkplumber.org>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20210916001416.39998-1-stephen@networkplumber.org>",
        "References": "<20210903004732.109023-1-stephen@networkplumber.org>\n <20210916001416.39998-1-stephen@networkplumber.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH v9 09/12] test: add a test for pcapng library",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Simple unit test that created pcapng file using API.\n\nTo run this test you need to have at least one device.\nFor example:\n\nDPDK_TEST=pcapng_autotest ./build/app/test/dpdk-test -l 0-15 \\\n    --no-huge -m 2048 --vdev=net_tap,iface=dummy\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\n app/test/meson.build   |   4 +\n app/test/test_pcapng.c | 272 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 276 insertions(+)\n create mode 100644 app/test/test_pcapng.c",
    "diff": "diff --git a/app/test/meson.build b/app/test/meson.build\nindex a7611686adcb..8cf41021deb4 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -395,6 +395,10 @@ if dpdk_conf.has('RTE_NET_RING')\n     fast_tests += [['pdump_autotest', true]]\n endif\n \n+if dpdk_conf.has('RTE_PORT_PCAP')\n+    test_sources += 'test_pcapng.c'\n+endif\n+\n if dpdk_conf.has('RTE_LIB_POWER')\n     test_deps += 'power'\n endif\ndiff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c\nnew file mode 100644\nindex 000000000000..df837ffe0d51\n--- /dev/null\n+++ b/app/test/test_pcapng.c\n@@ -0,0 +1,272 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (c) 2021 Microsoft Corporation\n+ */\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <unistd.h>\n+\n+#include <rte_ethdev.h>\n+#include <rte_ether.h>\n+#include <rte_mbuf.h>\n+#include <rte_mempool.h>\n+#include <rte_net.h>\n+#include <rte_pcapng.h>\n+\n+#include <pcap/pcap.h>\n+\n+#include \"test.h\"\n+\n+#define NUM_PACKETS    10\n+#define DUMMY_MBUF_NUM 3\n+\n+static rte_pcapng_t *pcapng;\n+static struct rte_mempool *mp;\n+static const uint32_t pkt_len = 200;\n+static uint16_t port_id;\n+static char file_name[] = \"/tmp/pcapng_test_XXXXXX.pcapng\";\n+\n+/* first mbuf in the packet, should always be at offset 0 */\n+struct dummy_mbuf {\n+\tstruct rte_mbuf mb[DUMMY_MBUF_NUM];\n+\tuint8_t buf[DUMMY_MBUF_NUM][RTE_MBUF_DEFAULT_BUF_SIZE];\n+};\n+\n+static void\n+dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len,\n+\tuint32_t data_len)\n+{\n+\tuint32_t i;\n+\tuint8_t *db;\n+\n+\tmb->buf_addr = buf;\n+\tmb->buf_iova = (uintptr_t)buf;\n+\tmb->buf_len = buf_len;\n+\trte_mbuf_refcnt_set(mb, 1);\n+\n+\t/* set pool pointer to dummy value, test doesn't use it */\n+\tmb->pool = (void *)buf;\n+\n+\trte_pktmbuf_reset(mb);\n+\tdb = (uint8_t *)rte_pktmbuf_append(mb, data_len);\n+\n+\tfor (i = 0; i != data_len; i++)\n+\t\tdb[i] = i;\n+}\n+\n+/* Make an IP packet consisting of chain of one packets */\n+static void\n+mbuf1_prepare(struct dummy_mbuf *dm, uint32_t plen)\n+{\n+\tstruct {\n+\t\tstruct rte_ether_hdr eth;\n+\t\tstruct rte_ipv4_hdr ip;\n+\t} pkt = {\n+\t\t.eth = {\n+\t\t\t.d_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },\n+\t\t\t.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4),\n+\t\t},\n+\t\t.ip = {\n+\t\t\t.version_ihl = RTE_IPV4_VHL_DEF,\n+\t\t\t.total_length = rte_cpu_to_be_16(plen),\n+\t\t\t.time_to_live = IPDEFTTL,\n+\t\t\t.next_proto_id = IPPROTO_RAW,\n+\t\t\t.src_addr = rte_cpu_to_be_32(RTE_IPV4_LOOPBACK),\n+\t\t\t.dst_addr = rte_cpu_to_be_32(RTE_IPV4_BROADCAST),\n+\t\t}\n+\t};\n+\n+\tmemset(dm, 0, sizeof(*dm));\n+\tdummy_mbuf_prep(&dm->mb[0], dm->buf[0], sizeof(dm->buf[0]), plen);\n+\n+\trte_eth_random_addr(pkt.eth.s_addr.addr_bytes);\n+\tmemcpy(rte_pktmbuf_mtod(dm->mb, void *), &pkt, RTE_MIN(sizeof(pkt), plen));\n+}\n+\n+static int\n+test_setup(void)\n+{\n+\tint tmp_fd;\n+\n+\tport_id = rte_eth_find_next(0);\n+\tif (port_id >= RTE_MAX_ETHPORTS) {\n+\t\tfprintf(stderr, \"No valid Ether port\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\ttmp_fd = mkstemps(file_name, strlen(\".pcapng\"));\n+\tif (tmp_fd == -1) {\n+\t\tperror(\"mkstemps() failure\");\n+\t\treturn -1;\n+\t}\n+\tprintf(\"pcapng: output file %s\\n\", file_name);\n+\n+\t/* open a test capture file */\n+\tpcapng = rte_pcapng_fdopen(tmp_fd, NULL, NULL, \"pcapng_test\", NULL);\n+\tif (pcapng == NULL) {\n+\t\tfprintf(stderr, \"rte_pcapng_fdopen failed\\n\");\n+\t\tclose(tmp_fd);\n+\t\treturn -1;\n+\t}\n+\n+\n+\t/* Make a pool for cloned packeets */\n+\tmp = rte_pktmbuf_pool_create_by_ops(\"pcapng_test_pool\", NUM_PACKETS,\n+\t\t\t\t\t    0, 0,\n+\t\t\t\t\t    rte_pcapng_mbuf_size(pkt_len),\n+\t\t\t\t\t    SOCKET_ID_ANY, \"ring_mp_sc\");\n+\tif (mp == NULL) {\n+\t\tfprintf(stderr, \"Cannot create mempool\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+\n+}\n+\n+static int\n+test_write_packets(void)\n+{\n+\tstruct rte_mbuf *orig;\n+\tstruct rte_mbuf *clones[NUM_PACKETS] = { };\n+\tstruct dummy_mbuf mbfs;\n+\tunsigned int i;\n+\tssize_t len;\n+\n+\t/* make a dummy packet */\n+\tmbuf1_prepare(&mbfs, pkt_len);\n+\n+\t/* clone them */\n+\torig  = &mbfs.mb[0];\n+\tfor (i = 0; i < NUM_PACKETS; i++) {\n+\t\tstruct rte_mbuf *mc;\n+\n+\t\tmc = rte_pcapng_copy(port_id, 0, orig, mp, pkt_len,\n+\t\t\t\trte_get_tsc_cycles(), 0);\n+\t\tif (mc == NULL) {\n+\t\t\tfprintf(stderr, \"Cannot copy packet\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\t\tclones[i] = mc;\n+\t}\n+\n+\t/* write it to capture file */\n+\tlen = rte_pcapng_write_packets(pcapng, clones, NUM_PACKETS);\n+\n+\trte_pktmbuf_free_bulk(clones, NUM_PACKETS);\n+\n+\tif (len <= 0) {\n+\t\tfprintf(stderr, \"Write of packets failed\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_write_stats(void)\n+{\n+\tssize_t len;\n+\n+\t/* write a statistics block */\n+\tlen = rte_pcapng_write_stats(pcapng, port_id,\n+\t\t\t\t     NULL, 0, 0,\n+\t\t\t\t     NUM_PACKETS, 0);\n+\tif (len <= 0) {\n+\t\tfprintf(stderr, \"Write of statistics failed\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n+static void\n+pkt_print(u_char *user, const struct pcap_pkthdr *h,\n+\t  const u_char *bytes)\n+{\n+\tunsigned int *countp = (unsigned int *)user;\n+\tconst struct rte_ether_hdr *eh;\n+\tstruct tm *tm;\n+\tchar tbuf[128], src[64], dst[64];\n+\n+\ttm = localtime(&h->ts.tv_sec);\n+\tif (tm == NULL) {\n+\t\tperror(\"localtime\");\n+\t\treturn;\n+\t}\n+\n+\tif (strftime(tbuf, sizeof(tbuf), \"%X\", tm) == 0) {\n+\t\tfprintf(stderr, \"strftime returned 0!\\n\");\n+\t\treturn;\n+\t}\n+\n+\teh = (const struct rte_ether_hdr *)bytes;\n+\trte_ether_format_addr(dst, sizeof(dst), &eh->d_addr);\n+\trte_ether_format_addr(src, sizeof(src), &eh->s_addr);\n+\tprintf(\"%s.%06lu: %s -> %s type %x length %u\\n\",\n+\t       tbuf, (unsigned long)h->ts.tv_usec,\n+\t       src, dst, rte_be_to_cpu_16(eh->ether_type), h->len);\n+\n+\t*countp += 1;\n+}\n+\n+/*\n+ * Open the resulting pcapng file with libpcap\n+ * Would be better to use capinfos from wireshark\n+ * but that creates an unwanted dependency.\n+ */\n+static int\n+test_validate(void)\n+{\n+\tchar errbuf[PCAP_ERRBUF_SIZE];\n+\tunsigned int count = 0;\n+\tpcap_t *pcap;\n+\tint ret;\n+\n+\tpcap = pcap_open_offline(file_name, errbuf);\n+\tif (pcap == NULL) {\n+\t\tfprintf(stderr, \"pcap_open_offline('%s') failed: %s\\n\",\n+\t\t\tfile_name, errbuf);\n+\t\treturn -1;\n+\t}\n+\n+\tret = pcap_loop(pcap, 0, pkt_print, (u_char *)&count);\n+\tif (ret == 0)\n+\t\tprintf(\"Saw %u packets\\n\", count);\n+\telse\n+\t\tfprintf(stderr, \"pcap_dispatch: failed: %s\\n\",\n+\t\t\tpcap_geterr(pcap));\n+\tpcap_close(pcap);\n+\n+\treturn ret;\n+}\n+\n+static void\n+test_cleanup(void)\n+{\n+\tif (mp)\n+\t\trte_mempool_free(mp);\n+\n+\tif (pcapng)\n+\t\trte_pcapng_close(pcapng);\n+\n+}\n+\n+static struct\n+unit_test_suite test_pcapng_suite  = {\n+\t.setup = test_setup,\n+\t.teardown = test_cleanup,\n+\t.suite_name = \"Test Pcapng Unit Test Suite\",\n+\t.unit_test_cases = {\n+\t\tTEST_CASE(test_write_packets),\n+\t\tTEST_CASE(test_write_stats),\n+\t\tTEST_CASE(test_validate),\n+\t\tTEST_CASES_END()\n+\t}\n+};\n+\n+static int\n+test_pcapng(void)\n+{\n+\treturn unit_test_suite_runner(&test_pcapng_suite);\n+}\n+\n+REGISTER_TEST_COMMAND(pcapng_autotest, test_pcapng);\n",
    "prefixes": [
        "v9",
        "09/12"
    ]
}