4 * Copyright(c) 2010-2015 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;
104 app->eal_argv[n_args++] = strdup(app->app_name);
106 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
107 app->eal_argv[n_args++] = strdup(buffer);
110 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
111 app->eal_argv[n_args++] = strdup(buffer);
114 if (p->master_lcore_present) {
117 "--master-lcore=%" PRIu32,
119 app->eal_argv[n_args++] = strdup(buffer);
122 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
123 app->eal_argv[n_args++] = strdup(buffer);
125 if (p->memory_present) {
126 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
127 app->eal_argv[n_args++] = strdup(buffer);
130 if (p->ranks_present) {
131 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
132 app->eal_argv[n_args++] = strdup(buffer);
135 if (p->pci_blacklist) {
138 "--pci-blacklist=%s",
140 app->eal_argv[n_args++] = strdup(buffer);
143 if (p->pci_whitelist) {
146 "--pci-whitelist=%s",
148 app->eal_argv[n_args++] = strdup(buffer);
152 snprintf(buffer, sizeof(buffer), "--vdev=%s", p->vdev);
153 app->eal_argv[n_args++] = strdup(buffer);
156 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
157 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
158 app->eal_argv[n_args++] = strdup(buffer);
166 app->eal_argv[n_args++] = strdup(buffer);
170 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
171 app->eal_argv[n_args++] = strdup(buffer);
174 if (p->log_level_present) {
177 "--log-level=%" PRIu32,
179 app->eal_argv[n_args++] = strdup(buffer);
182 if ((p->version_present) && p->version) {
183 snprintf(buffer, sizeof(buffer), "-v");
184 app->eal_argv[n_args++] = strdup(buffer);
187 if ((p->help_present) && p->help) {
188 snprintf(buffer, sizeof(buffer), "--help");
189 app->eal_argv[n_args++] = strdup(buffer);
192 if ((p->no_huge_present) && p->no_huge) {
193 snprintf(buffer, sizeof(buffer), "--no-huge");
194 app->eal_argv[n_args++] = strdup(buffer);
197 if ((p->no_pci_present) && p->no_pci) {
198 snprintf(buffer, sizeof(buffer), "--no-pci");
199 app->eal_argv[n_args++] = strdup(buffer);
202 if ((p->no_hpet_present) && p->no_hpet) {
203 snprintf(buffer, sizeof(buffer), "--no-hpet");
204 app->eal_argv[n_args++] = strdup(buffer);
207 if ((p->no_shconf_present) && p->no_shconf) {
208 snprintf(buffer, sizeof(buffer), "--no-shconf");
209 app->eal_argv[n_args++] = strdup(buffer);
213 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
214 app->eal_argv[n_args++] = strdup(buffer);
222 app->eal_argv[n_args++] = strdup(buffer);
226 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
227 app->eal_argv[n_args++] = strdup(buffer);
230 if (p->file_prefix) {
235 app->eal_argv[n_args++] = strdup(buffer);
238 if (p->base_virtaddr) {
241 "--base-virtaddr=%s",
243 app->eal_argv[n_args++] = strdup(buffer);
246 if ((p->create_uio_dev_present) && p->create_uio_dev) {
247 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
248 app->eal_argv[n_args++] = strdup(buffer);
256 app->eal_argv[n_args++] = strdup(buffer);
259 if ((p->xen_dom0_present) && (p->xen_dom0)) {
260 snprintf(buffer, sizeof(buffer), "--xen-dom0");
261 app->eal_argv[n_args++] = strdup(buffer);
264 snprintf(buffer, sizeof(buffer), "--");
265 app->eal_argv[n_args++] = strdup(buffer);
267 app->eal_argc = n_args;
269 APP_LOG(app, HIGH, "Initializing EAL ...");
270 status = rte_eal_init(app->eal_argc, app->eal_argv);
272 rte_panic("EAL init error\n");
276 app_init_mempool(struct app_params *app)
280 for (i = 0; i < app->n_mempools; i++) {
281 struct app_mempool_params *p = &app->mempool_params[i];
283 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
284 app->mempool[i] = rte_mempool_create(
289 sizeof(struct rte_pktmbuf_pool_private),
290 rte_pktmbuf_pool_init, NULL,
291 rte_pktmbuf_init, NULL,
295 if (app->mempool[i] == NULL)
296 rte_panic("%s init error\n", p->name);
301 app_link_filter_arp_add(struct app_link_params *link)
303 struct rte_eth_ethertype_filter filter = {
304 .ether_type = ETHER_TYPE_ARP,
306 .queue = link->arp_q,
309 return rte_eth_dev_filter_ctrl(link->pmd_id,
310 RTE_ETH_FILTER_ETHERTYPE,
316 app_link_filter_tcp_syn_add(struct app_link_params *link)
318 struct rte_eth_syn_filter filter = {
320 .queue = link->tcp_syn_local_q,
323 return rte_eth_dev_filter_ctrl(link->pmd_id,
330 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
332 struct rte_eth_ntuple_filter filter = {
333 .flags = RTE_5TUPLE_FLAGS,
334 .dst_ip = rte_bswap32(l2->ip),
335 .dst_ip_mask = UINT32_MAX, /* Enable */
337 .src_ip_mask = 0, /* Disable */
339 .dst_port_mask = 0, /* Disable */
341 .src_port_mask = 0, /* Disable */
343 .proto_mask = 0, /* Disable */
345 .priority = 1, /* Lowest */
346 .queue = l1->ip_local_q,
349 return rte_eth_dev_filter_ctrl(l1->pmd_id,
350 RTE_ETH_FILTER_NTUPLE,
356 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
358 struct rte_eth_ntuple_filter filter = {
359 .flags = RTE_5TUPLE_FLAGS,
360 .dst_ip = rte_bswap32(l2->ip),
361 .dst_ip_mask = UINT32_MAX, /* Enable */
363 .src_ip_mask = 0, /* Disable */
365 .dst_port_mask = 0, /* Disable */
367 .src_port_mask = 0, /* Disable */
369 .proto_mask = 0, /* Disable */
371 .priority = 1, /* Lowest */
372 .queue = l1->ip_local_q,
375 return rte_eth_dev_filter_ctrl(l1->pmd_id,
376 RTE_ETH_FILTER_NTUPLE,
377 RTE_ETH_FILTER_DELETE,
382 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
384 struct rte_eth_ntuple_filter filter = {
385 .flags = RTE_5TUPLE_FLAGS,
386 .dst_ip = rte_bswap32(l2->ip),
387 .dst_ip_mask = UINT32_MAX, /* Enable */
389 .src_ip_mask = 0, /* Disable */
391 .dst_port_mask = 0, /* Disable */
393 .src_port_mask = 0, /* Disable */
394 .proto = IPPROTO_TCP,
395 .proto_mask = UINT8_MAX, /* Enable */
397 .priority = 2, /* Higher priority than IP */
398 .queue = l1->tcp_local_q,
401 return rte_eth_dev_filter_ctrl(l1->pmd_id,
402 RTE_ETH_FILTER_NTUPLE,
408 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
410 struct rte_eth_ntuple_filter filter = {
411 .flags = RTE_5TUPLE_FLAGS,
412 .dst_ip = rte_bswap32(l2->ip),
413 .dst_ip_mask = UINT32_MAX, /* Enable */
415 .src_ip_mask = 0, /* Disable */
417 .dst_port_mask = 0, /* Disable */
419 .src_port_mask = 0, /* Disable */
420 .proto = IPPROTO_TCP,
421 .proto_mask = UINT8_MAX, /* Enable */
423 .priority = 2, /* Higher priority than IP */
424 .queue = l1->tcp_local_q,
427 return rte_eth_dev_filter_ctrl(l1->pmd_id,
428 RTE_ETH_FILTER_NTUPLE,
429 RTE_ETH_FILTER_DELETE,
434 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
436 struct rte_eth_ntuple_filter filter = {
437 .flags = RTE_5TUPLE_FLAGS,
438 .dst_ip = rte_bswap32(l2->ip),
439 .dst_ip_mask = UINT32_MAX, /* Enable */
441 .src_ip_mask = 0, /* Disable */
443 .dst_port_mask = 0, /* Disable */
445 .src_port_mask = 0, /* Disable */
446 .proto = IPPROTO_UDP,
447 .proto_mask = UINT8_MAX, /* Enable */
449 .priority = 2, /* Higher priority than IP */
450 .queue = l1->udp_local_q,
453 return rte_eth_dev_filter_ctrl(l1->pmd_id,
454 RTE_ETH_FILTER_NTUPLE,
460 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
462 struct rte_eth_ntuple_filter filter = {
463 .flags = RTE_5TUPLE_FLAGS,
464 .dst_ip = rte_bswap32(l2->ip),
465 .dst_ip_mask = UINT32_MAX, /* Enable */
467 .src_ip_mask = 0, /* Disable */
469 .dst_port_mask = 0, /* Disable */
471 .src_port_mask = 0, /* Disable */
472 .proto = IPPROTO_UDP,
473 .proto_mask = UINT8_MAX, /* Enable */
475 .priority = 2, /* Higher priority than IP */
476 .queue = l1->udp_local_q,
479 return rte_eth_dev_filter_ctrl(l1->pmd_id,
480 RTE_ETH_FILTER_NTUPLE,
481 RTE_ETH_FILTER_DELETE,
486 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
488 struct rte_eth_ntuple_filter filter = {
489 .flags = RTE_5TUPLE_FLAGS,
490 .dst_ip = rte_bswap32(l2->ip),
491 .dst_ip_mask = UINT32_MAX, /* Enable */
493 .src_ip_mask = 0, /* Disable */
495 .dst_port_mask = 0, /* Disable */
497 .src_port_mask = 0, /* Disable */
498 .proto = IPPROTO_SCTP,
499 .proto_mask = UINT8_MAX, /* Enable */
501 .priority = 2, /* Higher priority than IP */
502 .queue = l1->sctp_local_q,
505 return rte_eth_dev_filter_ctrl(l1->pmd_id,
506 RTE_ETH_FILTER_NTUPLE,
512 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
514 struct rte_eth_ntuple_filter filter = {
515 .flags = RTE_5TUPLE_FLAGS,
516 .dst_ip = rte_bswap32(l2->ip),
517 .dst_ip_mask = UINT32_MAX, /* Enable */
519 .src_ip_mask = 0, /* Disable */
521 .dst_port_mask = 0, /* Disable */
523 .src_port_mask = 0, /* Disable */
524 .proto = IPPROTO_SCTP,
525 .proto_mask = UINT8_MAX, /* Enable */
527 .priority = 2, /* Higher priority than IP */
528 .queue = l1->sctp_local_q,
531 return rte_eth_dev_filter_ctrl(l1->pmd_id,
532 RTE_ETH_FILTER_NTUPLE,
533 RTE_ETH_FILTER_DELETE,
538 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
540 if (cp->arp_q != 0) {
541 int status = app_link_filter_arp_add(cp);
543 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
544 "Adding ARP filter (queue = %" PRIu32 ")",
545 cp->name, cp->pmd_id, cp->arp_q);
548 rte_panic("%s (%" PRIu32 "): "
549 "Error adding ARP filter "
550 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
551 cp->name, cp->pmd_id, cp->arp_q, status);
556 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
558 if (cp->tcp_syn_local_q != 0) {
559 int status = app_link_filter_tcp_syn_add(cp);
561 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
562 "Adding TCP SYN filter (queue = %" PRIu32 ")",
563 cp->name, cp->pmd_id, cp->tcp_syn_local_q);
566 rte_panic("%s (%" PRIu32 "): "
567 "Error adding TCP SYN filter "
568 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
569 cp->name, cp->pmd_id, cp->tcp_syn_local_q,
575 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
580 /* For each link, add filters for IP of current link */
582 for (i = 0; i < app->n_links; i++) {
583 struct app_link_params *p = &app->link_params[i];
586 if (p->ip_local_q != 0) {
587 int status = app_link_filter_ip_add(p, cp);
589 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
590 "Adding IP filter (queue= %" PRIu32
591 ", IP = 0x%08" PRIx32 ")",
592 p->name, p->pmd_id, p->ip_local_q,
596 rte_panic("%s (%" PRIu32 "): "
598 "filter (queue= %" PRIu32 ", "
602 p->ip_local_q, cp->ip, status);
606 if (p->tcp_local_q != 0) {
607 int status = app_link_filter_tcp_add(p, cp);
609 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
612 ", IP = 0x%08" PRIx32 ")",
613 p->name, p->pmd_id, p->tcp_local_q,
617 rte_panic("%s (%" PRIu32 "): "
619 "filter (queue = %" PRIu32 ", "
623 p->tcp_local_q, cp->ip, status);
627 if (p->udp_local_q != 0) {
628 int status = app_link_filter_udp_add(p, cp);
630 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
633 ", IP = 0x%08" PRIx32 ")",
634 p->name, p->pmd_id, p->udp_local_q,
638 rte_panic("%s (%" PRIu32 "): "
640 "filter (queue = %" PRIu32 ", "
644 p->udp_local_q, cp->ip, status);
648 if (p->sctp_local_q != 0) {
649 int status = app_link_filter_sctp_add(p, cp);
651 APP_LOG(app, LOW, "%s (%" PRIu32
652 "): Adding SCTP filter "
654 ", IP = 0x%08" PRIx32 ")",
655 p->name, p->pmd_id, p->sctp_local_q,
659 rte_panic("%s (%" PRIu32 "): "
661 "filter (queue = %" PRIu32 ", "
665 p->sctp_local_q, cp->ip,
672 status = rte_eth_dev_set_link_up(cp->pmd_id);
674 rte_panic("%s (%" PRIu32 "): PMD set up error %" PRId32 "\n",
675 cp->name, cp->pmd_id, status);
677 /* Mark link as UP */
682 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
687 rte_eth_dev_set_link_down(cp->pmd_id);
689 /* Mark link as DOWN */
692 /* Return if current link IP is not valid */
696 /* For each link, remove filters for IP of current link */
697 for (i = 0; i < app->n_links; i++) {
698 struct app_link_params *p = &app->link_params[i];
701 if (p->ip_local_q != 0) {
702 int status = app_link_filter_ip_del(p, cp);
704 APP_LOG(app, LOW, "%s (%" PRIu32
705 "): Deleting IP filter "
706 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
707 p->name, p->pmd_id, p->ip_local_q, cp->ip);
710 rte_panic("%s (%" PRIu32
711 "): Error deleting IP filter "
715 p->name, p->pmd_id, p->ip_local_q,
720 if (p->tcp_local_q != 0) {
721 int status = app_link_filter_tcp_del(p, cp);
723 APP_LOG(app, LOW, "%s (%" PRIu32
724 "): Deleting TCP filter "
726 ", IP = 0x%" PRIx32 ")",
727 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
730 rte_panic("%s (%" PRIu32
731 "): Error deleting TCP filter "
735 p->name, p->pmd_id, p->tcp_local_q,
740 if (p->udp_local_q != 0) {
741 int status = app_link_filter_udp_del(p, cp);
743 APP_LOG(app, LOW, "%s (%" PRIu32
744 "): Deleting UDP filter "
745 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
746 p->name, p->pmd_id, p->udp_local_q, cp->ip);
749 rte_panic("%s (%" PRIu32
750 "): Error deleting UDP filter "
754 p->name, p->pmd_id, p->udp_local_q,
759 if (p->sctp_local_q != 0) {
760 int status = app_link_filter_sctp_del(p, cp);
762 APP_LOG(app, LOW, "%s (%" PRIu32
763 "): Deleting SCTP filter "
765 ", IP = 0x%" PRIx32 ")",
766 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
769 rte_panic("%s (%" PRIu32
770 "): Error deleting SCTP filter "
774 p->name, p->pmd_id, p->sctp_local_q,
781 app_check_link(struct app_params *app)
783 uint32_t all_links_up, i;
787 for (i = 0; i < app->n_links; i++) {
788 struct app_link_params *p = &app->link_params[i];
789 struct rte_eth_link link_params;
791 memset(&link_params, 0, sizeof(link_params));
792 rte_eth_link_get(p->pmd_id, &link_params);
794 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
797 link_params.link_speed / 1000,
798 link_params.link_status ? "UP" : "DOWN");
800 if (link_params.link_status == 0)
804 if (all_links_up == 0)
805 rte_panic("Some links are DOWN\n");
809 is_any_swq_frag_or_ras(struct app_params *app)
813 for (i = 0; i < app->n_pktq_swq; i++) {
814 struct app_pktq_swq_params *p = &app->swq_params[i];
816 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
817 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
825 app_init_link_frag_ras(struct app_params *app)
829 if (is_any_swq_frag_or_ras(app)) {
830 for (i = 0; i < app->n_pktq_hwq_out; i++) {
831 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
833 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
839 app_get_cpu_socket_id(uint32_t pmd_id)
841 int status = rte_eth_dev_socket_id(pmd_id);
843 return (status != SOCKET_ID_ANY) ? status : 0;
847 app_init_link(struct app_params *app)
851 app_init_link_frag_ras(app);
853 for (i = 0; i < app->n_links; i++) {
854 struct app_link_params *p_link = &app->link_params[i];
855 uint32_t link_id, n_hwq_in, n_hwq_out, j;
858 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
859 n_hwq_in = app_link_get_n_rxq(app, p_link);
860 n_hwq_out = app_link_get_n_txq(app, p_link);
862 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
863 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
870 status = rte_eth_dev_configure(
876 rte_panic("%s (%" PRId32 "): "
877 "init error (%" PRId32 ")\n",
878 p_link->name, p_link->pmd_id, status);
880 rte_eth_macaddr_get(p_link->pmd_id,
881 (struct ether_addr *) &p_link->mac_addr);
884 rte_eth_promiscuous_enable(p_link->pmd_id);
887 for (j = 0; j < app->n_pktq_hwq_in; j++) {
888 struct app_pktq_hwq_in_params *p_rxq =
889 &app->hwq_in_params[j];
890 uint32_t rxq_link_id, rxq_queue_id;
892 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
893 &rxq_link_id, &rxq_queue_id);
894 if (rxq_link_id != link_id)
897 status = rte_eth_rx_queue_setup(
901 app_get_cpu_socket_id(p_link->pmd_id),
903 app->mempool[p_rxq->mempool_id]);
905 rte_panic("%s (%" PRIu32 "): "
906 "%s init error (%" PRId32 ")\n",
914 for (j = 0; j < app->n_pktq_hwq_out; j++) {
915 struct app_pktq_hwq_out_params *p_txq =
916 &app->hwq_out_params[j];
917 uint32_t txq_link_id, txq_queue_id;
919 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
920 &txq_link_id, &txq_queue_id);
921 if (txq_link_id != link_id)
924 status = rte_eth_tx_queue_setup(
928 app_get_cpu_socket_id(p_link->pmd_id),
931 rte_panic("%s (%" PRIu32 "): "
932 "%s init error (%" PRId32 ")\n",
940 status = rte_eth_dev_start(p_link->pmd_id);
942 rte_panic("Cannot start %s (error %" PRId32 ")\n",
943 p_link->name, status);
946 app_link_set_arp_filter(app, p_link);
947 app_link_set_tcp_syn_filter(app, p_link);
948 app_link_up_internal(app, p_link);
955 app_init_swq(struct app_params *app)
959 for (i = 0; i < app->n_pktq_swq; i++) {
960 struct app_pktq_swq_params *p = &app->swq_params[i];
963 if (app_swq_get_readers(app, p) == 1)
964 flags |= RING_F_SC_DEQ;
965 if (app_swq_get_writers(app, p) == 1)
966 flags |= RING_F_SP_ENQ;
968 APP_LOG(app, HIGH, "Initializing %s...", p->name);
969 app->swq[i] = rte_ring_create(
975 if (app->swq[i] == NULL)
976 rte_panic("%s init error\n", p->name);
981 app_init_tm(struct app_params *app)
985 for (i = 0; i < app->n_pktq_tm; i++) {
986 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
987 struct app_link_params *p_link;
988 struct rte_eth_link link_eth_params;
989 struct rte_sched_port *sched;
990 uint32_t n_subports, subport_id;
993 p_link = app_get_link_for_tm(app, p_tm);
995 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
998 p_tm->sched_port_params.name = p_tm->name;
999 p_tm->sched_port_params.socket =
1000 app_get_cpu_socket_id(p_link->pmd_id);
1001 p_tm->sched_port_params.rate =
1002 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
1004 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
1005 sched = rte_sched_port_config(&p_tm->sched_port_params);
1007 rte_panic("%s init error\n", p_tm->name);
1011 n_subports = p_tm->sched_port_params.n_subports_per_port;
1012 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1013 uint32_t n_pipes_per_subport, pipe_id;
1015 status = rte_sched_subport_config(sched,
1017 &p_tm->sched_subport_params[subport_id]);
1019 rte_panic("%s subport %" PRIu32
1020 " init error (%" PRId32 ")\n",
1021 p_tm->name, subport_id, status);
1024 n_pipes_per_subport =
1025 p_tm->sched_port_params.n_pipes_per_subport;
1027 pipe_id < n_pipes_per_subport;
1029 int profile_id = p_tm->sched_pipe_to_profile[
1030 subport_id * APP_MAX_SCHED_PIPES +
1033 if (profile_id == -1)
1036 status = rte_sched_pipe_config(sched,
1041 rte_panic("%s subport %" PRIu32
1043 " (profile %" PRId32 ") "
1044 "init error (% " PRId32 ")\n",
1045 p_tm->name, subport_id, pipe_id,
1046 profile_id, status);
1053 app_init_msgq(struct app_params *app)
1057 for (i = 0; i < app->n_msgq; i++) {
1058 struct app_msgq_params *p = &app->msgq_params[i];
1060 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1061 app->msgq[i] = rte_ring_create(
1065 RING_F_SP_ENQ | RING_F_SC_DEQ);
1067 if (app->msgq[i] == NULL)
1068 rte_panic("%s init error\n", p->name);
1072 static void app_pipeline_params_get(struct app_params *app,
1073 struct app_pipeline_params *p_in,
1074 struct pipeline_params *p_out)
1077 uint32_t mempool_id;
1079 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1081 p_out->socket_id = (int) p_in->socket_id;
1083 p_out->log_level = app->log_level;
1086 p_out->n_ports_in = p_in->n_pktq_in;
1087 for (i = 0; i < p_in->n_pktq_in; i++) {
1088 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1089 struct pipeline_port_in_params *out = &p_out->port_in[i];
1092 case APP_PKTQ_IN_HWQ:
1094 struct app_pktq_hwq_in_params *p_hwq_in =
1095 &app->hwq_in_params[in->id];
1096 struct app_link_params *p_link =
1097 app_get_link_for_rxq(app, p_hwq_in);
1098 uint32_t rxq_link_id, rxq_queue_id;
1100 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1104 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1105 out->params.ethdev.port_id = p_link->pmd_id;
1106 out->params.ethdev.queue_id = rxq_queue_id;
1107 out->burst_size = p_hwq_in->burst;
1110 case APP_PKTQ_IN_SWQ:
1112 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1114 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1115 if (app_swq_get_readers(app, swq_params) == 1) {
1116 out->type = PIPELINE_PORT_IN_RING_READER;
1117 out->params.ring.ring = app->swq[in->id];
1118 out->burst_size = app->swq_params[in->id].burst_read;
1120 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1121 out->params.ring_multi.ring = app->swq[in->id];
1122 out->burst_size = swq_params->burst_read;
1125 if (swq_params->ipv4_frag == 1) {
1126 struct rte_port_ring_reader_ipv4_frag_params *params =
1127 &out->params.ring_ipv4_frag;
1129 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1130 params->ring = app->swq[in->id];
1131 params->mtu = swq_params->mtu;
1132 params->metadata_size = swq_params->metadata_size;
1133 params->pool_direct =
1134 app->mempool[swq_params->mempool_direct_id];
1135 params->pool_indirect =
1136 app->mempool[swq_params->mempool_indirect_id];
1137 out->burst_size = swq_params->burst_read;
1139 struct rte_port_ring_reader_ipv6_frag_params *params =
1140 &out->params.ring_ipv6_frag;
1142 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1143 params->ring = app->swq[in->id];
1144 params->mtu = swq_params->mtu;
1145 params->metadata_size = swq_params->metadata_size;
1146 params->pool_direct =
1147 app->mempool[swq_params->mempool_direct_id];
1148 params->pool_indirect =
1149 app->mempool[swq_params->mempool_indirect_id];
1150 out->burst_size = swq_params->burst_read;
1155 case APP_PKTQ_IN_TM:
1156 out->type = PIPELINE_PORT_IN_SCHED_READER;
1157 out->params.sched.sched = app->tm[in->id];
1158 out->burst_size = app->tm_params[in->id].burst_read;
1160 case APP_PKTQ_IN_SOURCE:
1161 mempool_id = app->source_params[in->id].mempool_id;
1162 out->type = PIPELINE_PORT_IN_SOURCE;
1163 out->params.source.mempool = app->mempool[mempool_id];
1164 out->burst_size = app->source_params[in->id].burst;
1172 p_out->n_ports_out = p_in->n_pktq_out;
1173 for (i = 0; i < p_in->n_pktq_out; i++) {
1174 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1175 struct pipeline_port_out_params *out = &p_out->port_out[i];
1178 case APP_PKTQ_OUT_HWQ:
1180 struct app_pktq_hwq_out_params *p_hwq_out =
1181 &app->hwq_out_params[in->id];
1182 struct app_link_params *p_link =
1183 app_get_link_for_txq(app, p_hwq_out);
1184 uint32_t txq_link_id, txq_queue_id;
1186 sscanf(p_hwq_out->name,
1187 "TXQ%" SCNu32 ".%" SCNu32,
1191 if (p_hwq_out->dropless == 0) {
1192 struct rte_port_ethdev_writer_params *params =
1193 &out->params.ethdev;
1195 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1196 params->port_id = p_link->pmd_id;
1197 params->queue_id = txq_queue_id;
1198 params->tx_burst_sz =
1199 app->hwq_out_params[in->id].burst;
1201 struct rte_port_ethdev_writer_nodrop_params
1202 *params = &out->params.ethdev_nodrop;
1205 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1206 params->port_id = p_link->pmd_id;
1207 params->queue_id = txq_queue_id;
1208 params->tx_burst_sz = p_hwq_out->burst;
1209 params->n_retries = p_hwq_out->n_retries;
1213 case APP_PKTQ_OUT_SWQ:
1215 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1217 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1218 if (app_swq_get_writers(app, swq_params) == 1) {
1219 if (app->swq_params[in->id].dropless == 0) {
1220 struct rte_port_ring_writer_params *params =
1223 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1224 params->ring = app->swq[in->id];
1225 params->tx_burst_sz =
1226 app->swq_params[in->id].burst_write;
1228 struct rte_port_ring_writer_nodrop_params
1229 *params = &out->params.ring_nodrop;
1232 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1233 params->ring = app->swq[in->id];
1234 params->tx_burst_sz =
1235 app->swq_params[in->id].burst_write;
1237 app->swq_params[in->id].n_retries;
1240 if (swq_params->dropless == 0) {
1241 struct rte_port_ring_multi_writer_params *params =
1242 &out->params.ring_multi;
1244 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1245 params->ring = app->swq[in->id];
1246 params->tx_burst_sz = swq_params->burst_write;
1248 struct rte_port_ring_multi_writer_nodrop_params
1249 *params = &out->params.ring_multi_nodrop;
1251 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1252 params->ring = app->swq[in->id];
1253 params->tx_burst_sz = swq_params->burst_write;
1254 params->n_retries = swq_params->n_retries;
1258 if (swq_params->ipv4_ras == 1) {
1259 struct rte_port_ring_writer_ipv4_ras_params *params =
1260 &out->params.ring_ipv4_ras;
1262 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1263 params->ring = app->swq[in->id];
1264 params->tx_burst_sz = swq_params->burst_write;
1266 struct rte_port_ring_writer_ipv6_ras_params *params =
1267 &out->params.ring_ipv6_ras;
1269 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1270 params->ring = app->swq[in->id];
1271 params->tx_burst_sz = swq_params->burst_write;
1276 case APP_PKTQ_OUT_TM: {
1277 struct rte_port_sched_writer_params *params =
1280 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1281 params->sched = app->tm[in->id];
1282 params->tx_burst_sz =
1283 app->tm_params[in->id].burst_write;
1286 case APP_PKTQ_OUT_SINK:
1287 out->type = PIPELINE_PORT_OUT_SINK;
1295 p_out->n_msgq = p_in->n_msgq_in;
1297 for (i = 0; i < p_in->n_msgq_in; i++)
1298 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1300 for (i = 0; i < p_in->n_msgq_out; i++)
1301 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1304 p_out->n_args = p_in->n_args;
1305 for (i = 0; i < p_in->n_args; i++) {
1306 p_out->args_name[i] = p_in->args_name[i];
1307 p_out->args_value[i] = p_in->args_value[i];
1312 app_init_pipelines(struct app_params *app)
1316 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1317 struct app_pipeline_params *params =
1318 &app->pipeline_params[p_id];
1319 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1320 struct pipeline_type *ptype;
1321 struct pipeline_params pp;
1323 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1325 ptype = app_pipeline_type_find(app, params->type);
1327 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1330 app_pipeline_params_get(app, params, &pp);
1334 if (ptype->be_ops->f_init) {
1335 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1337 if (data->be == NULL)
1338 rte_panic("Pipeline instance \"%s\" back-end "
1339 "init error\n", params->name);
1344 if (ptype->fe_ops->f_init) {
1345 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1347 if (data->fe == NULL)
1348 rte_panic("Pipeline instance \"%s\" front-end "
1349 "init error\n", params->name);
1352 data->ptype = ptype;
1354 data->timer_period = (rte_get_tsc_hz() * params->timer_period)
1360 app_init_threads(struct app_params *app)
1362 uint64_t time = rte_get_tsc_cycles();
1365 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1366 struct app_pipeline_params *params =
1367 &app->pipeline_params[p_id];
1368 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1369 struct pipeline_type *ptype;
1370 struct app_thread_data *t;
1371 struct app_thread_pipeline_data *p;
1374 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1377 params->hyper_th_id);
1380 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1383 (params->hyper_th_id) ? "h" : "");
1385 t = &app->thread_data[lcore_id];
1387 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1388 t->thread_req_deadline = time + t->timer_period;
1390 t->msgq_in = app_thread_msgq_in_get(app,
1393 params->hyper_th_id);
1394 if (t->msgq_in == NULL)
1395 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1398 t->msgq_out = app_thread_msgq_out_get(app,
1401 params->hyper_th_id);
1402 if (t->msgq_out == NULL)
1403 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1406 ptype = app_pipeline_type_find(app, params->type);
1408 rte_panic("Init error: Unknown pipeline "
1409 "type \"%s\"\n", params->type);
1411 p = (ptype->be_ops->f_run == NULL) ?
1412 &t->regular[t->n_regular] :
1413 &t->custom[t->n_custom];
1415 p->pipeline_id = p_id;
1417 p->f_run = ptype->be_ops->f_run;
1418 p->f_timer = ptype->be_ops->f_timer;
1419 p->timer_period = data->timer_period;
1420 p->deadline = time + data->timer_period;
1424 if (ptype->be_ops->f_run == NULL)
1431 int app_init(struct app_params *app)
1433 app_init_core_map(app);
1434 app_init_core_mask(app);
1437 app_init_mempool(app);
1443 app_pipeline_common_cmd_push(app);
1444 app_pipeline_thread_cmd_push(app);
1445 app_pipeline_type_register(app, &pipeline_master);
1446 app_pipeline_type_register(app, &pipeline_passthrough);
1447 app_pipeline_type_register(app, &pipeline_flow_classification);
1448 app_pipeline_type_register(app, &pipeline_flow_actions);
1449 app_pipeline_type_register(app, &pipeline_firewall);
1450 app_pipeline_type_register(app, &pipeline_routing);
1452 app_init_pipelines(app);
1453 app_init_threads(app);
1459 app_pipeline_type_cmd_push(struct app_params *app,
1460 struct pipeline_type *ptype)
1462 cmdline_parse_ctx_t *cmds;
1465 /* Check input arguments */
1466 if ((app == NULL) ||
1470 n_cmds = pipeline_type_cmds_count(ptype);
1474 cmds = ptype->fe_ops->cmds;
1476 /* Check for available slots in the application commands array */
1477 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1480 /* Push pipeline commands into the application */
1481 memcpy(&app->cmds[app->n_cmds],
1483 n_cmds * sizeof(cmdline_parse_ctx_t));
1485 for (i = 0; i < n_cmds; i++)
1486 app->cmds[app->n_cmds + i]->data = app;
1488 app->n_cmds += n_cmds;
1489 app->cmds[app->n_cmds] = NULL;
1495 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1499 /* Check input arguments */
1500 if ((app == NULL) ||
1502 (ptype->name == NULL) ||
1503 (strlen(ptype->name) == 0) ||
1504 (ptype->be_ops->f_init == NULL) ||
1505 (ptype->be_ops->f_timer == NULL))
1508 /* Check for duplicate entry */
1509 for (i = 0; i < app->n_pipeline_types; i++)
1510 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1513 /* Check for resource availability */
1514 n_cmds = pipeline_type_cmds_count(ptype);
1515 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1516 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1519 /* Copy pipeline type */
1520 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1522 sizeof(struct pipeline_type));
1524 /* Copy CLI commands */
1526 app_pipeline_type_cmd_push(app, ptype);
1532 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1536 for (i = 0; i < app->n_pipeline_types; i++)
1537 if (strcmp(app->pipeline_type[i].name, name) == 0)
1538 return &app->pipeline_type[i];