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>
30 #include "pipeline_common_fe.h"
31 #include "pipeline_master.h"
32 //#include "pipeline_passthrough.h"
33 #include "thread_fe.h"
34 #include "pipeline_loadb.h"
35 #include "pipeline_arpicmp.h"
36 #include "pipeline_acl.h"
37 #include "pipeline_txrx.h"
39 #include "interface.h"
40 #include "l3fwd_common.h"
41 #include "l3fwd_lpm4.h"
42 #include "l3fwd_lpm6.h"
45 #define APP_NAME_SIZE 32
47 /* Core Mask String in Hex Representation */
48 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
50 port_config_t *port_config;
54 app_init_core_map(struct app_params *app)
56 APP_LOG(app, HIGH, "Initializing CPU core map ...");
57 app->core_map = cpu_core_map_init(4, 32, 4, 0);
59 if (app->core_map == NULL)
60 rte_panic("Cannot create CPU core map\n");
62 if (app->log_level >= APP_LOG_LEVEL_LOW)
63 cpu_core_map_print(app->core_map);
67 app_init_core_mask(struct app_params *app)
69 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
72 for (i = 0; i < app->n_pipelines; i++) {
73 struct app_pipeline_params *p = &app->pipeline_params[i];
76 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
82 rte_panic("Cannot create CPU core mask\n");
84 app_core_enable_in_core_mask(app, lcore_id);
87 app_core_build_core_mask_string(app, core_mask_str);
88 APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
93 app_init_eal(struct app_params *app)
96 char core_mask_str[APP_CORE_MASK_STRING_SIZE];
97 struct app_eal_params *p = &app->eal_params;
102 app->eal_argv[n_args++] = strdup(app->app_name);
104 app_core_build_core_mask_string(app, core_mask_str);
105 snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
106 app->eal_argv[n_args++] = strdup(buffer);
109 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
110 app->eal_argv[n_args++] = strdup(buffer);
113 if (p->master_lcore_present) {
116 "--master-lcore=%" PRIu32,
118 app->eal_argv[n_args++] = strdup(buffer);
121 snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
122 app->eal_argv[n_args++] = strdup(buffer);
124 if (p->memory_present) {
125 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
126 app->eal_argv[n_args++] = strdup(buffer);
129 if (p->ranks_present) {
130 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
131 app->eal_argv[n_args++] = strdup(buffer);
134 for (i = 0; i < APP_MAX_LINKS; i++) {
135 if (p->pci_blacklist[i] == NULL)
140 "--pci-blacklist=%s",
141 p->pci_blacklist[i]);
142 app->eal_argv[n_args++] = strdup(buffer);
145 if (app->port_mask != 0)
146 for (i = 0; i < APP_MAX_LINKS; i++) {
147 if (p->pci_whitelist[i] == NULL)
152 "--pci-whitelist=%s",
153 p->pci_whitelist[i]);
155 app->eal_argv[n_args++] = strdup(buffer);
158 for (i = 0; i < app->n_links; i++) {
159 char *pci_bdf = app->link_params[i].pci_bdf;
163 "--pci-whitelist=%s",
165 app->eal_argv[n_args++] = strdup(buffer);
168 for (i = 0; i < APP_MAX_LINKS; i++) {
169 if (p->vdev[i] == NULL)
176 app->eal_argv[n_args++] = strdup(buffer);
179 if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
180 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
181 app->eal_argv[n_args++] = strdup(buffer);
189 app->eal_argv[n_args++] = strdup(buffer);
193 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
194 app->eal_argv[n_args++] = strdup(buffer);
197 if (p->log_level_present) {
200 "--log-level=%" PRIu32,
202 app->eal_argv[n_args++] = strdup(buffer);
205 if ((p->version_present) && p->version) {
206 snprintf(buffer, sizeof(buffer), "-v");
207 app->eal_argv[n_args++] = strdup(buffer);
210 if ((p->help_present) && p->help) {
211 snprintf(buffer, sizeof(buffer), "--help");
212 app->eal_argv[n_args++] = strdup(buffer);
215 if ((p->no_huge_present) && p->no_huge) {
216 snprintf(buffer, sizeof(buffer), "--no-huge");
217 app->eal_argv[n_args++] = strdup(buffer);
220 if ((p->no_pci_present) && p->no_pci) {
221 snprintf(buffer, sizeof(buffer), "--no-pci");
222 app->eal_argv[n_args++] = strdup(buffer);
225 if ((p->no_hpet_present) && p->no_hpet) {
226 snprintf(buffer, sizeof(buffer), "--no-hpet");
227 app->eal_argv[n_args++] = strdup(buffer);
230 if ((p->no_shconf_present) && p->no_shconf) {
231 snprintf(buffer, sizeof(buffer), "--no-shconf");
232 app->eal_argv[n_args++] = strdup(buffer);
236 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
237 app->eal_argv[n_args++] = strdup(buffer);
245 app->eal_argv[n_args++] = strdup(buffer);
249 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
250 app->eal_argv[n_args++] = strdup(buffer);
253 if (p->file_prefix) {
258 app->eal_argv[n_args++] = strdup(buffer);
261 if (p->base_virtaddr) {
264 "--base-virtaddr=%s",
266 app->eal_argv[n_args++] = strdup(buffer);
269 if ((p->create_uio_dev_present) && p->create_uio_dev) {
270 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
271 app->eal_argv[n_args++] = strdup(buffer);
279 app->eal_argv[n_args++] = strdup(buffer);
282 if ((p->xen_dom0_present) && (p->xen_dom0)) {
283 snprintf(buffer, sizeof(buffer), "--xen-dom0");
284 app->eal_argv[n_args++] = strdup(buffer);
287 snprintf(buffer, sizeof(buffer), "--");
288 app->eal_argv[n_args++] = strdup(buffer);
290 app->eal_argc = n_args;
292 APP_LOG(app, HIGH, "Initializing EAL ...");
293 if (app->log_level >= APP_LOG_LEVEL_LOW) {
296 fprintf(stdout, "[APP] EAL arguments: \"");
297 for (i = 1; i < app->eal_argc; i++)
298 fprintf(stdout, "%s ", app->eal_argv[i]);
299 fprintf(stdout, "\"\n");
302 status = rte_eal_init(app->eal_argc, app->eal_argv);
304 rte_panic("EAL init error\n");
308 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
310 struct rte_eth_ntuple_filter filter = {
311 .flags = RTE_5TUPLE_FLAGS,
312 .dst_ip = rte_bswap32(l2->ip),
313 .dst_ip_mask = UINT32_MAX, /* Enable */
315 .src_ip_mask = 0, /* Disable */
317 .dst_port_mask = 0, /* Disable */
319 .src_port_mask = 0, /* Disable */
321 .proto_mask = 0, /* Disable */
323 .priority = 1, /* Lowest */
324 .queue = l1->ip_local_q,
327 return rte_eth_dev_filter_ctrl(l1->pmd_id,
328 RTE_ETH_FILTER_NTUPLE,
334 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
336 struct rte_eth_ntuple_filter filter = {
337 .flags = RTE_5TUPLE_FLAGS,
338 .dst_ip = rte_bswap32(l2->ip),
339 .dst_ip_mask = UINT32_MAX, /* Enable */
341 .src_ip_mask = 0, /* Disable */
343 .dst_port_mask = 0, /* Disable */
345 .src_port_mask = 0, /* Disable */
347 .proto_mask = 0, /* Disable */
349 .priority = 1, /* Lowest */
350 .queue = l1->ip_local_q,
353 return rte_eth_dev_filter_ctrl(l1->pmd_id,
354 RTE_ETH_FILTER_NTUPLE,
355 RTE_ETH_FILTER_DELETE,
360 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
362 struct rte_eth_ntuple_filter filter = {
363 .flags = RTE_5TUPLE_FLAGS,
364 .dst_ip = rte_bswap32(l2->ip),
365 .dst_ip_mask = UINT32_MAX, /* Enable */
367 .src_ip_mask = 0, /* Disable */
369 .dst_port_mask = 0, /* Disable */
371 .src_port_mask = 0, /* Disable */
372 .proto = IPPROTO_TCP,
373 .proto_mask = UINT8_MAX, /* Enable */
375 .priority = 2, /* Higher priority than IP */
376 .queue = l1->tcp_local_q,
379 return rte_eth_dev_filter_ctrl(l1->pmd_id,
380 RTE_ETH_FILTER_NTUPLE,
386 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
388 struct rte_eth_ntuple_filter filter = {
389 .flags = RTE_5TUPLE_FLAGS,
390 .dst_ip = rte_bswap32(l2->ip),
391 .dst_ip_mask = UINT32_MAX, /* Enable */
393 .src_ip_mask = 0, /* Disable */
395 .dst_port_mask = 0, /* Disable */
397 .src_port_mask = 0, /* Disable */
398 .proto = IPPROTO_TCP,
399 .proto_mask = UINT8_MAX, /* Enable */
401 .priority = 2, /* Higher priority than IP */
402 .queue = l1->tcp_local_q,
405 return rte_eth_dev_filter_ctrl(l1->pmd_id,
406 RTE_ETH_FILTER_NTUPLE,
407 RTE_ETH_FILTER_DELETE,
412 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
414 struct rte_eth_ntuple_filter filter = {
415 .flags = RTE_5TUPLE_FLAGS,
416 .dst_ip = rte_bswap32(l2->ip),
417 .dst_ip_mask = UINT32_MAX, /* Enable */
419 .src_ip_mask = 0, /* Disable */
421 .dst_port_mask = 0, /* Disable */
423 .src_port_mask = 0, /* Disable */
424 .proto = IPPROTO_UDP,
425 .proto_mask = UINT8_MAX, /* Enable */
427 .priority = 2, /* Higher priority than IP */
428 .queue = l1->udp_local_q,
431 return rte_eth_dev_filter_ctrl(l1->pmd_id,
432 RTE_ETH_FILTER_NTUPLE,
438 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
440 struct rte_eth_ntuple_filter filter = {
441 .flags = RTE_5TUPLE_FLAGS,
442 .dst_ip = rte_bswap32(l2->ip),
443 .dst_ip_mask = UINT32_MAX, /* Enable */
445 .src_ip_mask = 0, /* Disable */
447 .dst_port_mask = 0, /* Disable */
449 .src_port_mask = 0, /* Disable */
450 .proto = IPPROTO_UDP,
451 .proto_mask = UINT8_MAX, /* Enable */
453 .priority = 2, /* Higher priority than IP */
454 .queue = l1->udp_local_q,
457 return rte_eth_dev_filter_ctrl(l1->pmd_id,
458 RTE_ETH_FILTER_NTUPLE,
459 RTE_ETH_FILTER_DELETE,
464 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
466 struct rte_eth_ntuple_filter filter = {
467 .flags = RTE_5TUPLE_FLAGS,
468 .dst_ip = rte_bswap32(l2->ip),
469 .dst_ip_mask = UINT32_MAX, /* Enable */
471 .src_ip_mask = 0, /* Disable */
473 .dst_port_mask = 0, /* Disable */
475 .src_port_mask = 0, /* Disable */
476 .proto = IPPROTO_SCTP,
477 .proto_mask = UINT8_MAX, /* Enable */
479 .priority = 2, /* Higher priority than IP */
480 .queue = l1->sctp_local_q,
483 return rte_eth_dev_filter_ctrl(l1->pmd_id,
484 RTE_ETH_FILTER_NTUPLE,
490 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
492 struct rte_eth_ntuple_filter filter = {
493 .flags = RTE_5TUPLE_FLAGS,
494 .dst_ip = rte_bswap32(l2->ip),
495 .dst_ip_mask = UINT32_MAX, /* Enable */
497 .src_ip_mask = 0, /* Disable */
499 .dst_port_mask = 0, /* Disable */
501 .src_port_mask = 0, /* Disable */
502 .proto = IPPROTO_SCTP,
503 .proto_mask = UINT8_MAX, /* Enable */
505 .priority = 2, /* Higher priority than IP */
506 .queue = l1->sctp_local_q,
509 return rte_eth_dev_filter_ctrl(l1->pmd_id,
510 RTE_ETH_FILTER_NTUPLE,
511 RTE_ETH_FILTER_DELETE,
516 app_link_is_virtual(struct app_link_params *p)
518 uint32_t pmd_id = p->pmd_id;
519 struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
521 if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
528 app_link_up_internal(struct app_params *app, struct app_link_params *cp)
532 struct rte_eth_link link;
534 if(app == NULL || cp == NULL)
535 printf("NULL Pointers");
537 if (app_link_is_virtual(cp)) {
542 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_UP);
544 /* Mark link as UP */
550 app_link_down_internal(struct app_params *app, struct app_link_params *cp)
554 struct rte_eth_link link;
556 if(app == NULL || cp == NULL)
557 printf("NULL Pointers");
559 if (app_link_is_virtual(cp)) {
564 ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_DOWN);
566 /* Mark link as DOWN */
572 app_check_link(struct app_params *app)
574 uint32_t all_links_up, i;
578 for (i = 0; i < app->n_links; i++) {
579 struct app_link_params *p = &app->link_params[i];
580 struct rte_eth_link link_params;
582 memset(&link_params, 0, sizeof(link_params));
583 rte_eth_link_get(p->pmd_id, &link_params);
585 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
588 link_params.link_speed / 1000,
589 link_params.link_status ? "UP" : "DOWN");
591 if (link_params.link_status == ETH_LINK_DOWN)
595 if (all_links_up == 0)
596 rte_panic("Some links are DOWN\n");
600 is_any_swq_frag_or_ras(struct app_params *app)
604 for (i = 0; i < app->n_pktq_swq; i++) {
605 struct app_pktq_swq_params *p = &app->swq_params[i];
607 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
608 (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
616 app_init_link_frag_ras(struct app_params *app)
620 if (is_any_swq_frag_or_ras(app)) {
621 for (i = 0; i < app->n_pktq_hwq_out; i++) {
622 struct app_pktq_hwq_out_params *p_txq = &app->hwq_out_params[i];
624 p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
630 app_get_cpu_socket_id(uint32_t pmd_id)
632 int status = rte_eth_dev_socket_id(pmd_id);
634 return (status != SOCKET_ID_ANY) ? status : 0;
636 struct rte_eth_rxmode rx_mode = {
637 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
639 .header_split = 0, /**< Header Split disabled. */
640 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
641 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
642 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
643 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
644 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
645 .hw_strip_crc = 0, /**< CRC stripping by hardware disabled. */
647 struct rte_fdir_conf fdir_conf = {
648 .mode = RTE_FDIR_MODE_NONE,
649 .pballoc = RTE_FDIR_PBALLOC_64K,
650 .status = RTE_FDIR_REPORT_STATUS,
652 .vlan_tci_mask = 0x0,
654 .src_ip = 0xFFFFFFFF,
655 .dst_ip = 0xFFFFFFFF,
658 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
660 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
663 .src_port_mask = 0xFFFF,
664 .dst_port_mask = 0xFFFF,
665 .mac_addr_byte_mask = 0xFF,
666 .tunnel_type_mask = 1,
667 .tunnel_id_mask = 0xFFFFFFFF,
672 app_init_link(struct app_params *app)
676 app_init_link_frag_ras(app);
679 *Configuring port_config_t structure for interface manager initialization
681 size = RTE_CACHE_LINE_ROUNDUP(sizeof(port_config_t));
682 port_config = rte_zmalloc(NULL, (app->n_links * size), RTE_CACHE_LINE_SIZE);
683 if (port_config == NULL)
684 rte_panic("port_config is NULL: Memory Allocation failure\n");
686 for (i = 0; i < app->n_links; i++) {
687 struct app_link_params *p_link = &app->link_params[i];
688 uint32_t link_id, n_hwq_in, n_hwq_out, j;
691 sscanf(p_link->name, "LINK%" PRIu32, &link_id);
692 n_hwq_in = app_link_get_n_rxq(app, p_link);
693 n_hwq_out = app_link_get_n_txq(app, p_link);
694 printf("\n\nn_hwq_in %d\n", n_hwq_in);
695 struct rte_eth_conf *My_local_conf = &p_link->conf;
697 My_local_conf->rxmode = rx_mode;
698 My_local_conf->fdir_conf = fdir_conf;
699 My_local_conf->rxmode.mq_mode = ETH_MQ_RX_RSS;
700 My_local_conf->rx_adv_conf.rss_conf.rss_key = NULL;
701 My_local_conf->rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP;
702 } else {/* disable-rss */
703 My_local_conf->rx_adv_conf.rss_conf.rss_hf = 0;
704 /* pkt-filter-mode is perfect */
705 My_local_conf->fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
708 /* Set the hardware CRC stripping to avoid double stripping of FCS in VM */
709 p_link->conf.rxmode.hw_strip_crc = 1;
711 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
712 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
718 port_config[i].port_id = p_link->pmd_id;
719 port_config[i].nrx_queue = n_hwq_in;
720 port_config[i].ntx_queue = n_hwq_out;
721 port_config[i].state = 1;
722 port_config[i].promisc = p_link->promisc;
723 port_config[i].mempool.pool_size = app->mempool_params[0].pool_size;
724 port_config[i].mempool.buffer_size = app->mempool_params[0].buffer_size;
725 port_config[i].mempool.cache_size = app->mempool_params[0].cache_size;
726 port_config[i].mempool.cpu_socket_id = app->mempool_params[0].cpu_socket_id;
727 memcpy (&port_config[i].port_conf, &p_link->conf, sizeof(struct rte_eth_conf));
728 memcpy (&port_config[i].rx_conf, &app->hwq_in_params[0].conf, sizeof(struct rte_eth_rxconf));
729 memcpy (&port_config[i].tx_conf, &app->hwq_out_params[0].conf, sizeof(struct rte_eth_txconf));
731 if (app->header_csum_req) {
732 /* Enable TCP and UDP HW Checksum */
733 port_config[i].tx_conf.txq_flags &=
734 ~(ETH_TXQ_FLAGS_NOXSUMTCP|ETH_TXQ_FLAGS_NOXSUMUDP);
737 if (ifm_port_setup (p_link->pmd_id, &port_config[i])) {
738 rte_panic ("Port Setup Failed: %s - %"PRIu32"\n",
739 p_link->name, p_link->pmd_id);
743 app_link_up_internal(app, p_link);
750 app_init_swq(struct app_params *app)
754 for (i = 0; i < app->n_pktq_swq; i++) {
755 struct app_pktq_swq_params *p = &app->swq_params[i];
756 unsigned int flags = 0;
758 if (app_swq_get_readers(app, p) == 1)
759 flags |= RING_F_SC_DEQ;
760 if (app_swq_get_writers(app, p) == 1)
761 flags |= RING_F_SP_ENQ;
763 APP_LOG(app, HIGH, "Initializing %s...", p->name);
764 app->swq[i] = rte_ring_create(
770 if (app->swq[i] == NULL)
771 rte_panic("%s init error\n", p->name);
776 app_init_tm(struct app_params *app)
780 for (i = 0; i < app->n_pktq_tm; i++) {
781 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
782 struct app_link_params *p_link;
783 struct rte_eth_link link_eth_params;
784 struct rte_sched_port *sched;
785 uint32_t n_subports, subport_id;
788 p_link = app_get_link_for_tm(app, p_tm);
790 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
793 p_tm->sched_port_params.name = p_tm->name;
794 p_tm->sched_port_params.socket =
795 app_get_cpu_socket_id(p_link->pmd_id);
796 p_tm->sched_port_params.rate =
797 (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
799 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
800 sched = rte_sched_port_config(&p_tm->sched_port_params);
802 rte_panic("%s init error\n", p_tm->name);
806 n_subports = p_tm->sched_port_params.n_subports_per_port;
807 for (subport_id = 0; subport_id < n_subports; subport_id++) {
808 uint32_t n_pipes_per_subport, pipe_id;
810 status = rte_sched_subport_config(sched,
812 &p_tm->sched_subport_params[subport_id]);
814 rte_panic("%s subport %" PRIu32
815 " init error (%" PRId32 ")\n",
816 p_tm->name, subport_id, status);
819 n_pipes_per_subport =
820 p_tm->sched_port_params.n_pipes_per_subport;
822 pipe_id < n_pipes_per_subport;
824 int profile_id = p_tm->sched_pipe_to_profile[
825 subport_id * APP_MAX_SCHED_PIPES +
828 if (profile_id == -1)
831 status = rte_sched_pipe_config(sched,
836 rte_panic("%s subport %" PRIu32
838 " (profile %" PRId32 ") "
839 "init error (% " PRId32 ")\n",
840 p_tm->name, subport_id, pipe_id,
848 app_init_msgq(struct app_params *app)
852 for (i = 0; i < app->n_msgq; i++) {
853 struct app_msgq_params *p = &app->msgq_params[i];
855 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
856 app->msgq[i] = rte_ring_create(
860 RING_F_SP_ENQ | RING_F_SC_DEQ);
862 if (app->msgq[i] == NULL)
863 rte_panic("%s init error\n", p->name);
867 static void app_pipeline_params_get(struct app_params *app,
868 struct app_pipeline_params *p_in,
869 struct pipeline_params *p_out)
874 snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
876 p_out->socket_id = (int) p_in->socket_id;
878 p_out->log_level = app->log_level;
881 p_out->n_ports_in = p_in->n_pktq_in;
882 for (i = 0; i < p_in->n_pktq_in; i++) {
883 struct app_pktq_in_params *in = &p_in->pktq_in[i];
884 struct pipeline_port_in_params *out = &p_out->port_in[i];
887 case APP_PKTQ_IN_HWQ:
889 struct app_pktq_hwq_in_params *p_hwq_in =
890 &app->hwq_in_params[in->id];
891 struct app_link_params *p_link =
892 app_get_link_for_rxq(app, p_hwq_in);
893 uint32_t rxq_link_id, rxq_queue_id;
895 sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
899 out->type = PIPELINE_PORT_IN_ETHDEV_READER;
900 out->params.ethdev.port_id = p_link->pmd_id;
901 out->params.ethdev.queue_id = rxq_queue_id;
902 out->burst_size = p_hwq_in->burst;
905 case APP_PKTQ_IN_SWQ:
907 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
909 if ((swq_params->ipv4_frag == 0) && (swq_params->ipv6_frag == 0)) {
910 if (app_swq_get_readers(app, swq_params) == 1) {
911 out->type = PIPELINE_PORT_IN_RING_READER;
912 out->params.ring.ring = app->swq[in->id];
913 out->burst_size = app->swq_params[in->id].burst_read;
915 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
916 out->params.ring_multi.ring = app->swq[in->id];
917 out->burst_size = swq_params->burst_read;
920 if (swq_params->ipv4_frag == 1) {
921 struct rte_port_ring_reader_ipv4_frag_params *params =
922 &out->params.ring_ipv4_frag;
924 out->type = PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
925 params->ring = app->swq[in->id];
926 params->mtu = swq_params->mtu;
927 params->metadata_size = swq_params->metadata_size;
928 params->pool_direct =
929 app->mempool[swq_params->mempool_direct_id];
930 params->pool_indirect =
931 app->mempool[swq_params->mempool_indirect_id];
932 out->burst_size = swq_params->burst_read;
934 struct rte_port_ring_reader_ipv6_frag_params *params =
935 &out->params.ring_ipv6_frag;
937 out->type = PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
938 params->ring = app->swq[in->id];
939 params->mtu = swq_params->mtu;
940 params->metadata_size = swq_params->metadata_size;
941 params->pool_direct =
942 app->mempool[swq_params->mempool_direct_id];
943 params->pool_indirect =
944 app->mempool[swq_params->mempool_indirect_id];
945 out->burst_size = swq_params->burst_read;
951 out->type = PIPELINE_PORT_IN_SCHED_READER;
952 out->params.sched.sched = app->tm[in->id];
953 out->burst_size = app->tm_params[in->id].burst_read;
955 case APP_PKTQ_IN_SOURCE:
956 mempool_id = app->source_params[in->id].mempool_id;
957 out->type = PIPELINE_PORT_IN_SOURCE;
958 out->params.source.mempool = app->mempool[mempool_id];
959 out->burst_size = app->source_params[in->id].burst;
962 if (app->source_params[in->id].file_name
964 out->params.source.file_name = strdup(
965 app->source_params[in->id].
967 if (out->params.source.file_name == NULL) {
972 out->params.source.n_bytes_per_pkt =
973 app->source_params[in->id].
985 p_out->n_ports_out = p_in->n_pktq_out;
986 for (i = 0; i < p_in->n_pktq_out; i++) {
987 struct app_pktq_out_params *in = &p_in->pktq_out[i];
988 struct pipeline_port_out_params *out = &p_out->port_out[i];
991 case APP_PKTQ_OUT_HWQ:
993 struct app_pktq_hwq_out_params *p_hwq_out =
994 &app->hwq_out_params[in->id];
995 struct app_link_params *p_link =
996 app_get_link_for_txq(app, p_hwq_out);
997 uint32_t txq_link_id, txq_queue_id;
999 sscanf(p_hwq_out->name,
1000 "TXQ%" SCNu32 ".%" SCNu32,
1004 if (p_hwq_out->dropless == 0) {
1005 struct rte_port_ethdev_writer_params *params =
1006 &out->params.ethdev;
1008 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1009 params->port_id = p_link->pmd_id;
1010 params->queue_id = txq_queue_id;
1011 params->tx_burst_sz =
1012 app->hwq_out_params[in->id].burst;
1014 struct rte_port_ethdev_writer_nodrop_params
1015 *params = &out->params.ethdev_nodrop;
1018 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1019 params->port_id = p_link->pmd_id;
1020 params->queue_id = txq_queue_id;
1021 params->tx_burst_sz = p_hwq_out->burst;
1022 params->n_retries = p_hwq_out->n_retries;
1026 case APP_PKTQ_OUT_SWQ:
1028 struct app_pktq_swq_params *swq_params = &app->swq_params[in->id];
1030 if ((swq_params->ipv4_ras == 0) && (swq_params->ipv6_ras == 0)) {
1031 if (app_swq_get_writers(app, swq_params) == 1) {
1032 if (app->swq_params[in->id].dropless == 0) {
1033 struct rte_port_ring_writer_params *params =
1036 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1037 params->ring = app->swq[in->id];
1038 params->tx_burst_sz =
1039 app->swq_params[in->id].burst_write;
1041 struct rte_port_ring_writer_nodrop_params
1042 *params = &out->params.ring_nodrop;
1045 PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1046 params->ring = app->swq[in->id];
1047 params->tx_burst_sz =
1048 app->swq_params[in->id].burst_write;
1050 app->swq_params[in->id].n_retries;
1053 if (swq_params->dropless == 0) {
1054 struct rte_port_ring_multi_writer_params *params =
1055 &out->params.ring_multi;
1057 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1058 params->ring = app->swq[in->id];
1059 params->tx_burst_sz = swq_params->burst_write;
1061 struct rte_port_ring_multi_writer_nodrop_params
1062 *params = &out->params.ring_multi_nodrop;
1064 out->type = PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1065 params->ring = app->swq[in->id];
1066 params->tx_burst_sz = swq_params->burst_write;
1067 params->n_retries = swq_params->n_retries;
1071 if (swq_params->ipv4_ras == 1) {
1072 struct rte_port_ring_writer_ipv4_ras_params *params =
1073 &out->params.ring_ipv4_ras;
1075 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1076 params->ring = app->swq[in->id];
1077 params->tx_burst_sz = swq_params->burst_write;
1079 struct rte_port_ring_writer_ipv6_ras_params *params =
1080 &out->params.ring_ipv6_ras;
1082 out->type = PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1083 params->ring = app->swq[in->id];
1084 params->tx_burst_sz = swq_params->burst_write;
1089 case APP_PKTQ_OUT_TM: {
1090 struct rte_port_sched_writer_params *params =
1093 out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1094 params->sched = app->tm[in->id];
1095 params->tx_burst_sz =
1096 app->tm_params[in->id].burst_write;
1099 case APP_PKTQ_OUT_SINK:
1100 out->type = PIPELINE_PORT_OUT_SINK;
1101 if (app->sink_params[in->id].file_name != NULL) {
1102 out->params.sink.file_name = strdup(
1103 app->sink_params[in->id].
1105 if (out->params.sink.file_name == NULL) {
1106 out->params.sink.max_n_pkts = 0;
1109 out->params.sink.max_n_pkts =
1110 app->sink_params[in->id].
1113 out->params.sink.file_name = NULL;
1114 out->params.sink.max_n_pkts = 0;
1123 p_out->n_msgq = p_in->n_msgq_in;
1125 for (i = 0; i < p_in->n_msgq_in; i++)
1126 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1128 for (i = 0; i < p_in->n_msgq_out; i++)
1129 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1132 p_out->n_args = p_in->n_args;
1133 for (i = 0; i < p_in->n_args; i++) {
1134 p_out->args_name[i] = p_in->args_name[i];
1135 p_out->args_value[i] = p_in->args_value[i];
1140 app_init_pipelines(struct app_params *app)
1144 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1145 struct app_pipeline_params *params =
1146 &app->pipeline_params[p_id];
1147 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1148 struct pipeline_type *ptype;
1149 struct pipeline_params pp;
1151 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1153 ptype = app_pipeline_type_find(app, params->type);
1155 rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1158 app_pipeline_params_get(app, params, &pp);
1162 if (ptype->be_ops->f_init) {
1163 data->be = ptype->be_ops->f_init(&pp, (void *) app);
1165 if (data->be == NULL)
1166 rte_panic("Pipeline instance \"%s\" back-end "
1167 "init error\n", params->name);
1172 if (ptype->fe_ops->f_init) {
1173 data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1175 if (data->fe == NULL)
1176 rte_panic("Pipeline instance \"%s\" front-end "
1177 "init error\n", params->name);
1180 data->ptype = ptype;
1182 data->timer_period = (rte_get_tsc_hz() *
1183 params->timer_period) / 100;
1188 app_init_threads(struct app_params *app)
1190 uint64_t time = rte_get_tsc_cycles();
1193 for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1194 struct app_pipeline_params *params =
1195 &app->pipeline_params[p_id];
1196 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1197 struct pipeline_type *ptype;
1198 struct app_thread_data *t;
1199 struct app_thread_pipeline_data *p;
1202 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1205 params->hyper_th_id);
1208 rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1211 (params->hyper_th_id) ? "h" : "");
1213 t = &app->thread_data[lcore_id];
1215 t->timer_period = (rte_get_tsc_hz() * APP_THREAD_TIMER_PERIOD) / 1000;
1216 t->thread_req_deadline = time + t->timer_period;
1218 t->headroom_cycles = 0;
1219 t->headroom_time = rte_get_tsc_cycles();
1220 t->headroom_ratio = 0.0;
1222 t->msgq_in = app_thread_msgq_in_get(app,
1225 params->hyper_th_id);
1226 if (t->msgq_in == NULL)
1227 rte_panic("Init error: Cannot find MSGQ_IN for thread %" PRId32,
1230 t->msgq_out = app_thread_msgq_out_get(app,
1233 params->hyper_th_id);
1234 if (t->msgq_out == NULL)
1235 rte_panic("Init error: Cannot find MSGQ_OUT for thread %" PRId32,
1238 ptype = app_pipeline_type_find(app, params->type);
1240 rte_panic("Init error: Unknown pipeline "
1241 "type \"%s\"\n", params->type);
1243 p = (ptype->be_ops->f_run == NULL) ?
1244 &t->regular[t->n_regular] :
1245 &t->custom[t->n_custom];
1247 p->pipeline_id = p_id;
1249 p->f_run = ptype->be_ops->f_run;
1250 p->f_timer = ptype->be_ops->f_timer;
1251 p->timer_period = data->timer_period;
1252 p->deadline = time + data->timer_period;
1256 if (ptype->be_ops->f_run == NULL)
1263 int app_init(struct app_params *app)
1265 app_init_core_map(app);
1266 app_init_core_mask(app);
1272 timer_lcore = rte_lcore_id();
1279 app_pipeline_common_cmd_push(app);
1280 app_pipeline_thread_cmd_push(app);
1281 app_pipeline_type_register(app, &pipeline_master);
1282 app_pipeline_type_register(app, &pipeline_arpicmp);
1284 app_pipeline_type_register(app, &pipeline_loadb);
1285 app_pipeline_type_register(app, &pipeline_acl);
1286 app_pipeline_type_register(app, &pipeline_txrx);
1288 app_init_pipelines(app);
1289 app_init_threads(app);
1294 populate_lpm_routes();
1295 print_interface_details();
1301 app_pipeline_type_cmd_push(struct app_params *app,
1302 struct pipeline_type *ptype)
1304 cmdline_parse_ctx_t *cmds;
1307 /* Check input arguments */
1308 if ((app == NULL) ||
1312 n_cmds = pipeline_type_cmds_count(ptype);
1316 cmds = ptype->fe_ops->cmds;
1318 /* Check for available slots in the application commands array */
1319 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1322 /* Push pipeline commands into the application */
1323 memcpy(&app->cmds[app->n_cmds],
1325 n_cmds * sizeof(cmdline_parse_ctx_t));
1327 for (i = 0; i < n_cmds; i++)
1328 app->cmds[app->n_cmds + i]->data = app;
1330 app->n_cmds += n_cmds;
1331 app->cmds[app->n_cmds] = NULL;
1337 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1341 /* Check input arguments */
1342 if ((app == NULL) ||
1344 (ptype->name == NULL) ||
1345 (strlen(ptype->name) == 0) ||
1346 (ptype->be_ops->f_init == NULL) ||
1347 (ptype->be_ops->f_timer == NULL))
1350 /* Check for duplicate entry */
1351 for (i = 0; i < app->n_pipeline_types; i++)
1352 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1355 /* Check for resource availability */
1356 n_cmds = pipeline_type_cmds_count(ptype);
1357 if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1358 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1361 /* Copy pipeline type */
1362 memcpy(&app->pipeline_type[app->n_pipeline_types++],
1364 sizeof(struct pipeline_type));
1366 /* Copy CLI commands */
1368 app_pipeline_type_cmd_push(app, ptype);
1374 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1378 for (i = 0; i < app->n_pipeline_types; i++)
1379 if (strcmp(app->pipeline_type[i].name, name) == 0)
1380 return &app->pipeline_type[i];