#include <stdlib.h>
#include <string.h>
+#include <netinet/in.h>
+#ifdef RTE_EXEC_ENV_LINUX
+#include <linux/if.h>
+#include <linux/if_tun.h>
+#endif
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
#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>
#include <rte_swx_ctl.h>
*/
TAILQ_HEAD(link_list, link);
+/*
+ * ring
+ */
+TAILQ_HEAD(ring_list, ring);
+
+/*
+ * tap
+ */
+TAILQ_HEAD(tap_list, tap);
+
/*
* pipeline
*/
struct obj {
struct mempool_list mempool_list;
struct link_list link_list;
+ struct ring_list ring_list;
struct pipeline_list pipeline_list;
+ struct tap_list tap_list;
};
/*
TAILQ_FIRST(&obj->link_list) : TAILQ_NEXT(link, node);
}
+/*
+ * ring
+ */
+struct ring *
+ring_create(struct obj *obj, const char *name, struct ring_params *params)
+{
+ struct ring *ring;
+ struct rte_ring *r;
+ unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
+
+ /* Check input params */
+ if (!name || ring_find(obj, name) || !params || !params->size)
+ return NULL;
+
+ /**
+ * Resource create
+ */
+ r = rte_ring_create(
+ name,
+ params->size,
+ params->numa_node,
+ flags);
+ if (!r)
+ return NULL;
+
+ /* Node allocation */
+ ring = calloc(1, sizeof(struct ring));
+ if (!ring) {
+ rte_ring_free(r);
+ return NULL;
+ }
+
+ /* Node fill in */
+ strlcpy(ring->name, name, sizeof(ring->name));
+
+ /* Node add to list */
+ TAILQ_INSERT_TAIL(&obj->ring_list, ring, node);
+
+ return ring;
+}
+
+struct ring *
+ring_find(struct obj *obj, const char *name)
+{
+ struct ring *ring;
+
+ if (!obj || !name)
+ return NULL;
+
+ TAILQ_FOREACH(ring, &obj->ring_list, node)
+ if (strcmp(ring->name, name) == 0)
+ return ring;
+
+ return NULL;
+}
+
+/*
+ * tap
+ */
+#define TAP_DEV "/dev/net/tun"
+
+struct tap *
+tap_find(struct obj *obj, const char *name)
+{
+ struct tap *tap;
+
+ if (!obj || !name)
+ return NULL;
+
+ TAILQ_FOREACH(tap, &obj->tap_list, node)
+ if (strcmp(tap->name, name) == 0)
+ return tap;
+
+ return NULL;
+}
+
+struct tap *
+tap_next(struct obj *obj, struct tap *tap)
+{
+ return (tap == NULL) ?
+ TAILQ_FIRST(&obj->tap_list) : TAILQ_NEXT(tap, node);
+}
+
+#ifndef RTE_EXEC_ENV_LINUX
+
+struct tap *
+tap_create(struct obj *obj __rte_unused, const char *name __rte_unused)
+{
+ return NULL;
+}
+
+#else
+
+struct tap *
+tap_create(struct obj *obj, const char *name)
+{
+ struct tap *tap;
+ struct ifreq ifr;
+ int fd, status;
+
+ /* Check input params */
+ if ((name == NULL) ||
+ tap_find(obj, name))
+ return NULL;
+
+ /* Resource create */
+ fd = open(TAP_DEV, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ return NULL;
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
+ strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+
+ status = ioctl(fd, TUNSETIFF, (void *) &ifr);
+ if (status < 0) {
+ close(fd);
+ return NULL;
+ }
+
+ /* Node allocation */
+ tap = calloc(1, sizeof(struct tap));
+ if (tap == NULL) {
+ close(fd);
+ return NULL;
+ }
+ /* Node fill in */
+ strlcpy(tap->name, name, sizeof(tap->name));
+ tap->fd = fd;
+
+ /* Node add to list */
+ TAILQ_INSERT_TAIL(&obj->tap_list, tap, node);
+
+ return tap;
+}
+
+#endif
+
/*
* pipeline
*/
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",
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,
if (status)
goto error;
+ status = rte_swx_pipeline_table_type_register(p,
+ "wildcard",
+ RTE_SWX_TABLE_MATCH_WILDCARD,
+ &rte_swx_table_wildcard_match_ops);
+ if (status)
+ goto error;
+
/* Node allocation */
pipeline = calloc(1, sizeof(struct pipeline));
if (pipeline == NULL)
TAILQ_INIT(&obj->mempool_list);
TAILQ_INIT(&obj->link_list);
+ TAILQ_INIT(&obj->ring_list);
TAILQ_INIT(&obj->pipeline_list);
+ TAILQ_INIT(&obj->tap_list);
return obj;
}