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(4, 32, 4, 0);
74 if (app->core_map == NULL)
75 rte_panic("Cannot create CPU core map\n");
77 if (app->log_level >= APP_LOG_LEVEL_LOW)
78 cpu_core_map_print(app->core_map);
82 app_init_core_mask(struct app_params *app)
87 for (i = 0; i < app->n_pipelines; i++) {
88 struct app_pipeline_params *p = &app->pipeline_params[i];
91 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
97 rte_panic("Cannot create CPU core mask\n");
99 mask |= 1LLU << lcore_id;
102 app->core_mask = mask;
103 APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
107 app_init_eal(struct app_params *app)
110 struct app_eal_params *p = &app->eal_params;
115 app->eal_argv[n_args++] = strdup(app->app_name);
117 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
118 app->eal_argv[n_args++] = strdup(buffer);
121 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
122 app->eal_argv[n_args++] = strdup(buffer);
125 if (p->master_lcore_present) {
128 "--master-lcore=%" PRIu32,
130 app->eal_argv[n_args++] = strdup(buffer);
133 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
134 app->eal_argv[n_args++] = strdup(buffer);
136 if (p->memory_present) {
137 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
138 app->eal_argv[n_args++] = strdup(buffer);
141 if (p->ranks_present) {
142 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
143 app->eal_argv[n_args++] = strdup(buffer);
146 for (i = 0; i < APP_MAX_LINKS; i++) {
147 if (p->pci_blacklist[i] == NULL)
152 "--pci-blacklist=%s",
153 p->pci_blacklist[i]);
154 app->eal_argv[n_args++] = strdup(buffer);
157 if (app->port_mask != 0)
158 for (i = 0; i < APP_MAX_LINKS; i++) {
159 if (p->pci_whitelist[i] == NULL)
164 "--pci-whitelist=%s",
165 p->pci_whitelist[i]);
166 app->eal_argv[n_args++] = strdup(buffer);
169 for (i = 0; i < app->n_links; i++) {
170 char *pci_bdf = app->link_params[i].pci_bdf;
174 "--pci-whitelist=%s",
176 app->eal_argv[n_args++] = strdup(buffer);
179 for (i = 0; i < APP_MAX_LINKS; i++) {
180 if (p->vdev[i] == NULL)
187 app->eal_argv[n_args++] = strdup(buffer);
190 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
191 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
192 app->eal_argv[n_args++] = strdup(buffer);
200 app->eal_argv[n_args++] = strdup(buffer);
204 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
205 app->eal_argv[n_args++] = strdup(buffer);
208 if (p->log_level_present) {
211 "--log-level=%" PRIu32,
213 app->eal_argv[n_args++] = strdup(buffer);
216 if ((p->version_present) && p->version) {
217 snprintf(buffer, sizeof(buffer), "-v");
218 app->eal_argv[n_args++] = strdup(buffer);
221 if ((p->help_present) && p->help) {
222 snprintf(buffer, sizeof(buffer), "--help");
223 app->eal_argv[n_args++] = strdup(buffer);
226 if ((p->no_huge_present) && p->no_huge) {
227 snprintf(buffer, sizeof(buffer), "--no-huge");
228 app->eal_argv[n_args++] = strdup(buffer);
231 if ((p->no_pci_present) && p->no_pci) {
232 snprintf(buffer, sizeof(buffer), "--no-pci");
233 app->eal_argv[n_args++] = strdup(buffer);
236 if ((p->no_hpet_present) && p->no_hpet) {
237 snprintf(buffer, sizeof(buffer), "--no-hpet");
238 app->eal_argv[n_args++] = strdup(buffer);
241 if ((p->no_shconf_present) && p->no_shconf) {
242 snprintf(buffer, sizeof(buffer), "--no-shconf");
243 app->eal_argv[n_args++] = strdup(buffer);
247 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
248 app->eal_argv[n_args++] = strdup(buffer);
256 app->eal_argv[n_args++] = strdup(buffer);
260 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
261 app->eal_argv[n_args++] = strdup(buffer);
264 if (p->file_prefix) {
269 app->eal_argv[n_args++] = strdup(buffer);
272 if (p->base_virtaddr) {
275 "--base-virtaddr=%s",
277 app->eal_argv[n_args++] = strdup(buffer);
280 if ((p->create_uio_dev_present) && p->create_uio_dev) {
281 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
282 app->eal_argv[n_args++] = strdup(buffer);
290 app->eal_argv[n_args++] = strdup(buffer);
293 if ((p->xen_dom0_present) && (p->xen_dom0)) {
294 snprintf(buffer, sizeof(buffer), "--xen-dom0");
295 app->eal_argv[n_args++] = strdup(buffer);
298 snprintf(buffer, sizeof(buffer), "--");
299 app->eal_argv[n_args++] = strdup(buffer);
301 app->eal_argc = n_args;
303 APP_LOG(app, HIGH, "Initializing EAL ...");
304 if (app->log_level >= APP_LOG_LEVEL_LOW) {
307 fprintf(stdout, "[APP] EAL arguments: \"");
308 for (i = 1; i < app->eal_argc; i++)
309 fprintf(stdout, "%s ", app->eal_argv[i]);
310 fprintf(stdout, "\"\n");
313 status = rte_eal_init(app->eal_argc, app->eal_argv);
315 rte_panic("EAL init error\n");
319 app_init_mempool(struct app_params *app)
323 for (i = 0; i < app->n_mempools; i++) {
324 struct app_mempool_params *p = &app->mempool_params[i];
326 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
327 app->mempool[i] = rte_mempool_create(
332 sizeof(struct rte_pktmbuf_pool_private),
333 rte_pktmbuf_pool_init, NULL,
334 rte_pktmbuf_init, NULL,
338 if (app->mempool[i] == NULL)
339 rte_panic("%s init error\n", p->name);
344 app_link_filter_arp_add(struct app_link_params *link)
346 struct rte_eth_ethertype_filter filter = {
347 .ether_type = ETHER_TYPE_ARP,
349 .queue = link->arp_q,
352 return rte_eth_dev_filter_ctrl(link->pmd_id,
353 RTE_ETH_FILTER_ETHERTYPE,
359 app_link_filter_tcp_syn_add(struct app_link_params *link)
361 struct rte_eth_syn_filter filter = {
363 .queue = link->tcp_syn_q,
366 return rte_eth_dev_filter_ctrl(link->pmd_id,
373 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
375 struct rte_eth_ntuple_filter filter = {
376 .flags = RTE_5TUPLE_FLAGS,
377 .dst_ip = rte_bswap32(l2->ip),
378 .dst_ip_mask = UINT32_MAX, /* Enable */
380 .src_ip_mask = 0, /* Disable */
382 .dst_port_mask = 0, /* Disable */
384 .src_port_mask = 0, /* Disable */
386 .proto_mask = 0, /* Disable */
388 .priority = 1, /* Lowest */
389 .queue = l1->ip_local_q,
392 return rte_eth_dev_filter_ctrl(l1->pmd_id,
393 RTE_ETH_FILTER_NTUPLE,
399 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
401 struct rte_eth_ntuple_filter filter = {
402 .flags = RTE_5TUPLE_FLAGS,
403 .dst_ip = rte_bswap32(l2->ip),
404 .dst_ip_mask = UINT32_MAX, /* Enable */
406 .src_ip_mask = 0, /* Disable */
408 .dst_port_mask = 0, /* Disable */
410 .src_port_mask = 0, /* Disable */
412 .proto_mask = 0, /* Disable */
414 .priority = 1, /* Lowest */
415 .queue = l1->ip_local_q,
418 return rte_eth_dev_filter_ctrl(l1->pmd_id,
419 RTE_ETH_FILTER_NTUPLE,
420 RTE_ETH_FILTER_DELETE,
425 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
427 struct rte_eth_ntuple_filter filter = {
428 .flags = RTE_5TUPLE_FLAGS,
429 .dst_ip = rte_bswap32(l2->ip),
430 .dst_ip_mask = UINT32_MAX, /* Enable */
432 .src_ip_mask = 0, /* Disable */
434 .dst_port_mask = 0, /* Disable */
436 .src_port_mask = 0, /* Disable */
437 .proto = IPPROTO_TCP,
438 .proto_mask = UINT8_MAX, /* Enable */
440 .priority = 2, /* Higher priority than IP */
441 .queue = l1->tcp_local_q,
444 return rte_eth_dev_filter_ctrl(l1->pmd_id,
445 RTE_ETH_FILTER_NTUPLE,
451 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
453 struct rte_eth_ntuple_filter filter = {
454 .flags = RTE_5TUPLE_FLAGS,
455 .dst_ip = rte_bswap32(l2->ip),
456 .dst_ip_mask = UINT32_MAX, /* Enable */
458 .src_ip_mask = 0, /* Disable */
460 .dst_port_mask = 0, /* Disable */
462 .src_port_mask = 0, /* Disable */
463 .proto = IPPROTO_TCP,
464 .proto_mask = UINT8_MAX, /* Enable */
466 .priority = 2, /* Higher priority than IP */
467 .queue = l1->tcp_local_q,
470 return rte_eth_dev_filter_ctrl(l1->pmd_id,
471 RTE_ETH_FILTER_NTUPLE,
472 RTE_ETH_FILTER_DELETE,
477 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
479 struct rte_eth_ntuple_filter filter = {
480 .flags = RTE_5TUPLE_FLAGS,
481 .dst_ip = rte_bswap32(l2->ip),
482 .dst_ip_mask = UINT32_MAX, /* Enable */
484 .src_ip_mask = 0, /* Disable */
486 .dst_port_mask = 0, /* Disable */
488 .src_port_mask = 0, /* Disable */
489 .proto = IPPROTO_UDP,
490 .proto_mask = UINT8_MAX, /* Enable */
492 .priority = 2, /* Higher priority than IP */
493 .queue = l1->udp_local_q,
496 return rte_eth_dev_filter_ctrl(l1->pmd_id,
497 RTE_ETH_FILTER_NTUPLE,
503 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
505 struct rte_eth_ntuple_filter filter = {
506 .flags = RTE_5TUPLE_FLAGS,
507 .dst_ip = rte_bswap32(l2->ip),
508 .dst_ip_mask = UINT32_MAX, /* Enable */
510 .src_ip_mask = 0, /* Disable */
512 .dst_port_mask = 0, /* Disable */
514 .src_port_mask = 0, /* Disable */
515 .proto = IPPROTO_UDP,
516 .proto_mask = UINT8_MAX, /* Enable */
518 .priority = 2, /* Higher priority than IP */
519 .queue = l1->udp_local_q,
522 return rte_eth_dev_filter_ctrl(l1->pmd_id,
523 RTE_ETH_FILTER_NTUPLE,
524 RTE_ETH_FILTER_DELETE,
529 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
531 struct rte_eth_ntuple_filter filter = {
532 .flags = RTE_5TUPLE_FLAGS,
533 .dst_ip = rte_bswap32(l2->ip),
534 .dst_ip_mask = UINT32_MAX, /* Enable */
536 .src_ip_mask = 0, /* Disable */
538 .dst_port_mask = 0, /* Disable */
540 .src_port_mask = 0, /* Disable */
541 .proto = IPPROTO_SCTP,
542 .proto_mask = UINT8_MAX, /* Enable */
544 .priority = 2, /* Higher priority than IP */
545 .queue = l1->sctp_local_q,
548 return rte_eth_dev_filter_ctrl(l1->pmd_id,
549 RTE_ETH_FILTER_NTUPLE,
555 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
557 struct rte_eth_ntuple_filter filter = {
558 .flags = RTE_5TUPLE_FLAGS,
559 .dst_ip = rte_bswap32(l2->ip),
560 .dst_ip_mask = UINT32_MAX, /* Enable */
562 .src_ip_mask = 0, /* Disable */
564 .dst_port_mask = 0, /* Disable */
566 .src_port_mask = 0, /* Disable */
567 .proto = IPPROTO_SCTP,
568 .proto_mask = UINT8_MAX, /* Enable */
570 .priority = 2, /* Higher priority than IP */
571 .queue = l1->sctp_local_q,
574 return rte_eth_dev_filter_ctrl(l1->pmd_id,
575 RTE_ETH_FILTER_NTUPLE,
576 RTE_ETH_FILTER_DELETE,
581 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
583 if (cp->arp_q != 0) {
584 int status = app_link_filter_arp_add(cp);
586 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
587 "Adding ARP filter (queue = %" PRIu32 ")",
588 cp->name, cp->pmd_id, cp->arp_q);
591 rte_panic("%s (%" PRIu32 "): "
592 "Error adding ARP filter "
593 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
594 cp->name, cp->pmd_id, cp->arp_q, status);
599 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
601 if (cp->tcp_syn_q != 0) {
602 int status = app_link_filter_tcp_syn_add(cp);
604 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
605 "Adding TCP SYN filter (queue = %" PRIu32 ")",
606 cp->name, cp->pmd_id, cp->tcp_syn_q);
609 rte_panic("%s (%" PRIu32 "): "
610 "Error adding TCP SYN filter "
611 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
612 cp->name, cp->pmd_id, cp->tcp_syn_q,
618 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
623 /* For each link, add filters for IP of current link */
625 for (i = 0; i < app->n_links; i++) {
626 struct app_link_params *p = &app->link_params[i];
629 if (p->ip_local_q != 0) {
630 int status = app_link_filter_ip_add(p, cp);
632 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
633 "Adding IP filter (queue= %" PRIu32
634 ", IP = 0x%08" PRIx32 ")",
635 p->name, p->pmd_id, p->ip_local_q,
639 rte_panic("%s (%" PRIu32 "): "
641 "filter (queue= %" PRIu32 ", "
645 p->ip_local_q, cp->ip, status);
649 if (p->tcp_local_q != 0) {
650 int status = app_link_filter_tcp_add(p, cp);
652 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
655 ", IP = 0x%08" PRIx32 ")",
656 p->name, p->pmd_id, p->tcp_local_q,
660 rte_panic("%s (%" PRIu32 "): "
662 "filter (queue = %" PRIu32 ", "
666 p->tcp_local_q, cp->ip, status);
670 if (p->udp_local_q != 0) {
671 int status = app_link_filter_udp_add(p, cp);
673 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
676 ", IP = 0x%08" PRIx32 ")",
677 p->name, p->pmd_id, p->udp_local_q,
681 rte_panic("%s (%" PRIu32 "): "
683 "filter (queue = %" PRIu32 ", "
687 p->udp_local_q, cp->ip, status);
691 if (p->sctp_local_q != 0) {
692 int status = app_link_filter_sctp_add(p, cp);
694 APP_LOG(app, LOW, "%s (%" PRIu32
695 "): Adding SCTP filter "
697 ", IP = 0x%08" PRIx32 ")",
698 p->name, p->pmd_id, p->sctp_local_q,
702 rte_panic("%s (%" PRIu32 "): "
704 "filter (queue = %" PRIu32 ", "
708 p->sctp_local_q, cp->ip,
715 status = rte_eth_dev_set_link_up(cp->pmd_id);
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);
733 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
734 PRId32 "\n", cp->name, cp->pmd_id, status);
736 /* Mark link as DOWN */
739 /* Return if current link IP is not valid */
743 /* For each link, remove filters for IP of current link */
744 for (i = 0; i < app->n_links; i++) {
745 struct app_link_params *p = &app->link_params[i];
748 if (p->ip_local_q != 0) {
749 int status = app_link_filter_ip_del(p, cp);
751 APP_LOG(app, LOW, "%s (%" PRIu32
752 "): Deleting IP filter "
753 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
754 p->name, p->pmd_id, p->ip_local_q, cp->ip);
757 rte_panic("%s (%" PRIu32
758 "): Error deleting IP filter "
762 p->name, p->pmd_id, p->ip_local_q,
767 if (p->tcp_local_q != 0) {
768 int status = app_link_filter_tcp_del(p, cp);
770 APP_LOG(app, LOW, "%s (%" PRIu32
771 "): Deleting TCP filter "
773 ", IP = 0x%" PRIx32 ")",
774 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
777 rte_panic("%s (%" PRIu32
778 "): Error deleting TCP filter "
782 p->name, p->pmd_id, p->tcp_local_q,
787 if (p->udp_local_q != 0) {
788 int status = app_link_filter_udp_del(p, cp);
790 APP_LOG(app, LOW, "%s (%" PRIu32
791 "): Deleting UDP filter "
792 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
793 p->name, p->pmd_id, p->udp_local_q, cp->ip);
796 rte_panic("%s (%" PRIu32
797 "): Error deleting UDP filter "
801 p->name, p->pmd_id, p->udp_local_q,
806 if (p->sctp_local_q != 0) {
807 int status = app_link_filter_sctp_del(p, cp);
809 APP_LOG(app, LOW, "%s (%" PRIu32
810 "): Deleting SCTP filter "
812 ", IP = 0x%" PRIx32 ")",
813 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
816 rte_panic("%s (%" PRIu32
817 "): Error deleting SCTP filter "
821 p->name, p->pmd_id, p->sctp_local_q,
828 app_check_link(struct app_params *app)
830 uint32_t all_links_up, i;
834 for (i = 0; i < app->n_links; i++) {
835 struct app_link_params *p = &app->link_params[i];
836 struct rte_eth_link link_params;
838 memset(&link_params, 0, sizeof(link_params));
839 rte_eth_link_get(p->pmd_id, &link_params);
841 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
844 link_params.link_speed / 1000,
845 link_params.link_status ? "UP" : "DOWN");
847 if (link_params.link_status == ETH_LINK_DOWN)
851 if (all_links_up == 0)
852 rte_panic("Some links are DOWN\n");
856 is_any_swq_frag_or_ras(struct app_params *app)
860 for (i = 0; i < app->n_pktq_swq; i++) {
861 struct app_pktq_swq_params *p = &app->swq_params[i];
863 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
864 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
872 app_init_link_frag_ras(struct app_params *app)
876 if (is_any_swq_frag_or_ras(app)) {
877 for (i = 0; i < app->n_pktq_hwq_out; i++) {
878 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
880 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
886 app_get_cpu_socket_id(uint32_t pmd_id)
888 int status = rte_eth_dev_socket_id(pmd_id);
890 return (status != SOCKET_ID_ANY) ? status : 0;
894 app_link_rss_enabled(struct app_link_params *cp)
896 return (cp->n_rss_qs) ? 1 : 0;
900 app_link_rss_setup(struct app_link_params *cp)
902 struct rte_eth_dev_info dev_info;
903 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
908 memset(&dev_info, 0, sizeof(dev_info));
909 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
911 if (dev_info.reta_size == 0)
912 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
913 cp->name, cp->pmd_id);
915 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
916 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
917 cp->name, cp->pmd_id);
919 /* Setup RETA contents */
920 memset(reta_conf, 0, sizeof(reta_conf));
922 for (i = 0; i < dev_info.reta_size; i++)
923 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
925 for (i = 0; i < dev_info.reta_size; i++) {
926 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
927 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
928 uint32_t rss_qs_pos = i % cp->n_rss_qs;
930 reta_conf[reta_id].reta[reta_pos] =
931 (uint16_t) cp->rss_qs[rss_qs_pos];
935 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
939 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
940 cp->name, cp->pmd_id);
944 app_init_link_set_config(struct app_link_params *p)
947 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
948 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
955 app_init_link(struct app_params *app)
959 app_init_link_frag_ras(app);
961 for (i = 0; i < app->n_links; i++) {
962 struct app_link_params *p_link = &app->link_params[i];
963 uint32_t link_id, n_hwq_in, n_hwq_out, j;
966 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
967 n_hwq_in = app_link_get_n_rxq(app, p_link);
968 n_hwq_out = app_link_get_n_txq(app, p_link);
969 app_init_link_set_config(p_link);
971 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
972 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
979 status = rte_eth_dev_configure(
985 rte_panic("%s (%" PRId32 "): "
986 "init error (%" PRId32 ")\n",
987 p_link->name, p_link->pmd_id, status);
989 rte_eth_macaddr_get(p_link->pmd_id,
990 (struct ether_addr *) &p_link->mac_addr);
993 rte_eth_promiscuous_enable(p_link->pmd_id);
996 for (j = 0; j < app->n_pktq_hwq_in; j++) {
997 struct app_pktq_hwq_in_params *p_rxq =
998 &app->hwq_in_params[j];
999 uint32_t rxq_link_id, rxq_queue_id;
1001 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
1002 &rxq_link_id, &rxq_queue_id);
1003 if (rxq_link_id != link_id)
1006 status = rte_eth_rx_queue_setup(
1010 app_get_cpu_socket_id(p_link->pmd_id),
1012 app->mempool[p_rxq->mempool_id]);
1014 rte_panic("%s (%" PRIu32 "): "
1015 "%s init error (%" PRId32 ")\n",
1023 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1024 struct app_pktq_hwq_out_params *p_txq =
1025 &app->hwq_out_params[j];
1026 uint32_t txq_link_id, txq_queue_id;
1028 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1029 &txq_link_id, &txq_queue_id);
1030 if (txq_link_id != link_id)
1033 status = rte_eth_tx_queue_setup(
1037 app_get_cpu_socket_id(p_link->pmd_id),
1040 rte_panic("%s (%" PRIu32 "): "
1041 "%s init error (%" PRId32 ")\n",
1049 status = rte_eth_dev_start(p_link->pmd_id);
1051 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1052 p_link->name, status);
1055 app_link_set_arp_filter(app, p_link);
1056 app_link_set_tcp_syn_filter(app, p_link);
1057 if (app_link_rss_enabled(p_link))
1058 app_link_rss_setup(p_link);
1061 app_link_up_internal(app, p_link);
1064 app_check_link(app);
1068 app_init_swq(struct app_params *app)
1072 for (i = 0; i < app->n_pktq_swq; i++) {
1073 struct app_pktq_swq_params *p = &app->swq_params[i];
1076 if (app_swq_get_readers(app, p) == 1)
1077 flags |= RING_F_SC_DEQ;
1078 if (app_swq_get_writers(app, p) == 1)
1079 flags |= RING_F_SP_ENQ;
1081 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1082 app->swq[i] = rte_ring_create(
1088 if (app->swq[i] == NULL)
1089 rte_panic("%s init error\n", p->name);
1094 app_init_tm(struct app_params *app)
1098 for (i = 0; i < app->n_pktq_tm; i++) {
1099 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1100 struct app_link_params *p_link;
1101 struct rte_eth_link link_eth_params;
1102 struct rte_sched_port *sched;
1103 uint32_t n_subports, subport_id;
1106 p_link = app_get_link_for_tm(app, p_tm);
1108 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1111 p_tm->sched_port_params.name = p_tm->name;
1112 p_tm->sched_port_params.socket =
1113 app_get_cpu_socket_id(p_link->pmd_id);
1114 p_tm->sched_port_params.rate =
1115 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1117 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1118 sched = rte_sched_port_config(&p_tm->sched_port_params);
1120 rte_panic("%s init error\n", p_tm->name);
1124 n_subports = p_tm->sched_port_params.n_subports_per_port;
1125 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1126 uint32_t n_pipes_per_subport, pipe_id;
1128 status = rte_sched_subport_config(sched,
1130 &p_tm->sched_subport_params[subport_id]);
1132 rte_panic("%s subport %" PRIu32
1133 " init error (%" PRId32 ")\n",
1134 p_tm->name, subport_id, status);
1137 n_pipes_per_subport =
1138 p_tm->sched_port_params.n_pipes_per_subport;
1140 pipe_id < n_pipes_per_subport;
1142 int profile_id = p_tm->sched_pipe_to_profile[
1143 subport_id * APP_MAX_SCHED_PIPES +
1146 if (profile_id == -1)
1149 status = rte_sched_pipe_config(sched,
1154 rte_panic("%s subport %" PRIu32
1156 " (profile %" PRId32 ") "
1157 "init error (% " PRId32 ")\n",
1158 p_tm->name, subport_id, pipe_id,
1159 profile_id, status);
1165 #ifndef RTE_EXEC_ENV_LINUXAPP
1167 app_init_tap(struct app_params *app) {
1168 if (app->n_pktq_tap == 0)
1171 rte_panic("TAP device not supported.\n");
1175 app_init_tap(struct app_params *app)
1179 for (i = 0; i < app->n_pktq_tap; i++) {
1180 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1184 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1186 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1188 rte_panic("Cannot open file /dev/net/tun\n");
1190 memset(&ifr, 0, sizeof(ifr));
1191 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1192 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1194 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1196 rte_panic("TAP setup error\n");
1203 #ifdef RTE_LIBRTE_KNI
1205 kni_config_network_interface(uint8_t port_id, uint8_t if_up) {
1208 if (port_id >= rte_eth_dev_count())
1212 rte_eth_dev_set_link_up(port_id) :
1213 rte_eth_dev_set_link_down(port_id);
1219 kni_change_mtu(uint8_t port_id, unsigned new_mtu) {
1222 if (port_id >= rte_eth_dev_count())
1225 if (new_mtu > ETHER_MAX_LEN)
1229 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1235 #endif /* RTE_LIBRTE_KNI */
1237 #ifndef RTE_LIBRTE_KNI
1239 app_init_kni(struct app_params *app) {
1240 if (app->n_pktq_kni == 0)
1243 rte_panic("Can not init KNI without librte_kni support.\n");
1247 app_init_kni(struct app_params *app) {
1250 if (app->n_pktq_kni == 0)
1253 rte_kni_init(app->n_pktq_kni);
1255 for (i = 0; i < app->n_pktq_kni; i++) {
1256 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1257 struct app_link_params *p_link;
1258 struct rte_eth_dev_info dev_info;
1259 struct app_mempool_params *mempool_params;
1260 struct rte_mempool *mempool;
1261 struct rte_kni_conf conf;
1262 struct rte_kni_ops ops;
1265 p_link = app_get_link_for_kni(app, p_kni);
1266 memset(&dev_info, 0, sizeof(dev_info));
1267 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1270 mempool_params = &app->mempool_params[p_kni->mempool_id];
1271 mempool = app->mempool[p_kni->mempool_id];
1274 memset(&conf, 0, sizeof(conf));
1275 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1276 conf.force_bind = p_kni->force_bind;
1277 if (conf.force_bind) {
1280 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1283 p_kni->hyper_th_id);
1286 rte_panic("%s invalid CPU core\n", p_kni->name);
1288 conf.core_id = (uint32_t) lcore_id;
1290 conf.group_id = p_link->pmd_id;
1291 conf.mbuf_size = mempool_params->buffer_size;
1292 conf.addr = dev_info.pci_dev->addr;
1293 conf.id = dev_info.pci_dev->id;
1295 memset(&ops, 0, sizeof(ops));
1296 ops.port_id = (uint8_t) p_link->pmd_id;
1297 ops.change_mtu = kni_change_mtu;
1298 ops.config_network_if = kni_config_network_interface;
1300 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1301 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1303 rte_panic("%s init error\n", p_kni->name);
1306 #endif /* RTE_LIBRTE_KNI */
1309 app_init_msgq(struct app_params *app)
1313 for (i = 0; i < app->n_msgq; i++) {
1314 struct app_msgq_params *p = &app->msgq_params[i];
1316 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1317 app->msgq[i] = rte_ring_create(
1321 RING_F_SP_ENQ | RING_F_SC_DEQ);
1323 if (app->msgq[i] == NULL)
1324 rte_panic("%s init error\n", p->name);
1328 void app_pipeline_params_get(struct app_params *app,
1329 struct app_pipeline_params *p_in,
1330 struct pipeline_params *p_out)
1334 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1336 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1338 p_out->socket_id = (int) p_in->socket_id;
1340 p_out->log_level = app->log_level;
1343 p_out->n_ports_in = p_in->n_pktq_in;
1344 for (i = 0; i < p_in->n_pktq_in; i++) {
1345 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1346 struct pipeline_port_in_params *out = &p_out->port_in[i];
1349 case APP_PKTQ_IN_HWQ:
1351 struct app_pktq_hwq_in_params *p_hwq_in =
1352 &app->hwq_in_params[in->id];
1353 struct app_link_params *p_link =
1354 app_get_link_for_rxq(app, p_hwq_in);
1355 uint32_t rxq_link_id, rxq_queue_id;
1357 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1361 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1362 out->params.ethdev.port_id = p_link->pmd_id;
1363 out->params.ethdev.queue_id = rxq_queue_id;
1364 out->burst_size = p_hwq_in->burst;
1367 case APP_PKTQ_IN_SWQ:
1369 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1371 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1372 if (app_swq_get_readers(app, swq_params) == 1) {
1373 out->type = PIPELINE_PORT_IN_RING_READER;
1374 out->params.ring.ring = app->swq[in->id];
1375 out->burst_size = app->swq_params[in->id].burst_read;
1377 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1378 out->params.ring_multi.ring = app->swq[in->id];
1379 out->burst_size = swq_params->burst_read;
1382 if (swq_params->ipv4_frag == 1) {
1383 struct rte_port_ring_reader_ipv4_frag_params *params =
1384 &out->params.ring_ipv4_frag;
1386 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1387 params->ring = app->swq[in->id];
1388 params->mtu = swq_params->mtu;
1389 params->metadata_size = swq_params->metadata_size;
1390 params->pool_direct =
1391 app->mempool[swq_params->mempool_direct_id];
1392 params->pool_indirect =
1393 app->mempool[swq_params->mempool_indirect_id];
1394 out->burst_size = swq_params->burst_read;
1396 struct rte_port_ring_reader_ipv6_frag_params *params =
1397 &out->params.ring_ipv6_frag;
1399 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1400 params->ring = app->swq[in->id];
1401 params->mtu = swq_params->mtu;
1402 params->metadata_size = swq_params->metadata_size;
1403 params->pool_direct =
1404 app->mempool[swq_params->mempool_direct_id];
1405 params->pool_indirect =
1406 app->mempool[swq_params->mempool_indirect_id];
1407 out->burst_size = swq_params->burst_read;
1412 case APP_PKTQ_IN_TM:
1414 out->type = PIPELINE_PORT_IN_SCHED_READER;
1415 out->params.sched.sched = app->tm[in->id];
1416 out->burst_size = app->tm_params[in->id].burst_read;
1419 #ifdef RTE_EXEC_ENV_LINUXAPP
1420 case APP_PKTQ_IN_TAP:
1422 struct app_pktq_tap_params *tap_params =
1423 &app->tap_params[in->id];
1424 struct app_mempool_params *mempool_params =
1425 &app->mempool_params[tap_params->mempool_id];
1426 struct rte_mempool *mempool =
1427 app->mempool[tap_params->mempool_id];
1429 out->type = PIPELINE_PORT_IN_FD_READER;
1430 out->params.fd.fd = app->tap[in->id];
1431 out->params.fd.mtu = mempool_params->buffer_size;
1432 out->params.fd.mempool = mempool;
1433 out->burst_size = app->tap_params[in->id].burst_read;
1437 #ifdef RTE_LIBRTE_KNI
1438 case APP_PKTQ_IN_KNI:
1440 out->type = PIPELINE_PORT_IN_KNI_READER;
1441 out->params.kni.kni = app->kni[in->id];
1442 out->burst_size = app->kni_params[in->id].burst_read;
1445 #endif /* RTE_LIBRTE_KNI */
1446 case APP_PKTQ_IN_SOURCE:
1448 uint32_t mempool_id =
1449 app->source_params[in->id].mempool_id;
1451 out->type = PIPELINE_PORT_IN_SOURCE;
1452 out->params.source.mempool = app->mempool[mempool_id];
1453 out->burst_size = app->source_params[in->id].burst;
1454 out->params.source.file_name =
1455 app->source_params[in->id].file_name;
1456 out->params.source.n_bytes_per_pkt =
1457 app->source_params[in->id].n_bytes_per_pkt;
1466 p_out->n_ports_out = p_in->n_pktq_out;
1467 for (i = 0; i < p_in->n_pktq_out; i++) {
1468 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1469 struct pipeline_port_out_params *out = &p_out->port_out[i];
1472 case APP_PKTQ_OUT_HWQ:
1474 struct app_pktq_hwq_out_params *p_hwq_out =
1475 &app->hwq_out_params[in->id];
1476 struct app_link_params *p_link =
1477 app_get_link_for_txq(app, p_hwq_out);
1478 uint32_t txq_link_id, txq_queue_id;
1480 sscanf(p_hwq_out->name,
1481 "TXQ%" SCNu32 ".%" SCNu32,
1485 if (p_hwq_out->dropless == 0) {
1486 struct rte_port_ethdev_writer_params *params =
1487 &out->params.ethdev;
1489 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1490 params->port_id = p_link->pmd_id;
1491 params->queue_id = txq_queue_id;
1492 params->tx_burst_sz =
1493 app->hwq_out_params[in->id].burst;
1495 struct rte_port_ethdev_writer_nodrop_params
1496 *params = &out->params.ethdev_nodrop;
1499 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1500 params->port_id = p_link->pmd_id;
1501 params->queue_id = txq_queue_id;
1502 params->tx_burst_sz = p_hwq_out->burst;
1503 params->n_retries = p_hwq_out->n_retries;
1507 case APP_PKTQ_OUT_SWQ:
1509 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1511 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1512 if (app_swq_get_writers(app, swq_params) == 1) {
1513 if (app->swq_params[in->id].dropless == 0) {
1514 struct rte_port_ring_writer_params *params =
1517 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1518 params->ring = app->swq[in->id];
1519 params->tx_burst_sz =
1520 app->swq_params[in->id].burst_write;
1522 struct rte_port_ring_writer_nodrop_params
1523 *params = &out->params.ring_nodrop;
1526 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1527 params->ring = app->swq[in->id];
1528 params->tx_burst_sz =
1529 app->swq_params[in->id].burst_write;
1531 app->swq_params[in->id].n_retries;
1534 if (swq_params->dropless == 0) {
1535 struct rte_port_ring_multi_writer_params *params =
1536 &out->params.ring_multi;
1538 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1539 params->ring = app->swq[in->id];
1540 params->tx_burst_sz = swq_params->burst_write;
1542 struct rte_port_ring_multi_writer_nodrop_params
1543 *params = &out->params.ring_multi_nodrop;
1545 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1546 params->ring = app->swq[in->id];
1547 params->tx_burst_sz = swq_params->burst_write;
1548 params->n_retries = swq_params->n_retries;
1552 if (swq_params->ipv4_ras == 1) {
1553 struct rte_port_ring_writer_ipv4_ras_params *params =
1554 &out->params.ring_ipv4_ras;
1556 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1557 params->ring = app->swq[in->id];
1558 params->tx_burst_sz = swq_params->burst_write;
1560 struct rte_port_ring_writer_ipv6_ras_params *params =
1561 &out->params.ring_ipv6_ras;
1563 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1564 params->ring = app->swq[in->id];
1565 params->tx_burst_sz = swq_params->burst_write;
1570 case APP_PKTQ_OUT_TM:
1572 struct rte_port_sched_writer_params *params =
1575 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1576 params->sched = app->tm[in->id];
1577 params->tx_burst_sz =
1578 app->tm_params[in->id].burst_write;
1581 #ifdef RTE_EXEC_ENV_LINUXAPP
1582 case APP_PKTQ_OUT_TAP:
1584 struct rte_port_fd_writer_params *params =
1587 out->type = PIPELINE_PORT_OUT_FD_WRITER;
1588 params->fd = app->tap[in->id];
1589 params->tx_burst_sz =
1590 app->tap_params[in->id].burst_write;
1594 #ifdef RTE_LIBRTE_KNI
1595 case APP_PKTQ_OUT_KNI:
1597 struct app_pktq_kni_params *p_kni =
1598 &app->kni_params[in->id];
1600 if (p_kni->dropless == 0) {
1601 struct rte_port_kni_writer_params *params =
1604 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1605 params->kni = app->kni[in->id];
1606 params->tx_burst_sz =
1607 app->kni_params[in->id].burst_write;
1609 struct rte_port_kni_writer_nodrop_params
1610 *params = &out->params.kni_nodrop;
1612 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1613 params->kni = app->kni[in->id];
1614 params->tx_burst_sz =
1615 app->kni_params[in->id].burst_write;
1617 app->kni_params[in->id].n_retries;
1621 #endif /* RTE_LIBRTE_KNI */
1622 case APP_PKTQ_OUT_SINK:
1624 out->type = PIPELINE_PORT_OUT_SINK;
1625 out->params.sink.file_name =
1626 app->sink_params[in->id].file_name;
1627 out->params.sink.max_n_pkts =
1628 app->sink_params[in->id].
1639 p_out->n_msgq = p_in->n_msgq_in;
1641 for (i = 0; i < p_in->n_msgq_in; i++)
1642 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1644 for (i = 0; i < p_in->n_msgq_out; i++)
1645 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1648 p_out->n_args = p_in->n_args;
1649 for (i = 0; i < p_in->n_args; i++) {
1650 p_out->args_name[i] = p_in->args_name[i];
1651 p_out->args_value[i] = p_in->args_value[i];
1656 app_init_pipelines(struct app_params *app)
1660 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1661 struct app_pipeline_params *params =
1662 &app->pipeline_params[p_id];
1663 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1664 struct pipeline_type *ptype;
1665 struct pipeline_params pp;
1667 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1669 ptype = app_pipeline_type_find(app, params->type);
1671 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1674 app_pipeline_params_get(app, params, &pp);
1678 if (ptype->be_ops->f_init) {
1679 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1681 if (data->be == NULL)
1682 rte_panic("Pipeline instance \"%s\" back-end "
1683 "init error\n", params->name);
1688 if (ptype->fe_ops->f_init) {
1689 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1691 if (data->fe == NULL)
1692 rte_panic("Pipeline instance \"%s\" front-end "
1693 "init error\n", params->name);
1696 data->ptype = ptype;
1698 data->timer_period = (rte_get_tsc_hz() *
1699 params->timer_period) / 100;
1704 app_post_init_pipelines(struct app_params *app)
1708 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1709 struct app_pipeline_params *params =
1710 &app->pipeline_params[p_id];
1711 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1714 if (data->ptype->fe_ops->f_post_init == NULL)
1717 status = data->ptype->fe_ops->f_post_init(data->fe);
1719 rte_panic("Pipeline instance \"%s\" front-end "
1720 "post-init error\n", params->name);
1725 app_init_threads(struct app_params *app)
1727 uint64_t time = rte_get_tsc_cycles();
1730 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1731 struct app_pipeline_params *params =
1732 &app->pipeline_params[p_id];
1733 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1734 struct pipeline_type *ptype;
1735 struct app_thread_data *t;
1736 struct app_thread_pipeline_data *p;
1739 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1742 params->hyper_th_id);
1745 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1748 (params->hyper_th_id) ? "h" : "");
1750 t = &app->thread_data[lcore_id];
1752 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1753 t->thread_req_deadline = time + t->timer_period;
1755 t->headroom_cycles = 0;
1756 t->headroom_time = rte_get_tsc_cycles();
1757 t->headroom_ratio = 0.0;
1759 t->msgq_in = app_thread_msgq_in_get(app,
1762 params->hyper_th_id);
1763 if (t->msgq_in == NULL)
1764 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1767 t->msgq_out = app_thread_msgq_out_get(app,
1770 params->hyper_th_id);
1771 if (t->msgq_out == NULL)
1772 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1775 ptype = app_pipeline_type_find(app, params->type);
1777 rte_panic("Init error: Unknown pipeline "
1778 "type \"%s\"\n", params->type);
1780 p = (ptype->be_ops->f_run == NULL) ?
1781 &t->regular[t->n_regular] :
1782 &t->custom[t->n_custom];
1784 p->pipeline_id = p_id;
1786 p->f_run = ptype->be_ops->f_run;
1787 p->f_timer = ptype->be_ops->f_timer;
1788 p->timer_period = data->timer_period;
1789 p->deadline = time + data->timer_period;
1793 if (ptype->be_ops->f_run == NULL)
1800 int app_init(struct app_params *app)
1802 app_init_core_map(app);
1803 app_init_core_mask(app);
1806 app_init_mempool(app);
1814 app_pipeline_common_cmd_push(app);
1815 app_pipeline_thread_cmd_push(app);
1816 app_pipeline_type_register(app, &pipeline_master);
1817 app_pipeline_type_register(app, &pipeline_passthrough);
1818 app_pipeline_type_register(app, &pipeline_flow_classification);
1819 app_pipeline_type_register(app, &pipeline_flow_actions);
1820 app_pipeline_type_register(app, &pipeline_firewall);
1821 app_pipeline_type_register(app, &pipeline_routing);
1823 app_init_pipelines(app);
1824 app_init_threads(app);
1829 int app_post_init(struct app_params *app)
1831 app_post_init_pipelines(app);
1837 app_pipeline_type_cmd_push(struct app_params *app,
1838 struct pipeline_type *ptype)
1840 cmdline_parse_ctx_t *cmds;
1843 /* Check input arguments */
1844 if ((app == NULL) ||
1848 n_cmds = pipeline_type_cmds_count(ptype);
1852 cmds = ptype->fe_ops->cmds;
1854 /* Check for available slots in the application commands array */
1855 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1858 /* Push pipeline commands into the application */
1859 memcpy(&app->cmds[app->n_cmds],
1861 n_cmds * sizeof(cmdline_parse_ctx_t));
1863 for (i = 0; i < n_cmds; i++)
1864 app->cmds[app->n_cmds + i]->data = app;
1866 app->n_cmds += n_cmds;
1867 app->cmds[app->n_cmds] = NULL;
1873 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1877 /* Check input arguments */
1878 if ((app == NULL) ||
1880 (ptype->name == NULL) ||
1881 (strlen(ptype->name) == 0) ||
1882 (ptype->be_ops->f_init == NULL) ||
1883 (ptype->be_ops->f_timer == NULL))
1886 /* Check for duplicate entry */
1887 for (i = 0; i < app->n_pipeline_types; i++)
1888 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1891 /* Check for resource availability */
1892 n_cmds = pipeline_type_cmds_count(ptype);
1893 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1894 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1897 /* Copy pipeline type */
1898 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1900 sizeof(struct pipeline_type));
1902 /* Copy CLI commands */
1904 app_pipeline_type_cmd_push(app, ptype);
1910 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1914 for (i = 0; i < app->n_pipeline_types; i++)
1915 if (strcmp(app->pipeline_type[i].name, name) == 0)
1916 return &app->pipeline_type[i];