examples/ip_pipeline: support KNI
[dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_fe.c
index fa0a482..cd1d082 100644 (file)
@@ -130,6 +130,33 @@ app_pipeline_track_pktq_out_to_link(struct app_params *app,
                        break;
                }
 
+               case APP_PKTQ_OUT_KNI:
+               {
+                       struct pipeline_params pp;
+                       struct pipeline_type *ptype;
+                       struct app_pktq_kni_params *kni;
+                       uint32_t pktq_in_id;
+                       int status;
+
+                       kni = &app->kni_params[pktq_out->id];
+                       p = app_kni_get_reader(app, kni, &pktq_in_id);
+                       if (p == NULL)
+                               return NULL;
+
+                       ptype = app_pipeline_type_find(app, p->type);
+                       if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL))
+                               return NULL;
+
+                       app_pipeline_params_get(app, p, &pp);
+                       status = ptype->fe_ops->f_track(&pp,
+                               pktq_in_id,
+                               &pktq_out_id);
+                       if (status)
+                               return NULL;
+
+                       break;
+               }
+
                case APP_PKTQ_OUT_SINK:
                default:
                        return NULL;
@@ -418,6 +445,40 @@ app_pipeline_port_in_disable(struct app_params *app,
        return status;
 }
 
+int
+app_link_set_op(struct app_params *app,
+       uint32_t link_id,
+       uint32_t pipeline_id,
+       app_link_op op,
+       void *arg)
+{
+       struct app_pipeline_params *pp;
+       struct app_link_params *lp;
+       struct app_link_data *ld;
+       uint32_t ppos, lpos;
+
+       /* Check input arguments */
+       if ((app == NULL) ||
+               (op == NULL))
+               return -1;
+
+       APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp);
+       if (lp == NULL)
+               return -1;
+       lpos = lp - app->link_params;
+       ld = &app->link_data[lpos];
+
+       APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, pp);
+       if (pp == NULL)
+               return -1;
+       ppos = pp - app->pipeline_params;
+
+       ld->f_link[ppos] = op;
+       ld->arg[ppos] = arg;
+
+       return 0;
+}
+
 int
 app_link_config(struct app_params *app,
        uint32_t link_id,
@@ -489,6 +550,8 @@ app_link_up(struct app_params *app,
        uint32_t link_id)
 {
        struct app_link_params *p;
+       struct app_link_data *d;
+       int i;
 
        /* Check input arguments */
        if (app == NULL)
@@ -501,6 +564,8 @@ app_link_up(struct app_params *app,
                return -1;
        }
 
+       d = &app->link_data[p - app->link_params];
+
        /* Check link state */
        if (p->state) {
                APP_LOG(app, HIGH, "%s is already UP", p->name);
@@ -515,6 +580,11 @@ app_link_up(struct app_params *app,
 
        app_link_up_internal(app, p);
 
+       /* Callbacks */
+       for (i = 0; i < APP_MAX_PIPELINES; i++)
+               if (d->f_link[i])
+                       d->f_link[i](app, link_id, 1, d->arg[i]);
+
        return 0;
 }
 
@@ -523,6 +593,8 @@ app_link_down(struct app_params *app,
        uint32_t link_id)
 {
        struct app_link_params *p;
+       struct app_link_data *d;
+       uint32_t i;
 
        /* Check input arguments */
        if (app == NULL)
@@ -535,6 +607,8 @@ app_link_down(struct app_params *app,
                return -1;
        }
 
+       d = &app->link_data[p - app->link_params];
+
        /* Check link state */
        if (p->state == 0) {
                APP_LOG(app, HIGH, "%s is already DOWN", p->name);
@@ -543,6 +617,11 @@ app_link_down(struct app_params *app,
 
        app_link_down_internal(app, p);
 
+       /* Callbacks */
+       for (i = 0; i < APP_MAX_PIPELINES; i++)
+               if (d->f_link[i])
+                       d->f_link[i](app, link_id, 0, d->arg[i]);
+
        return 0;
 }