examples/ip_pipeline: update routes when ports state change
authorJasvinder Singh <jasvinder.singh@intel.com>
Wed, 1 Jun 2016 14:01:01 +0000 (15:01 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 8 Jun 2016 19:40:38 +0000 (21:40 +0200)
The routing pipeline registers a callback function with the nic ports and
this function is invoked for updating the routing entries (corresponding to
local host and directly attached network) tables whenever the nic ports
change their states (up/down).

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
doc/guides/rel_notes/release_16_07.rst
examples/ip_pipeline/app.h
examples/ip_pipeline/pipeline/pipeline_common_fe.c
examples/ip_pipeline/pipeline/pipeline_common_fe.h
examples/ip_pipeline/pipeline/pipeline_routing.c
examples/ip_pipeline/pipeline/pipeline_routing_be.c
examples/ip_pipeline/pipeline/pipeline_routing_be.h

index 68efcd4..c0f6b02 100644 (file)
@@ -61,7 +61,8 @@ New Features
 
   The following features have been added to ip_pipeline application:
 
-  * Configure the MAC address in the routing pipeline.
+  * Configure the MAC address in the routing pipeline and automatic routes
+    updates with change in link state.
   * Enable RSS per network interface through the configuration file.
   * Streamline the CLI code.
 
index 93e96d0..848244a 100644 (file)
@@ -241,6 +241,22 @@ struct app_pipeline_params {
        uint32_t n_args;
 };
 
+struct app_params;
+
+typedef void (*app_link_op)(struct app_params *app,
+       uint32_t link_id,
+       uint32_t up,
+       void *arg);
+
+#ifndef APP_MAX_PIPELINES
+#define APP_MAX_PIPELINES                        64
+#endif
+
+struct app_link_data {
+       app_link_op f_link[APP_MAX_PIPELINES];
+       void *arg[APP_MAX_PIPELINES];
+};
+
 struct app_pipeline_data {
        void *be;
        void *fe;
@@ -416,10 +432,6 @@ struct app_eal_params {
 #define APP_MAX_MSGQ                             256
 #endif
 
-#ifndef APP_MAX_PIPELINES
-#define APP_MAX_PIPELINES                        64
-#endif
-
 #ifndef APP_EAL_ARGC
 #define APP_EAL_ARGC                             64
 #endif
@@ -480,6 +492,7 @@ struct app_params {
        struct cpu_core_map *core_map;
        uint64_t core_mask;
        struct rte_mempool *mempool[APP_MAX_MEMPOOLS];
+       struct app_link_data link_data[APP_MAX_LINKS];
        struct rte_ring *swq[APP_MAX_PKTQ_SWQ];
        struct rte_sched_port *tm[APP_MAX_PKTQ_TM];
        struct rte_ring *msgq[APP_MAX_MSGQ];
index fa0a482..70c57e4 100644 (file)
@@ -418,6 +418,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 +523,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 +537,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 +553,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 +566,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 +580,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 +590,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;
 }
 
index 8abee4a..ce0bf13 100644 (file)
@@ -224,6 +224,13 @@ app_pipeline_port_in_disable(struct app_params *app,
        uint32_t pipeline_id,
        uint32_t port_id);
 
+int
+app_link_set_op(struct app_params *app,
+       uint32_t link_id,
+       uint32_t pipeline_id,
+       app_link_op op,
+       void *arg);
+
 int
 app_link_config(struct app_params *app,
        uint32_t link_id,
index 80f029d..3aadbf9 100644 (file)
@@ -64,6 +64,9 @@ struct pipeline_routing {
        uint32_t n_ports_out;
        struct pipeline_routing_params rp;
 
+       /* Links */
+       uint32_t link_id[PIPELINE_MAX_PORT_OUT];
+
        /* Routes */
        TAILQ_HEAD(, app_pipeline_routing_route) routes;
        uint32_t n_routes;
@@ -81,6 +84,143 @@ struct pipeline_routing {
        void *default_arp_entry_ptr;
 };
 
+static int
+app_pipeline_routing_find_link(struct pipeline_routing *p,
+       uint32_t link_id,
+       uint32_t *port_id)
+{
+       uint32_t i;
+
+       for (i = 0; i < p->n_ports_out; i++)
+               if (p->link_id[i] == link_id) {
+                       *port_id = i;
+                       return 0;
+               }
+
+       return -1;
+}
+
+static void
+app_pipeline_routing_link_op(__rte_unused struct app_params *app,
+       uint32_t link_id,
+       uint32_t up,
+       void *arg)
+{
+       struct pipeline_routing_route_key key0, key1;
+       struct pipeline_routing *p = arg;
+       struct app_link_params *lp;
+       uint32_t port_id, netmask;
+       int status;
+
+       if (app == NULL)
+               return;
+
+       APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp);
+       if (lp == NULL)
+               return;
+
+       status = app_pipeline_routing_find_link(p,
+               link_id,
+               &port_id);
+       if (status)
+               return;
+
+       netmask = (~0U) << (32 - lp->depth);
+
+       /* Local network (directly attached network) */
+       key0.type = PIPELINE_ROUTING_ROUTE_IPV4;
+       key0.key.ipv4.ip = lp->ip & netmask;
+       key0.key.ipv4.depth = lp->depth;
+
+       /* Local termination */
+       key1.type = PIPELINE_ROUTING_ROUTE_IPV4;
+       key1.key.ipv4.ip = lp->ip;
+       key1.key.ipv4.depth = 32;
+
+       if (up) {
+               struct pipeline_routing_route_data data0, data1;
+
+               /* Local network (directly attached network) */
+               memset(&data0, 0, sizeof(data0));
+               data0.flags = PIPELINE_ROUTING_ROUTE_LOCAL |
+                       PIPELINE_ROUTING_ROUTE_ARP;
+               if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ)
+                       data0.flags |= PIPELINE_ROUTING_ROUTE_QINQ;
+               if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS) {
+                       data0.flags |= PIPELINE_ROUTING_ROUTE_MPLS;
+                       data0.l2.mpls.n_labels = 1;
+               }
+               data0.port_id = port_id;
+
+               if (p->rp.n_arp_entries)
+                       app_pipeline_routing_add_route(app,
+                               p->pipeline_id,
+                               &key0,
+                               &data0);
+
+               /* Local termination */
+               memset(&data1, 0, sizeof(data1));
+               data1.flags = PIPELINE_ROUTING_ROUTE_LOCAL |
+                       PIPELINE_ROUTING_ROUTE_ARP;
+               if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ)
+                       data1.flags |= PIPELINE_ROUTING_ROUTE_QINQ;
+               if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS) {
+                       data1.flags |= PIPELINE_ROUTING_ROUTE_MPLS;
+                       data1.l2.mpls.n_labels = 1;
+               }
+               data1.port_id = p->rp.port_local_dest;
+
+               app_pipeline_routing_add_route(app,
+                       p->pipeline_id,
+                       &key1,
+                       &data1);
+       } else {
+               /* Local network (directly attached network) */
+               if (p->rp.n_arp_entries)
+                       app_pipeline_routing_delete_route(app,
+                               p->pipeline_id,
+                               &key0);
+
+               /* Local termination */
+               app_pipeline_routing_delete_route(app,
+                       p->pipeline_id,
+                       &key1);
+       }
+}
+
+static int
+app_pipeline_routing_set_link_op(
+       struct app_params *app,
+       struct pipeline_routing *p)
+{
+       uint32_t port_id;
+
+       for (port_id = 0; port_id < p->n_ports_out; port_id++) {
+               struct app_link_params *link;
+               uint32_t link_id;
+               int status;
+
+               link = app_pipeline_track_pktq_out_to_link(app,
+                       p->pipeline_id,
+                       port_id);
+               if (link == NULL)
+                       continue;
+
+               link_id = link - app->link_params;
+               p->link_id[port_id] = link_id;
+
+               status = app_link_set_op(app,
+                       link_id,
+                       p->pipeline_id,
+                       app_pipeline_routing_link_op,
+                       (void *) p);
+               if (status)
+                       return status;
+       }
+
+       return 0;
+}
+
 static void *
 app_pipeline_routing_init(struct pipeline_params *params,
        void *arg)
