pipeline: support packet redirection at action handlers
[dpdk.git] / examples / ip_pipeline / app.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 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
48 #include "cpu_core_map.h"
49 #include "pipeline.h"
50
51 #define APP_PARAM_NAME_SIZE                      PIPELINE_NAME_SIZE
52 #define APP_LINK_PCI_BDF_SIZE                    16
53 struct app_mempool_params {
54         char *name;
55         uint32_t parsed;
56         uint32_t buffer_size;
57         uint32_t pool_size;
58         uint32_t cache_size;
59         uint32_t cpu_socket_id;
60 };
61
62 struct app_link_params {
63         char *name;
64         uint32_t parsed;
65         uint32_t pmd_id; /* Generated based on port mask */
66         uint32_t arp_q; /* 0 = Disabled (packets go to default queue 0) */
67         uint32_t tcp_syn_q; /* 0 = Disabled (pkts go to default queue) */
68         uint32_t ip_local_q; /* 0 = Disabled (pkts go to default queue 0) */
69         uint32_t tcp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
70         uint32_t udp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
71         uint32_t sctp_local_q; /* 0 = Disabled (pkts go to default queue 0) */
72         uint32_t state; /* DOWN = 0, UP = 1 */
73         uint32_t ip; /* 0 = Invalid */
74         uint32_t depth; /* Valid only when IP is valid */
75         uint64_t mac_addr; /* Read from HW */
76         char pci_bdf[APP_LINK_PCI_BDF_SIZE];
77
78         struct rte_eth_conf conf;
79         uint8_t promisc;
80 };
81
82 struct app_pktq_hwq_in_params {
83         char *name;
84         uint32_t parsed;
85         uint32_t mempool_id; /* Position in the app->mempool_params */
86         uint32_t size;
87         uint32_t burst;
88
89         struct rte_eth_rxconf conf;
90 };
91
92 struct app_pktq_hwq_out_params {
93         char *name;
94         uint32_t parsed;
95         uint32_t size;
96         uint32_t burst;
97         uint32_t dropless;
98         uint64_t n_retries;
99         struct rte_eth_txconf conf;
100 };
101
102 struct app_pktq_swq_params {
103         char *name;
104         uint32_t parsed;
105         uint32_t size;
106         uint32_t burst_read;
107         uint32_t burst_write;
108         uint32_t dropless;
109         uint64_t n_retries;
110         uint32_t cpu_socket_id;
111         uint32_t ipv4_frag;
112         uint32_t ipv6_frag;
113         uint32_t ipv4_ras;
114         uint32_t ipv6_ras;
115         uint32_t mtu;
116         uint32_t metadata_size;
117         uint32_t mempool_direct_id;
118         uint32_t mempool_indirect_id;
119 };
120
121 #ifndef APP_FILE_NAME_SIZE
122 #define APP_FILE_NAME_SIZE                       256
123 #endif
124
125 #ifndef APP_MAX_SCHED_SUBPORTS
126 #define APP_MAX_SCHED_SUBPORTS                   8
127 #endif
128
129 #ifndef APP_MAX_SCHED_PIPES
130 #define APP_MAX_SCHED_PIPES                      4096
131 #endif
132
133 struct app_pktq_tm_params {
134         char *name;
135         uint32_t parsed;
136         const char *file_name;
137         struct rte_sched_port_params sched_port_params;
138         struct rte_sched_subport_params
139                 sched_subport_params[APP_MAX_SCHED_SUBPORTS];
140         struct rte_sched_pipe_params
141                 sched_pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
142         int sched_pipe_to_profile[APP_MAX_SCHED_SUBPORTS * APP_MAX_SCHED_PIPES];
143         uint32_t burst_read;
144         uint32_t burst_write;
145 };
146
147 struct app_pktq_source_params {
148         char *name;
149         uint32_t parsed;
150         uint32_t mempool_id; /* Position in the app->mempool_params array */
151         uint32_t burst;
152 };
153
154 struct app_pktq_sink_params {
155         char *name;
156         uint8_t parsed;
157 };
158
159 struct app_msgq_params {
160         char *name;
161         uint32_t parsed;
162         uint32_t size;
163         uint32_t cpu_socket_id;
164 };
165
166 enum app_pktq_in_type {
167         APP_PKTQ_IN_HWQ,
168         APP_PKTQ_IN_SWQ,
169         APP_PKTQ_IN_TM,
170         APP_PKTQ_IN_SOURCE,
171 };
172
173 struct app_pktq_in_params {
174         enum app_pktq_in_type type;
175         uint32_t id; /* Position in the appropriate app array */
176 };
177
178 enum app_pktq_out_type {
179         APP_PKTQ_OUT_HWQ,
180         APP_PKTQ_OUT_SWQ,
181         APP_PKTQ_OUT_TM,
182         APP_PKTQ_OUT_SINK,
183 };
184
185 struct app_pktq_out_params {
186         enum app_pktq_out_type type;
187         uint32_t id; /* Position in the appropriate app array */
188 };
189
190 #ifndef APP_PIPELINE_TYPE_SIZE
191 #define APP_PIPELINE_TYPE_SIZE                   64
192 #endif
193
194 #define APP_MAX_PIPELINE_PKTQ_IN                 PIPELINE_MAX_PORT_IN
195 #define APP_MAX_PIPELINE_PKTQ_OUT                PIPELINE_MAX_PORT_OUT
196 #define APP_MAX_PIPELINE_MSGQ_IN                 PIPELINE_MAX_MSGQ_IN
197 #define APP_MAX_PIPELINE_MSGQ_OUT                PIPELINE_MAX_MSGQ_OUT
198
199 #define APP_MAX_PIPELINE_ARGS                    PIPELINE_MAX_ARGS
200
201 struct app_pipeline_params {
202         char *name;
203         uint8_t parsed;
204
205         char type[APP_PIPELINE_TYPE_SIZE];
206
207         uint32_t socket_id;
208         uint32_t core_id;
209         uint32_t hyper_th_id;
210
211         struct app_pktq_in_params pktq_in[APP_MAX_PIPELINE_PKTQ_IN];
212         struct app_pktq_out_params pktq_out[APP_MAX_PIPELINE_PKTQ_OUT];
213         uint32_t msgq_in[APP_MAX_PIPELINE_MSGQ_IN];
214         uint32_t msgq_out[APP_MAX_PIPELINE_MSGQ_OUT];
215
216         uint32_t n_pktq_in;
217         uint32_t n_pktq_out;
218         uint32_t n_msgq_in;
219         uint32_t n_msgq_out;
220
221         uint32_t timer_period;
222
223         char *args_name[APP_MAX_PIPELINE_ARGS];
224         char *args_value[APP_MAX_PIPELINE_ARGS];
225         uint32_t n_args;
226 };
227
228 struct app_pipeline_data {
229         void *be;
230         void *fe;
231         struct pipeline_type *ptype;
232         uint64_t timer_period;
233         uint32_t enabled;
234 };
235
236 struct app_thread_pipeline_data {
237         uint32_t pipeline_id;
238         void *be;
239         pipeline_be_op_run f_run;
240         pipeline_be_op_timer f_timer;
241         uint64_t timer_period;
242         uint64_t deadline;
243 };
244
245 #ifndef APP_MAX_THREAD_PIPELINES
246 #define APP_MAX_THREAD_PIPELINES                 16
247 #endif
248
249 #ifndef APP_THREAD_TIMER_PERIOD
250 #define APP_THREAD_TIMER_PERIOD                  1
251 #endif
252
253 struct app_thread_data {
254         struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
255         struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
256
257         uint32_t n_regular;
258         uint32_t n_custom;
259
260         uint64_t timer_period;
261         uint64_t thread_req_deadline;
262
263         uint64_t deadline;
264
265         struct rte_ring *msgq_in;
266         struct rte_ring *msgq_out;
267
268         uint64_t headroom_time;
269         uint64_t headroom_cycles;
270         double headroom_ratio;
271 };
272
273 #ifndef APP_MAX_LINKS
274 #define APP_MAX_LINKS                            16
275 #endif
276
277 struct app_eal_params {
278         /* Map lcore set to physical cpu set */
279         char *coremap;
280
281         /* Core ID that is used as master */
282         uint32_t master_lcore_present;
283         uint32_t master_lcore;
284
285         /* Number of memory channels */
286         uint32_t channels_present;
287         uint32_t channels;
288
289         /* Memory to allocate (see also --socket-mem) */
290         uint32_t memory_present;
291         uint32_t memory;
292
293         /* Force number of memory ranks (don't detect) */
294         uint32_t ranks_present;
295         uint32_t ranks;
296
297         /* Add a PCI device in black list. */
298         char *pci_blacklist[APP_MAX_LINKS];
299
300         /* Add a PCI device in white list. */
301         char *pci_whitelist[APP_MAX_LINKS];
302
303         /* Add a virtual device. */
304         char *vdev[APP_MAX_LINKS];
305
306          /* Use VMware TSC map instead of native RDTSC */
307         uint32_t vmware_tsc_map_present;
308         int vmware_tsc_map;
309
310          /* Type of this process (primary|secondary|auto) */
311         char *proc_type;
312
313          /* Set syslog facility */
314         char *syslog;
315
316         /* Set default log level */
317         uint32_t log_level_present;
318         uint32_t log_level;
319
320         /* Display version information on startup */
321         uint32_t version_present;
322         int version;
323
324         /* This help */
325         uint32_t help_present;
326         int help;
327
328          /* Use malloc instead of hugetlbfs */
329         uint32_t no_huge_present;
330         int no_huge;
331
332         /* Disable PCI */
333         uint32_t no_pci_present;
334         int no_pci;
335
336         /* Disable HPET */
337         uint32_t no_hpet_present;
338         int no_hpet;
339
340         /* No shared config (mmap'd files) */
341         uint32_t no_shconf_present;
342         int no_shconf;
343
344         /* Add driver */
345         char *add_driver;
346
347         /*  Memory to allocate on sockets (comma separated values)*/
348         char *socket_mem;
349
350         /* Directory where hugetlbfs is mounted */
351         char *huge_dir;
352
353         /* Prefix for hugepage filenames */
354         char *file_prefix;
355
356         /* Base virtual address */
357         char *base_virtaddr;
358
359         /* Create /dev/uioX (usually done by hotplug) */
360         uint32_t create_uio_dev_present;
361         int create_uio_dev;
362
363         /* Interrupt mode for VFIO (legacy|msi|msix) */
364         char *vfio_intr;
365
366         /* Support running on Xen dom0 without hugetlbfs */
367         uint32_t xen_dom0_present;
368         int xen_dom0;
369 };
370
371 #ifndef APP_APPNAME_SIZE
372 #define APP_APPNAME_SIZE                         256
373 #endif
374
375 #ifndef APP_MAX_MEMPOOLS
376 #define APP_MAX_MEMPOOLS                         8
377 #endif
378
379 #ifndef APP_LINK_MAX_HWQ_IN
380 #define APP_LINK_MAX_HWQ_IN                      64
381 #endif
382
383 #ifndef APP_LINK_MAX_HWQ_OUT
384 #define APP_LINK_MAX_HWQ_OUT                     64
385 #endif
386
387 #define APP_MAX_HWQ_IN                     (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
388
389 #define APP_MAX_HWQ_OUT                   (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
390
391 #ifndef APP_MAX_PKTQ_SWQ
392 #define APP_MAX_PKTQ_SWQ                         256
393 #endif
394
395 #define APP_MAX_PKTQ_TM                          APP_MAX_LINKS
396
397 #ifndef APP_MAX_PKTQ_SOURCE
398 #define APP_MAX_PKTQ_SOURCE                      16
399 #endif
400
401 #ifndef APP_MAX_PKTQ_SINK
402 #define APP_MAX_PKTQ_SINK                        16
403 #endif
404
405 #ifndef APP_MAX_MSGQ
406 #define APP_MAX_MSGQ                             64
407 #endif
408
409 #ifndef APP_MAX_PIPELINES
410 #define APP_MAX_PIPELINES                        64
411 #endif
412
413 #ifndef APP_EAL_ARGC
414 #define APP_EAL_ARGC                             32
415 #endif
416
417 #ifndef APP_MAX_PIPELINE_TYPES
418 #define APP_MAX_PIPELINE_TYPES                   64
419 #endif
420
421 #ifndef APP_MAX_THREADS
422 #define APP_MAX_THREADS                          RTE_MAX_LCORE
423 #endif
424
425 #ifndef APP_MAX_CMDS
426 #define APP_MAX_CMDS                             64
427 #endif
428
429 #ifndef APP_THREAD_HEADROOM_STATS_COLLECT
430 #define APP_THREAD_HEADROOM_STATS_COLLECT        1
431 #endif
432
433 struct app_params {
434         /* Config */
435         char app_name[APP_APPNAME_SIZE];
436         const char *config_file;
437         const char *script_file;
438         const char *parser_file;
439         const char *output_file;
440         const char *preproc;
441         const char *preproc_args;
442         uint64_t port_mask;
443         uint32_t log_level;
444
445         struct app_eal_params eal_params;
446         struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
447         struct app_link_params link_params[APP_MAX_LINKS];
448         struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
449         struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
450         struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
451         struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
452         struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
453         struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
454         struct app_msgq_params msgq_params[APP_MAX_MSGQ];
455         struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
456
457         uint32_t n_mempools;
458         uint32_t n_links;
459         uint32_t n_pktq_hwq_in;
460         uint32_t n_pktq_hwq_out;
461         uint32_t n_pktq_swq;
462         uint32_t n_pktq_tm;
463         uint32_t n_pktq_source;
464         uint32_t n_pktq_sink;
465         uint32_t n_msgq;
466         uint32_t n_pipelines;
467
468         /* Init */
469         char *eal_argv[1 + APP_EAL_ARGC];
470         struct cpu_core_map *core_map;
471         uint64_t core_mask;
472         struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
473         struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
474         struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
475         struct rte_ring *msgq[APP_MAX_MSGQ];
476         struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
477         struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
478         struct app_thread_data thread_data[APP_MAX_THREADS];
479         cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
480
481         int eal_argc;
482         uint32_t n_pipeline_types;
483         uint32_t n_cmds;
484 };
485
486 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
487
488 #define APP_PARAM_COUNT(obj_array, n_objs)                              \
489 {                                                                       \
490         size_t i;                                                       \
491                                                                         \
492         n_objs = 0;                                                     \
493         for (i = 0; i < RTE_DIM(obj_array); i++)                        \
494                 if (APP_PARAM_VALID(&((obj_array)[i])))                 \
495                         n_objs++;                                       \
496 }
497
498 #define APP_PARAM_FIND(obj_array, key)                                  \
499 ({                                                                      \
500         ssize_t obj_idx;                                                \
501         const ssize_t obj_count = RTE_DIM(obj_array);                   \
502                                                                         \
503         for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {             \
504                 if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
505                         continue;                                       \
506                                                                         \
507                 if (strcmp(key, (obj_array)[obj_idx].name) == 0)        \
508                         break;                                          \
509         }                                                               \
510         obj_idx < obj_count ? obj_idx : -ENOENT;                        \
511 })
512
513 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj)                \
514 do {                                                                    \
515         char name[APP_PARAM_NAME_SIZE];                                 \
516         ssize_t pos;                                                    \
517                                                                         \
518         sprintf(name, prefix "%" PRIu32, id);                           \
519         pos = APP_PARAM_FIND(obj_array, name);                          \
520         obj = (pos < 0) ? NULL : &((obj_array)[pos]);                   \
521 } while (0)
522
523 #define APP_PARAM_GET_ID(obj, prefix, id)                               \
524 do                                                                      \
525         sscanf(obj->name, prefix "%" SCNu32, &id);                              \
526 while (0)                                                               \
527
528 #define APP_PARAM_ADD(obj_array, obj_name)                              \
529 ({                                                                      \
530         ssize_t obj_idx;                                                \
531         const ssize_t obj_count = RTE_DIM(obj_array);                   \
532                                                                         \
533         obj_idx = APP_PARAM_FIND(obj_array, obj_name);                  \
534         if (obj_idx < 0) {                                              \
535                 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {     \
536                         if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))  \
537                                 break;                                  \
538                 }                                                       \
539                                                                         \
540                 if (obj_idx < obj_count) {                              \
541                         (obj_array)[obj_idx].name = strdup(obj_name);   \
542                         if ((obj_array)[obj_idx].name == NULL)          \
543                                 obj_idx = -EINVAL;                      \
544                 } else                                                  \
545                         obj_idx = -ENOMEM;                              \
546         }                                                               \
547         obj_idx;                                                        \
548 })
549
550 #define APP_CHECK(exp, fmt, ...)                                        \
551 do {                                                                    \
552         if (!(exp)) {                                                   \
553                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
554                 abort();                                                \
555         }                                                               \
556 } while (0)
557
558 enum app_log_level {
559         APP_LOG_LEVEL_HIGH = 1,
560         APP_LOG_LEVEL_LOW,
561         APP_LOG_LEVELS
562 };
563
564 #define APP_LOG(app, level, fmt, ...)                                   \
565 do {                                                                    \
566         if (app->log_level >= APP_LOG_LEVEL_ ## level)                  \
567                 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__);     \
568 } while (0)
569
570 static inline uint32_t
571 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
572 {
573         uint32_t n_rxq = 0, link_id, i;
574         uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
575                 RTE_DIM(app->hwq_in_params));
576
577         APP_PARAM_GET_ID(link, "LINK", link_id);
578
579         for (i = 0; i < n_pktq_hwq_in; i++) {
580                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
581                 uint32_t rxq_link_id, rxq_queue_id;
582
583                 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
584                         &rxq_link_id, &rxq_queue_id);
585                 if (rxq_link_id == link_id)
586                         n_rxq++;
587         }
588
589         return n_rxq;
590 }
591
592 static inline uint32_t
593 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
594 {
595         uint32_t n_txq = 0, link_id, i;
596         uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
597                 RTE_DIM(app->hwq_out_params));
598
599         APP_PARAM_GET_ID(link, "LINK", link_id);
600
601         for (i = 0; i < n_pktq_hwq_out; i++) {
602                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
603                 uint32_t txq_link_id, txq_queue_id;
604
605                 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
606                         &txq_link_id, &txq_queue_id);
607                 if (txq_link_id == link_id)
608                         n_txq++;
609         }
610
611         return n_txq;
612 }
613
614 static inline uint32_t
615 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
616 {
617         uint32_t pos = rxq - app->hwq_in_params;
618         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
619                 RTE_DIM(app->pipeline_params));
620         uint32_t n_readers = 0, i;
621
622         for (i = 0; i < n_pipelines; i++) {
623                 struct app_pipeline_params *p = &app->pipeline_params[i];
624                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
625                 uint32_t j;
626
627                 for (j = 0; j < n_pktq_in; j++) {
628                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
629
630                         if ((pktq->type == APP_PKTQ_IN_HWQ) &&
631                                 (pktq->id == pos))
632                                 n_readers++;
633                 }
634         }
635
636         return n_readers;
637 }
638
639 static inline uint32_t
640 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
641 {
642         uint32_t pos = swq - app->swq_params;
643         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
644                 RTE_DIM(app->pipeline_params));
645         uint32_t n_readers = 0, i;
646
647         for (i = 0; i < n_pipelines; i++) {
648                 struct app_pipeline_params *p = &app->pipeline_params[i];
649                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
650                 uint32_t j;
651
652                 for (j = 0; j < n_pktq_in; j++) {
653                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
654
655                         if ((pktq->type == APP_PKTQ_IN_SWQ) &&
656                                 (pktq->id == pos))
657                                 n_readers++;
658                 }
659         }
660
661         return n_readers;
662 }
663
664 static inline uint32_t
665 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
666 {
667         uint32_t pos = tm - app->tm_params;
668         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
669                 RTE_DIM(app->pipeline_params));
670         uint32_t n_readers = 0, i;
671
672         for (i = 0; i < n_pipelines; i++) {
673                 struct app_pipeline_params *p = &app->pipeline_params[i];
674                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
675                 uint32_t j;
676
677                 for (j = 0; j < n_pktq_in; j++) {
678                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
679
680                         if ((pktq->type == APP_PKTQ_IN_TM) &&
681                                 (pktq->id == pos))
682                                 n_readers++;
683                 }
684         }
685
686         return n_readers;
687 }
688
689 static inline uint32_t
690 app_source_get_readers(struct app_params *app,
691 struct app_pktq_source_params *source)
692 {
693         uint32_t pos = source - app->source_params;
694         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
695                 RTE_DIM(app->pipeline_params));
696         uint32_t n_readers = 0, i;
697
698         for (i = 0; i < n_pipelines; i++) {
699                 struct app_pipeline_params *p = &app->pipeline_params[i];
700                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
701                 uint32_t j;
702
703                 for (j = 0; j < n_pktq_in; j++) {
704                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
705
706                         if ((pktq->type == APP_PKTQ_IN_SOURCE) &&
707                                 (pktq->id == pos))
708                                 n_readers++;
709                 }
710         }
711
712         return n_readers;
713 }
714
715 static inline uint32_t
716 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
717 {
718         uint32_t pos = msgq - app->msgq_params;
719         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
720                 RTE_DIM(app->pipeline_params));
721         uint32_t n_readers = 0, i;
722
723         for (i = 0; i < n_pipelines; i++) {
724                 struct app_pipeline_params *p = &app->pipeline_params[i];
725                 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
726                 uint32_t j;
727
728                 for (j = 0; j < n_msgq_in; j++)
729                         if (p->msgq_in[j] == pos)
730                                 n_readers++;
731         }
732
733         return n_readers;
734 }
735
736 static inline uint32_t
737 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
738 {
739         uint32_t pos = txq - app->hwq_out_params;
740         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
741                 RTE_DIM(app->pipeline_params));
742         uint32_t n_writers = 0, i;
743
744         for (i = 0; i < n_pipelines; i++) {
745                 struct app_pipeline_params *p = &app->pipeline_params[i];
746                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
747                         RTE_DIM(p->pktq_out));
748                 uint32_t j;
749
750                 for (j = 0; j < n_pktq_out; j++) {
751                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
752
753                         if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
754                                 (pktq->id == pos))
755                                 n_writers++;
756                 }
757         }
758
759         return n_writers;
760 }
761
762 static inline uint32_t
763 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
764 {
765         uint32_t pos = swq - app->swq_params;
766         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
767                 RTE_DIM(app->pipeline_params));
768         uint32_t n_writers = 0, i;
769
770         for (i = 0; i < n_pipelines; i++) {
771                 struct app_pipeline_params *p = &app->pipeline_params[i];
772                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
773                         RTE_DIM(p->pktq_out));
774                 uint32_t j;
775
776                 for (j = 0; j < n_pktq_out; j++) {
777                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
778
779                         if ((pktq->type == APP_PKTQ_OUT_SWQ) &&
780                                 (pktq->id == pos))
781                                 n_writers++;
782                 }
783         }
784
785         return n_writers;
786 }
787
788 static inline uint32_t
789 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
790 {
791         uint32_t pos = tm - app->tm_params;
792         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
793                 RTE_DIM(app->pipeline_params));
794         uint32_t n_writers = 0, i;
795
796         for (i = 0; i < n_pipelines; i++) {
797                 struct app_pipeline_params *p = &app->pipeline_params[i];
798                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
799                         RTE_DIM(p->pktq_out));
800                 uint32_t j;
801
802                 for (j = 0; j < n_pktq_out; j++) {
803                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
804
805                         if ((pktq->type == APP_PKTQ_OUT_TM) &&
806                                 (pktq->id == pos))
807                                 n_writers++;
808                 }
809         }
810
811         return n_writers;
812 }
813
814 static inline uint32_t
815 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
816 {
817         uint32_t pos = sink - app->sink_params;
818         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
819                 RTE_DIM(app->pipeline_params));
820         uint32_t n_writers = 0, i;
821
822         for (i = 0; i < n_pipelines; i++) {
823                 struct app_pipeline_params *p = &app->pipeline_params[i];
824                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
825                         RTE_DIM(p->pktq_out));
826                 uint32_t j;
827
828                 for (j = 0; j < n_pktq_out; j++) {
829                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
830
831                         if ((pktq->type == APP_PKTQ_OUT_SINK) &&
832                                 (pktq->id == pos))
833                                 n_writers++;
834                 }
835         }
836
837         return n_writers;
838 }
839
840 static inline uint32_t
841 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
842 {
843         uint32_t pos = msgq - app->msgq_params;
844         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
845                 RTE_DIM(app->pipeline_params));
846         uint32_t n_writers = 0, i;
847
848         for (i = 0; i < n_pipelines; i++) {
849                 struct app_pipeline_params *p = &app->pipeline_params[i];
850                 uint32_t n_msgq_out = RTE_MIN(p->n_msgq_out,
851                         RTE_DIM(p->msgq_out));
852                 uint32_t j;
853
854                 for (j = 0; j < n_msgq_out; j++)
855                         if (p->msgq_out[j] == pos)
856                                 n_writers++;
857         }
858
859         return n_writers;
860 }
861
862 static inline struct app_link_params *
863 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
864 {
865         char link_name[APP_PARAM_NAME_SIZE];
866         ssize_t link_param_idx;
867         uint32_t rxq_link_id, rxq_queue_id;
868
869         sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
870                 &rxq_link_id, &rxq_queue_id);
871         sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
872         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
873         APP_CHECK((link_param_idx >= 0),
874                 "Cannot find %s for %s", link_name, p->name);
875
876         return &app->link_params[link_param_idx];
877 }
878
879 static inline struct app_link_params *
880 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
881 {
882         char link_name[APP_PARAM_NAME_SIZE];
883         ssize_t link_param_idx;
884         uint32_t txq_link_id, txq_queue_id;
885
886         sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
887                 &txq_link_id, &txq_queue_id);
888         sprintf(link_name, "LINK%" PRIu32, txq_link_id);
889         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
890         APP_CHECK((link_param_idx >= 0),
891                 "Cannot find %s for %s", link_name, p->name);
892
893         return &app->link_params[link_param_idx];
894 }
895
896 static inline struct app_link_params *
897 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
898 {
899         char link_name[APP_PARAM_NAME_SIZE];
900         uint32_t link_id;
901         ssize_t link_param_idx;
902
903         sscanf(p_tm->name, "TM%" PRIu32, &link_id);
904         sprintf(link_name, "LINK%" PRIu32, link_id);
905         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
906         APP_CHECK((link_param_idx >= 0),
907                 "Cannot find %s for %s", link_name, p_tm->name);
908
909         return &app->link_params[link_param_idx];
910 }
911
912 int app_config_init(struct app_params *app);
913
914 int app_config_args(struct app_params *app,
915         int argc, char **argv);
916
917 int app_config_preproc(struct app_params *app);
918
919 int app_config_parse(struct app_params *app,
920         const char *file_name);
921
922 int app_config_parse_tm(struct app_params *app);
923
924 void app_config_save(struct app_params *app,
925         const char *file_name);
926
927 int app_config_check(struct app_params *app);
928
929 int app_init(struct app_params *app);
930
931 int app_thread(void *arg);
932
933 int app_pipeline_type_register(struct app_params *app,
934         struct pipeline_type *ptype);
935
936 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
937         char *name);
938
939 void app_link_up_internal(struct app_params *app,
940         struct app_link_params *cp);
941
942 void app_link_down_internal(struct app_params *app,
943         struct app_link_params *cp);
944
945 #endif