examples/ip_pipeline: clean config parser
[dpdk.git] / examples / ip_pipeline / pipeline / pipeline_flow_classification_be.c
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 #include <string.h>
35
36 #include <rte_common.h>
37 #include <rte_malloc.h>
38 #include <rte_table_hash.h>
39 #include <rte_byteorder.h>
40 #include <pipeline.h>
41
42 #include "pipeline_flow_classification_be.h"
43 #include "pipeline_actions_common.h"
44 #include "parser.h"
45 #include "hash_func.h"
46
47 struct pipeline_flow_classification {
48         struct pipeline p;
49         pipeline_msg_req_handler custom_handlers[PIPELINE_FC_MSG_REQS];
50
51         uint32_t n_flows;
52         uint32_t key_size;
53         uint32_t flow_id;
54
55         uint32_t key_offset;
56         uint32_t hash_offset;
57         uint8_t key_mask[PIPELINE_FC_FLOW_KEY_MAX_SIZE];
58         uint32_t flow_id_offset;
59
60 } __rte_cache_aligned;
61
62 static void *
63 pipeline_fc_msg_req_custom_handler(struct pipeline *p, void *msg);
64
65 static pipeline_msg_req_handler handlers[] = {
66         [PIPELINE_MSG_REQ_PING] =
67                 pipeline_msg_req_ping_handler,
68         [PIPELINE_MSG_REQ_STATS_PORT_IN] =
69                 pipeline_msg_req_stats_port_in_handler,
70         [PIPELINE_MSG_REQ_STATS_PORT_OUT] =
71                 pipeline_msg_req_stats_port_out_handler,
72         [PIPELINE_MSG_REQ_STATS_TABLE] =
73                 pipeline_msg_req_stats_table_handler,
74         [PIPELINE_MSG_REQ_PORT_IN_ENABLE] =
75                 pipeline_msg_req_port_in_enable_handler,
76         [PIPELINE_MSG_REQ_PORT_IN_DISABLE] =
77                 pipeline_msg_req_port_in_disable_handler,
78         [PIPELINE_MSG_REQ_CUSTOM] =
79                 pipeline_fc_msg_req_custom_handler,
80 };
81
82 static void *
83 pipeline_fc_msg_req_add_handler(struct pipeline *p, void *msg);
84
85 static void *
86 pipeline_fc_msg_req_add_bulk_handler(struct pipeline *p, void *msg);
87
88 static void *
89 pipeline_fc_msg_req_del_handler(struct pipeline *p, void *msg);
90
91 static void *
92 pipeline_fc_msg_req_add_default_handler(struct pipeline *p, void *msg);
93
94 static void *
95 pipeline_fc_msg_req_del_default_handler(struct pipeline *p, void *msg);
96
97 static pipeline_msg_req_handler custom_handlers[] = {
98         [PIPELINE_FC_MSG_REQ_FLOW_ADD] =
99                 pipeline_fc_msg_req_add_handler,
100         [PIPELINE_FC_MSG_REQ_FLOW_ADD_BULK] =
101                 pipeline_fc_msg_req_add_bulk_handler,
102         [PIPELINE_FC_MSG_REQ_FLOW_DEL] =
103                 pipeline_fc_msg_req_del_handler,
104         [PIPELINE_FC_MSG_REQ_FLOW_ADD_DEFAULT] =
105                 pipeline_fc_msg_req_add_default_handler,
106         [PIPELINE_FC_MSG_REQ_FLOW_DEL_DEFAULT] =
107                 pipeline_fc_msg_req_del_default_handler,
108 };
109
110 /*
111  * Flow table
112  */
113 struct flow_table_entry {
114         struct rte_pipeline_table_entry head;
115
116         uint32_t flow_id;
117         uint32_t pad;
118 };
119
120 rte_table_hash_op_hash hash_func[] = {
121         hash_default_key8,
122         hash_default_key16,
123         hash_default_key24,
124         hash_default_key32,
125         hash_default_key40,
126         hash_default_key48,
127         hash_default_key56,
128         hash_default_key64
129 };
130
131 /*
132  * Flow table AH - Write flow_id to packet meta-data
133  */
134 static inline void
135 pkt_work_flow_id(
136         struct rte_mbuf *pkt,
137         struct rte_pipeline_table_entry *table_entry,
138         void *arg)
139 {
140         struct pipeline_flow_classification *p_fc = arg;
141         uint32_t *flow_id_ptr =
142                 RTE_MBUF_METADATA_UINT32_PTR(pkt, p_fc->flow_id_offset);
143         struct flow_table_entry *entry =
144                 (struct flow_table_entry *) table_entry;
145
146         /* Read */
147         uint32_t flow_id = entry->flow_id;
148
149         /* Compute */
150
151         /* Write */
152         *flow_id_ptr = flow_id;
153 }
154
155 static inline void
156 pkt4_work_flow_id(
157         struct rte_mbuf **pkts,
158         struct rte_pipeline_table_entry **table_entries,
159         void *arg)
160 {
161         struct pipeline_flow_classification *p_fc = arg;
162
163         uint32_t *flow_id_ptr0 =
164                 RTE_MBUF_METADATA_UINT32_PTR(pkts[0], p_fc->flow_id_offset);
165         uint32_t *flow_id_ptr1 =
166                 RTE_MBUF_METADATA_UINT32_PTR(pkts[1], p_fc->flow_id_offset);
167         uint32_t *flow_id_ptr2 =
168                 RTE_MBUF_METADATA_UINT32_PTR(pkts[2], p_fc->flow_id_offset);
169         uint32_t *flow_id_ptr3 =
170                 RTE_MBUF_METADATA_UINT32_PTR(pkts[3], p_fc->flow_id_offset);
171
172         struct flow_table_entry *entry0 =
173                 (struct flow_table_entry *) table_entries[0];
174         struct flow_table_entry *entry1 =
175                 (struct flow_table_entry *) table_entries[1];
176         struct flow_table_entry *entry2 =
177                 (struct flow_table_entry *) table_entries[2];
178         struct flow_table_entry *entry3 =
179                 (struct flow_table_entry *) table_entries[3];
180
181         /* Read */
182         uint32_t flow_id0 = entry0->flow_id;
183         uint32_t flow_id1 = entry1->flow_id;
184         uint32_t flow_id2 = entry2->flow_id;
185         uint32_t flow_id3 = entry3->flow_id;
186
187         /* Compute */
188
189         /* Write */
190         *flow_id_ptr0 = flow_id0;
191         *flow_id_ptr1 = flow_id1;
192         *flow_id_ptr2 = flow_id2;
193         *flow_id_ptr3 = flow_id3;
194 }
195
196 PIPELINE_TABLE_AH_HIT(fc_table_ah_hit,
197                 pkt_work_flow_id, pkt4_work_flow_id);
198
199 static rte_pipeline_table_action_handler_hit
200 get_fc_table_ah_hit(struct pipeline_flow_classification *p)
201 {
202         if (p->flow_id)
203                 return fc_table_ah_hit;
204
205         return NULL;
206 }
207
208 /*
209  * Argument parsing
210  */
211 static int
212 pipeline_fc_parse_args(struct pipeline_flow_classification *p,
213         struct pipeline_params *params)
214 {
215         uint32_t n_flows_present = 0;
216         uint32_t key_offset_present = 0;
217         uint32_t key_size_present = 0;
218         uint32_t hash_offset_present = 0;
219         uint32_t key_mask_present = 0;
220         uint32_t flow_id_offset_present = 0;
221
222         uint32_t i;
223         char key_mask_str[PIPELINE_FC_FLOW_KEY_MAX_SIZE * 2];
224
225         p->hash_offset = 0;
226
227         /* default values */
228         p->flow_id = 0;
229
230         for (i = 0; i < params->n_args; i++) {
231                 char *arg_name = params->args_name[i];
232                 char *arg_value = params->args_value[i];
233
234                 /* n_flows */
235                 if (strcmp(arg_name, "n_flows") == 0) {
236                         int status;
237
238                         PIPELINE_PARSE_ERR_DUPLICATE(
239                                 n_flows_present == 0, params->name,
240                                 arg_name);
241                         n_flows_present = 1;
242
243                         status = parser_read_uint32(&p->n_flows,
244                                 arg_value);
245                         PIPELINE_PARSE_ERR_INV_VAL(((status != -EINVAL) &&
246                                 (p->n_flows != 0)), params->name,
247                                 arg_name, arg_value);
248                         PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
249                                 params->name, arg_name, arg_value);
250
251                         continue;
252                 }
253
254                 /* key_offset */
255                 if (strcmp(arg_name, "key_offset") == 0) {
256                         int status;
257
258                         PIPELINE_PARSE_ERR_DUPLICATE(
259                                 key_offset_present == 0, params->name,
260                                 arg_name);
261                         key_offset_present = 1;
262
263                         status = parser_read_uint32(&p->key_offset,
264                                 arg_value);
265                         PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
266                                 params->name, arg_name, arg_value);
267                         PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
268                                 params->name, arg_name, arg_value);
269
270                         continue;
271                 }
272
273                 /* key_size */
274                 if (strcmp(arg_name, "key_size") == 0) {
275                         int status;
276
277                         PIPELINE_PARSE_ERR_DUPLICATE(
278                                 key_size_present == 0, params->name,
279                                 arg_name);
280                         key_size_present = 1;
281
282                         status = parser_read_uint32(&p->key_size,
283                                 arg_value);
284                         PIPELINE_PARSE_ERR_INV_VAL(((status != -EINVAL) &&
285                                 (p->key_size != 0) &&
286                                 (p->key_size % 8 == 0)),
287                                 params->name, arg_name, arg_value);
288                         PIPELINE_PARSE_ERR_OUT_RNG(((status != -ERANGE) &&
289                                 (p->key_size <=
290                                 PIPELINE_FC_FLOW_KEY_MAX_SIZE)),
291                                 params->name, arg_name, arg_value);
292
293                         continue;
294                 }
295
296                 /* key_mask */
297                 if (strcmp(arg_name, "key_mask") == 0) {
298                         int mask_str_len = strlen(arg_value);
299
300                         PIPELINE_PARSE_ERR_DUPLICATE(
301                                 key_mask_present == 0,
302                                 params->name, arg_name);
303                         key_mask_present = 1;
304
305                         PIPELINE_ARG_CHECK((mask_str_len <
306                                 (PIPELINE_FC_FLOW_KEY_MAX_SIZE * 2)),
307                                 "Parse error in section \"%s\": entry "
308                                 "\"%s\" is too long", params->name,
309                                 arg_name);
310
311                         snprintf(key_mask_str, mask_str_len, "%s",
312                                 arg_value);
313
314                         continue;
315                 }
316
317                 /* hash_offset */
318                 if (strcmp(arg_name, "hash_offset") == 0) {
319                         int status;
320
321                         PIPELINE_PARSE_ERR_DUPLICATE(
322                                 hash_offset_present == 0, params->name,
323                                 arg_name);
324                         hash_offset_present = 1;
325
326                         status = parser_read_uint32(&p->hash_offset,
327                                 arg_value);
328                         PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
329                                 params->name, arg_name, arg_value);
330                         PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
331                                 params->name, arg_name, arg_value);
332
333                         continue;
334                 }
335
336                 /* flow_id_offset */
337                 if (strcmp(arg_name, "flowid_offset") == 0) {
338                         int status;
339
340                         PIPELINE_PARSE_ERR_DUPLICATE(
341                                 flow_id_offset_present == 0, params->name,
342                                 arg_name);
343                         flow_id_offset_present = 1;
344
345                         status = parser_read_uint32(&p->flow_id_offset,
346                                 arg_value);
347                         PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
348                                 params->name, arg_name, arg_value);
349                         PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
350                                 params->name, arg_name, arg_value);
351
352                         p->flow_id = 1;
353
354                         continue;
355                 }
356
357                 /* Unknown argument */
358                 PIPELINE_PARSE_ERR_INV_ENT(0, params->name, arg_name);
359         }
360
361         /* Check that mandatory arguments are present */
362         PIPELINE_PARSE_ERR_MANDATORY((n_flows_present), params->name,
363                 "n_flows");
364         PIPELINE_PARSE_ERR_MANDATORY((key_offset_present), params->name,
365                 "key_offset");
366         PIPELINE_PARSE_ERR_MANDATORY((key_size_present), params->name,
367                 "key_size");
368
369         if (key_mask_present) {
370                 uint32_t key_size = p->key_size;
371                 int status;
372
373                 PIPELINE_ARG_CHECK((strlen(key_mask_str) ==
374                         (key_size * 2)), "Parse error in section "
375                         "\"%s\": key_mask should have exactly %u hex "
376                         "digits", params->name, (key_size * 2));
377
378                 status = parse_hex_string(key_mask_str, p->key_mask,
379                         &p->key_size);
380
381                 PIPELINE_PARSE_ERR_INV_VAL(((status == 0) &&
382                         (key_size == p->key_size)), params->name,
383                         "key_mask", key_mask_str);
384         }
385
386         return 0;
387 }
388
389 static void *pipeline_fc_init(struct pipeline_params *params,
390         __rte_unused void *arg)
391 {
392         struct pipeline *p;
393         struct pipeline_flow_classification *p_fc;
394         uint32_t size, i;
395
396         /* Check input arguments */
397         if (params == NULL)
398                 return NULL;
399
400         /* Memory allocation */
401         size = RTE_CACHE_LINE_ROUNDUP(
402                 sizeof(struct pipeline_flow_classification));
403         p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
404         if (p == NULL)
405                 return NULL;
406         p_fc = (struct pipeline_flow_classification *) p;
407
408         strcpy(p->name, params->name);
409         p->log_level = params->log_level;
410
411         PLOG(p, HIGH, "Flow classification");
412
413         /* Parse arguments */
414         if (pipeline_fc_parse_args(p_fc, params))
415                 return NULL;
416
417         /* Pipeline */
418         {
419                 struct rte_pipeline_params pipeline_params = {
420                         .name = params->name,
421                         .socket_id = params->socket_id,
422                         .offset_port_id = 0,
423                 };
424
425                 p->p = rte_pipeline_create(&pipeline_params);
426                 if (p->p == NULL) {
427                         rte_free(p);
428                         return NULL;
429                 }
430         }
431
432         /* Input ports */
433         p->n_ports_in = params->n_ports_in;
434         for (i = 0; i < p->n_ports_in; i++) {
435                 struct rte_pipeline_port_in_params port_params = {
436                         .ops = pipeline_port_in_params_get_ops(
437                                 &params->port_in[i]),
438                         .arg_create = pipeline_port_in_params_convert(
439                                 &params->port_in[i]),
440                         .f_action = NULL,
441                         .arg_ah = NULL,
442                         .burst_size = params->port_in[i].burst_size,
443                 };
444
445                 int status = rte_pipeline_port_in_create(p->p,
446                         &port_params,
447                         &p->port_in_id[i]);
448
449                 if (status) {
450                         rte_pipeline_free(p->p);
451                         rte_free(p);
452                         return NULL;
453                 }
454         }
455
456         /* Output ports */
457         p->n_ports_out = params->n_ports_out;
458         for (i = 0; i < p->n_ports_out; i++) {
459                 struct rte_pipeline_port_out_params port_params = {
460                         .ops = pipeline_port_out_params_get_ops(
461                                 &params->port_out[i]),
462                         .arg_create = pipeline_port_out_params_convert(
463                                 &params->port_out[i]),
464                         .f_action = NULL,
465                         .f_action_bulk = NULL,
466                         .arg_ah = NULL,
467                 };
468
469                 int status = rte_pipeline_port_out_create(p->p,
470                         &port_params,
471                         &p->port_out_id[i]);
472
473                 if (status) {
474                         rte_pipeline_free(p->p);
475                         rte_free(p);
476                         return NULL;
477                 }
478         }
479
480         /* Tables */
481         p->n_tables = 1;
482         {
483                 struct rte_table_hash_key8_ext_params
484                         table_hash_key8_params = {
485                         .n_entries = p_fc->n_flows,
486                         .n_entries_ext = p_fc->n_flows,
487                         .signature_offset = p_fc->hash_offset,
488                         .key_offset = p_fc->key_offset,
489                         .f_hash = hash_func[(p_fc->key_size / 8) - 1],
490                         .key_mask = p_fc->key_mask,
491                         .seed = 0,
492                 };
493
494                 struct rte_table_hash_key16_ext_params
495                         table_hash_key16_params = {
496                         .n_entries = p_fc->n_flows,
497                         .n_entries_ext = p_fc->n_flows,
498                         .signature_offset = p_fc->hash_offset,
499                         .key_offset = p_fc->key_offset,
500                         .f_hash = hash_func[(p_fc->key_size / 8) - 1],
501                         .key_mask = p_fc->key_mask,
502                         .seed = 0,
503                 };
504
505                 struct rte_table_hash_ext_params
506                         table_hash_params = {
507                         .key_size = p_fc->key_size,
508                         .n_keys = p_fc->n_flows,
509                         .n_buckets = p_fc->n_flows / 4,
510                         .n_buckets_ext = p_fc->n_flows / 4,
511                         .f_hash = hash_func[(p_fc->key_size / 8) - 1],
512                         .seed = 0,
513                         .signature_offset = p_fc->hash_offset,
514                         .key_offset = p_fc->key_offset,
515                 };
516
517                 struct rte_pipeline_table_params table_params = {
518                         .ops = NULL, /* set below */
519                         .arg_create = NULL, /* set below */
520                         .f_action_hit = get_fc_table_ah_hit(p_fc),
521                         .f_action_miss = NULL,
522                         .arg_ah = p_fc,
523                         .action_data_size = sizeof(struct flow_table_entry) -
524                                 sizeof(struct rte_pipeline_table_entry),
525                 };
526
527                 int status;
528
529                 switch (p_fc->key_size) {
530                 case 8:
531                         if (p_fc->hash_offset != 0) {
532                                 table_params.ops =
533                                         &rte_table_hash_key8_ext_ops;
534                         } else {
535                                 table_params.ops =
536                                         &rte_table_hash_key8_ext_dosig_ops;
537                         }
538                         table_params.arg_create = &table_hash_key8_params;
539                         break;
540
541                 case 16:
542                         if (p_fc->hash_offset != 0) {
543                                 table_params.ops =
544                                         &rte_table_hash_key16_ext_ops;
545                         } else {
546                                 table_params.ops =
547                                         &rte_table_hash_key16_ext_dosig_ops;
548                         }
549                         table_params.arg_create = &table_hash_key16_params;
550                         break;
551
552                 default:
553                         table_params.ops = &rte_table_hash_ext_ops;
554                         table_params.arg_create = &table_hash_params;
555                 }
556
557                 status = rte_pipeline_table_create(p->p,
558                         &table_params,
559                         &p->table_id[0]);
560
561                 if (status) {
562                         rte_pipeline_free(p->p);
563                         rte_free(p);
564                         return NULL;
565                 }
566         }
567
568         /* Connecting input ports to tables */
569         for (i = 0; i < p->n_ports_in; i++) {
570                 int status = rte_pipeline_port_in_connect_to_table(p->p,
571                         p->port_in_id[i],
572                         p->table_id[0]);
573
574                 if (status) {
575                         rte_pipeline_free(p->p);
576                         rte_free(p);
577                         return NULL;
578                 }
579         }
580
581         /* Enable input ports */
582         for (i = 0; i < p->n_ports_in; i++) {
583                 int status = rte_pipeline_port_in_enable(p->p,
584                         p->port_in_id[i]);
585
586                 if (status) {
587                         rte_pipeline_free(p->p);
588                         rte_free(p);
589                         return NULL;
590                 }
591         }
592
593         /* Check pipeline consistency */
594         if (rte_pipeline_check(p->p) < 0) {
595                 rte_pipeline_free(p->p);
596                 rte_free(p);
597                 return NULL;
598         }
599
600         /* Message queues */
601         p->n_msgq = params->n_msgq;
602         for (i = 0; i < p->n_msgq; i++)
603                 p->msgq_in[i] = params->msgq_in[i];
604         for (i = 0; i < p->n_msgq; i++)
605                 p->msgq_out[i] = params->msgq_out[i];
606
607         /* Message handlers */
608         memcpy(p->handlers, handlers, sizeof(p->handlers));
609         memcpy(p_fc->custom_handlers,
610                 custom_handlers,
611                 sizeof(p_fc->custom_handlers));
612
613         return p;
614 }
615
616 static int
617 pipeline_fc_free(void *pipeline)
618 {
619         struct pipeline *p = (struct pipeline *) pipeline;
620
621         /* Check input arguments */
622         if (p == NULL)
623                 return -1;
624
625         /* Free resources */
626         rte_pipeline_free(p->p);
627         rte_free(p);
628         return 0;
629 }
630
631 static int
632 pipeline_fc_track(void *pipeline,
633         __rte_unused uint32_t port_in,
634         uint32_t *port_out)
635 {
636         struct pipeline *p = (struct pipeline *) pipeline;
637
638         /* Check input arguments */
639         if ((p == NULL) ||
640                 (port_in >= p->n_ports_in) ||
641                 (port_out == NULL))
642                 return -1;
643
644         if (p->n_ports_in == 1) {
645                 *port_out = 0;
646                 return 0;
647         }
648
649         return -1;
650 }
651
652 static int
653 pipeline_fc_timer(void *pipeline)
654 {
655         struct pipeline *p = (struct pipeline *) pipeline;
656
657         pipeline_msg_req_handle(p);
658         rte_pipeline_flush(p->p);
659
660         return 0;
661 }
662
663 static void *
664 pipeline_fc_msg_req_custom_handler(struct pipeline *p, void *msg)
665 {
666         struct pipeline_flow_classification *p_fc =
667                         (struct pipeline_flow_classification *) p;
668         struct pipeline_custom_msg_req *req = msg;
669         pipeline_msg_req_handler f_handle;
670
671         f_handle = (req->subtype < PIPELINE_FC_MSG_REQS) ?
672                 p_fc->custom_handlers[req->subtype] :
673                 pipeline_msg_req_invalid_handler;
674
675         if (f_handle == NULL)
676                 f_handle = pipeline_msg_req_invalid_handler;
677
678         return f_handle(p, req);
679 }
680
681 static void *
682 pipeline_fc_msg_req_add_handler(struct pipeline *p, void *msg)
683 {
684         struct pipeline_fc_add_msg_req *req = msg;
685         struct pipeline_fc_add_msg_rsp *rsp = msg;
686
687         struct flow_table_entry entry = {
688                 .head = {
689                         .action = RTE_PIPELINE_ACTION_PORT,
690                         {.port_id = p->port_out_id[req->port_id]},
691                 },
692                 .flow_id = req->flow_id,
693         };
694
695         rsp->status = rte_pipeline_table_entry_add(p->p,
696                 p->table_id[0],
697                 &req->key,
698                 (struct rte_pipeline_table_entry *) &entry,
699                 &rsp->key_found,
700                 (struct rte_pipeline_table_entry **) &rsp->entry_ptr);
701
702         return rsp;
703 }
704
705 static void *
706 pipeline_fc_msg_req_add_bulk_handler(struct pipeline *p, void *msg)
707 {
708         struct pipeline_fc_add_bulk_msg_req *req = msg;
709         struct pipeline_fc_add_bulk_msg_rsp *rsp = msg;
710         uint32_t i;
711
712         for (i = 0; i < req->n_keys; i++) {
713                 struct pipeline_fc_add_bulk_flow_req *flow_req = &req->req[i];
714                 struct pipeline_fc_add_bulk_flow_rsp *flow_rsp = &req->rsp[i];
715
716                 struct flow_table_entry entry = {
717                         .head = {
718                                 .action = RTE_PIPELINE_ACTION_PORT,
719                                 {.port_id = p->port_out_id[flow_req->port_id]},
720                         },
721                         .flow_id = flow_req->flow_id,
722                 };
723
724                 int status = rte_pipeline_table_entry_add(p->p,
725                         p->table_id[0],
726                         &flow_req->key,
727                         (struct rte_pipeline_table_entry *) &entry,
728                         &flow_rsp->key_found,
729                         (struct rte_pipeline_table_entry **)
730                                 &flow_rsp->entry_ptr);
731
732                 if (status)
733                         break;
734         }
735
736         rsp->n_keys = i;
737
738         return rsp;
739 }
740
741 static void *
742 pipeline_fc_msg_req_del_handler(struct pipeline *p, void *msg)
743 {
744         struct pipeline_fc_del_msg_req *req = msg;
745         struct pipeline_fc_del_msg_rsp *rsp = msg;
746
747         rsp->status = rte_pipeline_table_entry_delete(p->p,
748                 p->table_id[0],
749                 &req->key,
750                 &rsp->key_found,
751                 NULL);
752
753         return rsp;
754 }
755
756 static void *
757 pipeline_fc_msg_req_add_default_handler(struct pipeline *p, void *msg)
758 {
759         struct pipeline_fc_add_default_msg_req *req = msg;
760         struct pipeline_fc_add_default_msg_rsp *rsp = msg;
761
762         struct flow_table_entry default_entry = {
763                 .head = {
764                         .action = RTE_PIPELINE_ACTION_PORT,
765                         {.port_id = p->port_out_id[req->port_id]},
766                 },
767
768                 .flow_id = 0,
769         };
770
771         rsp->status = rte_pipeline_table_default_entry_add(p->p,
772                 p->table_id[0],
773                 (struct rte_pipeline_table_entry *) &default_entry,
774                 (struct rte_pipeline_table_entry **) &rsp->entry_ptr);
775
776         return rsp;
777 }
778
779 static void *
780 pipeline_fc_msg_req_del_default_handler(struct pipeline *p, void *msg)
781 {
782         struct pipeline_fc_del_default_msg_rsp *rsp = msg;
783
784         rsp->status = rte_pipeline_table_default_entry_delete(p->p,
785                 p->table_id[0],
786                 NULL);
787
788         return rsp;
789 }
790
791 struct pipeline_be_ops pipeline_flow_classification_be_ops = {
792         .f_init = pipeline_fc_init,
793         .f_free = pipeline_fc_free,
794         .f_run = NULL,
795         .f_timer = pipeline_fc_timer,
796         .f_track = pipeline_fc_track,
797 };