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_routing.h"
53 #include "thread_fe.h"
55 #define APP_NAME_SIZE 32
58 app_init_core_map(struct app_params *app)
60 APP_LOG(app, HIGH, "Initializing CPU core map ...");
61 app->core_map = cpu_core_map_init(4, 32, 4, 0);
63 if (app->core_map == NULL)
64 rte_panic("Cannot create CPU core map\n");
66 if (app->log_level >= APP_LOG_LEVEL_LOW)
67 cpu_core_map_print(app->core_map);
71 app_init_core_mask(struct app_params *app)
76 for (i = 0; i < app->n_pipelines; i++) {
77 struct app_pipeline_params *p = &app->pipeline_params[i];
80 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
86 rte_panic("Cannot create CPU core mask\n");
88 mask |= 1LLU << lcore_id;
91 app->core_mask = mask;
92 APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
96 app_init_eal(struct app_params *app)
99 struct app_eal_params *p = &app->eal_params;
103 app->eal_argv[n_args++] = strdup(app->app_name);
105 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
106 app->eal_argv[n_args++] = strdup(buffer);
109 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
110 app->eal_argv[n_args++] = strdup(buffer);
113 if (p->master_lcore_present) {
116 "--master-lcore=%" PRIu32,
118 app->eal_argv[n_args++] = strdup(buffer);
121 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
122 app->eal_argv[n_args++] = strdup(buffer);
124 if (p->memory_present) {
125 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
126 app->eal_argv[n_args++] = strdup(buffer);
129 if (p->ranks_present) {
130 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
131 app->eal_argv[n_args++] = strdup(buffer);
134 if (p->pci_blacklist) {
137 "--pci-blacklist=%s",
139 app->eal_argv[n_args++] = strdup(buffer);
142 if (p->pci_whitelist) {
145 "--pci-whitelist=%s",
147 app->eal_argv[n_args++] = strdup(buffer);
151 snprintf(buffer, sizeof(buffer), "--vdev=%s", p->vdev);
152 app->eal_argv[n_args++] = strdup(buffer);
155 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
156 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
157 app->eal_argv[n_args++] = strdup(buffer);
165 app->eal_argv[n_args++] = strdup(buffer);
169 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
170 app->eal_argv[n_args++] = strdup(buffer);
173 if (p->log_level_present) {
176 "--log-level=%" PRIu32,
178 app->eal_argv[n_args++] = strdup(buffer);
181 if ((p->version_present) && p->version) {
182 snprintf(buffer, sizeof(buffer), "-v");
183 app->eal_argv[n_args++] = strdup(buffer);
186 if ((p->help_present) && p->help) {
187 snprintf(buffer, sizeof(buffer), "--help");
188 app->eal_argv[n_args++] = strdup(buffer);
191 if ((p->no_huge_present) && p->no_huge) {
192 snprintf(buffer, sizeof(buffer), "--no-huge");
193 app->eal_argv[n_args++] = strdup(buffer);
196 if ((p->no_pci_present) && p->no_pci) {
197 snprintf(buffer, sizeof(buffer), "--no-pci");
198 app->eal_argv[n_args++] = strdup(buffer);
201 if ((p->no_hpet_present) && p->no_hpet) {
202 snprintf(buffer, sizeof(buffer), "--no-hpet");
203 app->eal_argv[n_args++] = strdup(buffer);
206 if ((p->no_shconf_present) && p->no_shconf) {
207 snprintf(buffer, sizeof(buffer), "--no-shconf");
208 app->eal_argv[n_args++] = strdup(buffer);
212 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
213 app->eal_argv[n_args++] = strdup(buffer);
221 app->eal_argv[n_args++] = strdup(buffer);
225 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
226 app->eal_argv[n_args++] = strdup(buffer);
229 if (p->file_prefix) {
234 app->eal_argv[n_args++] = strdup(buffer);
237 if (p->base_virtaddr) {
240 "--base-virtaddr=%s",
242 app->eal_argv[n_args++] = strdup(buffer);
245 if ((p->create_uio_dev_present) && p->create_uio_dev) {
246 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
247 app->eal_argv[n_args++] = strdup(buffer);
255 app->eal_argv[n_args++] = strdup(buffer);
258 if ((p->xen_dom0_present) && (p->xen_dom0)) {
259 snprintf(buffer, sizeof(buffer), "--xen-dom0");
260 app->eal_argv[n_args++] = strdup(buffer);
263 snprintf(buffer, sizeof(buffer), "--");
264 app->eal_argv[n_args++] = strdup(buffer);
266 app->eal_argc = n_args;
268 APP_LOG(app, HIGH, "Initializing EAL ...");
269 status = rte_eal_init(app->eal_argc, app->eal_argv);
271 rte_panic("EAL init error\n");
275 app_init_mempool(struct app_params *app)
279 for (i = 0; i < app->n_mempools; i++) {
280 struct app_mempool_params *p = &app->mempool_params[i];
282 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
283 app->mempool[i] = rte_mempool_create(
288 sizeof(struct rte_pktmbuf_pool_private),
289 rte_pktmbuf_pool_init, NULL,
290 rte_pktmbuf_init, NULL,
294 if (app->mempool[i] == NULL)
295 rte_panic("%s init error\n", p->name);
300 app_link_filter_arp_add(struct app_link_params *link)
302 struct rte_eth_ethertype_filter filter = {
303 .ether_type = ETHER_TYPE_ARP,
305 .queue = link->arp_q,
308 return rte_eth_dev_filter_ctrl(link->pmd_id,
309 RTE_ETH_FILTER_ETHERTYPE,
315 app_link_filter_tcp_syn_add(struct app_link_params *link)
317 struct rte_eth_syn_filter filter = {
319 .queue = link->tcp_syn_local_q,
322 return rte_eth_dev_filter_ctrl(link->pmd_id,
329 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
331 struct rte_eth_ntuple_filter filter = {
332 .flags = RTE_5TUPLE_FLAGS,
333 .dst_ip = rte_bswap32(l2->ip),
334 .dst_ip_mask = UINT32_MAX, /* Enable */
336 .src_ip_mask = 0, /* Disable */
338 .dst_port_mask = 0, /* Disable */
340 .src_port_mask = 0, /* Disable */
342 .proto_mask = 0, /* Disable */
344 .priority = 1, /* Lowest */
345 .queue = l1->ip_local_q,
348 return rte_eth_dev_filter_ctrl(l1->pmd_id,
349 RTE_ETH_FILTER_NTUPLE,
355 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
357 struct rte_eth_ntuple_filter filter = {
358 .flags = RTE_5TUPLE_FLAGS,
359 .dst_ip = rte_bswap32(l2->ip),
360 .dst_ip_mask = UINT32_MAX, /* Enable */
362 .src_ip_mask = 0, /* Disable */
364 .dst_port_mask = 0, /* Disable */
366 .src_port_mask = 0, /* Disable */
368 .proto_mask = 0, /* Disable */
370 .priority = 1, /* Lowest */
371 .queue = l1->ip_local_q,
374 return rte_eth_dev_filter_ctrl(l1->pmd_id,
375 RTE_ETH_FILTER_NTUPLE,
376 RTE_ETH_FILTER_DELETE,
381 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
383 struct rte_eth_ntuple_filter filter = {
384 .flags = RTE_5TUPLE_FLAGS,
385 .dst_ip = rte_bswap32(l2->ip),
386 .dst_ip_mask = UINT32_MAX, /* Enable */
388 .src_ip_mask = 0, /* Disable */
390 .dst_port_mask = 0, /* Disable */
392 .src_port_mask = 0, /* Disable */
393 .proto = IPPROTO_TCP,
394 .proto_mask = UINT8_MAX, /* Enable */
396 .priority = 2, /* Higher priority than IP */
397 .queue = l1->tcp_local_q,
400 return rte_eth_dev_filter_ctrl(l1->pmd_id,
401 RTE_ETH_FILTER_NTUPLE,
407 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
409 struct rte_eth_ntuple_filter filter = {
410 .flags = RTE_5TUPLE_FLAGS,
411 .dst_ip = rte_bswap32(l2->ip),
412 .dst_ip_mask = UINT32_MAX, /* Enable */
414 .src_ip_mask = 0, /* Disable */
416 .dst_port_mask = 0, /* Disable */
418 .src_port_mask = 0, /* Disable */
419 .proto = IPPROTO_TCP,
420 .proto_mask = UINT8_MAX, /* Enable */
422 .priority = 2, /* Higher priority than IP */
423 .queue = l1->tcp_local_q,
426 return rte_eth_dev_filter_ctrl(l1->pmd_id,
427 RTE_ETH_FILTER_NTUPLE,
428 RTE_ETH_FILTER_DELETE,
433 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
435 struct rte_eth_ntuple_filter filter = {
436 .flags = RTE_5TUPLE_FLAGS,
437 .dst_ip = rte_bswap32(l2->ip),
438 .dst_ip_mask = UINT32_MAX, /* Enable */
440 .src_ip_mask = 0, /* Disable */
442 .dst_port_mask = 0, /* Disable */
444 .src_port_mask = 0, /* Disable */
445 .proto = IPPROTO_UDP,
446 .proto_mask = UINT8_MAX, /* Enable */
448 .priority = 2, /* Higher priority than IP */
449 .queue = l1->udp_local_q,
452 return rte_eth_dev_filter_ctrl(l1->pmd_id,
453 RTE_ETH_FILTER_NTUPLE,
459 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
461 struct rte_eth_ntuple_filter filter = {
462 .flags = RTE_5TUPLE_FLAGS,
463 .dst_ip = rte_bswap32(l2->ip),
464 .dst_ip_mask = UINT32_MAX, /* Enable */
466 .src_ip_mask = 0, /* Disable */
468 .dst_port_mask = 0, /* Disable */
470 .src_port_mask = 0, /* Disable */
471 .proto = IPPROTO_UDP,
472 .proto_mask = UINT8_MAX, /* Enable */
474 .priority = 2, /* Higher priority than IP */
475 .queue = l1->udp_local_q,
478 return rte_eth_dev_filter_ctrl(l1->pmd_id,
479 RTE_ETH_FILTER_NTUPLE,
480 RTE_ETH_FILTER_DELETE,
485 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
487 struct rte_eth_ntuple_filter filter = {
488 .flags = RTE_5TUPLE_FLAGS,
489 .dst_ip = rte_bswap32(l2->ip),
490 .dst_ip_mask = UINT32_MAX, /* Enable */
492 .src_ip_mask = 0, /* Disable */
494 .dst_port_mask = 0, /* Disable */
496 .src_port_mask = 0, /* Disable */
497 .proto = IPPROTO_SCTP,
498 .proto_mask = UINT8_MAX, /* Enable */
500 .priority = 2, /* Higher priority than IP */
501 .queue = l1->sctp_local_q,
504 return rte_eth_dev_filter_ctrl(l1->pmd_id,
505 RTE_ETH_FILTER_NTUPLE,
511 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
513 struct rte_eth_ntuple_filter filter = {
514 .flags = RTE_5TUPLE_FLAGS,
515 .dst_ip = rte_bswap32(l2->ip),
516 .dst_ip_mask = UINT32_MAX, /* Enable */
518 .src_ip_mask = 0, /* Disable */
520 .dst_port_mask = 0, /* Disable */
522 .src_port_mask = 0, /* Disable */
523 .proto = IPPROTO_SCTP,
524 .proto_mask = UINT8_MAX, /* Enable */
526 .priority = 2, /* Higher priority than IP */
527 .queue = l1->sctp_local_q,
530 return rte_eth_dev_filter_ctrl(l1->pmd_id,
531 RTE_ETH_FILTER_NTUPLE,
532 RTE_ETH_FILTER_DELETE,
537 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
539 if (cp->arp_q != 0) {
540 int status = app_link_filter_arp_add(cp);
542 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
543 "Adding ARP filter (queue = %" PRIu32 ")",
544 cp->name, cp->pmd_id, cp->arp_q);
547 rte_panic("%s (%" PRIu32 "): "
548 "Error adding ARP filter "
549 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
550 cp->name, cp->pmd_id, cp->arp_q, status);
555 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
557 if (cp->tcp_syn_local_q != 0) {
558 int status = app_link_filter_tcp_syn_add(cp);
560 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
561 "Adding TCP SYN filter (queue = %" PRIu32 ")",
562 cp->name, cp->pmd_id, cp->tcp_syn_local_q);
565 rte_panic("%s (%" PRIu32 "): "
566 "Error adding TCP SYN filter "
567 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
568 cp->name, cp->pmd_id, cp->tcp_syn_local_q,
574 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
579 /* For each link, add filters for IP of current link */
581 for (i = 0; i < app->n_links; i++) {
582 struct app_link_params *p = &app->link_params[i];
585 if (p->ip_local_q != 0) {
586 int status = app_link_filter_ip_add(p, cp);
588 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
589 "Adding IP filter (queue= %" PRIu32
590 ", IP = 0x%08" PRIx32 ")",
591 p->name, p->pmd_id, p->ip_local_q,
595 rte_panic("%s (%" PRIu32 "): "
597 "filter (queue= %" PRIu32 ", "
601 p->ip_local_q, cp->ip, status);
605 if (p->tcp_local_q != 0) {
606 int status = app_link_filter_tcp_add(p, cp);
608 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
611 ", IP = 0x%08" PRIx32 ")",
612 p->name, p->pmd_id, p->tcp_local_q,
616 rte_panic("%s (%" PRIu32 "): "
618 "filter (queue = %" PRIu32 ", "
622 p->tcp_local_q, cp->ip, status);
626 if (p->udp_local_q != 0) {
627 int status = app_link_filter_udp_add(p, cp);
629 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
632 ", IP = 0x%08" PRIx32 ")",
633 p->name, p->pmd_id, p->udp_local_q,
637 rte_panic("%s (%" PRIu32 "): "
639 "filter (queue = %" PRIu32 ", "
643 p->udp_local_q, cp->ip, status);
647 if (p->sctp_local_q != 0) {
648 int status = app_link_filter_sctp_add(p, cp);
650 APP_LOG(app, LOW, "%s (%" PRIu32
651 "): Adding SCTP filter "
653 ", IP = 0x%08" PRIx32 ")",
654 p->name, p->pmd_id, p->sctp_local_q,
658 rte_panic("%s (%" PRIu32 "): "
660 "filter (queue = %" PRIu32 ", "
664 p->sctp_local_q, cp->ip,
671 status = rte_eth_dev_set_link_up(cp->pmd_id);
673 rte_panic("%s (%" PRIu32 "): PMD set up error %" PRId32 "\n",
674 cp->name, cp->pmd_id, status);
676 /* Mark link as UP */
681 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
686 rte_eth_dev_set_link_down(cp->pmd_id);
688 /* Mark link as DOWN */
691 /* Return if current link IP is not valid */
695 /* For each link, remove filters for IP of current link */
696 for (i = 0; i < app->n_links; i++) {
697 struct app_link_params *p = &app->link_params[i];
700 if (p->ip_local_q != 0) {
701 int status = app_link_filter_ip_del(p, cp);
703 APP_LOG(app, LOW, "%s (%" PRIu32
704 "): Deleting IP filter "
705 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
706 p->name, p->pmd_id, p->ip_local_q, cp->ip);
709 rte_panic("%s (%" PRIu32
710 "): Error deleting IP filter "
714 p->name, p->pmd_id, p->ip_local_q,
719 if (p->tcp_local_q != 0) {
720 int status = app_link_filter_tcp_del(p, cp);
722 APP_LOG(app, LOW, "%s (%" PRIu32
723 "): Deleting TCP filter "
725 ", IP = 0x%" PRIx32 ")",
726 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
729 rte_panic("%s (%" PRIu32
730 "): Error deleting TCP filter "
734 p->name, p->pmd_id, p->tcp_local_q,
739 if (p->udp_local_q != 0) {
740 int status = app_link_filter_udp_del(p, cp);
742 APP_LOG(app, LOW, "%s (%" PRIu32
743 "): Deleting UDP filter "
744 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
745 p->name, p->pmd_id, p->udp_local_q, cp->ip);
748 rte_panic("%s (%" PRIu32
749 "): Error deleting UDP filter "
753 p->name, p->pmd_id, p->udp_local_q,
758 if (p->sctp_local_q != 0) {
759 int status = app_link_filter_sctp_del(p, cp);
761 APP_LOG(app, LOW, "%s (%" PRIu32
762 "): Deleting SCTP filter "
764 ", IP = 0x%" PRIx32 ")",
765 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
768 rte_panic("%s (%" PRIu32
769 "): Error deleting SCTP filter "
773 p->name, p->pmd_id, p->sctp_local_q,
780 app_check_link(struct app_params *app)
782 uint32_t all_links_up, i;
786 for (i = 0; i < app->n_links; i++) {
787 struct app_link_params *p = &app->link_params[i];
788 struct rte_eth_link link_params;
790 memset(&link_params, 0, sizeof(link_params));
791 rte_eth_link_get(p->pmd_id, &link_params);
793 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
796 link_params.link_speed / 1000,
797 link_params.link_status ? "UP" : "DOWN");
799 if (link_params.link_status == 0)
803 if (all_links_up == 0)
804 rte_panic("Some links are DOWN\n");
808 is_any_swq_frag_or_ras(struct app_params *app)
812 for (i = 0; i < app->n_pktq_swq; i++) {
813 struct app_pktq_swq_params *p = &app->swq_params[i];
815 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
816 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
824 app_init_link_frag_ras(struct app_params *app)
828 if (is_any_swq_frag_or_ras(app)) {
829 for (i = 0; i < app->n_pktq_hwq_out; i++) {
830 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
832 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
838 app_init_link(struct app_params *app)
842 app_init_link_frag_ras(app);
844 for (i = 0; i < app->n_links; i++) {
845 struct app_link_params *p_link = &app->link_params[i];
846 uint32_t link_id, n_hwq_in, n_hwq_out, j;
849 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
850 n_hwq_in = app_link_get_n_rxq(app, p_link);
851 n_hwq_out = app_link_get_n_txq(app, p_link);
853 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
854 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
861 status = rte_eth_dev_configure(
867 rte_panic("%s (%" PRId32 "): "
868 "init error (%" PRId32 ")\n",
869 p_link->name, p_link->pmd_id, status);
871 rte_eth_macaddr_get(p_link->pmd_id,
872 (struct ether_addr *) &p_link->mac_addr);
875 rte_eth_promiscuous_enable(p_link->pmd_id);
878 for (j = 0; j < app->n_pktq_hwq_in; j++) {
879 struct app_pktq_hwq_in_params *p_rxq =
880 &app->hwq_in_params[j];
881 uint32_t rxq_link_id, rxq_queue_id;
883 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
884 &rxq_link_id, &rxq_queue_id);
885 if (rxq_link_id != link_id)
888 status = rte_eth_rx_queue_setup(
892 rte_eth_dev_socket_id(p_link->pmd_id),
894 app->mempool[p_rxq->mempool_id]);
896 rte_panic("%s (%" PRIu32 "): "
897 "%s init error (%" PRId32 ")\n",
905 for (j = 0; j < app->n_pktq_hwq_out; j++) {
906 struct app_pktq_hwq_out_params *p_txq =
907 &app->hwq_out_params[j];
908 uint32_t txq_link_id, txq_queue_id;
910 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
911 &txq_link_id, &txq_queue_id);
912 if (txq_link_id != link_id)
915 status = rte_eth_tx_queue_setup(
919 rte_eth_dev_socket_id(p_link->pmd_id),
922 rte_panic("%s (%" PRIu32 "): "
923 "%s init error (%" PRId32 ")\n",
931 status = rte_eth_dev_start(p_link->pmd_id);
933 rte_panic("Cannot start %s (error %" PRId32 ")\n",
934 p_link->name, status);
937 app_link_set_arp_filter(app, p_link);
938 app_link_set_tcp_syn_filter(app, p_link);
939 app_link_up_internal(app, p_link);
946 app_init_swq(struct app_params *app)
950 for (i = 0; i < app->n_pktq_swq; i++) {
951 struct app_pktq_swq_params *p = &app->swq_params[i];
954 if (app_swq_get_readers(app, p) == 1)
955 flags |= RING_F_SC_DEQ;
956 if (app_swq_get_writers(app, p) == 1)
957 flags |= RING_F_SP_ENQ;
959 APP_LOG(app, HIGH, "Initializing %s...", p->name);
960 app->swq[i] = rte_ring_create(
966 if (app->swq[i] == NULL)
967 rte_panic("%s init error\n", p->name);
972 app_init_tm(struct app_params *app)
976 for (i = 0; i < app->n_pktq_tm; i++) {
977 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
978 struct app_link_params *p_link;
979 struct rte_eth_link link_eth_params;
980 struct rte_sched_port *sched;
981 uint32_t n_subports, subport_id;
984 p_link = app_get_link_for_tm(app, p_tm);
986 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
989 p_tm->sched_port_params.name = p_tm->name;
990 p_tm->sched_port_params.socket =
991 rte_eth_dev_socket_id(p_link->pmd_id);
992 p_tm->sched_port_params.rate =
993 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
995 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
996 sched = rte_sched_port_config(&p_tm->sched_port_params);
998 rte_panic("%s init error\n", p_tm->name);
1002 n_subports = p_tm->sched_port_params.n_subports_per_port;
1003 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1004 uint32_t n_pipes_per_subport, pipe_id;
1006 status = rte_sched_subport_config(sched,
1008 &p_tm->sched_subport_params[subport_id]);
1010 rte_panic("%s subport %" PRIu32
1011 " init error (%" PRId32 ")\n",
1012 p_tm->name, subport_id, status);
1015 n_pipes_per_subport =
1016 p_tm->sched_port_params.n_pipes_per_subport;
1018 pipe_id < n_pipes_per_subport;
1020 int profile_id = p_tm->sched_pipe_to_profile[
1021 subport_id * APP_MAX_SCHED_PIPES +
1024 if (profile_id == -1)
1027 status = rte_sched_pipe_config(sched,
1032 rte_panic("%s subport %" PRIu32
1034 " (profile %" PRId32 ") "
1035 "init error (% " PRId32 ")\n",
1036 p_tm->name, subport_id, pipe_id,
1037 profile_id, status);
1044 app_init_msgq(struct app_params *app)
1048 for (i = 0; i < app->n_msgq; i++) {
1049 struct app_msgq_params *p = &app->msgq_params[i];
1051 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1052 app->msgq[i] = rte_ring_create(
1056 RING_F_SP_ENQ | RING_F_SC_DEQ);
1058 if (app->msgq[i] == NULL)
1059 rte_panic("%s init error\n", p->name);
1063 static void app_pipeline_params_get(struct app_params *app,
1064 struct app_pipeline_params *p_in,
1065 struct pipeline_params *p_out)
1068 uint32_t mempool_id;
1070 strcpy(p_out->name, p_in->name);
1072 p_out->socket_id = (int) p_in->socket_id;
1074 p_out->log_level = app->log_level;
1077 p_out->n_ports_in = p_in->n_pktq_in;
1078 for (i = 0; i < p_in->n_pktq_in; i++) {
1079 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1080 struct pipeline_port_in_params *out = &p_out->port_in[i];
1083 case APP_PKTQ_IN_HWQ:
1085 struct app_pktq_hwq_in_params *p_hwq_in =
1086 &app->hwq_in_params[in->id];
1087 struct app_link_params *p_link =
1088 app_get_link_for_rxq(app, p_hwq_in);
1089 uint32_t rxq_link_id, rxq_queue_id;
1091 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1095 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1096 out->params.ethdev.port_id = p_link->pmd_id;
1097 out->params.ethdev.queue_id = rxq_queue_id;
1098 out->burst_size = p_hwq_in->burst;
1101 case APP_PKTQ_IN_SWQ:
1103 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1105 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1106 if (app_swq_get_readers(app, swq_params) == 1) {
1107 out->type = PIPELINE_PORT_IN_RING_READER;
1108 out->params.ring.ring = app->swq[in->id];
1109 out->burst_size = app->swq_params[in->id].burst_read;
1111 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1112 out->params.ring_multi.ring = app->swq[in->id];
1113 out->burst_size = swq_params->burst_read;
1116 if (swq_params->ipv4_frag == 1) {
1117 struct rte_port_ring_reader_ipv4_frag_params *params =
1118 &out->params.ring_ipv4_frag;
1120 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1121 params->ring = app->swq[in->id];
1122 params->mtu = swq_params->mtu;
1123 params->metadata_size = swq_params->metadata_size;
1124 params->pool_direct =
1125 app->mempool[swq_params->mempool_direct_id];
1126 params->pool_indirect =
1127 app->mempool[swq_params->mempool_indirect_id];
1128 out->burst_size = swq_params->burst_read;
1130 struct rte_port_ring_reader_ipv6_frag_params *params =
1131 &out->params.ring_ipv6_frag;
1133 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1134 params->ring = app->swq[in->id];
1135 params->mtu = swq_params->mtu;
1136 params->metadata_size = swq_params->metadata_size;
1137 params->pool_direct =
1138 app->mempool[swq_params->mempool_direct_id];
1139 params->pool_indirect =
1140 app->mempool[swq_params->mempool_indirect_id];
1141 out->burst_size = swq_params->burst_read;
1146 case APP_PKTQ_IN_TM:
1147 out->type = PIPELINE_PORT_IN_SCHED_READER;
1148 out->params.sched.sched = app->tm[in->id];
1149 out->burst_size = app->tm_params[in->id].burst_read;
1151 case APP_PKTQ_IN_SOURCE:
1152 mempool_id = app->source_params[in->id].mempool_id;
1153 out->type = PIPELINE_PORT_IN_SOURCE;
1154 out->params.source.mempool = app->mempool[mempool_id];
1155 out->burst_size = app->source_params[in->id].burst;
1163 p_out->n_ports_out = p_in->n_pktq_out;
1164 for (i = 0; i < p_in->n_pktq_out; i++) {
1165 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1166 struct pipeline_port_out_params *out = &p_out->port_out[i];
1169 case APP_PKTQ_OUT_HWQ:
1171 struct app_pktq_hwq_out_params *p_hwq_out =
1172 &app->hwq_out_params[in->id];
1173 struct app_link_params *p_link =
1174 app_get_link_for_txq(app, p_hwq_out);
1175 uint32_t txq_link_id, txq_queue_id;
1177 sscanf(p_hwq_out->name,
1178 "TXQ%" SCNu32 ".%" SCNu32,
1182 if (p_hwq_out->dropless == 0) {
1183 struct rte_port_ethdev_writer_params *params =
1184 &out->params.ethdev;
1186 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1187 params->port_id = p_link->pmd_id;
1188 params->queue_id = txq_queue_id;
1189 params->tx_burst_sz =
1190 app->hwq_out_params[in->id].burst;
1192 struct rte_port_ethdev_writer_nodrop_params
1193 *params = &out->params.ethdev_nodrop;
1196 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1197 params->port_id = p_link->pmd_id;
1198 params->queue_id = txq_queue_id;
1199 params->tx_burst_sz = p_hwq_out->burst;
1200 params->n_retries = p_hwq_out->n_retries;
1204 case APP_PKTQ_OUT_SWQ:
1206 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1208 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1209 if (app_swq_get_writers(app, swq_params) == 1) {
1210 if (app->swq_params[in->id].dropless == 0) {
1211 struct rte_port_ring_writer_params *params =
1214 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1215 params->ring = app->swq[in->id];
1216 params->tx_burst_sz =
1217 app->swq_params[in->id].burst_write;
1219 struct rte_port_ring_writer_nodrop_params
1220 *params = &out->params.ring_nodrop;
1223 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1224 params->ring = app->swq[in->id];
1225 params->tx_burst_sz =
1226 app->swq_params[in->id].burst_write;
1228 app->swq_params[in->id].n_retries;
1231 if (swq_params->dropless == 0) {
1232 struct rte_port_ring_multi_writer_params *params =
1233 &out->params.ring_multi;
1235 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1236 params->ring = app->swq[in->id];
1237 params->tx_burst_sz = swq_params->burst_write;
1239 struct rte_port_ring_multi_writer_nodrop_params
1240 *params = &out->params.ring_multi_nodrop;
1242 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1243 params->ring = app->swq[in->id];
1244 params->tx_burst_sz = swq_params->burst_write;
1245 params->n_retries = swq_params->n_retries;
1249 if (swq_params->ipv4_ras == 1) {
1250 struct rte_port_ring_writer_ipv4_ras_params *params =
1251 &out->params.ring_ipv4_ras;
1253 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1254 params->ring = app->swq[in->id];
1255 params->tx_burst_sz = swq_params->burst_write;
1257 struct rte_port_ring_writer_ipv6_ras_params *params =
1258 &out->params.ring_ipv6_ras;
1260 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1261 params->ring = app->swq[in->id];
1262 params->tx_burst_sz = swq_params->burst_write;
1267 case APP_PKTQ_OUT_TM: {
1268 struct rte_port_sched_writer_params *params =
1271 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1272 params->sched = app->tm[in->id];
1273 params->tx_burst_sz =
1274 app->tm_params[in->id].burst_write;
1277 case APP_PKTQ_OUT_SINK:
1278 out->type = PIPELINE_PORT_OUT_SINK;
1286 p_out->n_msgq = p_in->n_msgq_in;
1288 for (i = 0; i < p_in->n_msgq_in; i++)
1289 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1291 for (i = 0; i < p_in->n_msgq_out; i++)
1292 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1295 p_out->n_args = p_in->n_args;
1296 for (i = 0; i < p_in->n_args; i++) {
1297 p_out->args_name[i] = p_in->args_name[i];
1298 p_out->args_value[i] = p_in->args_value[i];
1303 app_init_pipelines(struct app_params *app)
1307 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1308 struct app_pipeline_params *params =
1309 &app->pipeline_params[p_id];
1310 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1311 struct pipeline_type *ptype;
1312 struct pipeline_params pp;
1314 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1316 ptype = app_pipeline_type_find(app, params->type);
1318 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1321 app_pipeline_params_get(app, params, &pp);
1325 if (ptype->be_ops->f_init) {
1326 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1328 if (data->be == NULL)
1329 rte_panic("Pipeline instance \"%s\" back-end "
1330 "init error\n", params->name);
1335 if (ptype->fe_ops->f_init) {
1336 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1338 if (data->fe == NULL)
1339 rte_panic("Pipeline instance \"%s\" front-end "
1340 "init error\n", params->name);
1343 data->timer_period = (rte_get_tsc_hz() * params->timer_period)
1349 app_init_threads(struct app_params *app)
1351 uint64_t time = rte_get_tsc_cycles();
1354 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1355 struct app_pipeline_params *params =
1356 &app->pipeline_params[p_id];
1357 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1358 struct pipeline_type *ptype;
1359 struct app_thread_data *t;
1360 struct app_thread_pipeline_data *p;
1363 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1366 params->hyper_th_id);
1369 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1372 (params->hyper_th_id) ? "h" : "");
1374 t = &app->thread_data[lcore_id];
1376 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1377 t->thread_req_deadline = time + t->timer_period;
1379 t->msgq_in = app_thread_msgq_in_get(app,
1382 params->hyper_th_id);
1383 if (t->msgq_in == NULL)
1384 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1387 t->msgq_out = app_thread_msgq_out_get(app,
1390 params->hyper_th_id);
1391 if (t->msgq_out == NULL)
1392 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1395 ptype = app_pipeline_type_find(app, params->type);
1397 rte_panic("Init error: Unknown pipeline "
1398 "type \"%s\"\n", params->type);
1400 p = (ptype->be_ops->f_run == NULL) ?
1401 &t->regular[t->n_regular] :
1402 &t->custom[t->n_custom];
1404 p->pipeline_id = p_id;
1406 p->f_run = ptype->be_ops->f_run;
1407 p->f_timer = ptype->be_ops->f_timer;
1408 p->timer_period = data->timer_period;
1409 p->deadline = time + data->timer_period;
1413 if (ptype->be_ops->f_run == NULL)
1420 int app_init(struct app_params *app)
1422 app_init_core_map(app);
1423 app_init_core_mask(app);
1426 app_init_mempool(app);
1432 app_pipeline_common_cmd_push(app);
1433 app_pipeline_thread_cmd_push(app);
1434 app_pipeline_type_register(app, &pipeline_master);
1435 app_pipeline_type_register(app, &pipeline_passthrough);
1436 app_pipeline_type_register(app, &pipeline_flow_classification);
1437 app_pipeline_type_register(app, &pipeline_firewall);
1438 app_pipeline_type_register(app, &pipeline_routing);
1440 app_init_pipelines(app);
1441 app_init_threads(app);
1447 app_pipeline_type_cmd_push(struct app_params *app,
1448 struct pipeline_type *ptype)
1450 cmdline_parse_ctx_t *cmds;
1453 /* Check input arguments */
1454 if ((app == NULL) ||
1458 n_cmds = pipeline_type_cmds_count(ptype);
1462 cmds = ptype->fe_ops->cmds;
1464 /* Check for available slots in the application commands array */
1465 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1468 /* Push pipeline commands into the application */
1469 memcpy(&app->cmds[app->n_cmds],
1471 n_cmds * sizeof(cmdline_parse_ctx_t *));
1473 for (i = 0; i < n_cmds; i++)
1474 app->cmds[app->n_cmds + i]->data = app;
1476 app->n_cmds += n_cmds;
1477 app->cmds[app->n_cmds] = NULL;
1483 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1487 /* Check input arguments */
1488 if ((app == NULL) ||
1490 (ptype->name == NULL) ||
1491 (strlen(ptype->name) == 0) ||
1492 (ptype->be_ops->f_init == NULL) ||
1493 (ptype->be_ops->f_timer == NULL))
1496 /* Check for duplicate entry */
1497 for (i = 0; i < app->n_pipeline_types; i++)
1498 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1501 /* Check for resource availability */
1502 n_cmds = pipeline_type_cmds_count(ptype);
1503 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1504 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1507 /* Copy pipeline type */
1508 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1510 sizeof(struct pipeline_type));
1512 /* Copy CLI commands */
1514 app_pipeline_type_cmd_push(app, ptype);
1520 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1524 for (i = 0; i < app->n_pipeline_types; i++)
1525 if (strcmp(app->pipeline_type[i].name, name) == 0)
1526 return &app->pipeline_type[i];