lib: Add a counter for number of nexthops

Add a ability to count the number of nexthops in a nexthop_group.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2019-02-15 11:02:44 -05:00
parent 73587535ff
commit 454192f46f
2 changed files with 29 additions and 0 deletions

View File

@ -59,6 +59,30 @@ nexthop_group_cmd_compare(const struct nexthop_group_cmd *nhgc1,
return strcmp(nhgc1->name, nhgc2->name); return strcmp(nhgc1->name, nhgc2->name);
} }
uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg)
{
struct nexthop *nhop;
uint8_t num = 0;
for (ALL_NEXTHOPS_PTR(nhg, nhop))
num++;
return num;
}
uint8_t nexthop_group_active_nexthop_num(const struct nexthop_group *nhg)
{
struct nexthop *nhop;
uint8_t num = 0;
for (ALL_NEXTHOPS_PTR(nhg, nhop)) {
if (CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_ACTIVE))
num++;
}
return num;
}
struct nexthop *nexthop_exists(struct nexthop_group *nhg, struct nexthop *nh) struct nexthop *nexthop_exists(struct nexthop_group *nhg, struct nexthop *nh)
{ {
struct nexthop *nexthop; struct nexthop *nexthop;

View File

@ -117,6 +117,11 @@ extern struct nexthop_group_cmd *nhgc_find(const char *name);
extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh); extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh);
/* Return the number of nexthops in this nhg */
extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg);
extern uint8_t
nexthop_group_active_nexthop_num(const struct nexthop_group *nhg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif