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