VNFs: rte_eth_dev is deprecated in DPDK version 16.11 and onwards
[samplevnf.git] / VNFs / vFW / init.c
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #include <inttypes.h>
18 #include <stdio.h>
19 #include <string.h>
20
21 #include <rte_cycles.h>
22 #include <rte_ethdev.h>
23 #include <rte_ether.h>
24 #include <rte_ip.h>
25 #include <rte_eal.h>
26 #include <rte_malloc.h>
27 #include <rte_version.h>
28
29 #include "app.h"
30 #include "pipeline.h"
31 #include "pipeline_common_fe.h"
32 #include "pipeline_master.h"
33 #include "pipeline_passthrough.h"
34 #include "thread_fe.h"
35 #include "pipeline_vfw.h"
36 #include "pipeline_loadb.h"
37 #include "pipeline_txrx.h"
38 #include "pipeline_arpicmp.h"
39 #include "interface.h"
40 #include "l3fwd_common.h"
41 #include "l3fwd_lpm4.h"
42 #include "l3fwd_lpm6.h"
43 #include "lib_arp.h"
44 #include "vnf_define.h"
45 #define APP_NAME_SIZE   32
46 port_config_t *port_config;
47
48 static void
49 app_init_core_map(struct app_params *app)
50 {
51         APP_LOG(app, HIGH, "Initializing CPU core map ...");
52         app->core_map = cpu_core_map_init(4, 32, 4, 0);
53
54         if (app->core_map == NULL)
55                 rte_panic("Cannot create CPU core map\n");
56
57         if (app->log_level >= APP_LOG_LEVEL_LOW)
58                 cpu_core_map_print(app->core_map);
59 }
60
61 /* Core Mask String in Hex Representation */
62 #define APP_CORE_MASK_STRING_SIZE ((64 * APP_CORE_MASK_SIZE) / 8 * 2 + 1)
63
64 static void
65 app_init_core_mask(struct app_params *app)
66 {
67         char core_mask_str[APP_CORE_MASK_STRING_SIZE];
68         uint32_t i;
69
70         for (i = 0; i < app->n_pipelines; i++) {
71                 struct app_pipeline_params *p = &app->pipeline_params[i];
72                 int lcore_id;
73
74                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
75                         p->socket_id,
76                         p->core_id,
77                         p->hyper_th_id);
78
79                 if (lcore_id < 0)
80                         rte_panic("Cannot create CPU core mask\n");
81
82                 app_core_enable_in_core_mask(app, lcore_id);
83         }
84
85        app_core_build_core_mask_string(app, core_mask_str);
86        APP_LOG(app, HIGH, "CPU core mask = 0x%s", core_mask_str);
87
88 }
89
90 static void
91 app_init_eal(struct app_params *app)
92 {
93         char buffer[256];
94         char core_mask_str[APP_CORE_MASK_STRING_SIZE];
95         struct app_eal_params *p = &app->eal_params;
96         uint8_t n_args = 0;
97         uint32_t i;
98         int status;
99
100         app->eal_argv[n_args++] = strdup(app->app_name);
101
102         app_core_build_core_mask_string(app, core_mask_str);
103         snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
104         app->eal_argv[n_args++] = strdup(buffer);
105
106         if (p->coremap) {
107                 snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
108                 app->eal_argv[n_args++] = strdup(buffer);
109         }
110
111         if (p->master_lcore_present) {
112                 snprintf(buffer,
113                         sizeof(buffer),
114                         "--master-lcore=%" PRIu32,
115                         p->master_lcore);
116                 app->eal_argv[n_args++] = strdup(buffer);
117         }
118
119         snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
120         app->eal_argv[n_args++] = strdup(buffer);
121
122         if (p->memory_present) {
123                 snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
124                 app->eal_argv[n_args++] = strdup(buffer);
125         }
126
127         if (p->ranks_present) {
128                 snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
129                 app->eal_argv[n_args++] = strdup(buffer);
130         }
131
132         for (i = 0; i < APP_MAX_LINKS; i++) {
133                 if (p->pci_blacklist[i] == NULL)
134                         break;
135
136                 snprintf(buffer,
137                         sizeof(buffer),
138                         "--pci-blacklist=%s",
139                         p->pci_blacklist[i]);
140                 app->eal_argv[n_args++] = strdup(buffer);
141         }
142
143         if (app->port_mask != 0)
144                 for (i = 0; i < APP_MAX_LINKS; i++) {
145                         if (p->pci_whitelist[i] == NULL)
146                                 break;
147
148                         snprintf(buffer,
149                                 sizeof(buffer),
150                                 "--pci-whitelist=%s",
151                                 p->pci_whitelist[i]);
152                         app->eal_argv[n_args++] = strdup(buffer);
153                 }
154         else
155                 for (i = 0; i < app->n_links; i++) {
156                         char *pci_bdf = app->link_params[i].pci_bdf;
157
158                         snprintf(buffer,
159                                 sizeof(buffer),
160                                 "--pci-whitelist=%s",
161                                 pci_bdf);
162                         app->eal_argv[n_args++] = strdup(buffer);
163                 }
164
165         for (i = 0; i < APP_MAX_LINKS; i++) {
166                 if (p->vdev[i] == NULL)
167                         break;
168
169                 snprintf(buffer,
170                         sizeof(buffer),
171                         "--vdev=%s",
172                         p->vdev[i]);
173                 app->eal_argv[n_args++] = strdup(buffer);
174         }
175
176         if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
177                 snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
178                 app->eal_argv[n_args++] = strdup(buffer);
179         }
180
181         if (p->proc_type) {
182                 snprintf(buffer,
183                         sizeof(buffer),
184                         "--proc-type=%s",
185                         p->proc_type);
186                 app->eal_argv[n_args++] = strdup(buffer);
187         }
188
189         if (p->syslog) {
190                 snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
191                 app->eal_argv[n_args++] = strdup(buffer);
192         }
193
194         if (p->log_level_present) {
195                 snprintf(buffer,
196                         sizeof(buffer),
197                         "--log-level=%" PRIu32,
198                         p->log_level);
199                 app->eal_argv[n_args++] = strdup(buffer);
200         }
201
202         if ((p->version_present) && p->version) {
203                 snprintf(buffer, sizeof(buffer), "-v");
204                 app->eal_argv[n_args++] = strdup(buffer);
205         }
206
207         if ((p->help_present) && p->help) {
208                 snprintf(buffer, sizeof(buffer), "--help");
209                 app->eal_argv[n_args++] = strdup(buffer);
210         }
211
212         if ((p->no_huge_present) && p->no_huge) {
213                 snprintf(buffer, sizeof(buffer), "--no-huge");
214                 app->eal_argv[n_args++] = strdup(buffer);
215         }
216
217         if ((p->no_pci_present) && p->no_pci) {
218                 snprintf(buffer, sizeof(buffer), "--no-pci");
219                 app->eal_argv[n_args++] = strdup(buffer);
220         }
221
222         if ((p->no_hpet_present) && p->no_hpet) {
223                 snprintf(buffer, sizeof(buffer), "--no-hpet");
224                 app->eal_argv[n_args++] = strdup(buffer);
225         }
226
227         if ((p->no_shconf_present) && p->no_shconf) {
228                 snprintf(buffer, sizeof(buffer), "--no-shconf");
229                 app->eal_argv[n_args++] = strdup(buffer);
230         }
231
232         if (p->add_driver) {
233                 snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
234                 app->eal_argv[n_args++] = strdup(buffer);
235         }
236
237         if (p->socket_mem) {
238                 snprintf(buffer,
239                         sizeof(buffer),
240                         "--socket-mem=%s",
241                         p->socket_mem);
242                 app->eal_argv[n_args++] = strdup(buffer);
243         }
244
245         if (p->huge_dir) {
246                 snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
247                 app->eal_argv[n_args++] = strdup(buffer);
248         }
249
250         if (p->file_prefix) {
251                 snprintf(buffer,
252                         sizeof(buffer),
253                         "--file-prefix=%s",
254                         p->file_prefix);
255                 app->eal_argv[n_args++] = strdup(buffer);
256         }
257
258         if (p->base_virtaddr) {
259                 snprintf(buffer,
260                         sizeof(buffer),
261                         "--base-virtaddr=%s",
262                         p->base_virtaddr);
263                 app->eal_argv[n_args++] = strdup(buffer);
264         }
265
266         if ((p->create_uio_dev_present) && p->create_uio_dev) {
267                 snprintf(buffer, sizeof(buffer), "--create-uio-dev");
268                 app->eal_argv[n_args++] = strdup(buffer);
269         }
270
271         if (p->vfio_intr) {
272                 snprintf(buffer,
273                         sizeof(buffer),
274                         "--vfio-intr=%s",
275                         p->vfio_intr);
276                 app->eal_argv[n_args++] = strdup(buffer);
277         }
278
279         if ((p->xen_dom0_present) && (p->xen_dom0)) {
280                 snprintf(buffer, sizeof(buffer), "--xen-dom0");
281                 app->eal_argv[n_args++] = strdup(buffer);
282         }
283
284         snprintf(buffer, sizeof(buffer), "--");
285         app->eal_argv[n_args++] = strdup(buffer);
286
287         app->eal_argc = n_args;
288
289         APP_LOG(app, HIGH, "Initializing EAL ...");
290         if (app->log_level >= APP_LOG_LEVEL_LOW) {
291                 int i;
292
293                 fprintf(stdout, "[APP] EAL arguments: \"");
294                 for (i = 1; i < app->eal_argc; i++)
295                         fprintf(stdout, "%s ", app->eal_argv[i]);
296                 fprintf(stdout, "\"\n");
297         }
298
299         status = rte_eal_init(app->eal_argc, app->eal_argv);
300         if (status < 0)
301                 rte_panic("EAL init error\n");
302 }
303 static inline int
304 app_link_filter_arp_add(struct app_link_params *link)
305 {
306         struct rte_eth_ethertype_filter filter = {
307                 .ether_type = ETHER_TYPE_ARP,
308                 .flags = 0,
309                 .queue = link->arp_q,
310         };
311
312         return rte_eth_dev_filter_ctrl(link->pmd_id,
313                 RTE_ETH_FILTER_ETHERTYPE,
314                 RTE_ETH_FILTER_ADD,
315                 &filter);
316 }
317
318 static inline int
319 app_link_filter_tcp_syn_add(struct app_link_params *link)
320 {
321         struct rte_eth_syn_filter filter = {
322                 .hig_pri = 1,
323                 .queue = link->tcp_syn_q,
324         };
325
326         return rte_eth_dev_filter_ctrl(link->pmd_id,
327                 RTE_ETH_FILTER_SYN,
328                 RTE_ETH_FILTER_ADD,
329                 &filter);
330 }
331
332 static inline int
333 app_link_filter_ip_add(struct app_link_params *l1, struct app_link_params *l2)
334 {
335         struct rte_eth_ntuple_filter filter = {
336                 .flags = RTE_5TUPLE_FLAGS,
337                 .dst_ip = rte_bswap32(l2->ip),
338                 .dst_ip_mask = UINT32_MAX, /* Enable */
339                 .src_ip = 0,
340                 .src_ip_mask = 0, /* Disable */
341                 .dst_port = 0,
342                 .dst_port_mask = 0, /* Disable */
343                 .src_port = 0,
344                 .src_port_mask = 0, /* Disable */
345                 .proto = 0,
346                 .proto_mask = 0, /* Disable */
347                 .tcp_flags = 0,
348                 .priority = 1, /* Lowest */
349                 .queue = l1->ip_local_q,
350         };
351
352         return rte_eth_dev_filter_ctrl(l1->pmd_id,
353                 RTE_ETH_FILTER_NTUPLE,
354                 RTE_ETH_FILTER_ADD,
355                 &filter);
356 }
357
358 static inline int
359 app_link_filter_ip_del(struct app_link_params *l1, struct app_link_params *l2)
360 {
361         struct rte_eth_ntuple_filter filter = {
362                 .flags = RTE_5TUPLE_FLAGS,
363                 .dst_ip = rte_bswap32(l2->ip),
364                 .dst_ip_mask = UINT32_MAX, /* Enable */
365                 .src_ip = 0,
366                 .src_ip_mask = 0, /* Disable */
367                 .dst_port = 0,
368                 .dst_port_mask = 0, /* Disable */
369                 .src_port = 0,
370                 .src_port_mask = 0, /* Disable */
371                 .proto = 0,
372                 .proto_mask = 0, /* Disable */
373                 .tcp_flags = 0,
374                 .priority = 1, /* Lowest */
375                 .queue = l1->ip_local_q,
376         };
377
378         return rte_eth_dev_filter_ctrl(l1->pmd_id,
379                 RTE_ETH_FILTER_NTUPLE,
380                 RTE_ETH_FILTER_DELETE,
381                 &filter);
382 }
383
384 static inline int
385 app_link_filter_tcp_add(struct app_link_params *l1, struct app_link_params *l2)
386 {
387         struct rte_eth_ntuple_filter filter = {
388                 .flags = RTE_5TUPLE_FLAGS,
389                 .dst_ip = rte_bswap32(l2->ip),
390                 .dst_ip_mask = UINT32_MAX, /* Enable */
391                 .src_ip = 0,
392                 .src_ip_mask = 0, /* Disable */
393                 .dst_port = 0,
394                 .dst_port_mask = 0, /* Disable */
395                 .src_port = 0,
396                 .src_port_mask = 0, /* Disable */
397                 .proto = IPPROTO_TCP,
398                 .proto_mask = UINT8_MAX, /* Enable */
399                 .tcp_flags = 0,
400                 .priority = 2, /* Higher priority than IP */
401                 .queue = l1->tcp_local_q,
402         };
403
404         return rte_eth_dev_filter_ctrl(l1->pmd_id,
405                 RTE_ETH_FILTER_NTUPLE,
406                 RTE_ETH_FILTER_ADD,
407                 &filter);
408 }
409
410 static inline int
411 app_link_filter_tcp_del(struct app_link_params *l1, struct app_link_params *l2)
412 {
413         struct rte_eth_ntuple_filter filter = {
414                 .flags = RTE_5TUPLE_FLAGS,
415                 .dst_ip = rte_bswap32(l2->ip),
416                 .dst_ip_mask = UINT32_MAX, /* Enable */
417                 .src_ip = 0,
418                 .src_ip_mask = 0, /* Disable */
419                 .dst_port = 0,
420                 .dst_port_mask = 0, /* Disable */
421                 .src_port = 0,
422                 .src_port_mask = 0, /* Disable */
423                 .proto = IPPROTO_TCP,
424                 .proto_mask = UINT8_MAX, /* Enable */
425                 .tcp_flags = 0,
426                 .priority = 2, /* Higher priority than IP */
427                 .queue = l1->tcp_local_q,
428         };
429
430         return rte_eth_dev_filter_ctrl(l1->pmd_id,
431                 RTE_ETH_FILTER_NTUPLE,
432                 RTE_ETH_FILTER_DELETE,
433                 &filter);
434 }
435
436 static inline int
437 app_link_filter_udp_add(struct app_link_params *l1, struct app_link_params *l2)
438 {
439         struct rte_eth_ntuple_filter filter = {
440                 .flags = RTE_5TUPLE_FLAGS,
441                 .dst_ip = rte_bswap32(l2->ip),
442                 .dst_ip_mask = UINT32_MAX, /* Enable */
443                 .src_ip = 0,
444                 .src_ip_mask = 0, /* Disable */
445                 .dst_port = 0,
446                 .dst_port_mask = 0, /* Disable */
447                 .src_port = 0,
448                 .src_port_mask = 0, /* Disable */
449                 .proto = IPPROTO_UDP,
450                 .proto_mask = UINT8_MAX, /* Enable */
451                 .tcp_flags = 0,
452                 .priority = 2, /* Higher priority than IP */
453                 .queue = l1->udp_local_q,
454         };
455
456         return rte_eth_dev_filter_ctrl(l1->pmd_id,
457                 RTE_ETH_FILTER_NTUPLE,
458                 RTE_ETH_FILTER_ADD,
459                 &filter);
460 }
461
462 static inline int
463 app_link_filter_udp_del(struct app_link_params *l1, struct app_link_params *l2)
464 {
465         struct rte_eth_ntuple_filter filter = {
466                 .flags = RTE_5TUPLE_FLAGS,
467                 .dst_ip = rte_bswap32(l2->ip),
468                 .dst_ip_mask = UINT32_MAX, /* Enable */
469                 .src_ip = 0,
470                 .src_ip_mask = 0, /* Disable */
471                 .dst_port = 0,
472                 .dst_port_mask = 0, /* Disable */
473                 .src_port = 0,
474                 .src_port_mask = 0, /* Disable */
475                 .proto = IPPROTO_UDP,
476                 .proto_mask = UINT8_MAX, /* Enable */
477                 .tcp_flags = 0,
478                 .priority = 2, /* Higher priority than IP */
479                 .queue = l1->udp_local_q,
480         };
481
482         return rte_eth_dev_filter_ctrl(l1->pmd_id,
483                 RTE_ETH_FILTER_NTUPLE,
484                 RTE_ETH_FILTER_DELETE,
485                 &filter);
486 }
487
488 static inline int
489 app_link_filter_sctp_add(struct app_link_params *l1, struct app_link_params *l2)
490 {
491         struct rte_eth_ntuple_filter filter = {
492                 .flags = RTE_5TUPLE_FLAGS,
493                 .dst_ip = rte_bswap32(l2->ip),
494                 .dst_ip_mask = UINT32_MAX, /* Enable */
495                 .src_ip = 0,
496                 .src_ip_mask = 0, /* Disable */
497                 .dst_port = 0,
498                 .dst_port_mask = 0, /* Disable */
499                 .src_port = 0,
500                 .src_port_mask = 0, /* Disable */
501                 .proto = IPPROTO_SCTP,
502                 .proto_mask = UINT8_MAX, /* Enable */
503                 .tcp_flags = 0,
504                 .priority = 2, /* Higher priority than IP */
505                 .queue = l1->sctp_local_q,
506         };
507
508         return rte_eth_dev_filter_ctrl(l1->pmd_id,
509                 RTE_ETH_FILTER_NTUPLE,
510                 RTE_ETH_FILTER_ADD,
511                 &filter);
512 }
513
514 static inline int
515 app_link_filter_sctp_del(struct app_link_params *l1, struct app_link_params *l2)
516 {
517         struct rte_eth_ntuple_filter filter = {
518                 .flags = RTE_5TUPLE_FLAGS,
519                 .dst_ip = rte_bswap32(l2->ip),
520                 .dst_ip_mask = UINT32_MAX, /* Enable */
521                 .src_ip = 0,
522                 .src_ip_mask = 0, /* Disable */
523                 .dst_port = 0,
524                 .dst_port_mask = 0, /* Disable */
525                 .src_port = 0,
526                 .src_port_mask = 0, /* Disable */
527                 .proto = IPPROTO_SCTP,
528                 .proto_mask = UINT8_MAX, /* Enable */
529                 .tcp_flags = 0,
530                 .priority = 2, /* Higher priority than IP */
531                 .queue = l1->sctp_local_q,
532         };
533
534         return rte_eth_dev_filter_ctrl(l1->pmd_id,
535                 RTE_ETH_FILTER_NTUPLE,
536                 RTE_ETH_FILTER_DELETE,
537                 &filter);
538 }
539
540 /* rte_eth_dev is removed in DPDK version 16.11 and onwards */
541 #if RTE_VERSION < 0x100b0000
542 static int
543 app_link_is_virtual(struct app_link_params *p)
544 {
545         uint32_t pmd_id = p->pmd_id;
546         struct rte_eth_dev *dev = &rte_eth_devices[pmd_id];
547
548         if (dev->dev_type == RTE_ETH_DEV_VIRTUAL)
549                 return 1;
550
551         return 0;
552 }
553 #endif
554
555 void
556 app_link_up_internal(__rte_unused struct app_params *app,
557                 struct app_link_params *cp)
558 {
559         if(app == NULL || cp == NULL)
560                 printf("NULL Pointers");
561
562 #if RTE_VERSION < 0x100b0000
563         if (app_link_is_virtual(cp)) {
564                 cp->state = 1;
565                 return;
566         }
567 #endif
568         ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_UP);
569
570         /* Mark link as UP */
571         cp->state = 1;
572 }
573
574 void
575 app_link_down_internal(__rte_unused struct app_params *app,
576                 struct app_link_params *cp)
577 {
578         if(app == NULL || cp == NULL)
579                 printf("NULL Pointers");
580
581 #if RTE_VERSION < 0x100b0000
582         if (app_link_is_virtual(cp)) {
583                 cp->state = 0;
584                 return;
585         }
586 #endif
587         ifm_update_linkstatus(cp->pmd_id, IFM_ETH_LINK_DOWN);
588         /* Mark link as DOWN */
589         cp->state = 0;
590
591 }
592
593 static void
594 app_check_link(struct app_params *app)
595 {
596         uint32_t all_links_up, i;
597
598         all_links_up = 1;
599
600         for (i = 0; i < app->n_links; i++) {
601                 struct app_link_params *p = &app->link_params[i];
602                 struct rte_eth_link link_params;
603
604                 memset(&link_params, 0, sizeof(link_params));
605                 rte_eth_link_get(p->pmd_id, &link_params);
606
607                 APP_LOG(app, HIGH, "%s (%" PRIu32 ") (%" PRIu32 " Gbps) %s",
608                         p->name,
609                         p->pmd_id,
610                         link_params.link_speed / 1000,
611                         link_params.link_status ? "UP" : "DOWN");
612
613                 if (link_params.link_status == ETH_LINK_DOWN)
614                         all_links_up = 0;
615         }
616
617         if (all_links_up == 0)
618                 rte_panic("Some links are DOWN\n");
619 }
620
621 static uint32_t
622 is_any_swq_frag_or_ras(struct app_params *app)
623 {
624         uint32_t i;
625
626         for (i = 0; i < app->n_pktq_swq; i++) {
627                 struct app_pktq_swq_params *p = &app->swq_params[i];
628
629                 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1) ||
630                         (p->ipv4_ras == 1) || (p->ipv6_ras == 1))
631                         return 1;
632         }
633
634         return 0;
635 }
636
637 static void
638 app_init_link_frag_ras(struct app_params *app)
639 {
640         uint32_t i;
641
642         if (is_any_swq_frag_or_ras(app)) {
643                 for (i = 0; i < app->n_pktq_hwq_out; i++) {
644                         struct app_pktq_hwq_out_params *p_txq =
645                                 &app->hwq_out_params[i];
646
647                         p_txq->conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS;
648                 }
649         }
650 }
651
652 static inline int
653 app_get_cpu_socket_id(uint32_t pmd_id)
654 {
655         int status = rte_eth_dev_socket_id(pmd_id);
656
657         return (status != SOCKET_ID_ANY) ? status : 0;
658 }
659
660 struct rte_eth_rxmode rx_mode = {
661         .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
662         .split_hdr_size = 0,
663         .header_split   = 0, /**< Header Split disabled. */
664         .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
665         .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
666         .hw_vlan_strip  = 1, /**< VLAN strip enabled. */
667         .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
668         .jumbo_frame    = 0, /**< Jumbo Frame Support disabled. */
669         .hw_strip_crc   = 0, /**< CRC stripping by hardware disabled. */
670 };
671 struct rte_fdir_conf fdir_conf = {
672         .mode = RTE_FDIR_MODE_NONE,
673         .pballoc = RTE_FDIR_PBALLOC_64K,
674         .status = RTE_FDIR_REPORT_STATUS,
675         .mask = {
676                 .vlan_tci_mask = 0x0,
677                 .ipv4_mask     = {
678                         .src_ip = 0xFFFFFFFF,
679                         .dst_ip = 0xFFFFFFFF,
680                 },
681                 .ipv6_mask     = {
682                 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
683                 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
684                 },
685                 .src_port_mask = 0xFFFF,
686                 .dst_port_mask = 0xFFFF,
687                 .mac_addr_byte_mask = 0xFF,
688                 .tunnel_type_mask = 1,
689                 .tunnel_id_mask = 0xFFFFFFFF,
690         },
691         .drop_queue = 127,
692 };
693
694         static void
695 app_init_link(struct app_params *app)
696 {
697         uint32_t i, size;
698
699         app_init_link_frag_ras(app);
700
701         /* Configuring port_config_t structure for interface
702          * manager initialization
703          */
704         size = RTE_CACHE_LINE_ROUNDUP(sizeof(port_config_t));
705         port_config = rte_zmalloc(NULL, (app->n_links * size),
706                         RTE_CACHE_LINE_SIZE);
707         if (port_config == NULL)
708                 rte_panic("port_config is NULL: Memory Allocation failure\n");
709
710         for (i = 0; i < app->n_links; i++) {
711                 struct app_link_params *p_link = &app->link_params[i];
712                 uint32_t link_id, n_hwq_in, n_hwq_out;
713                 int status;
714
715                 status = sscanf(p_link->name, "LINK%" PRIu32, &link_id);
716                 if (status < 0)
717                         rte_panic("%s (%" PRId32 "): "
718                                         "init error (%" PRId32 ")\n",
719                                         p_link->name, link_id, status);
720
721                 n_hwq_in = app_link_get_n_rxq(app, p_link);
722                 n_hwq_out = app_link_get_n_txq(app, p_link);
723
724                 printf("\n\nn_hwq_in %d\n", n_hwq_in);
725                 struct rte_eth_conf *My_local_conf = &p_link->conf;
726                 if (enable_hwlb) {
727                         My_local_conf->rxmode = rx_mode;
728                         My_local_conf->fdir_conf = fdir_conf;
729                         My_local_conf->rxmode.mq_mode = ETH_MQ_RX_RSS;
730                         My_local_conf->rx_adv_conf.rss_conf.rss_key = NULL;
731                         My_local_conf->rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP
732                                 | ETH_RSS_UDP | ETH_RSS_TCP;
733                 } else {/* disable-rss */
734                         My_local_conf->rx_adv_conf.rss_conf.rss_hf = 0;
735                         /* pkt-filter-mode is perfect */
736                         My_local_conf->fdir_conf.mode = RTE_FDIR_MODE_PERFECT;
737                 }
738
739                 /* Set the hardware CRC stripping to avoid double stripping
740                  * of FCS in VM */
741                 p_link->conf.rxmode.hw_strip_crc = 1;
742
743                 APP_LOG(app, HIGH, "Initializing %s (%" PRIu32") "
744                                 "(%" PRIu32 " RXQ, %" PRIu32 " TXQ) ...",
745                                 p_link->name,
746                                 p_link->pmd_id,
747                                 n_hwq_in,
748                                 n_hwq_out);
749
750                 port_config[i].port_id = p_link->pmd_id;
751                 port_config[i].nrx_queue = n_hwq_in;
752                 port_config[i].ntx_queue = n_hwq_out;
753                 port_config[i].state = 1;
754                 port_config[i].promisc = p_link->promisc;
755                 port_config[i].mempool.pool_size =
756                         app->mempool_params[0].pool_size;
757                 port_config[i].mempool.buffer_size =
758                         app->mempool_params[0].buffer_size;
759                 port_config[i].mempool.cache_size =
760                         app->mempool_params[0].cache_size;
761                 port_config[i].mempool.cpu_socket_id =
762                         app->mempool_params[0].cpu_socket_id;
763                 memcpy(&port_config[i].port_conf, &p_link->conf,
764                                 sizeof(struct rte_eth_conf));
765                 memcpy(&port_config[i].rx_conf, &app->hwq_in_params[0].conf,
766                                 sizeof(struct rte_eth_rxconf));
767                 memcpy(&port_config[i].tx_conf, &app->hwq_out_params[0].conf,
768                                 sizeof(struct rte_eth_txconf));
769
770                 if (app->header_csum_req) {
771                         /* Enable TCP and UDP HW Checksum */
772                         port_config[i].tx_conf.txq_flags &=
773                                 ~(ETH_TXQ_FLAGS_NOXSUMTCP |
774                                                 ETH_TXQ_FLAGS_NOXSUMUDP);
775                 }
776
777                 if (ifm_port_setup(p_link->pmd_id, &port_config[i])) {
778                         printf("Failed to configure port %s - %"PRIu32
779                                ".\n", p_link->name, p_link->pmd_id);
780                         printf("Try again with offload disabled....\n");
781                         port_config[i].tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOOFFLOADS;
782                         if (ifm_port_setup (p_link->pmd_id, &port_config[i]))
783                             rte_panic("Port Setup Failed: %s - %" PRIu32
784                                         "\n", p_link->name, p_link->pmd_id);
785                 }
786
787                 app_link_up_internal(app, p_link);
788         }
789
790         app_check_link(app);
791 }
792
793 static void
794 app_init_swq(struct app_params *app)
795 {
796         uint32_t i;
797
798         for (i = 0; i < app->n_pktq_swq; i++) {
799                 struct app_pktq_swq_params *p = &app->swq_params[i];
800                 unsigned int flags = 0;
801
802                 if (app_swq_get_readers(app, p) == 1)
803                         flags |= RING_F_SC_DEQ;
804                 if (app_swq_get_writers(app, p) == 1)
805                         flags |= RING_F_SP_ENQ;
806
807                 APP_LOG(app, HIGH, "Initializing %s...", p->name);
808                 app->swq[i] = rte_ring_create(
809                                 p->name,
810                                 p->size,
811                                 p->cpu_socket_id,
812                                 flags);
813
814                 if (app->swq[i] == NULL)
815                         rte_panic("%s init error\n", p->name);
816         }
817 }
818
819 static void
820 app_init_tm(struct app_params *app)
821 {
822         uint32_t i;
823
824         for (i = 0; i < app->n_pktq_tm; i++) {
825                 struct app_pktq_tm_params *p_tm = &app->tm_params[i];
826                 struct app_link_params *p_link;
827                 struct rte_eth_link link_eth_params;
828                 struct rte_sched_port *sched;
829                 uint32_t n_subports, subport_id;
830                 int status;
831
832                 p_link = app_get_link_for_tm(app, p_tm);
833                 /* LINK */
834                 rte_eth_link_get(p_link->pmd_id, &link_eth_params);
835
836                 /* TM */
837                 p_tm->sched_port_params.name = p_tm->name;
838                 p_tm->sched_port_params.socket =
839                         app_get_cpu_socket_id(p_link->pmd_id);
840                 p_tm->sched_port_params.rate =
841                         (uint64_t) link_eth_params.link_speed * 1000 * 1000 / 8;
842
843                 APP_LOG(app, HIGH, "Initializing %s ...", p_tm->name);
844                 sched = rte_sched_port_config(&p_tm->sched_port_params);
845                 if (sched == NULL)
846                         rte_panic("%s init error\n", p_tm->name);
847                 app->tm[i] = sched;
848
849                 /* Subport */
850                 n_subports = p_tm->sched_port_params.n_subports_per_port;
851                 for (subport_id = 0; subport_id < n_subports; subport_id++) {
852                         uint32_t n_pipes_per_subport, pipe_id;
853
854                         status = rte_sched_subport_config(sched,
855                                 subport_id,
856                                 &p_tm->sched_subport_params[subport_id]);
857                         if (status)
858                                 rte_panic("%s subport %" PRIu32
859                                         " init error (%" PRId32 ")\n",
860                                         p_tm->name, subport_id, status);
861
862                         /* Pipe */
863                         n_pipes_per_subport =
864                                 p_tm->sched_port_params.n_pipes_per_subport;
865                         for (pipe_id = 0;
866                                 pipe_id < n_pipes_per_subport;
867                                 pipe_id++) {
868                                 int profile_id = p_tm->sched_pipe_to_profile[
869                                         subport_id * APP_MAX_SCHED_PIPES +
870                                         pipe_id];
871
872                                 if (profile_id == -1)
873                                         continue;
874
875                                 status = rte_sched_pipe_config(sched,
876                                         subport_id,
877                                         pipe_id,
878                                         profile_id);
879                                 if (status)
880                                         rte_panic("%s subport %" PRIu32
881                                                 " pipe %" PRIu32
882                                                 " (profile %" PRId32 ") "
883                                                 "init error (% " PRId32 ")\n",
884                                                 p_tm->name, subport_id, pipe_id,
885                                                 profile_id, status);
886                         }
887                 }
888         }
889 }
890
891 static void
892 app_init_msgq(struct app_params *app)
893 {
894         uint32_t i;
895
896         for (i = 0; i < app->n_msgq; i++) {
897                 struct app_msgq_params *p = &app->msgq_params[i];
898
899                 APP_LOG(app, HIGH, "Initializing %s ...", p->name);
900                 app->msgq[i] = rte_ring_create(
901                                 p->name,
902                                 p->size,
903                                 p->cpu_socket_id,
904                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
905
906                 if (app->msgq[i] == NULL)
907                         rte_panic("%s init error\n", p->name);
908         }
909 }
910
911 static void app_pipeline_params_get(struct app_params *app,
912         struct app_pipeline_params *p_in,
913         struct pipeline_params *p_out)
914 {
915         uint32_t i;
916         uint32_t mempool_id;
917
918         snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
919
920         p_out->socket_id = (int) p_in->socket_id;
921
922         p_out->log_level = app->log_level;
923
924         /* pktq_in */
925         p_out->n_ports_in = p_in->n_pktq_in;
926         for (i = 0; i < p_in->n_pktq_in; i++) {
927                 struct app_pktq_in_params *in = &p_in->pktq_in[i];
928                 struct pipeline_port_in_params *out = &p_out->port_in[i];
929
930                 switch (in->type) {
931                 case APP_PKTQ_IN_HWQ:
932                 {
933                         struct app_pktq_hwq_in_params *p_hwq_in =
934                                 &app->hwq_in_params[in->id];
935                         struct app_link_params *p_link =
936                                 app_get_link_for_rxq(app, p_hwq_in);
937                         uint32_t rxq_link_id, rxq_queue_id;
938
939                         int status =
940                         sscanf(p_hwq_in->name, "RXQ%" SCNu32 ".%" SCNu32,
941                                 &rxq_link_id,
942                                 &rxq_queue_id);
943                         if (status < 0)
944                                 rte_panic("%s (%" PRId32 "): "
945                                 "init error (%" PRId32 ")\n",
946                                 p_hwq_in->name, rxq_link_id, status);
947
948                         out->type = PIPELINE_PORT_IN_ETHDEV_READER;
949                         out->params.ethdev.port_id = p_link->pmd_id;
950                         out->params.ethdev.queue_id = rxq_queue_id;
951                         out->burst_size = p_hwq_in->burst;
952                         break;
953                 }
954                 case APP_PKTQ_IN_SWQ:
955                 {
956                         struct app_pktq_swq_params *swq_params =
957                                 &app->swq_params[in->id];
958
959                         if ((swq_params->ipv4_frag == 0) &&
960                                 (swq_params->ipv6_frag == 0)) {
961                                 if (app_swq_get_readers(app,
962                                         swq_params) == 1) {
963                                         out->type =
964                                                 PIPELINE_PORT_IN_RING_READER;
965                                         out->params.ring.ring =
966                                                 app->swq[in->id];
967                                         out->burst_size =
968                                                 app->swq_params[in->id].
969                                                         burst_read;
970                                 } else {
971                                 out->type = PIPELINE_PORT_IN_RING_MULTI_READER;
972                                 out->params.ring_multi.ring = app->swq[in->id];
973                                 out->burst_size = swq_params->burst_read;
974                                 }
975                         } else {
976                                 if (swq_params->ipv4_frag == 1) {
977                                 struct rte_port_ring_reader_ipv4_frag_params
978                                         *params =
979                                                 &out->params.ring_ipv4_frag;
980
981                                 out->type =
982                                         PIPELINE_PORT_IN_RING_READER_IPV4_FRAG;
983                                 params->ring = app->swq[in->id];
984                                 params->mtu = swq_params->mtu;
985                                 params->metadata_size =
986                                         swq_params->metadata_size;
987                                 params->pool_direct =
988                                         app->mempool
989                                         [swq_params->mempool_direct_id];
990                                 params->pool_indirect =
991                                         app->mempool
992                                         [swq_params->mempool_indirect_id];
993                                 out->burst_size = swq_params->burst_read;
994                                 } else {
995                                 struct rte_port_ring_reader_ipv6_frag_params
996                                         *params =
997                                                 &out->params.ring_ipv6_frag;
998
999                                 out->type =
1000                                         PIPELINE_PORT_IN_RING_READER_IPV6_FRAG;
1001                                 params->ring = app->swq[in->id];
1002                                 params->mtu = swq_params->mtu;
1003                                 params->metadata_size =
1004                                         swq_params->metadata_size;
1005                                 params->pool_direct =
1006                                         app->mempool
1007                                         [swq_params->mempool_direct_id];
1008                                 params->pool_indirect =
1009                                         app->mempool
1010                                         [swq_params->mempool_indirect_id];
1011                                 out->burst_size = swq_params->burst_read;
1012                                 }
1013                         }
1014                         break;
1015                 }
1016                 case APP_PKTQ_IN_TM:
1017                         out->type = PIPELINE_PORT_IN_SCHED_READER;
1018                         out->params.sched.sched = app->tm[in->id];
1019                         out->burst_size = app->tm_params[in->id].burst_read;
1020                         break;
1021                 case APP_PKTQ_IN_SOURCE:
1022                         mempool_id = app->source_params[in->id].mempool_id;
1023                         out->type = PIPELINE_PORT_IN_SOURCE;
1024                         out->params.source.mempool = app->mempool[mempool_id];
1025                         out->burst_size = app->source_params[in->id].burst;
1026
1027 #ifdef RTE_NEXT_ABI
1028                         if (app->source_params[in->id].file_name
1029                                 != NULL) {
1030                                 out->params.source.file_name = strdup(
1031                                         app->source_params[in->id].
1032                                         file_name);
1033                                 if (out->params.source.file_name == NULL) {
1034                                         out->params.source.
1035                                                 n_bytes_per_pkt = 0;
1036                                         break;
1037                                 }
1038                                 out->params.source.n_bytes_per_pkt =
1039                                         app->source_params[in->id].
1040                                         n_bytes_per_pkt;
1041                         }
1042 #endif
1043
1044                         break;
1045                 default:
1046                         break;
1047                 }
1048         }
1049
1050         /* pktq_out */
1051         p_out->n_ports_out = p_in->n_pktq_out;
1052         for (i = 0; i < p_in->n_pktq_out; i++) {
1053                 struct app_pktq_out_params *in = &p_in->pktq_out[i];
1054                 struct pipeline_port_out_params *out = &p_out->port_out[i];
1055
1056                 switch (in->type) {
1057                 case APP_PKTQ_OUT_HWQ:
1058                 {
1059                         struct app_pktq_hwq_out_params *p_hwq_out =
1060                                 &app->hwq_out_params[in->id];
1061                         struct app_link_params *p_link =
1062                                 app_get_link_for_txq(app, p_hwq_out);
1063                         uint32_t txq_link_id, txq_queue_id;
1064
1065                         int status =
1066                         sscanf(p_hwq_out->name,
1067                                 "TXQ%" SCNu32 ".%" SCNu32,
1068                                 &txq_link_id,
1069                                 &txq_queue_id);
1070                         if (status < 0)
1071                                 rte_panic("%s (%" PRId32 "): "
1072                                 "init error (%" PRId32 ")\n",
1073                                 p_hwq_out->name, txq_link_id, status);
1074
1075                         if (p_hwq_out->dropless == 0) {
1076                                 struct rte_port_ethdev_writer_params *params =
1077                                         &out->params.ethdev;
1078
1079                                 out->type = PIPELINE_PORT_OUT_ETHDEV_WRITER;
1080                                 params->port_id = p_link->pmd_id;
1081                                 params->queue_id = txq_queue_id;
1082                                 params->tx_burst_sz =
1083                                         app->hwq_out_params[in->id].burst;
1084                         } else {
1085                                 struct rte_port_ethdev_writer_nodrop_params
1086                                         *params = &out->params.ethdev_nodrop;
1087
1088                                 out->type =
1089                                         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP;
1090                                 params->port_id = p_link->pmd_id;
1091                                 params->queue_id = txq_queue_id;
1092                                 params->tx_burst_sz = p_hwq_out->burst;
1093                                 params->n_retries = p_hwq_out->n_retries;
1094                         }
1095                         break;
1096                 }
1097                 case APP_PKTQ_OUT_SWQ:
1098                 {
1099                 struct app_pktq_swq_params *swq_params =
1100                         &app->swq_params[in->id];
1101
1102                 if ((swq_params->ipv4_ras == 0) &&
1103                         (swq_params->ipv6_ras == 0)) {
1104                         if (app_swq_get_writers(app, swq_params) == 1) {
1105                                 if (app->swq_params[in->id].dropless == 0) {
1106                                         struct rte_port_ring_writer_params
1107                                                 *params = &out->params.ring;
1108
1109                                 out->type = PIPELINE_PORT_OUT_RING_WRITER;
1110                                 params->ring = app->swq[in->id];
1111                                 params->tx_burst_sz =
1112                                         app->swq_params[in->id].burst_write;
1113                                 } else {
1114                                 struct rte_port_ring_writer_nodrop_params
1115                                         *params = &out->params.ring_nodrop;
1116
1117                                 out->type =
1118                                         PIPELINE_PORT_OUT_RING_WRITER_NODROP;
1119                                 params->ring = app->swq[in->id];
1120                                 params->tx_burst_sz =
1121                                         app->swq_params[in->id].burst_write;
1122                                 params->n_retries =
1123                                 app->swq_params[in->id].n_retries;
1124                                 }
1125                         } else {
1126                                 if (swq_params->dropless == 0) {
1127                                         struct rte_port_ring_multi_writer_params
1128                                                 *params =
1129                                                 &out->params.ring_multi;
1130
1131                                 out->type =
1132                                         PIPELINE_PORT_OUT_RING_MULTI_WRITER;
1133                                 params->ring = app->swq[in->id];
1134                                 params->tx_burst_sz = swq_params->burst_write;
1135                                 } else {
1136                                 struct rte_port_ring_multi_writer_nodrop_params
1137                                         *params =
1138                                                 &out->params.ring_multi_nodrop;
1139
1140                                 out->type =
1141                                 PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP;
1142
1143                                 params->ring = app->swq[in->id];
1144                                 params->tx_burst_sz = swq_params->burst_write;
1145                                 params->n_retries = swq_params->n_retries;
1146                                 }
1147                                 }
1148                         } else {
1149                         if (swq_params->ipv4_ras == 1) {
1150                                 struct rte_port_ring_writer_ipv4_ras_params
1151                                         *params =
1152                                                 &out->params.ring_ipv4_ras;
1153
1154                                 out->type =
1155                                         PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS;
1156                                 params->ring = app->swq[in->id];
1157                                 params->tx_burst_sz = swq_params->burst_write;
1158                         } else {
1159                                 struct rte_port_ring_writer_ipv6_ras_params
1160                                         *params =
1161                                                 &out->params.ring_ipv6_ras;
1162
1163                                 out->type =
1164                                         PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS;
1165                                 params->ring = app->swq[in->id];
1166                                 params->tx_burst_sz = swq_params->burst_write;
1167                         }
1168                         }
1169                         break;
1170                 }
1171                 case APP_PKTQ_OUT_TM: {
1172                         struct rte_port_sched_writer_params *params =
1173                                 &out->params.sched;
1174
1175                         out->type = PIPELINE_PORT_OUT_SCHED_WRITER;
1176                         params->sched = app->tm[in->id];
1177                         params->tx_burst_sz =
1178                                 app->tm_params[in->id].burst_write;
1179                         break;
1180                 }
1181                 case APP_PKTQ_OUT_SINK:
1182                         out->type = PIPELINE_PORT_OUT_SINK;
1183                         if (app->sink_params[in->id].file_name != NULL) {
1184                                 out->params.sink.file_name = strdup(
1185                                         app->sink_params[in->id].
1186                                         file_name);
1187                                 if (out->params.sink.file_name == NULL) {
1188                                         out->params.sink.max_n_pkts = 0;
1189                                         break;
1190                                 }
1191                                 out->params.sink.max_n_pkts =
1192                                         app->sink_params[in->id].
1193                                         n_pkts_to_dump;
1194                         } else {
1195                                 out->params.sink.file_name = NULL;
1196                                 out->params.sink.max_n_pkts = 0;
1197                         }
1198                         break;
1199                 default:
1200                         break;
1201                 }
1202         }
1203
1204         /* msgq */
1205         p_out->n_msgq = p_in->n_msgq_in;
1206
1207         for (i = 0; i < p_in->n_msgq_in; i++)
1208                 p_out->msgq_in[i] = app->msgq[p_in->msgq_in[i]];
1209
1210         for (i = 0; i < p_in->n_msgq_out; i++)
1211                 p_out->msgq_out[i] = app->msgq[p_in->msgq_out[i]];
1212
1213         /* args */
1214         p_out->n_args = p_in->n_args;
1215         for (i = 0; i < p_in->n_args; i++) {
1216                 p_out->args_name[i] = p_in->args_name[i];
1217                 p_out->args_value[i] = p_in->args_value[i];
1218         }
1219 }
1220
1221 static void
1222 app_init_pipelines(struct app_params *app)
1223 {
1224         uint32_t p_id;
1225
1226         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1227                 struct app_pipeline_params *params =
1228                         &app->pipeline_params[p_id];
1229                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1230                 struct pipeline_type *ptype;
1231                 struct pipeline_params pp;
1232
1233                 APP_LOG(app, HIGH, "Initializing %s ...", params->name);
1234
1235                 ptype = app_pipeline_type_find(app, params->type);
1236                 if (ptype == NULL)
1237                         rte_panic("Init error: Unknown pipeline type \"%s\"\n",
1238                                 params->type);
1239
1240                 app_pipeline_params_get(app, params, &pp);
1241
1242                 /* Back-end */
1243                 data->be = NULL;
1244                 if (ptype->be_ops->f_init) {
1245                         data->be = ptype->be_ops->f_init(&pp, (void *) app);
1246
1247                         if (data->be == NULL)
1248                                 rte_panic("Pipeline instance \"%s\" back-end "
1249                                         "init error\n", params->name);
1250                 }
1251
1252                 /* Front-end */
1253                 data->fe = NULL;
1254                 if (ptype->fe_ops->f_init) {
1255                         data->fe = ptype->fe_ops->f_init(&pp, (void *) app);
1256
1257                         if (data->fe == NULL)
1258                                 rte_panic("Pipeline instance \"%s\" front-end "
1259                                 "init error\n", params->name);
1260                 }
1261
1262                 data->ptype = ptype;
1263
1264                 data->timer_period = (rte_get_tsc_hz() *
1265                         params->timer_period) / 100;
1266         }
1267 }
1268
1269 static void
1270 app_init_threads(struct app_params *app)
1271 {
1272         uint64_t time = rte_get_tsc_cycles();
1273         uint32_t p_id;
1274
1275         for (p_id = 0; p_id < app->n_pipelines; p_id++) {
1276                 struct app_pipeline_params *params =
1277                         &app->pipeline_params[p_id];
1278                 struct app_pipeline_data *data = &app->pipeline_data[p_id];
1279                 struct pipeline_type *ptype;
1280                 struct app_thread_data *t;
1281                 struct app_thread_pipeline_data *p;
1282                 int lcore_id;
1283
1284                 lcore_id = cpu_core_map_get_lcore_id(app->core_map,
1285                         params->socket_id,
1286                         params->core_id,
1287                         params->hyper_th_id);
1288
1289                 if (lcore_id < 0)
1290                         rte_panic("Invalid core s%" PRIu32 "c%" PRIu32 "%s\n",
1291                                 params->socket_id,
1292                                 params->core_id,
1293                                 (params->hyper_th_id) ? "h" : "");
1294
1295                 t = &app->thread_data[lcore_id];
1296
1297                 t->timer_period = (rte_get_tsc_hz() *
1298                         APP_THREAD_TIMER_PERIOD) / DIV_CONV_HZ_SEC;
1299                 t->thread_req_deadline = time + t->timer_period;
1300
1301                 t->headroom_cycles = 0;
1302                 t->headroom_time = rte_get_tsc_cycles();
1303                 t->headroom_ratio = 0.0;
1304
1305                 t->msgq_in = app_thread_msgq_in_get(app,
1306                                 params->socket_id,
1307                                 params->core_id,
1308                                 params->hyper_th_id);
1309                 if (t->msgq_in == NULL)
1310                         rte_panic("Init error: Cannot find MSGQ_IN "
1311                                 "for thread %" PRId32, lcore_id);
1312
1313                 t->msgq_out = app_thread_msgq_out_get(app,
1314                                 params->socket_id,
1315                                 params->core_id,
1316                                 params->hyper_th_id);
1317                 if (t->msgq_out == NULL)
1318                         rte_panic("Init error: Cannot find MSGQ_OUT "
1319                                 "for thread %" PRId32, lcore_id);
1320
1321                 ptype = app_pipeline_type_find(app, params->type);
1322                 if (ptype == NULL)
1323                         rte_panic("Init error: Unknown pipeline "
1324                                 "type \"%s\"\n", params->type);
1325
1326                 p = (ptype->be_ops->f_run == NULL) ?
1327                         &t->regular[t->n_regular] :
1328                         &t->custom[t->n_custom];
1329
1330                 p->pipeline_id = p_id;
1331                 p->be = data->be;
1332                 p->f_run = ptype->be_ops->f_run;
1333                 p->f_timer = ptype->be_ops->f_timer;
1334                 p->timer_period = data->timer_period;
1335                 p->deadline = time + data->timer_period;
1336
1337                 data->enabled = 1;
1338
1339                 if (ptype->be_ops->f_run == NULL)
1340                         t->n_regular++;
1341                 else
1342                         t->n_custom++;
1343         }
1344 }
1345
1346 int app_init(struct app_params *app)
1347 {
1348         app_init_core_map(app);
1349         app_init_core_mask(app);
1350
1351         app_init_eal(app);
1352         ifm_init();
1353         /*app_init_mempool(app);*/
1354         app_init_link(app);
1355         app_init_swq(app);
1356         app_init_tm(app);
1357         app_init_msgq(app);
1358
1359         app_pipeline_common_cmd_push(app);
1360         app_pipeline_thread_cmd_push(app);
1361         app_pipeline_type_register(app, &pipeline_master);
1362         app_pipeline_type_register(app, &pipeline_passthrough);
1363         app_pipeline_type_register(app, &pipeline_vfw);
1364         app_pipeline_type_register(app, &pipeline_loadb);
1365         app_pipeline_type_register(app, &pipeline_txrx);
1366         app_pipeline_type_register(app, &pipeline_arpicmp);
1367
1368         app_init_pipelines(app);
1369         app_init_threads(app);
1370
1371         l3fwd_init();
1372         create_arp_table();
1373         create_nd_table();
1374         populate_lpm_routes();
1375         print_interface_details();
1376
1377         return 0;
1378 }
1379
1380 static int
1381 app_pipeline_type_cmd_push(struct app_params *app,
1382         struct pipeline_type *ptype)
1383 {
1384         cmdline_parse_ctx_t *cmds;
1385         uint32_t n_cmds, i;
1386
1387         /* Check input arguments */
1388         if ((app == NULL) ||
1389                 (ptype == NULL))
1390                 return -EINVAL;
1391
1392         n_cmds = pipeline_type_cmds_count(ptype);
1393         if (n_cmds == 0)
1394                 return 0;
1395
1396         cmds = ptype->fe_ops->cmds;
1397
1398         /* Check for available slots in the application commands array */
1399         if (n_cmds > APP_MAX_CMDS - app->n_cmds)
1400                 return -ENOMEM;
1401
1402         /* Push pipeline commands into the application */
1403         memcpy(&app->cmds[app->n_cmds],
1404                 cmds,
1405                 n_cmds * sizeof(cmdline_parse_ctx_t));
1406
1407         for (i = 0; i < n_cmds; i++)
1408                 app->cmds[app->n_cmds + i]->data = app;
1409
1410         app->n_cmds += n_cmds;
1411         app->cmds[app->n_cmds] = NULL;
1412
1413         return 0;
1414 }
1415
1416 int
1417 app_pipeline_type_register(struct app_params *app, struct pipeline_type *ptype)
1418 {
1419         uint32_t n_cmds, i;
1420
1421         /* Check input arguments */
1422         if ((app == NULL) ||
1423                 (ptype == NULL) ||
1424                 (ptype->name == NULL) ||
1425                 (strlen(ptype->name) == 0) ||
1426                 (ptype->be_ops->f_init == NULL) ||
1427                 (ptype->be_ops->f_timer == NULL))
1428                 return -EINVAL;
1429
1430         /* Check for duplicate entry */
1431         for (i = 0; i < app->n_pipeline_types; i++)
1432                 if (strcmp(app->pipeline_type[i].name, ptype->name) == 0)
1433                         return -EEXIST;
1434
1435         /* Check for resource availability */
1436         n_cmds = pipeline_type_cmds_count(ptype);
1437         if ((app->n_pipeline_types == APP_MAX_PIPELINE_TYPES) ||
1438                 (n_cmds > APP_MAX_CMDS - app->n_cmds))
1439                 return -ENOMEM;
1440
1441         /* Copy pipeline type */
1442         memcpy(&app->pipeline_type[app->n_pipeline_types++],
1443                 ptype,
1444                 sizeof(struct pipeline_type));
1445
1446         /* Copy CLI commands */
1447         if (n_cmds)
1448                 app_pipeline_type_cmd_push(app, ptype);
1449
1450         return 0;
1451 }
1452
1453 struct
1454 pipeline_type *app_pipeline_type_find(struct app_params *app, char *name)
1455 {
1456         uint32_t i;
1457
1458         for (i = 0; i < app->n_pipeline_types; i++)
1459                 if (strcmp(app->pipeline_type[i].name, name) == 0)
1460                         return &app->pipeline_type[i];
1461
1462         return NULL;
1463 }