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
59 app_init_core_map(struct app_params *app)
61 APP_LOG(app, HIGH, "Initializing CPU core map ...");
62 app->core_map = cpu_core_map_init(4, 32, 4, 0);
64 if (app->core_map == NULL)
65 rte_panic("Cannot create CPU core map\n");
67 if (app->log_level >= APP_LOG_LEVEL_LOW)
68 cpu_core_map_print(app->core_map);
72 app_init_core_mask(struct app_params *app)
77 for (i = 0; i < app->n_pipelines; i++) {
78 struct app_pipeline_params *p = &app->pipeline_params[i];
81 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
87 rte_panic("Cannot create CPU core mask\n");
89 mask |= 1LLU << lcore_id;
92 app->core_mask = mask;
93 APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
97 app_init_eal(struct app_params *app)
100 struct app_eal_params *p = &app->eal_params;
105 app->eal_argv[n_args++] = strdup(app->app_name);
107 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
108 app->eal_argv[n_args++] = strdup(buffer);
111 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
112 app->eal_argv[n_args++] = strdup(buffer);
115 if (p->master_lcore_present) {
118 "--master-lcore=%" PRIu32,
120 app->eal_argv[n_args++] = strdup(buffer);
123 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
124 app->eal_argv[n_args++] = strdup(buffer);
126 if (p->memory_present) {
127 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
128 app->eal_argv[n_args++] = strdup(buffer);
131 if (p->ranks_present) {
132 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
133 app->eal_argv[n_args++] = strdup(buffer);
136 for (i = 0; i < APP_MAX_LINKS; i++) {
137 if (p->pci_blacklist[i] == NULL)
142 "--pci-blacklist=%s",
143 p->pci_blacklist[i]);
144 app->eal_argv[n_args++] = strdup(buffer);
147 if (app->port_mask != 0)
148 for (i = 0; i < APP_MAX_LINKS; i++) {
149 if (p->pci_whitelist[i] == NULL)
154 "--pci-whitelist=%s",
155 p->pci_whitelist[i]);
156 app->eal_argv[n_args++] = strdup(buffer);
159 for (i = 0; i < app->n_links; i++) {
160 char *pci_bdf = app->link_params[i].pci_bdf;
164 "--pci-whitelist=%s",
166 app->eal_argv[n_args++] = strdup(buffer);
169 for (i = 0; i < APP_MAX_LINKS; i++) {
170 if (p->vdev[i] == NULL)
177 app->eal_argv[n_args++] = strdup(buffer);
180 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
181 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
182 app->eal_argv[n_args++] = strdup(buffer);
190 app->eal_argv[n_args++] = strdup(buffer);
194 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
195 app->eal_argv[n_args++] = strdup(buffer);
198 if (p->log_level_present) {
201 "--log-level=%" PRIu32,
203 app->eal_argv[n_args++] = strdup(buffer);
206 if ((p->version_present) && p->version) {
207 snprintf(buffer, sizeof(buffer), "-v");
208 app->eal_argv[n_args++] = strdup(buffer);
211 if ((p->help_present) && p->help) {
212 snprintf(buffer, sizeof(buffer), "--help");
213 app->eal_argv[n_args++] = strdup(buffer);
216 if ((p->no_huge_present) && p->no_huge) {
217 snprintf(buffer, sizeof(buffer), "--no-huge");
218 app->eal_argv[n_args++] = strdup(buffer);
221 if ((p->no_pci_present) && p->no_pci) {
222 snprintf(buffer, sizeof(buffer), "--no-pci");
223 app->eal_argv[n_args++] = strdup(buffer);
226 if ((p->no_hpet_present) && p->no_hpet) {
227 snprintf(buffer, sizeof(buffer), "--no-hpet");
228 app->eal_argv[n_args++] = strdup(buffer);
231 if ((p->no_shconf_present) && p->no_shconf) {
232 snprintf(buffer, sizeof(buffer), "--no-shconf");
233 app->eal_argv[n_args++] = strdup(buffer);
237 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
238 app->eal_argv[n_args++] = strdup(buffer);
246 app->eal_argv[n_args++] = strdup(buffer);
250 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
251 app->eal_argv[n_args++] = strdup(buffer);
254 if (p->file_prefix) {
259 app->eal_argv[n_args++] = strdup(buffer);
262 if (p->base_virtaddr) {
265 "--base-virtaddr=%s",
267 app->eal_argv[n_args++] = strdup(buffer);
270 if ((p->create_uio_dev_present) && p->create_uio_dev) {
271 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
272 app->eal_argv[n_args++] = strdup(buffer);
280 app->eal_argv[n_args++] = strdup(buffer);
283 if ((p->xen_dom0_present) && (p->xen_dom0)) {
284 snprintf(buffer, sizeof(buffer), "--xen-dom0");
285 app->eal_argv[n_args++] = strdup(buffer);
288 snprintf(buffer, sizeof(buffer), "--");
289 app->eal_argv[n_args++] = strdup(buffer);
291 app->eal_argc = n_args;
293 APP_LOG(app, HIGH, "Initializing EAL ...");
294 if (app->log_level >= APP_LOG_LEVEL_LOW) {
297 fprintf(stdout, "[APP] EAL arguments: \"");
298 for (i = 1; i < app->eal_argc; i++)
299 fprintf(stdout, "%s ", app->eal_argv[i]);
300 fprintf(stdout, "\"\n");
303 status = rte_eal_init(app->eal_argc, app->eal_argv);
305 rte_panic("EAL init error\n");
309 app_init_mempool(struct app_params *app)
313 for (i = 0; i < app->n_mempools; i++) {
314 struct app_mempool_params *p = &app->mempool_params[i];
316 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
317 app->mempool[i] = rte_mempool_create(
322 sizeof(struct rte_pktmbuf_pool_private),
323 rte_pktmbuf_pool_init, NULL,
324 rte_pktmbuf_init, NULL,
328 if (app->mempool[i] == NULL)
329 rte_panic("%s init error\n", p->name);
334 app_link_filter_arp_add(struct app_link_params *link)
336 struct rte_eth_ethertype_filter filter = {
337 .ether_type = ETHER_TYPE_ARP,
339 .queue = link->arp_q,
342 return rte_eth_dev_filter_ctrl(link->pmd_id,
343 RTE_ETH_FILTER_ETHERTYPE,
349 app_link_filter_tcp_syn_add(struct app_link_params *link)
351 struct rte_eth_syn_filter filter = {
353 .queue = link->tcp_syn_q,
356 return rte_eth_dev_filter_ctrl(link->pmd_id,
363 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
365 struct rte_eth_ntuple_filter filter = {
366 .flags = RTE_5TUPLE_FLAGS,
367 .dst_ip = rte_bswap32(l2->ip),
368 .dst_ip_mask = UINT32_MAX, /* Enable */
370 .src_ip_mask = 0, /* Disable */
372 .dst_port_mask = 0, /* Disable */
374 .src_port_mask = 0, /* Disable */
376 .proto_mask = 0, /* Disable */
378 .priority = 1, /* Lowest */
379 .queue = l1->ip_local_q,
382 return rte_eth_dev_filter_ctrl(l1->pmd_id,
383 RTE_ETH_FILTER_NTUPLE,
389 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
391 struct rte_eth_ntuple_filter filter = {
392 .flags = RTE_5TUPLE_FLAGS,
393 .dst_ip = rte_bswap32(l2->ip),
394 .dst_ip_mask = UINT32_MAX, /* Enable */
396 .src_ip_mask = 0, /* Disable */
398 .dst_port_mask = 0, /* Disable */
400 .src_port_mask = 0, /* Disable */
402 .proto_mask = 0, /* Disable */
404 .priority = 1, /* Lowest */
405 .queue = l1->ip_local_q,
408 return rte_eth_dev_filter_ctrl(l1->pmd_id,
409 RTE_ETH_FILTER_NTUPLE,
410 RTE_ETH_FILTER_DELETE,
415 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
417 struct rte_eth_ntuple_filter filter = {
418 .flags = RTE_5TUPLE_FLAGS,
419 .dst_ip = rte_bswap32(l2->ip),
420 .dst_ip_mask = UINT32_MAX, /* Enable */
422 .src_ip_mask = 0, /* Disable */
424 .dst_port_mask = 0, /* Disable */
426 .src_port_mask = 0, /* Disable */
427 .proto = IPPROTO_TCP,
428 .proto_mask = UINT8_MAX, /* Enable */
430 .priority = 2, /* Higher priority than IP */
431 .queue = l1->tcp_local_q,
434 return rte_eth_dev_filter_ctrl(l1->pmd_id,
435 RTE_ETH_FILTER_NTUPLE,
441 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
443 struct rte_eth_ntuple_filter filter = {
444 .flags = RTE_5TUPLE_FLAGS,
445 .dst_ip = rte_bswap32(l2->ip),
446 .dst_ip_mask = UINT32_MAX, /* Enable */
448 .src_ip_mask = 0, /* Disable */
450 .dst_port_mask = 0, /* Disable */
452 .src_port_mask = 0, /* Disable */
453 .proto = IPPROTO_TCP,
454 .proto_mask = UINT8_MAX, /* Enable */
456 .priority = 2, /* Higher priority than IP */
457 .queue = l1->tcp_local_q,
460 return rte_eth_dev_filter_ctrl(l1->pmd_id,
461 RTE_ETH_FILTER_NTUPLE,
462 RTE_ETH_FILTER_DELETE,
467 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
469 struct rte_eth_ntuple_filter filter = {
470 .flags = RTE_5TUPLE_FLAGS,
471 .dst_ip = rte_bswap32(l2->ip),
472 .dst_ip_mask = UINT32_MAX, /* Enable */
474 .src_ip_mask = 0, /* Disable */
476 .dst_port_mask = 0, /* Disable */
478 .src_port_mask = 0, /* Disable */
479 .proto = IPPROTO_UDP,
480 .proto_mask = UINT8_MAX, /* Enable */
482 .priority = 2, /* Higher priority than IP */
483 .queue = l1->udp_local_q,
486 return rte_eth_dev_filter_ctrl(l1->pmd_id,
487 RTE_ETH_FILTER_NTUPLE,
493 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
495 struct rte_eth_ntuple_filter filter = {
496 .flags = RTE_5TUPLE_FLAGS,
497 .dst_ip = rte_bswap32(l2->ip),
498 .dst_ip_mask = UINT32_MAX, /* Enable */
500 .src_ip_mask = 0, /* Disable */
502 .dst_port_mask = 0, /* Disable */
504 .src_port_mask = 0, /* Disable */
505 .proto = IPPROTO_UDP,
506 .proto_mask = UINT8_MAX, /* Enable */
508 .priority = 2, /* Higher priority than IP */
509 .queue = l1->udp_local_q,
512 return rte_eth_dev_filter_ctrl(l1->pmd_id,
513 RTE_ETH_FILTER_NTUPLE,
514 RTE_ETH_FILTER_DELETE,
519 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
521 struct rte_eth_ntuple_filter filter = {
522 .flags = RTE_5TUPLE_FLAGS,
523 .dst_ip = rte_bswap32(l2->ip),
524 .dst_ip_mask = UINT32_MAX, /* Enable */
526 .src_ip_mask = 0, /* Disable */
528 .dst_port_mask = 0, /* Disable */
530 .src_port_mask = 0, /* Disable */
531 .proto = IPPROTO_SCTP,
532 .proto_mask = UINT8_MAX, /* Enable */
534 .priority = 2, /* Higher priority than IP */
535 .queue = l1->sctp_local_q,
538 return rte_eth_dev_filter_ctrl(l1->pmd_id,
539 RTE_ETH_FILTER_NTUPLE,
545 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
547 struct rte_eth_ntuple_filter filter = {
548 .flags = RTE_5TUPLE_FLAGS,
549 .dst_ip = rte_bswap32(l2->ip),
550 .dst_ip_mask = UINT32_MAX, /* Enable */
552 .src_ip_mask = 0, /* Disable */
554 .dst_port_mask = 0, /* Disable */
556 .src_port_mask = 0, /* Disable */
557 .proto = IPPROTO_SCTP,
558 .proto_mask = UINT8_MAX, /* Enable */
560 .priority = 2, /* Higher priority than IP */
561 .queue = l1->sctp_local_q,
564 return rte_eth_dev_filter_ctrl(l1->pmd_id,
565 RTE_ETH_FILTER_NTUPLE,
566 RTE_ETH_FILTER_DELETE,
571 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
573 if (cp->arp_q != 0) {
574 int status = app_link_filter_arp_add(cp);
576 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
577 "Adding ARP filter (queue = %" PRIu32 ")",
578 cp->name, cp->pmd_id, cp->arp_q);
581 rte_panic("%s (%" PRIu32 "): "
582 "Error adding ARP filter "
583 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
584 cp->name, cp->pmd_id, cp->arp_q, status);
589 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
591 if (cp->tcp_syn_q != 0) {
592 int status = app_link_filter_tcp_syn_add(cp);
594 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
595 "Adding TCP SYN filter (queue = %" PRIu32 ")",
596 cp->name, cp->pmd_id, cp->tcp_syn_q);
599 rte_panic("%s (%" PRIu32 "): "
600 "Error adding TCP SYN filter "
601 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
602 cp->name, cp->pmd_id, cp->tcp_syn_q,
608 app_link_is_virtual(struct app_link_params *p)
610 uint32_t pmd_id = p->pmd_id;
611 struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
613 if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
620 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
625 if (app_link_is_virtual(cp)) {
630 /* For each link, add filters for IP of current link */
632 for (i = 0; i < app->n_links; i++) {
633 struct app_link_params *p = &app->link_params[i];
636 if (p->ip_local_q != 0) {
637 int status = app_link_filter_ip_add(p, cp);
639 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
640 "Adding IP filter (queue= %" PRIu32
641 ", IP = 0x%08" PRIx32 ")",
642 p->name, p->pmd_id, p->ip_local_q,
646 rte_panic("%s (%" PRIu32 "): "
648 "filter (queue= %" PRIu32 ", "
652 p->ip_local_q, cp->ip, status);
656 if (p->tcp_local_q != 0) {
657 int status = app_link_filter_tcp_add(p, cp);
659 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
662 ", IP = 0x%08" PRIx32 ")",
663 p->name, p->pmd_id, p->tcp_local_q,
667 rte_panic("%s (%" PRIu32 "): "
669 "filter (queue = %" PRIu32 ", "
673 p->tcp_local_q, cp->ip, status);
677 if (p->udp_local_q != 0) {
678 int status = app_link_filter_udp_add(p, cp);
680 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
683 ", IP = 0x%08" PRIx32 ")",
684 p->name, p->pmd_id, p->udp_local_q,
688 rte_panic("%s (%" PRIu32 "): "
690 "filter (queue = %" PRIu32 ", "
694 p->udp_local_q, cp->ip, status);
698 if (p->sctp_local_q != 0) {
699 int status = app_link_filter_sctp_add(p, cp);
701 APP_LOG(app, LOW, "%s (%" PRIu32
702 "): Adding SCTP filter "
704 ", IP = 0x%08" PRIx32 ")",
705 p->name, p->pmd_id, p->sctp_local_q,
709 rte_panic("%s (%" PRIu32 "): "
711 "filter (queue = %" PRIu32 ", "
715 p->sctp_local_q, cp->ip,
722 status = rte_eth_dev_set_link_up(cp->pmd_id);
724 rte_panic("%s (%" PRIu32 "): PMD set link up error %"
725 PRId32 "\n", cp->name, cp->pmd_id, status);
727 /* Mark link as UP */
732 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
737 if (app_link_is_virtual(cp)) {
743 status = rte_eth_dev_set_link_down(cp->pmd_id);
745 rte_panic("%s (%" PRIu32 "): PMD set link down error %"
746 PRId32 "\n", cp->name, cp->pmd_id, status);
748 /* Mark link as DOWN */
751 /* Return if current link IP is not valid */
755 /* For each link, remove filters for IP of current link */
756 for (i = 0; i < app->n_links; i++) {
757 struct app_link_params *p = &app->link_params[i];
760 if (p->ip_local_q != 0) {
761 int status = app_link_filter_ip_del(p, cp);
763 APP_LOG(app, LOW, "%s (%" PRIu32
764 "): Deleting IP filter "
765 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
766 p->name, p->pmd_id, p->ip_local_q, cp->ip);
769 rte_panic("%s (%" PRIu32
770 "): Error deleting IP filter "
774 p->name, p->pmd_id, p->ip_local_q,
779 if (p->tcp_local_q != 0) {
780 int status = app_link_filter_tcp_del(p, cp);
782 APP_LOG(app, LOW, "%s (%" PRIu32
783 "): Deleting TCP filter "
785 ", IP = 0x%" PRIx32 ")",
786 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
789 rte_panic("%s (%" PRIu32
790 "): Error deleting TCP filter "
794 p->name, p->pmd_id, p->tcp_local_q,
799 if (p->udp_local_q != 0) {
800 int status = app_link_filter_udp_del(p, cp);
802 APP_LOG(app, LOW, "%s (%" PRIu32
803 "): Deleting UDP filter "
804 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
805 p->name, p->pmd_id, p->udp_local_q, cp->ip);
808 rte_panic("%s (%" PRIu32
809 "): Error deleting UDP filter "
813 p->name, p->pmd_id, p->udp_local_q,
818 if (p->sctp_local_q != 0) {
819 int status = app_link_filter_sctp_del(p, cp);
821 APP_LOG(app, LOW, "%s (%" PRIu32
822 "): Deleting SCTP filter "
824 ", IP = 0x%" PRIx32 ")",
825 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
828 rte_panic("%s (%" PRIu32
829 "): Error deleting SCTP filter "
833 p->name, p->pmd_id, p->sctp_local_q,
840 app_check_link(struct app_params *app)
842 uint32_t all_links_up, i;
846 for (i = 0; i < app->n_links; i++) {
847 struct app_link_params *p = &app->link_params[i];
848 struct rte_eth_link link_params;
850 memset(&link_params, 0, sizeof(link_params));
851 rte_eth_link_get(p->pmd_id, &link_params);
853 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
856 link_params.link_speed / 1000,
857 link_params.link_status ? "UP" : "DOWN");
859 if (link_params.link_status == 0)
863 if (all_links_up == 0)
864 rte_panic("Some links are DOWN\n");
868 is_any_swq_frag_or_ras(struct app_params *app)
872 for (i = 0; i < app->n_pktq_swq; i++) {
873 struct app_pktq_swq_params *p = &app->swq_params[i];
875 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
876 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
884 app_init_link_frag_ras(struct app_params *app)
888 if (is_any_swq_frag_or_ras(app)) {
889 for (i = 0; i < app->n_pktq_hwq_out; i++) {
890 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
892 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
898 app_get_cpu_socket_id(uint32_t pmd_id)
900 int status = rte_eth_dev_socket_id(pmd_id);
902 return (status != SOCKET_ID_ANY) ? status : 0;
906 app_init_link(struct app_params *app)
910 app_init_link_frag_ras(app);
912 for (i = 0; i < app->n_links; i++) {
913 struct app_link_params *p_link = &app->link_params[i];
914 uint32_t link_id, n_hwq_in, n_hwq_out, j;
917 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
918 n_hwq_in = app_link_get_n_rxq(app, p_link);
919 n_hwq_out = app_link_get_n_txq(app, p_link);
921 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
922 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
929 status = rte_eth_dev_configure(
935 rte_panic("%s (%" PRId32 "): "
936 "init error (%" PRId32 ")\n",
937 p_link->name, p_link->pmd_id, status);
939 rte_eth_macaddr_get(p_link->pmd_id,
940 (struct ether_addr *) &p_link->mac_addr);
943 rte_eth_promiscuous_enable(p_link->pmd_id);
946 for (j = 0; j < app->n_pktq_hwq_in; j++) {
947 struct app_pktq_hwq_in_params *p_rxq =
948 &app->hwq_in_params[j];
949 uint32_t rxq_link_id, rxq_queue_id;
951 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
952 &rxq_link_id, &rxq_queue_id);
953 if (rxq_link_id != link_id)
956 status = rte_eth_rx_queue_setup(
960 app_get_cpu_socket_id(p_link->pmd_id),
962 app->mempool[p_rxq->mempool_id]);
964 rte_panic("%s (%" PRIu32 "): "
965 "%s init error (%" PRId32 ")\n",
973 for (j = 0; j < app->n_pktq_hwq_out; j++) {
974 struct app_pktq_hwq_out_params *p_txq =
975 &app->hwq_out_params[j];
976 uint32_t txq_link_id, txq_queue_id;
978 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
979 &txq_link_id, &txq_queue_id);
980 if (txq_link_id != link_id)
983 status = rte_eth_tx_queue_setup(
987 app_get_cpu_socket_id(p_link->pmd_id),
990 rte_panic("%s (%" PRIu32 "): "
991 "%s init error (%" PRId32 ")\n",
999 status = rte_eth_dev_start(p_link->pmd_id);
1001 rte_panic("Cannot start %s (error %" PRId32 ")\n",
1002 p_link->name, status);
1005 app_link_set_arp_filter(app, p_link);
1006 app_link_set_tcp_syn_filter(app, p_link);
1007 app_link_up_internal(app, p_link);
1010 app_check_link(app);
1014 app_init_swq(struct app_params *app)
1018 for (i = 0; i < app->n_pktq_swq; i++) {
1019 struct app_pktq_swq_params *p = &app->swq_params[i];
1022 if (app_swq_get_readers(app, p) == 1)
1023 flags |= RING_F_SC_DEQ;
1024 if (app_swq_get_writers(app, p) == 1)
1025 flags |= RING_F_SP_ENQ;
1027 APP_LOG(app, HIGH, "Initializing %s...", p->name);
1028 app->swq[i] = rte_ring_create(
1034 if (app->swq[i] == NULL)
1035 rte_panic("%s init error\n", p->name);
1040 app_init_tm(struct app_params *app)
1044 for (i = 0; i < app->n_pktq_tm; i++) {
1045 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
1046 struct app_link_params *p_link;
1047 struct rte_eth_link link_eth_params;
1048 struct rte_sched_port *sched;
1049 uint32_t n_subports, subport_id;
1052 p_link = app_get_link_for_tm(app, p_tm);
1054 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
1057 p_tm->sched_port_params.name = p_tm->name;
1058 p_tm->sched_port_params.socket =
1059 app_get_cpu_socket_id(p_link->pmd_id);
1060 p_tm->sched_port_params.rate =
1061 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1063 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1064 sched = rte_sched_port_config(&p_tm->sched_port_params);
1066 rte_panic("%s init error\n", p_tm->name);
1070 n_subports = p_tm->sched_port_params.n_subports_per_port;
1071 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1072 uint32_t n_pipes_per_subport, pipe_id;
1074 status = rte_sched_subport_config(sched,
1076 &p_tm->sched_subport_params[subport_id]);
1078 rte_panic("%s subport %" PRIu32
1079 " init error (%" PRId32 ")\n",
1080 p_tm->name, subport_id, status);
1083 n_pipes_per_subport =
1084 p_tm->sched_port_params.n_pipes_per_subport;
1086 pipe_id < n_pipes_per_subport;
1088 int profile_id = p_tm->sched_pipe_to_profile[
1089 subport_id * APP_MAX_SCHED_PIPES +
1092 if (profile_id == -1)
1095 status = rte_sched_pipe_config(sched,
1100 rte_panic("%s subport %" PRIu32
1102 " (profile %" PRId32 ") "
1103 "init error (% " PRId32 ")\n",
1104 p_tm->name, subport_id, pipe_id,
1105 profile_id, status);
1112 app_init_msgq(struct app_params *app)
1116 for (i = 0; i < app->n_msgq; i++) {
1117 struct app_msgq_params *p = &app->msgq_params[i];
1119 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1120 app->msgq[i] = rte_ring_create(
1124 RING_F_SP_ENQ | RING_F_SC_DEQ);
1126 if (app->msgq[i] == NULL)
1127 rte_panic("%s init error\n", p->name);
1131 static void app_pipeline_params_get(struct app_params *app,
1132 struct app_pipeline_params *p_in,
1133 struct pipeline_params *p_out)
1136 uint32_t mempool_id;
1138 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1140 p_out->socket_id = (int) p_in->socket_id;
1142 p_out->log_level = app->log_level;
1145 p_out->n_ports_in = p_in->n_pktq_in;
1146 for (i = 0; i < p_in->n_pktq_in; i++) {
1147 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1148 struct pipeline_port_in_params *out = &p_out->port_in[i];
1151 case APP_PKTQ_IN_HWQ:
1153 struct app_pktq_hwq_in_params *p_hwq_in =
1154 &app->hwq_in_params[in->id];
1155 struct app_link_params *p_link =
1156 app_get_link_for_rxq(app, p_hwq_in);
1157 uint32_t rxq_link_id, rxq_queue_id;
1159 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1163 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1164 out->params.ethdev.port_id = p_link->pmd_id;
1165 out->params.ethdev.queue_id = rxq_queue_id;
1166 out->burst_size = p_hwq_in->burst;
1169 case APP_PKTQ_IN_SWQ:
1171 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1173 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1174 if (app_swq_get_readers(app, swq_params) == 1) {
1175 out->type = PIPELINE_PORT_IN_RING_READER;
1176 out->params.ring.ring = app->swq[in->id];
1177 out->burst_size = app->swq_params[in->id].burst_read;
1179 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1180 out->params.ring_multi.ring = app->swq[in->id];
1181 out->burst_size = swq_params->burst_read;
1184 if (swq_params->ipv4_frag == 1) {
1185 struct rte_port_ring_reader_ipv4_frag_params *params =
1186 &out->params.ring_ipv4_frag;
1188 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1189 params->ring = app->swq[in->id];
1190 params->mtu = swq_params->mtu;
1191 params->metadata_size = swq_params->metadata_size;
1192 params->pool_direct =
1193 app->mempool[swq_params->mempool_direct_id];
1194 params->pool_indirect =
1195 app->mempool[swq_params->mempool_indirect_id];
1196 out->burst_size = swq_params->burst_read;
1198 struct rte_port_ring_reader_ipv6_frag_params *params =
1199 &out->params.ring_ipv6_frag;
1201 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1202 params->ring = app->swq[in->id];
1203 params->mtu = swq_params->mtu;
1204 params->metadata_size = swq_params->metadata_size;
1205 params->pool_direct =
1206 app->mempool[swq_params->mempool_direct_id];
1207 params->pool_indirect =
1208 app->mempool[swq_params->mempool_indirect_id];
1209 out->burst_size = swq_params->burst_read;
1214 case APP_PKTQ_IN_TM:
1215 out->type = PIPELINE_PORT_IN_SCHED_READER;
1216 out->params.sched.sched = app->tm[in->id];
1217 out->burst_size = app->tm_params[in->id].burst_read;
1219 case APP_PKTQ_IN_SOURCE:
1220 mempool_id = app->source_params[in->id].mempool_id;
1221 out->type = PIPELINE_PORT_IN_SOURCE;
1222 out->params.source.mempool = app->mempool[mempool_id];
1223 out->burst_size = app->source_params[in->id].burst;
1226 if (app->source_params[in->id].file_name
1228 out->params.source.file_name = strdup(
1229 app->source_params[in->id].
1231 if (out->params.source.file_name == NULL) {
1233 n_bytes_per_pkt = 0;
1236 out->params.source.n_bytes_per_pkt =
1237 app->source_params[in->id].
1249 p_out->n_ports_out = p_in->n_pktq_out;
1250 for (i = 0; i < p_in->n_pktq_out; i++) {
1251 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1252 struct pipeline_port_out_params *out = &p_out->port_out[i];
1255 case APP_PKTQ_OUT_HWQ:
1257 struct app_pktq_hwq_out_params *p_hwq_out =
1258 &app->hwq_out_params[in->id];
1259 struct app_link_params *p_link =
1260 app_get_link_for_txq(app, p_hwq_out);
1261 uint32_t txq_link_id, txq_queue_id;
1263 sscanf(p_hwq_out->name,
1264 "TXQ%" SCNu32 ".%" SCNu32,
1268 if (p_hwq_out->dropless == 0) {
1269 struct rte_port_ethdev_writer_params *params =
1270 &out->params.ethdev;
1272 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1273 params->port_id = p_link->pmd_id;
1274 params->queue_id = txq_queue_id;
1275 params->tx_burst_sz =
1276 app->hwq_out_params[in->id].burst;
1278 struct rte_port_ethdev_writer_nodrop_params
1279 *params = &out->params.ethdev_nodrop;
1282 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1283 params->port_id = p_link->pmd_id;
1284 params->queue_id = txq_queue_id;
1285 params->tx_burst_sz = p_hwq_out->burst;
1286 params->n_retries = p_hwq_out->n_retries;
1290 case APP_PKTQ_OUT_SWQ:
1292 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1294 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1295 if (app_swq_get_writers(app, swq_params) == 1) {
1296 if (app->swq_params[in->id].dropless == 0) {
1297 struct rte_port_ring_writer_params *params =
1300 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1301 params->ring = app->swq[in->id];
1302 params->tx_burst_sz =
1303 app->swq_params[in->id].burst_write;
1305 struct rte_port_ring_writer_nodrop_params
1306 *params = &out->params.ring_nodrop;
1309 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1310 params->ring = app->swq[in->id];
1311 params->tx_burst_sz =
1312 app->swq_params[in->id].burst_write;
1314 app->swq_params[in->id].n_retries;
1317 if (swq_params->dropless == 0) {
1318 struct rte_port_ring_multi_writer_params *params =
1319 &out->params.ring_multi;
1321 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1322 params->ring = app->swq[in->id];
1323 params->tx_burst_sz = swq_params->burst_write;
1325 struct rte_port_ring_multi_writer_nodrop_params
1326 *params = &out->params.ring_multi_nodrop;
1328 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1329 params->ring = app->swq[in->id];
1330 params->tx_burst_sz = swq_params->burst_write;
1331 params->n_retries = swq_params->n_retries;
1335 if (swq_params->ipv4_ras == 1) {
1336 struct rte_port_ring_writer_ipv4_ras_params *params =
1337 &out->params.ring_ipv4_ras;
1339 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1340 params->ring = app->swq[in->id];
1341 params->tx_burst_sz = swq_params->burst_write;
1343 struct rte_port_ring_writer_ipv6_ras_params *params =
1344 &out->params.ring_ipv6_ras;
1346 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1347 params->ring = app->swq[in->id];
1348 params->tx_burst_sz = swq_params->burst_write;
1353 case APP_PKTQ_OUT_TM: {
1354 struct rte_port_sched_writer_params *params =
1357 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1358 params->sched = app->tm[in->id];
1359 params->tx_burst_sz =
1360 app->tm_params[in->id].burst_write;
1363 case APP_PKTQ_OUT_SINK:
1364 out->type = PIPELINE_PORT_OUT_SINK;
1365 if (app->sink_params[in->id].file_name != NULL) {
1366 out->params.sink.file_name = strdup(
1367 app->sink_params[in->id].
1369 if (out->params.sink.file_name == NULL) {
1370 out->params.sink.max_n_pkts = 0;
1373 out->params.sink.max_n_pkts =
1374 app->sink_params[in->id].
1377 out->params.sink.file_name = NULL;
1378 out->params.sink.max_n_pkts = 0;
1387 p_out->n_msgq = p_in->n_msgq_in;
1389 for (i = 0; i < p_in->n_msgq_in; i++)
1390 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1392 for (i = 0; i < p_in->n_msgq_out; i++)
1393 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1396 p_out->n_args = p_in->n_args;
1397 for (i = 0; i < p_in->n_args; i++) {
1398 p_out->args_name[i] = p_in->args_name[i];
1399 p_out->args_value[i] = p_in->args_value[i];
1404 app_init_pipelines(struct app_params *app)
1408 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1409 struct app_pipeline_params *params =
1410 &app->pipeline_params[p_id];
1411 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1412 struct pipeline_type *ptype;
1413 struct pipeline_params pp;
1415 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1417 ptype = app_pipeline_type_find(app, params->type);
1419 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1422 app_pipeline_params_get(app, params, &pp);
1426 if (ptype->be_ops->f_init) {
1427 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1429 if (data->be == NULL)
1430 rte_panic("Pipeline instance \"%s\" back-end "
1431 "init error\n", params->name);
1436 if (ptype->fe_ops->f_init) {
1437 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1439 if (data->fe == NULL)
1440 rte_panic("Pipeline instance \"%s\" front-end "
1441 "init error\n", params->name);
1444 data->ptype = ptype;
1446 data->timer_period = (rte_get_tsc_hz() *
1447 params->timer_period) / 100;
1452 app_init_threads(struct app_params *app)
1454 uint64_t time = rte_get_tsc_cycles();
1457 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1458 struct app_pipeline_params *params =
1459 &app->pipeline_params[p_id];
1460 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1461 struct pipeline_type *ptype;
1462 struct app_thread_data *t;
1463 struct app_thread_pipeline_data *p;
1466 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1469 params->hyper_th_id);
1472 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1475 (params->hyper_th_id) ? "h" : "");
1477 t = &app->thread_data[lcore_id];
1479 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1480 t->thread_req_deadline = time + t->timer_period;
1482 t->headroom_cycles = 0;
1483 t->headroom_time = rte_get_tsc_cycles();
1484 t->headroom_ratio = 0.0;
1486 t->msgq_in = app_thread_msgq_in_get(app,
1489 params->hyper_th_id);
1490 if (t->msgq_in == NULL)
1491 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1494 t->msgq_out = app_thread_msgq_out_get(app,
1497 params->hyper_th_id);
1498 if (t->msgq_out == NULL)
1499 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1502 ptype = app_pipeline_type_find(app, params->type);
1504 rte_panic("Init error: Unknown pipeline "
1505 "type \"%s\"\n", params->type);
1507 p = (ptype->be_ops->f_run == NULL) ?
1508 &t->regular[t->n_regular] :
1509 &t->custom[t->n_custom];
1511 p->pipeline_id = p_id;
1513 p->f_run = ptype->be_ops->f_run;
1514 p->f_timer = ptype->be_ops->f_timer;
1515 p->timer_period = data->timer_period;
1516 p->deadline = time + data->timer_period;
1520 if (ptype->be_ops->f_run == NULL)
1527 int app_init(struct app_params *app)
1529 app_init_core_map(app);
1530 app_init_core_mask(app);
1533 app_init_mempool(app);
1539 app_pipeline_common_cmd_push(app);
1540 app_pipeline_thread_cmd_push(app);
1541 app_pipeline_type_register(app, &pipeline_master);
1542 app_pipeline_type_register(app, &pipeline_passthrough);
1543 app_pipeline_type_register(app, &pipeline_flow_classification);
1544 app_pipeline_type_register(app, &pipeline_flow_actions);
1545 app_pipeline_type_register(app, &pipeline_firewall);
1546 app_pipeline_type_register(app, &pipeline_routing);
1548 app_init_pipelines(app);
1549 app_init_threads(app);
1555 app_pipeline_type_cmd_push(struct app_params *app,
1556 struct pipeline_type *ptype)
1558 cmdline_parse_ctx_t *cmds;
1561 /* Check input arguments */
1562 if ((app == NULL) ||
1566 n_cmds = pipeline_type_cmds_count(ptype);
1570 cmds = ptype->fe_ops->cmds;
1572 /* Check for available slots in the application commands array */
1573 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1576 /* Push pipeline commands into the application */
1577 memcpy(&app->cmds[app->n_cmds],
1579 n_cmds * sizeof(cmdline_parse_ctx_t));
1581 for (i = 0; i < n_cmds; i++)
1582 app->cmds[app->n_cmds + i]->data = app;
1584 app->n_cmds += n_cmds;
1585 app->cmds[app->n_cmds] = NULL;
1591 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1595 /* Check input arguments */
1596 if ((app == NULL) ||
1598 (ptype->name == NULL) ||
1599 (strlen(ptype->name) == 0) ||
1600 (ptype->be_ops->f_init == NULL) ||
1601 (ptype->be_ops->f_timer == NULL))
1604 /* Check for duplicate entry */
1605 for (i = 0; i < app->n_pipeline_types; i++)
1606 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1609 /* Check for resource availability */
1610 n_cmds = pipeline_type_cmds_count(ptype);
1611 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1612 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1615 /* Copy pipeline type */
1616 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1618 sizeof(struct pipeline_type));
1620 /* Copy CLI commands */
1622 app_pipeline_type_cmd_push(app, ptype);
1628 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1632 for (i = 0; i < app->n_pipeline_types; i++)
1633 if (strcmp(app->pipeline_type[i].name, name) == 0)
1634 return &app->pipeline_type[i];