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_firewall.h"
30 #include "pipeline_flow_classification.h"
31 #include "pipeline_flow_actions.h"
32 #include "pipeline_routing.h"
33 #include "thread_fe.h"
35 #define APP_NAME_SIZE 32
37 #define APP_RETA_SIZE_MAX (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
40 app_init_core_map(struct app_params *app)
42 APP_LOG(app, HIGH, "Initializing CPU core map ...");
43 app->core_map = cpu_core_map_init(RTE_MAX_NUMA_NODES, RTE_MAX_LCORE,
46 if (app->core_map == NULL)
47 rte_panic("Cannot create CPU core map\n");
49 if (app->log_level >= APP_LOG_LEVEL_LOW)
50 cpu_core_map_print(app->core_map);
53 /* Core Mask String in Hex Representation */
54 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
57 app_init_core_mask(struct app_params *app)
60 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
62 for (i = 0; i < app->n_pipelines; i++) {
63 struct app_pipeline_params *p = &app->pipeline_params[i];
66 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
72 rte_panic("Cannot create CPU core mask\n");
74 app_core_enable_in_core_mask(app, lcore_id);
77 app_core_build_core_mask_string(app, core_mask_str);
78 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
82 app_init_eal(struct app_params *app)
85 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
86 struct app_eal_params *p = &app->eal_params;
91 app->eal_argv[n_args++] = strdup(app->app_name);
93 app_core_build_core_mask_string(app, core_mask_str);
94 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
95 app->eal_argv[n_args++] = strdup(buffer);
98 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
99 app->eal_argv[n_args++] = strdup(buffer);
102 if (p->master_lcore_present) {
105 "--master-lcore=%" PRIu32,
107 app->eal_argv[n_args++] = strdup(buffer);
110 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
111 app->eal_argv[n_args++] = strdup(buffer);
113 if (p->memory_present) {
114 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
115 app->eal_argv[n_args++] = strdup(buffer);
118 if (p->ranks_present) {
119 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
120 app->eal_argv[n_args++] = strdup(buffer);
123 for (i = 0; i < APP_MAX_LINKS; i++) {
124 if (p->pci_blacklist[i] == NULL)
129 "--pci-blacklist=%s",
130 p->pci_blacklist[i]);
131 app->eal_argv[n_args++] = strdup(buffer);
134 if (app->port_mask != 0)
135 for (i = 0; i < APP_MAX_LINKS; i++) {
136 if (p->pci_whitelist[i] == NULL)
141 "--pci-whitelist=%s",
142 p->pci_whitelist[i]);
143 app->eal_argv[n_args++] = strdup(buffer);
146 for (i = 0; i < app->n_links; i++) {
147 char *pci_bdf = app->link_params[i].pci_bdf;
151 "--pci-whitelist=%s",
153 app->eal_argv[n_args++] = strdup(buffer);
156 for (i = 0; i < APP_MAX_LINKS; i++) {
157 if (p->vdev[i] == NULL)
164 app->eal_argv[n_args++] = strdup(buffer);
167 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
168 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
169 app->eal_argv[n_args++] = strdup(buffer);
177 app->eal_argv[n_args++] = strdup(buffer);
181 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
182 app->eal_argv[n_args++] = strdup(buffer);
185 if (p->log_level_present) {
188 "--log-level=%" PRIu32,
190 app->eal_argv[n_args++] = strdup(buffer);
193 if ((p->version_present) && p->version) {
194 snprintf(buffer, sizeof(buffer), "-v");
195 app->eal_argv[n_args++] = strdup(buffer);
198 if ((p->help_present) && p->help) {
199 snprintf(buffer, sizeof(buffer), "--help");
200 app->eal_argv[n_args++] = strdup(buffer);
203 if ((p->no_huge_present) && p->no_huge) {
204 snprintf(buffer, sizeof(buffer), "--no-huge");
205 app->eal_argv[n_args++] = strdup(buffer);
208 if ((p->no_pci_present) && p->no_pci) {
209 snprintf(buffer, sizeof(buffer), "--no-pci");
210 app->eal_argv[n_args++] = strdup(buffer);
213 if ((p->no_hpet_present) && p->no_hpet) {
214 snprintf(buffer, sizeof(buffer), "--no-hpet");
215 app->eal_argv[n_args++] = strdup(buffer);
218 if ((p->no_shconf_present) && p->no_shconf) {
219 snprintf(buffer, sizeof(buffer), "--no-shconf");
220 app->eal_argv[n_args++] = strdup(buffer);
224 snprintf(buffer, sizeof(buffer), "-d%s", p->add_driver);
225 app->eal_argv[n_args++] = strdup(buffer);
233 app->eal_argv[n_args++] = strdup(buffer);
237 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
238 app->eal_argv[n_args++] = strdup(buffer);
241 if (p->file_prefix) {
246 app->eal_argv[n_args++] = strdup(buffer);
249 if (p->base_virtaddr) {
252 "--base-virtaddr=%s",
254 app->eal_argv[n_args++] = strdup(buffer);
257 if ((p->create_uio_dev_present) && p->create_uio_dev) {
258 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
259 app->eal_argv[n_args++] = strdup(buffer);
267 app->eal_argv[n_args++] = strdup(buffer);
270 snprintf(buffer, sizeof(buffer), "--");
271 app->eal_argv[n_args++] = strdup(buffer);
273 app->eal_argc = n_args;
275 APP_LOG(app, HIGH, "Initializing EAL ...");
276 if (app->log_level >= APP_LOG_LEVEL_LOW) {
279 fprintf(stdout, "[APP] EAL arguments: \"");
280 for (i = 1; i < app->eal_argc; i++)
281 fprintf(stdout, "%s ", app->eal_argv[i]);
282 fprintf(stdout, "\"\n");
285 status = rte_eal_init(app->eal_argc, app->eal_argv);
287 rte_panic("EAL init error\n");
291 app_init_mempool(struct app_params *app)
295 for (i = 0; i < app->n_mempools; i++) {
296 struct app_mempool_params *p = &app->mempool_params[i];
298 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
299 app->mempool[i] = rte_pktmbuf_pool_create(
305 sizeof(struct rte_mbuf), /* mbuf data size */
308 if (app->mempool[i] == NULL)
309 rte_panic("%s init error\n", p->name);
314 app_link_filter_arp_add(struct app_link_params *link)
316 struct rte_eth_ethertype_filter filter = {
317 .ether_type = ETHER_TYPE_ARP,
319 .queue = link->arp_q,
322 return rte_eth_dev_filter_ctrl(link->pmd_id,
323 RTE_ETH_FILTER_ETHERTYPE,
329 app_link_filter_tcp_syn_add(struct app_link_params *link)
331 struct rte_eth_syn_filter filter = {
333 .queue = link->tcp_syn_q,
336 return rte_eth_dev_filter_ctrl(link->pmd_id,
343 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
345 struct rte_eth_ntuple_filter filter = {
346 .flags = RTE_5TUPLE_FLAGS,
347 .dst_ip = rte_bswap32(l2->ip),
348 .dst_ip_mask = UINT32_MAX, /* Enable */
350 .src_ip_mask = 0, /* Disable */
352 .dst_port_mask = 0, /* Disable */
354 .src_port_mask = 0, /* Disable */
356 .proto_mask = 0, /* Disable */
358 .priority = 1, /* Lowest */
359 .queue = l1->ip_local_q,
362 return rte_eth_dev_filter_ctrl(l1->pmd_id,
363 RTE_ETH_FILTER_NTUPLE,
369 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
371 struct rte_eth_ntuple_filter filter = {
372 .flags = RTE_5TUPLE_FLAGS,
373 .dst_ip = rte_bswap32(l2->ip),
374 .dst_ip_mask = UINT32_MAX, /* Enable */
376 .src_ip_mask = 0, /* Disable */
378 .dst_port_mask = 0, /* Disable */
380 .src_port_mask = 0, /* Disable */
382 .proto_mask = 0, /* Disable */
384 .priority = 1, /* Lowest */
385 .queue = l1->ip_local_q,
388 return rte_eth_dev_filter_ctrl(l1->pmd_id,
389 RTE_ETH_FILTER_NTUPLE,
390 RTE_ETH_FILTER_DELETE,
395 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
397 struct rte_eth_ntuple_filter filter = {
398 .flags = RTE_5TUPLE_FLAGS,
399 .dst_ip = rte_bswap32(l2->ip),
400 .dst_ip_mask = UINT32_MAX, /* Enable */
402 .src_ip_mask = 0, /* Disable */
404 .dst_port_mask = 0, /* Disable */
406 .src_port_mask = 0, /* Disable */
407 .proto = IPPROTO_TCP,
408 .proto_mask = UINT8_MAX, /* Enable */
410 .priority = 2, /* Higher priority than IP */
411 .queue = l1->tcp_local_q,
414 return rte_eth_dev_filter_ctrl(l1->pmd_id,
415 RTE_ETH_FILTER_NTUPLE,
421 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
423 struct rte_eth_ntuple_filter filter = {
424 .flags = RTE_5TUPLE_FLAGS,
425 .dst_ip = rte_bswap32(l2->ip),
426 .dst_ip_mask = UINT32_MAX, /* Enable */
428 .src_ip_mask = 0, /* Disable */
430 .dst_port_mask = 0, /* Disable */
432 .src_port_mask = 0, /* Disable */
433 .proto = IPPROTO_TCP,
434 .proto_mask = UINT8_MAX, /* Enable */
436 .priority = 2, /* Higher priority than IP */
437 .queue = l1->tcp_local_q,
440 return rte_eth_dev_filter_ctrl(l1->pmd_id,
441 RTE_ETH_FILTER_NTUPLE,
442 RTE_ETH_FILTER_DELETE,
447 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
449 struct rte_eth_ntuple_filter filter = {
450 .flags = RTE_5TUPLE_FLAGS,
451 .dst_ip = rte_bswap32(l2->ip),
452 .dst_ip_mask = UINT32_MAX, /* Enable */
454 .src_ip_mask = 0, /* Disable */
456 .dst_port_mask = 0, /* Disable */
458 .src_port_mask = 0, /* Disable */
459 .proto = IPPROTO_UDP,
460 .proto_mask = UINT8_MAX, /* Enable */
462 .priority = 2, /* Higher priority than IP */
463 .queue = l1->udp_local_q,
466 return rte_eth_dev_filter_ctrl(l1->pmd_id,
467 RTE_ETH_FILTER_NTUPLE,
473 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
475 struct rte_eth_ntuple_filter filter = {
476 .flags = RTE_5TUPLE_FLAGS,
477 .dst_ip = rte_bswap32(l2->ip),
478 .dst_ip_mask = UINT32_MAX, /* Enable */
480 .src_ip_mask = 0, /* Disable */
482 .dst_port_mask = 0, /* Disable */
484 .src_port_mask = 0, /* Disable */
485 .proto = IPPROTO_UDP,
486 .proto_mask = UINT8_MAX, /* Enable */
488 .priority = 2, /* Higher priority than IP */
489 .queue = l1->udp_local_q,
492 return rte_eth_dev_filter_ctrl(l1->pmd_id,
493 RTE_ETH_FILTER_NTUPLE,
494 RTE_ETH_FILTER_DELETE,
499 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
501 struct rte_eth_ntuple_filter filter = {
502 .flags = RTE_5TUPLE_FLAGS,
503 .dst_ip = rte_bswap32(l2->ip),
504 .dst_ip_mask = UINT32_MAX, /* Enable */
506 .src_ip_mask = 0, /* Disable */
508 .dst_port_mask = 0, /* Disable */
510 .src_port_mask = 0, /* Disable */
511 .proto = IPPROTO_SCTP,
512 .proto_mask = UINT8_MAX, /* Enable */
514 .priority = 2, /* Higher priority than IP */
515 .queue = l1->sctp_local_q,
518 return rte_eth_dev_filter_ctrl(l1->pmd_id,
519 RTE_ETH_FILTER_NTUPLE,
525 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
527 struct rte_eth_ntuple_filter filter = {
528 .flags = RTE_5TUPLE_FLAGS,
529 .dst_ip = rte_bswap32(l2->ip),
530 .dst_ip_mask = UINT32_MAX, /* Enable */
532 .src_ip_mask = 0, /* Disable */
534 .dst_port_mask = 0, /* Disable */
536 .src_port_mask = 0, /* Disable */
537 .proto = IPPROTO_SCTP,
538 .proto_mask = UINT8_MAX, /* Enable */
540 .priority = 2, /* Higher priority than IP */
541 .queue = l1->sctp_local_q,
544 return rte_eth_dev_filter_ctrl(l1->pmd_id,
545 RTE_ETH_FILTER_NTUPLE,
546 RTE_ETH_FILTER_DELETE,
551 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
553 if (cp->arp_q != 0) {
554 int status = app_link_filter_arp_add(cp);
556 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
557 "Adding ARP filter (queue = %" PRIu32 ")",
558 cp->name, cp->pmd_id, cp->arp_q);
561 rte_panic("%s (%" PRIu32 "): "
562 "Error adding ARP filter "
563 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
564 cp->name, cp->pmd_id, cp->arp_q, status);
569 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
571 if (cp->tcp_syn_q != 0) {
572 int status = app_link_filter_tcp_syn_add(cp);
574 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
575 "Adding TCP SYN filter (queue = %" PRIu32 ")",
576 cp->name, cp->pmd_id, cp->tcp_syn_q);
579 rte_panic("%s (%" PRIu32 "): "
580 "Error adding TCP SYN filter "
581 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
582 cp->name, cp->pmd_id, cp->tcp_syn_q,
588 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
593 /* For each link, add filters for IP of current link */
595 for (i = 0; i < app->n_links; i++) {
596 struct app_link_params *p = &app->link_params[i];
599 if (p->ip_local_q != 0) {
600 int status = app_link_filter_ip_add(p, cp);
602 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
603 "Adding IP filter (queue= %" PRIu32
604 ", IP = 0x%08" PRIx32 ")",
605 p->name, p->pmd_id, p->ip_local_q,
609 rte_panic("%s (%" PRIu32 "): "
611 "filter (queue= %" PRIu32 ", "
615 p->ip_local_q, cp->ip, status);
619 if (p->tcp_local_q != 0) {
620 int status = app_link_filter_tcp_add(p, cp);
622 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
625 ", IP = 0x%08" PRIx32 ")",
626 p->name, p->pmd_id, p->tcp_local_q,
630 rte_panic("%s (%" PRIu32 "): "
632 "filter (queue = %" PRIu32 ", "
636 p->tcp_local_q, cp->ip, status);
640 if (p->udp_local_q != 0) {
641 int status = app_link_filter_udp_add(p, cp);
643 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
646 ", IP = 0x%08" PRIx32 ")",
647 p->name, p->pmd_id, p->udp_local_q,
651 rte_panic("%s (%" PRIu32 "): "
653 "filter (queue = %" PRIu32 ", "
657 p->udp_local_q, cp->ip, status);
661 if (p->sctp_local_q != 0) {
662 int status = app_link_filter_sctp_add(p, cp);
664 APP_LOG(app, LOW, "%s (%" PRIu32
665 "): Adding SCTP filter "
667 ", IP = 0x%08" PRIx32 ")",
668 p->name, p->pmd_id, p->sctp_local_q,
672 rte_panic("%s (%" PRIu32 "): "
674 "filter (queue = %" PRIu32 ", "
678 p->sctp_local_q, cp->ip,
685 status = rte_eth_dev_set_link_up(cp->pmd_id);
686 /* Do not panic if PMD does not provide link up functionality */
687 if (status < 0 && status != -ENOTSUP)
688 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
689 PRId32 "\n", cp->name, cp->pmd_id, status);
691 /* Mark link as UP */
696 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
702 status = rte_eth_dev_set_link_down(cp->pmd_id);
703 /* Do not panic if PMD does not provide link down functionality */
704 if (status < 0 && status != -ENOTSUP)
705 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
706 PRId32 "\n", cp->name, cp->pmd_id, status);
708 /* Mark link as DOWN */
711 /* Return if current link IP is not valid */
715 /* For each link, remove filters for IP of current link */
716 for (i = 0; i < app->n_links; i++) {
717 struct app_link_params *p = &app->link_params[i];
720 if (p->ip_local_q != 0) {
721 int status = app_link_filter_ip_del(p, cp);
723 APP_LOG(app, LOW, "%s (%" PRIu32
724 "): Deleting IP filter "
725 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
726 p->name, p->pmd_id, p->ip_local_q, cp->ip);
729 rte_panic("%s (%" PRIu32
730 "): Error deleting IP filter "
734 p->name, p->pmd_id, p->ip_local_q,
739 if (p->tcp_local_q != 0) {
740 int status = app_link_filter_tcp_del(p, cp);
742 APP_LOG(app, LOW, "%s (%" PRIu32
743 "): Deleting TCP filter "
745 ", IP = 0x%" PRIx32 ")",
746 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
749 rte_panic("%s (%" PRIu32
750 "): Error deleting TCP filter "
754 p->name, p->pmd_id, p->tcp_local_q,
759 if (p->udp_local_q != 0) {
760 int status = app_link_filter_udp_del(p, cp);
762 APP_LOG(app, LOW, "%s (%" PRIu32
763 "): Deleting UDP filter "
764 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
765 p->name, p->pmd_id, p->udp_local_q, cp->ip);
768 rte_panic("%s (%" PRIu32
769 "): Error deleting UDP filter "
773 p->name, p->pmd_id, p->udp_local_q,
778 if (p->sctp_local_q != 0) {
779 int status = app_link_filter_sctp_del(p, cp);
781 APP_LOG(app, LOW, "%s (%" PRIu32
782 "): Deleting SCTP filter "
784 ", IP = 0x%" PRIx32 ")",
785 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
788 rte_panic("%s (%" PRIu32
789 "): Error deleting SCTP filter "
793 p->name, p->pmd_id, p->sctp_local_q,
800 app_check_link(struct app_params *app)
802 uint32_t all_links_up, i;
806 for (i = 0; i < app->n_links; i++) {
807 struct app_link_params *p = &app->link_params[i];
808 struct rte_eth_link link_params;
810 memset(&link_params, 0, sizeof(link_params));
811 rte_eth_link_get(p->pmd_id, &link_params);
813 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
816 link_params.link_speed / 1000,
817 link_params.link_status ? "UP" : "DOWN");
819 if (link_params.link_status == ETH_LINK_DOWN)
823 if (all_links_up == 0)
824 rte_panic("Some links are DOWN\n");
828 is_any_swq_frag_or_ras(struct app_params *app)
832 for (i = 0; i < app->n_pktq_swq; i++) {
833 struct app_pktq_swq_params *p = &app->swq_params[i];
835 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
836 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
844 app_init_link_frag_ras(struct app_params *app)
848 if (is_any_swq_frag_or_ras(app)) {
849 for (i = 0; i < app->n_links; i++) {
850 struct app_link_params *p_link = &app->link_params[i];
851 p_link->conf.txmode.offloads |=
852 DEV_TX_OFFLOAD_MULTI_SEGS;
858 app_get_cpu_socket_id(uint32_t pmd_id)
860 int status = rte_eth_dev_socket_id(pmd_id);
862 return (status != SOCKET_ID_ANY) ? status : 0;
866 app_link_rss_enabled(struct app_link_params *cp)
868 return (cp->n_rss_qs) ? 1 : 0;
872 app_link_rss_setup(struct app_link_params *cp)
874 struct rte_eth_dev_info dev_info;
875 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
880 memset(&dev_info, 0, sizeof(dev_info));
881 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
883 if (dev_info.reta_size == 0)
884 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
885 cp->name, cp->pmd_id);
887 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
888 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
889 cp->name, cp->pmd_id);
891 /* Setup RETA contents */
892 memset(reta_conf, 0, sizeof(reta_conf));
894 for (i = 0; i < dev_info.reta_size; i++)
895 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
897 for (i = 0; i < dev_info.reta_size; i++) {
898 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
899 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
900 uint32_t rss_qs_pos = i % cp->n_rss_qs;
902 reta_conf[reta_id].reta[reta_pos] =
903 (uint16_t) cp->rss_qs[rss_qs_pos];
907 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
911 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
912 cp->name, cp->pmd_id);
916 app_init_link_set_config(struct app_link_params *p)
919 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
920 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
927 app_init_link(struct app_params *app)
931 app_init_link_frag_ras(app);
933 for (i = 0; i < app->n_links; i++) {
934 struct app_link_params *p_link = &app->link_params[i];
935 struct rte_eth_dev_info dev_info;
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 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
953 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
954 p_link->conf.txmode.offloads |=
955 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
956 status = rte_eth_dev_configure(
962 rte_panic("%s (%" PRId32 "): "
963 "init error (%" PRId32 ")\n",
964 p_link->name, p_link->pmd_id, status);
966 rte_eth_macaddr_get(p_link->pmd_id,
967 (struct ether_addr *) &p_link->mac_addr);
970 rte_eth_promiscuous_enable(p_link->pmd_id);
973 for (j = 0; j < app->n_pktq_hwq_in; j++) {
974 struct app_pktq_hwq_in_params *p_rxq =
975 &app->hwq_in_params[j];
976 uint32_t rxq_link_id, rxq_queue_id;
977 uint16_t nb_rxd = p_rxq->size;
979 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
980 &rxq_link_id, &rxq_queue_id);
981 if (rxq_link_id != link_id)
984 status = rte_eth_dev_adjust_nb_rx_tx_desc(
989 rte_panic("%s (%" PRIu32 "): "
990 "%s adjust number of Rx descriptors "
991 "error (%" PRId32 ")\n",
997 p_rxq->conf.offloads = p_link->conf.rxmode.offloads;
998 status = rte_eth_rx_queue_setup(
1002 app_get_cpu_socket_id(p_link->pmd_id),
1004 app->mempool[p_rxq->mempool_id]);
1006 rte_panic("%s (%" PRIu32 "): "
1007 "%s init error (%" PRId32 ")\n",
1015 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1016 struct app_pktq_hwq_out_params *p_txq =
1017 &app->hwq_out_params[j];
1018 uint32_t txq_link_id, txq_queue_id;
1019 uint16_t nb_txd = p_txq->size;
1021 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1022 &txq_link_id, &txq_queue_id);
1023 if (txq_link_id != link_id)
1026 status = rte_eth_dev_adjust_nb_rx_tx_desc(
1031 rte_panic("%s (%" PRIu32 "): "
1032 "%s adjust number of Tx descriptors "
1033 "error (%" PRId32 ")\n",
1039 p_txq->conf.offloads = p_link->conf.txmode.offloads;
1040 status = rte_eth_tx_queue_setup(
1044 app_get_cpu_socket_id(p_link->pmd_id),
1047 rte_panic("%s (%" PRIu32 "): "
1048 "%s init error (%" PRId32 ")\n",
1056 status = rte_eth_dev_start(p_link->pmd_id);
1058 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1059 p_link->name, status);
1062 app_link_set_arp_filter(app, p_link);
1063 app_link_set_tcp_syn_filter(app, p_link);
1064 if (app_link_rss_enabled(p_link))
1065 app_link_rss_setup(p_link);
1068 app_link_up_internal(app, p_link);
1071 app_check_link(app);
1075 app_init_swq(struct app_params *app)
1079 for (i = 0; i < app->n_pktq_swq; i++) {
1080 struct app_pktq_swq_params *p = &app->swq_params[i];
1083 if (app_swq_get_readers(app, p) == 1)
1084 flags |= RING_F_SC_DEQ;
1085 if (app_swq_get_writers(app, p) == 1)
1086 flags |= RING_F_SP_ENQ;
1088 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1089 app->swq[i] = rte_ring_create(
1095 if (app->swq[i] == NULL)
1096 rte_panic("%s init error\n", p->name);
1101 app_init_tm(struct app_params *app)
1105 for (i = 0; i < app->n_pktq_tm; i++) {
1106 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1107 struct app_link_params *p_link;
1108 struct rte_eth_link link_eth_params;
1109 struct rte_sched_port *sched;
1110 uint32_t n_subports, subport_id;
1113 p_link = app_get_link_for_tm(app, p_tm);
1115 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1118 p_tm->sched_port_params.name = p_tm->name;
1119 p_tm->sched_port_params.socket =
1120 app_get_cpu_socket_id(p_link->pmd_id);
1121 p_tm->sched_port_params.rate =
1122 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1124 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1125 sched = rte_sched_port_config(&p_tm->sched_port_params);
1127 rte_panic("%s init error\n", p_tm->name);
1131 n_subports = p_tm->sched_port_params.n_subports_per_port;
1132 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1133 uint32_t n_pipes_per_subport, pipe_id;
1135 status = rte_sched_subport_config(sched,
1137 &p_tm->sched_subport_params[subport_id]);
1139 rte_panic("%s subport %" PRIu32
1140 " init error (%" PRId32 ")\n",
1141 p_tm->name, subport_id, status);
1144 n_pipes_per_subport =
1145 p_tm->sched_port_params.n_pipes_per_subport;
1147 pipe_id < n_pipes_per_subport;
1149 int profile_id = p_tm->sched_pipe_to_profile[
1150 subport_id * APP_MAX_SCHED_PIPES +
1153 if (profile_id == -1)
1156 status = rte_sched_pipe_config(sched,
1161 rte_panic("%s subport %" PRIu32
1163 " (profile %" PRId32 ") "
1164 "init error (% " PRId32 ")\n",
1165 p_tm->name, subport_id, pipe_id,
1166 profile_id, status);
1172 #ifndef RTE_EXEC_ENV_LINUXAPP
1174 app_init_tap(struct app_params *app) {
1175 if (app->n_pktq_tap == 0)
1178 rte_panic("TAP device not supported.\n");
1182 app_init_tap(struct app_params *app)
1186 for (i = 0; i < app->n_pktq_tap; i++) {
1187 struct app_pktq_tap_params *p_tap = &app->tap_params[i];
1191 APP_LOG(app, HIGH, "Initializing %s ...", p_tap->name);
1193 fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
1195 rte_panic("Cannot open file /dev/net/tun\n");
1197 memset(&ifr, 0, sizeof(ifr));
1198 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* No packet information */
1199 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", p_tap->name);
1201 status = ioctl(fd, TUNSETIFF, (void *) &ifr);
1203 rte_panic("TAP setup error\n");
1210 #ifdef RTE_LIBRTE_KNI
1212 kni_config_network_interface(uint16_t port_id, uint8_t if_up) {
1215 if (port_id >= rte_eth_dev_count())
1219 rte_eth_dev_set_link_up(port_id) :
1220 rte_eth_dev_set_link_down(port_id);
1226 kni_change_mtu(uint16_t port_id, unsigned int new_mtu) {
1229 if (port_id >= rte_eth_dev_count())
1232 if (new_mtu > ETHER_MAX_LEN)
1236 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1242 #endif /* RTE_LIBRTE_KNI */
1244 #ifndef RTE_LIBRTE_KNI
1246 app_init_kni(struct app_params *app) {
1247 if (app->n_pktq_kni == 0)
1250 rte_panic("Can not init KNI without librte_kni support.\n");
1254 app_init_kni(struct app_params *app) {
1257 if (app->n_pktq_kni == 0)
1260 rte_kni_init(app->n_pktq_kni);
1262 for (i = 0; i < app->n_pktq_kni; i++) {
1263 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1264 struct app_link_params *p_link;
1265 struct rte_eth_dev_info dev_info;
1266 struct app_mempool_params *mempool_params;
1267 struct rte_mempool *mempool;
1268 struct rte_kni_conf conf;
1269 struct rte_kni_ops ops;
1272 p_link = app_get_link_for_kni(app, p_kni);
1273 memset(&dev_info, 0, sizeof(dev_info));
1274 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1277 mempool_params = &app->mempool_params[p_kni->mempool_id];
1278 mempool = app->mempool[p_kni->mempool_id];
1281 memset(&conf, 0, sizeof(conf));
1282 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1283 conf.force_bind = p_kni->force_bind;
1284 if (conf.force_bind) {
1287 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1290 p_kni->hyper_th_id);
1293 rte_panic("%s invalid CPU core\n", p_kni->name);
1295 conf.core_id = (uint32_t) lcore_id;
1297 conf.group_id = p_link->pmd_id;
1298 conf.mbuf_size = mempool_params->buffer_size;
1299 conf.addr = dev_info.pci_dev->addr;
1300 conf.id = dev_info.pci_dev->id;
1302 memset(&ops, 0, sizeof(ops));
1303 ops.port_id = (uint8_t) p_link->pmd_id;
1304 ops.change_mtu = kni_change_mtu;
1305 ops.config_network_if = kni_config_network_interface;
1307 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1308 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1310 rte_panic("%s init error\n", p_kni->name);
1313 #endif /* RTE_LIBRTE_KNI */
1316 app_init_msgq(struct app_params *app)
1320 for (i = 0; i < app->n_msgq; i++) {
1321 struct app_msgq_params *p = &app->msgq_params[i];
1323 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1324 app->msgq[i] = rte_ring_create(
1328 RING_F_SP_ENQ | RING_F_SC_DEQ);
1330 if (app->msgq[i] == NULL)
1331 rte_panic("%s init error\n", p->name);
1335 void app_pipeline_params_get(struct app_params *app,
1336 struct app_pipeline_params *p_in,
1337 struct pipeline_params *p_out)
1341 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1343 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1345 p_out->socket_id = (int) p_in->socket_id;
1347 p_out->log_level = app->log_level;
1350 p_out->n_ports_in = p_in->n_pktq_in;
1351 for (i = 0; i < p_in->n_pktq_in; i++) {
1352 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1353 struct pipeline_port_in_params *out = &p_out->port_in[i];
1356 case APP_PKTQ_IN_HWQ:
1358 struct app_pktq_hwq_in_params *p_hwq_in =
1359 &app->hwq_in_params[in->id];
1360 struct app_link_params *p_link =
1361 app_get_link_for_rxq(app, p_hwq_in);
1362 uint32_t rxq_link_id, rxq_queue_id;
1364 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1368 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1369 out->params.ethdev.port_id = p_link->pmd_id;
1370 out->params.ethdev.queue_id = rxq_queue_id;
1371 out->burst_size = p_hwq_in->burst;
1374 case APP_PKTQ_IN_SWQ:
1376 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1378 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1379 if (app_swq_get_readers(app, swq_params) == 1) {
1380 out->type = PIPELINE_PORT_IN_RING_READER;
1381 out->params.ring.ring = app->swq[in->id];
1382 out->burst_size = app->swq_params[in->id].burst_read;
1384 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1385 out->params.ring_multi.ring = app->swq[in->id];
1386 out->burst_size = swq_params->burst_read;
1389 if (swq_params->ipv4_frag == 1) {
1390 struct rte_port_ring_reader_ipv4_frag_params *params =
1391 &out->params.ring_ipv4_frag;
1393 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1394 params->ring = app->swq[in->id];
1395 params->mtu = swq_params->mtu;
1396 params->metadata_size = swq_params->metadata_size;
1397 params->pool_direct =
1398 app->mempool[swq_params->mempool_direct_id];
1399 params->pool_indirect =
1400 app->mempool[swq_params->mempool_indirect_id];
1401 out->burst_size = swq_params->burst_read;
1403 struct rte_port_ring_reader_ipv6_frag_params *params =
1404 &out->params.ring_ipv6_frag;
1406 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1407 params->ring = app->swq[in->id];
1408 params->mtu = swq_params->mtu;
1409 params->metadata_size = swq_params->metadata_size;
1410 params->pool_direct =
1411 app->mempool[swq_params->mempool_direct_id];
1412 params->pool_indirect =
1413 app->mempool[swq_params->mempool_indirect_id];
1414 out->burst_size = swq_params->burst_read;
1419 case APP_PKTQ_IN_TM:
1421 out->type = PIPELINE_PORT_IN_SCHED_READER;
1422 out->params.sched.sched = app->tm[in->id];
1423 out->burst_size = app->tm_params[in->id].burst_read;
1426 #ifdef RTE_EXEC_ENV_LINUXAPP
1427 case APP_PKTQ_IN_TAP:
1429 struct app_pktq_tap_params *tap_params =
1430 &app->tap_params[in->id];
1431 struct app_mempool_params *mempool_params =
1432 &app->mempool_params[tap_params->mempool_id];
1433 struct rte_mempool *mempool =
1434 app->mempool[tap_params->mempool_id];
1436 out->type = PIPELINE_PORT_IN_FD_READER;
1437 out->params.fd.fd = app->tap[in->id];
1438 out->params.fd.mtu = mempool_params->buffer_size;
1439 out->params.fd.mempool = mempool;
1440 out->burst_size = app->tap_params[in->id].burst_read;
1444 #ifdef RTE_LIBRTE_KNI
1445 case APP_PKTQ_IN_KNI:
1447 out->type = PIPELINE_PORT_IN_KNI_READER;
1448 out->params.kni.kni = app->kni[in->id];
1449 out->burst_size = app->kni_params[in->id].burst_read;
1452 #endif /* RTE_LIBRTE_KNI */
1453 case APP_PKTQ_IN_SOURCE:
1455 uint32_t mempool_id =
1456 app->source_params[in->id].mempool_id;
1458 out->type = PIPELINE_PORT_IN_SOURCE;
1459 out->params.source.mempool = app->mempool[mempool_id];
1460 out->burst_size = app->source_params[in->id].burst;
1461 out->params.source.file_name =
1462 app->source_params[in->id].file_name;
1463 out->params.source.n_bytes_per_pkt =
1464 app->source_params[in->id].n_bytes_per_pkt;
1473 p_out->n_ports_out = p_in->n_pktq_out;
1474 for (i = 0; i < p_in->n_pktq_out; i++) {
1475 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1476 struct pipeline_port_out_params *out = &p_out->port_out[i];
1479 case APP_PKTQ_OUT_HWQ:
1481 struct app_pktq_hwq_out_params *p_hwq_out =
1482 &app->hwq_out_params[in->id];
1483 struct app_link_params *p_link =
1484 app_get_link_for_txq(app, p_hwq_out);
1485 uint32_t txq_link_id, txq_queue_id;
1487 sscanf(p_hwq_out->name,
1488 "TXQ%" SCNu32 ".%" SCNu32,
1492 if (p_hwq_out->dropless == 0) {
1493 struct rte_port_ethdev_writer_params *params =
1494 &out->params.ethdev;
1496 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1497 params->port_id = p_link->pmd_id;
1498 params->queue_id = txq_queue_id;
1499 params->tx_burst_sz =
1500 app->hwq_out_params[in->id].burst;
1502 struct rte_port_ethdev_writer_nodrop_params
1503 *params = &out->params.ethdev_nodrop;
1506 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1507 params->port_id = p_link->pmd_id;
1508 params->queue_id = txq_queue_id;
1509 params->tx_burst_sz = p_hwq_out->burst;
1510 params->n_retries = p_hwq_out->n_retries;
1514 case APP_PKTQ_OUT_SWQ:
1516 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1518 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1519 if (app_swq_get_writers(app, swq_params) == 1) {
1520 if (app->swq_params[in->id].dropless == 0) {
1521 struct rte_port_ring_writer_params *params =
1524 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1525 params->ring = app->swq[in->id];
1526 params->tx_burst_sz =
1527 app->swq_params[in->id].burst_write;
1529 struct rte_port_ring_writer_nodrop_params
1530 *params = &out->params.ring_nodrop;
1533 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1534 params->ring = app->swq[in->id];
1535 params->tx_burst_sz =
1536 app->swq_params[in->id].burst_write;
1538 app->swq_params[in->id].n_retries;
1541 if (swq_params->dropless == 0) {
1542 struct rte_port_ring_multi_writer_params *params =
1543 &out->params.ring_multi;
1545 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1546 params->ring = app->swq[in->id];
1547 params->tx_burst_sz = swq_params->burst_write;
1549 struct rte_port_ring_multi_writer_nodrop_params
1550 *params = &out->params.ring_multi_nodrop;
1552 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1553 params->ring = app->swq[in->id];
1554 params->tx_burst_sz = swq_params->burst_write;
1555 params->n_retries = swq_params->n_retries;
1559 if (swq_params->ipv4_ras == 1) {
1560 struct rte_port_ring_writer_ipv4_ras_params *params =
1561 &out->params.ring_ipv4_ras;
1563 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1564 params->ring = app->swq[in->id];
1565 params->tx_burst_sz = swq_params->burst_write;
1567 struct rte_port_ring_writer_ipv6_ras_params *params =
1568 &out->params.ring_ipv6_ras;
1570 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1571 params->ring = app->swq[in->id];
1572 params->tx_burst_sz = swq_params->burst_write;
1577 case APP_PKTQ_OUT_TM:
1579 struct rte_port_sched_writer_params *params =
1582 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1583 params->sched = app->tm[in->id];
1584 params->tx_burst_sz =
1585 app->tm_params[in->id].burst_write;
1588 #ifdef RTE_EXEC_ENV_LINUXAPP
1589 case APP_PKTQ_OUT_TAP:
1591 struct rte_port_fd_writer_params *params =
1594 out->type = PIPELINE_PORT_OUT_FD_WRITER;
1595 params->fd = app->tap[in->id];
1596 params->tx_burst_sz =
1597 app->tap_params[in->id].burst_write;
1601 #ifdef RTE_LIBRTE_KNI
1602 case APP_PKTQ_OUT_KNI:
1604 struct app_pktq_kni_params *p_kni =
1605 &app->kni_params[in->id];
1607 if (p_kni->dropless == 0) {
1608 struct rte_port_kni_writer_params *params =
1611 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1612 params->kni = app->kni[in->id];
1613 params->tx_burst_sz =
1614 app->kni_params[in->id].burst_write;
1616 struct rte_port_kni_writer_nodrop_params
1617 *params = &out->params.kni_nodrop;
1619 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1620 params->kni = app->kni[in->id];
1621 params->tx_burst_sz =
1622 app->kni_params[in->id].burst_write;
1624 app->kni_params[in->id].n_retries;
1628 #endif /* RTE_LIBRTE_KNI */
1629 case APP_PKTQ_OUT_SINK:
1631 out->type = PIPELINE_PORT_OUT_SINK;
1632 out->params.sink.file_name =
1633 app->sink_params[in->id].file_name;
1634 out->params.sink.max_n_pkts =
1635 app->sink_params[in->id].
1646 p_out->n_msgq = p_in->n_msgq_in;
1648 for (i = 0; i < p_in->n_msgq_in; i++)
1649 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1651 for (i = 0; i < p_in->n_msgq_out; i++)
1652 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1655 p_out->n_args = p_in->n_args;
1656 for (i = 0; i < p_in->n_args; i++) {
1657 p_out->args_name[i] = p_in->args_name[i];
1658 p_out->args_value[i] = p_in->args_value[i];
1663 app_init_pipelines(struct app_params *app)
1667 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1668 struct app_pipeline_params *params =
1669 &app->pipeline_params[p_id];
1670 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1671 struct pipeline_type *ptype;
1672 struct pipeline_params pp;
1674 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1676 ptype = app_pipeline_type_find(app, params->type);
1678 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1681 app_pipeline_params_get(app, params, &pp);
1685 if (ptype->be_ops->f_init) {
1686 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1688 if (data->be == NULL)
1689 rte_panic("Pipeline instance \"%s\" back-end "
1690 "init error\n", params->name);
1695 if (ptype->fe_ops->f_init) {
1696 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1698 if (data->fe == NULL)
1699 rte_panic("Pipeline instance \"%s\" front-end "
1700 "init error\n", params->name);
1703 data->ptype = ptype;
1705 data->timer_period = (rte_get_tsc_hz() *
1706 params->timer_period) / 1000;
1711 app_post_init_pipelines(struct app_params *app)
1715 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1716 struct app_pipeline_params *params =
1717 &app->pipeline_params[p_id];
1718 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1721 if (data->ptype->fe_ops->f_post_init == NULL)
1724 status = data->ptype->fe_ops->f_post_init(data->fe);
1726 rte_panic("Pipeline instance \"%s\" front-end "
1727 "post-init error\n", params->name);
1732 app_init_threads(struct app_params *app)
1734 uint64_t time = rte_get_tsc_cycles();
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];
1741 struct pipeline_type *ptype;
1742 struct app_thread_data *t;
1743 struct app_thread_pipeline_data *p;
1746 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1749 params->hyper_th_id);
1752 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1755 (params->hyper_th_id) ? "h" : "");
1757 t = &app->thread_data[lcore_id];
1759 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1760 t->thread_req_deadline = time + t->timer_period;
1762 t->headroom_cycles = 0;
1763 t->headroom_time = rte_get_tsc_cycles();
1764 t->headroom_ratio = 0.0;
1766 t->msgq_in = app_thread_msgq_in_get(app,
1769 params->hyper_th_id);
1770 if (t->msgq_in == NULL)
1771 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1774 t->msgq_out = app_thread_msgq_out_get(app,
1777 params->hyper_th_id);
1778 if (t->msgq_out == NULL)
1779 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1782 ptype = app_pipeline_type_find(app, params->type);
1784 rte_panic("Init error: Unknown pipeline "
1785 "type \"%s\"\n", params->type);
1787 p = (ptype->be_ops->f_run == NULL) ?
1788 &t->regular[t->n_regular] :
1789 &t->custom[t->n_custom];
1791 p->pipeline_id = p_id;
1793 p->f_run = ptype->be_ops->f_run;
1794 p->f_timer = ptype->be_ops->f_timer;
1795 p->timer_period = data->timer_period;
1796 p->deadline = time + data->timer_period;
1800 if (ptype->be_ops->f_run == NULL)
1807 int app_init(struct app_params *app)
1809 app_init_core_map(app);
1810 app_init_core_mask(app);
1813 app_init_mempool(app);
1821 app_pipeline_common_cmd_push(app);
1822 app_pipeline_thread_cmd_push(app);
1823 app_pipeline_type_register(app, &pipeline_master);
1824 app_pipeline_type_register(app, &pipeline_flow_classification);
1825 app_pipeline_type_register(app, &pipeline_flow_actions);
1826 app_pipeline_type_register(app, &pipeline_firewall);
1827 app_pipeline_type_register(app, &pipeline_routing);
1829 app_init_pipelines(app);
1830 app_init_threads(app);
1835 int app_post_init(struct app_params *app)
1837 app_post_init_pipelines(app);
1843 app_pipeline_type_cmd_push(struct app_params *app,
1844 struct pipeline_type *ptype)
1846 cmdline_parse_ctx_t *cmds;
1849 /* Check input arguments */
1850 if ((app == NULL) ||
1854 n_cmds = pipeline_type_cmds_count(ptype);
1858 cmds = ptype->fe_ops->cmds;
1860 /* Check for available slots in the application commands array */
1861 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1864 /* Push pipeline commands into the application */
1865 memcpy(&app->cmds[app->n_cmds],
1867 n_cmds * sizeof(cmdline_parse_ctx_t));
1869 for (i = 0; i < n_cmds; i++)
1870 app->cmds[app->n_cmds + i]->data = app;
1872 app->n_cmds += n_cmds;
1873 app->cmds[app->n_cmds] = NULL;
1879 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1883 /* Check input arguments */
1884 if ((app == NULL) ||
1886 (ptype->name == NULL) ||
1887 (strlen(ptype->name) == 0) ||
1888 (ptype->be_ops->f_init == NULL) ||
1889 (ptype->be_ops->f_timer == NULL))
1892 /* Check for duplicate entry */
1893 for (i = 0; i < app->n_pipeline_types; i++)
1894 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1897 /* Check for resource availability */
1898 n_cmds = pipeline_type_cmds_count(ptype);
1899 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1900 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1903 /* Copy pipeline type */
1904 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1906 sizeof(struct pipeline_type));
1908 /* Copy CLI commands */
1910 app_pipeline_type_cmd_push(app, ptype);
1916 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1920 for (i = 0; i < app->n_pipeline_types; i++)
1921 if (strcmp(app->pipeline_type[i].name, name) == 0)
1922 return &app->pipeline_type[i];