mbuf: use pktmbuf helper to create the pool
[dpdk.git] / examples / ip_pipeline / init.c
index 0dbc332..c7f9470 100644 (file)
 #include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
+#include <netinet/in.h>
+#ifdef RTE_EXEC_ENV_LINUXAPP
+#include <linux/if.h>
+#include <linux/if_tun.h>
+#endif
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
 
 #include <rte_cycles.h>
 #include <rte_ethdev.h>
@@ -70,11 +78,14 @@ app_init_core_map(struct app_params *app)
                cpu_core_map_print(app->core_map);
 }
 
+/* Core Mask String in Hex Representation */
+#define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
+
 static void
 app_init_core_mask(struct app_params *app)
 {
-       uint64_t mask = 0;
        uint32_t i;
+       char core_mask_str[APP_CORE_MASK_STRING_SIZE];
 
        for (i = 0; i < app->n_pipelines; i++) {
                struct app_pipeline_params *p = &app->pipeline_params[i];
@@ -88,17 +99,18 @@ app_init_core_mask(struct app_params *app)
                if (lcore_id < 0)
                        rte_panic("Cannot create CPU core mask\n");
 
-               mask |= 1LLU << lcore_id;
+               app_core_enable_in_core_mask(app, lcore_id);
        }
 
-       app->core_mask = mask;
-       APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
+       app_core_build_core_mask_string(app, core_mask_str);
+       APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
 }
 
 static void
 app_init_eal(struct app_params *app)
 {
        char buffer[256];
+       char core_mask_str[APP_CORE_MASK_STRING_SIZE];
        struct app_eal_params *p = &app->eal_params;
        uint32_t n_args = 0;
        uint32_t i;
@@ -106,7 +118,8 @@ app_init_eal(struct app_params *app)
 
        app->eal_argv[n_args++] = strdup(app->app_name);
 
-       snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
+       app_core_build_core_mask_string(app, core_mask_str);
+       snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->coremap) {
@@ -236,7 +249,7 @@ app_init_eal(struct app_params *app)
        }
 
        if (p->add_driver) {
-               snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
+               snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -316,16 +329,14 @@ app_init_mempool(struct app_params *app)
                struct app_mempool_params *p = &app->mempool_params[i];
 
                APP_LOG(app, HIGH, "Initializing %s ...", p->name);
-               app->mempool[i] = rte_mempool_create(
-                               p->name,
-                               p->pool_size,
-                               p->buffer_size,
-                               p->cache_size,
-                               sizeof(struct rte_pktmbuf_pool_private),
-                               rte_pktmbuf_pool_init, NULL,
-                               rte_pktmbuf_init, NULL,
-                               p->cpu_socket_id,
-                               0);
+               app->mempool[i] = rte_pktmbuf_pool_create(
+                       p->name,
+                       p->pool_size,
+                       p->cache_size,
+                       0, /* priv_size */
+                       p->buffer_size -
+                               sizeof(struct rte_mbuf), /* mbuf data size */
+                       p->cpu_socket_id);
 
                if (app->mempool[i] == NULL)
                        rte_panic("%s init error\n", p->name);
@@ -1154,6 +1165,44 @@ app_init_tm(struct app_params *app)
        }
 }
 
+#ifndef RTE_EXEC_ENV_LINUXAPP
+static void
+app_init_tap(struct app_params *app) {
+       if (app->n_pktq_tap == 0)
+               return;
+
+       rte_panic("TAP device not supported.\n");
+}
+#else
+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;
+       }
+}
+#endif
+
 #ifdef RTE_LIBRTE_KNI
 static int
 kni_config_network_interface(uint8_t port_id, uint8_t if_up) {
@@ -1370,6 +1419,24 @@ void app_pipeline_params_get(struct app_params *app,
                        out->burst_size = app->tm_params[in->id].burst_read;
                        break;
                }
+#ifdef RTE_EXEC_ENV_LINUXAPP
+               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;
+               }
+#endif
 #ifdef RTE_LIBRTE_KNI
                case APP_PKTQ_IN_KNI:
                {
@@ -1514,6 +1581,19 @@ void app_pipeline_params_get(struct app_params *app,
                                app->tm_params[in->id].burst_write;
                        break;
                }
+#ifdef RTE_EXEC_ENV_LINUXAPP
+               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;
+               }
+#endif
 #ifdef RTE_LIBRTE_KNI
                case APP_PKTQ_OUT_KNI:
                {
@@ -1730,6 +1810,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);