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_init_link(struct app_params *app)
843 app_init_link_frag_ras(app);
845 for (i = 0; i < app->n_links; i++) {
846 struct app_link_params *p_link = &app->link_params[i];
847 uint32_t link_id, n_hwq_in, n_hwq_out, j;
850 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
851 n_hwq_in = app_link_get_n_rxq(app, p_link);
852 n_hwq_out = app_link_get_n_txq(app, p_link);
854 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
855 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
862 status = rte_eth_dev_configure(
868 rte_panic("%s (%" PRId32 "): "
869 "init error (%" PRId32 ")\n",
870 p_link->name, p_link->pmd_id, status);
872 rte_eth_macaddr_get(p_link->pmd_id,
873 (struct ether_addr *) &p_link->mac_addr);
876 rte_eth_promiscuous_enable(p_link->pmd_id);
879 for (j = 0; j < app->n_pktq_hwq_in; j++) {
880 struct app_pktq_hwq_in_params *p_rxq =
881 &app->hwq_in_params[j];
882 uint32_t rxq_link_id, rxq_queue_id;
884 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
885 &rxq_link_id, &rxq_queue_id);
886 if (rxq_link_id != link_id)
889 status = rte_eth_rx_queue_setup(
893 rte_eth_dev_socket_id(p_link->pmd_id),
895 app->mempool[p_rxq->mempool_id]);
897 rte_panic("%s (%" PRIu32 "): "
898 "%s init error (%" PRId32 ")\n",
906 for (j = 0; j < app->n_pktq_hwq_out; j++) {
907 struct app_pktq_hwq_out_params *p_txq =
908 &app->hwq_out_params[j];
909 uint32_t txq_link_id, txq_queue_id;
911 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
912 &txq_link_id, &txq_queue_id);
913 if (txq_link_id != link_id)
916 status = rte_eth_tx_queue_setup(
920 rte_eth_dev_socket_id(p_link->pmd_id),
923 rte_panic("%s (%" PRIu32 "): "
924 "%s init error (%" PRId32 ")\n",
932 status = rte_eth_dev_start(p_link->pmd_id);
934 rte_panic("Cannot start %s (error %" PRId32 ")\n",
935 p_link->name, status);
938 app_link_set_arp_filter(app, p_link);
939 app_link_set_tcp_syn_filter(app, p_link);
940 app_link_up_internal(app, p_link);
947 app_init_swq(struct app_params *app)
951 for (i = 0; i < app->n_pktq_swq; i++) {
952 struct app_pktq_swq_params *p = &app->swq_params[i];
955 if (app_swq_get_readers(app, p) == 1)
956 flags |= RING_F_SC_DEQ;
957 if (app_swq_get_writers(app, p) == 1)
958 flags |= RING_F_SP_ENQ;
960 APP_LOG(app, HIGH, "Initializing %s...", p->name);
961 app->swq[i] = rte_ring_create(
967 if (app->swq[i] == NULL)
968 rte_panic("%s init error\n", p->name);
973 app_init_tm(struct app_params *app)
977 for (i = 0; i < app->n_pktq_tm; i++) {
978 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
979 struct app_link_params *p_link;
980 struct rte_eth_link link_eth_params;
981 struct rte_sched_port *sched;
982 uint32_t n_subports, subport_id;
985 p_link = app_get_link_for_tm(app, p_tm);
987 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
990 p_tm->sched_port_params.name = p_tm->name;
991 p_tm->sched_port_params.socket =
992 rte_eth_dev_socket_id(p_link->pmd_id);
993 p_tm->sched_port_params.rate =
994 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
996 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
997 sched = rte_sched_port_config(&p_tm->sched_port_params);
999 rte_panic("%s init error\n", p_tm->name);
1003 n_subports = p_tm->sched_port_params.n_subports_per_port;
1004 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1005 uint32_t n_pipes_per_subport, pipe_id;
1007 status = rte_sched_subport_config(sched,
1009 &p_tm->sched_subport_params[subport_id]);
1011 rte_panic("%s subport %" PRIu32
1012 " init error (%" PRId32 ")\n",
1013 p_tm->name, subport_id, status);
1016 n_pipes_per_subport =
1017 p_tm->sched_port_params.n_pipes_per_subport;
1019 pipe_id < n_pipes_per_subport;
1021 int profile_id = p_tm->sched_pipe_to_profile[
1022 subport_id * APP_MAX_SCHED_PIPES +
1025 if (profile_id == -1)
1028 status = rte_sched_pipe_config(sched,
1033 rte_panic("%s subport %" PRIu32
1035 " (profile %" PRId32 ") "
1036 "init error (% " PRId32 ")\n",
1037 p_tm->name, subport_id, pipe_id,
1038 profile_id, status);
1045 app_init_msgq(struct app_params *app)
1049 for (i = 0; i < app->n_msgq; i++) {
1050 struct app_msgq_params *p = &app->msgq_params[i];
1052 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1053 app->msgq[i] = rte_ring_create(
1057 RING_F_SP_ENQ | RING_F_SC_DEQ);
1059 if (app->msgq[i] == NULL)
1060 rte_panic("%s init error\n", p->name);
1064 static void app_pipeline_params_get(struct app_params *app,
1065 struct app_pipeline_params *p_in,
1066 struct pipeline_params *p_out)
1069 uint32_t mempool_id;
1071 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
1073 p_out->socket_id = (int) p_in->socket_id;
1075 p_out->log_level = app->log_level;
1078 p_out->n_ports_in = p_in->n_pktq_in;
1079 for (i = 0; i < p_in->n_pktq_in; i++) {
1080 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1081 struct pipeline_port_in_params *out = &p_out->port_in[i];
1084 case APP_PKTQ_IN_HWQ:
1086 struct app_pktq_hwq_in_params *p_hwq_in =
1087 &app->hwq_in_params[in->id];
1088 struct app_link_params *p_link =
1089 app_get_link_for_rxq(app, p_hwq_in);
1090 uint32_t rxq_link_id, rxq_queue_id;
1092 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1096 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1097 out->params.ethdev.port_id = p_link->pmd_id;
1098 out->params.ethdev.queue_id = rxq_queue_id;
1099 out->burst_size = p_hwq_in->burst;
1102 case APP_PKTQ_IN_SWQ:
1104 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1106 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1107 if (app_swq_get_readers(app, swq_params) == 1) {
1108 out->type = PIPELINE_PORT_IN_RING_READER;
1109 out->params.ring.ring = app->swq[in->id];
1110 out->burst_size = app->swq_params[in->id].burst_read;
1112 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1113 out->params.ring_multi.ring = app->swq[in->id];
1114 out->burst_size = swq_params->burst_read;
1117 if (swq_params->ipv4_frag == 1) {
1118 struct rte_port_ring_reader_ipv4_frag_params *params =
1119 &out->params.ring_ipv4_frag;
1121 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1122 params->ring = app->swq[in->id];
1123 params->mtu = swq_params->mtu;
1124 params->metadata_size = swq_params->metadata_size;
1125 params->pool_direct =
1126 app->mempool[swq_params->mempool_direct_id];
1127 params->pool_indirect =
1128 app->mempool[swq_params->mempool_indirect_id];
1129 out->burst_size = swq_params->burst_read;
1131 struct rte_port_ring_reader_ipv6_frag_params *params =
1132 &out->params.ring_ipv6_frag;
1134 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1135 params->ring = app->swq[in->id];
1136 params->mtu = swq_params->mtu;
1137 params->metadata_size = swq_params->metadata_size;
1138 params->pool_direct =
1139 app->mempool[swq_params->mempool_direct_id];
1140 params->pool_indirect =
1141 app->mempool[swq_params->mempool_indirect_id];
1142 out->burst_size = swq_params->burst_read;
1147 case APP_PKTQ_IN_TM:
1148 out->type = PIPELINE_PORT_IN_SCHED_READER;
1149 out->params.sched.sched = app->tm[in->id];
1150 out->burst_size = app->tm_params[in->id].burst_read;
1152 case APP_PKTQ_IN_SOURCE:
1153 mempool_id = app->source_params[in->id].mempool_id;
1154 out->type = PIPELINE_PORT_IN_SOURCE;
1155 out->params.source.mempool = app->mempool[mempool_id];
1156 out->burst_size = app->source_params[in->id].burst;
1164 p_out->n_ports_out = p_in->n_pktq_out;
1165 for (i = 0; i < p_in->n_pktq_out; i++) {
1166 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1167 struct pipeline_port_out_params *out = &p_out->port_out[i];
1170 case APP_PKTQ_OUT_HWQ:
1172 struct app_pktq_hwq_out_params *p_hwq_out =
1173 &app->hwq_out_params[in->id];
1174 struct app_link_params *p_link =
1175 app_get_link_for_txq(app, p_hwq_out);
1176 uint32_t txq_link_id, txq_queue_id;
1178 sscanf(p_hwq_out->name,
1179 "TXQ%" SCNu32 ".%" SCNu32,
1183 if (p_hwq_out->dropless == 0) {
1184 struct rte_port_ethdev_writer_params *params =
1185 &out->params.ethdev;
1187 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1188 params->port_id = p_link->pmd_id;
1189 params->queue_id = txq_queue_id;
1190 params->tx_burst_sz =
1191 app->hwq_out_params[in->id].burst;
1193 struct rte_port_ethdev_writer_nodrop_params
1194 *params = &out->params.ethdev_nodrop;
1197 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1198 params->port_id = p_link->pmd_id;
1199 params->queue_id = txq_queue_id;
1200 params->tx_burst_sz = p_hwq_out->burst;
1201 params->n_retries = p_hwq_out->n_retries;
1205 case APP_PKTQ_OUT_SWQ:
1207 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1209 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1210 if (app_swq_get_writers(app, swq_params) == 1) {
1211 if (app->swq_params[in->id].dropless == 0) {
1212 struct rte_port_ring_writer_params *params =
1215 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1216 params->ring = app->swq[in->id];
1217 params->tx_burst_sz =
1218 app->swq_params[in->id].burst_write;
1220 struct rte_port_ring_writer_nodrop_params
1221 *params = &out->params.ring_nodrop;
1224 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1225 params->ring = app->swq[in->id];
1226 params->tx_burst_sz =
1227 app->swq_params[in->id].burst_write;
1229 app->swq_params[in->id].n_retries;
1232 if (swq_params->dropless == 0) {
1233 struct rte_port_ring_multi_writer_params *params =
1234 &out->params.ring_multi;
1236 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1237 params->ring = app->swq[in->id];
1238 params->tx_burst_sz = swq_params->burst_write;
1240 struct rte_port_ring_multi_writer_nodrop_params
1241 *params = &out->params.ring_multi_nodrop;
1243 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1244 params->ring = app->swq[in->id];
1245 params->tx_burst_sz = swq_params->burst_write;
1246 params->n_retries = swq_params->n_retries;
1250 if (swq_params->ipv4_ras == 1) {
1251 struct rte_port_ring_writer_ipv4_ras_params *params =
1252 &out->params.ring_ipv4_ras;
1254 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1255 params->ring = app->swq[in->id];
1256 params->tx_burst_sz = swq_params->burst_write;
1258 struct rte_port_ring_writer_ipv6_ras_params *params =
1259 &out->params.ring_ipv6_ras;
1261 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1262 params->ring = app->swq[in->id];
1263 params->tx_burst_sz = swq_params->burst_write;
1268 case APP_PKTQ_OUT_TM: {
1269 struct rte_port_sched_writer_params *params =
1272 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1273 params->sched = app->tm[in->id];
1274 params->tx_burst_sz =
1275 app->tm_params[in->id].burst_write;
1278 case APP_PKTQ_OUT_SINK:
1279 out->type = PIPELINE_PORT_OUT_SINK;
1287 p_out->n_msgq = p_in->n_msgq_in;
1289 for (i = 0; i < p_in->n_msgq_in; i++)
1290 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1292 for (i = 0; i < p_in->n_msgq_out; i++)
1293 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1296 p_out->n_args = p_in->n_args;
1297 for (i = 0; i < p_in->n_args; i++) {
1298 p_out->args_name[i] = p_in->args_name[i];
1299 p_out->args_value[i] = p_in->args_value[i];
1304 app_init_pipelines(struct app_params *app)
1308 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1309 struct app_pipeline_params *params =
1310 &app->pipeline_params[p_id];
1311 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1312 struct pipeline_type *ptype;
1313 struct pipeline_params pp;
1315 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1317 ptype = app_pipeline_type_find(app, params->type);
1319 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1322 app_pipeline_params_get(app, params, &pp);
1326 if (ptype->be_ops->f_init) {
1327 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1329 if (data->be == NULL)
1330 rte_panic("Pipeline instance \"%s\" back-end "
1331 "init error\n", params->name);
1336 if (ptype->fe_ops->f_init) {
1337 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1339 if (data->fe == NULL)
1340 rte_panic("Pipeline instance \"%s\" front-end "
1341 "init error\n", params->name);
1344 data->ptype = ptype;
1346 data->timer_period = (rte_get_tsc_hz() * params->timer_period)
1352 app_init_threads(struct app_params *app)
1354 uint64_t time = rte_get_tsc_cycles();
1357 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1358 struct app_pipeline_params *params =
1359 &app->pipeline_params[p_id];
1360 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1361 struct pipeline_type *ptype;
1362 struct app_thread_data *t;
1363 struct app_thread_pipeline_data *p;
1366 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1369 params->hyper_th_id);
1372 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1375 (params->hyper_th_id) ? "h" : "");
1377 t = &app->thread_data[lcore_id];
1379 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1380 t->thread_req_deadline = time + t->timer_period;
1382 t->msgq_in = app_thread_msgq_in_get(app,
1385 params->hyper_th_id);
1386 if (t->msgq_in == NULL)
1387 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1390 t->msgq_out = app_thread_msgq_out_get(app,
1393 params->hyper_th_id);
1394 if (t->msgq_out == NULL)
1395 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1398 ptype = app_pipeline_type_find(app, params->type);
1400 rte_panic("Init error: Unknown pipeline "
1401 "type \"%s\"\n", params->type);
1403 p = (ptype->be_ops->f_run == NULL) ?
1404 &t->regular[t->n_regular] :
1405 &t->custom[t->n_custom];
1407 p->pipeline_id = p_id;
1409 p->f_run = ptype->be_ops->f_run;
1410 p->f_timer = ptype->be_ops->f_timer;
1411 p->timer_period = data->timer_period;
1412 p->deadline = time + data->timer_period;
1416 if (ptype->be_ops->f_run == NULL)
1423 int app_init(struct app_params *app)
1425 app_init_core_map(app);
1426 app_init_core_mask(app);
1429 app_init_mempool(app);
1435 app_pipeline_common_cmd_push(app);
1436 app_pipeline_thread_cmd_push(app);
1437 app_pipeline_type_register(app, &pipeline_master);
1438 app_pipeline_type_register(app, &pipeline_passthrough);
1439 app_pipeline_type_register(app, &pipeline_flow_classification);
1440 app_pipeline_type_register(app, &pipeline_flow_actions);
1441 app_pipeline_type_register(app, &pipeline_firewall);
1442 app_pipeline_type_register(app, &pipeline_routing);
1444 app_init_pipelines(app);
1445 app_init_threads(app);
1451 app_pipeline_type_cmd_push(struct app_params *app,
1452 struct pipeline_type *ptype)
1454 cmdline_parse_ctx_t *cmds;
1457 /* Check input arguments */
1458 if ((app == NULL) ||
1462 n_cmds = pipeline_type_cmds_count(ptype);
1466 cmds = ptype->fe_ops->cmds;
1468 /* Check for available slots in the application commands array */
1469 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1472 /* Push pipeline commands into the application */
1473 memcpy(&app->cmds[app->n_cmds],
1475 n_cmds * sizeof(cmdline_parse_ctx_t));
1477 for (i = 0; i < n_cmds; i++)
1478 app->cmds[app->n_cmds + i]->data = app;
1480 app->n_cmds += n_cmds;
1481 app->cmds[app->n_cmds] = NULL;
1487 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1491 /* Check input arguments */
1492 if ((app == NULL) ||
1494 (ptype->name == NULL) ||
1495 (strlen(ptype->name) == 0) ||
1496 (ptype->be_ops->f_init == NULL) ||
1497 (ptype->be_ops->f_timer == NULL))
1500 /* Check for duplicate entry */
1501 for (i = 0; i < app->n_pipeline_types; i++)
1502 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1505 /* Check for resource availability */
1506 n_cmds = pipeline_type_cmds_count(ptype);
1507 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1508 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1511 /* Copy pipeline type */
1512 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1514 sizeof(struct pipeline_type));
1516 /* Copy CLI commands */
1518 app_pipeline_type_cmd_push(app, ptype);
1524 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1528 for (i = 0; i < app->n_pipeline_types; i++)
1529 if (strcmp(app->pipeline_type[i].name, name) == 0)
1530 return &app->pipeline_type[i];