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 app_init_link(struct app_params *app)
811 for (i = 0; i < app->n_links; i++) {
812 struct app_link_params *p_link = &app->link_params[i];
813 uint32_t link_id, n_hwq_in, n_hwq_out, j;
816 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
817 n_hwq_in = app_link_get_n_rxq(app, p_link);
818 n_hwq_out = app_link_get_n_txq(app, p_link);
820 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
821 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
828 status = rte_eth_dev_configure(
834 rte_panic("%s (%" PRId32 "): "
835 "init error (%" PRId32 ")\n",
836 p_link->name, p_link->pmd_id, status);
838 rte_eth_macaddr_get(p_link->pmd_id,
839 (struct ether_addr *) &p_link->mac_addr);
842 rte_eth_promiscuous_enable(p_link->pmd_id);
845 for (j = 0; j < app->n_pktq_hwq_in; j++) {
846 struct app_pktq_hwq_in_params *p_rxq =
847 &app->hwq_in_params[j];
848 uint32_t rxq_link_id, rxq_queue_id;
850 sscanf(p_rxq->name, "RXQ%" PRIu32 ".%" PRIu32,
851 &rxq_link_id, &rxq_queue_id);
852 if (rxq_link_id != link_id)
855 status = rte_eth_rx_queue_setup(
859 rte_eth_dev_socket_id(p_link->pmd_id),
861 app->mempool[p_rxq->mempool_id]);
863 rte_panic("%s (%" PRIu32 "): "
864 "%s init error (%" PRId32 ")\n",
872 for (j = 0; j < app->n_pktq_hwq_out; j++) {
873 struct app_pktq_hwq_out_params *p_txq =
874 &app->hwq_out_params[j];
875 uint32_t txq_link_id, txq_queue_id;
877 sscanf(p_txq->name, "TXQ%" PRIu32 ".%" PRIu32,
878 &txq_link_id, &txq_queue_id);
879 if (txq_link_id != link_id)
882 status = rte_eth_tx_queue_setup(
886 rte_eth_dev_socket_id(p_link->pmd_id),
889 rte_panic("%s (%" PRIu32 "): "
890 "%s init error (%" PRId32 ")\n",
898 status = rte_eth_dev_start(p_link->pmd_id);
900 rte_panic("Cannot start %s (error %" PRId32 ")\n",
901 p_link->name, status);
904 app_link_set_arp_filter(app, p_link);
905 app_link_set_tcp_syn_filter(app, p_link);
906 app_link_up_internal(app, p_link);
913 app_init_swq(struct app_params *app)
917 for (i = 0; i < app->n_pktq_swq; i++) {
918 struct app_pktq_swq_params *p = &app->swq_params[i];
920 APP_LOG(app, HIGH, "Initializing %s...", p->name);
921 app->swq[i] = rte_ring_create(
925 RING_F_SP_ENQ | RING_F_SC_DEQ);
927 if (app->swq[i] == NULL)
928 rte_panic("%s init error\n", p->name);
933 app_init_tm(struct app_params *app)
937 for (i = 0; i < app->n_pktq_tm; i++) {
938 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
939 struct app_link_params *p_link;
940 struct rte_eth_link link_eth_params;
941 struct rte_sched_port *sched;
942 uint32_t n_subports, subport_id;
945 p_link = app_get_link_for_tm(app, p_tm);
947 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
950 p_tm->sched_port_params.name = p_tm->name;
951 p_tm->sched_port_params.socket =
952 rte_eth_dev_socket_id(p_link->pmd_id);
953 p_tm->sched_port_params.rate =
954 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
956 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
957 sched = rte_sched_port_config(&p_tm->sched_port_params);
959 rte_panic("%s init error\n", p_tm->name);
963 n_subports = p_tm->sched_port_params.n_subports_per_port;
964 for (subport_id = 0; subport_id < n_subports; subport_id++) {
965 uint32_t n_pipes_per_subport, pipe_id;
967 status = rte_sched_subport_config(sched,
969 &p_tm->sched_subport_params[subport_id]);
971 rte_panic("%s subport %" PRIu32
972 " init error (%" PRId32 ")\n",
973 p_tm->name, subport_id, status);
976 n_pipes_per_subport =
977 p_tm->sched_port_params.n_pipes_per_subport;
979 pipe_id < n_pipes_per_subport;
981 int profile_id = p_tm->sched_pipe_to_profile[
982 subport_id * APP_MAX_SCHED_PIPES +
985 if (profile_id == -1)
988 status = rte_sched_pipe_config(sched,
993 rte_panic("%s subport %" PRIu32
995 " (profile %" PRId32 ") "
996 "init error (% " PRId32 ")\n",
997 p_tm->name, subport_id, pipe_id,
1005 app_init_msgq(struct app_params *app)
1009 for (i = 0; i < app->n_msgq; i++) {
1010 struct app_msgq_params *p = &app->msgq_params[i];
1012 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
1013 app->msgq[i] = rte_ring_create(
1017 RING_F_SP_ENQ | RING_F_SC_DEQ);
1019 if (app->msgq[i] == NULL)
1020 rte_panic("%s init error\n", p->name);
1024 static void app_pipeline_params_get(struct app_params *app,
1025 struct app_pipeline_params *p_in,
1026 struct pipeline_params *p_out)
1030 strcpy(p_out->name, p_in->name);
1032 p_out->socket_id = (int) p_in->socket_id;
1034 p_out->log_level = app->log_level;
1037 p_out->n_ports_in = p_in->n_pktq_in;
1038 for (i = 0; i < p_in->n_pktq_in; i++) {
1039 struct app_pktq_in_params *in = &p_in->pktq_in[i];
1040 struct pipeline_port_in_params *out = &p_out->port_in[i];
1043 case APP_PKTQ_IN_HWQ:
1045 struct app_pktq_hwq_in_params *p_hwq_in =
1046 &app->hwq_in_params[in->id];
1047 struct app_link_params *p_link =
1048 app_get_link_for_rxq(app, p_hwq_in);
1049 uint32_t rxq_link_id, rxq_queue_id;
1051 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
1055 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
1056 out->params.ethdev.port_id = p_link->pmd_id;
1057 out->params.ethdev.queue_id = rxq_queue_id;
1058 out->burst_size = p_hwq_in->burst;
1061 case APP_PKTQ_IN_SWQ:
1062 out->type = PIPELINE_PORT_IN_RING_READER;
1063 out->params.ring.ring = app->swq[in->id];
1064 out->burst_size = app->swq_params[in->id].burst_read;
1065 /* What about frag and ras ports? */
1067 case APP_PKTQ_IN_TM:
1068 out->type = PIPELINE_PORT_IN_SCHED_READER;
1069 out->params.sched.sched = app->tm[in->id];
1070 out->burst_size = app->tm_params[in->id].burst_read;
1072 case APP_PKTQ_IN_SOURCE:
1073 out->type = PIPELINE_PORT_IN_SOURCE;
1074 out->params.source.mempool = app->mempool[in->id];
1075 out->burst_size = app->source_params[in->id].burst;
1083 p_out->n_ports_out = p_in->n_pktq_out;
1084 for (i = 0; i < p_in->n_pktq_out; i++) {
1085 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1086 struct pipeline_port_out_params *out = &p_out->port_out[i];
1089 case APP_PKTQ_OUT_HWQ:
1091 struct app_pktq_hwq_out_params *p_hwq_out =
1092 &app->hwq_out_params[in->id];
1093 struct app_link_params *p_link =
1094 app_get_link_for_txq(app, p_hwq_out);
1095 uint32_t txq_link_id, txq_queue_id;
1097 sscanf(p_hwq_out->name,
1098 "TXQ%" SCNu32 ".%" SCNu32,
1102 if (p_hwq_out->dropless == 0) {
1103 struct rte_port_ethdev_writer_params *params =
1104 &out->params.ethdev;
1106 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1107 params->port_id = p_link->pmd_id;
1108 params->queue_id = txq_queue_id;
1109 params->tx_burst_sz =
1110 app->hwq_out_params[in->id].burst;
1112 struct rte_port_ethdev_writer_nodrop_params
1113 *params = &out->params.ethdev_nodrop;
1116 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1117 params->port_id = p_link->pmd_id;
1118 params->queue_id = txq_queue_id;
1119 params->tx_burst_sz = p_hwq_out->burst;
1120 params->n_retries = p_hwq_out->n_retries;
1124 case APP_PKTQ_OUT_SWQ:
1125 if (app->swq_params[in->id].dropless == 0) {
1126 struct rte_port_ring_writer_params *params =
1129 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1130 params->ring = app->swq[in->id];
1131 params->tx_burst_sz =
1132 app->swq_params[in->id].burst_write;
1134 struct rte_port_ring_writer_nodrop_params
1135 *params = &out->params.ring_nodrop;
1138 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1139 params->ring = app->swq[in->id];
1140 params->tx_burst_sz =
1141 app->swq_params[in->id].burst_write;
1143 app->swq_params[in->id].n_retries;
1145 /* What about frag and ras ports? */
1147 case APP_PKTQ_OUT_TM: {
1148 struct rte_port_sched_writer_params *params =
1151 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1152 params->sched = app->tm[in->id];
1153 params->tx_burst_sz =
1154 app->tm_params[in->id].burst_write;
1157 case APP_PKTQ_OUT_SINK:
1158 out->type = PIPELINE_PORT_OUT_SINK;
1166 p_out->n_msgq = p_in->n_msgq_in;
1168 for (i = 0; i < p_in->n_msgq_in; i++)
1169 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1171 for (i = 0; i < p_in->n_msgq_out; i++)
1172 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1175 p_out->n_args = p_in->n_args;
1176 for (i = 0; i < p_in->n_args; i++) {
1177 p_out->args_name[i] = p_in->args_name[i];
1178 p_out->args_value[i] = p_in->args_value[i];
1183 app_init_pipelines(struct app_params *app)
1187 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1188 struct app_pipeline_params *params =
1189 &app->pipeline_params[p_id];
1190 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1191 struct pipeline_type *ptype;
1192 struct pipeline_params pp;
1194 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1196 ptype = app_pipeline_type_find(app, params->type);
1198 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1201 app_pipeline_params_get(app, params, &pp);
1205 if (ptype->be_ops->f_init) {
1206 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1208 if (data->be == NULL)
1209 rte_panic("Pipeline instance \"%s\" back-end "
1210 "init error\n", params->name);
1215 if (ptype->fe_ops->f_init) {
1216 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1218 if (data->fe == NULL)
1219 rte_panic("Pipeline instance \"%s\" front-end "
1220 "init error\n", params->name);
1223 data->timer_period = (rte_get_tsc_hz() * params->timer_period)
1229 app_init_threads(struct app_params *app)
1231 uint64_t time = rte_get_tsc_cycles();
1234 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1235 struct app_pipeline_params *params =
1236 &app->pipeline_params[p_id];
1237 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1238 struct pipeline_type *ptype;
1239 struct app_thread_data *t;
1240 struct app_thread_pipeline_data *p;
1243 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1246 params->hyper_th_id);
1249 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1252 (params->hyper_th_id) ? "h" : "");
1254 t = &app->thread_data[lcore_id];
1256 ptype = app_pipeline_type_find(app, params->type);
1258 rte_panic("Init error: Unknown pipeline "
1259 "type \"%s\"\n", params->type);
1261 p = (ptype->be_ops->f_run == NULL) ?
1262 &t->regular[t->n_regular] :
1263 &t->custom[t->n_custom];
1266 p->f_run = ptype->be_ops->f_run;
1267 p->f_timer = ptype->be_ops->f_timer;
1268 p->timer_period = data->timer_period;
1269 p->deadline = time + data->timer_period;
1271 if (ptype->be_ops->f_run == NULL)
1278 int app_init(struct app_params *app)
1280 app_init_core_map(app);
1281 app_init_core_mask(app);
1284 app_init_mempool(app);
1290 app_pipeline_common_cmd_push(app);
1291 app_pipeline_type_register(app, &pipeline_master);
1292 app_pipeline_type_register(app, &pipeline_passthrough);
1293 app_pipeline_type_register(app, &pipeline_flow_classification);
1294 app_pipeline_type_register(app, &pipeline_firewall);
1295 app_pipeline_type_register(app, &pipeline_routing);
1297 app_init_pipelines(app);
1298 app_init_threads(app);
1304 app_pipeline_type_cmd_push(struct app_params *app,
1305 struct pipeline_type *ptype)
1307 cmdline_parse_ctx_t *cmds;
1310 /* Check input arguments */
1311 if ((app == NULL) ||
1315 n_cmds = pipeline_type_cmds_count(ptype);
1319 cmds = ptype->fe_ops->cmds;
1321 /* Check for available slots in the application commands array */
1322 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1325 /* Push pipeline commands into the application */
1326 memcpy(&app->cmds[app->n_cmds],
1328 n_cmds * sizeof(cmdline_parse_ctx_t *));
1330 for (i = 0; i < n_cmds; i++)
1331 app->cmds[app->n_cmds + i]->data = app;
1333 app->n_cmds += n_cmds;
1334 app->cmds[app->n_cmds] = NULL;
1340 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1344 /* Check input arguments */
1345 if ((app == NULL) ||
1347 (ptype->name == NULL) ||
1348 (strlen(ptype->name) == 0) ||
1349 (ptype->be_ops->f_init == NULL) ||
1350 (ptype->be_ops->f_timer == NULL))
1353 /* Check for duplicate entry */
1354 for (i = 0; i < app->n_pipeline_types; i++)
1355 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1358 /* Check for resource availability */
1359 n_cmds = pipeline_type_cmds_count(ptype);
1360 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1361 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1364 /* Copy pipeline type */
1365 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1367 sizeof(struct pipeline_type));
1369 /* Copy CLI commands */
1371 app_pipeline_type_cmd_push(app, ptype);
1377 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1381 for (i = 0; i < app->n_pipeline_types; i++)
1382 if (strcmp(app->pipeline_type[i].name, name) == 0)
1383 return &app->pipeline_type[i];