X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fpipeline%2Fobj.c;h=569207a79d62e69e390022dca5cb70a881c1463d;hb=c7ebd65c137215d714b445b7b4c584007cc89ffb;hp=154d832eda856bb4ff35fd9ef682ecceafa78830;hpb=77a413017c2d22a2be0337c14be523e4675dabdd;p=dpdk.git diff --git a/examples/pipeline/obj.c b/examples/pipeline/obj.c index 154d832eda..569207a79d 100644 --- a/examples/pipeline/obj.c +++ b/examples/pipeline/obj.c @@ -4,14 +4,24 @@ #include #include +#include +#ifdef RTE_EXEC_ENV_LINUX +#include +#include +#endif +#include +#include +#include #include #include #include #include +#include #include #include #include +#include #include #include @@ -32,6 +42,11 @@ TAILQ_HEAD(link_list, link); */ TAILQ_HEAD(ring_list, ring); +/* + * tap + */ +TAILQ_HEAD(tap_list, tap); + /* * pipeline */ @@ -45,6 +60,7 @@ struct obj { struct link_list link_list; struct ring_list ring_list; struct pipeline_list pipeline_list; + struct tap_list tap_list; }; /* @@ -117,8 +133,8 @@ mempool_find(struct obj *obj, const char *name) static struct rte_eth_conf port_conf_default = { .link_speeds = 0, .rxmode = { - .mq_mode = ETH_MQ_RX_NONE, - .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */ + .mq_mode = RTE_ETH_MQ_RX_NONE, + .mtu = 9000 - (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN), /* Jumbo frame MTU */ .split_hdr_size = 0, /* Header split buffer size */ }, .rx_adv_conf = { @@ -129,12 +145,12 @@ static struct rte_eth_conf port_conf_default = { }, }, .txmode = { - .mq_mode = ETH_MQ_TX_NONE, + .mq_mode = RTE_ETH_MQ_TX_NONE, }, .lpbk_mode = 0, }; -#define RETA_CONF_SIZE (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE) +#define RETA_CONF_SIZE (RTE_ETH_RSS_RETA_SIZE_512 / RTE_ETH_RETA_GROUP_SIZE) static int rss_setup(uint16_t port_id, @@ -149,11 +165,11 @@ rss_setup(uint16_t port_id, memset(reta_conf, 0, sizeof(reta_conf)); for (i = 0; i < reta_size; i++) - reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX; + reta_conf[i / RTE_ETH_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 reta_id = i / RTE_ETH_RETA_GROUP_SIZE; + uint32_t reta_pos = i % RTE_ETH_RETA_GROUP_SIZE; uint32_t rss_qs_pos = i % rss->n_queues; reta_conf[reta_id].reta[reta_pos] = @@ -211,7 +227,7 @@ link_create(struct obj *obj, const char *name, struct link_params *params) rss = params->rx.rss; if (rss) { if ((port_info.reta_size == 0) || - (port_info.reta_size > ETH_RSS_RETA_SIZE_512)) + (port_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512)) return NULL; if ((rss->n_queues == 0) || @@ -229,9 +245,9 @@ link_create(struct obj *obj, const char *name, struct link_params *params) /* Port */ memcpy(&port_conf, &port_conf_default, sizeof(port_conf)); if (rss) { - port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS; + port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS; port_conf.rx_adv_conf.rss_conf.rss_hf = - (ETH_RSS_IP | ETH_RSS_TCP | ETH_RSS_UDP) & + (RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP) & port_info.flow_type_rss_offloads; } @@ -340,7 +356,7 @@ link_is_up(struct obj *obj, const char *name) if (rte_eth_link_get(link->port_id, &link_params) < 0) return 0; - return (link_params.link_status == ETH_LINK_DOWN) ? 0 : 1; + return (link_params.link_status == RTE_ETH_LINK_DOWN) ? 0 : 1; } struct link * @@ -421,6 +437,88 @@ ring_find(struct obj *obj, const char *name) 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 */ @@ -483,6 +581,18 @@ pipeline_create(struct obj *obj, const char *name, int numa_node) 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, @@ -490,6 +600,13 @@ pipeline_create(struct obj *obj, const char *name, int numa_node) 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) @@ -541,6 +658,7 @@ obj_init(void) TAILQ_INIT(&obj->link_list); TAILQ_INIT(&obj->ring_list); TAILQ_INIT(&obj->pipeline_list); + TAILQ_INIT(&obj->tap_list); return obj; }