@@ -121,6 +261,8 @@ app_pipeline_routing_init(struct pipeline_params *params,
        TAILQ_INIT(&p->arp_entries);
        p->n_arp_entries = 0;
 
+       app_pipeline_routing_set_link_op(app, p);
+
        return p;
 }
 
@@ -223,7 +365,9 @@ print_route(const struct app_pipeline_routing_route *route)
                        key->depth,
                        route->data.port_id);
 
-               if (route->data.flags & PIPELINE_ROUTING_ROUTE_ARP)
+               if (route->data.flags & PIPELINE_ROUTING_ROUTE_LOCAL)
+                       printf(", Local");
+               else if (route->data.flags & PIPELINE_ROUTING_ROUTE_ARP)
                        printf(
                                ", Next Hop IP = %" PRIu32 ".%" PRIu32
                                ".%" PRIu32 ".%" PRIu32,
index a448157..21ac788 100644 (file)
@@ -930,6 +930,7 @@ pipeline_routing_parse_args(struct pipeline_routing_params *p,
        struct pipeline_params *params)
 {
        uint32_t n_routes_present = 0;
+       uint32_t port_local_dest_present = 0;
        uint32_t encap_present = 0;
        uint32_t qinq_sched_present = 0;
        uint32_t mpls_color_mark_present = 0;
@@ -942,6 +943,7 @@ pipeline_routing_parse_args(struct pipeline_routing_params *p,
 
        /* default values */
        p->n_routes = PIPELINE_ROUTING_N_ROUTES_DEFAULT;
+       p->port_local_dest = params->n_ports_out - 1;
        p->encap = PIPELINE_ROUTING_ENCAP_ETHERNET;
        p->qinq_sched = 0;
        p->mpls_color_mark = 0;
@@ -971,6 +973,23 @@ pipeline_routing_parse_args(struct pipeline_routing_params *p,
 
                        continue;
                }
+               /* port_local_dest */
+               if (strcmp(arg_name, "port_local_dest") == 0) {
+                       int status;
+
+                       PIPELINE_PARSE_ERR_DUPLICATE(
+                               port_local_dest_present == 0, params->name,
+                               arg_name);
+                       port_local_dest_present = 1;
+
+                       status = parser_read_uint32(&p->port_local_dest,
+                               arg_value);
+                       PIPELINE_PARSE_ERR_INV_VAL(((status == 0) &&
+                               (p->port_local_dest < params->n_ports_out)),
+                               params->name, arg_name, arg_value);
+
+                       continue;
+               }
 
                /* encap */
                if (strcmp(arg_name, "encap") == 0) {
index 822995b..1276342 100644 (file)
@@ -54,6 +54,7 @@ enum pipeline_routing_encap {
 struct pipeline_routing_params {
        /* routing */
        uint32_t n_routes;
+       uint32_t port_local_dest;
 
        /* routing packet encapsulation */
        enum pipeline_routing_encap encap;