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_routing.h"
53 #define APP_NAME_SIZE 32
56 app_init_core_map(struct app_params *app)
58 APP_LOG(app, HIGH, "Initializing CPU core map ...");
59 app->core_map = cpu_core_map_init(4, 32, 4, 0);
61 if (app->core_map == NULL)
62 rte_panic("Cannot create CPU core map\n");
64 if (app->log_level >= APP_LOG_LEVEL_LOW)
65 cpu_core_map_print(app->core_map);
69 app_init_core_mask(struct app_params *app)
74 for (i = 0; i < app->n_pipelines; i++) {
75 struct app_pipeline_params *p = &app->pipeline_params[i];
78 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
84 rte_panic("Cannot create CPU core mask\n");
86 mask |= 1LLU << lcore_id;
89 app->core_mask = mask;
90 APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
94 app_init_eal(struct app_params *app)
97 struct app_eal_params *p = &app->eal_params;
101 app->eal_argv[n_args++] = strdup(app->app_name);
103 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
104 app->eal_argv[n_args++] = strdup(buffer);
107 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
108 app->eal_argv[n_args++] = strdup(buffer);
111 if (p->master_lcore_present) {
114 "--master-lcore=%" PRIu32,
116 app->eal_argv[n_args++] = strdup(buffer);
119 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
120 app->eal_argv[n_args++] = strdup(buffer);
122 if (p->memory_present) {
123 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
124 app->eal_argv[n_args++] = strdup(buffer);
127 if (p->ranks_present) {
128 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
129 app->eal_argv[n_args++] = strdup(buffer);
132 if (p->pci_blacklist) {
135 "--pci-blacklist=%s",
137 app->eal_argv[n_args++] = strdup(buffer);
140 if (p->pci_whitelist) {
143 "--pci-whitelist=%s",
145 app->eal_argv[n_args++] = strdup(buffer);
149 snprintf(buffer, sizeof(buffer), "--vdev=%s", p->vdev);
150 app->eal_argv[n_args++] = strdup(buffer);
153 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
154 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
155 app->eal_argv[n_args++] = strdup(buffer);
163 app->eal_argv[n_args++] = strdup(buffer);
167 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
168 app->eal_argv[n_args++] = strdup(buffer);
171 if (p->log_level_present) {
174 "--log-level=%" PRIu32,
176 app->eal_argv[n_args++] = strdup(buffer);
179 if ((p->version_present) && p->version) {
180 snprintf(buffer, sizeof(buffer), "-v");
181 app->eal_argv[n_args++] = strdup(buffer);
184 if ((p->help_present) && p->help) {
185 snprintf(buffer, sizeof(buffer), "--help");
186 app->eal_argv[n_args++] = strdup(buffer);
189 if ((p->no_huge_present) && p->no_huge) {
190 snprintf(buffer, sizeof(buffer), "--no-huge");
191 app->eal_argv[n_args++] = strdup(buffer);
194 if ((p->no_pci_present) && p->no_pci) {
195 snprintf(buffer, sizeof(buffer), "--no-pci");
196 app->eal_argv[n_args++] = strdup(buffer);
199 if ((p->no_hpet_present) && p->no_hpet) {
200 snprintf(buffer, sizeof(buffer), "--no-hpet");
201 app->eal_argv[n_args++] = strdup(buffer);
204 if ((p->no_shconf_present) && p->no_shconf) {
205 snprintf(buffer, sizeof(buffer), "--no-shconf");
206 app->eal_argv[n_args++] = strdup(buffer);
210 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
211 app->eal_argv[n_args++] = strdup(buffer);
219 app->eal_argv[n_args++] = strdup(buffer);
223 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
224 app->eal_argv[n_args++] = strdup(buffer);
227 if (p->file_prefix) {
232 app->eal_argv[n_args++] = strdup(buffer);
235 if (p->base_virtaddr) {
238 "--base-virtaddr=%s",
240 app->eal_argv[n_args++] = strdup(buffer);
243 if ((p->create_uio_dev_present) && p->create_uio_dev) {
244 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
245 app->eal_argv[n_args++] = strdup(buffer);
253 app->eal_argv[n_args++] = strdup(buffer);
256 if ((p->xen_dom0_present) && (p->xen_dom0)) {
257 snprintf(buffer, sizeof(buffer), "--xen-dom0");
258 app->eal_argv[n_args++] = strdup(buffer);
261 snprintf(buffer, sizeof(buffer), "--");
262 app->eal_argv[n_args++] = strdup(buffer);
264 app->eal_argc = n_args;
266 APP_LOG(app, HIGH, "Initializing EAL ...");
267 status = rte_eal_init(app->eal_argc, app->eal_argv);
269 rte_panic("EAL init error\n");
273 app_init_mempool(struct app_params *app)
277 for (i = 0; i < app->n_mempools; i++) {
278 struct app_mempool_params *p = &app->mempool_params[i];
280 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
281 app->mempool[i] = rte_mempool_create(
286 sizeof(struct rte_pktmbuf_pool_private),
287 rte_pktmbuf_pool_init, NULL,
288 rte_pktmbuf_init, NULL,
292 if (app->mempool[i] == NULL)
293 rte_panic("%s init error\n", p->name);
298 app_link_filter_arp_add(struct app_link_params *link)
300 struct rte_eth_ethertype_filter filter = {
301 .ether_type = ETHER_TYPE_ARP,
303 .queue = link->arp_q,
306 return rte_eth_dev_filter_ctrl(link->pmd_id,
307 RTE_ETH_FILTER_ETHERTYPE,
313 app_link_filter_tcp_syn_add(struct app_link_params *link)
315 struct rte_eth_syn_filter filter = {
317 .queue = link->tcp_syn_local_q,
320 return rte_eth_dev_filter_ctrl(link->pmd_id,
327 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
329 struct rte_eth_ntuple_filter filter = {
330 .flags = RTE_5TUPLE_FLAGS,
331 .dst_ip = rte_bswap32(l2->ip),
332 .dst_ip_mask = UINT32_MAX, /* Enable */
334 .src_ip_mask = 0, /* Disable */
336 .dst_port_mask = 0, /* Disable */
338 .src_port_mask = 0, /* Disable */
340 .proto_mask = 0, /* Disable */
342 .priority = 1, /* Lowest */
343 .queue = l1->ip_local_q,
346 return rte_eth_dev_filter_ctrl(l1->pmd_id,
347 RTE_ETH_FILTER_NTUPLE,
353 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
355 struct rte_eth_ntuple_filter filter = {
356 .flags = RTE_5TUPLE_FLAGS,
357 .dst_ip = rte_bswap32(l2->ip),
358 .dst_ip_mask = UINT32_MAX, /* Enable */
360 .src_ip_mask = 0, /* Disable */
362 .dst_port_mask = 0, /* Disable */
364 .src_port_mask = 0, /* Disable */
366 .proto_mask = 0, /* Disable */
368 .priority = 1, /* Lowest */
369 .queue = l1->ip_local_q,
372 return rte_eth_dev_filter_ctrl(l1->pmd_id,
373 RTE_ETH_FILTER_NTUPLE,
374 RTE_ETH_FILTER_DELETE,
379 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
381 struct rte_eth_ntuple_filter filter = {
382 .flags = RTE_5TUPLE_FLAGS,
383 .dst_ip = rte_bswap32(l2->ip),
384 .dst_ip_mask = UINT32_MAX, /* Enable */
386 .src_ip_mask = 0, /* Disable */
388 .dst_port_mask = 0, /* Disable */
390 .src_port_mask = 0, /* Disable */
391 .proto = IPPROTO_TCP,
392 .proto_mask = UINT8_MAX, /* Enable */
394 .priority = 2, /* Higher priority than IP */
395 .queue = l1->tcp_local_q,
398 return rte_eth_dev_filter_ctrl(l1->pmd_id,
399 RTE_ETH_FILTER_NTUPLE,
405 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
407 struct rte_eth_ntuple_filter filter = {
408 .flags = RTE_5TUPLE_FLAGS,
409 .dst_ip = rte_bswap32(l2->ip),
410 .dst_ip_mask = UINT32_MAX, /* Enable */
412 .src_ip_mask = 0, /* Disable */
414 .dst_port_mask = 0, /* Disable */
416 .src_port_mask = 0, /* Disable */
417 .proto = IPPROTO_TCP,
418 .proto_mask = UINT8_MAX, /* Enable */
420 .priority = 2, /* Higher priority than IP */
421 .queue = l1->tcp_local_q,
424 return rte_eth_dev_filter_ctrl(l1->pmd_id,
425 RTE_ETH_FILTER_NTUPLE,
426 RTE_ETH_FILTER_DELETE,
431 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
433 struct rte_eth_ntuple_filter filter = {
434 .flags = RTE_5TUPLE_FLAGS,
435 .dst_ip = rte_bswap32(l2->ip),
436 .dst_ip_mask = UINT32_MAX, /* Enable */
438 .src_ip_mask = 0, /* Disable */
440 .dst_port_mask = 0, /* Disable */
442 .src_port_mask = 0, /* Disable */
443 .proto = IPPROTO_UDP,
444 .proto_mask = UINT8_MAX, /* Enable */
446 .priority = 2, /* Higher priority than IP */
447 .queue = l1->udp_local_q,
450 return rte_eth_dev_filter_ctrl(l1->pmd_id,
451 RTE_ETH_FILTER_NTUPLE,
457 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
459 struct rte_eth_ntuple_filter filter = {
460 .flags = RTE_5TUPLE_FLAGS,
461 .dst_ip = rte_bswap32(l2->ip),
462 .dst_ip_mask = UINT32_MAX, /* Enable */
464 .src_ip_mask = 0, /* Disable */
466 .dst_port_mask = 0, /* Disable */
468 .src_port_mask = 0, /* Disable */
469 .proto = IPPROTO_UDP,
470 .proto_mask = UINT8_MAX, /* Enable */
472 .priority = 2, /* Higher priority than IP */
473 .queue = l1->udp_local_q,
476 return rte_eth_dev_filter_ctrl(l1->pmd_id,
477 RTE_ETH_FILTER_NTUPLE,
478 RTE_ETH_FILTER_DELETE,
483 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
485 struct rte_eth_ntuple_filter filter = {
486 .flags = RTE_5TUPLE_FLAGS,
487 .dst_ip = rte_bswap32(l2->ip),
488 .dst_ip_mask = UINT32_MAX, /* Enable */
490 .src_ip_mask = 0, /* Disable */
492 .dst_port_mask = 0, /* Disable */
494 .src_port_mask = 0, /* Disable */
495 .proto = IPPROTO_SCTP,
496 .proto_mask = UINT8_MAX, /* Enable */
498 .priority = 2, /* Higher priority than IP */
499 .queue = l1->sctp_local_q,
502 return rte_eth_dev_filter_ctrl(l1->pmd_id,
503 RTE_ETH_FILTER_NTUPLE,
509 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
511 struct rte_eth_ntuple_filter filter = {
512 .flags = RTE_5TUPLE_FLAGS,
513 .dst_ip = rte_bswap32(l2->ip),
514 .dst_ip_mask = UINT32_MAX, /* Enable */
516 .src_ip_mask = 0, /* Disable */
518 .dst_port_mask = 0, /* Disable */
520 .src_port_mask = 0, /* Disable */
521 .proto = IPPROTO_SCTP,
522 .proto_mask = UINT8_MAX, /* Enable */
524 .priority = 2, /* Higher priority than IP */
525 .queue = l1->sctp_local_q,
528 return rte_eth_dev_filter_ctrl(l1->pmd_id,
529 RTE_ETH_FILTER_NTUPLE,
530 RTE_ETH_FILTER_DELETE,
535 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
537 if (cp->arp_q != 0) {
538 int status = app_link_filter_arp_add(cp);
540 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
541 "Adding ARP filter (queue = %" PRIu32 ")",
542 cp->name, cp->pmd_id, cp->arp_q);
545 rte_panic("%s (%" PRIu32 "): "
546 "Error adding ARP filter "
547 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
548 cp->name, cp->pmd_id, cp->arp_q, status);
553 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
555 if (cp->tcp_syn_local_q != 0) {
556 int status = app_link_filter_tcp_syn_add(cp);
558 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
559 "Adding TCP SYN filter (queue = %" PRIu32 ")",
560 cp->name, cp->pmd_id, cp->tcp_syn_local_q);
563 rte_panic("%s (%" PRIu32 "): "
564 "Error adding TCP SYN filter "
565 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
566 cp->name, cp->pmd_id, cp->tcp_syn_local_q,
572 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
577 /* For each link, add filters for IP of current link */
579 for (i = 0; i < app->n_links; i++) {
580 struct app_link_params *p = &app->link_params[i];
583 if (p->ip_local_q != 0) {
584 int status = app_link_filter_ip_add(p, cp);
586 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
587 "Adding IP filter (queue= %" PRIu32
588 ", IP = 0x%08" PRIx32 ")",
589 p->name, p->pmd_id, p->ip_local_q,
593 rte_panic("%s (%" PRIu32 "): "
595 "filter (queue= %" PRIu32 ", "
599 p->ip_local_q, cp->ip, status);
603 if (p->tcp_local_q != 0) {
604 int status = app_link_filter_tcp_add(p, cp);
606 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
609 ", IP = 0x%08" PRIx32 ")",
610 p->name, p->pmd_id, p->tcp_local_q,
614 rte_panic("%s (%" PRIu32 "): "
616 "filter (queue = %" PRIu32 ", "
620 p->tcp_local_q, cp->ip, status);
624 if (p->udp_local_q != 0) {
625 int status = app_link_filter_udp_add(p, cp);
627 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
630 ", IP = 0x%08" PRIx32 ")",
631 p->name, p->pmd_id, p->udp_local_q,
635 rte_panic("%s (%" PRIu32 "): "
637 "filter (queue = %" PRIu32 ", "
641 p->udp_local_q, cp->ip, status);
645 if (p->sctp_local_q != 0) {
646 int status = app_link_filter_sctp_add(p, cp);
648 APP_LOG(app, LOW, "%s (%" PRIu32
649 "): Adding SCTP filter "
651 ", IP = 0x%08" PRIx32 ")",
652 p->name, p->pmd_id, p->sctp_local_q,
656 rte_panic("%s (%" PRIu32 "): "
658 "filter (queue = %" PRIu32 ", "
662 p->sctp_local_q, cp->ip,
669 status = rte_eth_dev_set_link_up(cp->pmd_id);
671 rte_panic("%s (%" PRIu32 "): PMD set up error %" PRId32 "\n",
672 cp->name, cp->pmd_id, status);
674 /* Mark link as UP */
679 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
684 rte_eth_dev_set_link_down(cp->pmd_id);
686 /* Mark link as DOWN */
689 /* Return if current link IP is not valid */
693 /* For each link, remove filters for IP of current link */
694 for (i = 0; i < app->n_links; i++) {
695 struct app_link_params *p = &app->link_params[i];
698 if (p->ip_local_q != 0) {
699 int status = app_link_filter_ip_del(p, cp);
701 APP_LOG(app, LOW, "%s (%" PRIu32
702 "): Deleting IP filter "
703 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
704 p->name, p->pmd_id, p->ip_local_q, cp->ip);
707 rte_panic("%s (%" PRIu32
708 "): Error deleting IP filter "
712 p->name, p->pmd_id, p->ip_local_q,
717 if (p->tcp_local_q != 0) {
718 int status = app_link_filter_tcp_del(p, cp);
720 APP_LOG(app, LOW, "%s (%" PRIu32
721 "): Deleting TCP filter "
723 ", IP = 0x%" PRIx32 ")",
724 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
727 rte_panic("%s (%" PRIu32
728 "): Error deleting TCP filter "
732 p->name, p->pmd_id, p->tcp_local_q,
737 if (p->udp_local_q != 0) {
738 int status = app_link_filter_udp_del(p, cp);
740 APP_LOG(app, LOW, "%s (%" PRIu32
741 "): Deleting UDP filter "
742 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
743 p->name, p->pmd_id, p->udp_local_q, cp->ip);
746 rte_panic("%s (%" PRIu32
747 "): Error deleting UDP filter "
751 p->name, p->pmd_id, p->udp_local_q,
756 if (p->sctp_local_q != 0) {
757 int status = app_link_filter_sctp_del(p, cp);
759 APP_LOG(app, LOW, "%s (%" PRIu32
760 "): Deleting SCTP filter "
762 ", IP = 0x%" PRIx32 ")",
763 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
766 rte_panic("%s (%" PRIu32
767 "): Error deleting SCTP filter "
771 p->name, p->pmd_id, p->sctp_local_q,
778 app_check_link(struct app_params *app)
780 uint32_t all_links_up, i;
784 for (i = 0; i < app->n_links; i++) {
785 struct app_link_params *p = &app->link_params[i];
786 struct rte_eth_link link_params;
788 memset(&link_params, 0, sizeof(link_params));
789 rte_eth_link_get(p->pmd_id, &link_params);
791 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
794 link_params.link_speed / 1000,
795 link_params.link_status ? "UP" : "DOWN");
797 if (link_params.link_status == 0)
801 if (all_links_up == 0)
802 rte_panic("Some links are DOWN\n");
806 app_init_link(struct app_params *app)
810 for (i = 0; i < app->n_links; i++) {
811 struct app_link_params *p_link = &app->link_params[i];
812 uint32_t link_id, n_hwq_in, n_hwq_out, j;
815 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
816 n_hwq_in = app_link_get_n_rxq(app, p_link);
817 n_hwq_out = app_link_get_n_txq(app, p_link);
819 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
820 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
827 status = rte_eth_dev_configure(
833 rte_panic("%s (%" PRId32 "): "
834 "init error (%" PRId32 ")\n",
835 p_link->name, p_link->pmd_id, status);
837 rte_eth_macaddr_get(p_link->pmd_id,
838 (struct ether_addr *) &p_link->mac_addr);
841 rte_eth_promiscuous_enable(p_link->pmd_id);
844 for (j = 0; j < app->n_pktq_hwq_in; j++) {
845 struct app_pktq_hwq_in_params *p_rxq =
846 &app->hwq_in_params[j];
847 uint32_t rxq_link_id, rxq_queue_id;
849 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
850 &rxq_link_id, &rxq_queue_id);
851 if (rxq_link_id != link_id)
854 status = rte_eth_rx_queue_setup(
858 rte_eth_dev_socket_id(p_link->pmd_id),
860 app->mempool[p_rxq->mempool_id]);
862 rte_panic("%s (%" PRIu32 "): "
863 "%s init error (%" PRId32 ")\n",
871 for (j = 0; j < app->n_pktq_hwq_out; j++) {
872 struct app_pktq_hwq_out_params *p_txq =
873 &app->hwq_out_params[j];
874 uint32_t txq_link_id, txq_queue_id;
876 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
877 &txq_link_id, &txq_queue_id);
878 if (txq_link_id != link_id)
881 status = rte_eth_tx_queue_setup(
885 rte_eth_dev_socket_id(p_link->pmd_id),
888 rte_panic("%s (%" PRIu32 "): "
889 "%s init error (%" PRId32 ")\n",
897 status = rte_eth_dev_start(p_link->pmd_id);
899 rte_panic("Cannot start %s (error %" PRId32 ")\n",
900 p_link->name, status);
903 app_link_set_arp_filter(app, p_link);
904 app_link_set_tcp_syn_filter(app, p_link);
905 app_link_up_internal(app, p_link);
912 app_init_swq(struct app_params *app)
916 for (i = 0; i < app->n_pktq_swq; i++) {
917 struct app_pktq_swq_params *p = &app->swq_params[i];
919 APP_LOG(app, HIGH, "Initializing %s...", p->name);
920 app->swq[i] = rte_ring_create(
924 RING_F_SP_ENQ | RING_F_SC_DEQ);
926 if (app->swq[i] == NULL)
927 rte_panic("%s init error\n", p->name);
932 app_init_tm(struct app_params *app)
936 for (i = 0; i < app->n_pktq_tm; i++) {
937 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
938 struct app_link_params *p_link;
939 struct rte_eth_link link_eth_params;
940 struct rte_sched_port *sched;
941 uint32_t n_subports, subport_id;
944 p_link = app_get_link_for_tm(app, p_tm);
946 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
949 p_tm->sched_port_params.name = p_tm->name;
950 p_tm->sched_port_params.socket =
951 rte_eth_dev_socket_id(p_link->pmd_id);
952 p_tm->sched_port_params.rate =
953 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
955 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
956 sched = rte_sched_port_config(&p_tm->sched_port_params);
958 rte_panic("%s init error\n", p_tm->name);
962 n_subports = p_tm->sched_port_params.n_subports_per_port;
963 for (subport_id = 0; subport_id < n_subports; subport_id++) {
964 uint32_t n_pipes_per_subport, pipe_id;
966 status = rte_sched_subport_config(sched,
968 &p_tm->sched_subport_params[subport_id]);
970 rte_panic("%s subport %" PRIu32
971 " init error (%" PRId32 ")\n",
972 p_tm->name, subport_id, status);
975 n_pipes_per_subport =
976 p_tm->sched_port_params.n_pipes_per_subport;
978 pipe_id < n_pipes_per_subport;
980 int profile_id = p_tm->sched_pipe_to_profile[
981 subport_id * APP_MAX_SCHED_PIPES +
984 if (profile_id == -1)
987 status = rte_sched_pipe_config(sched,
992 rte_panic("%s subport %" PRIu32
994 " (profile %" PRId32 ") "
995 "init error (% " PRId32 ")\n",
996 p_tm->name, subport_id, pipe_id,
1004 app_init_msgq(struct app_params *app)
1008 for (i = 0; i < app->n_msgq; i++) {
1009 struct app_msgq_params *p = &app->msgq_params[i];
1011 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1012 app->msgq[i] = rte_ring_create(
1016 RING_F_SP_ENQ | RING_F_SC_DEQ);
1018 if (app->msgq[i] == NULL)
1019 rte_panic("%s init error\n", p->name);
1023 static void app_pipeline_params_get(struct app_params *app,
1024 struct app_pipeline_params *p_in,
1025 struct pipeline_params *p_out)
1029 strcpy(p_out->name, p_in->name);
1031 p_out->socket_id = (int) p_in->socket_id;
1033 p_out->log_level = app->log_level;
1036 p_out->n_ports_in = p_in->n_pktq_in;
1037 for (i = 0; i < p_in->n_pktq_in; i++) {
1038 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1039 struct pipeline_port_in_params *out = &p_out->port_in[i];
1042 case APP_PKTQ_IN_HWQ:
1044 struct app_pktq_hwq_in_params *p_hwq_in =
1045 &app->hwq_in_params[in->id];
1046 struct app_link_params *p_link =
1047 app_get_link_for_rxq(app, p_hwq_in);
1048 uint32_t rxq_link_id, rxq_queue_id;
1050 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1054 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1055 out->params.ethdev.port_id = p_link->pmd_id;
1056 out->params.ethdev.queue_id = rxq_queue_id;
1057 out->burst_size = p_hwq_in->burst;
1060 case APP_PKTQ_IN_SWQ:
1061 out->type = PIPELINE_PORT_IN_RING_READER;
1062 out->params.ring.ring = app->swq[in->id];
1063 out->burst_size = app->swq_params[in->id].burst_read;
1064 /* What about frag and ras ports? */
1066 case APP_PKTQ_IN_TM:
1067 out->type = PIPELINE_PORT_IN_SCHED_READER;
1068 out->params.sched.sched = app->tm[in->id];
1069 out->burst_size = app->tm_params[in->id].burst_read;
1071 case APP_PKTQ_IN_SOURCE:
1072 out->type = PIPELINE_PORT_IN_SOURCE;
1073 out->params.source.mempool = app->mempool[in->id];
1074 out->burst_size = app->source_params[in->id].burst;
1082 p_out->n_ports_out = p_in->n_pktq_out;
1083 for (i = 0; i < p_in->n_pktq_out; i++) {
1084 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1085 struct pipeline_port_out_params *out = &p_out->port_out[i];
1088 case APP_PKTQ_OUT_HWQ:
1090 struct app_pktq_hwq_out_params *p_hwq_out =
1091 &app->hwq_out_params[in->id];
1092 struct app_link_params *p_link =
1093 app_get_link_for_txq(app, p_hwq_out);
1094 uint32_t txq_link_id, txq_queue_id;
1096 sscanf(p_hwq_out->name,
1097 "TXQ%" SCNu32 ".%" SCNu32,
1101 if (p_hwq_out->dropless == 0) {
1102 struct rte_port_ethdev_writer_params *params =
1103 &out->params.ethdev;
1105 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1106 params->port_id = p_link->pmd_id;
1107 params->queue_id = txq_queue_id;
1108 params->tx_burst_sz =
1109 app->hwq_out_params[in->id].burst;
1111 struct rte_port_ethdev_writer_nodrop_params
1112 *params = &out->params.ethdev_nodrop;
1115 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1116 params->port_id = p_link->pmd_id;
1117 params->queue_id = txq_queue_id;
1118 params->tx_burst_sz = p_hwq_out->burst;
1119 params->n_retries = p_hwq_out->n_retries;
1123 case APP_PKTQ_OUT_SWQ:
1124 if (app->swq_params[in->id].dropless == 0) {
1125 struct rte_port_ring_writer_params *params =
1128 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1129 params->ring = app->swq[in->id];
1130 params->tx_burst_sz =
1131 app->swq_params[in->id].burst_write;
1133 struct rte_port_ring_writer_nodrop_params
1134 *params = &out->params.ring_nodrop;
1137 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1138 params->ring = app->swq[in->id];
1139 params->tx_burst_sz =
1140 app->swq_params[in->id].burst_write;
1142 app->swq_params[in->id].n_retries;
1144 /* What about frag and ras ports? */
1146 case APP_PKTQ_OUT_TM: {
1147 struct rte_port_sched_writer_params *params =
1150 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1151 params->sched = app->tm[in->id];
1152 params->tx_burst_sz =
1153 app->tm_params[in->id].burst_write;
1156 case APP_PKTQ_OUT_SINK:
1157 out->type = PIPELINE_PORT_OUT_SINK;
1165 p_out->n_msgq = p_in->n_msgq_in;
1167 for (i = 0; i < p_in->n_msgq_in; i++)
1168 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1170 for (i = 0; i < p_in->n_msgq_out; i++)
1171 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1174 p_out->n_args = p_in->n_args;
1175 for (i = 0; i < p_in->n_args; i++) {
1176 p_out->args_name[i] = p_in->args_name[i];
1177 p_out->args_value[i] = p_in->args_value[i];
1182 app_init_pipelines(struct app_params *app)
1186 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1187 struct app_pipeline_params *params =
1188 &app->pipeline_params[p_id];
1189 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1190 struct pipeline_type *ptype;
1191 struct pipeline_params pp;
1193 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1195 ptype = app_pipeline_type_find(app, params->type);
1197 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1200 app_pipeline_params_get(app, params, &pp);
1204 if (ptype->be_ops->f_init) {
1205 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1207 if (data->be == NULL)
1208 rte_panic("Pipeline instance \"%s\" back-end "
1209 "init error\n", params->name);
1214 if (ptype->fe_ops->f_init) {
1215 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1217 if (data->fe == NULL)
1218 rte_panic("Pipeline instance \"%s\" front-end "
1219 "init error\n", params->name);
1222 data->timer_period = (rte_get_tsc_hz() * params->timer_period)
1228 app_init_threads(struct app_params *app)
1230 uint64_t time = rte_get_tsc_cycles();
1233 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1234 struct app_pipeline_params *params =
1235 &app->pipeline_params[p_id];
1236 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1237 struct pipeline_type *ptype;
1238 struct app_thread_data *t;
1239 struct app_thread_pipeline_data *p;
1242 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1245 params->hyper_th_id);
1248 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1251 (params->hyper_th_id) ? "h" : "");
1253 t = &app->thread_data[lcore_id];
1255 ptype = app_pipeline_type_find(app, params->type);
1257 rte_panic("Init error: Unknown pipeline "
1258 "type \"%s\"\n", params->type);
1260 p = (ptype->be_ops->f_run == NULL) ?
1261 &t->regular[t->n_regular] :
1262 &t->custom[t->n_custom];
1265 p->f_run = ptype->be_ops->f_run;
1266 p->f_timer = ptype->be_ops->f_timer;
1267 p->timer_period = data->timer_period;
1268 p->deadline = time + data->timer_period;
1270 if (ptype->be_ops->f_run == NULL)
1277 int app_init(struct app_params *app)
1279 app_init_core_map(app);
1280 app_init_core_mask(app);
1283 app_init_mempool(app);
1289 app_pipeline_common_cmd_push(app);
1290 app_pipeline_type_register(app, &pipeline_master);
1291 app_pipeline_type_register(app, &pipeline_passthrough);
1292 app_pipeline_type_register(app, &pipeline_firewall);
1293 app_pipeline_type_register(app, &pipeline_routing);
1295 app_init_pipelines(app);
1296 app_init_threads(app);
1302 app_pipeline_type_cmd_push(struct app_params *app,
1303 struct pipeline_type *ptype)
1305 cmdline_parse_ctx_t *cmds;
1308 /* Check input arguments */
1309 if ((app == NULL) ||
1313 n_cmds = pipeline_type_cmds_count(ptype);
1317 cmds = ptype->fe_ops->cmds;
1319 /* Check for available slots in the application commands array */
1320 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1323 /* Push pipeline commands into the application */
1324 memcpy(&app->cmds[app->n_cmds],
1326 n_cmds * sizeof(cmdline_parse_ctx_t *));
1328 for (i = 0; i < n_cmds; i++)
1329 app->cmds[app->n_cmds + i]->data = app;
1331 app->n_cmds += n_cmds;
1332 app->cmds[app->n_cmds] = NULL;
1338 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1342 /* Check input arguments */
1343 if ((app == NULL) ||
1345 (ptype->name == NULL) ||
1346 (strlen(ptype->name) == 0) ||
1347 (ptype->be_ops->f_init == NULL) ||
1348 (ptype->be_ops->f_timer == NULL))
1351 /* Check for duplicate entry */
1352 for (i = 0; i < app->n_pipeline_types; i++)
1353 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1356 /* Check for resource availability */
1357 n_cmds = pipeline_type_cmds_count(ptype);
1358 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1359 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1362 /* Copy pipeline type */
1363 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1365 sizeof(struct pipeline_type));
1367 /* Copy CLI commands */
1369 app_pipeline_type_cmd_push(app, ptype);
1375 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1379 for (i = 0; i < app->n_pipeline_types; i++)
1380 if (strcmp(app->pipeline_type[i].name, name) == 0)
1381 return &app->pipeline_type[i];