#include <stdlib.h>
#include <string.h>
#include "obj.h"
struct obj {
struct mempool_list mempool_list;
struct link_list link_list;
struct pipeline_list pipeline_list;
};
#define BUFFER_SIZE_MIN (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
struct mempool *
mempool_create(struct obj *obj, const char *name, struct mempool_params *params)
{
struct mempool *mempool;
if ((name == NULL) ||
mempool_find(obj, name) ||
(params == NULL) ||
(params->buffer_size < BUFFER_SIZE_MIN) ||
(params->pool_size == 0))
return NULL;
name,
params->pool_size,
params->cache_size,
0,
params->buffer_size -
sizeof(
struct rte_mbuf),
params->cpu_id);
if (m == NULL)
return NULL;
mempool = calloc(1, sizeof(struct mempool));
if (mempool == NULL) {
return NULL;
}
strlcpy(mempool->name, name, sizeof(mempool->name));
mempool->m = m;
mempool->buffer_size = params->buffer_size;
TAILQ_INSERT_TAIL(&obj->mempool_list, mempool, node);
return mempool;
}
struct mempool *
mempool_find(struct obj *obj, const char *name)
{
struct mempool *mempool;
if (!obj || !name)
return NULL;
TAILQ_FOREACH(mempool, &obj->mempool_list, node)
if (strcmp(mempool->name, name) == 0)
return mempool;
return NULL;
}
.rxmode = {
.max_rx_pkt_len = 9000,
.split_hdr_size = 0,
},
.rx_adv_conf = {
.rss_conf = {
.rss_key = NULL,
.rss_key_len = 40,
.rss_hf = 0,
},
},
.txmode = {
},
.lpbk_mode = 0,
};
#define RETA_CONF_SIZE (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
static int
rss_setup(uint16_t port_id,
uint16_t reta_size,
struct link_params_rss *rss)
{
uint32_t i;
int status;
memset(reta_conf, 0, sizeof(reta_conf));
for (i = 0; i < reta_size; i++)
reta_conf[i / RTE_RETA_GROUP_SIZE].
mask = UINT64_MAX;
for (i = 0; i < reta_size; i++) {
uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
uint32_t rss_qs_pos = i % rss->n_queues;
reta_conf[reta_id].reta[reta_pos] =
(uint16_t) rss->queue_id[rss_qs_pos];
}
reta_conf,
reta_size);
return status;
}
struct link *
link_create(struct obj *obj, const char *name, struct link_params *params)
{
struct link *link;
struct link_params_rss *rss;
struct mempool *mempool;
uint32_t cpu_id, i;
int status;
uint16_t port_id;
if ((name == NULL) ||
link_find(obj, name) ||
(params == NULL) ||
(params->rx.n_queues == 0) ||
(params->rx.queue_size == 0) ||
(params->tx.n_queues == 0) ||
(params->tx.queue_size == 0))
return NULL;
port_id = params->port_id;
if (params->dev_name) {
&port_id);
if (status)
return NULL;
} else
return NULL;
return NULL;
mempool = mempool_find(obj, params->rx.mempool_name);
if (mempool == NULL)
return NULL;
rss = params->rx.rss;
if (rss) {
if ((port_info.reta_size == 0) ||
(port_info.reta_size > ETH_RSS_RETA_SIZE_512))
return NULL;
if ((rss->n_queues == 0) ||
(rss->n_queues >= LINK_RXQ_RSS_MAX))
return NULL;
for (i = 0; i < rss->n_queues; i++)
if (rss->queue_id[i] >= port_info.max_rx_queues)
return NULL;
}
memcpy(&port_conf, &port_conf_default, sizeof(port_conf));
if (rss) {
port_conf.rx_adv_conf.rss_conf.rss_hf =
(ETH_RSS_IP | ETH_RSS_TCP | ETH_RSS_UDP) &
port_info.flow_type_rss_offloads;
}
cpu_id = 0;
port_id,
params->rx.n_queues,
params->tx.n_queues,
&port_conf);
if (status < 0)
return NULL;
if (params->promiscuous) {
if (status != 0)
return NULL;
}
for (i = 0; i < params->rx.n_queues; i++) {
port_id,
i,
params->rx.queue_size,
cpu_id,
NULL,
mempool->m);
if (status < 0)
return NULL;
}
for (i = 0; i < params->tx.n_queues; i++) {
port_id,
i,
params->tx.queue_size,
cpu_id,
NULL);
if (status < 0)
return NULL;
}
if (status < 0)
return NULL;
if (rss) {
status = rss_setup(port_id, port_info.reta_size, rss);
if (status) {
return NULL;
}
}
if ((status < 0) && (status != -ENOTSUP)) {
return NULL;
}
link = calloc(1, sizeof(struct link));
if (link == NULL) {
return NULL;
}
strlcpy(link->name, name, sizeof(link->name));
link->port_id = port_id;
link->n_rxq = params->rx.n_queues;
link->n_txq = params->tx.n_queues;
TAILQ_INSERT_TAIL(&obj->link_list, link, node);
return link;
}
int
link_is_up(struct obj *obj, const char *name)
{
struct link *link;
if (!obj || !name)
return 0;
link = link_find(obj, name);
if (link == NULL)
return 0;
return 0;
}
struct link *
link_find(struct obj *obj, const char *name)
{
struct link *link;
if (!obj || !name)
return NULL;
TAILQ_FOREACH(link, &obj->link_list, node)
if (strcmp(link->name, name) == 0)
return link;
return NULL;
}
struct link *
link_next(struct obj *obj, struct link *link)
{
return (link == NULL) ?
TAILQ_FIRST(&obj->link_list) : TAILQ_NEXT(link, node);
}
#ifndef PIPELINE_MSGQ_SIZE
#define PIPELINE_MSGQ_SIZE 64
#endif
struct pipeline *
pipeline_create(struct obj *obj, const char *name, int numa_node)
{
struct pipeline *pipeline;
struct rte_swx_pipeline *p = NULL;
int status;
if ((name == NULL) ||
pipeline_find(obj, name))
return NULL;
if (status)
goto error;
"ethdev",
if (status)
goto error;
"ethdev",
if (status)
goto error;
#ifdef RTE_PORT_PCAP
"source",
if (status)
goto error;
#endif
"sink",
if (status)
goto error;
"exact",
if (status)
goto error;
pipeline = calloc(1, sizeof(struct pipeline));
if (pipeline == NULL)
goto error;
strlcpy(pipeline->name, name, sizeof(pipeline->name));
pipeline->p = p;
pipeline->timer_period_ms = 10;
TAILQ_INSERT_TAIL(&obj->pipeline_list, pipeline, node);
return pipeline;
error:
return NULL;
}
struct pipeline *
pipeline_find(struct obj *obj, const char *name)
{
struct pipeline *pipeline;
if (!obj || !name)
return NULL;
TAILQ_FOREACH(pipeline, &obj->pipeline_list, node)
if (strcmp(name, pipeline->name) == 0)
return pipeline;
return NULL;
}
struct obj *
obj_init(void)
{
struct obj *obj;
obj = calloc(1, sizeof(struct obj));
if (!obj)
return NULL;
TAILQ_INIT(&obj->mempool_list);
TAILQ_INIT(&obj->link_list);
TAILQ_INIT(&obj->pipeline_list);
return obj;
}