examples/ip_pipeline: add TAP port

The TAP port support is added to ip_pipeline app. To parse
configuration file with TAP port entries, parsing function is implemented.
The TAP ports configuration check and initialization routines have been
included in application code.

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
This commit is contained in:
Jasvinder Singh 2016-10-13 10:17:48 +01:00 committed by Thomas Monjalon
parent 5a99f20868
commit 3f2c9f3bb6
6 changed files with 382 additions and 0 deletions

View File

@ -177,6 +177,16 @@ struct app_pktq_tm_params {
uint32_t burst_write;
};
struct app_pktq_tap_params {
char *name;
uint32_t parsed;
uint32_t burst_read;
uint32_t burst_write;
uint32_t dropless;
uint64_t n_retries;
uint32_t mempool_id; /* Position in the app->mempool_params */
};
struct app_pktq_source_params {
char *name;
uint32_t parsed;
@ -204,6 +214,7 @@ enum app_pktq_in_type {
APP_PKTQ_IN_HWQ,
APP_PKTQ_IN_SWQ,
APP_PKTQ_IN_TM,
APP_PKTQ_IN_TAP,
APP_PKTQ_IN_KNI,
APP_PKTQ_IN_SOURCE,
};
@ -217,6 +228,7 @@ enum app_pktq_out_type {
APP_PKTQ_OUT_HWQ,
APP_PKTQ_OUT_SWQ,
APP_PKTQ_OUT_TM,
APP_PKTQ_OUT_TAP,
APP_PKTQ_OUT_KNI,
APP_PKTQ_OUT_SINK,
};
@ -441,6 +453,10 @@ struct app_eal_params {
#define APP_MAX_PKTQ_TM APP_MAX_LINKS
#ifndef APP_MAX_PKTQ_TAP
#define APP_MAX_PKTQ_TAP APP_MAX_LINKS
#endif
#define APP_MAX_PKTQ_KNI APP_MAX_LINKS
#ifndef APP_MAX_PKTQ_SOURCE
@ -494,6 +510,7 @@ struct app_params {
struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
struct app_pktq_tap_params tap_params[APP_MAX_PKTQ_TAP];
struct app_pktq_kni_params kni_params[APP_MAX_PKTQ_KNI];
struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
@ -506,6 +523,7 @@ struct app_params {
uint32_t n_pktq_hwq_out;
uint32_t n_pktq_swq;
uint32_t n_pktq_tm;
uint32_t n_pktq_tap;
uint32_t n_pktq_kni;
uint32_t n_pktq_source;
uint32_t n_pktq_sink;
@ -520,6 +538,7 @@ struct app_params {
struct app_link_data link_data[APP_MAX_LINKS];
struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
int tap[APP_MAX_PKTQ_TAP];
#ifdef RTE_LIBRTE_KNI
struct rte_kni *kni[APP_MAX_PKTQ_KNI];
#endif /* RTE_LIBRTE_KNI */
@ -785,6 +804,66 @@ app_tm_get_reader(struct app_params *app,
return reader;
}
static inline uint32_t
app_tap_get_readers(struct app_params *app, struct app_pktq_tap_params *tap)
{
uint32_t pos = tap - app->tap_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
uint32_t n_readers = 0, i;
for (i = 0; i < n_pipelines; i++) {
struct app_pipeline_params *p = &app->pipeline_params[i];
uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
uint32_t j;
for (j = 0; j < n_pktq_in; j++) {
struct app_pktq_in_params *pktq = &p->pktq_in[j];
if ((pktq->type == APP_PKTQ_IN_TAP) &&
(pktq->id == pos))
n_readers++;
}
}
return n_readers;
}
static inline struct app_pipeline_params *
app_tap_get_reader(struct app_params *app,
struct app_pktq_tap_params *tap,
uint32_t *pktq_in_id)
{
struct app_pipeline_params *reader = NULL;
uint32_t pos = tap - app->tap_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
uint32_t n_readers = 0, id = 0, i;
for (i = 0; i < n_pipelines; i++) {
struct app_pipeline_params *p = &app->pipeline_params[i];
uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
uint32_t j;
for (j = 0; j < n_pktq_in; j++) {
struct app_pktq_in_params *pktq = &p->pktq_in[j];
if ((pktq->type == APP_PKTQ_IN_TAP) &&
(pktq->id == pos)) {
n_readers++;
reader = p;
id = j;
}
}
}
if (n_readers != 1)
return NULL;
*pktq_in_id = id;
return reader;
}
static inline uint32_t
app_kni_get_readers(struct app_params *app, struct app_pktq_kni_params *kni)
{
@ -1042,6 +1121,67 @@ app_tm_get_writer(struct app_params *app,
return writer;
}
static inline uint32_t
app_tap_get_writers(struct app_params *app, struct app_pktq_tap_params *tap)
{
uint32_t pos = tap - app->tap_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
uint32_t n_writers = 0, i;
for (i = 0; i < n_pipelines; i++) {
struct app_pipeline_params *p = &app->pipeline_params[i];
uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
RTE_DIM(p->pktq_out));
uint32_t j;
for (j = 0; j < n_pktq_out; j++) {
struct app_pktq_out_params *pktq = &p->pktq_out[j];
if ((pktq->type == APP_PKTQ_OUT_TAP) &&
(pktq->id == pos))
n_writers++;
}
}
return n_writers;
}
static inline struct app_pipeline_params *
app_tap_get_writer(struct app_params *app,
struct app_pktq_tap_params *tap,
uint32_t *pktq_out_id)
{
struct app_pipeline_params *writer;
uint32_t pos = tap - app->tap_params;
uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
RTE_DIM(app->pipeline_params));
uint32_t n_writers = 0, id = 0, i;
for (i = 0; i < n_pipelines; i++) {
struct app_pipeline_params *p = &app->pipeline_params[i];
uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
RTE_DIM(p->pktq_out));
uint32_t j;
for (j = 0; j < n_pktq_out; j++) {
struct app_pktq_out_params *pktq = &p->pktq_out[j];
if ((pktq->type == APP_PKTQ_OUT_TAP) &&
(pktq->id == pos))
n_writers++;
writer = p;
id = j;
}
}
if (n_writers != 1)
return NULL;
*pktq_out_id = id;
return writer;
}
static inline uint32_t
app_kni_get_writers(struct app_params *app, struct app_pktq_kni_params *kni)
{

View File

@ -315,6 +315,36 @@ check_tms(struct app_params *app)
}
}
static void
check_taps(struct app_params *app)
{
uint32_t i;
for (i = 0; i < app->n_pktq_tap; i++) {
struct app_pktq_tap_params *p = &app->tap_params[i];
uint32_t n_readers = app_tap_get_readers(app, p);
uint32_t n_writers = app_tap_get_writers(app, p);
APP_CHECK((n_readers != 0),
"%s has no reader\n", p->name);
APP_CHECK((n_readers == 1),
"%s has more than one reader\n", p->name);
APP_CHECK((n_writers != 0),
"%s has no writer\n", p->name);
APP_CHECK((n_writers == 1),
"%s has more than one writer\n", p->name);
APP_CHECK((p->burst_read > 0),
"%s read burst size is 0\n", p->name);
APP_CHECK((p->burst_write > 0),
"%s write burst size is 0\n", p->name);
}
}
static void
check_knis(struct app_params *app) {
uint32_t i;
@ -476,6 +506,7 @@ app_config_check(struct app_params *app)
check_txqs(app);
check_swqs(app);
check_tms(app);
check_taps(app);
check_knis(app);
check_sources(app);
check_sinks(app);

View File

@ -189,6 +189,15 @@ struct app_pktq_tm_params default_tm_params = {
.burst_write = 32,
};
struct app_pktq_tap_params default_tap_params = {
.parsed = 0,
.burst_read = 32,
.burst_write = 32,
.dropless = 0,
.n_retries = 0,
.mempool_id = 0,
};
struct app_pktq_kni_params default_kni_params = {
.parsed = 0,
.socket_id = 0,
@ -852,6 +861,9 @@ parse_pipeline_pktq_in(struct app_params *app,
type = APP_PKTQ_IN_TM;
id = APP_PARAM_ADD(app->tm_params, name);
APP_PARAM_ADD_LINK_FOR_TM(app, name);
} else if (validate_name(name, "TAP", 1) == 0) {
type = APP_PKTQ_IN_TAP;
id = APP_PARAM_ADD(app->tap_params, name);
} else if (validate_name(name, "KNI", 1) == 0) {
type = APP_PKTQ_IN_KNI;
id = APP_PARAM_ADD(app->kni_params, name);
@ -901,6 +913,9 @@ parse_pipeline_pktq_out(struct app_params *app,
type = APP_PKTQ_OUT_TM;
id = APP_PARAM_ADD(app->tm_params, name);
APP_PARAM_ADD_LINK_FOR_TM(app, name);
} else if (validate_name(name, "TAP", 1) == 0) {
type = APP_PKTQ_OUT_TAP;
id = APP_PARAM_ADD(app->tap_params, name);
} else if (validate_name(name, "KNI", 1) == 0) {
type = APP_PKTQ_OUT_KNI;
id = APP_PARAM_ADD(app->kni_params, name);
@ -1895,6 +1910,88 @@ parse_tm(struct app_params *app,
free(entries);
}
static void
parse_tap(struct app_params *app,
const char *section_name,
struct rte_cfgfile *cfg)
{
struct app_pktq_tap_params *param;
struct rte_cfgfile_entry *entries;
int n_entries, i;
ssize_t param_idx;
n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
PARSE_ERROR_MALLOC(entries != NULL);
rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
param_idx = APP_PARAM_ADD(app->tap_params, section_name);
param = &app->tap_params[param_idx];
PARSE_CHECK_DUPLICATE_SECTION(param);
for (i = 0; i < n_entries; i++) {
struct rte_cfgfile_entry *ent = &entries[i];
if (strcmp(ent->name, "burst_read") == 0) {
int status = parser_read_uint32(
&param->burst_read, ent->value);
PARSE_ERROR((status == 0), section_name,
ent->name);
continue;
}
if (strcmp(ent->name, "burst_write") == 0) {
int status = parser_read_uint32(
&param->burst_write, ent->value);
PARSE_ERROR((status == 0), section_name,
ent->name);
continue;
}
if (strcmp(ent->name, "dropless") == 0) {
int status = parser_read_arg_bool(ent->value);
PARSE_ERROR((status != -EINVAL), section_name,
ent->name);
param->dropless = status;
continue;
}
if (strcmp(ent->name, "n_retries") == 0) {
int status = parser_read_uint64(&param->n_retries,
ent->value);
PARSE_ERROR((status == 0), section_name,
ent->name);
continue;
}
if (strcmp(ent->name, "mempool") == 0) {
int status = validate_name(ent->value,
"MEMPOOL", 1);
ssize_t idx;
PARSE_ERROR((status == 0), section_name,
ent->name);
idx = APP_PARAM_ADD(app->mempool_params, ent->value);
param->mempool_id = idx;
continue;
}
/* unrecognized */
PARSE_ERROR_INVALID(0, section_name, ent->name);
}
free(entries);
}
static void
parse_kni(struct app_params *app,
const char *section_name,
@ -2286,6 +2383,7 @@ static const struct config_section cfg_file_scheme[] = {
{"TXQ", 2, parse_txq},
{"SWQ", 1, parse_swq},
{"TM", 1, parse_tm},
{"TAP", 1, parse_tap},
{"KNI", 1, parse_kni},
{"SOURCE", 1, parse_source},
{"SINK", 1, parse_sink},
@ -2425,6 +2523,7 @@ app_config_parse(struct app_params *app, const char *file_name)
APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
APP_PARAM_COUNT(app->tap_params, app->n_pktq_tap);
APP_PARAM_COUNT(app->kni_params, app->n_pktq_kni);
APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
@ -2788,6 +2887,30 @@ save_tm_params(struct app_params *app, FILE *f)
}
}
static void
save_tap_params(struct app_params *app, FILE *f)
{
struct app_pktq_tap_params *p;
size_t i, count;
count = RTE_DIM(app->tap_params);
for (i = 0; i < count; i++) {
p = &app->tap_params[i];
if (!APP_PARAM_VALID(p))
continue;
fprintf(f, "[%s]\n", p->name);
fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
fprintf(f, "%s = %s\n", "mempool",
app->mempool_params[p->mempool_id].name);
fputc('\n', f);
}
}
static void
save_kni_params(struct app_params *app, FILE *f)
{
@ -2942,6 +3065,9 @@ save_pipeline_params(struct app_params *app, FILE *f)
case APP_PKTQ_IN_TM:
name = app->tm_params[pp->id].name;
break;
case APP_PKTQ_IN_TAP:
name = app->tap_params[pp->id].name;
break;
case APP_PKTQ_IN_KNI:
name = app->kni_params[pp->id].name;
break;
@ -2979,6 +3105,9 @@ save_pipeline_params(struct app_params *app, FILE *f)
case APP_PKTQ_OUT_TM:
name = app->tm_params[pp->id].name;
break;
case APP_PKTQ_OUT_TAP:
name = app->tap_params[pp->id].name;
break;
case APP_PKTQ_OUT_KNI:
name = app->kni_params[pp->id].name;
break;
@ -3067,6 +3196,7 @@ app_config_save(struct app_params *app, const char *file_name)
save_txq_params(app, file);
save_swq_params(app, file);
save_tm_params(app, file);
save_tap_params(app, file);
save_kni_params(app, file);
save_source_params(app, file);
save_sink_params(app, file);
@ -3113,6 +3243,11 @@ app_config_init(struct app_params *app)
&default_tm_params,
sizeof(default_tm_params));
for (i = 0; i < RTE_DIM(app->tap_params); i++)
memcpy(&app->tap_params[i],
&default_tap_params,
sizeof(default_tap_params));
for (i = 0; i < RTE_DIM(app->kni_params); i++)
memcpy(&app->kni_params[i],
&default_kni_params,

View File

@ -34,6 +34,12 @@
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <rte_cycles.h>
#include <rte_ethdev.h>
@ -1154,6 +1160,34 @@ app_init_tm(struct app_params *app)
}
}
static void
app_init_tap(struct app_params *app)
{
uint32_t i;
for (i = 0; i < app->n_pktq_tap; i++) {
struct app_pktq_tap_params *p_tap = &app->tap_params[i];
struct ifreq ifr;
int fd, status;
APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (fd < 0)
rte_panic("Cannot open file /dev/net/tun\n");
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
status = ioctl(fd, TUNSETIFF, (void *) &ifr);
if (status < 0)
rte_panic("TAP setup error\n");
app->tap[i] = fd;
}
}
#ifdef RTE_LIBRTE_KNI
static int
kni_config_network_interface(uint8_t port_id, uint8_t if_up) {
@ -1370,6 +1404,22 @@ void app_pipeline_params_get(struct app_params *app,
out->burst_size = app->tm_params[in->id].burst_read;
break;
}
case APP_PKTQ_IN_TAP:
{
struct app_pktq_tap_params *tap_params =
&app->tap_params[in->id];
struct app_mempool_params *mempool_params =
&app->mempool_params[tap_params->mempool_id];
struct rte_mempool *mempool =
app->mempool[tap_params->mempool_id];
out->type = PIPELINE_PORT_IN_FD_READER;
out->params.fd.fd = app->tap[in->id];
out->params.fd.mtu = mempool_params->buffer_size;
out->params.fd.mempool = mempool;
out->burst_size = app->tap_params[in->id].burst_read;
break;
}
#ifdef RTE_LIBRTE_KNI
case APP_PKTQ_IN_KNI:
{
@ -1514,6 +1564,17 @@ void app_pipeline_params_get(struct app_params *app,
app->tm_params[in->id].burst_write;
break;
}
case APP_PKTQ_OUT_TAP:
{
struct rte_port_fd_writer_params *params =
&out->params.fd;
out->type = PIPELINE_PORT_OUT_FD_WRITER;
params->fd = app->tap[in->id];
params->tx_burst_sz =
app->tap_params[in->id].burst_write;
break;
}
#ifdef RTE_LIBRTE_KNI
case APP_PKTQ_OUT_KNI:
{
@ -1730,6 +1791,7 @@ int app_init(struct app_params *app)
app_init_link(app);
app_init_swq(app);
app_init_tm(app);
app_init_tap(app);
app_init_kni(app);
app_init_msgq(app);

View File

@ -156,6 +156,7 @@ app_pipeline_track_pktq_out_to_link(struct app_params *app,
break;
}
case APP_PKTQ_OUT_TAP:
case APP_PKTQ_OUT_SINK:
default:
return NULL;

View File

@ -39,6 +39,7 @@
#include <rte_port_frag.h>
#include <rte_port_ras.h>
#include <rte_port_sched.h>
#include <rte_port_fd.h>
#include <rte_port_source_sink.h>
#ifdef RTE_LIBRTE_KNI
#include <rte_port_kni.h>
@ -52,6 +53,7 @@ enum pipeline_port_in_type {
PIPELINE_PORT_IN_RING_READER_IPV4_FRAG,
PIPELINE_PORT_IN_RING_READER_IPV6_FRAG,
PIPELINE_PORT_IN_SCHED_READER,
PIPELINE_PORT_IN_FD_READER,
PIPELINE_PORT_IN_KNI_READER,
PIPELINE_PORT_IN_SOURCE,
};
@ -65,6 +67,7 @@ struct pipeline_port_in_params {
struct rte_port_ring_reader_ipv4_frag_params ring_ipv4_frag;
struct rte_port_ring_reader_ipv6_frag_params ring_ipv6_frag;
struct rte_port_sched_reader_params sched;
struct rte_port_fd_reader_params fd;
#ifdef RTE_LIBRTE_KNI
struct rte_port_kni_reader_params kni;
#endif
@ -89,6 +92,8 @@ pipeline_port_in_params_convert(struct pipeline_port_in_params *p)
return (void *) &p->params.ring_ipv6_frag;
case PIPELINE_PORT_IN_SCHED_READER:
return (void *) &p->params.sched;
case PIPELINE_PORT_IN_FD_READER:
return (void *) &p->params.fd;
#ifdef RTE_LIBRTE_KNI
case PIPELINE_PORT_IN_KNI_READER:
return (void *) &p->params.kni;
@ -116,6 +121,8 @@ pipeline_port_in_params_get_ops(struct pipeline_port_in_params *p)
return &rte_port_ring_reader_ipv6_frag_ops;
case PIPELINE_PORT_IN_SCHED_READER:
return &rte_port_sched_reader_ops;
case PIPELINE_PORT_IN_FD_READER:
return &rte_port_fd_reader_ops;
#ifdef RTE_LIBRTE_KNI
case PIPELINE_PORT_IN_KNI_READER:
return &rte_port_kni_reader_ops;
@ -137,6 +144,7 @@ enum pipeline_port_out_type {
PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS,
PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS,
PIPELINE_PORT_OUT_SCHED_WRITER,
PIPELINE_PORT_OUT_FD_WRITER,
PIPELINE_PORT_OUT_KNI_WRITER,
PIPELINE_PORT_OUT_KNI_WRITER_NODROP,
PIPELINE_PORT_OUT_SINK,
@ -154,6 +162,7 @@ struct pipeline_port_out_params {
struct rte_port_ring_writer_ipv4_ras_params ring_ipv4_ras;
struct rte_port_ring_writer_ipv6_ras_params ring_ipv6_ras;
struct rte_port_sched_writer_params sched;
struct rte_port_fd_writer_params fd;
#ifdef RTE_LIBRTE_KNI
struct rte_port_kni_writer_params kni;
struct rte_port_kni_writer_nodrop_params kni_nodrop;
@ -184,6 +193,8 @@ pipeline_port_out_params_convert(struct pipeline_port_out_params *p)
return (void *) &p->params.ring_ipv6_ras;
case PIPELINE_PORT_OUT_SCHED_WRITER:
return (void *) &p->params.sched;
case PIPELINE_PORT_OUT_FD_WRITER:
return (void *) &p->params.fd;
#ifdef RTE_LIBRTE_KNI
case PIPELINE_PORT_OUT_KNI_WRITER:
return (void *) &p->params.kni;
@ -219,6 +230,8 @@ pipeline_port_out_params_get_ops(struct pipeline_port_out_params *p)
return &rte_port_ring_writer_ipv6_ras_ops;
case PIPELINE_PORT_OUT_SCHED_WRITER:
return &rte_port_sched_writer_ops;
case PIPELINE_PORT_OUT_FD_WRITER:
return &rte_port_fd_writer_ops;
#ifdef RTE_LIBRTE_KNI
case PIPELINE_PORT_OUT_KNI_WRITER:
return &rte_port_kni_writer_ops;