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"
54 #define APP_NAME_SIZE 32
57 app_init_core_map(struct app_params *app)
59 APP_LOG(app, HIGH, "Initializing CPU core map ...");
60 app->core_map = cpu_core_map_init(4, 32, 4, 0);
62 if (app->core_map == NULL)
63 rte_panic("Cannot create CPU core map\n");
65 if (app->log_level >= APP_LOG_LEVEL_LOW)
66 cpu_core_map_print(app->core_map);
70 app_init_core_mask(struct app_params *app)
75 for (i = 0; i < app->n_pipelines; i++) {
76 struct app_pipeline_params *p = &app->pipeline_params[i];
79 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
85 rte_panic("Cannot create CPU core mask\n");
87 mask |= 1LLU << lcore_id;
90 app->core_mask = mask;
91 APP_LOG(app, HIGH, "CPU core mask = 0x%016" PRIx64, app->core_mask);
95 app_init_eal(struct app_params *app)
98 struct app_eal_params *p = &app->eal_params;
102 app->eal_argv[n_args++] = strdup(app->app_name);
104 snprintf(buffer, sizeof(buffer), "-c%" PRIx64, app->core_mask);
105 app->eal_argv[n_args++] = strdup(buffer);
108 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
109 app->eal_argv[n_args++] = strdup(buffer);
112 if (p->master_lcore_present) {
115 "--master-lcore=%" PRIu32,
117 app->eal_argv[n_args++] = strdup(buffer);
120 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
121 app->eal_argv[n_args++] = strdup(buffer);
123 if (p->memory_present) {
124 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
125 app->eal_argv[n_args++] = strdup(buffer);
128 if (p->ranks_present) {
129 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
130 app->eal_argv[n_args++] = strdup(buffer);
133 if (p->pci_blacklist) {
136 "--pci-blacklist=%s",
138 app->eal_argv[n_args++] = strdup(buffer);
141 if (p->pci_whitelist) {
144 "--pci-whitelist=%s",
146 app->eal_argv[n_args++] = strdup(buffer);
150 snprintf(buffer, sizeof(buffer), "--vdev=%s", p->vdev);
151 app->eal_argv[n_args++] = strdup(buffer);
154 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
155 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
156 app->eal_argv[n_args++] = strdup(buffer);
164 app->eal_argv[n_args++] = strdup(buffer);
168 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
169 app->eal_argv[n_args++] = strdup(buffer);
172 if (p->log_level_present) {
175 "--log-level=%" PRIu32,
177 app->eal_argv[n_args++] = strdup(buffer);
180 if ((p->version_present) && p->version) {
181 snprintf(buffer, sizeof(buffer), "-v");
182 app->eal_argv[n_args++] = strdup(buffer);
185 if ((p->help_present) && p->help) {
186 snprintf(buffer, sizeof(buffer), "--help");
187 app->eal_argv[n_args++] = strdup(buffer);
190 if ((p->no_huge_present) && p->no_huge) {
191 snprintf(buffer, sizeof(buffer), "--no-huge");
192 app->eal_argv[n_args++] = strdup(buffer);
195 if ((p->no_pci_present) && p->no_pci) {
196 snprintf(buffer, sizeof(buffer), "--no-pci");
197 app->eal_argv[n_args++] = strdup(buffer);
200 if ((p->no_hpet_present) && p->no_hpet) {
201 snprintf(buffer, sizeof(buffer), "--no-hpet");
202 app->eal_argv[n_args++] = strdup(buffer);
205 if ((p->no_shconf_present) && p->no_shconf) {
206 snprintf(buffer, sizeof(buffer), "--no-shconf");
207 app->eal_argv[n_args++] = strdup(buffer);
211 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
212 app->eal_argv[n_args++] = strdup(buffer);
220 app->eal_argv[n_args++] = strdup(buffer);
224 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
225 app->eal_argv[n_args++] = strdup(buffer);
228 if (p->file_prefix) {
233 app->eal_argv[n_args++] = strdup(buffer);
236 if (p->base_virtaddr) {
239 "--base-virtaddr=%s",
241 app->eal_argv[n_args++] = strdup(buffer);
244 if ((p->create_uio_dev_present) && p->create_uio_dev) {
245 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
246 app->eal_argv[n_args++] = strdup(buffer);
254 app->eal_argv[n_args++] = strdup(buffer);
257 if ((p->xen_dom0_present) && (p->xen_dom0)) {
258 snprintf(buffer, sizeof(buffer), "--xen-dom0");
259 app->eal_argv[n_args++] = strdup(buffer);
262 snprintf(buffer, sizeof(buffer), "--");
263 app->eal_argv[n_args++] = strdup(buffer);
265 app->eal_argc = n_args;
267 APP_LOG(app, HIGH, "Initializing EAL ...");
268 status = rte_eal_init(app->eal_argc, app->eal_argv);
270 rte_panic("EAL init error\n");
274 app_init_mempool(struct app_params *app)
278 for (i = 0; i < app->n_mempools; i++) {
279 struct app_mempool_params *p = &app->mempool_params[i];
281 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
282 app->mempool[i] = rte_mempool_create(
287 sizeof(struct rte_pktmbuf_pool_private),
288 rte_pktmbuf_pool_init, NULL,
289 rte_pktmbuf_init, NULL,
293 if (app->mempool[i] == NULL)
294 rte_panic("%s init error\n", p->name);
299 app_link_filter_arp_add(struct app_link_params *link)
301 struct rte_eth_ethertype_filter filter = {
302 .ether_type = ETHER_TYPE_ARP,
304 .queue = link->arp_q,
307 return rte_eth_dev_filter_ctrl(link->pmd_id,
308 RTE_ETH_FILTER_ETHERTYPE,
314 app_link_filter_tcp_syn_add(struct app_link_params *link)
316 struct rte_eth_syn_filter filter = {
318 .queue = link->tcp_syn_local_q,
321 return rte_eth_dev_filter_ctrl(link->pmd_id,
328 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
330 struct rte_eth_ntuple_filter filter = {
331 .flags = RTE_5TUPLE_FLAGS,
332 .dst_ip = rte_bswap32(l2->ip),
333 .dst_ip_mask = UINT32_MAX, /* Enable */
335 .src_ip_mask = 0, /* Disable */
337 .dst_port_mask = 0, /* Disable */
339 .src_port_mask = 0, /* Disable */
341 .proto_mask = 0, /* Disable */
343 .priority = 1, /* Lowest */
344 .queue = l1->ip_local_q,
347 return rte_eth_dev_filter_ctrl(l1->pmd_id,
348 RTE_ETH_FILTER_NTUPLE,
354 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
356 struct rte_eth_ntuple_filter filter = {
357 .flags = RTE_5TUPLE_FLAGS,
358 .dst_ip = rte_bswap32(l2->ip),
359 .dst_ip_mask = UINT32_MAX, /* Enable */
361 .src_ip_mask = 0, /* Disable */
363 .dst_port_mask = 0, /* Disable */
365 .src_port_mask = 0, /* Disable */
367 .proto_mask = 0, /* Disable */
369 .priority = 1, /* Lowest */
370 .queue = l1->ip_local_q,
373 return rte_eth_dev_filter_ctrl(l1->pmd_id,
374 RTE_ETH_FILTER_NTUPLE,
375 RTE_ETH_FILTER_DELETE,
380 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
382 struct rte_eth_ntuple_filter filter = {
383 .flags = RTE_5TUPLE_FLAGS,
384 .dst_ip = rte_bswap32(l2->ip),
385 .dst_ip_mask = UINT32_MAX, /* Enable */
387 .src_ip_mask = 0, /* Disable */
389 .dst_port_mask = 0, /* Disable */
391 .src_port_mask = 0, /* Disable */
392 .proto = IPPROTO_TCP,
393 .proto_mask = UINT8_MAX, /* Enable */
395 .priority = 2, /* Higher priority than IP */
396 .queue = l1->tcp_local_q,
399 return rte_eth_dev_filter_ctrl(l1->pmd_id,
400 RTE_ETH_FILTER_NTUPLE,
406 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
408 struct rte_eth_ntuple_filter filter = {
409 .flags = RTE_5TUPLE_FLAGS,
410 .dst_ip = rte_bswap32(l2->ip),
411 .dst_ip_mask = UINT32_MAX, /* Enable */
413 .src_ip_mask = 0, /* Disable */
415 .dst_port_mask = 0, /* Disable */
417 .src_port_mask = 0, /* Disable */
418 .proto = IPPROTO_TCP,
419 .proto_mask = UINT8_MAX, /* Enable */
421 .priority = 2, /* Higher priority than IP */
422 .queue = l1->tcp_local_q,
425 return rte_eth_dev_filter_ctrl(l1->pmd_id,
426 RTE_ETH_FILTER_NTUPLE,
427 RTE_ETH_FILTER_DELETE,
432 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
434 struct rte_eth_ntuple_filter filter = {
435 .flags = RTE_5TUPLE_FLAGS,
436 .dst_ip = rte_bswap32(l2->ip),
437 .dst_ip_mask = UINT32_MAX, /* Enable */
439 .src_ip_mask = 0, /* Disable */
441 .dst_port_mask = 0, /* Disable */
443 .src_port_mask = 0, /* Disable */
444 .proto = IPPROTO_UDP,
445 .proto_mask = UINT8_MAX, /* Enable */
447 .priority = 2, /* Higher priority than IP */
448 .queue = l1->udp_local_q,
451 return rte_eth_dev_filter_ctrl(l1->pmd_id,
452 RTE_ETH_FILTER_NTUPLE,
458 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
460 struct rte_eth_ntuple_filter filter = {
461 .flags = RTE_5TUPLE_FLAGS,
462 .dst_ip = rte_bswap32(l2->ip),
463 .dst_ip_mask = UINT32_MAX, /* Enable */
465 .src_ip_mask = 0, /* Disable */
467 .dst_port_mask = 0, /* Disable */
469 .src_port_mask = 0, /* Disable */
470 .proto = IPPROTO_UDP,
471 .proto_mask = UINT8_MAX, /* Enable */
473 .priority = 2, /* Higher priority than IP */
474 .queue = l1->udp_local_q,
477 return rte_eth_dev_filter_ctrl(l1->pmd_id,
478 RTE_ETH_FILTER_NTUPLE,
479 RTE_ETH_FILTER_DELETE,
484 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
486 struct rte_eth_ntuple_filter filter = {
487 .flags = RTE_5TUPLE_FLAGS,
488 .dst_ip = rte_bswap32(l2->ip),
489 .dst_ip_mask = UINT32_MAX, /* Enable */
491 .src_ip_mask = 0, /* Disable */
493 .dst_port_mask = 0, /* Disable */
495 .src_port_mask = 0, /* Disable */
496 .proto = IPPROTO_SCTP,
497 .proto_mask = UINT8_MAX, /* Enable */
499 .priority = 2, /* Higher priority than IP */
500 .queue = l1->sctp_local_q,
503 return rte_eth_dev_filter_ctrl(l1->pmd_id,
504 RTE_ETH_FILTER_NTUPLE,
510 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
512 struct rte_eth_ntuple_filter filter = {
513 .flags = RTE_5TUPLE_FLAGS,
514 .dst_ip = rte_bswap32(l2->ip),
515 .dst_ip_mask = UINT32_MAX, /* Enable */
517 .src_ip_mask = 0, /* Disable */
519 .dst_port_mask = 0, /* Disable */
521 .src_port_mask = 0, /* Disable */
522 .proto = IPPROTO_SCTP,
523 .proto_mask = UINT8_MAX, /* Enable */
525 .priority = 2, /* Higher priority than IP */
526 .queue = l1->sctp_local_q,
529 return rte_eth_dev_filter_ctrl(l1->pmd_id,
530 RTE_ETH_FILTER_NTUPLE,
531 RTE_ETH_FILTER_DELETE,
536 app_link_set_arp_filter(struct app_params *app, struct app_link_params *cp)
538 if (cp->arp_q != 0) {
539 int status = app_link_filter_arp_add(cp);
541 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
542 "Adding ARP filter (queue = %" PRIu32 ")",
543 cp->name, cp->pmd_id, cp->arp_q);
546 rte_panic("%s (%" PRIu32 "): "
547 "Error adding ARP filter "
548 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
549 cp->name, cp->pmd_id, cp->arp_q, status);
554 app_link_set_tcp_syn_filter(struct app_params *app, struct app_link_params *cp)
556 if (cp->tcp_syn_local_q != 0) {
557 int status = app_link_filter_tcp_syn_add(cp);
559 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
560 "Adding TCP SYN filter (queue = %" PRIu32 ")",
561 cp->name, cp->pmd_id, cp->tcp_syn_local_q);
564 rte_panic("%s (%" PRIu32 "): "
565 "Error adding TCP SYN filter "
566 "(queue = %" PRIu32 ") (%" PRId32 ")\n",
567 cp->name, cp->pmd_id, cp->tcp_syn_local_q,
573 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
578 /* For each link, add filters for IP of current link */
580 for (i = 0; i < app->n_links; i++) {
581 struct app_link_params *p = &app->link_params[i];
584 if (p->ip_local_q != 0) {
585 int status = app_link_filter_ip_add(p, cp);
587 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
588 "Adding IP filter (queue= %" PRIu32
589 ", IP = 0x%08" PRIx32 ")",
590 p->name, p->pmd_id, p->ip_local_q,
594 rte_panic("%s (%" PRIu32 "): "
596 "filter (queue= %" PRIu32 ", "
600 p->ip_local_q, cp->ip, status);
604 if (p->tcp_local_q != 0) {
605 int status = app_link_filter_tcp_add(p, cp);
607 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
610 ", IP = 0x%08" PRIx32 ")",
611 p->name, p->pmd_id, p->tcp_local_q,
615 rte_panic("%s (%" PRIu32 "): "
617 "filter (queue = %" PRIu32 ", "
621 p->tcp_local_q, cp->ip, status);
625 if (p->udp_local_q != 0) {
626 int status = app_link_filter_udp_add(p, cp);
628 APP_LOG(app, LOW, "%s (%" PRIu32 "): "
631 ", IP = 0x%08" PRIx32 ")",
632 p->name, p->pmd_id, p->udp_local_q,
636 rte_panic("%s (%" PRIu32 "): "
638 "filter (queue = %" PRIu32 ", "
642 p->udp_local_q, cp->ip, status);
646 if (p->sctp_local_q != 0) {
647 int status = app_link_filter_sctp_add(p, cp);
649 APP_LOG(app, LOW, "%s (%" PRIu32
650 "): Adding SCTP filter "
652 ", IP = 0x%08" PRIx32 ")",
653 p->name, p->pmd_id, p->sctp_local_q,
657 rte_panic("%s (%" PRIu32 "): "
659 "filter (queue = %" PRIu32 ", "
663 p->sctp_local_q, cp->ip,
670 status = rte_eth_dev_set_link_up(cp->pmd_id);
672 rte_panic("%s (%" PRIu32 "): PMD set up error %" PRId32 "\n",
673 cp->name, cp->pmd_id, status);
675 /* Mark link as UP */
680 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
685 rte_eth_dev_set_link_down(cp->pmd_id);
687 /* Mark link as DOWN */
690 /* Return if current link IP is not valid */
694 /* For each link, remove filters for IP of current link */
695 for (i = 0; i < app->n_links; i++) {
696 struct app_link_params *p = &app->link_params[i];
699 if (p->ip_local_q != 0) {
700 int status = app_link_filter_ip_del(p, cp);
702 APP_LOG(app, LOW, "%s (%" PRIu32
703 "): Deleting IP filter "
704 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
705 p->name, p->pmd_id, p->ip_local_q, cp->ip);
708 rte_panic("%s (%" PRIu32
709 "): Error deleting IP filter "
713 p->name, p->pmd_id, p->ip_local_q,
718 if (p->tcp_local_q != 0) {
719 int status = app_link_filter_tcp_del(p, cp);
721 APP_LOG(app, LOW, "%s (%" PRIu32
722 "): Deleting TCP filter "
724 ", IP = 0x%" PRIx32 ")",
725 p->name, p->pmd_id, p->tcp_local_q, cp->ip);
728 rte_panic("%s (%" PRIu32
729 "): Error deleting TCP filter "
733 p->name, p->pmd_id, p->tcp_local_q,
738 if (p->udp_local_q != 0) {
739 int status = app_link_filter_udp_del(p, cp);
741 APP_LOG(app, LOW, "%s (%" PRIu32
742 "): Deleting UDP filter "
743 "(queue = %" PRIu32 ", IP = 0x%" PRIx32 ")",
744 p->name, p->pmd_id, p->udp_local_q, cp->ip);
747 rte_panic("%s (%" PRIu32
748 "): Error deleting UDP filter "
752 p->name, p->pmd_id, p->udp_local_q,
757 if (p->sctp_local_q != 0) {
758 int status = app_link_filter_sctp_del(p, cp);
760 APP_LOG(app, LOW, "%s (%" PRIu32
761 "): Deleting SCTP filter "
763 ", IP = 0x%" PRIx32 ")",
764 p->name, p->pmd_id, p->sctp_local_q, cp->ip);
767 rte_panic("%s (%" PRIu32
768 "): Error deleting SCTP filter "
772 p->name, p->pmd_id, p->sctp_local_q,
779 app_check_link(struct app_params *app)
781 uint32_t all_links_up, i;
785 for (i = 0; i < app->n_links; i++) {
786 struct app_link_params *p = &app->link_params[i];
787 struct rte_eth_link link_params;
789 memset(&link_params, 0, sizeof(link_params));
790 rte_eth_link_get(p->pmd_id, &link_params);
792 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
795 link_params.link_speed / 1000,
796 link_params.link_status ? "UP" : "DOWN");
798 if (link_params.link_status == 0)
802 if (all_links_up == 0)
803 rte_panic("Some links are DOWN\n");
807 is_any_swq_frag_or_ras(struct app_params *app)
811 for (i = 0; i < app->n_pktq_swq; i++) {
812 struct app_pktq_swq_params *p = &app->swq_params[i];
814 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
815 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
823 app_init_link_frag_ras(struct app_params *app)
827 if (is_any_swq_frag_or_ras(app)) {
828 for (i = 0; i < app->n_pktq_hwq_out; i++) {
829 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
831 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
837 app_init_link(struct app_params *app)
841 app_init_link_frag_ras(app);
843 for (i = 0; i < app->n_links; i++) {
844 struct app_link_params *p_link = &app->link_params[i];
845 uint32_t link_id, n_hwq_in, n_hwq_out, j;
848 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
849 n_hwq_in = app_link_get_n_rxq(app, p_link);
850 n_hwq_out = app_link_get_n_txq(app, p_link);
852 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
853 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
860 status = rte_eth_dev_configure(
866 rte_panic("%s (%" PRId32 "): "
867 "init error (%" PRId32 ")\n",
868 p_link->name, p_link->pmd_id, status);
870 rte_eth_macaddr_get(p_link->pmd_id,
871 (struct ether_addr *) &p_link->mac_addr);
874 rte_eth_promiscuous_enable(p_link->pmd_id);
877 for (j = 0; j < app->n_pktq_hwq_in; j++) {
878 struct app_pktq_hwq_in_params *p_rxq =
879 &app->hwq_in_params[j];
880 uint32_t rxq_link_id, rxq_queue_id;
882 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
883 &rxq_link_id, &rxq_queue_id);
884 if (rxq_link_id != link_id)
887 status = rte_eth_rx_queue_setup(
891 rte_eth_dev_socket_id(p_link->pmd_id),
893 app->mempool[p_rxq->mempool_id]);
895 rte_panic("%s (%" PRIu32 "): "
896 "%s init error (%" PRId32 ")\n",
904 for (j = 0; j < app->n_pktq_hwq_out; j++) {
905 struct app_pktq_hwq_out_params *p_txq =
906 &app->hwq_out_params[j];
907 uint32_t txq_link_id, txq_queue_id;
909 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
910 &txq_link_id, &txq_queue_id);
911 if (txq_link_id != link_id)
914 status = rte_eth_tx_queue_setup(
918 rte_eth_dev_socket_id(p_link->pmd_id),
921 rte_panic("%s (%" PRIu32 "): "
922 "%s init error (%" PRId32 ")\n",
930 status = rte_eth_dev_start(p_link->pmd_id);
932 rte_panic("Cannot start %s (error %" PRId32 ")\n",
933 p_link->name, status);
936 app_link_set_arp_filter(app, p_link);
937 app_link_set_tcp_syn_filter(app, p_link);
938 app_link_up_internal(app, p_link);
945 app_init_swq(struct app_params *app)
949 for (i = 0; i < app->n_pktq_swq; i++) {
950 struct app_pktq_swq_params *p = &app->swq_params[i];
953 if (app_swq_get_readers(app, p) == 1)
954 flags |= RING_F_SC_DEQ;
955 if (app_swq_get_writers(app, p) == 1)
956 flags |= RING_F_SP_ENQ;
958 APP_LOG(app, HIGH, "Initializing %s...", p->name);
959 app->swq[i] = rte_ring_create(
965 if (app->swq[i] == NULL)
966 rte_panic("%s init error\n", p->name);
971 app_init_tm(struct app_params *app)
975 for (i = 0; i < app->n_pktq_tm; i++) {
976 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
977 struct app_link_params *p_link;
978 struct rte_eth_link link_eth_params;
979 struct rte_sched_port *sched;
980 uint32_t n_subports, subport_id;
983 p_link = app_get_link_for_tm(app, p_tm);
985 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
988 p_tm->sched_port_params.name = p_tm->name;
989 p_tm->sched_port_params.socket =
990 rte_eth_dev_socket_id(p_link->pmd_id);
991 p_tm->sched_port_params.rate =
992 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
994 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
995 sched = rte_sched_port_config(&p_tm->sched_port_params);
997 rte_panic("%s init error\n", p_tm->name);
1001 n_subports = p_tm->sched_port_params.n_subports_per_port;
1002 for (subport_id = 0; subport_id < n_subports; subport_id++) {
1003 uint32_t n_pipes_per_subport, pipe_id;
1005 status = rte_sched_subport_config(sched,
1007 &p_tm->sched_subport_params[subport_id]);
1009 rte_panic("%s subport %" PRIu32
1010 " init error (%" PRId32 ")\n",
1011 p_tm->name, subport_id, status);
1014 n_pipes_per_subport =
1015 p_tm->sched_port_params.n_pipes_per_subport;
1017 pipe_id < n_pipes_per_subport;
1019 int profile_id = p_tm->sched_pipe_to_profile[
1020 subport_id * APP_MAX_SCHED_PIPES +
1023 if (profile_id == -1)
1026 status = rte_sched_pipe_config(sched,
1031 rte_panic("%s subport %" PRIu32
1033 " (profile %" PRId32 ") "
1034 "init error (% " PRId32 ")\n",
1035 p_tm->name, subport_id, pipe_id,
1036 profile_id, status);
1043 app_init_msgq(struct app_params *app)
1047 for (i = 0; i < app->n_msgq; i++) {
1048 struct app_msgq_params *p = &app->msgq_params[i];
1050 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1051 app->msgq[i] = rte_ring_create(
1055 RING_F_SP_ENQ | RING_F_SC_DEQ);
1057 if (app->msgq[i] == NULL)
1058 rte_panic("%s init error\n", p->name);
1062 static void app_pipeline_params_get(struct app_params *app,
1063 struct app_pipeline_params *p_in,
1064 struct pipeline_params *p_out)
1068 strcpy(p_out->name, p_in->name);
1070 p_out->socket_id = (int) p_in->socket_id;
1072 p_out->log_level = app->log_level;
1075 p_out->n_ports_in = p_in->n_pktq_in;
1076 for (i = 0; i < p_in->n_pktq_in; i++) {
1077 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1078 struct pipeline_port_in_params *out = &p_out->port_in[i];
1081 case APP_PKTQ_IN_HWQ:
1083 struct app_pktq_hwq_in_params *p_hwq_in =
1084 &app->hwq_in_params[in->id];
1085 struct app_link_params *p_link =
1086 app_get_link_for_rxq(app, p_hwq_in);
1087 uint32_t rxq_link_id, rxq_queue_id;
1089 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1093 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1094 out->params.ethdev.port_id = p_link->pmd_id;
1095 out->params.ethdev.queue_id = rxq_queue_id;
1096 out->burst_size = p_hwq_in->burst;
1099 case APP_PKTQ_IN_SWQ:
1101 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1103 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
1104 if (app_swq_get_readers(app, swq_params) == 1) {
1105 out->type = PIPELINE_PORT_IN_RING_READER;
1106 out->params.ring.ring = app->swq[in->id];
1107 out->burst_size = app->swq_params[in->id].burst_read;
1109 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
1110 out->params.ring_multi.ring = app->swq[in->id];
1111 out->burst_size = swq_params->burst_read;
1114 if (swq_params->ipv4_frag == 1) {
1115 struct rte_port_ring_reader_ipv4_frag_params *params =
1116 &out->params.ring_ipv4_frag;
1118 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
1119 params->ring = app->swq[in->id];
1120 params->mtu = swq_params->mtu;
1121 params->metadata_size = swq_params->metadata_size;
1122 params->pool_direct =
1123 app->mempool[swq_params->mempool_direct_id];
1124 params->pool_indirect =
1125 app->mempool[swq_params->mempool_indirect_id];
1126 out->burst_size = swq_params->burst_read;
1128 struct rte_port_ring_reader_ipv6_frag_params *params =
1129 &out->params.ring_ipv6_frag;
1131 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1132 params->ring = app->swq[in->id];
1133 params->mtu = swq_params->mtu;
1134 params->metadata_size = swq_params->metadata_size;
1135 params->pool_direct =
1136 app->mempool[swq_params->mempool_direct_id];
1137 params->pool_indirect =
1138 app->mempool[swq_params->mempool_indirect_id];
1139 out->burst_size = swq_params->burst_read;
1144 case APP_PKTQ_IN_TM:
1145 out->type = PIPELINE_PORT_IN_SCHED_READER;
1146 out->params.sched.sched = app->tm[in->id];
1147 out->burst_size = app->tm_params[in->id].burst_read;
1149 case APP_PKTQ_IN_SOURCE:
1150 out->type = PIPELINE_PORT_IN_SOURCE;
1151 out->params.source.mempool = app->mempool[in->id];
1152 out->burst_size = app->source_params[in->id].burst;
1160 p_out->n_ports_out = p_in->n_pktq_out;
1161 for (i = 0; i < p_in->n_pktq_out; i++) {
1162 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1163 struct pipeline_port_out_params *out = &p_out->port_out[i];
1166 case APP_PKTQ_OUT_HWQ:
1168 struct app_pktq_hwq_out_params *p_hwq_out =
1169 &app->hwq_out_params[in->id];
1170 struct app_link_params *p_link =
1171 app_get_link_for_txq(app, p_hwq_out);
1172 uint32_t txq_link_id, txq_queue_id;
1174 sscanf(p_hwq_out->name,
1175 "TXQ%" SCNu32 ".%" SCNu32,
1179 if (p_hwq_out->dropless == 0) {
1180 struct rte_port_ethdev_writer_params *params =
1181 &out->params.ethdev;
1183 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1184 params->port_id = p_link->pmd_id;
1185 params->queue_id = txq_queue_id;
1186 params->tx_burst_sz =
1187 app->hwq_out_params[in->id].burst;
1189 struct rte_port_ethdev_writer_nodrop_params
1190 *params = &out->params.ethdev_nodrop;
1193 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1194 params->port_id = p_link->pmd_id;
1195 params->queue_id = txq_queue_id;
1196 params->tx_burst_sz = p_hwq_out->burst;
1197 params->n_retries = p_hwq_out->n_retries;
1201 case APP_PKTQ_OUT_SWQ:
1203 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1205 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1206 if (app_swq_get_writers(app, swq_params) == 1) {
1207 if (app->swq_params[in->id].dropless == 0) {
1208 struct rte_port_ring_writer_params *params =
1211 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1212 params->ring = app->swq[in->id];
1213 params->tx_burst_sz =
1214 app->swq_params[in->id].burst_write;
1216 struct rte_port_ring_writer_nodrop_params
1217 *params = &out->params.ring_nodrop;
1220 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1221 params->ring = app->swq[in->id];
1222 params->tx_burst_sz =
1223 app->swq_params[in->id].burst_write;
1225 app->swq_params[in->id].n_retries;
1228 if (swq_params->dropless == 0) {
1229 struct rte_port_ring_multi_writer_params *params =
1230 &out->params.ring_multi;
1232 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1233 params->ring = app->swq[in->id];
1234 params->tx_burst_sz = swq_params->burst_write;
1236 struct rte_port_ring_multi_writer_nodrop_params
1237 *params = &out->params.ring_multi_nodrop;
1239 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1240 params->ring = app->swq[in->id];
1241 params->tx_burst_sz = swq_params->burst_write;
1242 params->n_retries = swq_params->n_retries;
1246 if (swq_params->ipv4_ras == 1) {
1247 struct rte_port_ring_writer_ipv4_ras_params *params =
1248 &out->params.ring_ipv4_ras;
1250 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1251 params->ring = app->swq[in->id];
1252 params->tx_burst_sz = swq_params->burst_write;
1254 struct rte_port_ring_writer_ipv6_ras_params *params =
1255 &out->params.ring_ipv6_ras;
1257 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1258 params->ring = app->swq[in->id];
1259 params->tx_burst_sz = swq_params->burst_write;
1264 case APP_PKTQ_OUT_TM: {
1265 struct rte_port_sched_writer_params *params =
1268 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1269 params->sched = app->tm[in->id];
1270 params->tx_burst_sz =
1271 app->tm_params[in->id].burst_write;
1274 case APP_PKTQ_OUT_SINK:
1275 out->type = PIPELINE_PORT_OUT_SINK;
1283 p_out->n_msgq = p_in->n_msgq_in;
1285 for (i = 0; i < p_in->n_msgq_in; i++)
1286 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1288 for (i = 0; i < p_in->n_msgq_out; i++)
1289 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1292 p_out->n_args = p_in->n_args;
1293 for (i = 0; i < p_in->n_args; i++) {
1294 p_out->args_name[i] = p_in->args_name[i];
1295 p_out->args_value[i] = p_in->args_value[i];
1300 app_init_pipelines(struct app_params *app)
1304 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1305 struct app_pipeline_params *params =
1306 &app->pipeline_params[p_id];
1307 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1308 struct pipeline_type *ptype;
1309 struct pipeline_params pp;
1311 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1313 ptype = app_pipeline_type_find(app, params->type);
1315 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1318 app_pipeline_params_get(app, params, &pp);
1322 if (ptype->be_ops->f_init) {
1323 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1325 if (data->be == NULL)
1326 rte_panic("Pipeline instance \"%s\" back-end "
1327 "init error\n", params->name);
1332 if (ptype->fe_ops->f_init) {
1333 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1335 if (data->fe == NULL)
1336 rte_panic("Pipeline instance \"%s\" front-end "
1337 "init error\n", params->name);
1340 data->timer_period = (rte_get_tsc_hz() * params->timer_period)
1346 app_init_threads(struct app_params *app)
1348 uint64_t time = rte_get_tsc_cycles();
1351 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1352 struct app_pipeline_params *params =
1353 &app->pipeline_params[p_id];
1354 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1355 struct pipeline_type *ptype;
1356 struct app_thread_data *t;
1357 struct app_thread_pipeline_data *p;
1360 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1363 params->hyper_th_id);
1366 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1369 (params->hyper_th_id) ? "h" : "");
1371 t = &app->thread_data[lcore_id];
1373 ptype = app_pipeline_type_find(app, params->type);
1375 rte_panic("Init error: Unknown pipeline "
1376 "type \"%s\"\n", params->type);
1378 p = (ptype->be_ops->f_run == NULL) ?
1379 &t->regular[t->n_regular] :
1380 &t->custom[t->n_custom];
1383 p->f_run = ptype->be_ops->f_run;
1384 p->f_timer = ptype->be_ops->f_timer;
1385 p->timer_period = data->timer_period;
1386 p->deadline = time + data->timer_period;
1388 if (ptype->be_ops->f_run == NULL)
1395 int app_init(struct app_params *app)
1397 app_init_core_map(app);
1398 app_init_core_mask(app);
1401 app_init_mempool(app);
1407 app_pipeline_common_cmd_push(app);
1408 app_pipeline_type_register(app, &pipeline_master);
1409 app_pipeline_type_register(app, &pipeline_passthrough);
1410 app_pipeline_type_register(app, &pipeline_flow_classification);
1411 app_pipeline_type_register(app, &pipeline_firewall);
1412 app_pipeline_type_register(app, &pipeline_routing);
1414 app_init_pipelines(app);
1415 app_init_threads(app);
1421 app_pipeline_type_cmd_push(struct app_params *app,
1422 struct pipeline_type *ptype)
1424 cmdline_parse_ctx_t *cmds;
1427 /* Check input arguments */
1428 if ((app == NULL) ||
1432 n_cmds = pipeline_type_cmds_count(ptype);
1436 cmds = ptype->fe_ops->cmds;
1438 /* Check for available slots in the application commands array */
1439 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1442 /* Push pipeline commands into the application */
1443 memcpy(&app->cmds[app->n_cmds],
1445 n_cmds * sizeof(cmdline_parse_ctx_t *));
1447 for (i = 0; i < n_cmds; i++)
1448 app->cmds[app->n_cmds + i]->data = app;
1450 app->n_cmds += n_cmds;
1451 app->cmds[app->n_cmds] = NULL;
1457 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1461 /* Check input arguments */
1462 if ((app == NULL) ||
1464 (ptype->name == NULL) ||
1465 (strlen(ptype->name) == 0) ||
1466 (ptype->be_ops->f_init == NULL) ||
1467 (ptype->be_ops->f_timer == NULL))
1470 /* Check for duplicate entry */
1471 for (i = 0; i < app->n_pipeline_types; i++)
1472 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1475 /* Check for resource availability */
1476 n_cmds = pipeline_type_cmds_count(ptype);
1477 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1478 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1481 /* Copy pipeline type */
1482 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1484 sizeof(struct pipeline_type));
1486 /* Copy CLI commands */
1488 app_pipeline_type_cmd_push(app, ptype);
1494 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1498 for (i = 0; i < app->n_pipeline_types; i++)
1499 if (strcmp(app->pipeline_type[i].name, name) == 0)
1500 return &app->pipeline_type[i];