1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
8 #include <netinet/in.h>
9 #ifdef RTE_EXEC_ENV_LINUXAPP
11 #include <linux/if_tun.h>
14 #include <sys/ioctl.h>
17 #include <rte_cycles.h>
18 #include <rte_ethdev.h>
19 #include <rte_ether.h>
22 #include <rte_malloc.h>
23 #include <rte_bus_pci.h>
27 #include "pipeline_common_fe.h"
28 #include "pipeline_master.h"
29 #include "pipeline_passthrough.h"
30 #include "pipeline_firewall.h"
31 #include "pipeline_flow_classification.h"
32 #include "pipeline_flow_actions.h"
33 #include "pipeline_routing.h"
34 #include "thread_fe.h"
36 #define APP_NAME_SIZE 32
38 #define APP_RETA_SIZE_MAX (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
41 app_init_core_map(struct app_params *app)
43 APP_LOG(app, HIGH, "Initializing CPU core map ...");
44 app->core_map = cpu_core_map_init(RTE_MAX_NUMA_NODES, RTE_MAX_LCORE,
47 if (app->core_map == NULL)
48 rte_panic("Cannot create CPU core map\n");
50 if (app->log_level >= APP_LOG_LEVEL_LOW)
51 cpu_core_map_print(app->core_map);
54 /* Core Mask String in Hex Representation */
55 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
58 app_init_core_mask(struct app_params *app)
61 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
63 for (i = 0; i < app->n_pipelines; i++) {
64 struct app_pipeline_params *p = &app->pipeline_params[i];
67 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
73 rte_panic("Cannot create CPU core mask\n");
75 app_core_enable_in_core_mask(app, lcore_id);
78 app_core_build_core_mask_string(app, core_mask_str);
79 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
83 app_init_eal(struct app_params *app)
86 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
87 struct app_eal_params *p = &app->eal_params;
92 app->eal_argv[n_args++] = strdup(app->app_name);
94 app_core_build_core_mask_string(app, core_mask_str);
95 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
96 app->eal_argv[n_args++] = strdup(buffer);
99 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
100 app->eal_argv[n_args++] = strdup(buffer);
103 if (p->master_lcore_present) {
106 "--master-lcore=%" PRIu32,
108 app->eal_argv[n_args++] = strdup(buffer);
111 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
112 app->eal_argv[n_args++] = strdup(buffer);
114 if (p->memory_present) {
115 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
116 app->eal_argv[n_args++] = strdup(buffer);
119 if (p->ranks_present) {
120 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
121 app->eal_argv[n_args++] = strdup(buffer);
124 for (i = 0; i < APP_MAX_LINKS; i++) {
125 if (p->pci_blacklist[i] == NULL)
130 "--pci-blacklist=%s",
131 p->pci_blacklist[i]);
132 app->eal_argv[n_args++] = strdup(buffer);
135 if (app->port_mask != 0)
136 for (i = 0; i < APP_MAX_LINKS; i++) {
137 if (p->pci_whitelist[i] == NULL)
142 "--pci-whitelist=%s",
143 p->pci_whitelist[i]);
144 app->eal_argv[n_args++] = strdup(buffer);
147 for (i = 0; i < app->n_links; i++) {
148 char *pci_bdf = app->link_params[i].pci_bdf;
152 "--pci-whitelist=%s",
154 app->eal_argv[n_args++] = strdup(buffer);
157 for (i = 0; i < APP_MAX_LINKS; i++) {
158 if (p->vdev[i] == NULL)
165 app->eal_argv[n_args++] = strdup(buffer);
168 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
169 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
170 app->eal_argv[n_args++] = strdup(buffer);
178 app->eal_argv[n_args++] = strdup(buffer);
182 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
183 app->eal_argv[n_args++] = strdup(buffer);
186 if (p->log_level_present) {
189 "--log-level=%" PRIu32,
191 app->eal_argv[n_args++] = strdup(buffer);
194 if ((p->version_present) && p->version) {
195 snprintf(buffer, sizeof(buffer), "-v");
196 app->eal_argv[n_args++] = strdup(buffer);
199 if ((p->help_present) && p->help) {
200 snprintf(buffer, sizeof(buffer), "--help");
201 app->eal_argv[n_args++] = strdup(buffer);
204 if ((p->no_huge_present) && p->no_huge) {
205 snprintf(buffer, sizeof(buffer), "--no-huge");
206 app->eal_argv[n_args++] = strdup(buffer);
209 if ((p->no_pci_present) && p->no_pci) {
210 snprintf(buffer, sizeof(buffer), "--no-pci");
211 app->eal_argv[n_args++] = strdup(buffer);
214 if ((p->no_hpet_present) && p->no_hpet) {
215 snprintf(buffer, sizeof(buffer), "--no-hpet");
216 app->eal_argv[n_args++] = strdup(buffer);
219 if ((p->no_shconf_present) && p->no_shconf) {
220 snprintf(buffer, sizeof(buffer), "--no-shconf");
221 app->eal_argv[n_args++] = strdup(buffer);
225 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
226 app->eal_argv[n_args++] = strdup(buffer);
234 app->eal_argv[n_args++] = strdup(buffer);
238 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
239 app->eal_argv[n_args++] = strdup(buffer);
242 if (p->file_prefix) {
247 app->eal_argv[n_args++] = strdup(buffer);
250 if (p->base_virtaddr) {
253 "--base-virtaddr=%s",
255 app->eal_argv[n_args++] = strdup(buffer);
258 if ((p->create_uio_dev_present) && p->create_uio_dev) {
259 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
260 app->eal_argv[n_args++] = strdup(buffer);
268 app->eal_argv[n_args++] = strdup(buffer);
271 snprintf(buffer, sizeof(buffer), "--");
272 app->eal_argv[n_args++] = strdup(buffer);
274 app->eal_argc = n_args;
276 APP_LOG(app, HIGH, "Initializing EAL ...");
277 if (app->log_level >= APP_LOG_LEVEL_LOW) {
280 fprintf(stdout, "[APP] EAL arguments: \"");
281 for (i = 1; i < app->eal_argc; i++)
282 fprintf(stdout, "%s ", app->eal_argv[i]);
283 fprintf(stdout, "\"\n");
286 status = rte_eal_init(app->eal_argc, app->eal_argv);
288 rte_panic("EAL init error\n");
292 app_init_mempool(struct app_params *app)
296 for (i = 0; i < app->n_mempools; i++) {
297 struct app_mempool_params *p = &app->mempool_params[i];
299 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
300 app->mempool[i] = rte_pktmbuf_pool_create(
306 sizeof(struct rte_mbuf), /* mbuf data size */
309 if (app->mempool[i] == NULL)
310 rte_panic("%s init error\n", p->name);
315 app_link_filter_arp_add(struct app_link_params *link)
317 struct rte_eth_ethertype_filter filter = {
318 .ether_type = ETHER_TYPE_ARP,
320 .queue = link->arp_q,
323 return rte_eth_dev_filter_ctrl(link->pmd_id,
324 RTE_ETH_FILTER_ETHERTYPE,
330 app_link_filter_tcp_syn_add(struct app_link_params *link)
332 struct rte_eth_syn_filter filter = {
334 .queue = link->tcp_syn_q,
337 return rte_eth_dev_filter_ctrl(link->pmd_id,
344 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
346 struct rte_eth_ntuple_filter filter = {
347 .flags = RTE_5TUPLE_FLAGS,
348 .dst_ip = rte_bswap32(l2->ip),
349 .dst_ip_mask = UINT32_MAX, /* Enable */
351 .src_ip_mask = 0, /* Disable */
353 .dst_port_mask = 0, /* Disable */
355 .src_port_mask = 0, /* Disable */
357 .proto_mask = 0, /* Disable */
359 .priority = 1, /* Lowest */
360 .queue = l1->ip_local_q,
363 return rte_eth_dev_filter_ctrl(l1->pmd_id,
364 RTE_ETH_FILTER_NTUPLE,
370 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
372 struct rte_eth_ntuple_filter filter = {
373 .flags = RTE_5TUPLE_FLAGS,
374 .dst_ip = rte_bswap32(l2->ip),
375 .dst_ip_mask = UINT32_MAX, /* Enable */
377 .src_ip_mask = 0, /* Disable */
379 .dst_port_mask = 0, /* Disable */
381 .src_port_mask = 0, /* Disable */
383 .proto_mask = 0, /* Disable */
385 .priority = 1, /* Lowest */
386 .queue = l1->ip_local_q,
389 return rte_eth_dev_filter_ctrl(l1->pmd_id,
390 RTE_ETH_FILTER_NTUPLE,
391 RTE_ETH_FILTER_DELETE,
396 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
398 struct rte_eth_ntuple_filter filter = {
399 .flags = RTE_5TUPLE_FLAGS,
400 .dst_ip = rte_bswap32(l2->ip),
401 .dst_ip_mask = UINT32_MAX, /* Enable */
403 .src_ip_mask = 0, /* Disable */
405 .dst_port_mask = 0, /* Disable */
407 .src_port_mask = 0, /* Disable */
408 .proto = IPPROTO_TCP,
409 .proto_mask = UINT8_MAX, /* Enable */
411 .priority = 2, /* Higher priority than IP */
412 .queue = l1->tcp_local_q,
415 return rte_eth_dev_filter_ctrl(l1->pmd_id,
416 RTE_ETH_FILTER_NTUPLE,
422 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
424 struct rte_eth_ntuple_filter filter = {
425 .flags = RTE_5TUPLE_FLAGS,
426 .dst_ip = rte_bswap32(l2->ip),
427 .dst_ip_mask = UINT32_MAX, /* Enable */
429 .src_ip_mask = 0, /* Disable */
431 .dst_port_mask = 0, /* Disable */
433 .src_port_mask = 0, /* Disable */
434 .proto = IPPROTO_TCP,
435 .proto_mask = UINT8_MAX, /* Enable */
437 .priority = 2, /* Higher priority than IP */
438 .queue = l1->tcp_local_q,
441 return rte_eth_dev_filter_ctrl(l1->pmd_id,
442 RTE_ETH_FILTER_NTUPLE,
443 RTE_ETH_FILTER_DELETE,
448 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
450 struct rte_eth_ntuple_filter filter = {
451 .flags = RTE_5TUPLE_FLAGS,
452 .dst_ip = rte_bswap32(l2->ip),
453 .dst_ip_mask = UINT32_MAX, /* Enable */
455 .src_ip_mask = 0, /* Disable */
457 .dst_port_mask = 0, /* Disable */
459 .src_port_mask = 0, /* Disable */
460 .proto = IPPROTO_UDP,
461 .proto_mask = UINT8_MAX, /* Enable */
463 .priority = 2, /* Higher priority than IP */
464 .queue = l1->udp_local_q,
467 return rte_eth_dev_filter_ctrl(l1->pmd_id,
468 RTE_ETH_FILTER_NTUPLE,
474 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
476 struct rte_eth_ntuple_filter filter = {
477 .flags = RTE_5TUPLE_FLAGS,
478 .dst_ip = rte_bswap32(l2->ip),
479 .dst_ip_mask = UINT32_MAX, /* Enable */
481 .src_ip_mask = 0, /* Disable */
483 .dst_port_mask = 0, /* Disable */
485 .src_port_mask = 0, /* Disable */
486 .proto = IPPROTO_UDP,
487 .proto_mask = UINT8_MAX, /* Enable */
489 .priority = 2, /* Higher priority than IP */
490 .queue = l1->udp_local_q,
493 return rte_eth_dev_filter_ctrl(l1->pmd_id,
494 RTE_ETH_FILTER_NTUPLE,
495 RTE_ETH_FILTER_DELETE,
500 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
502 struct rte_eth_ntuple_filter filter = {
503 .flags = RTE_5TUPLE_FLAGS,
504 .dst_ip = rte_bswap32(l2->ip),
505 .dst_ip_mask = UINT32_MAX, /* Enable */
507 .src_ip_mask = 0, /* Disable */
509 .dst_port_mask = 0, /* Disable */
511 .src_port_mask = 0, /* Disable */
512 .proto = IPPROTO_SCTP,
513 .proto_mask = UINT8_MAX, /* Enable */
515 .priority = 2, /* Higher priority than IP */
516 .queue = l1->sctp_local_q,
519 return rte_eth_dev_filter_ctrl(l1->pmd_id,
520 RTE_ETH_FILTER_NTUPLE,
526 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
528 struct rte_eth_ntuple_filter filter = {
529 .flags = RTE_5TUPLE_FLAGS,
530 .dst_ip = rte_bswap32(l2->ip),
531 .dst_ip_mask = UINT32_MAX, /* Enable */
533 .src_ip_mask = 0, /* Disable */
535 .dst_port_mask = 0, /* Disable */
537 .src_port_mask = 0, /* Disable */
538 .proto = IPPROTO_SCTP,
539 .proto_mask = UINT8_MAX, /* Enable */
541 .priority = 2, /* Higher priority than IP */
542 .queue = l1->sctp_local_q,
545 return rte_eth_dev_filter_ctrl(l1->pmd_id,
546 RTE_ETH_FILTER_NTUPLE,
547 RTE_ETH_FILTER_DELETE,
552 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
554 if (cp->arp_q != 0) {
555 int status = app_link_filter_arp_add(cp);
557 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
558 "Adding ARP filter (queue = %" PRIu32 ")",
559 cp->name, cp->pmd_id, cp->arp_q);
562 rte_panic("%s (%" PRIu32 "): "
563 "Error adding ARP filter "
564 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
565 cp->name, cp->pmd_id, cp->arp_q, status);
570 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
572 if (cp->tcp_syn_q != 0) {
573 int status = app_link_filter_tcp_syn_add(cp);
575 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
576 "Adding TCP SYN filter (queue = %" PRIu32 ")",
577 cp->name, cp->pmd_id, cp->tcp_syn_q);
580 rte_panic("%s (%" PRIu32 "): "
581 "Error adding TCP SYN filter "
582 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
583 cp->name, cp->pmd_id, cp->tcp_syn_q,
589 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
594 /* For each link, add filters for IP of current link */
596 for (i = 0; i < app->n_links; i++) {
597 struct app_link_params *p = &app->link_params[i];
600 if (p->ip_local_q != 0) {
601 int status = app_link_filter_ip_add(p, cp);
603 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
604 "Adding IP filter (queue= %" PRIu32
605 ", IP = 0x%08" PRIx32 ")",
606 p->name, p->pmd_id, p->ip_local_q,
610 rte_panic("%s (%" PRIu32 "): "
612 "filter (queue= %" PRIu32 ", "
616 p->ip_local_q, cp->ip, status);
620 if (p->tcp_local_q != 0) {
621 int status = app_link_filter_tcp_add(p, cp);
623 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
626 ", IP = 0x%08" PRIx32 ")",
627 p->name, p->pmd_id, p->tcp_local_q,
631 rte_panic("%s (%" PRIu32 "): "
633 "filter (queue = %" PRIu32 ", "
637 p->tcp_local_q, cp->ip, status);
641 if (p->udp_local_q != 0) {
642 int status = app_link_filter_udp_add(p, cp);
644 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
647 ", IP = 0x%08" PRIx32 ")",
648 p->name, p->pmd_id, p->udp_local_q,
652 rte_panic("%s (%" PRIu32 "): "
654 "filter (queue = %" PRIu32 ", "
658 p->udp_local_q, cp->ip, status);
662 if (p->sctp_local_q != 0) {
663 int status = app_link_filter_sctp_add(p, cp);
665 APP_LOG(app, LOW, "%s (%" PRIu32
666 "): Adding SCTP filter "
668 ", IP = 0x%08" PRIx32 ")",
669 p->name, p->pmd_id, p->sctp_local_q,
673 rte_panic("%s (%" PRIu32 "): "
675 "filter (queue = %" PRIu32 ", "
679 p->sctp_local_q, cp->ip,
686 status = rte_eth_dev_set_link_up(cp->pmd_id);
687 /* Do not panic if PMD does not provide link up functionality */
688 if (status < 0 && status != -ENOTSUP)
689 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
690 PRId32 "\n", cp->name, cp->pmd_id, status);
692 /* Mark link as UP */
697 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
703 status = rte_eth_dev_set_link_down(cp->pmd_id);
704 /* Do not panic if PMD does not provide link down functionality */
705 if (status < 0 && status != -ENOTSUP)
706 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
707 PRId32 "\n", cp->name, cp->pmd_id, status);
709 /* Mark link as DOWN */
712 /* Return if current link IP is not valid */
716 /* For each link, remove filters for IP of current link */
717 for (i = 0; i < app->n_links; i++) {
718 struct app_link_params *p = &app->link_params[i];
721 if (p->ip_local_q != 0) {
722 int status = app_link_filter_ip_del(p, cp);
724 APP_LOG(app, LOW, "%s (%" PRIu32
725 "): Deleting IP filter "
726 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
727 p->name, p->pmd_id, p->ip_local_q, cp->ip);
730 rte_panic("%s (%" PRIu32
731 "): Error deleting IP filter "
735 p->name, p->pmd_id, p->ip_local_q,
740 if (p->tcp_local_q != 0) {
741 int status = app_link_filter_tcp_del(p, cp);
743 APP_LOG(app, LOW, "%s (%" PRIu32
744 "): Deleting TCP filter "
746 ", IP = 0x%" PRIx32 ")",
747 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
750 rte_panic("%s (%" PRIu32
751 "): Error deleting TCP filter "
755 p->name, p->pmd_id, p->tcp_local_q,
760 if (p->udp_local_q != 0) {
761 int status = app_link_filter_udp_del(p, cp);
763 APP_LOG(app, LOW, "%s (%" PRIu32
764 "): Deleting UDP filter "
765 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
766 p->name, p->pmd_id, p->udp_local_q, cp->ip);
769 rte_panic("%s (%" PRIu32
770 "): Error deleting UDP filter "
774 p->name, p->pmd_id, p->udp_local_q,
779 if (p->sctp_local_q != 0) {
780 int status = app_link_filter_sctp_del(p, cp);
782 APP_LOG(app, LOW, "%s (%" PRIu32
783 "): Deleting SCTP filter "
785 ", IP = 0x%" PRIx32 ")",
786 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
789 rte_panic("%s (%" PRIu32
790 "): Error deleting SCTP filter "
794 p->name, p->pmd_id, p->sctp_local_q,
801 app_check_link(struct app_params *app)
803 uint32_t all_links_up, i;
807 for (i = 0; i < app->n_links; i++) {
808 struct app_link_params *p = &app->link_params[i];
809 struct rte_eth_link link_params;
811 memset(&link_params, 0, sizeof(link_params));
812 rte_eth_link_get(p->pmd_id, &link_params);
814 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
817 link_params.link_speed / 1000,
818 link_params.link_status ? "UP" : "DOWN");
820 if (link_params.link_status == ETH_LINK_DOWN)
824 if (all_links_up == 0)
825 rte_panic("Some links are DOWN\n");
829 is_any_swq_frag_or_ras(struct app_params *app)
833 for (i = 0; i < app->n_pktq_swq; i++) {
834 struct app_pktq_swq_params *p = &app->swq_params[i];
836 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
837 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
845 app_init_link_frag_ras(struct app_params *app)
849 if (is_any_swq_frag_or_ras(app)) {
850 for (i = 0; i < app->n_pktq_hwq_out; i++) {
851 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
853 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
859 app_get_cpu_socket_id(uint32_t pmd_id)
861 int status = rte_eth_dev_socket_id(pmd_id);
863 return (status != SOCKET_ID_ANY) ? status : 0;
867 app_link_rss_enabled(struct app_link_params *cp)
869 return (cp->n_rss_qs) ? 1 : 0;
873 app_link_rss_setup(struct app_link_params *cp)
875 struct rte_eth_dev_info dev_info;
876 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
881 memset(&dev_info, 0, sizeof(dev_info));
882 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
884 if (dev_info.reta_size == 0)
885 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
886 cp->name, cp->pmd_id);
888 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
889 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
890 cp->name, cp->pmd_id);
892 /* Setup RETA contents */
893 memset(reta_conf, 0, sizeof(reta_conf));
895 for (i = 0; i < dev_info.reta_size; i++)
896 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
898 for (i = 0; i < dev_info.reta_size; i++) {
899 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
900 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
901 uint32_t rss_qs_pos = i % cp->n_rss_qs;
903 reta_conf[reta_id].reta[reta_pos] =
904 (uint16_t) cp->rss_qs[rss_qs_pos];
908 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
912 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
913 cp->name, cp->pmd_id);
917 app_init_link_set_config(struct app_link_params *p)
920 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
921 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
928 app_init_link(struct app_params *app)
932 app_init_link_frag_ras(app);
934 for (i = 0; i < app->n_links; i++) {
935 struct app_link_params *p_link = &app->link_params[i];
936 uint32_t link_id, n_hwq_in, n_hwq_out, j;
939 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
940 n_hwq_in = app_link_get_n_rxq(app, p_link);
941 n_hwq_out = app_link_get_n_txq(app, p_link);
942 app_init_link_set_config(p_link);
944 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
945 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
952 status = rte_eth_dev_configure(
958 rte_panic("%s (%" PRId32 "): "
959 "init error (%" PRId32 ")\n",
960 p_link->name, p_link->pmd_id, status);
962 rte_eth_macaddr_get(p_link->pmd_id,
963 (struct ether_addr *) &p_link->mac_addr);
966 rte_eth_promiscuous_enable(p_link->pmd_id);
969 for (j = 0; j < app->n_pktq_hwq_in; j++) {
970 struct app_pktq_hwq_in_params *p_rxq =
971 &app->hwq_in_params[j];
972 uint32_t rxq_link_id, rxq_queue_id;
973 uint16_t nb_rxd = p_rxq->size;
975 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
976 &rxq_link_id, &rxq_queue_id);
977 if (rxq_link_id != link_id)
980 status = rte_eth_dev_adjust_nb_rx_tx_desc(
985 rte_panic("%s (%" PRIu32 "): "
986 "%s adjust number of Rx descriptors "
987 "error (%" PRId32 ")\n",
993 status = rte_eth_rx_queue_setup(
997 app_get_cpu_socket_id(p_link->pmd_id),
999 app->mempool[p_rxq->mempool_id]);
1001 rte_panic("%s (%" PRIu32 "): "
1002 "%s init error (%" PRId32 ")\n",
1010 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1011 struct app_pktq_hwq_out_params *p_txq =
1012 &app->hwq_out_params[j];
1013 uint32_t txq_link_id, txq_queue_id;
1014 uint16_t nb_txd = p_txq->size;
1016 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1017 &txq_link_id, &txq_queue_id);
1018 if (txq_link_id != link_id)
1021 status = rte_eth_dev_adjust_nb_rx_tx_desc(
1026 rte_panic("%s (%" PRIu32 "): "
1027 "%s adjust number of Tx descriptors "
1028 "error (%" PRId32 ")\n",
1034 status = rte_eth_tx_queue_setup(
1038 app_get_cpu_socket_id(p_link->pmd_id),
1041 rte_panic("%s (%" PRIu32 "): "
1042 "%s init error (%" PRId32 ")\n",
1050 status = rte_eth_dev_start(p_link->pmd_id);
1052 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1053 p_link->name, status);
1056 app_link_set_arp_filter(app, p_link);
1057 app_link_set_tcp_syn_filter(app, p_link);
1058 if (app_link_rss_enabled(p_link))
1059 app_link_rss_setup(p_link);
1062 app_link_up_internal(app, p_link);
1065 app_check_link(app);
1069 app_init_swq(struct app_params *app)
1073 for (i = 0; i < app->n_pktq_swq; i++) {
1074 struct app_pktq_swq_params *p = &app->swq_params[i];
1077 if (app_swq_get_readers(app, p) == 1)
1078 flags |= RING_F_SC_DEQ;
1079 if (app_swq_get_writers(app, p) == 1)
1080 flags |= RING_F_SP_ENQ;
1082 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1083 app->swq[i] = rte_ring_create(
1089 if (app->swq[i] == NULL)
1090 rte_panic("%s init error\n", p->name);
1095 app_init_tm(struct app_params *app)
1099 for (i = 0; i < app->n_pktq_tm; i++) {
1100 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1101 struct app_link_params *p_link;
1102 struct rte_eth_link link_eth_params;
1103 struct rte_sched_port *sched;
1104 uint32_t n_subports, subport_id;
1107 p_link = app_get_link_for_tm(app, p_tm);
1109 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1112 p_tm->sched_port_params.name = p_tm->name;
1113 p_tm->sched_port_params.socket =
1114 app_get_cpu_socket_id(p_link->pmd_id);
1115 p_tm->sched_port_params.rate =
1116 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1118 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1119 sched = rte_sched_port_config(&p_tm->sched_port_params);
1121 rte_panic("%s init error\n", p_tm->name);
1125 n_subports = p_tm->sched_port_params.n_subports_per_port;
1126 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1127 uint32_t n_pipes_per_subport, pipe_id;
1129 status = rte_sched_subport_config(sched,
1131 &p_tm->sched_subport_params[subport_id]);
1133 rte_panic("%s subport %" PRIu32
1134 " init error (%" PRId32 ")\n",
1135 p_tm->name, subport_id, status);
1138 n_pipes_per_subport =
1139 p_tm->sched_port_params.n_pipes_per_subport;
1141 pipe_id < n_pipes_per_subport;
1143 int profile_id = p_tm->sched_pipe_to_profile[
1144 subport_id * APP_MAX_SCHED_PIPES +
1147 if (profile_id == -1)
1150 status = rte_sched_pipe_config(sched,
1155 rte_panic("%s subport %" PRIu32
1157 " (profile %" PRId32 ") "
1158 "init error (% " PRId32 ")\n",
1159 p_tm->name, subport_id, pipe_id,
1160 profile_id, status);
1166 #ifndef RTE_EXEC_ENV_LINUXAPP
1168 app_init_tap(struct app_params *app) {
1169 if (app->n_pktq_tap == 0)
1172 rte_panic("TAP device not supported.\n");
1176 app_init_tap(struct app_params *app)
1180 for (i = 0; i < app->n_pktq_tap; i++) {
1181 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1185 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1187 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1189 rte_panic("Cannot open file /dev/net/tun\n");
1191 memset(&ifr, 0, sizeof(ifr));
1192 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1193 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1195 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1197 rte_panic("TAP setup error\n");
1204 #ifdef RTE_LIBRTE_KNI
1206 kni_config_network_interface(uint16_t port_id, uint8_t if_up) {
1209 if (port_id >= rte_eth_dev_count())
1213 rte_eth_dev_set_link_up(port_id) :
1214 rte_eth_dev_set_link_down(port_id);
1220 kni_change_mtu(uint16_t port_id, unsigned int new_mtu) {
1223 if (port_id >= rte_eth_dev_count())
1226 if (new_mtu > ETHER_MAX_LEN)
1230 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1236 #endif /* RTE_LIBRTE_KNI */
1238 #ifndef RTE_LIBRTE_KNI
1240 app_init_kni(struct app_params *app) {
1241 if (app->n_pktq_kni == 0)
1244 rte_panic("Can not init KNI without librte_kni support.\n");
1248 app_init_kni(struct app_params *app) {
1251 if (app->n_pktq_kni == 0)
1254 rte_kni_init(app->n_pktq_kni);
1256 for (i = 0; i < app->n_pktq_kni; i++) {
1257 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1258 struct app_link_params *p_link;
1259 struct rte_eth_dev_info dev_info;
1260 struct app_mempool_params *mempool_params;
1261 struct rte_mempool *mempool;
1262 struct rte_kni_conf conf;
1263 struct rte_kni_ops ops;
1266 p_link = app_get_link_for_kni(app, p_kni);
1267 memset(&dev_info, 0, sizeof(dev_info));
1268 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1271 mempool_params = &app->mempool_params[p_kni->mempool_id];
1272 mempool = app->mempool[p_kni->mempool_id];
1275 memset(&conf, 0, sizeof(conf));
1276 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1277 conf.force_bind = p_kni->force_bind;
1278 if (conf.force_bind) {
1281 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1284 p_kni->hyper_th_id);
1287 rte_panic("%s invalid CPU core\n", p_kni->name);
1289 conf.core_id = (uint32_t) lcore_id;
1291 conf.group_id = p_link->pmd_id;
1292 conf.mbuf_size = mempool_params->buffer_size;
1293 conf.addr = dev_info.pci_dev->addr;
1294 conf.id = dev_info.pci_dev->id;
1296 memset(&ops, 0, sizeof(ops));
1297 ops.port_id = (uint8_t) p_link->pmd_id;
1298 ops.change_mtu = kni_change_mtu;
1299 ops.config_network_if = kni_config_network_interface;
1301 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1302 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1304 rte_panic("%s init error\n", p_kni->name);
1307 #endif /* RTE_LIBRTE_KNI */
1310 app_init_msgq(struct app_params *app)
1314 for (i = 0; i < app->n_msgq; i++) {
1315 struct app_msgq_params *p = &app->msgq_params[i];
1317 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1318 app->msgq[i] = rte_ring_create(
1322 RING_F_SP_ENQ | RING_F_SC_DEQ);
1324 if (app->msgq[i] == NULL)
1325 rte_panic("%s init error\n", p->name);
1329 void app_pipeline_params_get(struct app_params *app,
1330 struct app_pipeline_params *p_in,
1331 struct pipeline_params *p_out)
1335 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1337 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1339 p_out->socket_id = (int) p_in->socket_id;
1341 p_out->log_level = app->log_level;
1344 p_out->n_ports_in = p_in->n_pktq_in;
1345 for (i = 0; i < p_in->n_pktq_in; i++) {
1346 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1347 struct pipeline_port_in_params *out = &p_out->port_in[i];
1350 case APP_PKTQ_IN_HWQ:
1352 struct app_pktq_hwq_in_params *p_hwq_in =
1353 &app->hwq_in_params[in->id];
1354 struct app_link_params *p_link =
1355 app_get_link_for_rxq(app, p_hwq_in);
1356 uint32_t rxq_link_id, rxq_queue_id;
1358 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1362 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1363 out->params.ethdev.port_id = p_link->pmd_id;
1364 out->params.ethdev.queue_id = rxq_queue_id;
1365 out->burst_size = p_hwq_in->burst;
1368 case APP_PKTQ_IN_SWQ:
1370 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1372 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1373 if (app_swq_get_readers(app, swq_params) == 1) {
1374 out->type = PIPELINE_PORT_IN_RING_READER;
1375 out->params.ring.ring = app->swq[in->id];
1376 out->burst_size = app->swq_params[in->id].burst_read;
1378 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1379 out->params.ring_multi.ring = app->swq[in->id];
1380 out->burst_size = swq_params->burst_read;
1383 if (swq_params->ipv4_frag == 1) {
1384 struct rte_port_ring_reader_ipv4_frag_params *params =
1385 &out->params.ring_ipv4_frag;
1387 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1388 params->ring = app->swq[in->id];
1389 params->mtu = swq_params->mtu;
1390 params->metadata_size = swq_params->metadata_size;
1391 params->pool_direct =
1392 app->mempool[swq_params->mempool_direct_id];
1393 params->pool_indirect =
1394 app->mempool[swq_params->mempool_indirect_id];
1395 out->burst_size = swq_params->burst_read;
1397 struct rte_port_ring_reader_ipv6_frag_params *params =
1398 &out->params.ring_ipv6_frag;
1400 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1401 params->ring = app->swq[in->id];
1402 params->mtu = swq_params->mtu;
1403 params->metadata_size = swq_params->metadata_size;
1404 params->pool_direct =
1405 app->mempool[swq_params->mempool_direct_id];
1406 params->pool_indirect =
1407 app->mempool[swq_params->mempool_indirect_id];
1408 out->burst_size = swq_params->burst_read;
1413 case APP_PKTQ_IN_TM:
1415 out->type = PIPELINE_PORT_IN_SCHED_READER;
1416 out->params.sched.sched = app->tm[in->id];
1417 out->burst_size = app->tm_params[in->id].burst_read;
1420 #ifdef RTE_EXEC_ENV_LINUXAPP
1421 case APP_PKTQ_IN_TAP:
1423 struct app_pktq_tap_params *tap_params =
1424 &app->tap_params[in->id];
1425 struct app_mempool_params *mempool_params =
1426 &app->mempool_params[tap_params->mempool_id];
1427 struct rte_mempool *mempool =
1428 app->mempool[tap_params->mempool_id];
1430 out->type = PIPELINE_PORT_IN_FD_READER;
1431 out->params.fd.fd = app->tap[in->id];
1432 out->params.fd.mtu = mempool_params->buffer_size;
1433 out->params.fd.mempool = mempool;
1434 out->burst_size = app->tap_params[in->id].burst_read;
1438 #ifdef RTE_LIBRTE_KNI
1439 case APP_PKTQ_IN_KNI:
1441 out->type = PIPELINE_PORT_IN_KNI_READER;
1442 out->params.kni.kni = app->kni[in->id];
1443 out->burst_size = app->kni_params[in->id].burst_read;
1446 #endif /* RTE_LIBRTE_KNI */
1447 case APP_PKTQ_IN_SOURCE:
1449 uint32_t mempool_id =
1450 app->source_params[in->id].mempool_id;
1452 out->type = PIPELINE_PORT_IN_SOURCE;
1453 out->params.source.mempool = app->mempool[mempool_id];
1454 out->burst_size = app->source_params[in->id].burst;
1455 out->params.source.file_name =
1456 app->source_params[in->id].file_name;
1457 out->params.source.n_bytes_per_pkt =
1458 app->source_params[in->id].n_bytes_per_pkt;
1467 p_out->n_ports_out = p_in->n_pktq_out;
1468 for (i = 0; i < p_in->n_pktq_out; i++) {
1469 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1470 struct pipeline_port_out_params *out = &p_out->port_out[i];
1473 case APP_PKTQ_OUT_HWQ:
1475 struct app_pktq_hwq_out_params *p_hwq_out =
1476 &app->hwq_out_params[in->id];
1477 struct app_link_params *p_link =
1478 app_get_link_for_txq(app, p_hwq_out);
1479 uint32_t txq_link_id, txq_queue_id;
1481 sscanf(p_hwq_out->name,
1482 "TXQ%" SCNu32 ".%" SCNu32,
1486 if (p_hwq_out->dropless == 0) {
1487 struct rte_port_ethdev_writer_params *params =
1488 &out->params.ethdev;
1490 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1491 params->port_id = p_link->pmd_id;
1492 params->queue_id = txq_queue_id;
1493 params->tx_burst_sz =
1494 app->hwq_out_params[in->id].burst;
1496 struct rte_port_ethdev_writer_nodrop_params
1497 *params = &out->params.ethdev_nodrop;
1500 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1501 params->port_id = p_link->pmd_id;
1502 params->queue_id = txq_queue_id;
1503 params->tx_burst_sz = p_hwq_out->burst;
1504 params->n_retries = p_hwq_out->n_retries;
1508 case APP_PKTQ_OUT_SWQ:
1510 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1512 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1513 if (app_swq_get_writers(app, swq_params) == 1) {
1514 if (app->swq_params[in->id].dropless == 0) {
1515 struct rte_port_ring_writer_params *params =
1518 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1519 params->ring = app->swq[in->id];
1520 params->tx_burst_sz =
1521 app->swq_params[in->id].burst_write;
1523 struct rte_port_ring_writer_nodrop_params
1524 *params = &out->params.ring_nodrop;
1527 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1528 params->ring = app->swq[in->id];
1529 params->tx_burst_sz =
1530 app->swq_params[in->id].burst_write;
1532 app->swq_params[in->id].n_retries;
1535 if (swq_params->dropless == 0) {
1536 struct rte_port_ring_multi_writer_params *params =
1537 &out->params.ring_multi;
1539 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1540 params->ring = app->swq[in->id];
1541 params->tx_burst_sz = swq_params->burst_write;
1543 struct rte_port_ring_multi_writer_nodrop_params
1544 *params = &out->params.ring_multi_nodrop;
1546 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1547 params->ring = app->swq[in->id];
1548 params->tx_burst_sz = swq_params->burst_write;
1549 params->n_retries = swq_params->n_retries;
1553 if (swq_params->ipv4_ras == 1) {
1554 struct rte_port_ring_writer_ipv4_ras_params *params =
1555 &out->params.ring_ipv4_ras;
1557 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1558 params->ring = app->swq[in->id];
1559 params->tx_burst_sz = swq_params->burst_write;
1561 struct rte_port_ring_writer_ipv6_ras_params *params =
1562 &out->params.ring_ipv6_ras;
1564 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1565 params->ring = app->swq[in->id];
1566 params->tx_burst_sz = swq_params->burst_write;
1571 case APP_PKTQ_OUT_TM:
1573 struct rte_port_sched_writer_params *params =
1576 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1577 params->sched = app->tm[in->id];
1578 params->tx_burst_sz =
1579 app->tm_params[in->id].burst_write;
1582 #ifdef RTE_EXEC_ENV_LINUXAPP
1583 case APP_PKTQ_OUT_TAP:
1585 struct rte_port_fd_writer_params *params =
1588 out->type = PIPELINE_PORT_OUT_FD_WRITER;
1589 params->fd = app->tap[in->id];
1590 params->tx_burst_sz =
1591 app->tap_params[in->id].burst_write;
1595 #ifdef RTE_LIBRTE_KNI
1596 case APP_PKTQ_OUT_KNI:
1598 struct app_pktq_kni_params *p_kni =
1599 &app->kni_params[in->id];
1601 if (p_kni->dropless == 0) {
1602 struct rte_port_kni_writer_params *params =
1605 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1606 params->kni = app->kni[in->id];
1607 params->tx_burst_sz =
1608 app->kni_params[in->id].burst_write;
1610 struct rte_port_kni_writer_nodrop_params
1611 *params = &out->params.kni_nodrop;
1613 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1614 params->kni = app->kni[in->id];
1615 params->tx_burst_sz =
1616 app->kni_params[in->id].burst_write;
1618 app->kni_params[in->id].n_retries;
1622 #endif /* RTE_LIBRTE_KNI */
1623 case APP_PKTQ_OUT_SINK:
1625 out->type = PIPELINE_PORT_OUT_SINK;
1626 out->params.sink.file_name =
1627 app->sink_params[in->id].file_name;
1628 out->params.sink.max_n_pkts =
1629 app->sink_params[in->id].
1640 p_out->n_msgq = p_in->n_msgq_in;
1642 for (i = 0; i < p_in->n_msgq_in; i++)
1643 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1645 for (i = 0; i < p_in->n_msgq_out; i++)
1646 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1649 p_out->n_args = p_in->n_args;
1650 for (i = 0; i < p_in->n_args; i++) {
1651 p_out->args_name[i] = p_in->args_name[i];
1652 p_out->args_value[i] = p_in->args_value[i];
1657 app_init_pipelines(struct app_params *app)
1661 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1662 struct app_pipeline_params *params =
1663 &app->pipeline_params[p_id];
1664 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1665 struct pipeline_type *ptype;
1666 struct pipeline_params pp;
1668 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1670 ptype = app_pipeline_type_find(app, params->type);
1672 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1675 app_pipeline_params_get(app, params, &pp);
1679 if (ptype->be_ops->f_init) {
1680 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1682 if (data->be == NULL)
1683 rte_panic("Pipeline instance \"%s\" back-end "
1684 "init error\n", params->name);
1689 if (ptype->fe_ops->f_init) {
1690 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1692 if (data->fe == NULL)
1693 rte_panic("Pipeline instance \"%s\" front-end "
1694 "init error\n", params->name);
1697 data->ptype = ptype;
1699 data->timer_period = (rte_get_tsc_hz() *
1700 params->timer_period) / 100;
1705 app_post_init_pipelines(struct app_params *app)
1709 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1710 struct app_pipeline_params *params =
1711 &app->pipeline_params[p_id];
1712 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1715 if (data->ptype->fe_ops->f_post_init == NULL)
1718 status = data->ptype->fe_ops->f_post_init(data->fe);
1720 rte_panic("Pipeline instance \"%s\" front-end "
1721 "post-init error\n", params->name);
1726 app_init_threads(struct app_params *app)
1728 uint64_t time = rte_get_tsc_cycles();
1731 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1732 struct app_pipeline_params *params =
1733 &app->pipeline_params[p_id];
1734 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1735 struct pipeline_type *ptype;
1736 struct app_thread_data *t;
1737 struct app_thread_pipeline_data *p;
1740 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1743 params->hyper_th_id);
1746 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1749 (params->hyper_th_id) ? "h" : "");
1751 t = &app->thread_data[lcore_id];
1753 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1754 t->thread_req_deadline = time + t->timer_period;
1756 t->headroom_cycles = 0;
1757 t->headroom_time = rte_get_tsc_cycles();
1758 t->headroom_ratio = 0.0;
1760 t->msgq_in = app_thread_msgq_in_get(app,
1763 params->hyper_th_id);
1764 if (t->msgq_in == NULL)
1765 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1768 t->msgq_out = app_thread_msgq_out_get(app,
1771 params->hyper_th_id);
1772 if (t->msgq_out == NULL)
1773 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1776 ptype = app_pipeline_type_find(app, params->type);
1778 rte_panic("Init error: Unknown pipeline "
1779 "type \"%s\"\n", params->type);
1781 p = (ptype->be_ops->f_run == NULL) ?
1782 &t->regular[t->n_regular] :
1783 &t->custom[t->n_custom];
1785 p->pipeline_id = p_id;
1787 p->f_run = ptype->be_ops->f_run;
1788 p->f_timer = ptype->be_ops->f_timer;
1789 p->timer_period = data->timer_period;
1790 p->deadline = time + data->timer_period;
1794 if (ptype->be_ops->f_run == NULL)
1801 int app_init(struct app_params *app)
1803 app_init_core_map(app);
1804 app_init_core_mask(app);
1807 app_init_mempool(app);
1815 app_pipeline_common_cmd_push(app);
1816 app_pipeline_thread_cmd_push(app);
1817 app_pipeline_type_register(app, &pipeline_master);
1818 app_pipeline_type_register(app, &pipeline_passthrough);
1819 app_pipeline_type_register(app, &pipeline_flow_classification);
1820 app_pipeline_type_register(app, &pipeline_flow_actions);
1821 app_pipeline_type_register(app, &pipeline_firewall);
1822 app_pipeline_type_register(app, &pipeline_routing);
1824 app_init_pipelines(app);
1825 app_init_threads(app);
1830 int app_post_init(struct app_params *app)
1832 app_post_init_pipelines(app);
1838 app_pipeline_type_cmd_push(struct app_params *app,
1839 struct pipeline_type *ptype)
1841 cmdline_parse_ctx_t *cmds;
1844 /* Check input arguments */
1845 if ((app == NULL) ||
1849 n_cmds = pipeline_type_cmds_count(ptype);
1853 cmds = ptype->fe_ops->cmds;
1855 /* Check for available slots in the application commands array */
1856 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1859 /* Push pipeline commands into the application */
1860 memcpy(&app->cmds[app->n_cmds],
1862 n_cmds * sizeof(cmdline_parse_ctx_t));
1864 for (i = 0; i < n_cmds; i++)
1865 app->cmds[app->n_cmds + i]->data = app;
1867 app->n_cmds += n_cmds;
1868 app->cmds[app->n_cmds] = NULL;
1874 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1878 /* Check input arguments */
1879 if ((app == NULL) ||
1881 (ptype->name == NULL) ||
1882 (strlen(ptype->name) == 0) ||
1883 (ptype->be_ops->f_init == NULL) ||
1884 (ptype->be_ops->f_timer == NULL))
1887 /* Check for duplicate entry */
1888 for (i = 0; i < app->n_pipeline_types; i++)
1889 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1892 /* Check for resource availability */
1893 n_cmds = pipeline_type_cmds_count(ptype);
1894 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1895 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1898 /* Copy pipeline type */
1899 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1901 sizeof(struct pipeline_type));
1903 /* Copy CLI commands */
1905 app_pipeline_type_cmd_push(app, ptype);
1911 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1915 for (i = 0; i < app->n_pipeline_types; i++)
1916 if (strcmp(app->pipeline_type[i].name, name) == 0)
1917 return &app->pipeline_type[i];