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