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