test/table: fix memory leak
[dpdk.git] / examples / ip_pipeline / app.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4
5 #ifndef __INCLUDE_APP_H__
6 #define __INCLUDE_APP_H__
7
8 #include <stdint.h>
9 #include <string.h>
10
11 #include <rte_common.h>
12 #include <rte_mempool.h>
13 #include <rte_ring.h>
14 #include <rte_sched.h>
15 #include <cmdline_parse.h>
16
17 #include <rte_ethdev.h>
18 #ifdef RTE_LIBRTE_KNI
19 #include <rte_kni.h>
20 #endif
21
22 #include "cpu_core_map.h"
23 #include "pipeline.h"
24
25 #define APP_PARAM_NAME_SIZE                      PIPELINE_NAME_SIZE
26 #define APP_LINK_PCI_BDF_SIZE                    16
27
28 #ifndef APP_LINK_MAX_HWQ_IN
29 #define APP_LINK_MAX_HWQ_IN                      128
30 #endif
31
32 #ifndef APP_LINK_MAX_HWQ_OUT
33 #define APP_LINK_MAX_HWQ_OUT                     128
34 #endif
35
36 struct app_mempool_params {
37         char *name;
38         uint32_t parsed;
39         uint32_t buffer_size;
40         uint32_t pool_size;
41         uint32_t cache_size;
42         uint32_t cpu_socket_id;
43 };
44
45 struct app_link_params {
46         char *name;
47         uint32_t parsed;
48         uint32_t pmd_id; /* Generated based on port mask */
49         uint32_t arp_q; /* 0 = Disabled (packets go to default queue 0) */
50         uint32_t tcp_syn_q; /* 0 = Disabled (pkts go to default queue) */
51         uint32_t ip_local_q; /* 0 = Disabled (pkts go to default queue 0) */
52         uint32_t tcp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
53         uint32_t udp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
54         uint32_t sctp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
55         uint32_t rss_qs[APP_LINK_MAX_HWQ_IN];
56         uint32_t n_rss_qs;
57         uint64_t rss_proto_ipv4;
58         uint64_t rss_proto_ipv6;
59         uint64_t rss_proto_l2;
60         uint32_t promisc;
61         uint32_t state; /* DOWN = 0, UP = 1 */
62         uint32_t ip; /* 0 = Invalid */
63         uint32_t depth; /* Valid only when IP is valid */
64         uint64_t mac_addr; /* Read from HW */
65         char pci_bdf[APP_LINK_PCI_BDF_SIZE];
66
67         struct rte_eth_conf conf;
68 };
69
70 struct app_pktq_hwq_in_params {
71         char *name;
72         uint32_t parsed;
73         uint32_t mempool_id; /* Position in the app->mempool_params */
74         uint32_t size;
75         uint32_t burst;
76
77         struct rte_eth_rxconf conf;
78 };
79
80 struct app_pktq_hwq_out_params {
81         char *name;
82         uint32_t parsed;
83         uint32_t size;
84         uint32_t burst;
85         uint32_t dropless;
86         uint64_t n_retries;
87         struct rte_eth_txconf conf;
88 };
89
90 struct app_pktq_swq_params {
91         char *name;
92         uint32_t parsed;
93         uint32_t size;
94         uint32_t burst_read;
95         uint32_t burst_write;
96         uint32_t dropless;
97         uint64_t n_retries;
98         uint32_t cpu_socket_id;
99         uint32_t ipv4_frag;
100         uint32_t ipv6_frag;
101         uint32_t ipv4_ras;
102         uint32_t ipv6_ras;
103         uint32_t mtu;
104         uint32_t metadata_size;
105         uint32_t mempool_direct_id;
106         uint32_t mempool_indirect_id;
107 };
108
109 struct app_pktq_kni_params {
110         char *name;
111         uint32_t parsed;
112
113         uint32_t socket_id;
114         uint32_t core_id;
115         uint32_t hyper_th_id;
116         uint32_t force_bind;
117
118         uint32_t mempool_id; /* Position in the app->mempool_params */
119         uint32_t burst_read;
120         uint32_t burst_write;
121         uint32_t dropless;
122         uint64_t n_retries;
123 };
124
125 #ifndef APP_FILE_NAME_SIZE
126 #define APP_FILE_NAME_SIZE                       256
127 #endif
128
129 #ifndef APP_MAX_SCHED_SUBPORTS
130 #define APP_MAX_SCHED_SUBPORTS                   8
131 #endif
132
133 #ifndef APP_MAX_SCHED_PIPES
134 #define APP_MAX_SCHED_PIPES                      4096
135 #endif
136
137 struct app_pktq_tm_params {
138         char *name;
139         uint32_t parsed;
140         const char *file_name;
141         struct rte_sched_port_params sched_port_params;
142         struct rte_sched_subport_params
143                 sched_subport_params[APP_MAX_SCHED_SUBPORTS];
144         struct rte_sched_pipe_params
145                 sched_pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
146         int sched_pipe_to_profile[APP_MAX_SCHED_SUBPORTS * APP_MAX_SCHED_PIPES];
147         uint32_t burst_read;
148         uint32_t burst_write;
149 };
150
151 struct app_pktq_tap_params {
152         char *name;
153         uint32_t parsed;
154         uint32_t burst_read;
155         uint32_t burst_write;
156         uint32_t dropless;
157         uint64_t n_retries;
158         uint32_t mempool_id; /* Position in the app->mempool_params */
159 };
160
161 struct app_pktq_source_params {
162         char *name;
163         uint32_t parsed;
164         uint32_t mempool_id; /* Position in the app->mempool_params array */
165         uint32_t burst;
166         const char *file_name; /* Full path of PCAP file to be copied to mbufs */
167         uint32_t n_bytes_per_pkt;
168 };
169
170 struct app_pktq_sink_params {
171         char *name;
172         uint8_t parsed;
173         const char *file_name; /* Full path of PCAP file to be copied to mbufs */
174         uint32_t n_pkts_to_dump;
175 };
176
177 struct app_msgq_params {
178         char *name;
179         uint32_t parsed;
180         uint32_t size;
181         uint32_t cpu_socket_id;
182 };
183
184 enum app_pktq_in_type {
185         APP_PKTQ_IN_HWQ,
186         APP_PKTQ_IN_SWQ,
187         APP_PKTQ_IN_TM,
188         APP_PKTQ_IN_TAP,
189         APP_PKTQ_IN_KNI,
190         APP_PKTQ_IN_SOURCE,
191 };
192
193 struct app_pktq_in_params {
194         enum app_pktq_in_type type;
195         uint32_t id; /* Position in the appropriate app array */
196 };
197
198 enum app_pktq_out_type {
199         APP_PKTQ_OUT_HWQ,
200         APP_PKTQ_OUT_SWQ,
201         APP_PKTQ_OUT_TM,
202         APP_PKTQ_OUT_TAP,
203         APP_PKTQ_OUT_KNI,
204         APP_PKTQ_OUT_SINK,
205 };
206
207 struct app_pktq_out_params {
208         enum app_pktq_out_type type;
209         uint32_t id; /* Position in the appropriate app array */
210 };
211
212 #define APP_PIPELINE_TYPE_SIZE                   PIPELINE_TYPE_SIZE
213
214 #define APP_MAX_PIPELINE_PKTQ_IN                 PIPELINE_MAX_PORT_IN
215 #define APP_MAX_PIPELINE_PKTQ_OUT                PIPELINE_MAX_PORT_OUT
216 #define APP_MAX_PIPELINE_MSGQ_IN                 PIPELINE_MAX_MSGQ_IN
217 #define APP_MAX_PIPELINE_MSGQ_OUT                PIPELINE_MAX_MSGQ_OUT
218
219 #define APP_MAX_PIPELINE_ARGS                    PIPELINE_MAX_ARGS
220
221 struct app_pipeline_params {
222         char *name;
223         uint8_t parsed;
224
225         char type[APP_PIPELINE_TYPE_SIZE];
226
227         uint32_t socket_id;
228         uint32_t core_id;
229         uint32_t hyper_th_id;
230
231         struct app_pktq_in_params pktq_in[APP_MAX_PIPELINE_PKTQ_IN];
232         struct app_pktq_out_params pktq_out[APP_MAX_PIPELINE_PKTQ_OUT];
233         uint32_t msgq_in[APP_MAX_PIPELINE_MSGQ_IN];
234         uint32_t msgq_out[APP_MAX_PIPELINE_MSGQ_OUT];
235
236         uint32_t n_pktq_in;
237         uint32_t n_pktq_out;
238         uint32_t n_msgq_in;
239         uint32_t n_msgq_out;
240
241         uint32_t timer_period;
242
243         char *args_name[APP_MAX_PIPELINE_ARGS];
244         char *args_value[APP_MAX_PIPELINE_ARGS];
245         uint32_t n_args;
246 };
247
248 struct app_params;
249
250 typedef void (*app_link_op)(struct app_params *app,
251         uint32_t link_id,
252         uint32_t up,
253         void *arg);
254
255 #ifndef APP_MAX_PIPELINES
256 #define APP_MAX_PIPELINES                        64
257 #endif
258
259 struct app_link_data {
260         app_link_op f_link[APP_MAX_PIPELINES];
261         void *arg[APP_MAX_PIPELINES];
262 };
263
264 struct app_pipeline_data {
265         void *be;
266         void *fe;
267         struct pipeline_type *ptype;
268         uint64_t timer_period;
269         uint32_t enabled;
270 };
271
272 struct app_thread_pipeline_data {
273         uint32_t pipeline_id;
274         void *be;
275         pipeline_be_op_run f_run;
276         pipeline_be_op_timer f_timer;
277         uint64_t timer_period;
278         uint64_t deadline;
279 };
280
281 #ifndef APP_MAX_THREAD_PIPELINES
282 #define APP_MAX_THREAD_PIPELINES                 64
283 #endif
284
285 #ifndef APP_THREAD_TIMER_PERIOD
286 #define APP_THREAD_TIMER_PERIOD                  1
287 #endif
288
289 struct app_thread_data {
290         struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
291         struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
292
293         uint32_t n_regular;
294         uint32_t n_custom;
295
296         uint64_t timer_period;
297         uint64_t thread_req_deadline;
298
299         uint64_t deadline;
300
301         struct rte_ring *msgq_in;
302         struct rte_ring *msgq_out;
303
304         uint64_t headroom_time;
305         uint64_t headroom_cycles;
306         double headroom_ratio;
307 } __rte_cache_aligned;
308
309 #ifndef APP_MAX_LINKS
310 #define APP_MAX_LINKS                            16
311 #endif
312
313 struct app_eal_params {
314         /* Map lcore set to physical cpu set */
315         char *coremap;
316
317         /* Core ID that is used as master */
318         uint32_t master_lcore_present;
319         uint32_t master_lcore;
320
321         /* Number of memory channels */
322         uint32_t channels_present;
323         uint32_t channels;
324
325         /* Memory to allocate (see also --socket-mem) */
326         uint32_t memory_present;
327         uint32_t memory;
328
329         /* Force number of memory ranks (don't detect) */
330         uint32_t ranks_present;
331         uint32_t ranks;
332
333         /* Add a PCI device in black list. */
334         char *pci_blacklist[APP_MAX_LINKS];
335
336         /* Add a PCI device in white list. */
337         char *pci_whitelist[APP_MAX_LINKS];
338
339         /* Add a virtual device. */
340         char *vdev[APP_MAX_LINKS];
341
342          /* Use VMware TSC map instead of native RDTSC */
343         uint32_t vmware_tsc_map_present;
344         int vmware_tsc_map;
345
346          /* Type of this process (primary|secondary|auto) */
347         char *proc_type;
348
349          /* Set syslog facility */
350         char *syslog;
351
352         /* Set default log level */
353         uint32_t log_level_present;
354         uint32_t log_level;
355
356         /* Display version information on startup */
357         uint32_t version_present;
358         int version;
359
360         /* This help */
361         uint32_t help_present;
362         int help;
363
364          /* Use malloc instead of hugetlbfs */
365         uint32_t no_huge_present;
366         int no_huge;
367
368         /* Disable PCI */
369         uint32_t no_pci_present;
370         int no_pci;
371
372         /* Disable HPET */
373         uint32_t no_hpet_present;
374         int no_hpet;
375
376         /* No shared config (mmap'd files) */
377         uint32_t no_shconf_present;
378         int no_shconf;
379
380         /* Add driver */
381         char *add_driver;
382
383         /*  Memory to allocate on sockets (comma separated values)*/
384         char *socket_mem;
385
386         /* Directory where hugetlbfs is mounted */
387         char *huge_dir;
388
389         /* Prefix for hugepage filenames */
390         char *file_prefix;
391
392         /* Base virtual address */
393         char *base_virtaddr;
394
395         /* Create /dev/uioX (usually done by hotplug) */
396         uint32_t create_uio_dev_present;
397         int create_uio_dev;
398
399         /* Interrupt mode for VFIO (legacy|msi|msix) */
400         char *vfio_intr;
401
402         uint32_t parsed;
403 };
404
405 #ifndef APP_APPNAME_SIZE
406 #define APP_APPNAME_SIZE                         256
407 #endif
408
409 #ifndef APP_MAX_MEMPOOLS
410 #define APP_MAX_MEMPOOLS                         8
411 #endif
412
413 #define APP_MAX_HWQ_IN                  (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
414
415 #define APP_MAX_HWQ_OUT                 (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
416
417 #ifndef APP_MAX_PKTQ_SWQ
418 #define APP_MAX_PKTQ_SWQ                         256
419 #endif
420
421 #define APP_MAX_PKTQ_TM                          APP_MAX_LINKS
422
423 #ifndef APP_MAX_PKTQ_TAP
424 #define APP_MAX_PKTQ_TAP                         APP_MAX_LINKS
425 #endif
426
427 #define APP_MAX_PKTQ_KNI                         APP_MAX_LINKS
428
429 #ifndef APP_MAX_PKTQ_SOURCE
430 #define APP_MAX_PKTQ_SOURCE                      64
431 #endif
432
433 #ifndef APP_MAX_PKTQ_SINK
434 #define APP_MAX_PKTQ_SINK                        64
435 #endif
436
437 #ifndef APP_MAX_MSGQ
438 #define APP_MAX_MSGQ                             256
439 #endif
440
441 #ifndef APP_EAL_ARGC
442 #define APP_EAL_ARGC                             64
443 #endif
444
445 #ifndef APP_MAX_PIPELINE_TYPES
446 #define APP_MAX_PIPELINE_TYPES                   64
447 #endif
448
449 #ifndef APP_MAX_THREADS
450 #define APP_MAX_THREADS                          RTE_MAX_LCORE
451 #endif
452
453 #ifndef APP_MAX_CMDS
454 #define APP_MAX_CMDS                             64
455 #endif
456
457 #ifndef APP_THREAD_HEADROOM_STATS_COLLECT
458 #define APP_THREAD_HEADROOM_STATS_COLLECT        1
459 #endif
460
461 #define APP_CORE_MASK_SIZE                                      \
462         (RTE_MAX_LCORE / 64 + ((RTE_MAX_LCORE % 64) ? 1 : 0))
463
464 struct app_params {
465         /* Config */
466         char app_name[APP_APPNAME_SIZE];
467         const char *config_file;
468         const char *script_file;
469         const char *parser_file;
470         const char *output_file;
471         const char *preproc;
472         const char *preproc_args;
473         uint64_t port_mask;
474         uint32_t log_level;
475
476         struct app_eal_params eal_params;
477         struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
478         struct app_link_params link_params[APP_MAX_LINKS];
479         struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
480         struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
481         struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
482         struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
483         struct app_pktq_tap_params tap_params[APP_MAX_PKTQ_TAP];
484         struct app_pktq_kni_params kni_params[APP_MAX_PKTQ_KNI];
485         struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
486         struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
487         struct app_msgq_params msgq_params[APP_MAX_MSGQ];
488         struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
489
490         uint32_t n_mempools;
491         uint32_t n_links;
492         uint32_t n_pktq_hwq_in;
493         uint32_t n_pktq_hwq_out;
494         uint32_t n_pktq_swq;
495         uint32_t n_pktq_tm;
496         uint32_t n_pktq_tap;
497         uint32_t n_pktq_kni;
498         uint32_t n_pktq_source;
499         uint32_t n_pktq_sink;
500         uint32_t n_msgq;
501         uint32_t n_pipelines;
502
503         /* Init */
504         char *eal_argv[1 + APP_EAL_ARGC];
505         struct cpu_core_map *core_map;
506         uint64_t core_mask[APP_CORE_MASK_SIZE];
507         struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
508         struct app_link_data link_data[APP_MAX_LINKS];
509         struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
510         struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
511         int tap[APP_MAX_PKTQ_TAP];
512 #ifdef RTE_LIBRTE_KNI
513         struct rte_kni *kni[APP_MAX_PKTQ_KNI];
514 #endif /* RTE_LIBRTE_KNI */
515         struct rte_ring *msgq[APP_MAX_MSGQ];
516         struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
517         struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
518         struct app_thread_data thread_data[APP_MAX_THREADS];
519         cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
520
521         int eal_argc;
522         uint32_t n_pipeline_types;
523         uint32_t n_cmds;
524 };
525
526 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
527
528 #define APP_PARAM_COUNT(obj_array, n_objs)                              \
529 {                                                                       \
530         size_t i;                                                       \
531                                                                         \
532         n_objs = 0;                                                     \
533         for (i = 0; i < RTE_DIM(obj_array); i++)                        \
534                 if (APP_PARAM_VALID(&((obj_array)[i])))                 \
535                         n_objs++;                                       \
536 }
537
538 #define APP_PARAM_FIND(obj_array, key)                                  \
539 ({                                                                      \
540         ssize_t obj_idx;                                                \
541         const ssize_t obj_count = RTE_DIM(obj_array);                   \
542                                                                         \
543         for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {             \
544                 if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
545                         continue;                                       \
546                                                                         \
547                 if (strcmp(key, (obj_array)[obj_idx].name) == 0)        \
548                         break;                                          \
549         }                                                               \
550         obj_idx < obj_count ? obj_idx : -ENOENT;                        \
551 })
552
553 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj)                \
554 do {                                                                    \
555         char name[APP_PARAM_NAME_SIZE];                                 \
556         ssize_t pos;                                                    \
557                                                                         \
558         sprintf(name, prefix "%" PRIu32, id);                           \
559         pos = APP_PARAM_FIND(obj_array, name);                          \
560         obj = (pos < 0) ? NULL : &((obj_array)[pos]);                   \
561 } while (0)
562
563 #define APP_PARAM_GET_ID(obj, prefix, id)                               \
564 do                                                                      \
565         sscanf(obj->name, prefix "%" SCNu32, &id);                              \
566 while (0)                                                               \
567
568 #define APP_CHECK(exp, fmt, ...)                                        \
569 do {                                                                    \
570         if (!(exp)) {                                                   \
571                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
572                 abort();                                                \
573         }                                                               \
574 } while (0)
575
576 enum app_log_level {
577         APP_LOG_LEVEL_HIGH = 1,
578         APP_LOG_LEVEL_LOW,
579         APP_LOG_LEVELS
580 };
581
582 #define APP_LOG(app, level, fmt, ...)                                   \
583 do {                                                                    \
584         if (app->log_level >= APP_LOG_LEVEL_ ## level)                  \
585                 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__);     \
586 } while (0)
587
588 static inline uint32_t
589 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
590 {
591         uint32_t n_rxq = 0, link_id, i;
592         uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
593                 RTE_DIM(app->hwq_in_params));
594
595         APP_PARAM_GET_ID(link, "LINK", link_id);
596
597         for (i = 0; i < n_pktq_hwq_in; i++) {
598                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
599                 uint32_t rxq_link_id, rxq_queue_id;
600
601                 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
602                         &rxq_link_id, &rxq_queue_id);
603                 if (rxq_link_id == link_id)
604                         n_rxq++;
605         }
606
607         return n_rxq;
608 }
609
610 static inline uint32_t
611 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
612 {
613         uint32_t n_txq = 0, link_id, i;
614         uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
615                 RTE_DIM(app->hwq_out_params));
616
617         APP_PARAM_GET_ID(link, "LINK", link_id);
618
619         for (i = 0; i < n_pktq_hwq_out; i++) {
620                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
621                 uint32_t txq_link_id, txq_queue_id;
622
623                 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
624                         &txq_link_id, &txq_queue_id);
625                 if (txq_link_id == link_id)
626                         n_txq++;
627         }
628
629         return n_txq;
630 }
631
632 static inline uint32_t
633 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
634 {
635         uint32_t pos = rxq - app->hwq_in_params;
636         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
637                 RTE_DIM(app->pipeline_params));
638         uint32_t n_readers = 0, i;
639
640         for (i = 0; i < n_pipelines; i++) {
641                 struct app_pipeline_params *p = &app->pipeline_params[i];
642                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
643                 uint32_t j;
644
645                 for (j = 0; j < n_pktq_in; j++) {
646                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
647
648                         if ((pktq->type == APP_PKTQ_IN_HWQ) &&
649                                 (pktq->id == pos))
650                                 n_readers++;
651                 }
652         }
653
654         return n_readers;
655 }
656
657 static inline uint32_t
658 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
659 {
660         uint32_t pos = swq - app->swq_params;
661         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
662                 RTE_DIM(app->pipeline_params));
663         uint32_t n_readers = 0, i;
664
665         for (i = 0; i < n_pipelines; i++) {
666                 struct app_pipeline_params *p = &app->pipeline_params[i];
667                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
668                 uint32_t j;
669
670                 for (j = 0; j < n_pktq_in; j++) {
671                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
672
673                         if ((pktq->type == APP_PKTQ_IN_SWQ) &&
674                                 (pktq->id == pos))
675                                 n_readers++;
676                 }
677         }
678
679         return n_readers;
680 }
681
682 static inline struct app_pipeline_params *
683 app_swq_get_reader(struct app_params *app,
684         struct app_pktq_swq_params *swq,
685         uint32_t *pktq_in_id)
686 {
687         struct app_pipeline_params *reader = NULL;
688         uint32_t pos = swq - app->swq_params;
689         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
690                 RTE_DIM(app->pipeline_params));
691         uint32_t n_readers = 0, id = 0, i;
692
693         for (i = 0; i < n_pipelines; i++) {
694                 struct app_pipeline_params *p = &app->pipeline_params[i];
695                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
696                 uint32_t j;
697
698                 for (j = 0; j < n_pktq_in; j++) {
699                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
700
701                         if ((pktq->type == APP_PKTQ_IN_SWQ) &&
702                                 (pktq->id == pos)) {
703                                 n_readers++;
704                                 reader = p;
705                                 id = j;
706                         }
707                 }
708         }
709
710         if (n_readers != 1)
711                 return NULL;
712
713         *pktq_in_id = id;
714         return reader;
715 }
716
717 static inline uint32_t
718 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
719 {
720         uint32_t pos = tm - app->tm_params;
721         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
722                 RTE_DIM(app->pipeline_params));
723         uint32_t n_readers = 0, i;
724
725         for (i = 0; i < n_pipelines; i++) {
726                 struct app_pipeline_params *p = &app->pipeline_params[i];
727                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
728                 uint32_t j;
729
730                 for (j = 0; j < n_pktq_in; j++) {
731                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
732
733                         if ((pktq->type == APP_PKTQ_IN_TM) &&
734                                 (pktq->id == pos))
735                                 n_readers++;
736                 }
737         }
738
739         return n_readers;
740 }
741
742 static inline struct app_pipeline_params *
743 app_tm_get_reader(struct app_params *app,
744         struct app_pktq_tm_params *tm,
745         uint32_t *pktq_in_id)
746 {
747         struct app_pipeline_params *reader = NULL;
748         uint32_t pos = tm - app->tm_params;
749         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
750                 RTE_DIM(app->pipeline_params));
751         uint32_t n_readers = 0, id = 0, i;
752
753         for (i = 0; i < n_pipelines; i++) {
754                 struct app_pipeline_params *p = &app->pipeline_params[i];
755                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
756                 uint32_t j;
757
758                 for (j = 0; j < n_pktq_in; j++) {
759                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
760
761                         if ((pktq->type == APP_PKTQ_IN_TM) &&
762                                 (pktq->id == pos)) {
763                                 n_readers++;
764                                 reader = p;
765                                 id = j;
766                         }
767                 }
768         }
769
770         if (n_readers != 1)
771                 return NULL;
772
773         *pktq_in_id = id;
774         return reader;
775 }
776
777 static inline uint32_t
778 app_tap_get_readers(struct app_params *app, struct app_pktq_tap_params *tap)
779 {
780         uint32_t pos = tap - app->tap_params;
781         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
782                 RTE_DIM(app->pipeline_params));
783         uint32_t n_readers = 0, i;
784
785         for (i = 0; i < n_pipelines; i++) {
786                 struct app_pipeline_params *p = &app->pipeline_params[i];
787                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
788                 uint32_t j;
789
790                 for (j = 0; j < n_pktq_in; j++) {
791                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
792
793                         if ((pktq->type == APP_PKTQ_IN_TAP) &&
794                                 (pktq->id == pos))
795                                 n_readers++;
796                 }
797         }
798
799         return n_readers;
800 }
801
802 static inline struct app_pipeline_params *
803 app_tap_get_reader(struct app_params *app,
804         struct app_pktq_tap_params *tap,
805         uint32_t *pktq_in_id)
806 {
807         struct app_pipeline_params *reader = NULL;
808         uint32_t pos = tap - app->tap_params;
809         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
810                 RTE_DIM(app->pipeline_params));
811         uint32_t n_readers = 0, id = 0, i;
812
813         for (i = 0; i < n_pipelines; i++) {
814                 struct app_pipeline_params *p = &app->pipeline_params[i];
815                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
816                 uint32_t j;
817
818                 for (j = 0; j < n_pktq_in; j++) {
819                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
820
821                         if ((pktq->type == APP_PKTQ_IN_TAP) &&
822                                 (pktq->id == pos)) {
823                                 n_readers++;
824                                 reader = p;
825                                 id = j;
826                         }
827                 }
828         }
829
830         if (n_readers != 1)
831                 return NULL;
832
833         *pktq_in_id = id;
834         return reader;
835 }
836
837 static inline uint32_t
838 app_kni_get_readers(struct app_params *app, struct app_pktq_kni_params *kni)
839 {
840         uint32_t pos = kni - app->kni_params;
841         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
842                 RTE_DIM(app->pipeline_params));
843         uint32_t n_readers = 0, i;
844
845         for (i = 0; i < n_pipelines; i++) {
846                 struct app_pipeline_params *p = &app->pipeline_params[i];
847                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
848                 uint32_t j;
849
850                 for (j = 0; j < n_pktq_in; j++) {
851                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
852
853                         if ((pktq->type == APP_PKTQ_IN_KNI) &&
854                                 (pktq->id == pos))
855                                 n_readers++;
856                 }
857         }
858
859         return n_readers;
860 }
861
862 static inline struct app_pipeline_params *
863 app_kni_get_reader(struct app_params *app,
864                                   struct app_pktq_kni_params *kni,
865                                   uint32_t *pktq_in_id)
866 {
867         struct app_pipeline_params *reader = NULL;
868         uint32_t pos = kni - app->kni_params;
869         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
870                 RTE_DIM(app->pipeline_params));
871         uint32_t n_readers = 0, id = 0, i;
872
873         for (i = 0; i < n_pipelines; i++) {
874                 struct app_pipeline_params *p = &app->pipeline_params[i];
875                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
876                 uint32_t j;
877
878                 for (j = 0; j < n_pktq_in; j++) {
879                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
880
881                         if ((pktq->type == APP_PKTQ_IN_KNI) &&
882                                 (pktq->id == pos)) {
883                                 n_readers++;
884                                 reader = p;
885                                 id = j;
886                         }
887                 }
888         }
889
890         if (n_readers != 1)
891                 return NULL;
892
893         *pktq_in_id = id;
894         return reader;
895 }
896
897 static inline uint32_t
898 app_source_get_readers(struct app_params *app,
899 struct app_pktq_source_params *source)
900 {
901         uint32_t pos = source - app->source_params;
902         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
903                 RTE_DIM(app->pipeline_params));
904         uint32_t n_readers = 0, i;
905
906         for (i = 0; i < n_pipelines; i++) {
907                 struct app_pipeline_params *p = &app->pipeline_params[i];
908                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
909                 uint32_t j;
910
911                 for (j = 0; j < n_pktq_in; j++) {
912                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
913
914                         if ((pktq->type == APP_PKTQ_IN_SOURCE) &&
915                                 (pktq->id == pos))
916                                 n_readers++;
917                 }
918         }
919
920         return n_readers;
921 }
922
923 static inline uint32_t
924 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
925 {
926         uint32_t pos = msgq - app->msgq_params;
927         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
928                 RTE_DIM(app->pipeline_params));
929         uint32_t n_readers = 0, i;
930
931         for (i = 0; i < n_pipelines; i++) {
932                 struct app_pipeline_params *p = &app->pipeline_params[i];
933                 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
934                 uint32_t j;
935
936                 for (j = 0; j < n_msgq_in; j++)
937                         if (p->msgq_in[j] == pos)
938                                 n_readers++;
939         }
940
941         return n_readers;
942 }
943
944 static inline uint32_t
945 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
946 {
947         uint32_t pos = txq - app->hwq_out_params;
948         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
949                 RTE_DIM(app->pipeline_params));
950         uint32_t n_writers = 0, i;
951
952         for (i = 0; i < n_pipelines; i++) {
953                 struct app_pipeline_params *p = &app->pipeline_params[i];
954                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
955                         RTE_DIM(p->pktq_out));
956                 uint32_t j;
957
958                 for (j = 0; j < n_pktq_out; j++) {
959                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
960
961                         if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
962                                 (pktq->id == pos))
963                                 n_writers++;
964                 }
965         }
966
967         return n_writers;
968 }
969
970 static inline uint32_t
971 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
972 {
973         uint32_t pos = swq - app->swq_params;
974         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
975                 RTE_DIM(app->pipeline_params));
976         uint32_t n_writers = 0, i;
977
978         for (i = 0; i < n_pipelines; i++) {
979                 struct app_pipeline_params *p = &app->pipeline_params[i];
980                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
981                         RTE_DIM(p->pktq_out));
982                 uint32_t j;
983
984                 for (j = 0; j < n_pktq_out; j++) {
985                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
986
987                         if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
988                                 (pktq->id == pos))
989                                 n_writers++;
990                 }
991         }
992
993         return n_writers;
994 }
995
996 static inline struct app_pipeline_params *
997 app_swq_get_writer(struct app_params *app,
998         struct app_pktq_swq_params *swq,
999         uint32_t *pktq_out_id)
1000 {
1001         struct app_pipeline_params *writer = NULL;
1002         uint32_t pos = swq - app->swq_params;
1003         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1004                 RTE_DIM(app->pipeline_params));
1005         uint32_t n_writers = 0, id = 0, i;
1006
1007         for (i = 0; i < n_pipelines; i++) {
1008                 struct app_pipeline_params *p = &app->pipeline_params[i];
1009                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1010                         RTE_DIM(p->pktq_out));
1011                 uint32_t j;
1012
1013                 for (j = 0; j < n_pktq_out; j++) {
1014                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1015
1016                         if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
1017                                 (pktq->id == pos)) {
1018                                 n_writers++;
1019                                 writer = p;
1020                                 id = j;
1021                         }
1022                 }
1023         }
1024
1025         if (n_writers != 1)
1026                 return NULL;
1027
1028         *pktq_out_id = id;
1029         return writer;
1030 }
1031
1032 static inline uint32_t
1033 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
1034 {
1035         uint32_t pos = tm - app->tm_params;
1036         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1037                 RTE_DIM(app->pipeline_params));
1038         uint32_t n_writers = 0, i;
1039
1040         for (i = 0; i < n_pipelines; i++) {
1041                 struct app_pipeline_params *p = &app->pipeline_params[i];
1042                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1043                         RTE_DIM(p->pktq_out));
1044                 uint32_t j;
1045
1046                 for (j = 0; j < n_pktq_out; j++) {
1047                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1048
1049                         if ((pktq->type == APP_PKTQ_OUT_TM) &&
1050                                 (pktq->id == pos))
1051                                 n_writers++;
1052                 }
1053         }
1054
1055         return n_writers;
1056 }
1057
1058 static inline struct app_pipeline_params *
1059 app_tm_get_writer(struct app_params *app,
1060         struct app_pktq_tm_params *tm,
1061         uint32_t *pktq_out_id)
1062 {
1063         struct app_pipeline_params *writer = NULL;
1064         uint32_t pos = tm - app->tm_params;
1065         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1066                 RTE_DIM(app->pipeline_params));
1067         uint32_t n_writers = 0, id = 0, i;
1068
1069         for (i = 0; i < n_pipelines; i++) {
1070                 struct app_pipeline_params *p = &app->pipeline_params[i];
1071                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1072                         RTE_DIM(p->pktq_out));
1073                 uint32_t j;
1074
1075                 for (j = 0; j < n_pktq_out; j++) {
1076                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1077
1078                         if ((pktq->type == APP_PKTQ_OUT_TM) &&
1079                                 (pktq->id == pos)) {
1080                                 n_writers++;
1081                                 writer = p;
1082                                 id = j;
1083                         }
1084                 }
1085         }
1086
1087         if (n_writers != 1)
1088                 return NULL;
1089
1090         *pktq_out_id = id;
1091         return writer;
1092 }
1093
1094 static inline uint32_t
1095 app_tap_get_writers(struct app_params *app, struct app_pktq_tap_params *tap)
1096 {
1097         uint32_t pos = tap - app->tap_params;
1098         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1099                 RTE_DIM(app->pipeline_params));
1100         uint32_t n_writers = 0, i;
1101
1102         for (i = 0; i < n_pipelines; i++) {
1103                 struct app_pipeline_params *p = &app->pipeline_params[i];
1104                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1105                         RTE_DIM(p->pktq_out));
1106                 uint32_t j;
1107
1108                 for (j = 0; j < n_pktq_out; j++) {
1109                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1110
1111                 if ((pktq->type == APP_PKTQ_OUT_TAP) &&
1112                         (pktq->id == pos))
1113                         n_writers++;
1114                 }
1115         }
1116
1117         return n_writers;
1118 }
1119
1120 static inline struct app_pipeline_params *
1121 app_tap_get_writer(struct app_params *app,
1122         struct app_pktq_tap_params *tap,
1123         uint32_t *pktq_out_id)
1124 {
1125         struct app_pipeline_params *writer = NULL;
1126         uint32_t pos = tap - app->tap_params;
1127         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1128                 RTE_DIM(app->pipeline_params));
1129         uint32_t n_writers = 0, id = 0, i;
1130
1131         for (i = 0; i < n_pipelines; i++) {
1132                 struct app_pipeline_params *p = &app->pipeline_params[i];
1133                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1134                         RTE_DIM(p->pktq_out));
1135                 uint32_t j;
1136
1137                 for (j = 0; j < n_pktq_out; j++) {
1138                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1139
1140                         if ((pktq->type == APP_PKTQ_OUT_TAP) &&
1141                                 (pktq->id == pos)) {
1142                                 n_writers++;
1143                                 writer = p;
1144                                 id = j;
1145                         }
1146                 }
1147         }
1148
1149         if (n_writers != 1)
1150                 return NULL;
1151
1152         *pktq_out_id = id;
1153         return writer;
1154 }
1155
1156 static inline uint32_t
1157 app_kni_get_writers(struct app_params *app, struct app_pktq_kni_params *kni)
1158 {
1159         uint32_t pos = kni - app->kni_params;
1160         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1161                 RTE_DIM(app->pipeline_params));
1162         uint32_t n_writers = 0, i;
1163
1164         for (i = 0; i < n_pipelines; i++) {
1165                 struct app_pipeline_params *p = &app->pipeline_params[i];
1166                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1167                         RTE_DIM(p->pktq_out));
1168                 uint32_t j;
1169
1170                 for (j = 0; j < n_pktq_out; j++) {
1171                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1172
1173                         if ((pktq->type == APP_PKTQ_OUT_KNI) &&
1174                                 (pktq->id == pos))
1175                                 n_writers++;
1176                 }
1177         }
1178
1179         return n_writers;
1180 }
1181
1182 static inline struct app_pipeline_params *
1183 app_kni_get_writer(struct app_params *app,
1184                                   struct app_pktq_kni_params *kni,
1185                                   uint32_t *pktq_out_id)
1186 {
1187         struct app_pipeline_params *writer = NULL;
1188         uint32_t pos = kni - app->kni_params;
1189         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1190                 RTE_DIM(app->pipeline_params));
1191         uint32_t n_writers = 0, id = 0, i;
1192
1193         for (i = 0; i < n_pipelines; i++) {
1194                 struct app_pipeline_params *p = &app->pipeline_params[i];
1195                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1196                         RTE_DIM(p->pktq_out));
1197                 uint32_t j;
1198
1199                 for (j = 0; j < n_pktq_out; j++) {
1200                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1201
1202                         if ((pktq->type == APP_PKTQ_OUT_KNI) &&
1203                                 (pktq->id == pos)) {
1204                                 n_writers++;
1205                                 writer = p;
1206                                 id = j;
1207                         }
1208                 }
1209         }
1210
1211         if (n_writers != 1)
1212                 return NULL;
1213
1214         *pktq_out_id = id;
1215         return writer;
1216 }
1217
1218 static inline uint32_t
1219 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
1220 {
1221         uint32_t pos = sink - app->sink_params;
1222         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1223                 RTE_DIM(app->pipeline_params));
1224         uint32_t n_writers = 0, i;
1225
1226         for (i = 0; i < n_pipelines; i++) {
1227                 struct app_pipeline_params *p = &app->pipeline_params[i];
1228                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
1229                         RTE_DIM(p->pktq_out));
1230                 uint32_t j;
1231
1232                 for (j = 0; j < n_pktq_out; j++) {
1233                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
1234
1235                         if ((pktq->type == APP_PKTQ_OUT_SINK) &&
1236                                 (pktq->id == pos))
1237                                 n_writers++;
1238                 }
1239         }
1240
1241         return n_writers;
1242 }
1243
1244 static inline uint32_t
1245 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
1246 {
1247         uint32_t pos = msgq - app->msgq_params;
1248         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
1249                 RTE_DIM(app->pipeline_params));
1250         uint32_t n_writers = 0, i;
1251
1252         for (i = 0; i < n_pipelines; i++) {
1253                 struct app_pipeline_params *p = &app->pipeline_params[i];
1254                 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
1255                         RTE_DIM(p->msgq_out));
1256                 uint32_t j;
1257
1258                 for (j = 0; j < n_msgq_out; j++)
1259                         if (p->msgq_out[j] == pos)
1260                                 n_writers++;
1261         }
1262
1263         return n_writers;
1264 }
1265
1266 static inline struct app_link_params *
1267 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
1268 {
1269         char link_name[APP_PARAM_NAME_SIZE];
1270         ssize_t link_param_idx;
1271         uint32_t rxq_link_id, rxq_queue_id;
1272
1273         sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
1274                 &rxq_link_id, &rxq_queue_id);
1275         sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
1276         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1277         APP_CHECK((link_param_idx >= 0),
1278                 "Cannot find %s for %s", link_name, p->name);
1279
1280         return &app->link_params[link_param_idx];
1281 }
1282
1283 static inline struct app_link_params *
1284 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
1285 {
1286         char link_name[APP_PARAM_NAME_SIZE];
1287         ssize_t link_param_idx;
1288         uint32_t txq_link_id, txq_queue_id;
1289
1290         sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
1291                 &txq_link_id, &txq_queue_id);
1292         sprintf(link_name, "LINK%" PRIu32, txq_link_id);
1293         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1294         APP_CHECK((link_param_idx >= 0),
1295                 "Cannot find %s for %s", link_name, p->name);
1296
1297         return &app->link_params[link_param_idx];
1298 }
1299
1300 static inline struct app_link_params *
1301 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
1302 {
1303         char link_name[APP_PARAM_NAME_SIZE];
1304         uint32_t link_id;
1305         ssize_t link_param_idx;
1306
1307         sscanf(p_tm->name, "TM%" PRIu32, &link_id);
1308         sprintf(link_name, "LINK%" PRIu32, link_id);
1309         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1310         APP_CHECK((link_param_idx >= 0),
1311                 "Cannot find %s for %s", link_name, p_tm->name);
1312
1313         return &app->link_params[link_param_idx];
1314 }
1315
1316 static inline struct app_link_params *
1317 app_get_link_for_kni(struct app_params *app, struct app_pktq_kni_params *p_kni)
1318 {
1319         char link_name[APP_PARAM_NAME_SIZE];
1320         uint32_t link_id;
1321         ssize_t link_param_idx;
1322
1323         sscanf(p_kni->name, "KNI%" PRIu32, &link_id);
1324         sprintf(link_name, "LINK%" PRIu32, link_id);
1325         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
1326         APP_CHECK((link_param_idx >= 0),
1327                           "Cannot find %s for %s", link_name, p_kni->name);
1328
1329         return &app->link_params[link_param_idx];
1330 }
1331
1332 static inline uint32_t
1333 app_core_is_enabled(struct app_params *app, uint32_t lcore_id)
1334 {
1335         return(app->core_mask[lcore_id / 64] &
1336                 (1LLU << (lcore_id % 64)));
1337 }
1338
1339 static inline void
1340 app_core_enable_in_core_mask(struct app_params *app, int lcore_id)
1341 {
1342         app->core_mask[lcore_id / 64] |= 1LLU << (lcore_id % 64);
1343
1344 }
1345
1346 static inline void
1347 app_core_build_core_mask_string(struct app_params *app, char *mask_buffer)
1348 {
1349         int i;
1350
1351         mask_buffer[0] = '\0';
1352         for (i = (int)RTE_DIM(app->core_mask); i > 0; i--) {
1353                 /* For Hex representation of bits in uint64_t */
1354                 char buffer[(64 / 8) * 2 + 1];
1355                 memset(buffer, 0, sizeof(buffer));
1356                 snprintf(buffer, sizeof(buffer), "%016" PRIx64,
1357                          app->core_mask[i-1]);
1358                 strcat(mask_buffer, buffer);
1359         }
1360 }
1361
1362 void app_pipeline_params_get(struct app_params *app,
1363         struct app_pipeline_params *p_in,
1364         struct pipeline_params *p_out);
1365
1366 int app_config_init(struct app_params *app);
1367
1368 int app_config_args(struct app_params *app,
1369         int argc, char **argv);
1370
1371 int app_config_preproc(struct app_params *app);
1372
1373 int app_config_parse(struct app_params *app,
1374         const char *file_name);
1375
1376 int app_config_parse_tm(struct app_params *app);
1377
1378 void app_config_save(struct app_params *app,
1379         const char *file_name);
1380
1381 int app_config_check(struct app_params *app);
1382
1383 int app_init(struct app_params *app);
1384
1385 int app_post_init(struct app_params *app);
1386
1387 int app_thread(void *arg);
1388
1389 int app_pipeline_type_register(struct app_params *app,
1390         struct pipeline_type *ptype);
1391
1392 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
1393         char *name);
1394
1395 void app_link_up_internal(struct app_params *app,
1396         struct app_link_params *cp);
1397
1398 void app_link_down_internal(struct app_params *app,
1399         struct app_link_params *cp);
1400
1401 #endif