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);
1180 app_init_msgq(struct app_params *app)
1184 for (i = 0; i < app->n_msgq; i++) {
1185 struct app_msgq_params *p = &app->msgq_params[i];
1187 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1188 app->msgq[i] = rte_ring_create(
1192 RING_F_SP_ENQ | RING_F_SC_DEQ);
1194 if (app->msgq[i] == NULL)
1195 rte_panic("%s init error\n", p->name);
1199 void app_pipeline_params_get(struct app_params *app,
1200 struct app_pipeline_params *p_in,
1201 struct pipeline_params *p_out)
1205 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1207 snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
1209 p_out->socket_id = (int) p_in->socket_id;
1211 p_out->log_level = app->log_level;
1214 p_out->n_ports_in = p_in->n_pktq_in;
1215 for (i = 0; i < p_in->n_pktq_in; i++) {
1216 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1217 struct pipeline_port_in_params *out = &p_out->port_in[i];
1220 case APP_PKTQ_IN_HWQ:
1222 struct app_pktq_hwq_in_params *p_hwq_in =
1223 &app->hwq_in_params[in->id];
1224 struct app_link_params *p_link =
1225 app_get_link_for_rxq(app, p_hwq_in);
1226 uint32_t rxq_link_id, rxq_queue_id;
1228 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1232 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1233 out->params.ethdev.port_id = p_link->pmd_id;
1234 out->params.ethdev.queue_id = rxq_queue_id;
1235 out->burst_size = p_hwq_in->burst;
1238 case APP_PKTQ_IN_SWQ:
1240 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1242 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1243 if (app_swq_get_readers(app, swq_params) == 1) {
1244 out->type = PIPELINE_PORT_IN_RING_READER;
1245 out->params.ring.ring = app->swq[in->id];
1246 out->burst_size = app->swq_params[in->id].burst_read;
1248 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1249 out->params.ring_multi.ring = app->swq[in->id];
1250 out->burst_size = swq_params->burst_read;
1253 if (swq_params->ipv4_frag == 1) {
1254 struct rte_port_ring_reader_ipv4_frag_params *params =
1255 &out->params.ring_ipv4_frag;
1257 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1258 params->ring = app->swq[in->id];
1259 params->mtu = swq_params->mtu;
1260 params->metadata_size = swq_params->metadata_size;
1261 params->pool_direct =
1262 app->mempool[swq_params->mempool_direct_id];
1263 params->pool_indirect =
1264 app->mempool[swq_params->mempool_indirect_id];
1265 out->burst_size = swq_params->burst_read;
1267 struct rte_port_ring_reader_ipv6_frag_params *params =
1268 &out->params.ring_ipv6_frag;
1270 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1271 params->ring = app->swq[in->id];
1272 params->mtu = swq_params->mtu;
1273 params->metadata_size = swq_params->metadata_size;
1274 params->pool_direct =
1275 app->mempool[swq_params->mempool_direct_id];
1276 params->pool_indirect =
1277 app->mempool[swq_params->mempool_indirect_id];
1278 out->burst_size = swq_params->burst_read;
1283 case APP_PKTQ_IN_TM:
1284 out->type = PIPELINE_PORT_IN_SCHED_READER;
1285 out->params.sched.sched = app->tm[in->id];
1286 out->burst_size = app->tm_params[in->id].burst_read;
1288 case APP_PKTQ_IN_SOURCE:
1290 uint32_t mempool_id =
1291 app->source_params[in->id].mempool_id;
1293 out->type = PIPELINE_PORT_IN_SOURCE;
1294 out->params.source.mempool = app->mempool[mempool_id];
1295 out->burst_size = app->source_params[in->id].burst;
1296 out->params.source.file_name =
1297 app->source_params[in->id].file_name;
1298 out->params.source.n_bytes_per_pkt =
1299 app->source_params[in->id].n_bytes_per_pkt;
1308 p_out->n_ports_out = p_in->n_pktq_out;
1309 for (i = 0; i < p_in->n_pktq_out; i++) {
1310 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1311 struct pipeline_port_out_params *out = &p_out->port_out[i];
1314 case APP_PKTQ_OUT_HWQ:
1316 struct app_pktq_hwq_out_params *p_hwq_out =
1317 &app->hwq_out_params[in->id];
1318 struct app_link_params *p_link =
1319 app_get_link_for_txq(app, p_hwq_out);
1320 uint32_t txq_link_id, txq_queue_id;
1322 sscanf(p_hwq_out->name,
1323 "TXQ%" SCNu32 ".%" SCNu32,
1327 if (p_hwq_out->dropless == 0) {
1328 struct rte_port_ethdev_writer_params *params =
1329 &out->params.ethdev;
1331 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1332 params->port_id = p_link->pmd_id;
1333 params->queue_id = txq_queue_id;
1334 params->tx_burst_sz =
1335 app->hwq_out_params[in->id].burst;
1337 struct rte_port_ethdev_writer_nodrop_params
1338 *params = &out->params.ethdev_nodrop;
1341 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1342 params->port_id = p_link->pmd_id;
1343 params->queue_id = txq_queue_id;
1344 params->tx_burst_sz = p_hwq_out->burst;
1345 params->n_retries = p_hwq_out->n_retries;
1349 case APP_PKTQ_OUT_SWQ:
1351 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1353 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1354 if (app_swq_get_writers(app, swq_params) == 1) {
1355 if (app->swq_params[in->id].dropless == 0) {
1356 struct rte_port_ring_writer_params *params =
1359 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1360 params->ring = app->swq[in->id];
1361 params->tx_burst_sz =
1362 app->swq_params[in->id].burst_write;
1364 struct rte_port_ring_writer_nodrop_params
1365 *params = &out->params.ring_nodrop;
1368 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1369 params->ring = app->swq[in->id];
1370 params->tx_burst_sz =
1371 app->swq_params[in->id].burst_write;
1373 app->swq_params[in->id].n_retries;
1376 if (swq_params->dropless == 0) {
1377 struct rte_port_ring_multi_writer_params *params =
1378 &out->params.ring_multi;
1380 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1381 params->ring = app->swq[in->id];
1382 params->tx_burst_sz = swq_params->burst_write;
1384 struct rte_port_ring_multi_writer_nodrop_params
1385 *params = &out->params.ring_multi_nodrop;
1387 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1388 params->ring = app->swq[in->id];
1389 params->tx_burst_sz = swq_params->burst_write;
1390 params->n_retries = swq_params->n_retries;
1394 if (swq_params->ipv4_ras == 1) {
1395 struct rte_port_ring_writer_ipv4_ras_params *params =
1396 &out->params.ring_ipv4_ras;
1398 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1399 params->ring = app->swq[in->id];
1400 params->tx_burst_sz = swq_params->burst_write;
1402 struct rte_port_ring_writer_ipv6_ras_params *params =
1403 &out->params.ring_ipv6_ras;
1405 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1406 params->ring = app->swq[in->id];
1407 params->tx_burst_sz = swq_params->burst_write;
1412 case APP_PKTQ_OUT_TM: {
1413 struct rte_port_sched_writer_params *params =
1416 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1417 params->sched = app->tm[in->id];
1418 params->tx_burst_sz =
1419 app->tm_params[in->id].burst_write;
1422 case APP_PKTQ_OUT_SINK:
1424 out->type = PIPELINE_PORT_OUT_SINK;
1425 out->params.sink.file_name =
1426 app->sink_params[in->id].file_name;
1427 out->params.sink.max_n_pkts =
1428 app->sink_params[in->id].
1439 p_out->n_msgq = p_in->n_msgq_in;
1441 for (i = 0; i < p_in->n_msgq_in; i++)
1442 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1444 for (i = 0; i < p_in->n_msgq_out; i++)
1445 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1448 p_out->n_args = p_in->n_args;
1449 for (i = 0; i < p_in->n_args; i++) {
1450 p_out->args_name[i] = p_in->args_name[i];
1451 p_out->args_value[i] = p_in->args_value[i];
1456 app_init_pipelines(struct app_params *app)
1460 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1461 struct app_pipeline_params *params =
1462 &app->pipeline_params[p_id];
1463 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1464 struct pipeline_type *ptype;
1465 struct pipeline_params pp;
1467 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1469 ptype = app_pipeline_type_find(app, params->type);
1471 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1474 app_pipeline_params_get(app, params, &pp);
1478 if (ptype->be_ops->f_init) {
1479 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1481 if (data->be == NULL)
1482 rte_panic("Pipeline instance \"%s\" back-end "
1483 "init error\n", params->name);
1488 if (ptype->fe_ops->f_init) {
1489 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1491 if (data->fe == NULL)
1492 rte_panic("Pipeline instance \"%s\" front-end "
1493 "init error\n", params->name);
1496 data->ptype = ptype;
1498 data->timer_period = (rte_get_tsc_hz() *
1499 params->timer_period) / 100;
1504 app_post_init_pipelines(struct app_params *app)
1508 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1509 struct app_pipeline_params *params =
1510 &app->pipeline_params[p_id];
1511 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1514 if (data->ptype->fe_ops->f_post_init == NULL)
1517 status = data->ptype->fe_ops->f_post_init(data->fe);
1519 rte_panic("Pipeline instance \"%s\" front-end "
1520 "post-init error\n", params->name);
1525 app_init_threads(struct app_params *app)
1527 uint64_t time = rte_get_tsc_cycles();
1530 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1531 struct app_pipeline_params *params =
1532 &app->pipeline_params[p_id];
1533 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1534 struct pipeline_type *ptype;
1535 struct app_thread_data *t;
1536 struct app_thread_pipeline_data *p;
1539 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1542 params->hyper_th_id);
1545 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1548 (params->hyper_th_id) ? "h" : "");
1550 t = &app->thread_data[lcore_id];
1552 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1553 t->thread_req_deadline = time + t->timer_period;
1555 t->headroom_cycles = 0;
1556 t->headroom_time = rte_get_tsc_cycles();
1557 t->headroom_ratio = 0.0;
1559 t->msgq_in = app_thread_msgq_in_get(app,
1562 params->hyper_th_id);
1563 if (t->msgq_in == NULL)
1564 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1567 t->msgq_out = app_thread_msgq_out_get(app,
1570 params->hyper_th_id);
1571 if (t->msgq_out == NULL)
1572 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1575 ptype = app_pipeline_type_find(app, params->type);
1577 rte_panic("Init error: Unknown pipeline "
1578 "type \"%s\"\n", params->type);
1580 p = (ptype->be_ops->f_run == NULL) ?
1581 &t->regular[t->n_regular] :
1582 &t->custom[t->n_custom];
1584 p->pipeline_id = p_id;
1586 p->f_run = ptype->be_ops->f_run;
1587 p->f_timer = ptype->be_ops->f_timer;
1588 p->timer_period = data->timer_period;
1589 p->deadline = time + data->timer_period;
1593 if (ptype->be_ops->f_run == NULL)
1600 int app_init(struct app_params *app)
1602 app_init_core_map(app);
1603 app_init_core_mask(app);
1606 app_init_mempool(app);
1612 app_pipeline_common_cmd_push(app);
1613 app_pipeline_thread_cmd_push(app);
1614 app_pipeline_type_register(app, &pipeline_master);
1615 app_pipeline_type_register(app, &pipeline_passthrough);
1616 app_pipeline_type_register(app, &pipeline_flow_classification);
1617 app_pipeline_type_register(app, &pipeline_flow_actions);
1618 app_pipeline_type_register(app, &pipeline_firewall);
1619 app_pipeline_type_register(app, &pipeline_routing);
1621 app_init_pipelines(app);
1622 app_init_threads(app);
1627 int app_post_init(struct app_params *app)
1629 app_post_init_pipelines(app);
1635 app_pipeline_type_cmd_push(struct app_params *app,
1636 struct pipeline_type *ptype)
1638 cmdline_parse_ctx_t *cmds;
1641 /* Check input arguments */
1642 if ((app == NULL) ||
1646 n_cmds = pipeline_type_cmds_count(ptype);
1650 cmds = ptype->fe_ops->cmds;
1652 /* Check for available slots in the application commands array */
1653 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1656 /* Push pipeline commands into the application */
1657 memcpy(&app->cmds[app->n_cmds],
1659 n_cmds * sizeof(cmdline_parse_ctx_t));
1661 for (i = 0; i < n_cmds; i++)
1662 app->cmds[app->n_cmds + i]->data = app;
1664 app->n_cmds += n_cmds;
1665 app->cmds[app->n_cmds] = NULL;
1671 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1675 /* Check input arguments */
1676 if ((app == NULL) ||
1678 (ptype->name == NULL) ||
1679 (strlen(ptype->name) == 0) ||
1680 (ptype->be_ops->f_init == NULL) ||
1681 (ptype->be_ops->f_timer == NULL))
1684 /* Check for duplicate entry */
1685 for (i = 0; i < app->n_pipeline_types; i++)
1686 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1689 /* Check for resource availability */
1690 n_cmds = pipeline_type_cmds_count(ptype);
1691 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1692 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1695 /* Copy pipeline type */
1696 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1698 sizeof(struct pipeline_type));
1700 /* Copy CLI commands */
1702 app_pipeline_type_cmd_push(app, ptype);
1708 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1712 for (i = 0; i < app->n_pipeline_types; i++)
1713 if (strcmp(app->pipeline_type[i].name, name) == 0)
1714 return &app->pipeline_type[i];