[03/12] gen: add files for initial traffic generation library

Message ID 20211214141242.3383831-4-ronan.randles@intel.com (mailing list archive)
State Not Applicable, archived
Delegated to: Thomas Monjalon
Headers
Series add packet generator library and example app |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ronan Randles Dec. 14, 2021, 2:12 p.m. UTC
  From: Harry van Haaren <harry.van.haaren@intel.com>

This commit adds empty files to the DPDK build for a traffic
generation library, including the bare create and destroy functions.
Unit testing infrastructure is added for the create function.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 app/test/meson.build      |  2 ++
 app/test/test_gen.c       | 55 +++++++++++++++++++++++++++++++++++++++
 doc/api/doxy-api-index.md |  3 ++-
 doc/api/doxy-api.conf.in  |  1 +
 lib/gen/meson.build       |  5 ++++
 lib/gen/rte_gen.c         | 33 +++++++++++++++++++++++
 lib/gen/rte_gen.h         | 44 +++++++++++++++++++++++++++++++
 lib/gen/version.map       |  6 +++++
 lib/meson.build           |  1 +
 9 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_gen.c
 create mode 100644 lib/gen/meson.build
 create mode 100644 lib/gen/rte_gen.c
 create mode 100644 lib/gen/rte_gen.h
 create mode 100644 lib/gen/version.map
  

Patch

