diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2019-01-02 20:38:15 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2019-01-02 21:40:10 +0100 |
commit | 6b98d34fdfeeafeb51887044f02f2496d2807bfd (patch) | |
tree | c10bdec4cb802e046bfdfeab6be26baaa36b107b /sharpd | |
parent | Merge pull request #3553 from opensourcerouting/fix-interface-vrf-update-msg (diff) | |
download | frr-6b98d34fdfeeafeb51887044f02f2496d2807bfd.tar.xz frr-6b98d34fdfeeafeb51887044f02f2496d2807bfd.zip |
sharpd: Abstract the route install/delete functions a bit
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>
Diffstat (limited to 'sharpd')
-rw-r--r-- | sharpd/sharp_vty.c | 21 | ||||
-rw-r--r-- | sharpd/sharp_zebra.c | 55 | ||||
-rw-r--r-- | sharpd/sharp_zebra.h | 6 |
3 files changed, 63 insertions, 19 deletions
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 3aed8eb12..abc2c720c 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -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; } diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 4a88b6c8e..72e1eb2b2 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -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"); diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index ffe21df9b..7326056ca 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -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 |