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.
38 #include <rte_cycles.h>
39 #include <rte_ethdev.h>
40 #include <rte_ether.h>
43 #include <rte_malloc.h>
47 #include "pipeline_common_fe.h"
48 #include "pipeline_master.h"
49 #include "pipeline_passthrough.h"
50 #include "pipeline_firewall.h"
51 #include "pipeline_flow_classification.h"
52 #include "pipeline_flow_actions.h"
53 #include "pipeline_routing.h"
54 #include "thread_fe.h"
56 #define APP_NAME_SIZE 32
58 #define APP_RETA_SIZE_MAX (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE)
61 app_init_core_map(struct app_params *app)
63 APP_LOG(app, HIGH, "Initializing CPU core map ...");
64 app->core_map = cpu_core_map_init(4, 32, 4, 0);
66 if (app->core_map == NULL)
67 rte_panic("Cannot create CPU core map\n");
69 if (app->log_level >= APP_LOG_LEVEL_LOW)
70 cpu_core_map_print(app->core_map);
74 app_init_core_mask(struct app_params *app)
79 for (i = 0; i < app->n_pipelines; i++) {
80 struct app_pipeline_params *p = &app->pipeline_params[i];
83 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
89 rte_panic("Cannot create CPU core mask\n");
91 mask |= 1LLU << lcore_id;
94 app->core_mask = mask;
95 APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
99 app_init_eal(struct app_params *app)
102 struct app_eal_params *p = &app->eal_params;
107 app->eal_argv[n_args++] = strdup(app->app_name);
109 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
110 app->eal_argv[n_args++] = strdup(buffer);
113 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
114 app->eal_argv[n_args++] = strdup(buffer);
117 if (p->master_lcore_present) {
120 "--master-lcore=%" PRIu32,
122 app->eal_argv[n_args++] = strdup(buffer);
125 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
126 app->eal_argv[n_args++] = strdup(buffer);
128 if (p->memory_present) {
129 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
130 app->eal_argv[n_args++] = strdup(buffer);
133 if (p->ranks_present) {
134 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
135 app->eal_argv[n_args++] = strdup(buffer);
138 for (i = 0; i < APP_MAX_LINKS; i++) {
139 if (p->pci_blacklist[i] == NULL)
144 "--pci-blacklist=%s",
145 p->pci_blacklist[i]);
146 app->eal_argv[n_args++] = strdup(buffer);
149 if (app->port_mask != 0)
150 for (i = 0; i < APP_MAX_LINKS; i++) {
151 if (p->pci_whitelist[i] == NULL)
156 "--pci-whitelist=%s",
157 p->pci_whitelist[i]);
158 app->eal_argv[n_args++] = strdup(buffer);
161 for (i = 0; i < app->n_links; i++) {
162 char *pci_bdf = app->link_params[i].pci_bdf;
166 "--pci-whitelist=%s",
168 app->eal_argv[n_args++] = strdup(buffer);
171 for (i = 0; i < APP_MAX_LINKS; i++) {
172 if (p->vdev[i] == NULL)
179 app->eal_argv[n_args++] = strdup(buffer);
182 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
183 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
184 app->eal_argv[n_args++] = strdup(buffer);
192 app->eal_argv[n_args++] = strdup(buffer);
196 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
197 app->eal_argv[n_args++] = strdup(buffer);
200 if (p->log_level_present) {
203 "--log-level=%" PRIu32,
205 app->eal_argv[n_args++] = strdup(buffer);
208 if ((p->version_present) && p->version) {
209 snprintf(buffer, sizeof(buffer), "-v");
210 app->eal_argv[n_args++] = strdup(buffer);
213 if ((p->help_present) && p->help) {
214 snprintf(buffer, sizeof(buffer), "--help");
215 app->eal_argv[n_args++] = strdup(buffer);
218 if ((p->no_huge_present) && p->no_huge) {
219 snprintf(buffer, sizeof(buffer), "--no-huge");
220 app->eal_argv[n_args++] = strdup(buffer);
223 if ((p->no_pci_present) && p->no_pci) {
224 snprintf(buffer, sizeof(buffer), "--no-pci");
225 app->eal_argv[n_args++] = strdup(buffer);
228 if ((p->no_hpet_present) && p->no_hpet) {
229 snprintf(buffer, sizeof(buffer), "--no-hpet");
230 app->eal_argv[n_args++] = strdup(buffer);
233 if ((p->no_shconf_present) && p->no_shconf) {
234 snprintf(buffer, sizeof(buffer), "--no-shconf");
235 app->eal_argv[n_args++] = strdup(buffer);
239 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
240 app->eal_argv[n_args++] = strdup(buffer);
248 app->eal_argv[n_args++] = strdup(buffer);
252 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
253 app->eal_argv[n_args++] = strdup(buffer);
256 if (p->file_prefix) {
261 app->eal_argv[n_args++] = strdup(buffer);
264 if (p->base_virtaddr) {
267 "--base-virtaddr=%s",
269 app->eal_argv[n_args++] = strdup(buffer);
272 if ((p->create_uio_dev_present) && p->create_uio_dev) {
273 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
274 app->eal_argv[n_args++] = strdup(buffer);
282 app->eal_argv[n_args++] = strdup(buffer);
285 if ((p->xen_dom0_present) && (p->xen_dom0)) {
286 snprintf(buffer, sizeof(buffer), "--xen-dom0");
287 app->eal_argv[n_args++] = strdup(buffer);
290 snprintf(buffer, sizeof(buffer), "--");
291 app->eal_argv[n_args++] = strdup(buffer);
293 app->eal_argc = n_args;
295 APP_LOG(app, HIGH, "Initializing EAL ...");
296 if (app->log_level >= APP_LOG_LEVEL_LOW) {
299 fprintf(stdout, "[APP] EAL arguments: \"");
300 for (i = 1; i < app->eal_argc; i++)
301 fprintf(stdout, "%s ", app->eal_argv[i]);
302 fprintf(stdout, "\"\n");
305 status = rte_eal_init(app->eal_argc, app->eal_argv);
307 rte_panic("EAL init error\n");
311 app_init_mempool(struct app_params *app)
315 for (i = 0; i < app->n_mempools; i++) {
316 struct app_mempool_params *p = &app->mempool_params[i];
318 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
319 app->mempool[i] = rte_mempool_create(
324 sizeof(struct rte_pktmbuf_pool_private),
325 rte_pktmbuf_pool_init, NULL,
326 rte_pktmbuf_init, NULL,
330 if (app->mempool[i] == NULL)
331 rte_panic("%s init error\n", p->name);
336 app_link_filter_arp_add(struct app_link_params *link)
338 struct rte_eth_ethertype_filter filter = {
339 .ether_type = ETHER_TYPE_ARP,
341 .queue = link->arp_q,
344 return rte_eth_dev_filter_ctrl(link->pmd_id,
345 RTE_ETH_FILTER_ETHERTYPE,
351 app_link_filter_tcp_syn_add(struct app_link_params *link)
353 struct rte_eth_syn_filter filter = {
355 .queue = link->tcp_syn_q,
358 return rte_eth_dev_filter_ctrl(link->pmd_id,
365 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
367 struct rte_eth_ntuple_filter filter = {
368 .flags = RTE_5TUPLE_FLAGS,
369 .dst_ip = rte_bswap32(l2->ip),
370 .dst_ip_mask = UINT32_MAX, /* Enable */
372 .src_ip_mask = 0, /* Disable */
374 .dst_port_mask = 0, /* Disable */
376 .src_port_mask = 0, /* Disable */
378 .proto_mask = 0, /* Disable */
380 .priority = 1, /* Lowest */
381 .queue = l1->ip_local_q,
384 return rte_eth_dev_filter_ctrl(l1->pmd_id,
385 RTE_ETH_FILTER_NTUPLE,
391 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
393 struct rte_eth_ntuple_filter filter = {
394 .flags = RTE_5TUPLE_FLAGS,
395 .dst_ip = rte_bswap32(l2->ip),
396 .dst_ip_mask = UINT32_MAX, /* Enable */
398 .src_ip_mask = 0, /* Disable */
400 .dst_port_mask = 0, /* Disable */
402 .src_port_mask = 0, /* Disable */
404 .proto_mask = 0, /* Disable */
406 .priority = 1, /* Lowest */
407 .queue = l1->ip_local_q,
410 return rte_eth_dev_filter_ctrl(l1->pmd_id,
411 RTE_ETH_FILTER_NTUPLE,
412 RTE_ETH_FILTER_DELETE,
417 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
419 struct rte_eth_ntuple_filter filter = {
420 .flags = RTE_5TUPLE_FLAGS,
421 .dst_ip = rte_bswap32(l2->ip),
422 .dst_ip_mask = UINT32_MAX, /* Enable */
424 .src_ip_mask = 0, /* Disable */
426 .dst_port_mask = 0, /* Disable */
428 .src_port_mask = 0, /* Disable */
429 .proto = IPPROTO_TCP,
430 .proto_mask = UINT8_MAX, /* Enable */
432 .priority = 2, /* Higher priority than IP */
433 .queue = l1->tcp_local_q,
436 return rte_eth_dev_filter_ctrl(l1->pmd_id,
437 RTE_ETH_FILTER_NTUPLE,
443 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
445 struct rte_eth_ntuple_filter filter = {
446 .flags = RTE_5TUPLE_FLAGS,
447 .dst_ip = rte_bswap32(l2->ip),
448 .dst_ip_mask = UINT32_MAX, /* Enable */
450 .src_ip_mask = 0, /* Disable */
452 .dst_port_mask = 0, /* Disable */
454 .src_port_mask = 0, /* Disable */
455 .proto = IPPROTO_TCP,
456 .proto_mask = UINT8_MAX, /* Enable */
458 .priority = 2, /* Higher priority than IP */
459 .queue = l1->tcp_local_q,
462 return rte_eth_dev_filter_ctrl(l1->pmd_id,
463 RTE_ETH_FILTER_NTUPLE,
464 RTE_ETH_FILTER_DELETE,
469 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
471 struct rte_eth_ntuple_filter filter = {
472 .flags = RTE_5TUPLE_FLAGS,
473 .dst_ip = rte_bswap32(l2->ip),
474 .dst_ip_mask = UINT32_MAX, /* Enable */
476 .src_ip_mask = 0, /* Disable */
478 .dst_port_mask = 0, /* Disable */
480 .src_port_mask = 0, /* Disable */
481 .proto = IPPROTO_UDP,
482 .proto_mask = UINT8_MAX, /* Enable */
484 .priority = 2, /* Higher priority than IP */
485 .queue = l1->udp_local_q,
488 return rte_eth_dev_filter_ctrl(l1->pmd_id,
489 RTE_ETH_FILTER_NTUPLE,
495 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
497 struct rte_eth_ntuple_filter filter = {
498 .flags = RTE_5TUPLE_FLAGS,
499 .dst_ip = rte_bswap32(l2->ip),
500 .dst_ip_mask = UINT32_MAX, /* Enable */
502 .src_ip_mask = 0, /* Disable */
504 .dst_port_mask = 0, /* Disable */
506 .src_port_mask = 0, /* Disable */
507 .proto = IPPROTO_UDP,
508 .proto_mask = UINT8_MAX, /* Enable */
510 .priority = 2, /* Higher priority than IP */
511 .queue = l1->udp_local_q,
514 return rte_eth_dev_filter_ctrl(l1->pmd_id,
515 RTE_ETH_FILTER_NTUPLE,
516 RTE_ETH_FILTER_DELETE,
521 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
523 struct rte_eth_ntuple_filter filter = {
524 .flags = RTE_5TUPLE_FLAGS,
525 .dst_ip = rte_bswap32(l2->ip),
526 .dst_ip_mask = UINT32_MAX, /* Enable */
528 .src_ip_mask = 0, /* Disable */
530 .dst_port_mask = 0, /* Disable */
532 .src_port_mask = 0, /* Disable */
533 .proto = IPPROTO_SCTP,
534 .proto_mask = UINT8_MAX, /* Enable */
536 .priority = 2, /* Higher priority than IP */
537 .queue = l1->sctp_local_q,
540 return rte_eth_dev_filter_ctrl(l1->pmd_id,
541 RTE_ETH_FILTER_NTUPLE,
547 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
549 struct rte_eth_ntuple_filter filter = {
550 .flags = RTE_5TUPLE_FLAGS,
551 .dst_ip = rte_bswap32(l2->ip),
552 .dst_ip_mask = UINT32_MAX, /* Enable */
554 .src_ip_mask = 0, /* Disable */
556 .dst_port_mask = 0, /* Disable */
558 .src_port_mask = 0, /* Disable */
559 .proto = IPPROTO_SCTP,
560 .proto_mask = UINT8_MAX, /* Enable */
562 .priority = 2, /* Higher priority than IP */
563 .queue = l1->sctp_local_q,
566 return rte_eth_dev_filter_ctrl(l1->pmd_id,
567 RTE_ETH_FILTER_NTUPLE,
568 RTE_ETH_FILTER_DELETE,
573 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
575 if (cp->arp_q != 0) {
576 int status = app_link_filter_arp_add(cp);
578 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
579 "Adding ARP filter (queue = %" PRIu32 ")",
580 cp->name, cp->pmd_id, cp->arp_q);
583 rte_panic("%s (%" PRIu32 "): "
584 "Error adding ARP filter "
585 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
586 cp->name, cp->pmd_id, cp->arp_q, status);
591 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
593 if (cp->tcp_syn_q != 0) {
594 int status = app_link_filter_tcp_syn_add(cp);
596 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
597 "Adding TCP SYN filter (queue = %" PRIu32 ")",
598 cp->name, cp->pmd_id, cp->tcp_syn_q);
601 rte_panic("%s (%" PRIu32 "): "
602 "Error adding TCP SYN filter "
603 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
604 cp->name, cp->pmd_id, cp->tcp_syn_q,
610 app_link_is_virtual(struct app_link_params *p)
612 uint32_t pmd_id = p->pmd_id;
613 struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
615 if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
622 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
627 if (app_link_is_virtual(cp)) {
632 /* For each link, add filters for IP of current link */
634 for (i = 0; i < app->n_links; i++) {
635 struct app_link_params *p = &app->link_params[i];
638 if (p->ip_local_q != 0) {
639 int status = app_link_filter_ip_add(p, cp);
641 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
642 "Adding IP filter (queue= %" PRIu32
643 ", IP = 0x%08" PRIx32 ")",
644 p->name, p->pmd_id, p->ip_local_q,
648 rte_panic("%s (%" PRIu32 "): "
650 "filter (queue= %" PRIu32 ", "
654 p->ip_local_q, cp->ip, status);
658 if (p->tcp_local_q != 0) {
659 int status = app_link_filter_tcp_add(p, cp);
661 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
664 ", IP = 0x%08" PRIx32 ")",
665 p->name, p->pmd_id, p->tcp_local_q,
669 rte_panic("%s (%" PRIu32 "): "
671 "filter (queue = %" PRIu32 ", "
675 p->tcp_local_q, cp->ip, status);
679 if (p->udp_local_q != 0) {
680 int status = app_link_filter_udp_add(p, cp);
682 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
685 ", IP = 0x%08" PRIx32 ")",
686 p->name, p->pmd_id, p->udp_local_q,
690 rte_panic("%s (%" PRIu32 "): "
692 "filter (queue = %" PRIu32 ", "
696 p->udp_local_q, cp->ip, status);
700 if (p->sctp_local_q != 0) {
701 int status = app_link_filter_sctp_add(p, cp);
703 APP_LOG(app, LOW, "%s (%" PRIu32
704 "): Adding SCTP filter "
706 ", IP = 0x%08" PRIx32 ")",
707 p->name, p->pmd_id, p->sctp_local_q,
711 rte_panic("%s (%" PRIu32 "): "
713 "filter (queue = %" PRIu32 ", "
717 p->sctp_local_q, cp->ip,
724 status = rte_eth_dev_set_link_up(cp->pmd_id);
726 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
727 PRId32 "\n", cp->name, cp->pmd_id, status);
729 /* Mark link as UP */
734 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
739 if (app_link_is_virtual(cp)) {
745 status = rte_eth_dev_set_link_down(cp->pmd_id);
747 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
748 PRId32 "\n", cp->name, cp->pmd_id, status);
750 /* Mark link as DOWN */
753 /* Return if current link IP is not valid */
757 /* For each link, remove filters for IP of current link */
758 for (i = 0; i < app->n_links; i++) {
759 struct app_link_params *p = &app->link_params[i];
762 if (p->ip_local_q != 0) {
763 int status = app_link_filter_ip_del(p, cp);
765 APP_LOG(app, LOW, "%s (%" PRIu32
766 "): Deleting IP filter "
767 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
768 p->name, p->pmd_id, p->ip_local_q, cp->ip);
771 rte_panic("%s (%" PRIu32
772 "): Error deleting IP filter "
776 p->name, p->pmd_id, p->ip_local_q,
781 if (p->tcp_local_q != 0) {
782 int status = app_link_filter_tcp_del(p, cp);
784 APP_LOG(app, LOW, "%s (%" PRIu32
785 "): Deleting TCP filter "
787 ", IP = 0x%" PRIx32 ")",
788 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
791 rte_panic("%s (%" PRIu32
792 "): Error deleting TCP filter "
796 p->name, p->pmd_id, p->tcp_local_q,
801 if (p->udp_local_q != 0) {
802 int status = app_link_filter_udp_del(p, cp);
804 APP_LOG(app, LOW, "%s (%" PRIu32
805 "): Deleting UDP filter "
806 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
807 p->name, p->pmd_id, p->udp_local_q, cp->ip);
810 rte_panic("%s (%" PRIu32
811 "): Error deleting UDP filter "
815 p->name, p->pmd_id, p->udp_local_q,
820 if (p->sctp_local_q != 0) {
821 int status = app_link_filter_sctp_del(p, cp);
823 APP_LOG(app, LOW, "%s (%" PRIu32
824 "): Deleting SCTP filter "
826 ", IP = 0x%" PRIx32 ")",
827 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
830 rte_panic("%s (%" PRIu32
831 "): Error deleting SCTP filter "
835 p->name, p->pmd_id, p->sctp_local_q,
842 app_check_link(struct app_params *app)
844 uint32_t all_links_up, i;
848 for (i = 0; i < app->n_links; i++) {
849 struct app_link_params *p = &app->link_params[i];
850 struct rte_eth_link link_params;
852 memset(&link_params, 0, sizeof(link_params));
853 rte_eth_link_get(p->pmd_id, &link_params);
855 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
858 link_params.link_speed / 1000,
859 link_params.link_status ? "UP" : "DOWN");
861 if (link_params.link_status == ETH_LINK_DOWN)
865 if (all_links_up == 0)
866 rte_panic("Some links are DOWN\n");
870 is_any_swq_frag_or_ras(struct app_params *app)
874 for (i = 0; i < app->n_pktq_swq; i++) {
875 struct app_pktq_swq_params *p = &app->swq_params[i];
877 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
878 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
886 app_init_link_frag_ras(struct app_params *app)
890 if (is_any_swq_frag_or_ras(app)) {
891 for (i = 0; i < app->n_pktq_hwq_out; i++) {
892 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
894 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
900 app_get_cpu_socket_id(uint32_t pmd_id)
902 int status = rte_eth_dev_socket_id(pmd_id);
904 return (status != SOCKET_ID_ANY) ? status : 0;
908 app_link_rss_enabled(struct app_link_params *cp)
910 return (cp->n_rss_qs) ? 1 : 0;
914 app_link_rss_setup(struct app_link_params *cp)
916 struct rte_eth_dev_info dev_info;
917 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
922 memset(&dev_info, 0, sizeof(dev_info));
923 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
925 if (dev_info.reta_size == 0)
926 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
927 cp->name, cp->pmd_id);
929 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
930 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
931 cp->name, cp->pmd_id);
933 /* Setup RETA contents */
934 memset(reta_conf, 0, sizeof(reta_conf));
936 for (i = 0; i < dev_info.reta_size; i++)
937 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
939 for (i = 0; i < dev_info.reta_size; i++) {
940 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
941 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
942 uint32_t rss_qs_pos = i % cp->n_rss_qs;
944 reta_conf[reta_id].reta[reta_pos] =
945 (uint16_t) cp->rss_qs[rss_qs_pos];
949 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
953 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
954 cp->name, cp->pmd_id);
958 app_init_link_set_config(struct app_link_params *p)
961 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
962 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
969 app_init_link(struct app_params *app)
973 app_init_link_frag_ras(app);
975 for (i = 0; i < app->n_links; i++) {
976 struct app_link_params *p_link = &app->link_params[i];
977 uint32_t link_id, n_hwq_in, n_hwq_out, j;
980 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
981 n_hwq_in = app_link_get_n_rxq(app, p_link);
982 n_hwq_out = app_link_get_n_txq(app, p_link);
983 app_init_link_set_config(p_link);
985 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
986 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
993 status = rte_eth_dev_configure(
999 rte_panic("%s (%" PRId32 "): "
1000 "init error (%" PRId32 ")\n",
1001 p_link->name, p_link->pmd_id, status);
1003 rte_eth_macaddr_get(p_link->pmd_id,
1004 (struct ether_addr *) &p_link->mac_addr);
1006 if (p_link->promisc)
1007 rte_eth_promiscuous_enable(p_link->pmd_id);
1010 for (j = 0; j < app->n_pktq_hwq_in; j++) {
1011 struct app_pktq_hwq_in_params *p_rxq =
1012 &app->hwq_in_params[j];
1013 uint32_t rxq_link_id, rxq_queue_id;
1015 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
1016 &rxq_link_id, &rxq_queue_id);
1017 if (rxq_link_id != link_id)
1020 status = rte_eth_rx_queue_setup(
1024 app_get_cpu_socket_id(p_link->pmd_id),
1026 app->mempool[p_rxq->mempool_id]);
1028 rte_panic("%s (%" PRIu32 "): "
1029 "%s init error (%" PRId32 ")\n",
1037 for (j = 0; j < app->n_pktq_hwq_out; j++) {
1038 struct app_pktq_hwq_out_params *p_txq =
1039 &app->hwq_out_params[j];
1040 uint32_t txq_link_id, txq_queue_id;
1042 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1043 &txq_link_id, &txq_queue_id);
1044 if (txq_link_id != link_id)
1047 status = rte_eth_tx_queue_setup(
1051 app_get_cpu_socket_id(p_link->pmd_id),
1054 rte_panic("%s (%" PRIu32 "): "
1055 "%s init error (%" PRId32 ")\n",
1063 status = rte_eth_dev_start(p_link->pmd_id);
1065 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1066 p_link->name, status);
1069 app_link_set_arp_filter(app, p_link);
1070 app_link_set_tcp_syn_filter(app, p_link);
1071 if (app_link_rss_enabled(p_link))
1072 app_link_rss_setup(p_link);
1075 app_link_up_internal(app, p_link);
1078 app_check_link(app);
1082 app_init_swq(struct app_params *app)
1086 for (i = 0; i < app->n_pktq_swq; i++) {
1087 struct app_pktq_swq_params *p = &app->swq_params[i];
1090 if (app_swq_get_readers(app, p) == 1)
1091 flags |= RING_F_SC_DEQ;
1092 if (app_swq_get_writers(app, p) == 1)
1093 flags |= RING_F_SP_ENQ;
1095 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1096 app->swq[i] = rte_ring_create(
1102 if (app->swq[i] == NULL)
1103 rte_panic("%s init error\n", p->name);
1108 app_init_tm(struct app_params *app)
1112 for (i = 0; i < app->n_pktq_tm; i++) {
1113 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1114 struct app_link_params *p_link;
1115 struct rte_eth_link link_eth_params;
1116 struct rte_sched_port *sched;
1117 uint32_t n_subports, subport_id;
1120 p_link = app_get_link_for_tm(app, p_tm);
1122 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1125 p_tm->sched_port_params.name = p_tm->name;
1126 p_tm->sched_port_params.socket =
1127 app_get_cpu_socket_id(p_link->pmd_id);
1128 p_tm->sched_port_params.rate =
1129 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1131 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1132 sched = rte_sched_port_config(&p_tm->sched_port_params);
1134 rte_panic("%s init error\n", p_tm->name);
1138 n_subports = p_tm->sched_port_params.n_subports_per_port;
1139 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1140 uint32_t n_pipes_per_subport, pipe_id;
1142 status = rte_sched_subport_config(sched,
1144 &p_tm->sched_subport_params[subport_id]);
1146 rte_panic("%s subport %" PRIu32
1147 " init error (%" PRId32 ")\n",
1148 p_tm->name, subport_id, status);
1151 n_pipes_per_subport =
1152 p_tm->sched_port_params.n_pipes_per_subport;
1154 pipe_id < n_pipes_per_subport;
1156 int profile_id = p_tm->sched_pipe_to_profile[
1157 subport_id * APP_MAX_SCHED_PIPES +
1160 if (profile_id == -1)
1163 status = rte_sched_pipe_config(sched,
1168 rte_panic("%s subport %" PRIu32
1170 " (profile %" PRId32 ") "
1171 "init error (% " PRId32 ")\n",
1172 p_tm->name, subport_id, pipe_id,
1173 profile_id, status);
1179 #ifdef RTE_LIBRTE_KNI
1181 kni_config_network_interface(uint8_t port_id, uint8_t if_up) {
1184 if (port_id >= rte_eth_dev_count())
1188 rte_eth_dev_set_link_up(port_id) :
1189 rte_eth_dev_set_link_down(port_id);
1195 kni_change_mtu(uint8_t port_id, unsigned new_mtu) {
1198 if (port_id >= rte_eth_dev_count())
1201 if (new_mtu > ETHER_MAX_LEN)
1205 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1211 #endif /* RTE_LIBRTE_KNI */
1213 #ifndef RTE_LIBRTE_KNI
1215 app_init_kni(struct app_params *app) {
1216 if (app->n_pktq_kni == 0)
1219 rte_panic("Can not init KNI without librte_kni support.\n");
1223 app_init_kni(struct app_params *app) {
1226 if (app->n_pktq_kni == 0)
1229 rte_kni_init(app->n_pktq_kni);
1231 for (i = 0; i < app->n_pktq_kni; i++) {
1232 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1233 struct app_link_params *p_link;
1234 struct rte_eth_dev_info dev_info;
1235 struct app_mempool_params *mempool_params;
1236 struct rte_mempool *mempool;
1237 struct rte_kni_conf conf;
1238 struct rte_kni_ops ops;
1241 p_link = app_get_link_for_kni(app, p_kni);
1242 memset(&dev_info, 0, sizeof(dev_info));
1243 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1246 mempool_params = &app->mempool_params[p_kni->mempool_id];
1247 mempool = app->mempool[p_kni->mempool_id];
1250 memset(&conf, 0, sizeof(conf));
1251 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1252 conf.force_bind = p_kni->force_bind;
1253 if (conf.force_bind) {
1256 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1259 p_kni->hyper_th_id);
1262 rte_panic("%s invalid CPU core\n", p_kni->name);
1264 conf.core_id = (uint32_t) lcore_id;
1266 conf.group_id = p_link->pmd_id;
1267 conf.mbuf_size = mempool_params->buffer_size;
1268 conf.addr = dev_info.pci_dev->addr;
1269 conf.id = dev_info.pci_dev->id;
1271 memset(&ops, 0, sizeof(ops));
1272 ops.port_id = (uint8_t) p_link->pmd_id;
1273 ops.change_mtu = kni_change_mtu;
1274 ops.config_network_if = kni_config_network_interface;
1276 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1277 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1279 rte_panic("%s init error\n", p_kni->name);
1282 #endif /* RTE_LIBRTE_KNI */
1285 app_init_msgq(struct app_params *app)
1289 for (i = 0; i < app->n_msgq; i++) {
1290 struct app_msgq_params *p = &app->msgq_params[i];
1292 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1293 app->msgq[i] = rte_ring_create(
1297 RING_F_SP_ENQ | RING_F_SC_DEQ);
1299 if (app->msgq[i] == NULL)
1300 rte_panic("%s init error\n", p->name);
1304 void app_pipeline_params_get(struct app_params *app,
1305 struct app_pipeline_params *p_in,
1306 struct pipeline_params *p_out)
1310 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1312 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1314 p_out->socket_id = (int) p_in->socket_id;
1316 p_out->log_level = app->log_level;
1319 p_out->n_ports_in = p_in->n_pktq_in;
1320 for (i = 0; i < p_in->n_pktq_in; i++) {
1321 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1322 struct pipeline_port_in_params *out = &p_out->port_in[i];
1325 case APP_PKTQ_IN_HWQ:
1327 struct app_pktq_hwq_in_params *p_hwq_in =
1328 &app->hwq_in_params[in->id];
1329 struct app_link_params *p_link =
1330 app_get_link_for_rxq(app, p_hwq_in);
1331 uint32_t rxq_link_id, rxq_queue_id;
1333 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1337 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1338 out->params.ethdev.port_id = p_link->pmd_id;
1339 out->params.ethdev.queue_id = rxq_queue_id;
1340 out->burst_size = p_hwq_in->burst;
1343 case APP_PKTQ_IN_SWQ:
1345 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1347 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1348 if (app_swq_get_readers(app, swq_params) == 1) {
1349 out->type = PIPELINE_PORT_IN_RING_READER;
1350 out->params.ring.ring = app->swq[in->id];
1351 out->burst_size = app->swq_params[in->id].burst_read;
1353 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1354 out->params.ring_multi.ring = app->swq[in->id];
1355 out->burst_size = swq_params->burst_read;
1358 if (swq_params->ipv4_frag == 1) {
1359 struct rte_port_ring_reader_ipv4_frag_params *params =
1360 &out->params.ring_ipv4_frag;
1362 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1363 params->ring = app->swq[in->id];
1364 params->mtu = swq_params->mtu;
1365 params->metadata_size = swq_params->metadata_size;
1366 params->pool_direct =
1367 app->mempool[swq_params->mempool_direct_id];
1368 params->pool_indirect =
1369 app->mempool[swq_params->mempool_indirect_id];
1370 out->burst_size = swq_params->burst_read;
1372 struct rte_port_ring_reader_ipv6_frag_params *params =
1373 &out->params.ring_ipv6_frag;
1375 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1376 params->ring = app->swq[in->id];
1377 params->mtu = swq_params->mtu;
1378 params->metadata_size = swq_params->metadata_size;
1379 params->pool_direct =
1380 app->mempool[swq_params->mempool_direct_id];
1381 params->pool_indirect =
1382 app->mempool[swq_params->mempool_indirect_id];
1383 out->burst_size = swq_params->burst_read;
1388 case APP_PKTQ_IN_TM:
1390 out->type = PIPELINE_PORT_IN_SCHED_READER;
1391 out->params.sched.sched = app->tm[in->id];
1392 out->burst_size = app->tm_params[in->id].burst_read;
1395 #ifdef RTE_LIBRTE_KNI
1396 case APP_PKTQ_IN_KNI:
1398 out->type = PIPELINE_PORT_IN_KNI_READER;
1399 out->params.kni.kni = app->kni[in->id];
1400 out->burst_size = app->kni_params[in->id].burst_read;
1403 #endif /* RTE_LIBRTE_KNI */
1404 case APP_PKTQ_IN_SOURCE:
1406 uint32_t mempool_id =
1407 app->source_params[in->id].mempool_id;
1409 out->type = PIPELINE_PORT_IN_SOURCE;
1410 out->params.source.mempool = app->mempool[mempool_id];
1411 out->burst_size = app->source_params[in->id].burst;
1412 out->params.source.file_name =
1413 app->source_params[in->id].file_name;
1414 out->params.source.n_bytes_per_pkt =
1415 app->source_params[in->id].n_bytes_per_pkt;
1424 p_out->n_ports_out = p_in->n_pktq_out;
1425 for (i = 0; i < p_in->n_pktq_out; i++) {
1426 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1427 struct pipeline_port_out_params *out = &p_out->port_out[i];
1430 case APP_PKTQ_OUT_HWQ:
1432 struct app_pktq_hwq_out_params *p_hwq_out =
1433 &app->hwq_out_params[in->id];
1434 struct app_link_params *p_link =
1435 app_get_link_for_txq(app, p_hwq_out);
1436 uint32_t txq_link_id, txq_queue_id;
1438 sscanf(p_hwq_out->name,
1439 "TXQ%" SCNu32 ".%" SCNu32,
1443 if (p_hwq_out->dropless == 0) {
1444 struct rte_port_ethdev_writer_params *params =
1445 &out->params.ethdev;
1447 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1448 params->port_id = p_link->pmd_id;
1449 params->queue_id = txq_queue_id;
1450 params->tx_burst_sz =
1451 app->hwq_out_params[in->id].burst;
1453 struct rte_port_ethdev_writer_nodrop_params
1454 *params = &out->params.ethdev_nodrop;
1457 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1458 params->port_id = p_link->pmd_id;
1459 params->queue_id = txq_queue_id;
1460 params->tx_burst_sz = p_hwq_out->burst;
1461 params->n_retries = p_hwq_out->n_retries;
1465 case APP_PKTQ_OUT_SWQ:
1467 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1469 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1470 if (app_swq_get_writers(app, swq_params) == 1) {
1471 if (app->swq_params[in->id].dropless == 0) {
1472 struct rte_port_ring_writer_params *params =
1475 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1476 params->ring = app->swq[in->id];
1477 params->tx_burst_sz =
1478 app->swq_params[in->id].burst_write;
1480 struct rte_port_ring_writer_nodrop_params
1481 *params = &out->params.ring_nodrop;
1484 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1485 params->ring = app->swq[in->id];
1486 params->tx_burst_sz =
1487 app->swq_params[in->id].burst_write;
1489 app->swq_params[in->id].n_retries;
1492 if (swq_params->dropless == 0) {
1493 struct rte_port_ring_multi_writer_params *params =
1494 &out->params.ring_multi;
1496 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1497 params->ring = app->swq[in->id];
1498 params->tx_burst_sz = swq_params->burst_write;
1500 struct rte_port_ring_multi_writer_nodrop_params
1501 *params = &out->params.ring_multi_nodrop;
1503 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1504 params->ring = app->swq[in->id];
1505 params->tx_burst_sz = swq_params->burst_write;
1506 params->n_retries = swq_params->n_retries;
1510 if (swq_params->ipv4_ras == 1) {
1511 struct rte_port_ring_writer_ipv4_ras_params *params =
1512 &out->params.ring_ipv4_ras;
1514 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1515 params->ring = app->swq[in->id];
1516 params->tx_burst_sz = swq_params->burst_write;
1518 struct rte_port_ring_writer_ipv6_ras_params *params =
1519 &out->params.ring_ipv6_ras;
1521 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1522 params->ring = app->swq[in->id];
1523 params->tx_burst_sz = swq_params->burst_write;
1528 case APP_PKTQ_OUT_TM:
1530 struct rte_port_sched_writer_params *params =
1533 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1534 params->sched = app->tm[in->id];
1535 params->tx_burst_sz =
1536 app->tm_params[in->id].burst_write;
1539 #ifdef RTE_LIBRTE_KNI
1540 case APP_PKTQ_OUT_KNI:
1542 struct app_pktq_kni_params *p_kni =
1543 &app->kni_params[in->id];
1545 if (p_kni->dropless == 0) {
1546 struct rte_port_kni_writer_params *params =
1549 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1550 params->kni = app->kni[in->id];
1551 params->tx_burst_sz =
1552 app->kni_params[in->id].burst_write;
1554 struct rte_port_kni_writer_nodrop_params
1555 *params = &out->params.kni_nodrop;
1557 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1558 params->kni = app->kni[in->id];
1559 params->tx_burst_sz =
1560 app->kni_params[in->id].burst_write;
1562 app->kni_params[in->id].n_retries;
1566 #endif /* RTE_LIBRTE_KNI */
1567 case APP_PKTQ_OUT_SINK:
1569 out->type = PIPELINE_PORT_OUT_SINK;
1570 out->params.sink.file_name =
1571 app->sink_params[in->id].file_name;
1572 out->params.sink.max_n_pkts =
1573 app->sink_params[in->id].
1584 p_out->n_msgq = p_in->n_msgq_in;
1586 for (i = 0; i < p_in->n_msgq_in; i++)
1587 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1589 for (i = 0; i < p_in->n_msgq_out; i++)
1590 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1593 p_out->n_args = p_in->n_args;
1594 for (i = 0; i < p_in->n_args; i++) {
1595 p_out->args_name[i] = p_in->args_name[i];
1596 p_out->args_value[i] = p_in->args_value[i];
1601 app_init_pipelines(struct app_params *app)
1605 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1606 struct app_pipeline_params *params =
1607 &app->pipeline_params[p_id];
1608 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1609 struct pipeline_type *ptype;
1610 struct pipeline_params pp;
1612 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1614 ptype = app_pipeline_type_find(app, params->type);
1616 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1619 app_pipeline_params_get(app, params, &pp);
1623 if (ptype->be_ops->f_init) {
1624 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1626 if (data->be == NULL)
1627 rte_panic("Pipeline instance \"%s\" back-end "
1628 "init error\n", params->name);
1633 if (ptype->fe_ops->f_init) {
1634 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1636 if (data->fe == NULL)
1637 rte_panic("Pipeline instance \"%s\" front-end "
1638 "init error\n", params->name);
1641 data->ptype = ptype;
1643 data->timer_period = (rte_get_tsc_hz() *
1644 params->timer_period) / 100;
1649 app_post_init_pipelines(struct app_params *app)
1653 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1654 struct app_pipeline_params *params =
1655 &app->pipeline_params[p_id];
1656 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1659 if (data->ptype->fe_ops->f_post_init == NULL)
1662 status = data->ptype->fe_ops->f_post_init(data->fe);
1664 rte_panic("Pipeline instance \"%s\" front-end "
1665 "post-init error\n", params->name);
1670 app_init_threads(struct app_params *app)
1672 uint64_t time = rte_get_tsc_cycles();
1675 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1676 struct app_pipeline_params *params =
1677 &app->pipeline_params[p_id];
1678 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1679 struct pipeline_type *ptype;
1680 struct app_thread_data *t;
1681 struct app_thread_pipeline_data *p;
1684 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1687 params->hyper_th_id);
1690 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1693 (params->hyper_th_id) ? "h" : "");
1695 t = &app->thread_data[lcore_id];
1697 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1698 t->thread_req_deadline = time + t->timer_period;
1700 t->headroom_cycles = 0;
1701 t->headroom_time = rte_get_tsc_cycles();
1702 t->headroom_ratio = 0.0;
1704 t->msgq_in = app_thread_msgq_in_get(app,
1707 params->hyper_th_id);
1708 if (t->msgq_in == NULL)
1709 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1712 t->msgq_out = app_thread_msgq_out_get(app,
1715 params->hyper_th_id);
1716 if (t->msgq_out == NULL)
1717 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1720 ptype = app_pipeline_type_find(app, params->type);
1722 rte_panic("Init error: Unknown pipeline "
1723 "type \"%s\"\n", params->type);
1725 p = (ptype->be_ops->f_run == NULL) ?
1726 &t->regular[t->n_regular] :
1727 &t->custom[t->n_custom];
1729 p->pipeline_id = p_id;
1731 p->f_run = ptype->be_ops->f_run;
1732 p->f_timer = ptype->be_ops->f_timer;
1733 p->timer_period = data->timer_period;
1734 p->deadline = time + data->timer_period;
1738 if (ptype->be_ops->f_run == NULL)
1745 int app_init(struct app_params *app)
1747 app_init_core_map(app);
1748 app_init_core_mask(app);
1751 app_init_mempool(app);
1758 app_pipeline_common_cmd_push(app);
1759 app_pipeline_thread_cmd_push(app);
1760 app_pipeline_type_register(app, &pipeline_master);
1761 app_pipeline_type_register(app, &pipeline_passthrough);
1762 app_pipeline_type_register(app, &pipeline_flow_classification);
1763 app_pipeline_type_register(app, &pipeline_flow_actions);
1764 app_pipeline_type_register(app, &pipeline_firewall);
1765 app_pipeline_type_register(app, &pipeline_routing);
1767 app_init_pipelines(app);
1768 app_init_threads(app);
1773 int app_post_init(struct app_params *app)
1775 app_post_init_pipelines(app);
1781 app_pipeline_type_cmd_push(struct app_params *app,
1782 struct pipeline_type *ptype)
1784 cmdline_parse_ctx_t *cmds;
1787 /* Check input arguments */
1788 if ((app == NULL) ||
1792 n_cmds = pipeline_type_cmds_count(ptype);
1796 cmds = ptype->fe_ops->cmds;
1798 /* Check for available slots in the application commands array */
1799 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1802 /* Push pipeline commands into the application */
1803 memcpy(&app->cmds[app->n_cmds],
1805 n_cmds * sizeof(cmdline_parse_ctx_t));
1807 for (i = 0; i < n_cmds; i++)
1808 app->cmds[app->n_cmds + i]->data = app;
1810 app->n_cmds += n_cmds;
1811 app->cmds[app->n_cmds] = NULL;
1817 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1821 /* Check input arguments */
1822 if ((app == NULL) ||
1824 (ptype->name == NULL) ||
1825 (strlen(ptype->name) == 0) ||
1826 (ptype->be_ops->f_init == NULL) ||
1827 (ptype->be_ops->f_timer == NULL))
1830 /* Check for duplicate entry */
1831 for (i = 0; i < app->n_pipeline_types; i++)
1832 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1835 /* Check for resource availability */
1836 n_cmds = pipeline_type_cmds_count(ptype);
1837 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1838 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1841 /* Copy pipeline type */
1842 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1844 sizeof(struct pipeline_type));
1846 /* Copy CLI commands */
1848 app_pipeline_type_cmd_push(app, ptype);
1854 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1858 for (i = 0; i < app->n_pipeline_types; i++)
1859 if (strcmp(app->pipeline_type[i].name, name) == 0)
1860 return &app->pipeline_type[i];