4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <netinet/in.h>
38 #ifdef RTE_EXEC_ENV_LINUXAPP
40 #include <linux/if_tun.h>
43 #include <sys/ioctl.h>
46 #include <rte_cycles.h>
47 #include <rte_ethdev.h>
48 #include <rte_ether.h>
51 #include <rte_malloc.h>
55 #include "pipeline_common_fe.h"
56 #include "pipeline_master.h"
57 #include "pipeline_passthrough.h"
58 #include "pipeline_firewall.h"
59 #include "pipeline_flow_classification.h"
60 #include "pipeline_flow_actions.h"
61 #include "pipeline_routing.h"
62 #include "thread_fe.h"
64 #define APP_NAME_SIZE 32
66 #define APP_RETA_SIZE_MAX (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
69 app_init_core_map(struct app_params *app)
71 APP_LOG(app, HIGH, "Initializing CPU core map ...");
72 app->core_map = cpu_core_map_init(RTE_MAX_NUMA_NODES, RTE_MAX_LCORE,
75 if (app->core_map == NULL)
76 rte_panic("Cannot create CPU core map\n");
78 if (app->log_level >= APP_LOG_LEVEL_LOW)
79 cpu_core_map_print(app->core_map);
82 /* Core Mask String in Hex Representation */
83 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
86 app_init_core_mask(struct app_params *app)
89 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
91 for (i = 0; i < app->n_pipelines; i++) {
92 struct app_pipeline_params *p = &app->pipeline_params[i];
95 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
101 rte_panic("Cannot create CPU core mask\n");
103 app_core_enable_in_core_mask(app, lcore_id);
106 app_core_build_core_mask_string(app, core_mask_str);
107 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
111 app_init_eal(struct app_params *app)
114 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
115 struct app_eal_params *p = &app->eal_params;
120 app->eal_argv[n_args++] = strdup(app->app_name);
122 app_core_build_core_mask_string(app, core_mask_str);
123 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
124 app->eal_argv[n_args++] = strdup(buffer);
127 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
128 app->eal_argv[n_args++] = strdup(buffer);
131 if (p->master_lcore_present) {
134 "--master-lcore=%" PRIu32,
136 app->eal_argv[n_args++] = strdup(buffer);
139 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
140 app->eal_argv[n_args++] = strdup(buffer);
142 if (p->memory_present) {
143 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
144 app->eal_argv[n_args++] = strdup(buffer);
147 if (p->ranks_present) {
148 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
149 app->eal_argv[n_args++] = strdup(buffer);
152 for (i = 0; i < APP_MAX_LINKS; i++) {
153 if (p->pci_blacklist[i] == NULL)
158 "--pci-blacklist=%s",
159 p->pci_blacklist[i]);
160 app->eal_argv[n_args++] = strdup(buffer);
163 if (app->port_mask != 0)
164 for (i = 0; i < APP_MAX_LINKS; i++) {
165 if (p->pci_whitelist[i] == NULL)
170 "--pci-whitelist=%s",
171 p->pci_whitelist[i]);
172 app->eal_argv[n_args++] = strdup(buffer);
175 for (i = 0; i < app->n_links; i++) {
176 char *pci_bdf = app->link_params[i].pci_bdf;
180 "--pci-whitelist=%s",
182 app->eal_argv[n_args++] = strdup(buffer);
185 for (i = 0; i < APP_MAX_LINKS; i++) {
186 if (p->vdev[i] == NULL)
193 app->eal_argv[n_args++] = strdup(buffer);
196 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
197 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
198 app->eal_argv[n_args++] = strdup(buffer);
206 app->eal_argv[n_args++] = strdup(buffer);
210 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
211 app->eal_argv[n_args++] = strdup(buffer);
214 if (p->log_level_present) {
217 "--log-level=%" PRIu32,
219 app->eal_argv[n_args++] = strdup(buffer);
222 if ((p->version_present) && p->version) {
223 snprintf(buffer, sizeof(buffer), "-v");
224 app->eal_argv[n_args++] = strdup(buffer);
227 if ((p->help_present) && p->help) {
228 snprintf(buffer, sizeof(buffer), "--help");
229 app->eal_argv[n_args++] = strdup(buffer);
232 if ((p->no_huge_present) && p->no_huge) {
233 snprintf(buffer, sizeof(buffer), "--no-huge");
234 app->eal_argv[n_args++] = strdup(buffer);
237 if ((p->no_pci_present) && p->no_pci) {
238 snprintf(buffer, sizeof(buffer), "--no-pci");
239 app->eal_argv[n_args++] = strdup(buffer);
242 if ((p->no_hpet_present) && p->no_hpet) {
243 snprintf(buffer, sizeof(buffer), "--no-hpet");
244 app->eal_argv[n_args++] = strdup(buffer);
247 if ((p->no_shconf_present) && p->no_shconf) {
248 snprintf(buffer, sizeof(buffer), "--no-shconf");
249 app->eal_argv[n_args++] = strdup(buffer);
253 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
254 app->eal_argv[n_args++] = strdup(buffer);
262 app->eal_argv[n_args++] = strdup(buffer);
266 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
267 app->eal_argv[n_args++] = strdup(buffer);
270 if (p->file_prefix) {
275 app->eal_argv[n_args++] = strdup(buffer);
278 if (p->base_virtaddr) {
281 "--base-virtaddr=%s",
283 app->eal_argv[n_args++] = strdup(buffer);
286 if ((p->create_uio_dev_present) && p->create_uio_dev) {
287 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
288 app->eal_argv[n_args++] = strdup(buffer);
296 app->eal_argv[n_args++] = strdup(buffer);
299 snprintf(buffer, sizeof(buffer), "--");
300 app->eal_argv[n_args++] = strdup(buffer);
302 app->eal_argc = n_args;
304 APP_LOG(app, HIGH, "Initializing EAL ...");
305 if (app->log_level >= APP_LOG_LEVEL_LOW) {
308 fprintf(stdout, "[APP] EAL arguments: \"");
309 for (i = 1; i < app->eal_argc; i++)
310 fprintf(stdout, "%s ", app->eal_argv[i]);
311 fprintf(stdout, "\"\n");
314 status = rte_eal_init(app->eal_argc, app->eal_argv);
316 rte_panic("EAL init error\n");
320 app_init_mempool(struct app_params *app)
324 for (i = 0; i < app->n_mempools; i++) {
325 struct app_mempool_params *p = &app->mempool_params[i];
327 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
328 app->mempool[i] = rte_pktmbuf_pool_create(
334 sizeof(struct rte_mbuf), /* mbuf data size */
337 if (app->mempool[i] == NULL)
338 rte_panic("%s init error\n", p->name);
343 app_link_filter_arp_add(struct app_link_params *link)
345 struct rte_eth_ethertype_filter filter = {
346 .ether_type = ETHER_TYPE_ARP,
348 .queue = link->arp_q,
351 return rte_eth_dev_filter_ctrl(link->pmd_id,
352 RTE_ETH_FILTER_ETHERTYPE,
358 app_link_filter_tcp_syn_add(struct app_link_params *link)
360 struct rte_eth_syn_filter filter = {
362 .queue = link->tcp_syn_q,
365 return rte_eth_dev_filter_ctrl(link->pmd_id,
372 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
374 struct rte_eth_ntuple_filter filter = {
375 .flags = RTE_5TUPLE_FLAGS,
376 .dst_ip = rte_bswap32(l2->ip),
377 .dst_ip_mask = UINT32_MAX, /* Enable */
379 .src_ip_mask = 0, /* Disable */
381 .dst_port_mask = 0, /* Disable */
383 .src_port_mask = 0, /* Disable */
385 .proto_mask = 0, /* Disable */
387 .priority = 1, /* Lowest */
388 .queue = l1->ip_local_q,
391 return rte_eth_dev_filter_ctrl(l1->pmd_id,
392 RTE_ETH_FILTER_NTUPLE,
398 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
400 struct rte_eth_ntuple_filter filter = {
401 .flags = RTE_5TUPLE_FLAGS,
402 .dst_ip = rte_bswap32(l2->ip),
403 .dst_ip_mask = UINT32_MAX, /* Enable */
405 .src_ip_mask = 0, /* Disable */
407 .dst_port_mask = 0, /* Disable */
409 .src_port_mask = 0, /* Disable */
411 .proto_mask = 0, /* Disable */
413 .priority = 1, /* Lowest */
414 .queue = l1->ip_local_q,
417 return rte_eth_dev_filter_ctrl(l1->pmd_id,
418 RTE_ETH_FILTER_NTUPLE,
419 RTE_ETH_FILTER_DELETE,
424 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
426 struct rte_eth_ntuple_filter filter = {
427 .flags = RTE_5TUPLE_FLAGS,
428 .dst_ip = rte_bswap32(l2->ip),
429 .dst_ip_mask = UINT32_MAX, /* Enable */
431 .src_ip_mask = 0, /* Disable */
433 .dst_port_mask = 0, /* Disable */
435 .src_port_mask = 0, /* Disable */
436 .proto = IPPROTO_TCP,
437 .proto_mask = UINT8_MAX, /* Enable */
439 .priority = 2, /* Higher priority than IP */
440 .queue = l1->tcp_local_q,
443 return rte_eth_dev_filter_ctrl(l1->pmd_id,
444 RTE_ETH_FILTER_NTUPLE,
450 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
452 struct rte_eth_ntuple_filter filter = {
453 .flags = RTE_5TUPLE_FLAGS,
454 .dst_ip = rte_bswap32(l2->ip),
455 .dst_ip_mask = UINT32_MAX, /* Enable */
457 .src_ip_mask = 0, /* Disable */
459 .dst_port_mask = 0, /* Disable */
461 .src_port_mask = 0, /* Disable */
462 .proto = IPPROTO_TCP,
463 .proto_mask = UINT8_MAX, /* Enable */
465 .priority = 2, /* Higher priority than IP */
466 .queue = l1->tcp_local_q,
469 return rte_eth_dev_filter_ctrl(l1->pmd_id,
470 RTE_ETH_FILTER_NTUPLE,
471 RTE_ETH_FILTER_DELETE,
476 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
478 struct rte_eth_ntuple_filter filter = {
479 .flags = RTE_5TUPLE_FLAGS,
480 .dst_ip = rte_bswap32(l2->ip),
481 .dst_ip_mask = UINT32_MAX, /* Enable */
483 .src_ip_mask = 0, /* Disable */
485 .dst_port_mask = 0, /* Disable */
487 .src_port_mask = 0, /* Disable */
488 .proto = IPPROTO_UDP,
489 .proto_mask = UINT8_MAX, /* Enable */
491 .priority = 2, /* Higher priority than IP */
492 .queue = l1->udp_local_q,
495 return rte_eth_dev_filter_ctrl(l1->pmd_id,
496 RTE_ETH_FILTER_NTUPLE,
502 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
504 struct rte_eth_ntuple_filter filter = {
505 .flags = RTE_5TUPLE_FLAGS,
506 .dst_ip = rte_bswap32(l2->ip),
507 .dst_ip_mask = UINT32_MAX, /* Enable */
509 .src_ip_mask = 0, /* Disable */
511 .dst_port_mask = 0, /* Disable */
513 .src_port_mask = 0, /* Disable */
514 .proto = IPPROTO_UDP,
515 .proto_mask = UINT8_MAX, /* Enable */
517 .priority = 2, /* Higher priority than IP */
518 .queue = l1->udp_local_q,
521 return rte_eth_dev_filter_ctrl(l1->pmd_id,
522 RTE_ETH_FILTER_NTUPLE,
523 RTE_ETH_FILTER_DELETE,
528 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
530 struct rte_eth_ntuple_filter filter = {
531 .flags = RTE_5TUPLE_FLAGS,
532 .dst_ip = rte_bswap32(l2->ip),
533 .dst_ip_mask = UINT32_MAX, /* Enable */
535 .src_ip_mask = 0, /* Disable */
537 .dst_port_mask = 0, /* Disable */
539 .src_port_mask = 0, /* Disable */
540 .proto = IPPROTO_SCTP,
541 .proto_mask = UINT8_MAX, /* Enable */
543 .priority = 2, /* Higher priority than IP */
544 .queue = l1->sctp_local_q,
547 return rte_eth_dev_filter_ctrl(l1->pmd_id,
548 RTE_ETH_FILTER_NTUPLE,
554 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
556 struct rte_eth_ntuple_filter filter = {
557 .flags = RTE_5TUPLE_FLAGS,
558 .dst_ip = rte_bswap32(l2->ip),
559 .dst_ip_mask = UINT32_MAX, /* Enable */
561 .src_ip_mask = 0, /* Disable */
563 .dst_port_mask = 0, /* Disable */
565 .src_port_mask = 0, /* Disable */
566 .proto = IPPROTO_SCTP,
567 .proto_mask = UINT8_MAX, /* Enable */
569 .priority = 2, /* Higher priority than IP */
570 .queue = l1->sctp_local_q,
573 return rte_eth_dev_filter_ctrl(l1->pmd_id,
574 RTE_ETH_FILTER_NTUPLE,
575 RTE_ETH_FILTER_DELETE,
580 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
582 if (cp->arp_q != 0) {
583 int status = app_link_filter_arp_add(cp);
585 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
586 "Adding ARP filter (queue = %" PRIu32 ")",
587 cp->name, cp->pmd_id, cp->arp_q);
590 rte_panic("%s (%" PRIu32 "): "
591 "Error adding ARP filter "
592 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
593 cp->name, cp->pmd_id, cp->arp_q, status);
598 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
600 if (cp->tcp_syn_q != 0) {
601 int status = app_link_filter_tcp_syn_add(cp);
603 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
604 "Adding TCP SYN filter (queue = %" PRIu32 ")",
605 cp->name, cp->pmd_id, cp->tcp_syn_q);
608 rte_panic("%s (%" PRIu32 "): "
609 "Error adding TCP SYN filter "
610 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
611 cp->name, cp->pmd_id, cp->tcp_syn_q,
617 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
622 /* For each link, add filters for IP of current link */
624 for (i = 0; i < app->n_links; i++) {
625 struct app_link_params *p = &app->link_params[i];
628 if (p->ip_local_q != 0) {
629 int status = app_link_filter_ip_add(p, cp);
631 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
632 "Adding IP filter (queue= %" PRIu32
633 ", IP = 0x%08" PRIx32 ")",
634 p->name, p->pmd_id, p->ip_local_q,
638 rte_panic("%s (%" PRIu32 "): "
640 "filter (queue= %" PRIu32 ", "
644 p->ip_local_q, cp->ip, status);
648 if (p->tcp_local_q != 0) {
649 int status = app_link_filter_tcp_add(p, cp);
651 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
654 ", IP = 0x%08" PRIx32 ")",
655 p->name, p->pmd_id, p->tcp_local_q,
659 rte_panic("%s (%" PRIu32 "): "
661 "filter (queue = %" PRIu32 ", "
665 p->tcp_local_q, cp->ip, status);
669 if (p->udp_local_q != 0) {
670 int status = app_link_filter_udp_add(p, cp);
672 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
675 ", IP = 0x%08" PRIx32 ")",
676 p->name, p->pmd_id, p->udp_local_q,
680 rte_panic("%s (%" PRIu32 "): "
682 "filter (queue = %" PRIu32 ", "
686 p->udp_local_q, cp->ip, status);
690 if (p->sctp_local_q != 0) {
691 int status = app_link_filter_sctp_add(p, cp);
693 APP_LOG(app, LOW, "%s (%" PRIu32
694 "): Adding SCTP filter "
696 ", IP = 0x%08" PRIx32 ")",
697 p->name, p->pmd_id, p->sctp_local_q,
701 rte_panic("%s (%" PRIu32 "): "
703 "filter (queue = %" PRIu32 ", "
707 p->sctp_local_q, cp->ip,
714 status = rte_eth_dev_set_link_up(cp->pmd_id);
715 /* Do not panic if PMD does not provide link up functionality */
716 if (status < 0 && status != -ENOTSUP)
717 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
718 PRId32 "\n", cp->name, cp->pmd_id, status);
720 /* Mark link as UP */
725 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
731 status = rte_eth_dev_set_link_down(cp->pmd_id);
732 /* Do not panic if PMD does not provide link down functionality */
733 if (status < 0 && status != -ENOTSUP)
734 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
735 PRId32 "\n", cp->name, cp->pmd_id, status);
737 /* Mark link as DOWN */
740 /* Return if current link IP is not valid */
744 /* For each link, remove filters for IP of current link */
745 for (i = 0; i < app->n_links; i++) {
746 struct app_link_params *p = &app->link_params[i];
749 if (p->ip_local_q != 0) {
750 int status = app_link_filter_ip_del(p, cp);
752 APP_LOG(app, LOW, "%s (%" PRIu32
753 "): Deleting IP filter "
754 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
755 p->name, p->pmd_id, p->ip_local_q, cp->ip);
758 rte_panic("%s (%" PRIu32
759 "): Error deleting IP filter "
763 p->name, p->pmd_id, p->ip_local_q,
768 if (p->tcp_local_q != 0) {
769 int status = app_link_filter_tcp_del(p, cp);
771 APP_LOG(app, LOW, "%s (%" PRIu32
772 "): Deleting TCP filter "
774 ", IP = 0x%" PRIx32 ")",
775 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
778 rte_panic("%s (%" PRIu32
779 "): Error deleting TCP filter "
783 p->name, p->pmd_id, p->tcp_local_q,
788 if (p->udp_local_q != 0) {
789 int status = app_link_filter_udp_del(p, cp);
791 APP_LOG(app, LOW, "%s (%" PRIu32
792 "): Deleting UDP filter "
793 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
794 p->name, p->pmd_id, p->udp_local_q, cp->ip);
797 rte_panic("%s (%" PRIu32
798 "): Error deleting UDP filter "
802 p->name, p->pmd_id, p->udp_local_q,
807 if (p->sctp_local_q != 0) {
808 int status = app_link_filter_sctp_del(p, cp);
810 APP_LOG(app, LOW, "%s (%" PRIu32
811 "): Deleting SCTP filter "
813 ", IP = 0x%" PRIx32 ")",
814 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
817 rte_panic("%s (%" PRIu32
818 "): Error deleting SCTP filter "
822 p->name, p->pmd_id, p->sctp_local_q,
829 app_check_link(struct app_params *app)
831 uint32_t all_links_up, i;
835 for (i = 0; i < app->n_links; i++) {
836 struct app_link_params *p = &app->link_params[i];
837 struct rte_eth_link link_params;
839 memset(&link_params, 0, sizeof(link_params));
840 rte_eth_link_get(p->pmd_id, &link_params);
842 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
845 link_params.link_speed / 1000,
846 link_params.link_status ? "UP" : "DOWN");
848 if (link_params.link_status == ETH_LINK_DOWN)
852 if (all_links_up == 0)
853 rte_panic("Some links are DOWN\n");
857 is_any_swq_frag_or_ras(struct app_params *app)
861 for (i = 0; i < app->n_pktq_swq; i++) {
862 struct app_pktq_swq_params *p = &app->swq_params[i];
864 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
865 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
873 app_init_link_frag_ras(struct app_params *app)
877 if (is_any_swq_frag_or_ras(app)) {
878 for (i = 0; i < app->n_pktq_hwq_out; i++) {
879 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
881 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
887 app_get_cpu_socket_id(uint32_t pmd_id)
889 int status = rte_eth_dev_socket_id(pmd_id);
891 return (status != SOCKET_ID_ANY) ? status : 0;
895 app_link_rss_enabled(struct app_link_params *cp)
897 return (cp->n_rss_qs) ? 1 : 0;
901 app_link_rss_setup(struct app_link_params *cp)
903 struct rte_eth_dev_info dev_info;
904 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
909 memset(&dev_info, 0, sizeof(dev_info));
910 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
912 if (dev_info.reta_size == 0)
913 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
914 cp->name, cp->pmd_id);
916 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
917 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
918 cp->name, cp->pmd_id);
920 /* Setup RETA contents */
921 memset(reta_conf, 0, sizeof(reta_conf));
923 for (i = 0; i < dev_info.reta_size; i++)
924 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
926 for (i = 0; i < dev_info.reta_size; i++) {
927 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
928 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
929 uint32_t rss_qs_pos = i % cp->n_rss_qs;
931 reta_conf[reta_id].reta[reta_pos] =
932 (uint16_t) cp->rss_qs[rss_qs_pos];
936 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
940 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
941 cp->name, cp->pmd_id);
945 app_init_link_set_config(struct app_link_params *p)
948 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
949 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
956 app_init_link(struct app_params *app)
960 app_init_link_frag_ras(app);
962 for (i = 0; i < app->n_links; i++) {
963 struct app_link_params *p_link = &app->link_params[i];
964 uint32_t link_id, n_hwq_in, n_hwq_out, j;
967 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
968 n_hwq_in = app_link_get_n_rxq(app, p_link);
969 n_hwq_out = app_link_get_n_txq(app, p_link);
970 app_init_link_set_config(p_link);
972 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
973 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
980 status = rte_eth_dev_configure(
986 rte_panic("%s (%" PRId32 "): "
987 "init error (%" PRId32 ")\n",
988 p_link->name, p_link->pmd_id, status);
990 rte_eth_macaddr_get(p_link->pmd_id,
991 (struct ether_addr *) &p_link->mac_addr);
994 rte_eth_promiscuous_enable(p_link->pmd_id);
997 for (j = 0; j < app->n_pktq_hwq_in; j++) {
998 struct app_pktq_hwq_in_params *p_rxq =
999 &app->hwq_in_params[j];
1000 uint32_t rxq_link_id, rxq_queue_id;
1001 uint16_t nb_rxd = p_rxq->size;
1003 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
1004 &rxq_link_id, &rxq_queue_id);
1005 if (rxq_link_id != link_id)
1008 status = rte_eth_dev_adjust_nb_rx_tx_desc(
1013 rte_panic("%s (%" PRIu32 "): "
1014 "%s adjust number of Rx descriptors "
1015 "error (%" PRId32 ")\n",
1021 status = rte_eth_rx_queue_setup(
1025 app_get_cpu_socket_id(p_link->pmd_id),
1027 app->mempool[p_rxq->mempool_id]);
1029 rte_panic("%s (%" PRIu32 "): "
1030 "%s init error (%" PRId32 ")\n",
1038 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1039 struct app_pktq_hwq_out_params *p_txq =
1040 &app->hwq_out_params[j];
1041 uint32_t txq_link_id, txq_queue_id;
1042 uint16_t nb_txd = p_txq->size;
1044 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1045 &txq_link_id, &txq_queue_id);
1046 if (txq_link_id != link_id)
1049 status = rte_eth_dev_adjust_nb_rx_tx_desc(
1054 rte_panic("%s (%" PRIu32 "): "
1055 "%s adjust number of Tx descriptors "
1056 "error (%" PRId32 ")\n",
1062 status = rte_eth_tx_queue_setup(
1066 app_get_cpu_socket_id(p_link->pmd_id),
1069 rte_panic("%s (%" PRIu32 "): "
1070 "%s init error (%" PRId32 ")\n",
1078 status = rte_eth_dev_start(p_link->pmd_id);
1080 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1081 p_link->name, status);
1084 app_link_set_arp_filter(app, p_link);
1085 app_link_set_tcp_syn_filter(app, p_link);
1086 if (app_link_rss_enabled(p_link))
1087 app_link_rss_setup(p_link);
1090 app_link_up_internal(app, p_link);
1093 app_check_link(app);
1097 app_init_swq(struct app_params *app)
1101 for (i = 0; i < app->n_pktq_swq; i++) {
1102 struct app_pktq_swq_params *p = &app->swq_params[i];
1105 if (app_swq_get_readers(app, p) == 1)
1106 flags |= RING_F_SC_DEQ;
1107 if (app_swq_get_writers(app, p) == 1)
1108 flags |= RING_F_SP_ENQ;
1110 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1111 app->swq[i] = rte_ring_create(
1117 if (app->swq[i] == NULL)
1118 rte_panic("%s init error\n", p->name);
1123 app_init_tm(struct app_params *app)
1127 for (i = 0; i < app->n_pktq_tm; i++) {
1128 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1129 struct app_link_params *p_link;
1130 struct rte_eth_link link_eth_params;
1131 struct rte_sched_port *sched;
1132 uint32_t n_subports, subport_id;
1135 p_link = app_get_link_for_tm(app, p_tm);
1137 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1140 p_tm->sched_port_params.name = p_tm->name;
1141 p_tm->sched_port_params.socket =
1142 app_get_cpu_socket_id(p_link->pmd_id);
1143 p_tm->sched_port_params.rate =
1144 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1146 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1147 sched = rte_sched_port_config(&p_tm->sched_port_params);
1149 rte_panic("%s init error\n", p_tm->name);
1153 n_subports = p_tm->sched_port_params.n_subports_per_port;
1154 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1155 uint32_t n_pipes_per_subport, pipe_id;
1157 status = rte_sched_subport_config(sched,
1159 &p_tm->sched_subport_params[subport_id]);
1161 rte_panic("%s subport %" PRIu32
1162 " init error (%" PRId32 ")\n",
1163 p_tm->name, subport_id, status);
1166 n_pipes_per_subport =
1167 p_tm->sched_port_params.n_pipes_per_subport;
1169 pipe_id < n_pipes_per_subport;
1171 int profile_id = p_tm->sched_pipe_to_profile[
1172 subport_id * APP_MAX_SCHED_PIPES +
1175 if (profile_id == -1)
1178 status = rte_sched_pipe_config(sched,
1183 rte_panic("%s subport %" PRIu32
1185 " (profile %" PRId32 ") "
1186 "init error (% " PRId32 ")\n",
1187 p_tm->name, subport_id, pipe_id,
1188 profile_id, status);
1194 #ifndef RTE_EXEC_ENV_LINUXAPP
1196 app_init_tap(struct app_params *app) {
1197 if (app->n_pktq_tap == 0)
1200 rte_panic("TAP device not supported.\n");
1204 app_init_tap(struct app_params *app)
1208 for (i = 0; i < app->n_pktq_tap; i++) {
1209 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1213 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1215 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1217 rte_panic("Cannot open file /dev/net/tun\n");
1219 memset(&ifr, 0, sizeof(ifr));
1220 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1221 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1223 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1225 rte_panic("TAP setup error\n");
1232 #ifdef RTE_LIBRTE_KNI
1234 kni_config_network_interface(uint16_t port_id, uint8_t if_up) {
1237 if (port_id >= rte_eth_dev_count())
1241 rte_eth_dev_set_link_up(port_id) :
1242 rte_eth_dev_set_link_down(port_id);
1248 kni_change_mtu(uint16_t port_id, unsigned int new_mtu) {
1251 if (port_id >= rte_eth_dev_count())
1254 if (new_mtu > ETHER_MAX_LEN)
1258 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1264 #endif /* RTE_LIBRTE_KNI */
1266 #ifndef RTE_LIBRTE_KNI
1268 app_init_kni(struct app_params *app) {
1269 if (app->n_pktq_kni == 0)
1272 rte_panic("Can not init KNI without librte_kni support.\n");
1276 app_init_kni(struct app_params *app) {
1279 if (app->n_pktq_kni == 0)
1282 rte_kni_init(app->n_pktq_kni);
1284 for (i = 0; i < app->n_pktq_kni; i++) {
1285 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1286 struct app_link_params *p_link;
1287 struct rte_eth_dev_info dev_info;
1288 struct app_mempool_params *mempool_params;
1289 struct rte_mempool *mempool;
1290 struct rte_kni_conf conf;
1291 struct rte_kni_ops ops;
1294 p_link = app_get_link_for_kni(app, p_kni);
1295 memset(&dev_info, 0, sizeof(dev_info));
1296 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1299 mempool_params = &app->mempool_params[p_kni->mempool_id];
1300 mempool = app->mempool[p_kni->mempool_id];
1303 memset(&conf, 0, sizeof(conf));
1304 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1305 conf.force_bind = p_kni->force_bind;
1306 if (conf.force_bind) {
1309 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1312 p_kni->hyper_th_id);
1315 rte_panic("%s invalid CPU core\n", p_kni->name);
1317 conf.core_id = (uint32_t) lcore_id;
1319 conf.group_id = p_link->pmd_id;
1320 conf.mbuf_size = mempool_params->buffer_size;
1321 conf.addr = dev_info.pci_dev->addr;
1322 conf.id = dev_info.pci_dev->id;
1324 memset(&ops, 0, sizeof(ops));
1325 ops.port_id = (uint8_t) p_link->pmd_id;
1326 ops.change_mtu = kni_change_mtu;
1327 ops.config_network_if = kni_config_network_interface;
1329 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1330 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1332 rte_panic("%s init error\n", p_kni->name);
1335 #endif /* RTE_LIBRTE_KNI */
1338 app_init_msgq(struct app_params *app)
1342 for (i = 0; i < app->n_msgq; i++) {
1343 struct app_msgq_params *p = &app->msgq_params[i];
1345 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1346 app->msgq[i] = rte_ring_create(
1350 RING_F_SP_ENQ | RING_F_SC_DEQ);
1352 if (app->msgq[i] == NULL)
1353 rte_panic("%s init error\n", p->name);
1357 void app_pipeline_params_get(struct app_params *app,
1358 struct app_pipeline_params *p_in,
1359 struct pipeline_params *p_out)
1363 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1365 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1367 p_out->socket_id = (int) p_in->socket_id;
1369 p_out->log_level = app->log_level;
1372 p_out->n_ports_in = p_in->n_pktq_in;
1373 for (i = 0; i < p_in->n_pktq_in; i++) {
1374 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1375 struct pipeline_port_in_params *out = &p_out->port_in[i];
1378 case APP_PKTQ_IN_HWQ:
1380 struct app_pktq_hwq_in_params *p_hwq_in =
1381 &app->hwq_in_params[in->id];
1382 struct app_link_params *p_link =
1383 app_get_link_for_rxq(app, p_hwq_in);
1384 uint32_t rxq_link_id, rxq_queue_id;
1386 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1390 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1391 out->params.ethdev.port_id = p_link->pmd_id;
1392 out->params.ethdev.queue_id = rxq_queue_id;
1393 out->burst_size = p_hwq_in->burst;
1396 case APP_PKTQ_IN_SWQ:
1398 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1400 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1401 if (app_swq_get_readers(app, swq_params) == 1) {
1402 out->type = PIPELINE_PORT_IN_RING_READER;
1403 out->params.ring.ring = app->swq[in->id];
1404 out->burst_size = app->swq_params[in->id].burst_read;
1406 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1407 out->params.ring_multi.ring = app->swq[in->id];
1408 out->burst_size = swq_params->burst_read;
1411 if (swq_params->ipv4_frag == 1) {
1412 struct rte_port_ring_reader_ipv4_frag_params *params =
1413 &out->params.ring_ipv4_frag;
1415 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1416 params->ring = app->swq[in->id];
1417 params->mtu = swq_params->mtu;
1418 params->metadata_size = swq_params->metadata_size;
1419 params->pool_direct =
1420 app->mempool[swq_params->mempool_direct_id];
1421 params->pool_indirect =
1422 app->mempool[swq_params->mempool_indirect_id];
1423 out->burst_size = swq_params->burst_read;
1425 struct rte_port_ring_reader_ipv6_frag_params *params =
1426 &out->params.ring_ipv6_frag;
1428 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1429 params->ring = app->swq[in->id];
1430 params->mtu = swq_params->mtu;
1431 params->metadata_size = swq_params->metadata_size;
1432 params->pool_direct =
1433 app->mempool[swq_params->mempool_direct_id];
1434 params->pool_indirect =
1435 app->mempool[swq_params->mempool_indirect_id];
1436 out->burst_size = swq_params->burst_read;
1441 case APP_PKTQ_IN_TM:
1443 out->type = PIPELINE_PORT_IN_SCHED_READER;
1444 out->params.sched.sched = app->tm[in->id];
1445 out->burst_size = app->tm_params[in->id].burst_read;
1448 #ifdef RTE_EXEC_ENV_LINUXAPP
1449 case APP_PKTQ_IN_TAP:
1451 struct app_pktq_tap_params *tap_params =
1452 &app->tap_params[in->id];
1453 struct app_mempool_params *mempool_params =
1454 &app->mempool_params[tap_params->mempool_id];
1455 struct rte_mempool *mempool =
1456 app->mempool[tap_params->mempool_id];
1458 out->type = PIPELINE_PORT_IN_FD_READER;
1459 out->params.fd.fd = app->tap[in->id];
1460 out->params.fd.mtu = mempool_params->buffer_size;
1461 out->params.fd.mempool = mempool;
1462 out->burst_size = app->tap_params[in->id].burst_read;
1466 #ifdef RTE_LIBRTE_KNI
1467 case APP_PKTQ_IN_KNI:
1469 out->type = PIPELINE_PORT_IN_KNI_READER;
1470 out->params.kni.kni = app->kni[in->id];
1471 out->burst_size = app->kni_params[in->id].burst_read;
1474 #endif /* RTE_LIBRTE_KNI */
1475 case APP_PKTQ_IN_SOURCE:
1477 uint32_t mempool_id =
1478 app->source_params[in->id].mempool_id;
1480 out->type = PIPELINE_PORT_IN_SOURCE;
1481 out->params.source.mempool = app->mempool[mempool_id];
1482 out->burst_size = app->source_params[in->id].burst;
1483 out->params.source.file_name =
1484 app->source_params[in->id].file_name;
1485 out->params.source.n_bytes_per_pkt =
1486 app->source_params[in->id].n_bytes_per_pkt;
1495 p_out->n_ports_out = p_in->n_pktq_out;
1496 for (i = 0; i < p_in->n_pktq_out; i++) {
1497 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1498 struct pipeline_port_out_params *out = &p_out->port_out[i];
1501 case APP_PKTQ_OUT_HWQ:
1503 struct app_pktq_hwq_out_params *p_hwq_out =
1504 &app->hwq_out_params[in->id];
1505 struct app_link_params *p_link =
1506 app_get_link_for_txq(app, p_hwq_out);
1507 uint32_t txq_link_id, txq_queue_id;
1509 sscanf(p_hwq_out->name,
1510 "TXQ%" SCNu32 ".%" SCNu32,
1514 if (p_hwq_out->dropless == 0) {
1515 struct rte_port_ethdev_writer_params *params =
1516 &out->params.ethdev;
1518 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1519 params->port_id = p_link->pmd_id;
1520 params->queue_id = txq_queue_id;
1521 params->tx_burst_sz =
1522 app->hwq_out_params[in->id].burst;
1524 struct rte_port_ethdev_writer_nodrop_params
1525 *params = &out->params.ethdev_nodrop;
1528 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1529 params->port_id = p_link->pmd_id;
1530 params->queue_id = txq_queue_id;
1531 params->tx_burst_sz = p_hwq_out->burst;
1532 params->n_retries = p_hwq_out->n_retries;
1536 case APP_PKTQ_OUT_SWQ:
1538 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1540 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1541 if (app_swq_get_writers(app, swq_params) == 1) {
1542 if (app->swq_params[in->id].dropless == 0) {
1543 struct rte_port_ring_writer_params *params =
1546 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1547 params->ring = app->swq[in->id];
1548 params->tx_burst_sz =
1549 app->swq_params[in->id].burst_write;
1551 struct rte_port_ring_writer_nodrop_params
1552 *params = &out->params.ring_nodrop;
1555 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1556 params->ring = app->swq[in->id];
1557 params->tx_burst_sz =
1558 app->swq_params[in->id].burst_write;
1560 app->swq_params[in->id].n_retries;
1563 if (swq_params->dropless == 0) {
1564 struct rte_port_ring_multi_writer_params *params =
1565 &out->params.ring_multi;
1567 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1568 params->ring = app->swq[in->id];
1569 params->tx_burst_sz = swq_params->burst_write;
1571 struct rte_port_ring_multi_writer_nodrop_params
1572 *params = &out->params.ring_multi_nodrop;
1574 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1575 params->ring = app->swq[in->id];
1576 params->tx_burst_sz = swq_params->burst_write;
1577 params->n_retries = swq_params->n_retries;
1581 if (swq_params->ipv4_ras == 1) {
1582 struct rte_port_ring_writer_ipv4_ras_params *params =
1583 &out->params.ring_ipv4_ras;
1585 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1586 params->ring = app->swq[in->id];
1587 params->tx_burst_sz = swq_params->burst_write;
1589 struct rte_port_ring_writer_ipv6_ras_params *params =
1590 &out->params.ring_ipv6_ras;
1592 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1593 params->ring = app->swq[in->id];
1594 params->tx_burst_sz = swq_params->burst_write;
1599 case APP_PKTQ_OUT_TM:
1601 struct rte_port_sched_writer_params *params =
1604 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1605 params->sched = app->tm[in->id];
1606 params->tx_burst_sz =
1607 app->tm_params[in->id].burst_write;
1610 #ifdef RTE_EXEC_ENV_LINUXAPP
1611 case APP_PKTQ_OUT_TAP:
1613 struct rte_port_fd_writer_params *params =
1616 out->type = PIPELINE_PORT_OUT_FD_WRITER;
1617 params->fd = app->tap[in->id];
1618 params->tx_burst_sz =
1619 app->tap_params[in->id].burst_write;
1623 #ifdef RTE_LIBRTE_KNI
1624 case APP_PKTQ_OUT_KNI:
1626 struct app_pktq_kni_params *p_kni =
1627 &app->kni_params[in->id];
1629 if (p_kni->dropless == 0) {
1630 struct rte_port_kni_writer_params *params =
1633 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1634 params->kni = app->kni[in->id];
1635 params->tx_burst_sz =
1636 app->kni_params[in->id].burst_write;
1638 struct rte_port_kni_writer_nodrop_params
1639 *params = &out->params.kni_nodrop;
1641 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1642 params->kni = app->kni[in->id];
1643 params->tx_burst_sz =
1644 app->kni_params[in->id].burst_write;
1646 app->kni_params[in->id].n_retries;
1650 #endif /* RTE_LIBRTE_KNI */
1651 case APP_PKTQ_OUT_SINK:
1653 out->type = PIPELINE_PORT_OUT_SINK;
1654 out->params.sink.file_name =
1655 app->sink_params[in->id].file_name;
1656 out->params.sink.max_n_pkts =
1657 app->sink_params[in->id].
1668 p_out->n_msgq = p_in->n_msgq_in;
1670 for (i = 0; i < p_in->n_msgq_in; i++)
1671 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1673 for (i = 0; i < p_in->n_msgq_out; i++)
1674 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1677 p_out->n_args = p_in->n_args;
1678 for (i = 0; i < p_in->n_args; i++) {
1679 p_out->args_name[i] = p_in->args_name[i];
1680 p_out->args_value[i] = p_in->args_value[i];
1685 app_init_pipelines(struct app_params *app)
1689 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1690 struct app_pipeline_params *params =
1691 &app->pipeline_params[p_id];
1692 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1693 struct pipeline_type *ptype;
1694 struct pipeline_params pp;
1696 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1698 ptype = app_pipeline_type_find(app, params->type);
1700 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1703 app_pipeline_params_get(app, params, &pp);
1707 if (ptype->be_ops->f_init) {
1708 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1710 if (data->be == NULL)
1711 rte_panic("Pipeline instance \"%s\" back-end "
1712 "init error\n", params->name);
1717 if (ptype->fe_ops->f_init) {
1718 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1720 if (data->fe == NULL)
1721 rte_panic("Pipeline instance \"%s\" front-end "
1722 "init error\n", params->name);
1725 data->ptype = ptype;
1727 data->timer_period = (rte_get_tsc_hz() *
1728 params->timer_period) / 100;
1733 app_post_init_pipelines(struct app_params *app)
1737 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1738 struct app_pipeline_params *params =
1739 &app->pipeline_params[p_id];
1740 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1743 if (data->ptype->fe_ops->f_post_init == NULL)
1746 status = data->ptype->fe_ops->f_post_init(data->fe);
1748 rte_panic("Pipeline instance \"%s\" front-end "
1749 "post-init error\n", params->name);
1754 app_init_threads(struct app_params *app)
1756 uint64_t time = rte_get_tsc_cycles();
1759 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1760 struct app_pipeline_params *params =
1761 &app->pipeline_params[p_id];
1762 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1763 struct pipeline_type *ptype;
1764 struct app_thread_data *t;
1765 struct app_thread_pipeline_data *p;
1768 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1771 params->hyper_th_id);
1774 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1777 (params->hyper_th_id) ? "h" : "");
1779 t = &app->thread_data[lcore_id];
1781 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1782 t->thread_req_deadline = time + t->timer_period;
1784 t->headroom_cycles = 0;
1785 t->headroom_time = rte_get_tsc_cycles();
1786 t->headroom_ratio = 0.0;
1788 t->msgq_in = app_thread_msgq_in_get(app,
1791 params->hyper_th_id);
1792 if (t->msgq_in == NULL)
1793 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1796 t->msgq_out = app_thread_msgq_out_get(app,
1799 params->hyper_th_id);
1800 if (t->msgq_out == NULL)
1801 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1804 ptype = app_pipeline_type_find(app, params->type);
1806 rte_panic("Init error: Unknown pipeline "
1807 "type \"%s\"\n", params->type);
1809 p = (ptype->be_ops->f_run == NULL) ?
1810 &t->regular[t->n_regular] :
1811 &t->custom[t->n_custom];
1813 p->pipeline_id = p_id;
1815 p->f_run = ptype->be_ops->f_run;
1816 p->f_timer = ptype->be_ops->f_timer;
1817 p->timer_period = data->timer_period;
1818 p->deadline = time + data->timer_period;
1822 if (ptype->be_ops->f_run == NULL)
1829 int app_init(struct app_params *app)
1831 app_init_core_map(app);
1832 app_init_core_mask(app);
1835 app_init_mempool(app);
1843 app_pipeline_common_cmd_push(app);
1844 app_pipeline_thread_cmd_push(app);
1845 app_pipeline_type_register(app, &pipeline_master);
1846 app_pipeline_type_register(app, &pipeline_passthrough);
1847 app_pipeline_type_register(app, &pipeline_flow_classification);
1848 app_pipeline_type_register(app, &pipeline_flow_actions);
1849 app_pipeline_type_register(app, &pipeline_firewall);
1850 app_pipeline_type_register(app, &pipeline_routing);
1852 app_init_pipelines(app);
1853 app_init_threads(app);
1858 int app_post_init(struct app_params *app)
1860 app_post_init_pipelines(app);
1866 app_pipeline_type_cmd_push(struct app_params *app,
1867 struct pipeline_type *ptype)
1869 cmdline_parse_ctx_t *cmds;
1872 /* Check input arguments */
1873 if ((app == NULL) ||
1877 n_cmds = pipeline_type_cmds_count(ptype);
1881 cmds = ptype->fe_ops->cmds;
1883 /* Check for available slots in the application commands array */
1884 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1887 /* Push pipeline commands into the application */
1888 memcpy(&app->cmds[app->n_cmds],
1890 n_cmds * sizeof(cmdline_parse_ctx_t));
1892 for (i = 0; i < n_cmds; i++)
1893 app->cmds[app->n_cmds + i]->data = app;
1895 app->n_cmds += n_cmds;
1896 app->cmds[app->n_cmds] = NULL;
1902 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1906 /* Check input arguments */
1907 if ((app == NULL) ||
1909 (ptype->name == NULL) ||
1910 (strlen(ptype->name) == 0) ||
1911 (ptype->be_ops->f_init == NULL) ||
1912 (ptype->be_ops->f_timer == NULL))
1915 /* Check for duplicate entry */
1916 for (i = 0; i < app->n_pipeline_types; i++)
1917 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1920 /* Check for resource availability */
1921 n_cmds = pipeline_type_cmds_count(ptype);
1922 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1923 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1926 /* Copy pipeline type */
1927 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1929 sizeof(struct pipeline_type));
1931 /* Copy CLI commands */
1933 app_pipeline_type_cmd_push(app, ptype);
1939 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1943 for (i = 0; i < app->n_pipeline_types; i++)
1944 if (strcmp(app->pipeline_type[i].name, name) == 0)
1945 return &app->pipeline_type[i];