diff options
Diffstat (limited to 'sharpd/sharp_zebra.c')
| -rw-r--r-- | sharpd/sharp_zebra.c | 94 |
1 files changed, 90 insertions, 4 deletions
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 4a88b6c8ee..c9f333e34b 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -129,13 +129,89 @@ static int interface_state_down(int command, struct zclient *zclient, return 0; } +static struct timeval t_start; +static struct timeval t_end; extern uint32_t total_routes; extern uint32_t installed_routes; extern uint32_t removed_routes; +extern int32_t repeat; +extern struct prefix orig_prefix; +extern struct nexthop_group nhop_group; +extern uint8_t inst; + +void sharp_install_routes_helper(struct prefix *p, uint8_t instance, + struct nexthop_group *nhg, + uint32_t routes) +{ + uint32_t temp, i; + bool v4 = false; + + zlog_debug("Inserting %u routes", routes); + + if (p->family == AF_INET) { + v4 = true; + temp = ntohl(p->u.prefix4.s_addr); + } else + temp = ntohl(p->u.val32[3]); + + monotime(&t_start); + for (i = 0; i < routes; i++) { + route_add(p, (uint8_t)instance, nhg); + if (v4) + p->u.prefix4.s_addr = htonl(++temp); + else + p->u.val32[3] = htonl(++temp); + } +} + +void sharp_remove_routes_helper(struct prefix *p, uint8_t instance, + uint32_t routes) +{ + uint32_t temp, i; + bool v4 = false; + + zlog_debug("Removing %u routes", routes); + + if (p->family == AF_INET) { + v4 = true; + temp = ntohl(p->u.prefix4.s_addr); + } else + temp = ntohl(p->u.val32[3]); + + monotime(&t_start); + for (i = 0; i < routes; i++) { + route_delete(p, (uint8_t)instance); + if (v4) + p->u.prefix4.s_addr = htonl(++temp); + else + p->u.val32[3] = htonl(++temp); + } +} + +static void handle_repeated(bool installed) +{ + struct prefix p = orig_prefix; + repeat--; + + if (repeat <= 0) + return; + + if (installed) { + removed_routes = 0; + sharp_remove_routes_helper(&p, inst, total_routes); + } + + if (!installed) { + installed_routes = 0; + sharp_install_routes_helper(&p, inst, &nhop_group, + total_routes); + } +} static int route_notify_owner(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { + struct timeval r; struct prefix p; enum zapi_route_notify_owner note; uint32_t table; @@ -146,8 +222,13 @@ static int route_notify_owner(int command, struct zclient *zclient, switch (note) { case ZAPI_ROUTE_INSTALLED: installed_routes++; - if (total_routes == installed_routes) - zlog_debug("Installed All Items"); + if (total_routes == installed_routes) { + monotime(&t_end); + timersub(&t_end, &t_start, &r); + zlog_debug("Installed All Items %ld.%ld", r.tv_sec, + r.tv_usec); + handle_repeated(true); + } break; case ZAPI_ROUTE_FAIL_INSTALL: zlog_debug("Failed install of route"); @@ -157,8 +238,13 @@ static int route_notify_owner(int command, struct zclient *zclient, break; case ZAPI_ROUTE_REMOVED: removed_routes++; - if (total_routes == removed_routes) - zlog_debug("Removed all Items"); + if (total_routes == removed_routes) { + monotime(&t_end); + timersub(&t_end, &t_start, &r); + zlog_debug("Removed all Items %ld.%ld", r.tv_sec, + r.tv_usec); + handle_repeated(false); + } break; case ZAPI_ROUTE_REMOVE_FAIL: zlog_debug("Route removal Failure"); |
