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 == ETH_LINK_DOWN)
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)
1137 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1139 p_out->socket_id = (int) p_in->socket_id;
1141 p_out->log_level = app->log_level;
1144 p_out->n_ports_in = p_in->n_pktq_in;
1145 for (i = 0; i < p_in->n_pktq_in; i++) {
1146 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1147 struct pipeline_port_in_params *out = &p_out->port_in[i];
1150 case APP_PKTQ_IN_HWQ:
1152 struct app_pktq_hwq_in_params *p_hwq_in =
1153 &app->hwq_in_params[in->id];
1154 struct app_link_params *p_link =
1155 app_get_link_for_rxq(app, p_hwq_in);
1156 uint32_t rxq_link_id, rxq_queue_id;
1158 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1162 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1163 out->params.ethdev.port_id = p_link->pmd_id;
1164 out->params.ethdev.queue_id = rxq_queue_id;
1165 out->burst_size = p_hwq_in->burst;
1168 case APP_PKTQ_IN_SWQ:
1170 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1172 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1173 if (app_swq_get_readers(app, swq_params) == 1) {
1174 out->type = PIPELINE_PORT_IN_RING_READER;
1175 out->params.ring.ring = app->swq[in->id];
1176 out->burst_size = app->swq_params[in->id].burst_read;
1178 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1179 out->params.ring_multi.ring = app->swq[in->id];
1180 out->burst_size = swq_params->burst_read;
1183 if (swq_params->ipv4_frag == 1) {
1184 struct rte_port_ring_reader_ipv4_frag_params *params =
1185 &out->params.ring_ipv4_frag;
1187 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1188 params->ring = app->swq[in->id];
1189 params->mtu = swq_params->mtu;
1190 params->metadata_size = swq_params->metadata_size;
1191 params->pool_direct =
1192 app->mempool[swq_params->mempool_direct_id];
1193 params->pool_indirect =
1194 app->mempool[swq_params->mempool_indirect_id];
1195 out->burst_size = swq_params->burst_read;
1197 struct rte_port_ring_reader_ipv6_frag_params *params =
1198 &out->params.ring_ipv6_frag;
1200 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1201 params->ring = app->swq[in->id];
1202 params->mtu = swq_params->mtu;
1203 params->metadata_size = swq_params->metadata_size;
1204 params->pool_direct =
1205 app->mempool[swq_params->mempool_direct_id];
1206 params->pool_indirect =
1207 app->mempool[swq_params->mempool_indirect_id];
1208 out->burst_size = swq_params->burst_read;
1213 case APP_PKTQ_IN_TM:
1214 out->type = PIPELINE_PORT_IN_SCHED_READER;
1215 out->params.sched.sched = app->tm[in->id];
1216 out->burst_size = app->tm_params[in->id].burst_read;
1218 case APP_PKTQ_IN_SOURCE:
1220 uint32_t mempool_id =
1221 app->source_params[in->id].mempool_id;
1223 out->type = PIPELINE_PORT_IN_SOURCE;
1224 out->params.source.mempool = app->mempool[mempool_id];
1225 out->burst_size = app->source_params[in->id].burst;
1226 out->params.source.file_name =
1227 app->source_params[in->id].file_name;
1228 out->params.source.n_bytes_per_pkt =
1229 app->source_params[in->id].n_bytes_per_pkt;
1238 p_out->n_ports_out = p_in->n_pktq_out;
1239 for (i = 0; i < p_in->n_pktq_out; i++) {
1240 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1241 struct pipeline_port_out_params *out = &p_out->port_out[i];
1244 case APP_PKTQ_OUT_HWQ:
1246 struct app_pktq_hwq_out_params *p_hwq_out =
1247 &app->hwq_out_params[in->id];
1248 struct app_link_params *p_link =
1249 app_get_link_for_txq(app, p_hwq_out);
1250 uint32_t txq_link_id, txq_queue_id;
1252 sscanf(p_hwq_out->name,
1253 "TXQ%" SCNu32 ".%" SCNu32,
1257 if (p_hwq_out->dropless == 0) {
1258 struct rte_port_ethdev_writer_params *params =
1259 &out->params.ethdev;
1261 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1262 params->port_id = p_link->pmd_id;
1263 params->queue_id = txq_queue_id;
1264 params->tx_burst_sz =
1265 app->hwq_out_params[in->id].burst;
1267 struct rte_port_ethdev_writer_nodrop_params
1268 *params = &out->params.ethdev_nodrop;
1271 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1272 params->port_id = p_link->pmd_id;
1273 params->queue_id = txq_queue_id;
1274 params->tx_burst_sz = p_hwq_out->burst;
1275 params->n_retries = p_hwq_out->n_retries;
1279 case APP_PKTQ_OUT_SWQ:
1281 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1283 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1284 if (app_swq_get_writers(app, swq_params) == 1) {
1285 if (app->swq_params[in->id].dropless == 0) {
1286 struct rte_port_ring_writer_params *params =
1289 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1290 params->ring = app->swq[in->id];
1291 params->tx_burst_sz =
1292 app->swq_params[in->id].burst_write;
1294 struct rte_port_ring_writer_nodrop_params
1295 *params = &out->params.ring_nodrop;
1298 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1299 params->ring = app->swq[in->id];
1300 params->tx_burst_sz =
1301 app->swq_params[in->id].burst_write;
1303 app->swq_params[in->id].n_retries;
1306 if (swq_params->dropless == 0) {
1307 struct rte_port_ring_multi_writer_params *params =
1308 &out->params.ring_multi;
1310 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1311 params->ring = app->swq[in->id];
1312 params->tx_burst_sz = swq_params->burst_write;
1314 struct rte_port_ring_multi_writer_nodrop_params
1315 *params = &out->params.ring_multi_nodrop;
1317 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1318 params->ring = app->swq[in->id];
1319 params->tx_burst_sz = swq_params->burst_write;
1320 params->n_retries = swq_params->n_retries;
1324 if (swq_params->ipv4_ras == 1) {
1325 struct rte_port_ring_writer_ipv4_ras_params *params =
1326 &out->params.ring_ipv4_ras;
1328 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1329 params->ring = app->swq[in->id];
1330 params->tx_burst_sz = swq_params->burst_write;
1332 struct rte_port_ring_writer_ipv6_ras_params *params =
1333 &out->params.ring_ipv6_ras;
1335 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1336 params->ring = app->swq[in->id];
1337 params->tx_burst_sz = swq_params->burst_write;
1342 case APP_PKTQ_OUT_TM: {
1343 struct rte_port_sched_writer_params *params =
1346 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1347 params->sched = app->tm[in->id];
1348 params->tx_burst_sz =
1349 app->tm_params[in->id].burst_write;
1352 case APP_PKTQ_OUT_SINK:
1354 out->type = PIPELINE_PORT_OUT_SINK;
1355 out->params.sink.file_name =
1356 app->sink_params[in->id].file_name;
1357 out->params.sink.max_n_pkts =
1358 app->sink_params[in->id].
1369 p_out->n_msgq = p_in->n_msgq_in;
1371 for (i = 0; i < p_in->n_msgq_in; i++)
1372 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1374 for (i = 0; i < p_in->n_msgq_out; i++)
1375 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1378 p_out->n_args = p_in->n_args;
1379 for (i = 0; i < p_in->n_args; i++) {
1380 p_out->args_name[i] = p_in->args_name[i];
1381 p_out->args_value[i] = p_in->args_value[i];
1386 app_init_pipelines(struct app_params *app)
1390 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1391 struct app_pipeline_params *params =
1392 &app->pipeline_params[p_id];
1393 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1394 struct pipeline_type *ptype;
1395 struct pipeline_params pp;
1397 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1399 ptype = app_pipeline_type_find(app, params->type);
1401 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1404 app_pipeline_params_get(app, params, &pp);
1408 if (ptype->be_ops->f_init) {
1409 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1411 if (data->be == NULL)
1412 rte_panic("Pipeline instance \"%s\" back-end "
1413 "init error\n", params->name);
1418 if (ptype->fe_ops->f_init) {
1419 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1421 if (data->fe == NULL)
1422 rte_panic("Pipeline instance \"%s\" front-end "
1423 "init error\n", params->name);
1426 data->ptype = ptype;
1428 data->timer_period = (rte_get_tsc_hz() *
1429 params->timer_period) / 100;
1434 app_init_threads(struct app_params *app)
1436 uint64_t time = rte_get_tsc_cycles();
1439 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1440 struct app_pipeline_params *params =
1441 &app->pipeline_params[p_id];
1442 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1443 struct pipeline_type *ptype;
1444 struct app_thread_data *t;
1445 struct app_thread_pipeline_data *p;
1448 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1451 params->hyper_th_id);
1454 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1457 (params->hyper_th_id) ? "h" : "");
1459 t = &app->thread_data[lcore_id];
1461 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1462 t->thread_req_deadline = time + t->timer_period;
1464 t->headroom_cycles = 0;
1465 t->headroom_time = rte_get_tsc_cycles();
1466 t->headroom_ratio = 0.0;
1468 t->msgq_in = app_thread_msgq_in_get(app,
1471 params->hyper_th_id);
1472 if (t->msgq_in == NULL)
1473 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1476 t->msgq_out = app_thread_msgq_out_get(app,
1479 params->hyper_th_id);
1480 if (t->msgq_out == NULL)
1481 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1484 ptype = app_pipeline_type_find(app, params->type);
1486 rte_panic("Init error: Unknown pipeline "
1487 "type \"%s\"\n", params->type);
1489 p = (ptype->be_ops->f_run == NULL) ?
1490 &t->regular[t->n_regular] :
1491 &t->custom[t->n_custom];
1493 p->pipeline_id = p_id;
1495 p->f_run = ptype->be_ops->f_run;
1496 p->f_timer = ptype->be_ops->f_timer;
1497 p->timer_period = data->timer_period;
1498 p->deadline = time + data->timer_period;
1502 if (ptype->be_ops->f_run == NULL)
1509 int app_init(struct app_params *app)
1511 app_init_core_map(app);
1512 app_init_core_mask(app);
1515 app_init_mempool(app);
1521 app_pipeline_common_cmd_push(app);
1522 app_pipeline_thread_cmd_push(app);
1523 app_pipeline_type_register(app, &pipeline_master);
1524 app_pipeline_type_register(app, &pipeline_passthrough);
1525 app_pipeline_type_register(app, &pipeline_flow_classification);
1526 app_pipeline_type_register(app, &pipeline_flow_actions);
1527 app_pipeline_type_register(app, &pipeline_firewall);
1528 app_pipeline_type_register(app, &pipeline_routing);
1530 app_init_pipelines(app);
1531 app_init_threads(app);
1537 app_pipeline_type_cmd_push(struct app_params *app,
1538 struct pipeline_type *ptype)
1540 cmdline_parse_ctx_t *cmds;
1543 /* Check input arguments */
1544 if ((app == NULL) ||
1548 n_cmds = pipeline_type_cmds_count(ptype);
1552 cmds = ptype->fe_ops->cmds;
1554 /* Check for available slots in the application commands array */
1555 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1558 /* Push pipeline commands into the application */
1559 memcpy(&app->cmds[app->n_cmds],
1561 n_cmds * sizeof(cmdline_parse_ctx_t));
1563 for (i = 0; i < n_cmds; i++)
1564 app->cmds[app->n_cmds + i]->data = app;
1566 app->n_cmds += n_cmds;
1567 app->cmds[app->n_cmds] = NULL;
1573 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1577 /* Check input arguments */
1578 if ((app == NULL) ||
1580 (ptype->name == NULL) ||
1581 (strlen(ptype->name) == 0) ||
1582 (ptype->be_ops->f_init == NULL) ||
1583 (ptype->be_ops->f_timer == NULL))
1586 /* Check for duplicate entry */
1587 for (i = 0; i < app->n_pipeline_types; i++)
1588 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1591 /* Check for resource availability */
1592 n_cmds = pipeline_type_cmds_count(ptype);
1593 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1594 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1597 /* Copy pipeline type */
1598 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1600 sizeof(struct pipeline_type));
1602 /* Copy CLI commands */
1604 app_pipeline_type_cmd_push(app, ptype);
1610 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1614 for (i = 0; i < app->n_pipeline_types; i++)
1615 if (strcmp(app->pipeline_type[i].name, name) == 0)
1616 return &app->pipeline_type[i];