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