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 app->eal_argv[n_args++] = strdup(app->app_name);
105 app_core_build_core_mask_string(app, core_mask_str);
106 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
107 app->eal_argv[n_args++] = strdup(buffer);
110 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
111 app->eal_argv[n_args++] = strdup(buffer);
114 if (p->master_lcore_present) {
117 "--master-lcore=%" PRIu32,
119 app->eal_argv[n_args++] = strdup(buffer);
122 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
123 app->eal_argv[n_args++] = strdup(buffer);
125 if (p->memory_present) {
126 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
127 app->eal_argv[n_args++] = strdup(buffer);
130 if (p->ranks_present) {
131 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
132 app->eal_argv[n_args++] = strdup(buffer);
135 for (i = 0; i < APP_MAX_LINKS; i++) {
136 if (p->pci_blacklist[i] == NULL)
141 "--pci-blacklist=%s",
142 p->pci_blacklist[i]);
143 app->eal_argv[n_args++] = strdup(buffer);
146 if (app->port_mask != 0)
147 for (i = 0; i < APP_MAX_LINKS; i++) {
148 if (p->pci_whitelist[i] == NULL)
153 "--pci-whitelist=%s",
154 p->pci_whitelist[i]);
156 app->eal_argv[n_args++] = strdup(buffer);
159 for (i = 0; i < app->n_links; i++) {
160 char *pci_bdf = app->link_params[i].pci_bdf;
164 "--pci-whitelist=%s",
166 app->eal_argv[n_args++] = strdup(buffer);
169 for (i = 0; i < APP_MAX_LINKS; i++) {
170 if (p->vdev[i] == NULL)
177 app->eal_argv[n_args++] = strdup(buffer);
180 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
181 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
182 app->eal_argv[n_args++] = strdup(buffer);
190 app->eal_argv[n_args++] = strdup(buffer);
194 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
195 app->eal_argv[n_args++] = strdup(buffer);
198 if (p->log_level_present) {
201 "--log-level=%" PRIu32,
203 app->eal_argv[n_args++] = strdup(buffer);
206 if ((p->version_present) && p->version) {
207 snprintf(buffer, sizeof(buffer), "-v");
208 app->eal_argv[n_args++] = strdup(buffer);
211 if ((p->help_present) && p->help) {
212 snprintf(buffer, sizeof(buffer), "--help");
213 app->eal_argv[n_args++] = strdup(buffer);
216 if ((p->no_huge_present) && p->no_huge) {
217 snprintf(buffer, sizeof(buffer), "--no-huge");
218 app->eal_argv[n_args++] = strdup(buffer);
221 if ((p->no_pci_present) && p->no_pci) {
222 snprintf(buffer, sizeof(buffer), "--no-pci");
223 app->eal_argv[n_args++] = strdup(buffer);
226 if ((p->no_hpet_present) && p->no_hpet) {
227 snprintf(buffer, sizeof(buffer), "--no-hpet");
228 app->eal_argv[n_args++] = strdup(buffer);
231 if ((p->no_shconf_present) && p->no_shconf) {
232 snprintf(buffer, sizeof(buffer), "--no-shconf");
233 app->eal_argv[n_args++] = strdup(buffer);
237 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
238 app->eal_argv[n_args++] = strdup(buffer);
246 app->eal_argv[n_args++] = strdup(buffer);
250 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
251 app->eal_argv[n_args++] = strdup(buffer);
254 if (p->file_prefix) {
259 app->eal_argv[n_args++] = strdup(buffer);
262 if (p->base_virtaddr) {
265 "--base-virtaddr=%s",
267 app->eal_argv[n_args++] = strdup(buffer);
270 if ((p->create_uio_dev_present) && p->create_uio_dev) {
271 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
272 app->eal_argv[n_args++] = strdup(buffer);
280 app->eal_argv[n_args++] = strdup(buffer);
283 if ((p->xen_dom0_present) && (p->xen_dom0)) {
284 snprintf(buffer, sizeof(buffer), "--xen-dom0");
285 app->eal_argv[n_args++] = strdup(buffer);
288 snprintf(buffer, sizeof(buffer), "--");
289 app->eal_argv[n_args++] = strdup(buffer);
291 app->eal_argc = n_args;
293 APP_LOG(app, HIGH, "Initializing EAL ...");
294 if (app->log_level >= APP_LOG_LEVEL_LOW) {
297 fprintf(stdout, "[APP] EAL arguments: \"");
298 for (i = 1; i < app->eal_argc; i++)
299 fprintf(stdout, "%s ", app->eal_argv[i]);
300 fprintf(stdout, "\"\n");
303 status = rte_eal_init(app->eal_argc, app->eal_argv);
305 rte_panic("EAL init error\n");
309 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
311 struct rte_eth_ntuple_filter filter = {
312 .flags = RTE_5TUPLE_FLAGS,
313 .dst_ip = rte_bswap32(l2->ip),
314 .dst_ip_mask = UINT32_MAX, /* Enable */
316 .src_ip_mask = 0, /* Disable */
318 .dst_port_mask = 0, /* Disable */
320 .src_port_mask = 0, /* Disable */
322 .proto_mask = 0, /* Disable */
324 .priority = 1, /* Lowest */
325 .queue = l1->ip_local_q,
328 return rte_eth_dev_filter_ctrl(l1->pmd_id,
329 RTE_ETH_FILTER_NTUPLE,
335 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
337 struct rte_eth_ntuple_filter filter = {
338 .flags = RTE_5TUPLE_FLAGS,
339 .dst_ip = rte_bswap32(l2->ip),
340 .dst_ip_mask = UINT32_MAX, /* Enable */
342 .src_ip_mask = 0, /* Disable */
344 .dst_port_mask = 0, /* Disable */
346 .src_port_mask = 0, /* Disable */
348 .proto_mask = 0, /* Disable */
350 .priority = 1, /* Lowest */
351 .queue = l1->ip_local_q,
354 return rte_eth_dev_filter_ctrl(l1->pmd_id,
355 RTE_ETH_FILTER_NTUPLE,
356 RTE_ETH_FILTER_DELETE,
361 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
363 struct rte_eth_ntuple_filter filter = {
364 .flags = RTE_5TUPLE_FLAGS,
365 .dst_ip = rte_bswap32(l2->ip),
366 .dst_ip_mask = UINT32_MAX, /* Enable */
368 .src_ip_mask = 0, /* Disable */
370 .dst_port_mask = 0, /* Disable */
372 .src_port_mask = 0, /* Disable */
373 .proto = IPPROTO_TCP,
374 .proto_mask = UINT8_MAX, /* Enable */
376 .priority = 2, /* Higher priority than IP */
377 .queue = l1->tcp_local_q,
380 return rte_eth_dev_filter_ctrl(l1->pmd_id,
381 RTE_ETH_FILTER_NTUPLE,
387 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
389 struct rte_eth_ntuple_filter filter = {
390 .flags = RTE_5TUPLE_FLAGS,
391 .dst_ip = rte_bswap32(l2->ip),
392 .dst_ip_mask = UINT32_MAX, /* Enable */
394 .src_ip_mask = 0, /* Disable */
396 .dst_port_mask = 0, /* Disable */
398 .src_port_mask = 0, /* Disable */
399 .proto = IPPROTO_TCP,
400 .proto_mask = UINT8_MAX, /* Enable */
402 .priority = 2, /* Higher priority than IP */
403 .queue = l1->tcp_local_q,
406 return rte_eth_dev_filter_ctrl(l1->pmd_id,
407 RTE_ETH_FILTER_NTUPLE,
408 RTE_ETH_FILTER_DELETE,
413 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
415 struct rte_eth_ntuple_filter filter = {
416 .flags = RTE_5TUPLE_FLAGS,
417 .dst_ip = rte_bswap32(l2->ip),
418 .dst_ip_mask = UINT32_MAX, /* Enable */
420 .src_ip_mask = 0, /* Disable */
422 .dst_port_mask = 0, /* Disable */
424 .src_port_mask = 0, /* Disable */
425 .proto = IPPROTO_UDP,
426 .proto_mask = UINT8_MAX, /* Enable */
428 .priority = 2, /* Higher priority than IP */
429 .queue = l1->udp_local_q,
432 return rte_eth_dev_filter_ctrl(l1->pmd_id,
433 RTE_ETH_FILTER_NTUPLE,
439 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
441 struct rte_eth_ntuple_filter filter = {
442 .flags = RTE_5TUPLE_FLAGS,
443 .dst_ip = rte_bswap32(l2->ip),
444 .dst_ip_mask = UINT32_MAX, /* Enable */
446 .src_ip_mask = 0, /* Disable */
448 .dst_port_mask = 0, /* Disable */
450 .src_port_mask = 0, /* Disable */
451 .proto = IPPROTO_UDP,
452 .proto_mask = UINT8_MAX, /* Enable */
454 .priority = 2, /* Higher priority than IP */
455 .queue = l1->udp_local_q,
458 return rte_eth_dev_filter_ctrl(l1->pmd_id,
459 RTE_ETH_FILTER_NTUPLE,
460 RTE_ETH_FILTER_DELETE,
465 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
467 struct rte_eth_ntuple_filter filter = {
468 .flags = RTE_5TUPLE_FLAGS,
469 .dst_ip = rte_bswap32(l2->ip),
470 .dst_ip_mask = UINT32_MAX, /* Enable */
472 .src_ip_mask = 0, /* Disable */
474 .dst_port_mask = 0, /* Disable */
476 .src_port_mask = 0, /* Disable */
477 .proto = IPPROTO_SCTP,
478 .proto_mask = UINT8_MAX, /* Enable */
480 .priority = 2, /* Higher priority than IP */
481 .queue = l1->sctp_local_q,
484 return rte_eth_dev_filter_ctrl(l1->pmd_id,
485 RTE_ETH_FILTER_NTUPLE,
491 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
493 struct rte_eth_ntuple_filter filter = {
494 .flags = RTE_5TUPLE_FLAGS,
495 .dst_ip = rte_bswap32(l2->ip),
496 .dst_ip_mask = UINT32_MAX, /* Enable */
498 .src_ip_mask = 0, /* Disable */
500 .dst_port_mask = 0, /* Disable */
502 .src_port_mask = 0, /* Disable */
503 .proto = IPPROTO_SCTP,
504 .proto_mask = UINT8_MAX, /* Enable */
506 .priority = 2, /* Higher priority than IP */
507 .queue = l1->sctp_local_q,
510 return rte_eth_dev_filter_ctrl(l1->pmd_id,
511 RTE_ETH_FILTER_NTUPLE,
512 RTE_ETH_FILTER_DELETE,
516 /* rte_eth_dev is removed in DPDK version 16.11 and onwards */
517 #if RTE_VERSION < 0x100b0000
519 app_link_is_virtual(struct app_link_params *p)
521 uint32_t pmd_id = p->pmd_id;
522 struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
524 if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
532 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
536 struct rte_eth_link link;
538 if(app == NULL || cp == NULL)
539 printf("NULL Pointers");
541 #if RTE_VERSION < 0x100b0000
542 if (app_link_is_virtual(cp)) {
547 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_UP);
549 /* Mark link as UP */
555 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
559 struct rte_eth_link link;
561 if(app == NULL || cp == NULL)
562 printf("NULL Pointers");
564 #if RTE_VERSION < 0x100b0000
565 if (app_link_is_virtual(cp)) {
571 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_DOWN);
573 /* Mark link as DOWN */
579 app_check_link(struct app_params *app)
581 uint32_t all_links_up, i;
585 for (i = 0; i < app->n_links; i++) {
586 struct app_link_params *p = &app->link_params[i];
587 struct rte_eth_link link_params;
589 memset(&link_params, 0, sizeof(link_params));
590 rte_eth_link_get(p->pmd_id, &link_params);
592 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
595 link_params.link_speed / 1000,
596 link_params.link_status ? "UP" : "DOWN");
598 if (link_params.link_status == ETH_LINK_DOWN)
602 if (all_links_up == 0)
603 rte_panic("Some links are DOWN\n");
607 is_any_swq_frag_or_ras(struct app_params *app)
611 for (i = 0; i < app->n_pktq_swq; i++) {
612 struct app_pktq_swq_params *p = &app->swq_params[i];
614 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
615 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
623 app_init_link_frag_ras(struct app_params *app)
627 if (is_any_swq_frag_or_ras(app)) {
628 for (i = 0; i < app->n_pktq_hwq_out; i++) {
629 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
631 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
637 app_get_cpu_socket_id(uint32_t pmd_id)
639 int status = rte_eth_dev_socket_id(pmd_id);
641 return (status != SOCKET_ID_ANY) ? status : 0;
643 struct rte_eth_rxmode rx_mode = {
644 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
646 .header_split = 0, /**< Header Split disabled. */
647 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
648 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
649 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
650 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
651 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
652 .hw_strip_crc = 0, /**< CRC stripping by hardware disabled. */
654 struct rte_fdir_conf fdir_conf = {
655 .mode = RTE_FDIR_MODE_NONE,
656 .pballoc = RTE_FDIR_PBALLOC_64K,
657 .status = RTE_FDIR_REPORT_STATUS,
659 .vlan_tci_mask = 0x0,
661 .src_ip = 0xFFFFFFFF,
662 .dst_ip = 0xFFFFFFFF,
665 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
667 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
670 .src_port_mask = 0xFFFF,
671 .dst_port_mask = 0xFFFF,
672 .mac_addr_byte_mask = 0xFF,
673 .tunnel_type_mask = 1,
674 .tunnel_id_mask = 0xFFFFFFFF,
679 app_init_link(struct app_params *app)
683 app_init_link_frag_ras(app);
686 *Configuring port_config_t structure for interface manager initialization
688 size = RTE_CACHE_LINE_ROUNDUP(sizeof(port_config_t));
689 port_config = rte_zmalloc(NULL, (app->n_links * size), RTE_CACHE_LINE_SIZE);
690 if (port_config == NULL)
691 rte_panic("port_config is NULL: Memory Allocation failure\n");
693 for (i = 0; i < app->n_links; i++) {
694 struct app_link_params *p_link = &app->link_params[i];
695 uint32_t link_id, n_hwq_in, n_hwq_out, j;
698 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
699 n_hwq_in = app_link_get_n_rxq(app, p_link);
700 n_hwq_out = app_link_get_n_txq(app, p_link);
701 printf("\n\nn_hwq_in %d\n", n_hwq_in);
702 struct rte_eth_conf *My_local_conf = &p_link->conf;
704 My_local_conf->rxmode = rx_mode;
705 My_local_conf->fdir_conf = fdir_conf;
706 My_local_conf->rxmode.mq_mode = ETH_MQ_RX_RSS;
707 My_local_conf->rx_adv_conf.rss_conf.rss_key = NULL;
708 My_local_conf->rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
709 } else {/* disable-rss */
710 My_local_conf->rx_adv_conf.rss_conf.rss_hf = 0;
711 /* pkt-filter-mode is perfect */
712 My_local_conf->fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
715 /* Set the hardware CRC stripping to avoid double stripping of FCS in VM */
716 p_link->conf.rxmode.hw_strip_crc = 1;
718 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
719 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
725 port_config[i].port_id = p_link->pmd_id;
726 port_config[i].nrx_queue = n_hwq_in;
727 port_config[i].ntx_queue = n_hwq_out;
728 port_config[i].state = 1;
729 port_config[i].promisc = p_link->promisc;
730 port_config[i].mempool.pool_size = app->mempool_params[0].pool_size;
731 port_config[i].mempool.buffer_size = app->mempool_params[0].buffer_size;
732 port_config[i].mempool.cache_size = app->mempool_params[0].cache_size;
733 port_config[i].mempool.cpu_socket_id = app->mempool_params[0].cpu_socket_id;
734 memcpy (&port_config[i].port_conf, &p_link->conf, sizeof(struct rte_eth_conf));
735 memcpy (&port_config[i].rx_conf, &app->hwq_in_params[0].conf, sizeof(struct rte_eth_rxconf));
736 memcpy (&port_config[i].tx_conf, &app->hwq_out_params[0].conf, sizeof(struct rte_eth_txconf));
738 if (app->header_csum_req) {
739 /* Enable TCP and UDP HW Checksum */
740 port_config[i].tx_conf.txq_flags &=
741 ~(ETH_TXQ_FLAGS_NOXSUMTCP|ETH_TXQ_FLAGS_NOXSUMUDP);
743 if (ifm_port_setup(p_link->pmd_id, &port_config[i])) {
744 printf("Failed to configure port %s - %"PRIu32
745 ".\n", p_link->name, p_link->pmd_id);
746 printf("Try again with offload disabled....\n");
747 port_config[i].tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOOFFLOADS;
748 if (ifm_port_setup (p_link->pmd_id, &port_config[i]))
749 rte_panic("Port Setup Failed: %s - %" PRIu32
750 "\n", p_link->name, p_link->pmd_id);
754 app_link_up_internal(app, p_link);
761 app_init_swq(struct app_params *app)
765 for (i = 0; i < app->n_pktq_swq; i++) {
766 struct app_pktq_swq_params *p = &app->swq_params[i];
767 unsigned int flags = 0;
769 if (app_swq_get_readers(app, p) == 1)
770 flags |= RING_F_SC_DEQ;
771 if (app_swq_get_writers(app, p) == 1)
772 flags |= RING_F_SP_ENQ;
774 APP_LOG(app, HIGH, "Initializing %s...", p->name);
775 app->swq[i] = rte_ring_create(
781 if (app->swq[i] == NULL)
782 rte_panic("%s init error\n", p->name);
787 app_init_tm(struct app_params *app)
791 for (i = 0; i < app->n_pktq_tm; i++) {
792 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
793 struct app_link_params *p_link;
794 struct rte_eth_link link_eth_params;
795 struct rte_sched_port *sched;
796 uint32_t n_subports, subport_id;
799 p_link = app_get_link_for_tm(app, p_tm);
801 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
804 p_tm->sched_port_params.name = p_tm->name;
805 p_tm->sched_port_params.socket =
806 app_get_cpu_socket_id(p_link->pmd_id);
807 p_tm->sched_port_params.rate =
808 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
810 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
811 sched = rte_sched_port_config(&p_tm->sched_port_params);
813 rte_panic("%s init error\n", p_tm->name);
817 n_subports = p_tm->sched_port_params.n_subports_per_port;
818 for (subport_id = 0; subport_id < n_subports; subport_id++) {
819 uint32_t n_pipes_per_subport, pipe_id;
821 status = rte_sched_subport_config(sched,
823 &p_tm->sched_subport_params[subport_id]);
825 rte_panic("%s subport %" PRIu32
826 " init error (%" PRId32 ")\n",
827 p_tm->name, subport_id, status);
830 n_pipes_per_subport =
831 p_tm->sched_port_params.n_pipes_per_subport;
833 pipe_id < n_pipes_per_subport;
835 int profile_id = p_tm->sched_pipe_to_profile[
836 subport_id * APP_MAX_SCHED_PIPES +
839 if (profile_id == -1)
842 status = rte_sched_pipe_config(sched,
847 rte_panic("%s subport %" PRIu32
849 " (profile %" PRId32 ") "
850 "init error (% " PRId32 ")\n",
851 p_tm->name, subport_id, pipe_id,
859 app_init_msgq(struct app_params *app)
863 for (i = 0; i < app->n_msgq; i++) {
864 struct app_msgq_params *p = &app->msgq_params[i];
866 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
867 app->msgq[i] = rte_ring_create(
871 RING_F_SP_ENQ | RING_F_SC_DEQ);
873 if (app->msgq[i] == NULL)
874 rte_panic("%s init error\n", p->name);
878 static void app_pipeline_params_get(struct app_params *app,
879 struct app_pipeline_params *p_in,
880 struct pipeline_params *p_out)
885 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
887 p_out->socket_id = (int) p_in->socket_id;
889 p_out->log_level = app->log_level;
892 p_out->n_ports_in = p_in->n_pktq_in;
893 for (i = 0; i < p_in->n_pktq_in; i++) {
894 struct app_pktq_in_params *in = &p_in->pktq_in[i];
895 struct pipeline_port_in_params *out = &p_out->port_in[i];
898 case APP_PKTQ_IN_HWQ:
900 struct app_pktq_hwq_in_params *p_hwq_in =
901 &app->hwq_in_params[in->id];
902 struct app_link_params *p_link =
903 app_get_link_for_rxq(app, p_hwq_in);
904 uint32_t rxq_link_id, rxq_queue_id;
906 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
910 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
911 out->params.ethdev.port_id = p_link->pmd_id;
912 out->params.ethdev.queue_id = rxq_queue_id;
913 out->burst_size = p_hwq_in->burst;
916 case APP_PKTQ_IN_SWQ:
918 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
920 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
921 if (app_swq_get_readers(app, swq_params) == 1) {
922 out->type = PIPELINE_PORT_IN_RING_READER;
923 out->params.ring.ring = app->swq[in->id];
924 out->burst_size = app->swq_params[in->id].burst_read;
926 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
927 out->params.ring_multi.ring = app->swq[in->id];
928 out->burst_size = swq_params->burst_read;
931 if (swq_params->ipv4_frag == 1) {
932 struct rte_port_ring_reader_ipv4_frag_params *params =
933 &out->params.ring_ipv4_frag;
935 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
936 params->ring = app->swq[in->id];
937 params->mtu = swq_params->mtu;
938 params->metadata_size = swq_params->metadata_size;
939 params->pool_direct =
940 app->mempool[swq_params->mempool_direct_id];
941 params->pool_indirect =
942 app->mempool[swq_params->mempool_indirect_id];
943 out->burst_size = swq_params->burst_read;
945 struct rte_port_ring_reader_ipv6_frag_params *params =
946 &out->params.ring_ipv6_frag;
948 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
949 params->ring = app->swq[in->id];
950 params->mtu = swq_params->mtu;
951 params->metadata_size = swq_params->metadata_size;
952 params->pool_direct =
953 app->mempool[swq_params->mempool_direct_id];
954 params->pool_indirect =
955 app->mempool[swq_params->mempool_indirect_id];
956 out->burst_size = swq_params->burst_read;
962 out->type = PIPELINE_PORT_IN_SCHED_READER;
963 out->params.sched.sched = app->tm[in->id];
964 out->burst_size = app->tm_params[in->id].burst_read;
966 case APP_PKTQ_IN_SOURCE:
967 mempool_id = app->source_params[in->id].mempool_id;
968 out->type = PIPELINE_PORT_IN_SOURCE;
969 out->params.source.mempool = app->mempool[mempool_id];
970 out->burst_size = app->source_params[in->id].burst;
973 if (app->source_params[in->id].file_name
975 out->params.source.file_name = strdup(
976 app->source_params[in->id].
978 if (out->params.source.file_name == NULL) {
983 out->params.source.n_bytes_per_pkt =
984 app->source_params[in->id].
996 p_out->n_ports_out = p_in->n_pktq_out;
997 for (i = 0; i < p_in->n_pktq_out; i++) {
998 struct app_pktq_out_params *in = &p_in->pktq_out[i];
999 struct pipeline_port_out_params *out = &p_out->port_out[i];
1002 case APP_PKTQ_OUT_HWQ:
1004 struct app_pktq_hwq_out_params *p_hwq_out =
1005 &app->hwq_out_params[in->id];
1006 struct app_link_params *p_link =
1007 app_get_link_for_txq(app, p_hwq_out);
1008 uint32_t txq_link_id, txq_queue_id;
1010 sscanf(p_hwq_out->name,
1011 "TXQ%" SCNu32 ".%" SCNu32,
1015 if (p_hwq_out->dropless == 0) {
1016 struct rte_port_ethdev_writer_params *params =
1017 &out->params.ethdev;
1019 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1020 params->port_id = p_link->pmd_id;
1021 params->queue_id = txq_queue_id;
1022 params->tx_burst_sz =
1023 app->hwq_out_params[in->id].burst;
1025 struct rte_port_ethdev_writer_nodrop_params
1026 *params = &out->params.ethdev_nodrop;
1029 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1030 params->port_id = p_link->pmd_id;
1031 params->queue_id = txq_queue_id;
1032 params->tx_burst_sz = p_hwq_out->burst;
1033 params->n_retries = p_hwq_out->n_retries;
1037 case APP_PKTQ_OUT_SWQ:
1039 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1041 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1042 if (app_swq_get_writers(app, swq_params) == 1) {
1043 if (app->swq_params[in->id].dropless == 0) {
1044 struct rte_port_ring_writer_params *params =
1047 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1048 params->ring = app->swq[in->id];
1049 params->tx_burst_sz =
1050 app->swq_params[in->id].burst_write;
1052 struct rte_port_ring_writer_nodrop_params
1053 *params = &out->params.ring_nodrop;
1056 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1057 params->ring = app->swq[in->id];
1058 params->tx_burst_sz =
1059 app->swq_params[in->id].burst_write;
1061 app->swq_params[in->id].n_retries;
1064 if (swq_params->dropless == 0) {
1065 struct rte_port_ring_multi_writer_params *params =
1066 &out->params.ring_multi;
1068 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1069 params->ring = app->swq[in->id];
1070 params->tx_burst_sz = swq_params->burst_write;
1072 struct rte_port_ring_multi_writer_nodrop_params
1073 *params = &out->params.ring_multi_nodrop;
1075 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1076 params->ring = app->swq[in->id];
1077 params->tx_burst_sz = swq_params->burst_write;
1078 params->n_retries = swq_params->n_retries;
1082 if (swq_params->ipv4_ras == 1) {
1083 struct rte_port_ring_writer_ipv4_ras_params *params =
1084 &out->params.ring_ipv4_ras;
1086 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1087 params->ring = app->swq[in->id];
1088 params->tx_burst_sz = swq_params->burst_write;
1090 struct rte_port_ring_writer_ipv6_ras_params *params =
1091 &out->params.ring_ipv6_ras;
1093 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1094 params->ring = app->swq[in->id];
1095 params->tx_burst_sz = swq_params->burst_write;
1100 case APP_PKTQ_OUT_TM: {
1101 struct rte_port_sched_writer_params *params =
1104 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1105 params->sched = app->tm[in->id];
1106 params->tx_burst_sz =
1107 app->tm_params[in->id].burst_write;
1110 case APP_PKTQ_OUT_SINK:
1111 out->type = PIPELINE_PORT_OUT_SINK;
1112 if (app->sink_params[in->id].file_name != NULL) {
1113 out->params.sink.file_name = strdup(
1114 app->sink_params[in->id].
1116 if (out->params.sink.file_name == NULL) {
1117 out->params.sink.max_n_pkts = 0;
1120 out->params.sink.max_n_pkts =
1121 app->sink_params[in->id].
1124 out->params.sink.file_name = NULL;
1125 out->params.sink.max_n_pkts = 0;
1134 p_out->n_msgq = p_in->n_msgq_in;
1136 for (i = 0; i < p_in->n_msgq_in; i++)
1137 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1139 for (i = 0; i < p_in->n_msgq_out; i++)
1140 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1143 p_out->n_args = p_in->n_args;
1144 for (i = 0; i < p_in->n_args; i++) {
1145 p_out->args_name[i] = p_in->args_name[i];
1146 p_out->args_value[i] = p_in->args_value[i];
1151 app_init_pipelines(struct app_params *app)
1155 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1156 struct app_pipeline_params *params =
1157 &app->pipeline_params[p_id];
1158 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1159 struct pipeline_type *ptype;
1160 struct pipeline_params pp;
1162 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1164 ptype = app_pipeline_type_find(app, params->type);
1166 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1169 app_pipeline_params_get(app, params, &pp);
1173 if (ptype->be_ops->f_init) {
1174 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1176 if (data->be == NULL)
1177 rte_panic("Pipeline instance \"%s\" back-end "
1178 "init error\n", params->name);
1183 if (ptype->fe_ops->f_init) {
1184 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1186 if (data->fe == NULL)
1187 rte_panic("Pipeline instance \"%s\" front-end "
1188 "init error\n", params->name);
1191 data->ptype = ptype;
1193 data->timer_period = (rte_get_tsc_hz() *
1194 params->timer_period) / 100;
1199 app_init_threads(struct app_params *app)
1201 uint64_t time = rte_get_tsc_cycles();
1204 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1205 struct app_pipeline_params *params =
1206 &app->pipeline_params[p_id];
1207 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1208 struct pipeline_type *ptype;
1209 struct app_thread_data *t;
1210 struct app_thread_pipeline_data *p;
1213 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1216 params->hyper_th_id);
1219 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1222 (params->hyper_th_id) ? "h" : "");
1224 t = &app->thread_data[lcore_id];
1226 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1227 t->thread_req_deadline = time + t->timer_period;
1229 t->headroom_cycles = 0;
1230 t->headroom_time = rte_get_tsc_cycles();
1231 t->headroom_ratio = 0.0;
1233 t->msgq_in = app_thread_msgq_in_get(app,
1236 params->hyper_th_id);
1237 if (t->msgq_in == NULL)
1238 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1241 t->msgq_out = app_thread_msgq_out_get(app,
1244 params->hyper_th_id);
1245 if (t->msgq_out == NULL)
1246 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1249 ptype = app_pipeline_type_find(app, params->type);
1251 rte_panic("Init error: Unknown pipeline "
1252 "type \"%s\"\n", params->type);
1254 p = (ptype->be_ops->f_run == NULL) ?
1255 &t->regular[t->n_regular] :
1256 &t->custom[t->n_custom];
1258 p->pipeline_id = p_id;
1260 p->f_run = ptype->be_ops->f_run;
1261 p->f_timer = ptype->be_ops->f_timer;
1262 p->timer_period = data->timer_period;
1263 p->deadline = time + data->timer_period;
1267 if (ptype->be_ops->f_run == NULL)
1274 int app_init(struct app_params *app)
1276 app_init_core_map(app);
1277 app_init_core_mask(app);
1283 timer_lcore = rte_lcore_id();
1290 app_pipeline_common_cmd_push(app);
1291 app_pipeline_thread_cmd_push(app);
1292 app_pipeline_type_register(app, &pipeline_master);
1293 app_pipeline_type_register(app, &pipeline_arpicmp);
1295 app_pipeline_type_register(app, &pipeline_loadb);
1296 app_pipeline_type_register(app, &pipeline_acl);
1297 app_pipeline_type_register(app, &pipeline_txrx);
1299 app_init_pipelines(app);
1300 app_init_threads(app);
1305 populate_lpm_routes();
1306 print_interface_details();
1312 app_pipeline_type_cmd_push(struct app_params *app,
1313 struct pipeline_type *ptype)
1315 cmdline_parse_ctx_t *cmds;
1318 /* Check input arguments */
1319 if ((app == NULL) ||
1323 n_cmds = pipeline_type_cmds_count(ptype);
1327 cmds = ptype->fe_ops->cmds;
1329 /* Check for available slots in the application commands array */
1330 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1333 /* Push pipeline commands into the application */
1334 memcpy(&app->cmds[app->n_cmds],
1336 n_cmds * sizeof(cmdline_parse_ctx_t));
1338 for (i = 0; i < n_cmds; i++)
1339 app->cmds[app->n_cmds + i]->data = app;
1341 app->n_cmds += n_cmds;
1342 app->cmds[app->n_cmds] = NULL;
1348 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1352 /* Check input arguments */
1353 if ((app == NULL) ||
1355 (ptype->name == NULL) ||
1356 (strlen(ptype->name) == 0) ||
1357 (ptype->be_ops->f_init == NULL) ||
1358 (ptype->be_ops->f_timer == NULL))
1361 /* Check for duplicate entry */
1362 for (i = 0; i < app->n_pipeline_types; i++)
1363 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1366 /* Check for resource availability */
1367 n_cmds = pipeline_type_cmds_count(ptype);
1368 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1369 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1372 /* Copy pipeline type */
1373 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1375 sizeof(struct pipeline_type));
1377 /* Copy CLI commands */
1379 app_pipeline_type_cmd_push(app, ptype);
1385 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1389 for (i = 0; i < app->n_pipeline_types; i++)
1390 if (strcmp(app->pipeline_type[i].name, name) == 0)
1391 return &app->pipeline_type[i];