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_loadb.h"
36 #include "pipeline_arpicmp.h"
37 #include "pipeline_acl.h"
38 #include "pipeline_txrx.h"
40 #include "interface.h"
41 #include "l3fwd_common.h"
42 #include "l3fwd_lpm4.h"
43 #include "l3fwd_lpm6.h"
46 #define APP_NAME_SIZE 32
48 /* Core Mask String in Hex Representation */
49 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
51 port_config_t *port_config;
55 app_init_core_map(struct app_params *app)
57 APP_LOG(app, HIGH, "Initializing CPU core map ...");
58 app->core_map = cpu_core_map_init(4, 32, 4, 0);
60 if (app->core_map == NULL)
61 rte_panic("Cannot create CPU core map\n");
63 if (app->log_level >= APP_LOG_LEVEL_LOW)
64 cpu_core_map_print(app->core_map);
68 app_init_core_mask(struct app_params *app)
70 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
73 for (i = 0; i < app->n_pipelines; i++) {
74 struct app_pipeline_params *p = &app->pipeline_params[i];
77 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
83 rte_panic("Cannot create CPU core mask\n");
85 app_core_enable_in_core_mask(app, lcore_id);
88 app_core_build_core_mask_string(app, core_mask_str);
89 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
94 app_init_eal(struct app_params *app)
97 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
98 struct app_eal_params *p = &app->eal_params;
103 if (unlikely (n_args >= APP_EAL_ARGC))
105 app->eal_argv[n_args++] = strdup(app->app_name);
107 app_core_build_core_mask_string(app, core_mask_str);
108 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
109 if (unlikely (n_args >= APP_EAL_ARGC))
111 app->eal_argv[n_args++] = strdup(buffer);
114 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
115 if (unlikely (n_args >= APP_EAL_ARGC))
117 app->eal_argv[n_args++] = strdup(buffer);
120 if (p->master_lcore_present) {
123 "--master-lcore=%" PRIu32,
125 if (unlikely (n_args >= APP_EAL_ARGC))
127 app->eal_argv[n_args++] = strdup(buffer);
130 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
131 if (unlikely (n_args >= APP_EAL_ARGC))
133 app->eal_argv[n_args++] = strdup(buffer);
135 if (p->memory_present) {
136 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
137 if (unlikely (n_args >= APP_EAL_ARGC))
139 app->eal_argv[n_args++] = strdup(buffer);
142 if (p->ranks_present) {
143 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
144 if (unlikely (n_args >= APP_EAL_ARGC))
146 app->eal_argv[n_args++] = strdup(buffer);
149 for (i = 0; i < APP_MAX_LINKS; i++) {
150 if (p->pci_blacklist[i] == NULL)
155 "--pci-blacklist=%s",
156 p->pci_blacklist[i]);
157 if (unlikely (n_args >= APP_EAL_ARGC))
159 app->eal_argv[n_args++] = strdup(buffer);
162 if (app->port_mask != 0)
163 for (i = 0; i < APP_MAX_LINKS; i++) {
164 if (p->pci_whitelist[i] == NULL)
169 "--pci-whitelist=%s",
170 p->pci_whitelist[i]);
172 app->eal_argv[n_args++] = strdup(buffer);
175 for (i = 0; i < app->n_links; i++) {
176 char *pci_bdf = app->link_params[i].pci_bdf;
180 "--pci-whitelist=%s",
182 if (unlikely (n_args >= APP_EAL_ARGC))
184 app->eal_argv[n_args++] = strdup(buffer);
187 for (i = 0; i < APP_MAX_LINKS; i++) {
188 if (p->vdev[i] == NULL)
195 if (unlikely (n_args >= APP_EAL_ARGC))
197 app->eal_argv[n_args++] = strdup(buffer);
200 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
201 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
202 if (unlikely (n_args >= APP_EAL_ARGC))
204 app->eal_argv[n_args++] = strdup(buffer);
212 if (unlikely (n_args >= APP_EAL_ARGC))
214 app->eal_argv[n_args++] = strdup(buffer);
218 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
219 if (unlikely (n_args >= APP_EAL_ARGC))
221 app->eal_argv[n_args++] = strdup(buffer);
224 if (p->log_level_present) {
227 "--log-level=%" PRIu32,
229 if (unlikely (n_args >= APP_EAL_ARGC))
231 app->eal_argv[n_args++] = strdup(buffer);
234 if ((p->version_present) && p->version) {
235 snprintf(buffer, sizeof(buffer), "-v");
236 if (unlikely (n_args >= APP_EAL_ARGC))
238 app->eal_argv[n_args++] = strdup(buffer);
241 if ((p->help_present) && p->help) {
242 snprintf(buffer, sizeof(buffer), "--help");
243 if (unlikely (n_args >= APP_EAL_ARGC))
245 app->eal_argv[n_args++] = strdup(buffer);
248 if ((p->no_huge_present) && p->no_huge) {
249 snprintf(buffer, sizeof(buffer), "--no-huge");
250 if (unlikely (n_args >= APP_EAL_ARGC))
252 app->eal_argv[n_args++] = strdup(buffer);
255 if ((p->no_pci_present) && p->no_pci) {
256 snprintf(buffer, sizeof(buffer), "--no-pci");
257 if (unlikely (n_args >= APP_EAL_ARGC))
259 app->eal_argv[n_args++] = strdup(buffer);
262 if ((p->no_hpet_present) && p->no_hpet) {
263 snprintf(buffer, sizeof(buffer), "--no-hpet");
264 if (unlikely (n_args >= APP_EAL_ARGC))
266 app->eal_argv[n_args++] = strdup(buffer);
269 if ((p->no_shconf_present) && p->no_shconf) {
270 snprintf(buffer, sizeof(buffer), "--no-shconf");
271 if (unlikely (n_args >= APP_EAL_ARGC))
273 app->eal_argv[n_args++] = strdup(buffer);
277 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
278 if (unlikely (n_args >= APP_EAL_ARGC))
280 app->eal_argv[n_args++] = strdup(buffer);
288 if (unlikely (n_args >= APP_EAL_ARGC))
290 app->eal_argv[n_args++] = strdup(buffer);
294 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
295 if (unlikely (n_args >= APP_EAL_ARGC))
297 app->eal_argv[n_args++] = strdup(buffer);
300 if (p->file_prefix) {
305 if (unlikely (n_args >= APP_EAL_ARGC))
307 app->eal_argv[n_args++] = strdup(buffer);
310 if (p->base_virtaddr) {
313 "--base-virtaddr=%s",
315 if (unlikely (n_args >= APP_EAL_ARGC))
317 app->eal_argv[n_args++] = strdup(buffer);
320 if ((p->create_uio_dev_present) && p->create_uio_dev) {
321 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
322 if (unlikely (n_args >= APP_EAL_ARGC))
324 app->eal_argv[n_args++] = strdup(buffer);
332 if (unlikely (n_args >= APP_EAL_ARGC))
334 app->eal_argv[n_args++] = strdup(buffer);
337 if ((p->xen_dom0_present) && (p->xen_dom0)) {
338 snprintf(buffer, sizeof(buffer), "--xen-dom0");
339 if (unlikely (n_args >= APP_EAL_ARGC))
341 app->eal_argv[n_args++] = strdup(buffer);
344 snprintf(buffer, sizeof(buffer), "--");
345 if (unlikely (n_args >= APP_EAL_ARGC))
347 app->eal_argv[n_args++] = strdup(buffer);
349 app->eal_argc = n_args;
351 APP_LOG(app, HIGH, "Initializing EAL ...");
352 if (app->log_level >= APP_LOG_LEVEL_LOW) {
355 fprintf(stdout, "[APP] EAL arguments: \"");
356 for (i = 1; i < app->eal_argc; i++)
357 fprintf(stdout, "%s ", app->eal_argv[i]);
358 fprintf(stdout, "\"\n");
361 status = rte_eal_init(app->eal_argc, app->eal_argv);
364 rte_panic("EAL init error\n");
369 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
371 struct rte_eth_ntuple_filter filter = {
372 .flags = RTE_5TUPLE_FLAGS,
373 .dst_ip = rte_bswap32(l2->ip),
374 .dst_ip_mask = UINT32_MAX, /* Enable */
376 .src_ip_mask = 0, /* Disable */
378 .dst_port_mask = 0, /* Disable */
380 .src_port_mask = 0, /* Disable */
382 .proto_mask = 0, /* Disable */
384 .priority = 1, /* Lowest */
385 .queue = l1->ip_local_q,
388 return rte_eth_dev_filter_ctrl(l1->pmd_id,
389 RTE_ETH_FILTER_NTUPLE,
395 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
397 struct rte_eth_ntuple_filter filter = {
398 .flags = RTE_5TUPLE_FLAGS,
399 .dst_ip = rte_bswap32(l2->ip),
400 .dst_ip_mask = UINT32_MAX, /* Enable */
402 .src_ip_mask = 0, /* Disable */
404 .dst_port_mask = 0, /* Disable */
406 .src_port_mask = 0, /* Disable */
408 .proto_mask = 0, /* Disable */
410 .priority = 1, /* Lowest */
411 .queue = l1->ip_local_q,
414 return rte_eth_dev_filter_ctrl(l1->pmd_id,
415 RTE_ETH_FILTER_NTUPLE,
416 RTE_ETH_FILTER_DELETE,
421 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
423 struct rte_eth_ntuple_filter filter = {
424 .flags = RTE_5TUPLE_FLAGS,
425 .dst_ip = rte_bswap32(l2->ip),
426 .dst_ip_mask = UINT32_MAX, /* Enable */
428 .src_ip_mask = 0, /* Disable */
430 .dst_port_mask = 0, /* Disable */
432 .src_port_mask = 0, /* Disable */
433 .proto = IPPROTO_TCP,
434 .proto_mask = UINT8_MAX, /* Enable */
436 .priority = 2, /* Higher priority than IP */
437 .queue = l1->tcp_local_q,
440 return rte_eth_dev_filter_ctrl(l1->pmd_id,
441 RTE_ETH_FILTER_NTUPLE,
447 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
449 struct rte_eth_ntuple_filter filter = {
450 .flags = RTE_5TUPLE_FLAGS,
451 .dst_ip = rte_bswap32(l2->ip),
452 .dst_ip_mask = UINT32_MAX, /* Enable */
454 .src_ip_mask = 0, /* Disable */
456 .dst_port_mask = 0, /* Disable */
458 .src_port_mask = 0, /* Disable */
459 .proto = IPPROTO_TCP,
460 .proto_mask = UINT8_MAX, /* Enable */
462 .priority = 2, /* Higher priority than IP */
463 .queue = l1->tcp_local_q,
466 return rte_eth_dev_filter_ctrl(l1->pmd_id,
467 RTE_ETH_FILTER_NTUPLE,
468 RTE_ETH_FILTER_DELETE,
473 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
475 struct rte_eth_ntuple_filter filter = {
476 .flags = RTE_5TUPLE_FLAGS,
477 .dst_ip = rte_bswap32(l2->ip),
478 .dst_ip_mask = UINT32_MAX, /* Enable */
480 .src_ip_mask = 0, /* Disable */
482 .dst_port_mask = 0, /* Disable */
484 .src_port_mask = 0, /* Disable */
485 .proto = IPPROTO_UDP,
486 .proto_mask = UINT8_MAX, /* Enable */
488 .priority = 2, /* Higher priority than IP */
489 .queue = l1->udp_local_q,
492 return rte_eth_dev_filter_ctrl(l1->pmd_id,
493 RTE_ETH_FILTER_NTUPLE,
499 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
501 struct rte_eth_ntuple_filter filter = {
502 .flags = RTE_5TUPLE_FLAGS,
503 .dst_ip = rte_bswap32(l2->ip),
504 .dst_ip_mask = UINT32_MAX, /* Enable */
506 .src_ip_mask = 0, /* Disable */
508 .dst_port_mask = 0, /* Disable */
510 .src_port_mask = 0, /* Disable */
511 .proto = IPPROTO_UDP,
512 .proto_mask = UINT8_MAX, /* Enable */
514 .priority = 2, /* Higher priority than IP */
515 .queue = l1->udp_local_q,
518 return rte_eth_dev_filter_ctrl(l1->pmd_id,
519 RTE_ETH_FILTER_NTUPLE,
520 RTE_ETH_FILTER_DELETE,
525 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
527 struct rte_eth_ntuple_filter filter = {
528 .flags = RTE_5TUPLE_FLAGS,
529 .dst_ip = rte_bswap32(l2->ip),
530 .dst_ip_mask = UINT32_MAX, /* Enable */
532 .src_ip_mask = 0, /* Disable */
534 .dst_port_mask = 0, /* Disable */
536 .src_port_mask = 0, /* Disable */
537 .proto = IPPROTO_SCTP,
538 .proto_mask = UINT8_MAX, /* Enable */
540 .priority = 2, /* Higher priority than IP */
541 .queue = l1->sctp_local_q,
544 return rte_eth_dev_filter_ctrl(l1->pmd_id,
545 RTE_ETH_FILTER_NTUPLE,
551 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
553 struct rte_eth_ntuple_filter filter = {
554 .flags = RTE_5TUPLE_FLAGS,
555 .dst_ip = rte_bswap32(l2->ip),
556 .dst_ip_mask = UINT32_MAX, /* Enable */
558 .src_ip_mask = 0, /* Disable */
560 .dst_port_mask = 0, /* Disable */
562 .src_port_mask = 0, /* Disable */
563 .proto = IPPROTO_SCTP,
564 .proto_mask = UINT8_MAX, /* Enable */
566 .priority = 2, /* Higher priority than IP */
567 .queue = l1->sctp_local_q,
570 return rte_eth_dev_filter_ctrl(l1->pmd_id,
571 RTE_ETH_FILTER_NTUPLE,
572 RTE_ETH_FILTER_DELETE,
576 /* rte_eth_dev is removed in DPDK version 16.11 and onwards */
577 #if RTE_VERSION < 0x100b0000
579 app_link_is_virtual(struct app_link_params *p)
581 uint32_t pmd_id = p->pmd_id;
582 struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
584 if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
592 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
596 struct rte_eth_link link;
598 if(app == NULL || cp == NULL)
599 rte_panic("NULL Pointers");
601 #if RTE_VERSION < 0x100b0000
602 if (app_link_is_virtual(cp)) {
607 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_UP);
609 /* Mark link as UP */
615 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
619 struct rte_eth_link link;
621 if(app == NULL || cp == NULL)
622 rte_panic("NULL Pointers");
624 #if RTE_VERSION < 0x100b0000
625 if (app_link_is_virtual(cp)) {
631 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_DOWN);
633 /* Mark link as DOWN */
639 app_check_link(struct app_params *app)
641 uint32_t all_links_up, i;
645 for (i = 0; i < app->n_links; i++) {
646 struct app_link_params *p = &app->link_params[i];
647 struct rte_eth_link link_params;
649 memset(&link_params, 0, sizeof(link_params));
650 rte_eth_link_get(p->pmd_id, &link_params);
652 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
655 link_params.link_speed / 1000,
656 link_params.link_status ? "UP" : "DOWN");
658 if (link_params.link_status == ETH_LINK_DOWN)
662 if (all_links_up == 0)
663 rte_panic("Some links are DOWN\n");
667 is_any_swq_frag_or_ras(struct app_params *app)
671 for (i = 0; i < app->n_pktq_swq; i++) {
672 struct app_pktq_swq_params *p = &app->swq_params[i];
674 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
675 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
683 app_init_link_frag_ras(struct app_params *app)
687 if (is_any_swq_frag_or_ras(app)) {
688 for (i = 0; i < app->n_pktq_hwq_out; i++) {
689 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
691 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
697 app_get_cpu_socket_id(uint32_t pmd_id)
699 int status = rte_eth_dev_socket_id(pmd_id);
701 return (status != SOCKET_ID_ANY) ? status : 0;
703 struct rte_eth_rxmode rx_mode = {
704 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
706 .header_split = 0, /**< Header Split disabled. */
707 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
708 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
709 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
710 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
711 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
712 .hw_strip_crc = 0, /**< CRC stripping by hardware disabled. */
714 struct rte_fdir_conf fdir_conf = {
715 .mode = RTE_FDIR_MODE_NONE,
716 .pballoc = RTE_FDIR_PBALLOC_64K,
717 .status = RTE_FDIR_REPORT_STATUS,
719 .vlan_tci_mask = 0x0,
721 .src_ip = 0xFFFFFFFF,
722 .dst_ip = 0xFFFFFFFF,
725 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
727 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
730 .src_port_mask = 0xFFFF,
731 .dst_port_mask = 0xFFFF,
732 .mac_addr_byte_mask = 0xFF,
733 .tunnel_type_mask = 1,
734 .tunnel_id_mask = 0xFFFFFFFF,
739 app_init_link(struct app_params *app)
743 app_init_link_frag_ras(app);
746 *Configuring port_config_t structure for interface manager initialization
748 size = RTE_CACHE_LINE_ROUNDUP(sizeof(port_config_t));
749 port_config = rte_zmalloc(NULL, (app->n_links * size), RTE_CACHE_LINE_SIZE);
750 if (port_config == NULL)
751 rte_panic("port_config is NULL: Memory Allocation failure\n");
753 for (i = 0; i < app->n_links; i++) {
754 struct app_link_params *p_link = &app->link_params[i];
755 uint32_t link_id, n_hwq_in, n_hwq_out, j;
758 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
759 n_hwq_in = app_link_get_n_rxq(app, p_link);
760 n_hwq_out = app_link_get_n_txq(app, p_link);
761 printf("\n\nn_hwq_in %d\n", n_hwq_in);
762 struct rte_eth_conf *My_local_conf = &p_link->conf;
764 My_local_conf->rxmode = rx_mode;
765 My_local_conf->fdir_conf = fdir_conf;
766 My_local_conf->rxmode.mq_mode = ETH_MQ_RX_RSS;
767 My_local_conf->rx_adv_conf.rss_conf.rss_key = NULL;
768 My_local_conf->rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
769 /* pkt-filter-mode is perfect */
770 My_local_conf->fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
773 My_local_conf->rx_adv_conf.rss_conf.rss_hf = 0;
776 /* Set the hardware CRC stripping to avoid double stripping of FCS in VM */
777 p_link->conf.rxmode.hw_strip_crc = 1;
779 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
780 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
786 port_config[i].port_id = p_link->pmd_id;
787 port_config[i].nrx_queue = n_hwq_in;
788 port_config[i].ntx_queue = n_hwq_out;
789 port_config[i].state = 1;
790 port_config[i].promisc = p_link->promisc;
791 port_config[i].mempool.pool_size = app->mempool_params[0].pool_size;
792 port_config[i].mempool.buffer_size = app->mempool_params[0].buffer_size;
793 port_config[i].mempool.cache_size = app->mempool_params[0].cache_size;
794 port_config[i].mempool.cpu_socket_id = app->mempool_params[0].cpu_socket_id;
795 memcpy (&port_config[i].port_conf, &p_link->conf, sizeof(struct rte_eth_conf));
796 memcpy (&port_config[i].rx_conf, &app->hwq_in_params[0].conf, sizeof(struct rte_eth_rxconf));
797 memcpy (&port_config[i].tx_conf, &app->hwq_out_params[0].conf, sizeof(struct rte_eth_txconf));
799 if (app->header_csum_req) {
800 /* Enable TCP and UDP HW Checksum */
801 port_config[i].tx_conf.txq_flags &=
802 ~(ETH_TXQ_FLAGS_NOXSUMTCP|ETH_TXQ_FLAGS_NOXSUMUDP);
804 if (ifm_port_setup(p_link->pmd_id, &port_config[i])) {
805 printf("Failed to configure port %s - %"PRIu32
806 ".\n", p_link->name, p_link->pmd_id);
807 printf("Try again with offload disabled....\n");
808 port_config[i].tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOOFFLOADS;
809 if (ifm_port_setup (p_link->pmd_id, &port_config[i]))
810 rte_panic("Port Setup Failed: %s - %" PRIu32
811 "\n", p_link->name, p_link->pmd_id);
815 app_link_up_internal(app, p_link);
822 app_init_swq(struct app_params *app)
826 for (i = 0; i < app->n_pktq_swq; i++) {
827 struct app_pktq_swq_params *p = &app->swq_params[i];
828 unsigned int flags = 0;
830 if (app_swq_get_readers(app, p) == 1)
831 flags |= RING_F_SC_DEQ;
832 if (app_swq_get_writers(app, p) == 1)
833 flags |= RING_F_SP_ENQ;
835 APP_LOG(app, HIGH, "Initializing %s...", p->name);
836 app->swq[i] = rte_ring_create(
842 if (app->swq[i] == NULL)
843 rte_panic("%s init error\n", p->name);
848 app_init_tm(struct app_params *app)
852 for (i = 0; i < app->n_pktq_tm; i++) {
853 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
854 struct app_link_params *p_link;
855 struct rte_eth_link link_eth_params;
856 struct rte_sched_port *sched;
857 uint32_t n_subports, subport_id;
860 p_link = app_get_link_for_tm(app, p_tm);
862 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
865 p_tm->sched_port_params.name = p_tm->name;
866 p_tm->sched_port_params.socket =
867 app_get_cpu_socket_id(p_link->pmd_id);
868 p_tm->sched_port_params.rate =
869 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
871 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
872 sched = rte_sched_port_config(&p_tm->sched_port_params);
874 rte_panic("%s init error\n", p_tm->name);
878 n_subports = p_tm->sched_port_params.n_subports_per_port;
879 for (subport_id = 0; subport_id < n_subports; subport_id++) {
880 uint32_t n_pipes_per_subport, pipe_id;
882 status = rte_sched_subport_config(sched,
884 &p_tm->sched_subport_params[subport_id]);
886 rte_panic("%s subport %" PRIu32
887 " init error (%" PRId32 ")\n",
888 p_tm->name, subport_id, status);
891 n_pipes_per_subport =
892 p_tm->sched_port_params.n_pipes_per_subport;
894 pipe_id < n_pipes_per_subport;
896 int profile_id = p_tm->sched_pipe_to_profile[
897 subport_id * APP_MAX_SCHED_PIPES +
900 if (profile_id == -1)
903 status = rte_sched_pipe_config(sched,
908 rte_panic("%s subport %" PRIu32
910 " (profile %" PRId32 ") "
911 "init error (% " PRId32 ")\n",
912 p_tm->name, subport_id, pipe_id,
920 app_init_msgq(struct app_params *app)
924 for (i = 0; i < app->n_msgq; i++) {
925 struct app_msgq_params *p = &app->msgq_params[i];
927 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
928 app->msgq[i] = rte_ring_create(
932 RING_F_SP_ENQ | RING_F_SC_DEQ);
934 if (app->msgq[i] == NULL)
935 rte_panic("%s init error\n", p->name);
939 static void app_pipeline_params_get(struct app_params *app,
940 struct app_pipeline_params *p_in,
941 struct pipeline_params *p_out)
946 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
948 p_out->socket_id = (int) p_in->socket_id;
950 p_out->log_level = app->log_level;
953 p_out->n_ports_in = p_in->n_pktq_in;
954 for (i = 0; i < p_in->n_pktq_in; i++) {
955 struct app_pktq_in_params *in = &p_in->pktq_in[i];
956 struct pipeline_port_in_params *out = &p_out->port_in[i];
959 case APP_PKTQ_IN_HWQ:
961 struct app_pktq_hwq_in_params *p_hwq_in =
962 &app->hwq_in_params[in->id];
963 struct app_link_params *p_link =
964 app_get_link_for_rxq(app, p_hwq_in);
965 uint32_t rxq_link_id, rxq_queue_id;
967 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
971 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
972 out->params.ethdev.port_id = p_link->pmd_id;
973 out->params.ethdev.queue_id = rxq_queue_id;
974 out->burst_size = p_hwq_in->burst;
977 case APP_PKTQ_IN_SWQ:
979 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
981 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
982 if (app_swq_get_readers(app, swq_params) == 1) {
983 out->type = PIPELINE_PORT_IN_RING_READER;
984 out->params.ring.ring = app->swq[in->id];
985 out->burst_size = app->swq_params[in->id].burst_read;
987 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
988 out->params.ring_multi.ring = app->swq[in->id];
989 out->burst_size = swq_params->burst_read;
992 if (swq_params->ipv4_frag == 1) {
993 struct rte_port_ring_reader_ipv4_frag_params *params =
994 &out->params.ring_ipv4_frag;
996 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
997 params->ring = app->swq[in->id];
998 params->mtu = swq_params->mtu;
999 params->metadata_size = swq_params->metadata_size;
1000 params->pool_direct =
1001 app->mempool[swq_params->mempool_direct_id];
1002 params->pool_indirect =
1003 app->mempool[swq_params->mempool_indirect_id];
1004 out->burst_size = swq_params->burst_read;
1006 struct rte_port_ring_reader_ipv6_frag_params *params =
1007 &out->params.ring_ipv6_frag;
1009 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1010 params->ring = app->swq[in->id];
1011 params->mtu = swq_params->mtu;
1012 params->metadata_size = swq_params->metadata_size;
1013 params->pool_direct =
1014 app->mempool[swq_params->mempool_direct_id];
1015 params->pool_indirect =
1016 app->mempool[swq_params->mempool_indirect_id];
1017 out->burst_size = swq_params->burst_read;
1022 case APP_PKTQ_IN_TM:
1023 out->type = PIPELINE_PORT_IN_SCHED_READER;
1024 out->params.sched.sched = app->tm[in->id];
1025 out->burst_size = app->tm_params[in->id].burst_read;
1027 case APP_PKTQ_IN_SOURCE:
1028 mempool_id = app->source_params[in->id].mempool_id;
1029 out->type = PIPELINE_PORT_IN_SOURCE;
1030 out->params.source.mempool = app->mempool[mempool_id];
1031 out->burst_size = app->source_params[in->id].burst;
1034 if (app->source_params[in->id].file_name
1036 out->params.source.file_name = strdup(
1037 app->source_params[in->id].
1039 if (out->params.source.file_name == NULL) {
1041 n_bytes_per_pkt = 0;
1044 out->params.source.n_bytes_per_pkt =
1045 app->source_params[in->id].
1057 p_out->n_ports_out = p_in->n_pktq_out;
1058 for (i = 0; i < p_in->n_pktq_out; i++) {
1059 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1060 struct pipeline_port_out_params *out = &p_out->port_out[i];
1063 case APP_PKTQ_OUT_HWQ:
1065 struct app_pktq_hwq_out_params *p_hwq_out =
1066 &app->hwq_out_params[in->id];
1067 struct app_link_params *p_link =
1068 app_get_link_for_txq(app, p_hwq_out);
1069 uint32_t txq_link_id, txq_queue_id;
1071 sscanf(p_hwq_out->name,
1072 "TXQ%" SCNu32 ".%" SCNu32,
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 = &app->swq_params[in->id];
1102 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1103 if (app_swq_get_writers(app, swq_params) == 1) {
1104 if (app->swq_params[in->id].dropless == 0) {
1105 struct rte_port_ring_writer_params *params =
1108 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1109 params->ring = app->swq[in->id];
1110 params->tx_burst_sz =
1111 app->swq_params[in->id].burst_write;
1113 struct rte_port_ring_writer_nodrop_params
1114 *params = &out->params.ring_nodrop;
1117 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1118 params->ring = app->swq[in->id];
1119 params->tx_burst_sz =
1120 app->swq_params[in->id].burst_write;
1122 app->swq_params[in->id].n_retries;
1125 if (swq_params->dropless == 0) {
1126 struct rte_port_ring_multi_writer_params *params =
1127 &out->params.ring_multi;
1129 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1130 params->ring = app->swq[in->id];
1131 params->tx_burst_sz = swq_params->burst_write;
1133 struct rte_port_ring_multi_writer_nodrop_params
1134 *params = &out->params.ring_multi_nodrop;
1136 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1137 params->ring = app->swq[in->id];
1138 params->tx_burst_sz = swq_params->burst_write;
1139 params->n_retries = swq_params->n_retries;
1143 if (swq_params->ipv4_ras == 1) {
1144 struct rte_port_ring_writer_ipv4_ras_params *params =
1145 &out->params.ring_ipv4_ras;
1147 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1148 params->ring = app->swq[in->id];
1149 params->tx_burst_sz = swq_params->burst_write;
1151 struct rte_port_ring_writer_ipv6_ras_params *params =
1152 &out->params.ring_ipv6_ras;
1154 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1155 params->ring = app->swq[in->id];
1156 params->tx_burst_sz = swq_params->burst_write;
1161 case APP_PKTQ_OUT_TM: {
1162 struct rte_port_sched_writer_params *params =
1165 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1166 params->sched = app->tm[in->id];
1167 params->tx_burst_sz =
1168 app->tm_params[in->id].burst_write;
1171 case APP_PKTQ_OUT_SINK:
1172 out->type = PIPELINE_PORT_OUT_SINK;
1173 if (app->sink_params[in->id].file_name != NULL) {
1174 out->params.sink.file_name = strdup(
1175 app->sink_params[in->id].
1177 if (out->params.sink.file_name == NULL) {
1178 out->params.sink.max_n_pkts = 0;
1181 out->params.sink.max_n_pkts =
1182 app->sink_params[in->id].
1185 out->params.sink.file_name = NULL;
1186 out->params.sink.max_n_pkts = 0;
1195 p_out->n_msgq = p_in->n_msgq_in;
1197 for (i = 0; i < p_in->n_msgq_in; i++)
1198 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1200 for (i = 0; i < p_in->n_msgq_out; i++)
1201 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1204 p_out->n_args = p_in->n_args;
1205 for (i = 0; i < p_in->n_args; i++) {
1206 p_out->args_name[i] = p_in->args_name[i];
1207 p_out->args_value[i] = p_in->args_value[i];
1212 app_init_pipelines(struct app_params *app)
1216 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1217 struct app_pipeline_params *params =
1218 &app->pipeline_params[p_id];
1219 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1220 struct pipeline_type *ptype;
1221 struct pipeline_params pp;
1223 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1225 ptype = app_pipeline_type_find(app, params->type);
1227 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1230 app_pipeline_params_get(app, params, &pp);
1234 if (ptype->be_ops->f_init) {
1235 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1237 if (data->be == NULL)
1238 rte_panic("Pipeline instance \"%s\" back-end "
1239 "init error\n", params->name);
1244 if (ptype->fe_ops->f_init) {
1245 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1247 if (data->fe == NULL)
1248 rte_panic("Pipeline instance \"%s\" front-end "
1249 "init error\n", params->name);
1252 data->ptype = ptype;
1254 data->timer_period = (rte_get_tsc_hz() *
1255 params->timer_period) / 100;
1260 app_init_threads(struct app_params *app)
1262 uint64_t time = rte_get_tsc_cycles();
1265 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1266 struct app_pipeline_params *params =
1267 &app->pipeline_params[p_id];
1268 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1269 struct pipeline_type *ptype;
1270 struct app_thread_data *t;
1271 struct app_thread_pipeline_data *p;
1274 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1277 params->hyper_th_id);
1280 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1283 (params->hyper_th_id) ? "h" : "");
1285 t = &app->thread_data[lcore_id];
1287 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1288 t->thread_req_deadline = time + t->timer_period;
1290 t->headroom_cycles = 0;
1291 t->headroom_time = rte_get_tsc_cycles();
1292 t->headroom_ratio = 0.0;
1294 t->msgq_in = app_thread_msgq_in_get(app,
1297 params->hyper_th_id);
1298 if (t->msgq_in == NULL)
1299 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1302 t->msgq_out = app_thread_msgq_out_get(app,
1305 params->hyper_th_id);
1306 if (t->msgq_out == NULL)
1307 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1310 ptype = app_pipeline_type_find(app, params->type);
1312 rte_panic("Init error: Unknown pipeline "
1313 "type \"%s\"\n", params->type);
1315 p = (ptype->be_ops->f_run == NULL) ?
1316 &t->regular[t->n_regular] :
1317 &t->custom[t->n_custom];
1319 p->pipeline_id = p_id;
1321 p->f_run = ptype->be_ops->f_run;
1322 p->f_timer = ptype->be_ops->f_timer;
1323 p->timer_period = data->timer_period;
1324 p->deadline = time + data->timer_period;
1328 if (ptype->be_ops->f_run == NULL)
1335 int app_init(struct app_params *app)
1337 app_init_core_map(app);
1338 app_init_core_mask(app);
1344 timer_lcore = rte_lcore_id();
1351 app_pipeline_common_cmd_push(app);
1352 app_pipeline_thread_cmd_push(app);
1353 app_pipeline_type_register(app, &pipeline_master);
1354 app_pipeline_type_register(app, &pipeline_arpicmp);
1356 app_pipeline_type_register(app, &pipeline_loadb);
1357 app_pipeline_type_register(app, &pipeline_acl);
1358 app_pipeline_type_register(app, &pipeline_txrx);
1360 app_init_pipelines(app);
1361 app_init_threads(app);
1363 #ifdef L3_STACK_SUPPORT
1367 populate_lpm_routes();
1368 print_interface_details();
1375 app_pipeline_type_cmd_push(struct app_params *app,
1376 struct pipeline_type *ptype)
1378 cmdline_parse_ctx_t *cmds;
1381 /* Check input arguments */
1382 if ((app == NULL) ||
1386 n_cmds = pipeline_type_cmds_count(ptype);
1390 cmds = ptype->fe_ops->cmds;
1392 /* Check for available slots in the application commands array */
1393 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1396 /* Push pipeline commands into the application */
1397 memcpy(&app->cmds[app->n_cmds],
1399 n_cmds * sizeof(cmdline_parse_ctx_t));
1401 for (i = 0; i < n_cmds; i++)
1402 app->cmds[app->n_cmds + i]->data = app;
1404 app->n_cmds += n_cmds;
1405 app->cmds[app->n_cmds] = NULL;
1411 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1415 /* Check input arguments */
1416 if ((app == NULL) ||
1418 (ptype->name == NULL) ||
1419 (strlen(ptype->name) == 0) ||
1420 (ptype->be_ops->f_init == NULL) ||
1421 (ptype->be_ops->f_timer == NULL))
1424 /* Check for duplicate entry */
1425 for (i = 0; i < app->n_pipeline_types; i++)
1426 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1429 /* Check for resource availability */
1430 n_cmds = pipeline_type_cmds_count(ptype);
1431 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1432 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1435 /* Copy pipeline type */
1436 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1438 sizeof(struct pipeline_type));
1440 /* Copy CLI commands */
1442 app_pipeline_type_cmd_push(app, ptype);
1448 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1452 for (i = 0; i < app->n_pipeline_types; i++)
1453 if (strcmp(app->pipeline_type[i].name, name) == 0)
1454 return &app->pipeline_type[i];