i40evf: fix MAC deletion when stopping
[dpdk.git] / examples / ip_pipeline / app.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef __INCLUDE_APP_H__
35 #define __INCLUDE_APP_H__
36
37 #include <stdint.h>
38 #include <string.h>
39
40 #include <rte_common.h>
41 #include <rte_mempool.h>
42 #include <rte_ring.h>
43 #include <rte_sched.h>
44 #include <cmdline_parse.h>
45
46 #include <rte_ethdev.h>
47
48 #include "cpu_core_map.h"
49 #include "pipeline.h"
50
51 #define APP_PARAM_NAME_SIZE                      PIPELINE_NAME_SIZE
52
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_local_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
77         struct rte_eth_conf conf;
78         uint8_t promisc;
79 };
80
81 struct app_pktq_hwq_in_params {
82         char *name;
83         uint32_t parsed;
84         uint32_t mempool_id; /* Position in the app->mempool_params */
85         uint32_t size;
86         uint32_t burst;
87
88         struct rte_eth_rxconf conf;
89 };
90
91 struct app_pktq_hwq_out_params {
92         char *name;
93         uint32_t parsed;
94         uint32_t size;
95         uint32_t burst;
96         uint32_t dropless;
97         uint64_t n_retries;
98         struct rte_eth_txconf conf;
99 };
100
101 struct app_pktq_swq_params {
102         char *name;
103         uint32_t parsed;
104         uint32_t size;
105         uint32_t burst_read;
106         uint32_t burst_write;
107         uint32_t dropless;
108         uint64_t n_retries;
109         uint32_t cpu_socket_id;
110         uint32_t ipv4_frag;
111         uint32_t ipv6_frag;
112         uint32_t ipv4_ras;
113         uint32_t ipv6_ras;
114         uint32_t mtu;
115         uint32_t metadata_size;
116         uint32_t mempool_direct_id;
117         uint32_t mempool_indirect_id;
118 };
119
120 #ifndef APP_FILE_NAME_SIZE
121 #define APP_FILE_NAME_SIZE                       256
122 #endif
123
124 #ifndef APP_MAX_SCHED_SUBPORTS
125 #define APP_MAX_SCHED_SUBPORTS                   8
126 #endif
127
128 #ifndef APP_MAX_SCHED_PIPES
129 #define APP_MAX_SCHED_PIPES                      4096
130 #endif
131
132 struct app_pktq_tm_params {
133         char *name;
134         uint32_t parsed;
135         const char *file_name;
136         struct rte_sched_port_params sched_port_params;
137         struct rte_sched_subport_params
138                 sched_subport_params[APP_MAX_SCHED_SUBPORTS];
139         struct rte_sched_pipe_params
140                 sched_pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
141         int sched_pipe_to_profile[APP_MAX_SCHED_SUBPORTS * APP_MAX_SCHED_PIPES];
142         uint32_t burst_read;
143         uint32_t burst_write;
144 };
145
146 struct app_pktq_source_params {
147         char *name;
148         uint32_t parsed;
149         uint32_t mempool_id; /* Position in the app->mempool_params array */
150         uint32_t burst;
151 };
152
153 struct app_pktq_sink_params {
154         char *name;
155         uint8_t parsed;
156 };
157
158 struct app_msgq_params {
159         char *name;
160         uint32_t parsed;
161         uint32_t size;
162         uint32_t cpu_socket_id;
163 };
164
165 enum app_pktq_in_type {
166         APP_PKTQ_IN_HWQ,
167         APP_PKTQ_IN_SWQ,
168         APP_PKTQ_IN_TM,
169         APP_PKTQ_IN_SOURCE,
170 };
171
172 struct app_pktq_in_params {
173         enum app_pktq_in_type type;
174         uint32_t id; /* Position in the appropriate app array */
175 };
176
177 enum app_pktq_out_type {
178         APP_PKTQ_OUT_HWQ,
179         APP_PKTQ_OUT_SWQ,
180         APP_PKTQ_OUT_TM,
181         APP_PKTQ_OUT_SINK,
182 };
183
184 struct app_pktq_out_params {
185         enum app_pktq_out_type type;
186         uint32_t id; /* Position in the appropriate app array */
187 };
188
189 #ifndef APP_PIPELINE_TYPE_SIZE
190 #define APP_PIPELINE_TYPE_SIZE                   64
191 #endif
192
193 #define APP_MAX_PIPELINE_PKTQ_IN                 PIPELINE_MAX_PORT_IN
194 #define APP_MAX_PIPELINE_PKTQ_OUT                PIPELINE_MAX_PORT_OUT
195 #define APP_MAX_PIPELINE_MSGQ_IN                 PIPELINE_MAX_MSGQ_IN
196 #define APP_MAX_PIPELINE_MSGQ_OUT                PIPELINE_MAX_MSGQ_OUT
197
198 #define APP_MAX_PIPELINE_ARGS                    PIPELINE_MAX_ARGS
199
200 struct app_pipeline_params {
201         char *name;
202         uint8_t parsed;
203
204         char type[APP_PIPELINE_TYPE_SIZE];
205
206         uint32_t socket_id;
207         uint32_t core_id;
208         uint32_t hyper_th_id;
209
210         struct app_pktq_in_params pktq_in[APP_MAX_PIPELINE_PKTQ_IN];
211         struct app_pktq_out_params pktq_out[APP_MAX_PIPELINE_PKTQ_OUT];
212         uint32_t msgq_in[APP_MAX_PIPELINE_MSGQ_IN];
213         uint32_t msgq_out[APP_MAX_PIPELINE_MSGQ_OUT];
214
215         uint32_t n_pktq_in;
216         uint32_t n_pktq_out;
217         uint32_t n_msgq_in;
218         uint32_t n_msgq_out;
219
220         uint32_t timer_period;
221
222         char *args_name[APP_MAX_PIPELINE_ARGS];
223         char *args_value[APP_MAX_PIPELINE_ARGS];
224         uint32_t n_args;
225 };
226
227 struct app_pipeline_data {
228         void *be;
229         void *fe;
230         uint64_t timer_period;
231 };
232
233 struct app_thread_pipeline_data {
234         void *be;
235         pipeline_be_op_run f_run;
236         pipeline_be_op_timer f_timer;
237         uint64_t timer_period;
238         uint64_t deadline;
239 };
240
241 #ifndef APP_MAX_THREAD_PIPELINES
242 #define APP_MAX_THREAD_PIPELINES                 16
243 #endif
244
245 struct app_thread_data {
246         struct app_thread_pipeline_data regular[APP_MAX_THREAD_PIPELINES];
247         struct app_thread_pipeline_data custom[APP_MAX_THREAD_PIPELINES];
248
249         uint32_t n_regular;
250         uint32_t n_custom;
251
252         uint64_t deadline;
253 };
254
255 struct app_eal_params {
256         /* Map lcore set to physical cpu set */
257         char *coremap;
258
259         /* Core ID that is used as master */
260         uint32_t master_lcore_present;
261         uint32_t master_lcore;
262
263         /* Number of memory channels */
264         uint32_t channels_present;
265         uint32_t channels;
266
267         /* Memory to allocate (see also --socket-mem) */
268         uint32_t memory_present;
269         uint32_t memory;
270
271         /* Force number of memory ranks (don't detect) */
272         uint32_t ranks_present;
273         uint32_t ranks;
274
275         /* Add a PCI device in black list. */
276         char *pci_blacklist;
277
278         /* Add a PCI device in white list. */
279         char *pci_whitelist;
280
281         /* Add a virtual device. */
282         char *vdev;
283
284          /* Use VMware TSC map instead of native RDTSC */
285         uint32_t vmware_tsc_map_present;
286         int vmware_tsc_map;
287
288          /* Type of this process (primary|secondary|auto) */
289         char *proc_type;
290
291          /* Set syslog facility */
292         char *syslog;
293
294         /* Set default log level */
295         uint32_t log_level_present;
296         uint32_t log_level;
297
298         /* Display version information on startup */
299         uint32_t version_present;
300         int version;
301
302         /* This help */
303         uint32_t help_present;
304         int help;
305
306          /* Use malloc instead of hugetlbfs */
307         uint32_t no_huge_present;
308         int no_huge;
309
310         /* Disable PCI */
311         uint32_t no_pci_present;
312         int no_pci;
313
314         /* Disable HPET */
315         uint32_t no_hpet_present;
316         int no_hpet;
317
318         /* No shared config (mmap'd files) */
319         uint32_t no_shconf_present;
320         int no_shconf;
321
322         /* Add driver */
323         char *add_driver;
324
325         /*  Memory to allocate on sockets (comma separated values)*/
326         char *socket_mem;
327
328         /* Directory where hugetlbfs is mounted */
329         char *huge_dir;
330
331         /* Prefix for hugepage filenames */
332         char *file_prefix;
333
334         /* Base virtual address */
335         char *base_virtaddr;
336
337         /* Create /dev/uioX (usually done by hotplug) */
338         uint32_t create_uio_dev_present;
339         int create_uio_dev;
340
341         /* Interrupt mode for VFIO (legacy|msi|msix) */
342         char *vfio_intr;
343
344         /* Support running on Xen dom0 without hugetlbfs */
345         uint32_t xen_dom0_present;
346         int xen_dom0;
347 };
348
349 #ifndef APP_APPNAME_SIZE
350 #define APP_APPNAME_SIZE                         256
351 #endif
352
353 #ifndef APP_MAX_MEMPOOLS
354 #define APP_MAX_MEMPOOLS                         8
355 #endif
356
357 #ifndef APP_MAX_LINKS
358 #define APP_MAX_LINKS                            16
359 #endif
360
361 #ifndef APP_LINK_MAX_HWQ_IN
362 #define APP_LINK_MAX_HWQ_IN                      64
363 #endif
364
365 #ifndef APP_LINK_MAX_HWQ_OUT
366 #define APP_LINK_MAX_HWQ_OUT                     64
367 #endif
368
369 #define APP_MAX_HWQ_IN                     (APP_MAX_LINKS * APP_LINK_MAX_HWQ_IN)
370
371 #define APP_MAX_HWQ_OUT                   (APP_MAX_LINKS * APP_LINK_MAX_HWQ_OUT)
372
373 #ifndef APP_MAX_PKTQ_SWQ
374 #define APP_MAX_PKTQ_SWQ                         256
375 #endif
376
377 #define APP_MAX_PKTQ_TM                          APP_MAX_LINKS
378
379 #ifndef APP_MAX_PKTQ_SOURCE
380 #define APP_MAX_PKTQ_SOURCE                      16
381 #endif
382
383 #ifndef APP_MAX_PKTQ_SINK
384 #define APP_MAX_PKTQ_SINK                        16
385 #endif
386
387 #ifndef APP_MAX_MSGQ
388 #define APP_MAX_MSGQ                             64
389 #endif
390
391 #ifndef APP_MAX_PIPELINES
392 #define APP_MAX_PIPELINES                        64
393 #endif
394
395 #ifndef APP_EAL_ARGC
396 #define APP_EAL_ARGC                             32
397 #endif
398
399 #ifndef APP_MAX_PIPELINE_TYPES
400 #define APP_MAX_PIPELINE_TYPES                   64
401 #endif
402
403 #ifndef APP_MAX_THREADS
404 #define APP_MAX_THREADS                          RTE_MAX_LCORE
405 #endif
406
407 #ifndef APP_MAX_CMDS
408 #define APP_MAX_CMDS                             64
409 #endif
410
411 struct app_params {
412         /* Config */
413         char app_name[APP_APPNAME_SIZE];
414         const char *config_file;
415         const char *script_file;
416         const char *parser_file;
417         const char *output_file;
418         const char *preproc;
419         const char *preproc_args;
420         uint64_t port_mask;
421         uint32_t log_level;
422
423         struct app_eal_params eal_params;
424         struct app_mempool_params mempool_params[APP_MAX_MEMPOOLS];
425         struct app_link_params link_params[APP_MAX_LINKS];
426         struct app_pktq_hwq_in_params hwq_in_params[APP_MAX_HWQ_IN];
427         struct app_pktq_hwq_out_params hwq_out_params[APP_MAX_HWQ_OUT];
428         struct app_pktq_swq_params swq_params[APP_MAX_PKTQ_SWQ];
429         struct app_pktq_tm_params tm_params[APP_MAX_PKTQ_TM];
430         struct app_pktq_source_params source_params[APP_MAX_PKTQ_SOURCE];
431         struct app_pktq_sink_params sink_params[APP_MAX_PKTQ_SINK];
432         struct app_msgq_params msgq_params[APP_MAX_MSGQ];
433         struct app_pipeline_params pipeline_params[APP_MAX_PIPELINES];
434
435         uint32_t n_mempools;
436         uint32_t n_links;
437         uint32_t n_pktq_hwq_in;
438         uint32_t n_pktq_hwq_out;
439         uint32_t n_pktq_swq;
440         uint32_t n_pktq_tm;
441         uint32_t n_pktq_source;
442         uint32_t n_pktq_sink;
443         uint32_t n_msgq;
444         uint32_t n_pipelines;
445
446         /* Init */
447         char *eal_argv[1 + APP_EAL_ARGC];
448         struct cpu_core_map *core_map;
449         uint64_t core_mask;
450         struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
451         struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
452         struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
453         struct rte_ring *msgq[APP_MAX_MSGQ];
454         struct pipeline_type pipeline_type[APP_MAX_PIPELINE_TYPES];
455         struct app_pipeline_data pipeline_data[APP_MAX_PIPELINES];
456         struct app_thread_data thread_data[APP_MAX_THREADS];
457         cmdline_parse_ctx_t cmds[APP_MAX_CMDS + 1];
458
459         int eal_argc;
460         uint32_t n_pipeline_types;
461         uint32_t n_cmds;
462 };
463
464 #define APP_PARAM_VALID(obj) ((obj)->name != NULL)
465
466 #define APP_PARAM_COUNT(obj_array, n_objs)                              \
467 {                                                                       \
468         size_t i;                                                       \
469                                                                         \
470         n_objs = 0;                                                     \
471         for (i = 0; i < RTE_DIM(obj_array); i++)                        \
472                 if (APP_PARAM_VALID(&((obj_array)[i])))                 \
473                         n_objs++;                                       \
474 }
475
476 #define APP_PARAM_FIND(obj_array, key)                                  \
477 ({                                                                      \
478         ssize_t obj_idx;                                                \
479         const ssize_t obj_count = RTE_DIM(obj_array);                   \
480                                                                         \
481         for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {             \
482                 if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))          \
483                         continue;                                       \
484                                                                         \
485                 if (strcmp(key, (obj_array)[obj_idx].name) == 0)        \
486                         break;                                          \
487         }                                                               \
488         obj_idx < obj_count ? obj_idx : -ENOENT;                        \
489 })
490
491 #define APP_PARAM_FIND_BY_ID(obj_array, prefix, id, obj)                \
492 do {                                                                    \
493         char name[APP_PARAM_NAME_SIZE];                                 \
494         ssize_t pos;                                                    \
495                                                                         \
496         sprintf(name, prefix "%" PRIu32, id);                           \
497         pos = APP_PARAM_FIND(obj_array, name);                          \
498         obj = (pos < 0) ? NULL : &((obj_array)[pos]);                   \
499 } while (0)
500
501 #define APP_PARAM_GET_ID(obj, prefix, id)                               \
502 do                                                                      \
503         sscanf(obj->name, prefix "%" SCNu32, &id);                              \
504 while (0)                                                               \
505
506 #define APP_PARAM_ADD(obj_array, obj_name)                              \
507 ({                                                                      \
508         ssize_t obj_idx;                                                \
509         const ssize_t obj_count = RTE_DIM(obj_array);                   \
510                                                                         \
511         obj_idx = APP_PARAM_FIND(obj_array, obj_name);                  \
512         if (obj_idx < 0) {                                              \
513                 for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {     \
514                         if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))  \
515                                 break;                                  \
516                 }                                                       \
517                                                                         \
518                 if (obj_idx < obj_count) {                              \
519                         (obj_array)[obj_idx].name = strdup(obj_name);   \
520                         if ((obj_array)[obj_idx].name == NULL)          \
521                                 obj_idx = -EINVAL;                      \
522                 } else                                                  \
523                         obj_idx = -ENOMEM;                              \
524         }                                                               \
525         obj_idx;                                                        \
526 })
527
528 #define APP_CHECK(exp, fmt, ...)                                        \
529 do {                                                                    \
530         if (!(exp)) {                                                   \
531                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
532                 abort();                                                \
533         }                                                               \
534 } while (0)
535
536 enum app_log_level {
537         APP_LOG_LEVEL_HIGH = 1,
538         APP_LOG_LEVEL_LOW,
539         APP_LOG_LEVELS
540 };
541
542 #define APP_LOG(app, level, fmt, ...)                                   \
543 do {                                                                    \
544         if (app->log_level >= APP_LOG_LEVEL_ ## level)                  \
545                 fprintf(stdout, "[APP] " fmt "\n", ## __VA_ARGS__);     \
546 } while (0)
547
548 static inline uint32_t
549 app_link_get_n_rxq(struct app_params *app, struct app_link_params *link)
550 {
551         uint32_t n_rxq = 0, link_id, i;
552         uint32_t n_pktq_hwq_in = RTE_MIN(app->n_pktq_hwq_in,
553                 RTE_DIM(app->hwq_in_params));
554
555         APP_PARAM_GET_ID(link, "LINK", link_id);
556
557         for (i = 0; i < n_pktq_hwq_in; i++) {
558                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
559                 uint32_t rxq_link_id, rxq_queue_id;
560
561                 sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
562                         &rxq_link_id, &rxq_queue_id);
563                 if (rxq_link_id == link_id)
564                         n_rxq++;
565         }
566
567         return n_rxq;
568 }
569
570 static inline uint32_t
571 app_link_get_n_txq(struct app_params *app, struct app_link_params *link)
572 {
573         uint32_t n_txq = 0, link_id, i;
574         uint32_t n_pktq_hwq_out = RTE_MIN(app->n_pktq_hwq_out,
575                 RTE_DIM(app->hwq_out_params));
576
577         APP_PARAM_GET_ID(link, "LINK", link_id);
578
579         for (i = 0; i < n_pktq_hwq_out; i++) {
580                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
581                 uint32_t txq_link_id, txq_queue_id;
582
583                 sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
584                         &txq_link_id, &txq_queue_id);
585                 if (txq_link_id == link_id)
586                         n_txq++;
587         }
588
589         return n_txq;
590 }
591
592 static inline uint32_t
593 app_rxq_get_readers(struct app_params *app, struct app_pktq_hwq_in_params *rxq)
594 {
595         uint32_t pos = rxq - app->hwq_in_params;
596         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
597                 RTE_DIM(app->pipeline_params));
598         uint32_t n_readers = 0, i;
599
600         for (i = 0; i < n_pipelines; i++) {
601                 struct app_pipeline_params *p = &app->pipeline_params[i];
602                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
603                 uint32_t j;
604
605                 for (j = 0; j < n_pktq_in; j++) {
606                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
607
608                         if ((pktq->type == APP_PKTQ_IN_HWQ) &&
609                                 (pktq->id == pos))
610                                 n_readers++;
611                 }
612         }
613
614         return n_readers;
615 }
616
617 static inline uint32_t
618 app_swq_get_readers(struct app_params *app, struct app_pktq_swq_params *swq)
619 {
620         uint32_t pos = swq - app->swq_params;
621         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
622                 RTE_DIM(app->pipeline_params));
623         uint32_t n_readers = 0, i;
624
625         for (i = 0; i < n_pipelines; i++) {
626                 struct app_pipeline_params *p = &app->pipeline_params[i];
627                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
628                 uint32_t j;
629
630                 for (j = 0; j < n_pktq_in; j++) {
631                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
632
633                         if ((pktq->type == APP_PKTQ_IN_SWQ) &&
634                                 (pktq->id == pos))
635                                 n_readers++;
636                 }
637         }
638
639         return n_readers;
640 }
641
642 static inline uint32_t
643 app_tm_get_readers(struct app_params *app, struct app_pktq_tm_params *tm)
644 {
645         uint32_t pos = tm - app->tm_params;
646         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
647                 RTE_DIM(app->pipeline_params));
648         uint32_t n_readers = 0, i;
649
650         for (i = 0; i < n_pipelines; i++) {
651                 struct app_pipeline_params *p = &app->pipeline_params[i];
652                 uint32_t n_pktq_in = RTE_MIN(p->n_pktq_in, RTE_DIM(p->pktq_in));
653                 uint32_t j;
654
655                 for (j = 0; j < n_pktq_in; j++) {
656                         struct app_pktq_in_params *pktq = &p->pktq_in[j];
657
658                         if ((pktq->type == APP_PKTQ_IN_TM) &&
659                                 (pktq->id == pos))
660                                 n_readers++;
661                 }
662         }
663
664         return n_readers;
665 }
666
667 static inline uint32_t
668 app_source_get_readers(struct app_params *app,
669 struct app_pktq_source_params *source)
670 {
671         uint32_t pos = source - app->source_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_SOURCE) &&
685                                 (pktq->id == pos))
686                                 n_readers++;
687                 }
688         }
689
690         return n_readers;
691 }
692
693 static inline uint32_t
694 app_msgq_get_readers(struct app_params *app, struct app_msgq_params *msgq)
695 {
696         uint32_t pos = msgq - app->msgq_params;
697         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
698                 RTE_DIM(app->pipeline_params));
699         uint32_t n_readers = 0, i;
700
701         for (i = 0; i < n_pipelines; i++) {
702                 struct app_pipeline_params *p = &app->pipeline_params[i];
703                 uint32_t n_msgq_in = RTE_MIN(p->n_msgq_in, RTE_DIM(p->msgq_in));
704                 uint32_t j;
705
706                 for (j = 0; j < n_msgq_in; j++)
707                         if (p->msgq_in[j] == pos)
708                                 n_readers++;
709         }
710
711         return n_readers;
712 }
713
714 static inline uint32_t
715 app_txq_get_writers(struct app_params *app, struct app_pktq_hwq_out_params *txq)
716 {
717         uint32_t pos = txq - app->hwq_out_params;
718         uint32_t n_pipelines = RTE_MIN(app->n_pipelines,
719                 RTE_DIM(app->pipeline_params));
720         uint32_t n_writers = 0, i;
721
722         for (i = 0; i < n_pipelines; i++) {
723                 struct app_pipeline_params *p = &app->pipeline_params[i];
724                 uint32_t n_pktq_out = RTE_MIN(p->n_pktq_out,
725                         RTE_DIM(p->pktq_out));
726                 uint32_t j;
727
728                 for (j = 0; j < n_pktq_out; j++) {
729                         struct app_pktq_out_params *pktq = &p->pktq_out[j];
730
731                         if ((pktq->type == APP_PKTQ_OUT_HWQ) &&
732                                 (pktq->id == pos))
733                                 n_writers++;
734                 }
735         }
736
737         return n_writers;
738 }
739
740 static inline uint32_t
741 app_swq_get_writers(struct app_params *app, struct app_pktq_swq_params *swq)
742 {
743         uint32_t pos = swq - app->swq_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_SWQ) &&
758                                 (pktq->id == pos))
759                                 n_writers++;
760                 }
761         }
762
763         return n_writers;
764 }
765
766 static inline uint32_t
767 app_tm_get_writers(struct app_params *app, struct app_pktq_tm_params *tm)
768 {
769         uint32_t pos = tm - app->tm_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_TM) &&
784                                 (pktq->id == pos))
785                                 n_writers++;
786                 }
787         }
788
789         return n_writers;
790 }
791
792 static inline uint32_t
793 app_sink_get_writers(struct app_params *app, struct app_pktq_sink_params *sink)
794 {
795         uint32_t pos = sink - app->sink_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_SINK) &&
810                                 (pktq->id == pos))
811                                 n_writers++;
812                 }
813         }
814
815         return n_writers;
816 }
817
818 static inline uint32_t
819 app_msgq_get_writers(struct app_params *app, struct app_msgq_params *msgq)
820 {
821         uint32_t pos = msgq - app->msgq_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_msgq_out = RTE_MIN(p->n_msgq_out,
829                         RTE_DIM(p->msgq_out));
830                 uint32_t j;
831
832                 for (j = 0; j < n_msgq_out; j++)
833                         if (p->msgq_out[j] == pos)
834                                 n_writers++;
835         }
836
837         return n_writers;
838 }
839
840 static inline struct app_link_params *
841 app_get_link_for_rxq(struct app_params *app, struct app_pktq_hwq_in_params *p)
842 {
843         char link_name[APP_PARAM_NAME_SIZE];
844         ssize_t link_param_idx;
845         uint32_t rxq_link_id, rxq_queue_id;
846
847         sscanf(p->name, "RXQ%" SCNu32 ".%" SCNu32,
848                 &rxq_link_id, &rxq_queue_id);
849         sprintf(link_name, "LINK%" PRIu32, rxq_link_id);
850         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
851         APP_CHECK((link_param_idx >= 0),
852                 "Cannot find %s for %s", link_name, p->name);
853
854         return &app->link_params[link_param_idx];
855 }
856
857 static inline struct app_link_params *
858 app_get_link_for_txq(struct app_params *app, struct app_pktq_hwq_out_params *p)
859 {
860         char link_name[APP_PARAM_NAME_SIZE];
861         ssize_t link_param_idx;
862         uint32_t txq_link_id, txq_queue_id;
863
864         sscanf(p->name, "TXQ%" SCNu32 ".%" SCNu32,
865                 &txq_link_id, &txq_queue_id);
866         sprintf(link_name, "LINK%" PRIu32, txq_link_id);
867         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
868         APP_CHECK((link_param_idx >= 0),
869                 "Cannot find %s for %s", link_name, p->name);
870
871         return &app->link_params[link_param_idx];
872 }
873
874 static inline struct app_link_params *
875 app_get_link_for_tm(struct app_params *app, struct app_pktq_tm_params *p_tm)
876 {
877         char link_name[APP_PARAM_NAME_SIZE];
878         uint32_t link_id;
879         ssize_t link_param_idx;
880
881         sscanf(p_tm->name, "TM%" PRIu32, &link_id);
882         sprintf(link_name, "LINK%" PRIu32, link_id);
883         link_param_idx = APP_PARAM_FIND(app->link_params, link_name);
884         APP_CHECK((link_param_idx >= 0),
885                 "Cannot find %s for %s", link_name, p_tm->name);
886
887         return &app->link_params[link_param_idx];
888 }
889
890 int app_config_init(struct app_params *app);
891
892 int app_config_args(struct app_params *app,
893         int argc, char **argv);
894
895 int app_config_preproc(struct app_params *app);
896
897 int app_config_parse(struct app_params *app,
898         const char *file_name);
899
900 int app_config_parse_tm(struct app_params *app);
901
902 void app_config_save(struct app_params *app,
903         const char *file_name);
904
905 int app_config_check(struct app_params *app);
906
907 int app_init(struct app_params *app);
908
909 int app_thread(void *arg);
910
911 int app_pipeline_type_register(struct app_params *app,
912         struct pipeline_type *ptype);
913
914 struct pipeline_type *app_pipeline_type_find(struct app_params *app,
915         char *name);
916
917 void app_link_up_internal(struct app_params *app,
918         struct app_link_params *cp);
919
920 void app_link_down_internal(struct app_params *app,
921         struct app_link_params *cp);
922
923 #endif