diff --git a/app/test/meson.build b/app/test/meson.build
index 4cf540fc74..0e4f3b810d 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -66,6 +66,7 @@  test_sources = files(
         'test_fib6_perf.c',
         'test_func_reentrancy.c',
         'test_flow_classify.c',
+        'test_gen.c',
         'test_graph.c',
         'test_graph_perf.c',
         'test_hash.c',
@@ -173,6 +174,7 @@  test_deps = [
         'eventdev',
         'fib',
         'flow_classify',
+        'gen',
         'graph',
         'hash',
         'ipsec',
diff --git a/app/test/test_gen.c b/app/test/test_gen.c
new file mode 100644
index 0000000000..f53f4a6608
--- /dev/null
+++ b/app/test/test_gen.c
@@ -0,0 +1,55 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2021 Intel Corporation
+ */
+
+#include <rte_common.h>
+#include <rte_gen.h>
+#include <rte_mbuf.h>
+
+#include "test.h"
+
+static struct rte_mempool *mp;
+
+static int
+testsuite_setup(void)
+{
+	if (!mp) {
+		mp = rte_pktmbuf_pool_create("test_gen_mp", 8192, 256, 0, 2048,
+						SOCKET_ID_ANY);
+	}
+	return mp ? TEST_SUCCESS : TEST_FAILED;
+}
+
+static void
+testsuite_teardown(void)
+{
+	rte_mempool_free(mp);
+}
+
+static int
+test_gen_create(void)
+{
+	struct rte_gen *gen = rte_gen_create(mp);
+	TEST_ASSERT_FAIL(gen, "Expected valid pointer after create()");
+
+	rte_gen_destroy(gen);
+	return 0;
+}
+
+static struct unit_test_suite gen_suite  = {
+	.suite_name = "gen: packet generator unit test suite",
+	.setup = testsuite_setup,
+	.teardown = testsuite_teardown,
+	.unit_test_cases = {
+		TEST_CASE_ST(NULL, NULL, test_gen_create),
+		TEST_CASES_END() /**< NULL terminate unit test array */
+	}
+};
+
+static int
+test_gen_suite(void)
+{
+	return unit_test_suite_runner(&gen_suite);
+}
+
+REGISTER_TEST_COMMAND(gen_autotest, test_gen_suite);
diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md
index 4245b9635c..f7ddadd21a 100644
--- a/doc/api/doxy-api-index.md
+++ b/doc/api/doxy-api-index.md
@@ -220,7 +220,8 @@  The public API headers are grouped by topics:
   [log]                (@ref rte_log.h),
   [errno]              (@ref rte_errno.h),
   [trace]              (@ref rte_trace.h),
-  [trace_point]        (@ref rte_trace_point.h)
+  [trace_point]        (@ref rte_trace_point.h),
+  [gen]                (@ref rte_gen.h)
 
 - **misc**:
   [EAL config]         (@ref rte_eal.h),
diff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in
index db2ca9b6ed..6344e949d9 100644
--- a/doc/api/doxy-api.conf.in
+++ b/doc/api/doxy-api.conf.in
@@ -41,6 +41,7 @@  INPUT                   = @TOPDIR@/doc/api/doxy-api-index.md \
                           @TOPDIR@/lib/eventdev \
                           @TOPDIR@/lib/fib \
                           @TOPDIR@/lib/flow_classify \
+                          @TOPDIR@/lib/gen \
                           @TOPDIR@/lib/gpudev \
                           @TOPDIR@/lib/graph \
                           @TOPDIR@/lib/gro \
diff --git a/lib/gen/meson.build b/lib/gen/meson.build
new file mode 100644
index 0000000000..3c5d854645
--- /dev/null
+++ b/lib/gen/meson.build
@@ -0,0 +1,5 @@ 
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+sources = files('rte_gen.c')
+headers = files('rte_gen.h')
diff --git a/lib/gen/rte_gen.c b/lib/gen/rte_gen.c
new file mode 100644
index 0000000000..d993772422
--- /dev/null
+++ b/lib/gen/rte_gen.c
@@ -0,0 +1,33 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2021 Intel Corporation
+ */
+
+#include "rte_gen.h"
+
+#include <rte_malloc.h>
+
+/** Structure that represents a traffic generator. */
+struct rte_gen {
+	/* Mempool that buffers are retrieved from. */
+	struct rte_mempool *mp;
+};
+
+/* Allocate and initialize a traffic generator instance. */
+struct rte_gen *
+rte_gen_create(struct rte_mempool *mempool)
+{
+	struct rte_gen *gen = rte_zmalloc(NULL, sizeof(*gen), 0);
+	if (gen == NULL)
+		return NULL;
+
+	gen->mp = mempool;
+
+	return gen;
+}
+
+/* Free a traffic generator instance. */
+void
+rte_gen_destroy(struct rte_gen *gen)
+{
+	rte_free(gen);
+}
diff --git a/lib/gen/rte_gen.h b/lib/gen/rte_gen.h
new file mode 100644
index 0000000000..5b30430f9e
--- /dev/null
+++ b/lib/gen/rte_gen.h
@@ -0,0 +1,44 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2021 Intel Corporation
+ */
+
+#ifndef _RTE_GEN_H_
+#define _RTE_GEN_H_
+
+/**
+ * @file
+ * RTE gen
+ *
+ * A library for the generation of packets, to allow easy generation
+ * of various flows of packets.
+ */
+
+#include <stdint.h>
+#include <rte_compat.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/** Structure that represents a logical traffic generator. */
+struct rte_gen;
+
+/* Forward declarations for DPDK componeents. */
+struct rte_mempool;
+
+/* Allocate and initialize a traffic generator instance. */
+__rte_experimental
+struct rte_gen *
+rte_gen_create(struct rte_mempool *mempool);
+
+/* Free a traffic generator instance. */
+__rte_experimental
+void
+rte_gen_destroy(struct rte_gen *gen);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_GEN_H_ */
diff --git a/lib/gen/version.map b/lib/gen/version.map
new file mode 100644
index 0000000000..d8a26eb53a
--- /dev/null
+++ b/lib/gen/version.map
@@ -0,0 +1,6 @@ 
+EXPERIMENTAL {
+	global:
+
+	rte_gen_create;
+	rte_gen_destroy;
+};
diff --git a/lib/meson.build b/lib/meson.build
index 018976df17..5b28cd3a89 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -35,6 +35,7 @@  libraries = [
         'efd',
         'eventdev',
         'gpudev',
+        'gen',
         'gro',
         'gso',
         'ip_frag',