]> git.puffer.fish Git - matthieu/frr.git/commitdiff
sharpd: Abstract the route install/delete functions a bit
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 2 Jan 2019 19:38:15 +0000 (14:38 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 2 Jan 2019 20:40:10 +0000 (15:40 -0500)
Abstract the route install/delete functions a bit to allow me to
expand on them in the with future commits.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
sharpd/sharp_vty.c
sharpd/sharp_zebra.c
sharpd/sharp_zebra.h

index 3aed8eb1231623cc40eafc22f44f0dc5ef5eb99e..abc2c720ce77ec04c0991f0e87fd0b937e214b05 100644 (file)
@@ -80,6 +80,8 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
        return CMD_SUCCESS;
 }
 
+
+
 DEFPY (install_routes,
        install_routes_cmd,
        "sharp install routes A.B.C.D$start <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance]",
@@ -96,11 +98,9 @@ DEFPY (install_routes,
        "Instance to use\n"
        "Instance\n")
 {
-       int i;
        struct prefix p;
        struct nexthop nhop;
        struct nexthop_group nhg;
-       uint32_t temp;
 
        total_routes = routes;
        installed_routes = 0;
@@ -134,13 +134,8 @@ DEFPY (install_routes,
 
                nhg.nexthop = &nhop;
        }
-       zlog_debug("Inserting %ld routes", routes);
 
-       temp = ntohl(p.u.prefix4.s_addr);
-       for (i = 0; i < routes; i++) {
-               route_add(&p, (uint8_t)instance, &nhg);
-               p.u.prefix4.s_addr = htonl(++temp);
-       }
+       sharp_install_routes_helper(&p, instance, &nhg, routes);
 
        return CMD_SUCCESS;
 }
@@ -186,9 +181,7 @@ DEFPY (remove_routes,
        "instance to use\n"
        "Value of instance\n")
 {
-       int i;
        struct prefix p;
-       uint32_t temp;
        total_routes = routes;
        removed_routes = 0;
 
@@ -198,13 +191,7 @@ DEFPY (remove_routes,
        p.prefixlen = 32;
        p.u.prefix4 = start;
 
-       zlog_debug("Removing %ld routes", routes);
-
-       temp = ntohl(p.u.prefix4.s_addr);
-       for (i = 0; i < routes; i++) {
-               route_delete(&p, (uint8_t)instance);
-               p.u.prefix4.s_addr = htonl(++temp);
-       }
+       sharp_remove_routes_helper(&p, instance, routes);
 
        return CMD_SUCCESS;
 }
index 4a88b6c8ee13e984f03c90ca2b1fe15210153d59..72e1eb2b2197f6dd61d1140493670d80611fbc2d 100644 (file)
@@ -133,6 +133,53 @@ extern uint32_t total_routes;
 extern uint32_t installed_routes;
 extern uint32_t removed_routes;
 
+void sharp_install_routes_helper(struct prefix *p, uint8_t instance,
+                                struct nexthop_group *nhg,
+                                uint32_t routes)
+{
+       uint32_t temp, i;
+
+       zlog_debug("Inserting %u routes", routes);
+
+       temp = ntohl(p->u.prefix4.s_addr);
+       for (i = 0; i < routes; i++) {
+               route_add(p, (uint8_t)instance, nhg);
+               p->u.prefix4.s_addr = htonl(++temp);
+       }
+}
+
+void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
+                               uint32_t routes)
+{
+       uint32_t temp, i;
+
+       zlog_debug("Removing %u routes", routes);
+
+       temp = ntohl(p->u.prefix4.s_addr);
+       for (i = 0; i < routes; i++) {
+               route_delete(p, (uint8_t)instance);
+               p->u.prefix4.s_addr = htonl(++temp);
+       }
+}
+
+static int handle_repeated(bool installed)
+{
+       repeat--;
+
+       if (repeat <= 0)
+               return;
+
+       if (installed) {
+               removed_routes = 0;
+               sharp_remove_routes_helper(&prefix, inst, total_routes);
+       }
+
+       if (!installed) {
+               installed_routes = 0;
+               sharp_remove_routes
+       }
+}
+
 static int route_notify_owner(int command, struct zclient *zclient,
                              zebra_size_t length, vrf_id_t vrf_id)
 {
@@ -146,8 +193,10 @@ static int route_notify_owner(int command, struct zclient *zclient,
        switch (note) {
        case ZAPI_ROUTE_INSTALLED:
                installed_routes++;
-               if (total_routes == installed_routes)
+               if (total_routes == installed_routes) {
                        zlog_debug("Installed All Items");
+                       handle_repeated(true);
+               }
                break;
        case ZAPI_ROUTE_FAIL_INSTALL:
                zlog_debug("Failed install of route");
@@ -157,8 +206,10 @@ static int route_notify_owner(int command, struct zclient *zclient,
                break;
        case ZAPI_ROUTE_REMOVED:
                removed_routes++;
-               if (total_routes == removed_routes)
+               if (total_routes == removed_routes) {
                        zlog_debug("Removed all Items");
+                       handle_repeated(false);
+               }
                break;
        case ZAPI_ROUTE_REMOVE_FAIL:
                zlog_debug("Route removal Failure");
index ffe21df9b807af57ee0c19e426619b1f040c06e7..7326056cae773e044dd9a6eed23ab97295a4ebf4 100644 (file)
@@ -29,4 +29,10 @@ extern void route_add(struct prefix *p, uint8_t instance,
                      struct nexthop_group *nhg);
 extern void route_delete(struct prefix *p, uint8_t instance);
 extern void sharp_zebra_nexthop_watch(struct prefix *p, bool watch);
+
+extern void sharp_install_routes_helper(struct prefix *p, uint8_t instance,
+                                        struct nexthop_group *nhg,
+                                        uint32_t routes);
+extern void sharp_remove_routes_helper(struct prefix *p, uint8_t instance,
+                                      uint32_t routes);
 #endif