examples/ip_pipeline: check pipeline type
authorMaciej Gajdzica <maciejx.t.gajdzica@intel.com>
Thu, 17 Sep 2015 12:58:33 +0000 (14:58 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 7 Dec 2015 01:35:56 +0000 (02:35 +0100)
This commit add to CLI command check for pipeline type. It prevents
running CLI commands on not supported pipeline types.

Signed-off-by: Maciej Gajdzica <maciejx.t.gajdzica@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
examples/ip_pipeline/app.h
examples/ip_pipeline/init.c
examples/ip_pipeline/pipeline/pipeline_common_fe.h
examples/ip_pipeline/pipeline/pipeline_firewall.c
examples/ip_pipeline/pipeline/pipeline_flow_classification.c
examples/ip_pipeline/pipeline/pipeline_routing.c

index d8a1717..6510d6d 100644 (file)
@@ -227,6 +227,7 @@ struct app_pipeline_params {
 struct app_pipeline_data {
        void *be;
        void *fe;
+       struct pipeline_type *ptype;
        uint64_t timer_period;
        uint32_t enabled;
 };
index 838a383..23fd561 100644 (file)
@@ -1340,6 +1340,8 @@ app_init_pipelines(struct app_params *app)
                                "init error\n", params->name);
                }
 
+               data->ptype = ptype;
+
                data->timer_period = (rte_get_tsc_hz() * params->timer_period)
                        / 1000;
        }
index e84aa3a..cfad963 100644 (file)
@@ -60,7 +60,7 @@ app_pipeline_data(struct app_params *app, uint32_t id)
 }
 
 static inline void *
-app_pipeline_data_fe(struct app_params *app, uint32_t id)
+app_pipeline_data_fe(struct app_params *app, uint32_t id, struct pipeline_type *ptype)
 {
        struct app_pipeline_data *pipeline_data;
 
@@ -68,6 +68,9 @@ app_pipeline_data_fe(struct app_params *app, uint32_t id)
        if (pipeline_data == NULL)
                return NULL;
 
+       if (strcmp(pipeline_data->ptype->name, ptype->name) != 0)
+               return NULL;
+
        if (pipeline_data->enabled == 0)
                return NULL;
 
index 4137923..3d7ea7a 100644 (file)
@@ -141,7 +141,7 @@ app_pipeline_firewall_rule_find(struct app_pipeline_firewall *p,
        return NULL;
 }
 
-static void
+static int
 app_pipeline_firewall_ls(
        struct app_params *app,
        uint32_t pipeline_id)
@@ -153,11 +153,11 @@ app_pipeline_firewall_ls(
 
        /* Check input arguments */
        if (app == NULL)
-               return;
+               return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
-               return;
+               return -1;
 
        n_rules = p->n_rules;
        for (priority = 0; n_rules; priority++)
@@ -175,6 +175,8 @@ app_pipeline_firewall_ls(
                printf("Default rule: DROP\n");
 
        printf("\n");
+
+       return 0;
 }
 
 static void*
@@ -641,7 +643,7 @@ app_pipeline_firewall_add_rule(struct app_params *app,
                (key->type != PIPELINE_FIREWALL_IPV4_5TUPLE))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
                return -1;
 
@@ -729,7 +731,7 @@ app_pipeline_firewall_delete_rule(struct app_params *app,
                (key->type != PIPELINE_FIREWALL_IPV4_5TUPLE))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
                return -1;
 
@@ -797,7 +799,7 @@ app_pipeline_firewall_add_bulk(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
                return -1;
 
@@ -1023,7 +1025,7 @@ app_pipeline_firewall_delete_bulk(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
                return -1;
 
@@ -1111,7 +1113,7 @@ app_pipeline_firewall_add_default_rule(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
                return -1;
 
@@ -1162,7 +1164,7 @@ app_pipeline_firewall_delete_default_rule(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_firewall);
        if (p == NULL)
                return -1;
 
@@ -1804,8 +1806,14 @@ cmd_firewall_ls_parsed(
 {
        struct cmd_firewall_ls_result *params = parsed_result;
        struct app_params *app = data;
+       int status;
 
-       app_pipeline_firewall_ls(app, params->pipeline_id);
+       status = app_pipeline_firewall_ls(app, params->pipeline_id);
+
+       if (status != 0) {
+               printf("Command failed\n");
+               return;
+       }
 }
 
 cmdline_parse_token_string_t cmd_firewall_ls_p_string =
index 04b6915..76a152f 100644 (file)
@@ -298,7 +298,7 @@ app_pipeline_fc_add(struct app_params *app,
                (key == NULL))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_flow_classification);
        if (p == NULL)
                return -1;
 
@@ -398,7 +398,7 @@ app_pipeline_fc_add_bulk(struct app_params *app,
                (n_keys == 0))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_flow_classification);
        if (p == NULL)
                return -1;
 
@@ -588,7 +588,7 @@ app_pipeline_fc_del(struct app_params *app,
                (key == NULL))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_flow_classification);
        if (p == NULL)
                return -1;
 
@@ -646,7 +646,7 @@ app_pipeline_fc_add_default(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_flow_classification);
        if (p == NULL)
                return -1;
 
@@ -698,7 +698,7 @@ app_pipeline_fc_del_default(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_flow_classification);
        if (p == NULL)
                return -EINVAL;
 
@@ -879,7 +879,7 @@ app_pipeline_fc_ls(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_flow_classification);
        if (p == NULL)
                return -1;
 
index 4f6ff81..6354730 100644 (file)
@@ -267,7 +267,7 @@ app_pipeline_routing_route_ls(struct app_params *app, uint32_t pipeline_id)
        struct pipeline_routing *p;
        struct app_pipeline_routing_route *it;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -EINVAL;
 
@@ -305,7 +305,7 @@ app_pipeline_routing_add_route(struct app_params *app,
                (data == NULL))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -1;
 
@@ -407,7 +407,7 @@ app_pipeline_routing_delete_route(struct app_params *app,
                (key == NULL))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -1;
 
@@ -479,7 +479,7 @@ app_pipeline_routing_add_default_route(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -1;
 
@@ -531,7 +531,7 @@ app_pipeline_routing_delete_default_route(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -1;
 
@@ -569,7 +569,7 @@ app_pipeline_routing_arp_ls(struct app_params *app, uint32_t pipeline_id)
        struct pipeline_routing *p;
        struct app_pipeline_routing_arp_entry *it;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -EINVAL;
 
@@ -606,7 +606,7 @@ app_pipeline_routing_add_arp_entry(struct app_params *app, uint32_t pipeline_id,
                (macaddr == NULL))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -1;
 
@@ -701,7 +701,7 @@ app_pipeline_routing_delete_arp_entry(struct app_params *app,
                (key == NULL))
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -EINVAL;
 
@@ -769,7 +769,7 @@ app_pipeline_routing_add_default_arp_entry(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -1;
 
@@ -821,7 +821,7 @@ app_pipeline_routing_delete_default_arp_entry(struct app_params *app,
        if (app == NULL)
                return -1;
 
-       p = app_pipeline_data_fe(app, pipeline_id);
+       p = app_pipeline_data_fe(app, pipeline_id, &pipeline_routing);
        if (p == NULL)
                return -EINVAL;
 
@@ -2172,7 +2172,7 @@ cmd_arp_ls_parsed(
        struct app_params *app = data;
        struct pipeline_routing *p;
 
-       p = app_pipeline_data_fe(app, params->p);
+       p = app_pipeline_data_fe(app, params->p, &pipeline_routing);
        if (p == NULL)
                return;