pipeline: move port type registration to library
authorCristian Dumitrescu <cristian.dumitrescu@intel.com>
Sat, 27 Nov 2021 00:02:52 +0000 (00:02 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 13 Feb 2022 21:07:55 +0000 (22:07 +0100)
Move the port type registration for the well known port types from the
application to the pipeline library.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Yogesh Jangra <yogesh.jangra@intel.com>
examples/pipeline/obj.c
lib/pipeline/rte_swx_pipeline.c

index 569207a..4b2db66 100644 (file)
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
-#include <rte_swx_port_ethdev.h>
-#include <rte_swx_port_fd.h>
-#include <rte_swx_port_ring.h>
-#include <rte_swx_port_source_sink.h>
 #include <rte_swx_table_em.h>
 #include <rte_swx_table_wm.h>
 #include <rte_swx_pipeline.h>
@@ -543,56 +539,6 @@ pipeline_create(struct obj *obj, const char *name, int numa_node)
        if (status)
                goto error;
 
-       status = rte_swx_pipeline_port_in_type_register(p,
-               "ethdev",
-               &rte_swx_port_ethdev_reader_ops);
-       if (status)
-               goto error;
-
-       status = rte_swx_pipeline_port_out_type_register(p,
-               "ethdev",
-               &rte_swx_port_ethdev_writer_ops);
-       if (status)
-               goto error;
-
-       status = rte_swx_pipeline_port_in_type_register(p,
-               "ring",
-               &rte_swx_port_ring_reader_ops);
-       if (status)
-               goto error;
-
-       status = rte_swx_pipeline_port_out_type_register(p,
-               "ring",
-               &rte_swx_port_ring_writer_ops);
-       if (status)
-               goto error;
-
-#ifdef RTE_PORT_PCAP
-       status = rte_swx_pipeline_port_in_type_register(p,
-               "source",
-               &rte_swx_port_source_ops);
-       if (status)
-               goto error;
-#endif
-
-       status = rte_swx_pipeline_port_out_type_register(p,
-               "sink",
-               &rte_swx_port_sink_ops);
-       if (status)
-               goto error;
-
-       status = rte_swx_pipeline_port_in_type_register(p,
-               "fd",
-               &rte_swx_port_fd_reader_ops);
-       if (status)
-               goto error;
-
-       status = rte_swx_pipeline_port_out_type_register(p,
-               "fd",
-               &rte_swx_port_fd_writer_ops);
-       if (status)
-               goto error;
-
        status = rte_swx_pipeline_table_type_register(p,
                "exact",
                RTE_SWX_TABLE_MATCH_EXACT,
index ff2fe96..bebad98 100644 (file)
@@ -7,6 +7,11 @@
 #include <arpa/inet.h>
 #include <dlfcn.h>
 
+#include <rte_swx_port_ethdev.h>
+#include <rte_swx_port_fd.h>
+#include <rte_swx_port_ring.h>
+#include "rte_swx_port_source_sink.h"
+
 #include "rte_swx_pipeline_internal.h"
 
 #define CHECK(condition, err_code)                                             \
@@ -8982,17 +8987,122 @@ metarray_free(struct rte_swx_pipeline *p)
 /*
  * Pipeline.
  */
+void
+rte_swx_pipeline_free(struct rte_swx_pipeline *p)
+{
+       void *lib;
+
+       if (!p)
+               return;
+
+       lib = p->lib;
+
+       free(p->instruction_data);
+       free(p->instructions);
+
+       metarray_free(p);
+       regarray_free(p);
+       table_state_free(p);
+       learner_free(p);
+       selector_free(p);
+       table_free(p);
+       action_free(p);
+       instruction_table_free(p);
+       metadata_free(p);
+       header_free(p);
+       extern_func_free(p);
+       extern_obj_free(p);
+       port_out_free(p);
+       port_in_free(p);
+       struct_free(p);
+
+       free(p);
+
+       if (lib)
+               dlclose(lib);
+}
+
+static int
+port_in_types_register(struct rte_swx_pipeline *p)
+{
+       int status;
+
+       status = rte_swx_pipeline_port_in_type_register(p,
+               "ethdev",
+               &rte_swx_port_ethdev_reader_ops);
+       if (status)
+               return status;
+
+       status = rte_swx_pipeline_port_in_type_register(p,
+               "ring",
+               &rte_swx_port_ring_reader_ops);
+       if (status)
+               return status;
+
+#ifdef RTE_PORT_PCAP
+       status = rte_swx_pipeline_port_in_type_register(p,
+               "source",
+               &rte_swx_port_source_ops);
+       if (status)
+               return status;
+#endif
+
+       status = rte_swx_pipeline_port_in_type_register(p,
+               "fd",
+               &rte_swx_port_fd_reader_ops);
+       if (status)
+               return status;
+
+       return 0;
+}
+
+static int
+port_out_types_register(struct rte_swx_pipeline *p)
+{
+       int status;
+
+       status = rte_swx_pipeline_port_out_type_register(p,
+               "ethdev",
+               &rte_swx_port_ethdev_writer_ops);
+       if (status)
+               return status;
+
+       status = rte_swx_pipeline_port_out_type_register(p,
+               "ring",
+               &rte_swx_port_ring_writer_ops);
+       if (status)
+               return status;
+
+       status = rte_swx_pipeline_port_out_type_register(p,
+               "sink",
+               &rte_swx_port_sink_ops);
+       if (status)
+               return status;
+
+       status = rte_swx_pipeline_port_out_type_register(p,
+               "fd",
+               &rte_swx_port_fd_writer_ops);
+       if (status)
+               return status;
+
+       return 0;
+}
+
 int
 rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node)
 {
-       struct rte_swx_pipeline *pipeline;
+       struct rte_swx_pipeline *pipeline = NULL;
+       int status = 0;
 
        /* Check input parameters. */
        CHECK(p, EINVAL);
 
        /* Memory allocation. */
        pipeline = calloc(1, sizeof(struct rte_swx_pipeline));
-       CHECK(pipeline, ENOMEM);
+       if (!pipeline) {
+               status = -ENOMEM;
+               goto error;
+       }
 
        /* Initialization. */
        TAILQ_INIT(&pipeline->struct_types);
@@ -9016,43 +9126,20 @@ rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node)
        pipeline->n_structs = 1; /* Struct 0 is reserved for action_data. */
        pipeline->numa_node = numa_node;
 
-       *p = pipeline;
-       return 0;
-}
-
-void
-rte_swx_pipeline_free(struct rte_swx_pipeline *p)
-{
-       void *lib;
-
-       if (!p)
-               return;
-
-       lib = p->lib;
-
-       free(p->instruction_data);
-       free(p->instructions);
+       status = port_in_types_register(pipeline);
+       if (status)
+               goto error;
 
-       metarray_free(p);
-       regarray_free(p);
-       table_state_free(p);
-       learner_free(p);
-       selector_free(p);
-       table_free(p);
-       action_free(p);
-       instruction_table_free(p);
-       metadata_free(p);
-       header_free(p);
-       extern_func_free(p);
-       extern_obj_free(p);
-       port_out_free(p);
-       port_in_free(p);
-       struct_free(p);
+       status = port_out_types_register(pipeline);
+       if (status)
+               goto error;
 
-       free(p);
+       *p = pipeline;
+       return 0;
 
-       if (lib)
-               dlclose(lib);
+error:
+       rte_swx_pipeline_free(pipeline);
+       return status;
 }
 
 int