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_up_internal(struct app_params *app, struct app_link_params *cp)
615 /* For each link, add filters for IP of current link */
617 for (i = 0; i < app->n_links; i++) {
618 struct app_link_params *p = &app->link_params[i];
621 if (p->ip_local_q != 0) {
622 int status = app_link_filter_ip_add(p, cp);
624 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
625 "Adding IP filter (queue= %" PRIu32
626 ", IP = 0x%08" PRIx32 ")",
627 p->name, p->pmd_id, p->ip_local_q,
631 rte_panic("%s (%" PRIu32 "): "
633 "filter (queue= %" PRIu32 ", "
637 p->ip_local_q, cp->ip, status);
641 if (p->tcp_local_q != 0) {
642 int status = app_link_filter_tcp_add(p, cp);
644 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
647 ", IP = 0x%08" PRIx32 ")",
648 p->name, p->pmd_id, p->tcp_local_q,
652 rte_panic("%s (%" PRIu32 "): "
654 "filter (queue = %" PRIu32 ", "
658 p->tcp_local_q, cp->ip, status);
662 if (p->udp_local_q != 0) {
663 int status = app_link_filter_udp_add(p, cp);
665 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
668 ", IP = 0x%08" PRIx32 ")",
669 p->name, p->pmd_id, p->udp_local_q,
673 rte_panic("%s (%" PRIu32 "): "
675 "filter (queue = %" PRIu32 ", "
679 p->udp_local_q, cp->ip, status);
683 if (p->sctp_local_q != 0) {
684 int status = app_link_filter_sctp_add(p, cp);
686 APP_LOG(app, LOW, "%s (%" PRIu32
687 "): Adding SCTP filter "
689 ", IP = 0x%08" PRIx32 ")",
690 p->name, p->pmd_id, p->sctp_local_q,
694 rte_panic("%s (%" PRIu32 "): "
696 "filter (queue = %" PRIu32 ", "
700 p->sctp_local_q, cp->ip,
707 status = rte_eth_dev_set_link_up(cp->pmd_id);
709 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
710 PRId32 "\n", cp->name, cp->pmd_id, status);
712 /* Mark link as UP */
717 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
723 status = rte_eth_dev_set_link_down(cp->pmd_id);
725 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
726 PRId32 "\n", cp->name, cp->pmd_id, status);
728 /* Mark link as DOWN */
731 /* Return if current link IP is not valid */
735 /* For each link, remove filters for IP of current link */
736 for (i = 0; i < app->n_links; i++) {
737 struct app_link_params *p = &app->link_params[i];
740 if (p->ip_local_q != 0) {
741 int status = app_link_filter_ip_del(p, cp);
743 APP_LOG(app, LOW, "%s (%" PRIu32
744 "): Deleting IP filter "
745 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
746 p->name, p->pmd_id, p->ip_local_q, cp->ip);
749 rte_panic("%s (%" PRIu32
750 "): Error deleting IP filter "
754 p->name, p->pmd_id, p->ip_local_q,
759 if (p->tcp_local_q != 0) {
760 int status = app_link_filter_tcp_del(p, cp);
762 APP_LOG(app, LOW, "%s (%" PRIu32
763 "): Deleting TCP filter "
765 ", IP = 0x%" PRIx32 ")",
766 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
769 rte_panic("%s (%" PRIu32
770 "): Error deleting TCP filter "
774 p->name, p->pmd_id, p->tcp_local_q,
779 if (p->udp_local_q != 0) {
780 int status = app_link_filter_udp_del(p, cp);
782 APP_LOG(app, LOW, "%s (%" PRIu32
783 "): Deleting UDP filter "
784 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
785 p->name, p->pmd_id, p->udp_local_q, cp->ip);
788 rte_panic("%s (%" PRIu32
789 "): Error deleting UDP filter "
793 p->name, p->pmd_id, p->udp_local_q,
798 if (p->sctp_local_q != 0) {
799 int status = app_link_filter_sctp_del(p, cp);
801 APP_LOG(app, LOW, "%s (%" PRIu32
802 "): Deleting SCTP filter "
804 ", IP = 0x%" PRIx32 ")",
805 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
808 rte_panic("%s (%" PRIu32
809 "): Error deleting SCTP filter "
813 p->name, p->pmd_id, p->sctp_local_q,
820 app_check_link(struct app_params *app)
822 uint32_t all_links_up, i;
826 for (i = 0; i < app->n_links; i++) {
827 struct app_link_params *p = &app->link_params[i];
828 struct rte_eth_link link_params;
830 memset(&link_params, 0, sizeof(link_params));
831 rte_eth_link_get(p->pmd_id, &link_params);
833 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
836 link_params.link_speed / 1000,
837 link_params.link_status ? "UP" : "DOWN");
839 if (link_params.link_status == ETH_LINK_DOWN)
843 if (all_links_up == 0)
844 rte_panic("Some links are DOWN\n");
848 is_any_swq_frag_or_ras(struct app_params *app)
852 for (i = 0; i < app->n_pktq_swq; i++) {
853 struct app_pktq_swq_params *p = &app->swq_params[i];
855 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
856 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
864 app_init_link_frag_ras(struct app_params *app)
868 if (is_any_swq_frag_or_ras(app)) {
869 for (i = 0; i < app->n_pktq_hwq_out; i++) {
870 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
872 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
878 app_get_cpu_socket_id(uint32_t pmd_id)
880 int status = rte_eth_dev_socket_id(pmd_id);
882 return (status != SOCKET_ID_ANY) ? status : 0;
886 app_link_rss_enabled(struct app_link_params *cp)
888 return (cp->n_rss_qs) ? 1 : 0;
892 app_link_rss_setup(struct app_link_params *cp)
894 struct rte_eth_dev_info dev_info;
895 struct rte_eth_rss_reta_entry64 reta_conf[APP_RETA_SIZE_MAX];
900 memset(&dev_info, 0, sizeof(dev_info));
901 rte_eth_dev_info_get(cp->pmd_id, &dev_info);
903 if (dev_info.reta_size == 0)
904 rte_panic("%s (%u): RSS setup error (null RETA size)\n",
905 cp->name, cp->pmd_id);
907 if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512)
908 rte_panic("%s (%u): RSS setup error (RETA size too big)\n",
909 cp->name, cp->pmd_id);
911 /* Setup RETA contents */
912 memset(reta_conf, 0, sizeof(reta_conf));
914 for (i = 0; i < dev_info.reta_size; i++)
915 reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX;
917 for (i = 0; i < dev_info.reta_size; i++) {
918 uint32_t reta_id = i / RTE_RETA_GROUP_SIZE;
919 uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE;
920 uint32_t rss_qs_pos = i % cp->n_rss_qs;
922 reta_conf[reta_id].reta[reta_pos] =
923 (uint16_t) cp->rss_qs[rss_qs_pos];
927 status = rte_eth_dev_rss_reta_update(cp->pmd_id,
931 rte_panic("%s (%u): RSS setup error (RETA update failed)\n",
932 cp->name, cp->pmd_id);
936 app_init_link_set_config(struct app_link_params *p)
939 p->conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
940 p->conf.rx_adv_conf.rss_conf.rss_hf = p->rss_proto_ipv4 |
947 app_init_link(struct app_params *app)
951 app_init_link_frag_ras(app);
953 for (i = 0; i < app->n_links; i++) {
954 struct app_link_params *p_link = &app->link_params[i];
955 uint32_t link_id, n_hwq_in, n_hwq_out, j;
958 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
959 n_hwq_in = app_link_get_n_rxq(app, p_link);
960 n_hwq_out = app_link_get_n_txq(app, p_link);
961 app_init_link_set_config(p_link);
963 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
964 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
971 status = rte_eth_dev_configure(
977 rte_panic("%s (%" PRId32 "): "
978 "init error (%" PRId32 ")\n",
979 p_link->name, p_link->pmd_id, status);
981 rte_eth_macaddr_get(p_link->pmd_id,
982 (struct ether_addr *) &p_link->mac_addr);
985 rte_eth_promiscuous_enable(p_link->pmd_id);
988 for (j = 0; j < app->n_pktq_hwq_in; j++) {
989 struct app_pktq_hwq_in_params *p_rxq =
990 &app->hwq_in_params[j];
991 uint32_t rxq_link_id, rxq_queue_id;
993 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
994 &rxq_link_id, &rxq_queue_id);
995 if (rxq_link_id != link_id)
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;
1020 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
1021 &txq_link_id, &txq_queue_id);
1022 if (txq_link_id != link_id)
1025 status = rte_eth_tx_queue_setup(
1029 app_get_cpu_socket_id(p_link->pmd_id),
1032 rte_panic("%s (%" PRIu32 "): "
1033 "%s init error (%" PRId32 ")\n",
1041 status = rte_eth_dev_start(p_link->pmd_id);
1043 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1044 p_link->name, status);
1047 app_link_set_arp_filter(app, p_link);
1048 app_link_set_tcp_syn_filter(app, p_link);
1049 if (app_link_rss_enabled(p_link))
1050 app_link_rss_setup(p_link);
1053 app_link_up_internal(app, p_link);
1056 app_check_link(app);
1060 app_init_swq(struct app_params *app)
1064 for (i = 0; i < app->n_pktq_swq; i++) {
1065 struct app_pktq_swq_params *p = &app->swq_params[i];
1068 if (app_swq_get_readers(app, p) == 1)
1069 flags |= RING_F_SC_DEQ;
1070 if (app_swq_get_writers(app, p) == 1)
1071 flags |= RING_F_SP_ENQ;
1073 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1074 app->swq[i] = rte_ring_create(
1080 if (app->swq[i] == NULL)
1081 rte_panic("%s init error\n", p->name);
1086 app_init_tm(struct app_params *app)
1090 for (i = 0; i < app->n_pktq_tm; i++) {
1091 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1092 struct app_link_params *p_link;
1093 struct rte_eth_link link_eth_params;
1094 struct rte_sched_port *sched;
1095 uint32_t n_subports, subport_id;
1098 p_link = app_get_link_for_tm(app, p_tm);
1100 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1103 p_tm->sched_port_params.name = p_tm->name;
1104 p_tm->sched_port_params.socket =
1105 app_get_cpu_socket_id(p_link->pmd_id);
1106 p_tm->sched_port_params.rate =
1107 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1109 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1110 sched = rte_sched_port_config(&p_tm->sched_port_params);
1112 rte_panic("%s init error\n", p_tm->name);
1116 n_subports = p_tm->sched_port_params.n_subports_per_port;
1117 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1118 uint32_t n_pipes_per_subport, pipe_id;
1120 status = rte_sched_subport_config(sched,
1122 &p_tm->sched_subport_params[subport_id]);
1124 rte_panic("%s subport %" PRIu32
1125 " init error (%" PRId32 ")\n",
1126 p_tm->name, subport_id, status);
1129 n_pipes_per_subport =
1130 p_tm->sched_port_params.n_pipes_per_subport;
1132 pipe_id < n_pipes_per_subport;
1134 int profile_id = p_tm->sched_pipe_to_profile[
1135 subport_id * APP_MAX_SCHED_PIPES +
1138 if (profile_id == -1)
1141 status = rte_sched_pipe_config(sched,
1146 rte_panic("%s subport %" PRIu32
1148 " (profile %" PRId32 ") "
1149 "init error (% " PRId32 ")\n",
1150 p_tm->name, subport_id, pipe_id,
1151 profile_id, status);
1157 #ifdef RTE_LIBRTE_KNI
1159 kni_config_network_interface(uint8_t port_id, uint8_t if_up) {
1162 if (port_id >= rte_eth_dev_count())
1166 rte_eth_dev_set_link_up(port_id) :
1167 rte_eth_dev_set_link_down(port_id);
1173 kni_change_mtu(uint8_t port_id, unsigned new_mtu) {
1176 if (port_id >= rte_eth_dev_count())
1179 if (new_mtu > ETHER_MAX_LEN)
1183 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
1189 #endif /* RTE_LIBRTE_KNI */
1191 #ifndef RTE_LIBRTE_KNI
1193 app_init_kni(struct app_params *app) {
1194 if (app->n_pktq_kni == 0)
1197 rte_panic("Can not init KNI without librte_kni support.\n");
1201 app_init_kni(struct app_params *app) {
1204 if (app->n_pktq_kni == 0)
1207 rte_kni_init(app->n_pktq_kni);
1209 for (i = 0; i < app->n_pktq_kni; i++) {
1210 struct app_pktq_kni_params *p_kni = &app->kni_params[i];
1211 struct app_link_params *p_link;
1212 struct rte_eth_dev_info dev_info;
1213 struct app_mempool_params *mempool_params;
1214 struct rte_mempool *mempool;
1215 struct rte_kni_conf conf;
1216 struct rte_kni_ops ops;
1219 p_link = app_get_link_for_kni(app, p_kni);
1220 memset(&dev_info, 0, sizeof(dev_info));
1221 rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
1224 mempool_params = &app->mempool_params[p_kni->mempool_id];
1225 mempool = app->mempool[p_kni->mempool_id];
1228 memset(&conf, 0, sizeof(conf));
1229 snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
1230 conf.force_bind = p_kni->force_bind;
1231 if (conf.force_bind) {
1234 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1237 p_kni->hyper_th_id);
1240 rte_panic("%s invalid CPU core\n", p_kni->name);
1242 conf.core_id = (uint32_t) lcore_id;
1244 conf.group_id = p_link->pmd_id;
1245 conf.mbuf_size = mempool_params->buffer_size;
1246 conf.addr = dev_info.pci_dev->addr;
1247 conf.id = dev_info.pci_dev->id;
1249 memset(&ops, 0, sizeof(ops));
1250 ops.port_id = (uint8_t) p_link->pmd_id;
1251 ops.change_mtu = kni_change_mtu;
1252 ops.config_network_if = kni_config_network_interface;
1254 APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
1255 app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
1257 rte_panic("%s init error\n", p_kni->name);
1260 #endif /* RTE_LIBRTE_KNI */
1263 app_init_msgq(struct app_params *app)
1267 for (i = 0; i < app->n_msgq; i++) {
1268 struct app_msgq_params *p = &app->msgq_params[i];
1270 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1271 app->msgq[i] = rte_ring_create(
1275 RING_F_SP_ENQ | RING_F_SC_DEQ);
1277 if (app->msgq[i] == NULL)
1278 rte_panic("%s init error\n", p->name);
1282 void app_pipeline_params_get(struct app_params *app,
1283 struct app_pipeline_params *p_in,
1284 struct pipeline_params *p_out)
1288 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1290 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1292 p_out->socket_id = (int) p_in->socket_id;
1294 p_out->log_level = app->log_level;
1297 p_out->n_ports_in = p_in->n_pktq_in;
1298 for (i = 0; i < p_in->n_pktq_in; i++) {
1299 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1300 struct pipeline_port_in_params *out = &p_out->port_in[i];
1303 case APP_PKTQ_IN_HWQ:
1305 struct app_pktq_hwq_in_params *p_hwq_in =
1306 &app->hwq_in_params[in->id];
1307 struct app_link_params *p_link =
1308 app_get_link_for_rxq(app, p_hwq_in);
1309 uint32_t rxq_link_id, rxq_queue_id;
1311 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1315 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1316 out->params.ethdev.port_id = p_link->pmd_id;
1317 out->params.ethdev.queue_id = rxq_queue_id;
1318 out->burst_size = p_hwq_in->burst;
1321 case APP_PKTQ_IN_SWQ:
1323 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1325 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1326 if (app_swq_get_readers(app, swq_params) == 1) {
1327 out->type = PIPELINE_PORT_IN_RING_READER;
1328 out->params.ring.ring = app->swq[in->id];
1329 out->burst_size = app->swq_params[in->id].burst_read;
1331 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1332 out->params.ring_multi.ring = app->swq[in->id];
1333 out->burst_size = swq_params->burst_read;
1336 if (swq_params->ipv4_frag == 1) {
1337 struct rte_port_ring_reader_ipv4_frag_params *params =
1338 &out->params.ring_ipv4_frag;
1340 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1341 params->ring = app->swq[in->id];
1342 params->mtu = swq_params->mtu;
1343 params->metadata_size = swq_params->metadata_size;
1344 params->pool_direct =
1345 app->mempool[swq_params->mempool_direct_id];
1346 params->pool_indirect =
1347 app->mempool[swq_params->mempool_indirect_id];
1348 out->burst_size = swq_params->burst_read;
1350 struct rte_port_ring_reader_ipv6_frag_params *params =
1351 &out->params.ring_ipv6_frag;
1353 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1354 params->ring = app->swq[in->id];
1355 params->mtu = swq_params->mtu;
1356 params->metadata_size = swq_params->metadata_size;
1357 params->pool_direct =
1358 app->mempool[swq_params->mempool_direct_id];
1359 params->pool_indirect =
1360 app->mempool[swq_params->mempool_indirect_id];
1361 out->burst_size = swq_params->burst_read;
1366 case APP_PKTQ_IN_TM:
1368 out->type = PIPELINE_PORT_IN_SCHED_READER;
1369 out->params.sched.sched = app->tm[in->id];
1370 out->burst_size = app->tm_params[in->id].burst_read;
1373 #ifdef RTE_LIBRTE_KNI
1374 case APP_PKTQ_IN_KNI:
1376 out->type = PIPELINE_PORT_IN_KNI_READER;
1377 out->params.kni.kni = app->kni[in->id];
1378 out->burst_size = app->kni_params[in->id].burst_read;
1381 #endif /* RTE_LIBRTE_KNI */
1382 case APP_PKTQ_IN_SOURCE:
1384 uint32_t mempool_id =
1385 app->source_params[in->id].mempool_id;
1387 out->type = PIPELINE_PORT_IN_SOURCE;
1388 out->params.source.mempool = app->mempool[mempool_id];
1389 out->burst_size = app->source_params[in->id].burst;
1390 out->params.source.file_name =
1391 app->source_params[in->id].file_name;
1392 out->params.source.n_bytes_per_pkt =
1393 app->source_params[in->id].n_bytes_per_pkt;
1402 p_out->n_ports_out = p_in->n_pktq_out;
1403 for (i = 0; i < p_in->n_pktq_out; i++) {
1404 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1405 struct pipeline_port_out_params *out = &p_out->port_out[i];
1408 case APP_PKTQ_OUT_HWQ:
1410 struct app_pktq_hwq_out_params *p_hwq_out =
1411 &app->hwq_out_params[in->id];
1412 struct app_link_params *p_link =
1413 app_get_link_for_txq(app, p_hwq_out);
1414 uint32_t txq_link_id, txq_queue_id;
1416 sscanf(p_hwq_out->name,
1417 "TXQ%" SCNu32 ".%" SCNu32,
1421 if (p_hwq_out->dropless == 0) {
1422 struct rte_port_ethdev_writer_params *params =
1423 &out->params.ethdev;
1425 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1426 params->port_id = p_link->pmd_id;
1427 params->queue_id = txq_queue_id;
1428 params->tx_burst_sz =
1429 app->hwq_out_params[in->id].burst;
1431 struct rte_port_ethdev_writer_nodrop_params
1432 *params = &out->params.ethdev_nodrop;
1435 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1436 params->port_id = p_link->pmd_id;
1437 params->queue_id = txq_queue_id;
1438 params->tx_burst_sz = p_hwq_out->burst;
1439 params->n_retries = p_hwq_out->n_retries;
1443 case APP_PKTQ_OUT_SWQ:
1445 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1447 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1448 if (app_swq_get_writers(app, swq_params) == 1) {
1449 if (app->swq_params[in->id].dropless == 0) {
1450 struct rte_port_ring_writer_params *params =
1453 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1454 params->ring = app->swq[in->id];
1455 params->tx_burst_sz =
1456 app->swq_params[in->id].burst_write;
1458 struct rte_port_ring_writer_nodrop_params
1459 *params = &out->params.ring_nodrop;
1462 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1463 params->ring = app->swq[in->id];
1464 params->tx_burst_sz =
1465 app->swq_params[in->id].burst_write;
1467 app->swq_params[in->id].n_retries;
1470 if (swq_params->dropless == 0) {
1471 struct rte_port_ring_multi_writer_params *params =
1472 &out->params.ring_multi;
1474 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1475 params->ring = app->swq[in->id];
1476 params->tx_burst_sz = swq_params->burst_write;
1478 struct rte_port_ring_multi_writer_nodrop_params
1479 *params = &out->params.ring_multi_nodrop;
1481 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1482 params->ring = app->swq[in->id];
1483 params->tx_burst_sz = swq_params->burst_write;
1484 params->n_retries = swq_params->n_retries;
1488 if (swq_params->ipv4_ras == 1) {
1489 struct rte_port_ring_writer_ipv4_ras_params *params =
1490 &out->params.ring_ipv4_ras;
1492 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1493 params->ring = app->swq[in->id];
1494 params->tx_burst_sz = swq_params->burst_write;
1496 struct rte_port_ring_writer_ipv6_ras_params *params =
1497 &out->params.ring_ipv6_ras;
1499 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1500 params->ring = app->swq[in->id];
1501 params->tx_burst_sz = swq_params->burst_write;
1506 case APP_PKTQ_OUT_TM:
1508 struct rte_port_sched_writer_params *params =
1511 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1512 params->sched = app->tm[in->id];
1513 params->tx_burst_sz =
1514 app->tm_params[in->id].burst_write;
1517 #ifdef RTE_LIBRTE_KNI
1518 case APP_PKTQ_OUT_KNI:
1520 struct app_pktq_kni_params *p_kni =
1521 &app->kni_params[in->id];
1523 if (p_kni->dropless == 0) {
1524 struct rte_port_kni_writer_params *params =
1527 out->type = PIPELINE_PORT_OUT_KNI_WRITER;
1528 params->kni = app->kni[in->id];
1529 params->tx_burst_sz =
1530 app->kni_params[in->id].burst_write;
1532 struct rte_port_kni_writer_nodrop_params
1533 *params = &out->params.kni_nodrop;
1535 out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
1536 params->kni = app->kni[in->id];
1537 params->tx_burst_sz =
1538 app->kni_params[in->id].burst_write;
1540 app->kni_params[in->id].n_retries;
1544 #endif /* RTE_LIBRTE_KNI */
1545 case APP_PKTQ_OUT_SINK:
1547 out->type = PIPELINE_PORT_OUT_SINK;
1548 out->params.sink.file_name =
1549 app->sink_params[in->id].file_name;
1550 out->params.sink.max_n_pkts =
1551 app->sink_params[in->id].
1562 p_out->n_msgq = p_in->n_msgq_in;
1564 for (i = 0; i < p_in->n_msgq_in; i++)
1565 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1567 for (i = 0; i < p_in->n_msgq_out; i++)
1568 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1571 p_out->n_args = p_in->n_args;
1572 for (i = 0; i < p_in->n_args; i++) {
1573 p_out->args_name[i] = p_in->args_name[i];
1574 p_out->args_value[i] = p_in->args_value[i];
1579 app_init_pipelines(struct app_params *app)
1583 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1584 struct app_pipeline_params *params =
1585 &app->pipeline_params[p_id];
1586 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1587 struct pipeline_type *ptype;
1588 struct pipeline_params pp;
1590 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1592 ptype = app_pipeline_type_find(app, params->type);
1594 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1597 app_pipeline_params_get(app, params, &pp);
1601 if (ptype->be_ops->f_init) {
1602 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1604 if (data->be == NULL)
1605 rte_panic("Pipeline instance \"%s\" back-end "
1606 "init error\n", params->name);
1611 if (ptype->fe_ops->f_init) {
1612 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1614 if (data->fe == NULL)
1615 rte_panic("Pipeline instance \"%s\" front-end "
1616 "init error\n", params->name);
1619 data->ptype = ptype;
1621 data->timer_period = (rte_get_tsc_hz() *
1622 params->timer_period) / 100;
1627 app_post_init_pipelines(struct app_params *app)
1631 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1632 struct app_pipeline_params *params =
1633 &app->pipeline_params[p_id];
1634 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1637 if (data->ptype->fe_ops->f_post_init == NULL)
1640 status = data->ptype->fe_ops->f_post_init(data->fe);
1642 rte_panic("Pipeline instance \"%s\" front-end "
1643 "post-init error\n", params->name);
1648 app_init_threads(struct app_params *app)
1650 uint64_t time = rte_get_tsc_cycles();
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];
1657 struct pipeline_type *ptype;
1658 struct app_thread_data *t;
1659 struct app_thread_pipeline_data *p;
1662 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1665 params->hyper_th_id);
1668 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1671 (params->hyper_th_id) ? "h" : "");
1673 t = &app->thread_data[lcore_id];
1675 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1676 t->thread_req_deadline = time + t->timer_period;
1678 t->headroom_cycles = 0;
1679 t->headroom_time = rte_get_tsc_cycles();
1680 t->headroom_ratio = 0.0;
1682 t->msgq_in = app_thread_msgq_in_get(app,
1685 params->hyper_th_id);
1686 if (t->msgq_in == NULL)
1687 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1690 t->msgq_out = app_thread_msgq_out_get(app,
1693 params->hyper_th_id);
1694 if (t->msgq_out == NULL)
1695 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1698 ptype = app_pipeline_type_find(app, params->type);
1700 rte_panic("Init error: Unknown pipeline "
1701 "type \"%s\"\n", params->type);
1703 p = (ptype->be_ops->f_run == NULL) ?
1704 &t->regular[t->n_regular] :
1705 &t->custom[t->n_custom];
1707 p->pipeline_id = p_id;
1709 p->f_run = ptype->be_ops->f_run;
1710 p->f_timer = ptype->be_ops->f_timer;
1711 p->timer_period = data->timer_period;
1712 p->deadline = time + data->timer_period;
1716 if (ptype->be_ops->f_run == NULL)
1723 int app_init(struct app_params *app)
1725 app_init_core_map(app);
1726 app_init_core_mask(app);
1729 app_init_mempool(app);
1736 app_pipeline_common_cmd_push(app);
1737 app_pipeline_thread_cmd_push(app);
1738 app_pipeline_type_register(app, &pipeline_master);
1739 app_pipeline_type_register(app, &pipeline_passthrough);
1740 app_pipeline_type_register(app, &pipeline_flow_classification);
1741 app_pipeline_type_register(app, &pipeline_flow_actions);
1742 app_pipeline_type_register(app, &pipeline_firewall);
1743 app_pipeline_type_register(app, &pipeline_routing);
1745 app_init_pipelines(app);
1746 app_init_threads(app);
1751 int app_post_init(struct app_params *app)
1753 app_post_init_pipelines(app);
1759 app_pipeline_type_cmd_push(struct app_params *app,
1760 struct pipeline_type *ptype)
1762 cmdline_parse_ctx_t *cmds;
1765 /* Check input arguments */
1766 if ((app == NULL) ||
1770 n_cmds = pipeline_type_cmds_count(ptype);
1774 cmds = ptype->fe_ops->cmds;
1776 /* Check for available slots in the application commands array */
1777 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1780 /* Push pipeline commands into the application */
1781 memcpy(&app->cmds[app->n_cmds],
1783 n_cmds * sizeof(cmdline_parse_ctx_t));
1785 for (i = 0; i < n_cmds; i++)
1786 app->cmds[app->n_cmds + i]->data = app;
1788 app->n_cmds += n_cmds;
1789 app->cmds[app->n_cmds] = NULL;
1795 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1799 /* Check input arguments */
1800 if ((app == NULL) ||
1802 (ptype->name == NULL) ||
1803 (strlen(ptype->name) == 0) ||
1804 (ptype->be_ops->f_init == NULL) ||
1805 (ptype->be_ops->f_timer == NULL))
1808 /* Check for duplicate entry */
1809 for (i = 0; i < app->n_pipeline_types; i++)
1810 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1813 /* Check for resource availability */
1814 n_cmds = pipeline_type_cmds_count(ptype);
1815 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1816 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1819 /* Copy pipeline type */
1820 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1822 sizeof(struct pipeline_type));
1824 /* Copy CLI commands */
1826 app_pipeline_type_cmd_push(app, ptype);
1832 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1836 for (i = 0; i < app->n_pipeline_types; i++)
1837 if (strcmp(app->pipeline_type[i].name, name) == 0)
1838 return &app->pipeline_type[i];