mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-16 15:27:59 +00:00
Merge pull request #4052 from opensourcerouting/bgpd-show-stats-vpn
bgpd: fix "show bgp statistics" for the VPN safi
This commit is contained in:
commit
7811f2f6ae
152
bgpd/bgp_route.c
152
bgpd/bgp_route.c
@ -10225,40 +10225,20 @@ ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int bgp_table_stats_walker(struct thread *t)
|
static void bgp_table_stats_rn(struct bgp_node *rn, struct bgp_node *top,
|
||||||
|
struct bgp_table_stats *ts, unsigned int space)
|
||||||
{
|
{
|
||||||
struct bgp_node *rn;
|
struct bgp_node *prn = bgp_node_parent_nolock(rn);
|
||||||
struct bgp_node *top;
|
struct bgp_path_info *pi;
|
||||||
struct bgp_table_stats *ts = THREAD_ARG(t);
|
|
||||||
unsigned int space = 0;
|
|
||||||
|
|
||||||
if (!(top = bgp_table_top(ts->table)))
|
if (rn == top)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
switch (top->p.family) {
|
if (!bgp_node_has_bgp_path_info_data(rn))
|
||||||
case AF_INET:
|
return;
|
||||||
space = IPV4_MAX_BITLEN;
|
|
||||||
break;
|
|
||||||
case AF_INET6:
|
|
||||||
space = IPV6_MAX_BITLEN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ts->counts[BGP_STATS_MAXBITLEN] = space;
|
ts->counts[BGP_STATS_PREFIXES]++;
|
||||||
|
ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
|
||||||
for (rn = top; rn; rn = bgp_route_next(rn)) {
|
|
||||||
struct bgp_path_info *pi;
|
|
||||||
struct bgp_node *prn = bgp_node_parent_nolock(rn);
|
|
||||||
unsigned int pinum = 0;
|
|
||||||
|
|
||||||
if (rn == top)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!bgp_node_has_bgp_path_info_data(rn))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ts->counts[BGP_STATS_PREFIXES]++;
|
|
||||||
ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
ts->counts[BGP_STATS_AVGPLEN]
|
ts->counts[BGP_STATS_AVGPLEN]
|
||||||
@ -10267,49 +10247,43 @@ static int bgp_table_stats_walker(struct thread *t)
|
|||||||
rn->p.prefixlen);
|
rn->p.prefixlen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check if the prefix is included by any other announcements */
|
/* check if the prefix is included by any other announcements */
|
||||||
while (prn && !bgp_node_has_bgp_path_info_data(prn))
|
while (prn && !bgp_node_has_bgp_path_info_data(prn))
|
||||||
prn = bgp_node_parent_nolock(prn);
|
prn = bgp_node_parent_nolock(prn);
|
||||||
|
|
||||||
if (prn == NULL || prn == top) {
|
if (prn == NULL || prn == top) {
|
||||||
ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
|
ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
|
||||||
/* announced address space */
|
/* announced address space */
|
||||||
if (space)
|
if (space)
|
||||||
ts->total_space +=
|
ts->total_space += pow(2.0, space - rn->p.prefixlen);
|
||||||
pow(2.0, space - rn->p.prefixlen);
|
} else if (bgp_node_has_bgp_path_info_data(prn))
|
||||||
} else if (bgp_node_has_bgp_path_info_data(prn))
|
ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
|
||||||
ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
|
|
||||||
|
|
||||||
for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) {
|
|
||||||
pinum++;
|
|
||||||
ts->counts[BGP_STATS_RIB]++;
|
|
||||||
|
|
||||||
if (pi->attr
|
for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) {
|
||||||
&& (CHECK_FLAG(pi->attr->flag,
|
ts->counts[BGP_STATS_RIB]++;
|
||||||
ATTR_FLAG_BIT(
|
|
||||||
BGP_ATTR_ATOMIC_AGGREGATE))))
|
|
||||||
ts->counts[BGP_STATS_AGGREGATES]++;
|
|
||||||
|
|
||||||
/* as-path stats */
|
if (pi->attr
|
||||||
if (pi->attr && pi->attr->aspath) {
|
&& (CHECK_FLAG(pi->attr->flag,
|
||||||
unsigned int hops =
|
ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))))
|
||||||
aspath_count_hops(pi->attr->aspath);
|
ts->counts[BGP_STATS_AGGREGATES]++;
|
||||||
unsigned int size =
|
|
||||||
aspath_size(pi->attr->aspath);
|
|
||||||
as_t highest = aspath_highest(pi->attr->aspath);
|
|
||||||
|
|
||||||
ts->counts[BGP_STATS_ASPATH_COUNT]++;
|
/* as-path stats */
|
||||||
|
if (pi->attr && pi->attr->aspath) {
|
||||||
|
unsigned int hops = aspath_count_hops(pi->attr->aspath);
|
||||||
|
unsigned int size = aspath_size(pi->attr->aspath);
|
||||||
|
as_t highest = aspath_highest(pi->attr->aspath);
|
||||||
|
|
||||||
if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
|
ts->counts[BGP_STATS_ASPATH_COUNT]++;
|
||||||
ts->counts[BGP_STATS_ASPATH_MAXHOPS] =
|
|
||||||
hops;
|
|
||||||
|
|
||||||
if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
|
if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
|
||||||
ts->counts[BGP_STATS_ASPATH_MAXSIZE] =
|
ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
|
||||||
size;
|
|
||||||
|
|
||||||
ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
|
if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
|
||||||
ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
|
ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
|
||||||
|
|
||||||
|
ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
|
||||||
|
ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
|
||||||
#if 0
|
#if 0
|
||||||
ts->counts[BGP_STATS_ASPATH_AVGHOPS]
|
ts->counts[BGP_STATS_ASPATH_AVGHOPS]
|
||||||
= ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
|
= ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
|
||||||
@ -10320,12 +10294,52 @@ static int bgp_table_stats_walker(struct thread *t)
|
|||||||
ts->counts[BGP_STATS_ASPATH_AVGSIZE],
|
ts->counts[BGP_STATS_ASPATH_AVGSIZE],
|
||||||
size);
|
size);
|
||||||
#endif
|
#endif
|
||||||
if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
|
if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
|
||||||
ts->counts[BGP_STATS_ASN_HIGHEST] =
|
ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
|
||||||
highest;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bgp_table_stats_walker(struct thread *t)
|
||||||
|
{
|
||||||
|
struct bgp_node *rn, *nrn;
|
||||||
|
struct bgp_node *top;
|
||||||
|
struct bgp_table_stats *ts = THREAD_ARG(t);
|
||||||
|
unsigned int space = 0;
|
||||||
|
|
||||||
|
if (!(top = bgp_table_top(ts->table)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (ts->table->afi) {
|
||||||
|
case AFI_IP:
|
||||||
|
space = IPV4_MAX_BITLEN;
|
||||||
|
break;
|
||||||
|
case AFI_IP6:
|
||||||
|
space = IPV6_MAX_BITLEN;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ts->counts[BGP_STATS_MAXBITLEN] = space;
|
||||||
|
|
||||||
|
for (rn = top; rn; rn = bgp_route_next(rn)) {
|
||||||
|
if (ts->table->safi == SAFI_MPLS_VPN) {
|
||||||
|
struct bgp_table *table;
|
||||||
|
|
||||||
|
table = bgp_node_get_bgp_table_info(rn);
|
||||||
|
if (!table)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
top = bgp_table_top(table);
|
||||||
|
for (nrn = bgp_table_top(table); nrn;
|
||||||
|
nrn = bgp_route_next(nrn))
|
||||||
|
bgp_table_stats_rn(nrn, top, ts, space);
|
||||||
|
} else {
|
||||||
|
bgp_table_stats_rn(rn, top, ts, space);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user