From: rgirada Date: Thu, 20 Dec 2018 15:56:21 +0000 (-0800) Subject: lib: Implemented a cli "show route-map-unsed" to track all unsed routemaps. X-Git-Tag: 7.1_pulled~273^2~6 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=4a2a09d03dd32848c95b1d2ad32ac8f70d15f1f0;p=matthieu%2Ffrr.git lib: Implemented a cli "show route-map-unsed" to track all unsed routemaps. Made the following changes. 1.Defined two apis in routemap-lib, one for increment and another for decrement the applied counter. 2.Added a new configuration “show route-map-unused” to track all unused routemaps. 3.called the corresponding route map update api when a route map attached or detached from any redistribution list. Signed-off-by: RajeshGirada --- diff --git a/lib/routemap.c b/lib/routemap.c index 5c6d106d83..61e597520e 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -1007,6 +1007,34 @@ static int vty_show_route_map(struct vty *vty, const char *name) return CMD_SUCCESS; } +/* Unused route map details */ +static int vty_show_unused_route_map(struct vty *vty) +{ + struct list *maplist = list_new(); + struct listnode *ln; + struct route_map *map; + + for (map = route_map_master.head; map; map = map->next) { + /* If use_count is zero, No protocol is using this routemap. + * so adding to the list. + */ + if (!map->use_count) + listnode_add(maplist, map); + } + + if (maplist->count > 0) { + vty_out(vty, "\n%s:\n", frr_protonameinst); + list_sort(maplist, sort_route_map); + + for (ALL_LIST_ELEMENTS_RO(maplist, ln, map)) + vty_show_route_map_entry(vty, map); + } else { + vty_out(vty, "\n%s: None\n", frr_protonameinst); + } + + list_delete(&maplist); + return CMD_SUCCESS; +} /* New route map allocation. Please note route map's name must be specified. */ @@ -2759,6 +2787,15 @@ DEFUN (rmap_show_name, return vty_show_route_map(vty, name); } +DEFUN (rmap_show_unused, + rmap_show_unused_cmd, + "show route-map-unused", + SHOW_STR + "unused route-map information\n") +{ + return vty_show_unused_route_map(vty); +} + DEFUN (rmap_call, rmap_call_cmd, "call WORD", @@ -2949,6 +2986,23 @@ static void rmap_autocomplete(vector comps, struct cmd_token *token) vector_set(comps, XSTRDUP(MTYPE_COMPLETION, map->name)); } +/* Increment the use_count counter while attaching the route map */ +void route_map_counter_increment(struct route_map *map) +{ + if (map) + map->use_count++; +} + +/* Decrement the use_count counter while detaching the route map. */ +void route_map_counter_decrement(struct route_map *map) +{ + if (map) { + if (map->use_count <= 0) + return; + map->use_count--; + } +} + static const struct cmd_variable_handler rmap_var_handlers[] = { {/* "route-map WORD" */ .varname = "route_map", @@ -3006,6 +3060,7 @@ void route_map_init(void) /* Install show command */ install_element(ENABLE_NODE, &rmap_show_name_cmd); + install_element(ENABLE_NODE, &rmap_show_unused_cmd); install_element(RMAP_NODE, &match_interface_cmd); install_element(RMAP_NODE, &no_match_interface_cmd); diff --git a/lib/routemap.h b/lib/routemap.h index 463aa91725..6fd88ba5de 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -169,6 +169,9 @@ struct route_map { /* How many times have we applied this route-map */ uint64_t applied; + /* Counter to track active usage of this route-map */ + uint16_t use_count; + QOBJ_FIELDS }; DECLARE_QOBJ_TYPE(route_map) @@ -379,4 +382,10 @@ extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty, extern void *route_map_rule_tag_compile(const char *arg); extern void route_map_rule_tag_free(void *rule); +/* Increment the route-map used counter */ +extern void route_map_counter_increment(struct route_map *map); + +/* Decrement the route-map used counter */ +extern void route_map_counter_decrement(struct route_map *map); + #endif /* _ZEBRA_ROUTEMAP_H */