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