2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
21 #include <rte_cycles.h>
22 #include <rte_ethdev.h>
23 #include <rte_ether.h>
26 #include <rte_malloc.h>
27 #include <rte_version.h>
31 #include "pipeline_common_fe.h"
32 #include "pipeline_master.h"
33 #include "pipeline_passthrough.h"
34 #include "thread_fe.h"
35 #include "pipeline_vfw.h"
36 #include "pipeline_loadb.h"
37 #include "pipeline_txrx.h"
38 #include "pipeline_arpicmp.h"
39 #include "interface.h"
40 #include "l3fwd_common.h"
41 #include "l3fwd_lpm4.h"
42 #include "l3fwd_lpm6.h"
44 #include "vnf_define.h"
45 #define APP_NAME_SIZE 32
46 port_config_t *port_config;
49 app_init_core_map(struct app_params *app)
51 APP_LOG(app, HIGH, "Initializing CPU core map ...");
52 app->core_map = cpu_core_map_init(4, 32, 4, 0);
54 if (app->core_map == NULL)
55 rte_panic("Cannot create CPU core map\n");
57 if (app->log_level >= APP_LOG_LEVEL_LOW)
58 cpu_core_map_print(app->core_map);
61 /* Core Mask String in Hex Representation */
62 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
65 app_init_core_mask(struct app_params *app)
67 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
70 for (i = 0; i < app->n_pipelines; i++) {
71 struct app_pipeline_params *p = &app->pipeline_params[i];
74 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
80 rte_panic("Cannot create CPU core mask\n");
82 app_core_enable_in_core_mask(app, lcore_id);
85 app_core_build_core_mask_string(app, core_mask_str);
86 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
91 app_init_eal(struct app_params *app)
94 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
95 struct app_eal_params *p = &app->eal_params;
100 app->eal_argv[n_args++] = strdup(app->app_name);
102 app_core_build_core_mask_string(app, core_mask_str);
103 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
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 for (i = 0; i < APP_MAX_LINKS; i++) {
133 if (p->pci_blacklist[i] == NULL)
138 "--pci-blacklist=%s",
139 p->pci_blacklist[i]);
140 app->eal_argv[n_args++] = strdup(buffer);
143 if (app->port_mask != 0)
144 for (i = 0; i < APP_MAX_LINKS; i++) {
145 if (p->pci_whitelist[i] == NULL)
150 "--pci-whitelist=%s",
151 p->pci_whitelist[i]);
152 app->eal_argv[n_args++] = strdup(buffer);
155 for (i = 0; i < app->n_links; i++) {
156 char *pci_bdf = app->link_params[i].pci_bdf;
160 "--pci-whitelist=%s",
162 app->eal_argv[n_args++] = strdup(buffer);
165 for (i = 0; i < APP_MAX_LINKS; i++) {
166 if (p->vdev[i] == NULL)
173 app->eal_argv[n_args++] = strdup(buffer);
176 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
177 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
178 app->eal_argv[n_args++] = strdup(buffer);
186 app->eal_argv[n_args++] = strdup(buffer);
190 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
191 app->eal_argv[n_args++] = strdup(buffer);
194 if (p->log_level_present) {
197 "--log-level=%" PRIu32,
199 app->eal_argv[n_args++] = strdup(buffer);
202 if ((p->version_present) && p->version) {
203 snprintf(buffer, sizeof(buffer), "-v");
204 app->eal_argv[n_args++] = strdup(buffer);
207 if ((p->help_present) && p->help) {
208 snprintf(buffer, sizeof(buffer), "--help");
209 app->eal_argv[n_args++] = strdup(buffer);
212 if ((p->no_huge_present) && p->no_huge) {
213 snprintf(buffer, sizeof(buffer), "--no-huge");
214 app->eal_argv[n_args++] = strdup(buffer);
217 if ((p->no_pci_present) && p->no_pci) {
218 snprintf(buffer, sizeof(buffer), "--no-pci");
219 app->eal_argv[n_args++] = strdup(buffer);
222 if ((p->no_hpet_present) && p->no_hpet) {
223 snprintf(buffer, sizeof(buffer), "--no-hpet");
224 app->eal_argv[n_args++] = strdup(buffer);
227 if ((p->no_shconf_present) && p->no_shconf) {
228 snprintf(buffer, sizeof(buffer), "--no-shconf");
229 app->eal_argv[n_args++] = strdup(buffer);
233 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
234 app->eal_argv[n_args++] = strdup(buffer);
242 app->eal_argv[n_args++] = strdup(buffer);
246 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
247 app->eal_argv[n_args++] = strdup(buffer);
250 if (p->file_prefix) {
255 app->eal_argv[n_args++] = strdup(buffer);
258 if (p->base_virtaddr) {
261 "--base-virtaddr=%s",
263 app->eal_argv[n_args++] = strdup(buffer);
266 if ((p->create_uio_dev_present) && p->create_uio_dev) {
267 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
268 app->eal_argv[n_args++] = strdup(buffer);
276 app->eal_argv[n_args++] = strdup(buffer);
279 if ((p->xen_dom0_present) && (p->xen_dom0)) {
280 snprintf(buffer, sizeof(buffer), "--xen-dom0");
281 app->eal_argv[n_args++] = strdup(buffer);
284 snprintf(buffer, sizeof(buffer), "--");
285 app->eal_argv[n_args++] = strdup(buffer);
287 app->eal_argc = n_args;
289 APP_LOG(app, HIGH, "Initializing EAL ...");
290 if (app->log_level >= APP_LOG_LEVEL_LOW) {
293 fprintf(stdout, "[APP] EAL arguments: \"");
294 for (i = 1; i < app->eal_argc; i++)
295 fprintf(stdout, "%s ", app->eal_argv[i]);
296 fprintf(stdout, "\"\n");
299 status = rte_eal_init(app->eal_argc, app->eal_argv);
301 rte_panic("EAL init error\n");
304 app_link_filter_arp_add(struct app_link_params *link)
306 struct rte_eth_ethertype_filter filter = {
307 .ether_type = ETHER_TYPE_ARP,
309 .queue = link->arp_q,
312 return rte_eth_dev_filter_ctrl(link->pmd_id,
313 RTE_ETH_FILTER_ETHERTYPE,
319 app_link_filter_tcp_syn_add(struct app_link_params *link)
321 struct rte_eth_syn_filter filter = {
323 .queue = link->tcp_syn_q,
326 return rte_eth_dev_filter_ctrl(link->pmd_id,
333 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
335 struct rte_eth_ntuple_filter filter = {
336 .flags = RTE_5TUPLE_FLAGS,
337 .dst_ip = rte_bswap32(l2->ip),
338 .dst_ip_mask = UINT32_MAX, /* Enable */
340 .src_ip_mask = 0, /* Disable */
342 .dst_port_mask = 0, /* Disable */
344 .src_port_mask = 0, /* Disable */
346 .proto_mask = 0, /* Disable */
348 .priority = 1, /* Lowest */
349 .queue = l1->ip_local_q,
352 return rte_eth_dev_filter_ctrl(l1->pmd_id,
353 RTE_ETH_FILTER_NTUPLE,
359 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
361 struct rte_eth_ntuple_filter filter = {
362 .flags = RTE_5TUPLE_FLAGS,
363 .dst_ip = rte_bswap32(l2->ip),
364 .dst_ip_mask = UINT32_MAX, /* Enable */
366 .src_ip_mask = 0, /* Disable */
368 .dst_port_mask = 0, /* Disable */
370 .src_port_mask = 0, /* Disable */
372 .proto_mask = 0, /* Disable */
374 .priority = 1, /* Lowest */
375 .queue = l1->ip_local_q,
378 return rte_eth_dev_filter_ctrl(l1->pmd_id,
379 RTE_ETH_FILTER_NTUPLE,
380 RTE_ETH_FILTER_DELETE,
385 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
387 struct rte_eth_ntuple_filter filter = {
388 .flags = RTE_5TUPLE_FLAGS,
389 .dst_ip = rte_bswap32(l2->ip),
390 .dst_ip_mask = UINT32_MAX, /* Enable */
392 .src_ip_mask = 0, /* Disable */
394 .dst_port_mask = 0, /* Disable */
396 .src_port_mask = 0, /* Disable */
397 .proto = IPPROTO_TCP,
398 .proto_mask = UINT8_MAX, /* Enable */
400 .priority = 2, /* Higher priority than IP */
401 .queue = l1->tcp_local_q,
404 return rte_eth_dev_filter_ctrl(l1->pmd_id,
405 RTE_ETH_FILTER_NTUPLE,
411 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
413 struct rte_eth_ntuple_filter filter = {
414 .flags = RTE_5TUPLE_FLAGS,
415 .dst_ip = rte_bswap32(l2->ip),
416 .dst_ip_mask = UINT32_MAX, /* Enable */
418 .src_ip_mask = 0, /* Disable */
420 .dst_port_mask = 0, /* Disable */
422 .src_port_mask = 0, /* Disable */
423 .proto = IPPROTO_TCP,
424 .proto_mask = UINT8_MAX, /* Enable */
426 .priority = 2, /* Higher priority than IP */
427 .queue = l1->tcp_local_q,
430 return rte_eth_dev_filter_ctrl(l1->pmd_id,
431 RTE_ETH_FILTER_NTUPLE,
432 RTE_ETH_FILTER_DELETE,
437 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
439 struct rte_eth_ntuple_filter filter = {
440 .flags = RTE_5TUPLE_FLAGS,
441 .dst_ip = rte_bswap32(l2->ip),
442 .dst_ip_mask = UINT32_MAX, /* Enable */
444 .src_ip_mask = 0, /* Disable */
446 .dst_port_mask = 0, /* Disable */
448 .src_port_mask = 0, /* Disable */
449 .proto = IPPROTO_UDP,
450 .proto_mask = UINT8_MAX, /* Enable */
452 .priority = 2, /* Higher priority than IP */
453 .queue = l1->udp_local_q,
456 return rte_eth_dev_filter_ctrl(l1->pmd_id,
457 RTE_ETH_FILTER_NTUPLE,
463 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
465 struct rte_eth_ntuple_filter filter = {
466 .flags = RTE_5TUPLE_FLAGS,
467 .dst_ip = rte_bswap32(l2->ip),
468 .dst_ip_mask = UINT32_MAX, /* Enable */
470 .src_ip_mask = 0, /* Disable */
472 .dst_port_mask = 0, /* Disable */
474 .src_port_mask = 0, /* Disable */
475 .proto = IPPROTO_UDP,
476 .proto_mask = UINT8_MAX, /* Enable */
478 .priority = 2, /* Higher priority than IP */
479 .queue = l1->udp_local_q,
482 return rte_eth_dev_filter_ctrl(l1->pmd_id,
483 RTE_ETH_FILTER_NTUPLE,
484 RTE_ETH_FILTER_DELETE,
489 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
491 struct rte_eth_ntuple_filter filter = {
492 .flags = RTE_5TUPLE_FLAGS,
493 .dst_ip = rte_bswap32(l2->ip),
494 .dst_ip_mask = UINT32_MAX, /* Enable */
496 .src_ip_mask = 0, /* Disable */
498 .dst_port_mask = 0, /* Disable */
500 .src_port_mask = 0, /* Disable */
501 .proto = IPPROTO_SCTP,
502 .proto_mask = UINT8_MAX, /* Enable */
504 .priority = 2, /* Higher priority than IP */
505 .queue = l1->sctp_local_q,
508 return rte_eth_dev_filter_ctrl(l1->pmd_id,
509 RTE_ETH_FILTER_NTUPLE,
515 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
517 struct rte_eth_ntuple_filter filter = {
518 .flags = RTE_5TUPLE_FLAGS,
519 .dst_ip = rte_bswap32(l2->ip),
520 .dst_ip_mask = UINT32_MAX, /* Enable */
522 .src_ip_mask = 0, /* Disable */
524 .dst_port_mask = 0, /* Disable */
526 .src_port_mask = 0, /* Disable */
527 .proto = IPPROTO_SCTP,
528 .proto_mask = UINT8_MAX, /* Enable */
530 .priority = 2, /* Higher priority than IP */
531 .queue = l1->sctp_local_q,
534 return rte_eth_dev_filter_ctrl(l1->pmd_id,
535 RTE_ETH_FILTER_NTUPLE,
536 RTE_ETH_FILTER_DELETE,
540 /* rte_eth_dev is removed in DPDK version 16.11 and onwards */
541 #if RTE_VERSION < 0x100b0000
543 app_link_is_virtual(struct app_link_params *p)
545 uint32_t pmd_id = p->pmd_id;
546 struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
548 if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
556 app_link_up_internal(__rte_unused struct app_params *app,
557 struct app_link_params *cp)
559 if(app == NULL || cp == NULL)
560 printf("NULL Pointers");
562 #if RTE_VERSION < 0x100b0000
563 if (app_link_is_virtual(cp)) {
568 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_UP);
570 /* Mark link as UP */
575 app_link_down_internal(__rte_unused struct app_params *app,
576 struct app_link_params *cp)
578 if(app == NULL || cp == NULL)
579 printf("NULL Pointers");
581 #if RTE_VERSION < 0x100b0000
582 if (app_link_is_virtual(cp)) {
587 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_DOWN);
588 /* Mark link as DOWN */
594 app_check_link(struct app_params *app)
596 uint32_t all_links_up, i;
600 for (i = 0; i < app->n_links; i++) {
601 struct app_link_params *p = &app->link_params[i];
602 struct rte_eth_link link_params;
604 memset(&link_params, 0, sizeof(link_params));
605 rte_eth_link_get(p->pmd_id, &link_params);
607 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
610 link_params.link_speed / 1000,
611 link_params.link_status ? "UP" : "DOWN");
613 if (link_params.link_status == ETH_LINK_DOWN)
617 if (all_links_up == 0)
618 rte_panic("Some links are DOWN\n");
622 is_any_swq_frag_or_ras(struct app_params *app)
626 for (i = 0; i < app->n_pktq_swq; i++) {
627 struct app_pktq_swq_params *p = &app->swq_params[i];
629 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
630 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
638 app_init_link_frag_ras(struct app_params *app)
642 if (is_any_swq_frag_or_ras(app)) {
643 for (i = 0; i < app->n_pktq_hwq_out; i++) {
644 struct app_pktq_hwq_out_params *p_txq =
645 &app->hwq_out_params[i];
647 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
653 app_get_cpu_socket_id(uint32_t pmd_id)
655 int status = rte_eth_dev_socket_id(pmd_id);
657 return (status != SOCKET_ID_ANY) ? status : 0;
660 struct rte_eth_rxmode rx_mode = {
661 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
663 .header_split = 0, /**< Header Split disabled. */
664 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
665 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
666 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
667 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
668 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
669 .hw_strip_crc = 0, /**< CRC stripping by hardware disabled. */
671 struct rte_fdir_conf fdir_conf = {
672 .mode = RTE_FDIR_MODE_NONE,
673 .pballoc = RTE_FDIR_PBALLOC_64K,
674 .status = RTE_FDIR_REPORT_STATUS,
676 .vlan_tci_mask = 0x0,
678 .src_ip = 0xFFFFFFFF,
679 .dst_ip = 0xFFFFFFFF,
682 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
683 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
685 .src_port_mask = 0xFFFF,
686 .dst_port_mask = 0xFFFF,
687 .mac_addr_byte_mask = 0xFF,
688 .tunnel_type_mask = 1,
689 .tunnel_id_mask = 0xFFFFFFFF,
695 app_init_link(struct app_params *app)
699 app_init_link_frag_ras(app);
701 /* Configuring port_config_t structure for interface
702 * manager initialization
704 size = RTE_CACHE_LINE_ROUNDUP(sizeof(port_config_t));
705 port_config = rte_zmalloc(NULL, (app->n_links * size),
706 RTE_CACHE_LINE_SIZE);
707 if (port_config == NULL)
708 rte_panic("port_config is NULL: Memory Allocation failure\n");
710 for (i = 0; i < app->n_links; i++) {
711 struct app_link_params *p_link = &app->link_params[i];
712 uint32_t link_id, n_hwq_in, n_hwq_out;
715 status = sscanf(p_link->name, "LINK%" PRIu32, &link_id);
717 rte_panic("%s (%" PRId32 "): "
718 "init error (%" PRId32 ")\n",
719 p_link->name, link_id, status);
721 n_hwq_in = app_link_get_n_rxq(app, p_link);
722 n_hwq_out = app_link_get_n_txq(app, p_link);
724 printf("\n\nn_hwq_in %d\n", n_hwq_in);
725 struct rte_eth_conf *My_local_conf = &p_link->conf;
727 My_local_conf->rxmode = rx_mode;
728 My_local_conf->fdir_conf = fdir_conf;
729 My_local_conf->rxmode.mq_mode = ETH_MQ_RX_RSS;
730 My_local_conf->rx_adv_conf.rss_conf.rss_key = NULL;
731 My_local_conf->rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP
732 | ETH_RSS_UDP | ETH_RSS_TCP;
733 /* pkt-filter-mode is perfect */
734 My_local_conf->fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
737 My_local_conf->rx_adv_conf.rss_conf.rss_hf = 0;
740 /* Set the hardware CRC stripping to avoid double stripping
742 p_link->conf.rxmode.hw_strip_crc = 1;
744 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
745 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
751 port_config[i].port_id = p_link->pmd_id;
752 port_config[i].nrx_queue = n_hwq_in;
753 port_config[i].ntx_queue = n_hwq_out;
754 port_config[i].state = 1;
755 port_config[i].promisc = p_link->promisc;
756 port_config[i].mempool.pool_size =
757 app->mempool_params[0].pool_size;
758 port_config[i].mempool.buffer_size =
759 app->mempool_params[0].buffer_size;
760 port_config[i].mempool.cache_size =
761 app->mempool_params[0].cache_size;
762 port_config[i].mempool.cpu_socket_id =
763 app->mempool_params[0].cpu_socket_id;
764 memcpy(&port_config[i].port_conf, &p_link->conf,
765 sizeof(struct rte_eth_conf));
766 memcpy(&port_config[i].rx_conf, &app->hwq_in_params[0].conf,
767 sizeof(struct rte_eth_rxconf));
768 memcpy(&port_config[i].tx_conf, &app->hwq_out_params[0].conf,
769 sizeof(struct rte_eth_txconf));
771 if (app->header_csum_req) {
772 /* Enable TCP and UDP HW Checksum */
773 port_config[i].tx_conf.txq_flags &=
774 ~(ETH_TXQ_FLAGS_NOXSUMTCP |
775 ETH_TXQ_FLAGS_NOXSUMUDP);
778 if (ifm_port_setup(p_link->pmd_id, &port_config[i])) {
779 printf("Failed to configure port %s - %"PRIu32
780 ".\n", p_link->name, p_link->pmd_id);
781 printf("Try again with offload disabled....\n");
782 port_config[i].tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOOFFLOADS;
783 if (ifm_port_setup (p_link->pmd_id, &port_config[i]))
784 rte_panic("Port Setup Failed: %s - %" PRIu32
785 "\n", p_link->name, p_link->pmd_id);
788 app_link_up_internal(app, p_link);
795 app_init_swq(struct app_params *app)
799 for (i = 0; i < app->n_pktq_swq; i++) {
800 struct app_pktq_swq_params *p = &app->swq_params[i];
801 unsigned int flags = 0;
803 if (app_swq_get_readers(app, p) == 1)
804 flags |= RING_F_SC_DEQ;
805 if (app_swq_get_writers(app, p) == 1)
806 flags |= RING_F_SP_ENQ;
808 APP_LOG(app, HIGH, "Initializing %s...", p->name);
809 app->swq[i] = rte_ring_create(
815 if (app->swq[i] == NULL)
816 rte_panic("%s init error\n", p->name);
821 app_init_tm(struct app_params *app)
825 for (i = 0; i < app->n_pktq_tm; i++) {
826 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
827 struct app_link_params *p_link;
828 struct rte_eth_link link_eth_params;
829 struct rte_sched_port *sched;
830 uint32_t n_subports, subport_id;
833 p_link = app_get_link_for_tm(app, p_tm);
835 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
838 p_tm->sched_port_params.name = p_tm->name;
839 p_tm->sched_port_params.socket =
840 app_get_cpu_socket_id(p_link->pmd_id);
841 p_tm->sched_port_params.rate =
842 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
844 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
845 sched = rte_sched_port_config(&p_tm->sched_port_params);
847 rte_panic("%s init error\n", p_tm->name);
851 n_subports = p_tm->sched_port_params.n_subports_per_port;
852 for (subport_id = 0; subport_id < n_subports; subport_id++) {
853 uint32_t n_pipes_per_subport, pipe_id;
855 status = rte_sched_subport_config(sched,
857 &p_tm->sched_subport_params[subport_id]);
859 rte_panic("%s subport %" PRIu32
860 " init error (%" PRId32 ")\n",
861 p_tm->name, subport_id, status);
864 n_pipes_per_subport =
865 p_tm->sched_port_params.n_pipes_per_subport;
867 pipe_id < n_pipes_per_subport;
869 int profile_id = p_tm->sched_pipe_to_profile[
870 subport_id * APP_MAX_SCHED_PIPES +
873 if (profile_id == -1)
876 status = rte_sched_pipe_config(sched,
881 rte_panic("%s subport %" PRIu32
883 " (profile %" PRId32 ") "
884 "init error (% " PRId32 ")\n",
885 p_tm->name, subport_id, pipe_id,
893 app_init_msgq(struct app_params *app)
897 for (i = 0; i < app->n_msgq; i++) {
898 struct app_msgq_params *p = &app->msgq_params[i];
900 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
901 app->msgq[i] = rte_ring_create(
905 RING_F_SP_ENQ | RING_F_SC_DEQ);
907 if (app->msgq[i] == NULL)
908 rte_panic("%s init error\n", p->name);
912 static void app_pipeline_params_get(struct app_params *app,
913 struct app_pipeline_params *p_in,
914 struct pipeline_params *p_out)
919 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
921 p_out->socket_id = (int) p_in->socket_id;
923 p_out->log_level = app->log_level;
926 p_out->n_ports_in = p_in->n_pktq_in;
927 for (i = 0; i < p_in->n_pktq_in; i++) {
928 struct app_pktq_in_params *in = &p_in->pktq_in[i];
929 struct pipeline_port_in_params *out = &p_out->port_in[i];
932 case APP_PKTQ_IN_HWQ:
934 struct app_pktq_hwq_in_params *p_hwq_in =
935 &app->hwq_in_params[in->id];
936 struct app_link_params *p_link =
937 app_get_link_for_rxq(app, p_hwq_in);
938 uint32_t rxq_link_id, rxq_queue_id;
941 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
945 rte_panic("%s (%" PRId32 "): "
946 "init error (%" PRId32 ")\n",
947 p_hwq_in->name, rxq_link_id, status);
949 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
950 out->params.ethdev.port_id = p_link->pmd_id;
951 out->params.ethdev.queue_id = rxq_queue_id;
952 out->burst_size = p_hwq_in->burst;
955 case APP_PKTQ_IN_SWQ:
957 struct app_pktq_swq_params *swq_params =
958 &app->swq_params[in->id];
960 if ((swq_params->ipv4_frag == 0) &&
961 (swq_params->ipv6_frag == 0)) {
962 if (app_swq_get_readers(app,
965 PIPELINE_PORT_IN_RING_READER;
966 out->params.ring.ring =
969 app->swq_params[in->id].
972 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
973 out->params.ring_multi.ring = app->swq[in->id];
974 out->burst_size = swq_params->burst_read;
977 if (swq_params->ipv4_frag == 1) {
978 struct rte_port_ring_reader_ipv4_frag_params
980 &out->params.ring_ipv4_frag;
983 PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
984 params->ring = app->swq[in->id];
985 params->mtu = swq_params->mtu;
986 params->metadata_size =
987 swq_params->metadata_size;
988 params->pool_direct =
990 [swq_params->mempool_direct_id];
991 params->pool_indirect =
993 [swq_params->mempool_indirect_id];
994 out->burst_size = swq_params->burst_read;
996 struct rte_port_ring_reader_ipv6_frag_params
998 &out->params.ring_ipv6_frag;
1001 PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1002 params->ring = app->swq[in->id];
1003 params->mtu = swq_params->mtu;
1004 params->metadata_size =
1005 swq_params->metadata_size;
1006 params->pool_direct =
1008 [swq_params->mempool_direct_id];
1009 params->pool_indirect =
1011 [swq_params->mempool_indirect_id];
1012 out->burst_size = swq_params->burst_read;
1017 case APP_PKTQ_IN_TM:
1018 out->type = PIPELINE_PORT_IN_SCHED_READER;
1019 out->params.sched.sched = app->tm[in->id];
1020 out->burst_size = app->tm_params[in->id].burst_read;
1022 case APP_PKTQ_IN_SOURCE:
1023 mempool_id = app->source_params[in->id].mempool_id;
1024 out->type = PIPELINE_PORT_IN_SOURCE;
1025 out->params.source.mempool = app->mempool[mempool_id];
1026 out->burst_size = app->source_params[in->id].burst;
1029 if (app->source_params[in->id].file_name
1031 out->params.source.file_name = strdup(
1032 app->source_params[in->id].
1034 if (out->params.source.file_name == NULL) {
1036 n_bytes_per_pkt = 0;
1039 out->params.source.n_bytes_per_pkt =
1040 app->source_params[in->id].
1052 p_out->n_ports_out = p_in->n_pktq_out;
1053 for (i = 0; i < p_in->n_pktq_out; i++) {
1054 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1055 struct pipeline_port_out_params *out = &p_out->port_out[i];
1058 case APP_PKTQ_OUT_HWQ:
1060 struct app_pktq_hwq_out_params *p_hwq_out =
1061 &app->hwq_out_params[in->id];
1062 struct app_link_params *p_link =
1063 app_get_link_for_txq(app, p_hwq_out);
1064 uint32_t txq_link_id, txq_queue_id;
1067 sscanf(p_hwq_out->name,
1068 "TXQ%" SCNu32 ".%" SCNu32,
1072 rte_panic("%s (%" PRId32 "): "
1073 "init error (%" PRId32 ")\n",
1074 p_hwq_out->name, txq_link_id, status);
1076 if (p_hwq_out->dropless == 0) {
1077 struct rte_port_ethdev_writer_params *params =
1078 &out->params.ethdev;
1080 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1081 params->port_id = p_link->pmd_id;
1082 params->queue_id = txq_queue_id;
1083 params->tx_burst_sz =
1084 app->hwq_out_params[in->id].burst;
1086 struct rte_port_ethdev_writer_nodrop_params
1087 *params = &out->params.ethdev_nodrop;
1090 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1091 params->port_id = p_link->pmd_id;
1092 params->queue_id = txq_queue_id;
1093 params->tx_burst_sz = p_hwq_out->burst;
1094 params->n_retries = p_hwq_out->n_retries;
1098 case APP_PKTQ_OUT_SWQ:
1100 struct app_pktq_swq_params *swq_params =
1101 &app->swq_params[in->id];
1103 if ((swq_params->ipv4_ras == 0) &&
1104 (swq_params->ipv6_ras == 0)) {
1105 if (app_swq_get_writers(app, swq_params) == 1) {
1106 if (app->swq_params[in->id].dropless == 0) {
1107 struct rte_port_ring_writer_params
1108 *params = &out->params.ring;
1110 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1111 params->ring = app->swq[in->id];
1112 params->tx_burst_sz =
1113 app->swq_params[in->id].burst_write;
1115 struct rte_port_ring_writer_nodrop_params
1116 *params = &out->params.ring_nodrop;
1119 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1120 params->ring = app->swq[in->id];
1121 params->tx_burst_sz =
1122 app->swq_params[in->id].burst_write;
1124 app->swq_params[in->id].n_retries;
1127 if (swq_params->dropless == 0) {
1128 struct rte_port_ring_multi_writer_params
1130 &out->params.ring_multi;
1133 PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1134 params->ring = app->swq[in->id];
1135 params->tx_burst_sz = swq_params->burst_write;
1137 struct rte_port_ring_multi_writer_nodrop_params
1139 &out->params.ring_multi_nodrop;
1142 PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1144 params->ring = app->swq[in->id];
1145 params->tx_burst_sz = swq_params->burst_write;
1146 params->n_retries = swq_params->n_retries;
1150 if (swq_params->ipv4_ras == 1) {
1151 struct rte_port_ring_writer_ipv4_ras_params
1153 &out->params.ring_ipv4_ras;
1156 PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1157 params->ring = app->swq[in->id];
1158 params->tx_burst_sz = swq_params->burst_write;
1160 struct rte_port_ring_writer_ipv6_ras_params
1162 &out->params.ring_ipv6_ras;
1165 PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1166 params->ring = app->swq[in->id];
1167 params->tx_burst_sz = swq_params->burst_write;
1172 case APP_PKTQ_OUT_TM: {
1173 struct rte_port_sched_writer_params *params =
1176 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1177 params->sched = app->tm[in->id];
1178 params->tx_burst_sz =
1179 app->tm_params[in->id].burst_write;
1182 case APP_PKTQ_OUT_SINK:
1183 out->type = PIPELINE_PORT_OUT_SINK;
1184 if (app->sink_params[in->id].file_name != NULL) {
1185 out->params.sink.file_name = strdup(
1186 app->sink_params[in->id].
1188 if (out->params.sink.file_name == NULL) {
1189 out->params.sink.max_n_pkts = 0;
1192 out->params.sink.max_n_pkts =
1193 app->sink_params[in->id].
1196 out->params.sink.file_name = NULL;
1197 out->params.sink.max_n_pkts = 0;
1206 p_out->n_msgq = p_in->n_msgq_in;
1208 for (i = 0; i < p_in->n_msgq_in; i++)
1209 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1211 for (i = 0; i < p_in->n_msgq_out; i++)
1212 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1215 p_out->n_args = p_in->n_args;
1216 for (i = 0; i < p_in->n_args; i++) {
1217 p_out->args_name[i] = p_in->args_name[i];
1218 p_out->args_value[i] = p_in->args_value[i];
1223 app_init_pipelines(struct app_params *app)
1227 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1228 struct app_pipeline_params *params =
1229 &app->pipeline_params[p_id];
1230 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1231 struct pipeline_type *ptype;
1232 struct pipeline_params pp;
1234 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1236 ptype = app_pipeline_type_find(app, params->type);
1238 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1241 app_pipeline_params_get(app, params, &pp);
1245 if (ptype->be_ops->f_init) {
1246 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1248 if (data->be == NULL)
1249 rte_panic("Pipeline instance \"%s\" back-end "
1250 "init error\n", params->name);
1255 if (ptype->fe_ops->f_init) {
1256 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1258 if (data->fe == NULL)
1259 rte_panic("Pipeline instance \"%s\" front-end "
1260 "init error\n", params->name);
1263 data->ptype = ptype;
1265 data->timer_period = (rte_get_tsc_hz() *
1266 params->timer_period) / 100;
1271 app_init_threads(struct app_params *app)
1273 uint64_t time = rte_get_tsc_cycles();
1276 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1277 struct app_pipeline_params *params =
1278 &app->pipeline_params[p_id];
1279 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1280 struct pipeline_type *ptype;
1281 struct app_thread_data *t;
1282 struct app_thread_pipeline_data *p;
1285 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1288 params->hyper_th_id);
1291 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1294 (params->hyper_th_id) ? "h" : "");
1296 t = &app->thread_data[lcore_id];
1298 t->timer_period = (rte_get_tsc_hz() *
1299 APP_THREAD_TIMER_PERIOD) / DIV_CONV_HZ_SEC;
1300 t->thread_req_deadline = time + t->timer_period;
1302 t->headroom_cycles = 0;
1303 t->headroom_time = rte_get_tsc_cycles();
1304 t->headroom_ratio = 0.0;
1306 t->msgq_in = app_thread_msgq_in_get(app,
1309 params->hyper_th_id);
1310 if (t->msgq_in == NULL)
1311 rte_panic("Init error: Cannot find MSGQ_IN "
1312 "for thread %" PRId32, lcore_id);
1314 t->msgq_out = app_thread_msgq_out_get(app,
1317 params->hyper_th_id);
1318 if (t->msgq_out == NULL)
1319 rte_panic("Init error: Cannot find MSGQ_OUT "
1320 "for thread %" PRId32, lcore_id);
1322 ptype = app_pipeline_type_find(app, params->type);
1324 rte_panic("Init error: Unknown pipeline "
1325 "type \"%s\"\n", params->type);
1327 p = (ptype->be_ops->f_run == NULL) ?
1328 &t->regular[t->n_regular] :
1329 &t->custom[t->n_custom];
1331 p->pipeline_id = p_id;
1333 p->f_run = ptype->be_ops->f_run;
1334 p->f_timer = ptype->be_ops->f_timer;
1335 p->timer_period = data->timer_period;
1336 p->deadline = time + data->timer_period;
1340 if (ptype->be_ops->f_run == NULL)
1347 int app_init(struct app_params *app)
1349 app_init_core_map(app);
1350 app_init_core_mask(app);
1354 /*app_init_mempool(app);*/
1360 app_pipeline_common_cmd_push(app);
1361 app_pipeline_thread_cmd_push(app);
1362 app_pipeline_type_register(app, &pipeline_master);
1363 app_pipeline_type_register(app, &pipeline_passthrough);
1364 app_pipeline_type_register(app, &pipeline_vfw);
1365 app_pipeline_type_register(app, &pipeline_loadb);
1366 app_pipeline_type_register(app, &pipeline_txrx);
1367 app_pipeline_type_register(app, &pipeline_arpicmp);
1369 app_init_pipelines(app);
1370 app_init_threads(app);
1372 #ifdef L3_STACK_SUPPORT
1376 populate_lpm_routes();
1377 print_interface_details();
1383 app_pipeline_type_cmd_push(struct app_params *app,
1384 struct pipeline_type *ptype)
1386 cmdline_parse_ctx_t *cmds;
1389 /* Check input arguments */
1390 if ((app == NULL) ||
1394 n_cmds = pipeline_type_cmds_count(ptype);
1398 cmds = ptype->fe_ops->cmds;
1400 /* Check for available slots in the application commands array */
1401 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1404 /* Push pipeline commands into the application */
1405 memcpy(&app->cmds[app->n_cmds],
1407 n_cmds * sizeof(cmdline_parse_ctx_t));
1409 for (i = 0; i < n_cmds; i++)
1410 app->cmds[app->n_cmds + i]->data = app;
1412 app->n_cmds += n_cmds;
1413 app->cmds[app->n_cmds] = NULL;
1419 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1423 /* Check input arguments */
1424 if ((app == NULL) ||
1426 (ptype->name == NULL) ||
1427 (strlen(ptype->name) == 0) ||
1428 (ptype->be_ops->f_init == NULL) ||
1429 (ptype->be_ops->f_timer == NULL))
1432 /* Check for duplicate entry */
1433 for (i = 0; i < app->n_pipeline_types; i++)
1434 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1437 /* Check for resource availability */
1438 n_cmds = pipeline_type_cmds_count(ptype);
1439 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1440 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1443 /* Copy pipeline type */
1444 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1446 sizeof(struct pipeline_type));
1448 /* Copy CLI commands */
1450 app_pipeline_type_cmd_push(app, ptype);
1456 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1460 for (i = 0; i < app->n_pipeline_types; i++)
1461 if (strcmp(app->pipeline_type[i].name, name) == 0)
1462 return &app->pipeline_type[i];