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