From 3a76b1be886ba84a55eaf25bb0866b292c1ab428 Mon Sep 17 00:00:00 2001 From: GalaxyGorilla Date: Wed, 12 Aug 2020 11:58:54 +0000 Subject: [PATCH] ospfd: add print helper for SPF trees and route tables Signed-off-by: GalaxyGorilla --- ospfd/ospf_route.c | 31 +++++++++++++++++++++++++++++++ ospfd/ospf_route.h | 1 + ospfd/ospf_spf.c | 27 +++++++++++++++++++++++++++ ospfd/ospf_spf.h | 2 ++ 4 files changed, 61 insertions(+) diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index 487275beec..3b049555ba 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -665,6 +665,37 @@ void ospf_route_table_dump(struct route_table *rt) zlog_debug("========================================"); } +void ospf_route_table_print(struct vty *vty, struct route_table *rt) +{ + struct route_node *rn; + struct ospf_route * or ; + struct listnode *pnode; + struct ospf_path *path; + + vty_out(vty, "========== OSPF routing table ==========\n"); + for (rn = route_top(rt); rn; rn = route_next(rn)) + if ((or = rn->info) != NULL) { + if (or->type == OSPF_DESTINATION_NETWORK) { + vty_out(vty, "N %-18pFX %-15pI4 %s %d\n", + &rn->p, & or->u.std.area_id, + ospf_path_type_str[or->path_type], + or->cost); + for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, + path)) + vty_out(vty, " -> %s\n", + path->nexthop.s_addr != 0 + ? inet_ntoa( + path->nexthop) + : "directly connected"); + } else + vty_out(vty, "R %-18pI4 %-15pI4 %s %d\n", + &rn->p.u.prefix4, & or->u.std.area_id, + ospf_path_type_str[or->path_type], + or->cost); + } + vty_out(vty, "========================================\n"); +} + /* This is 16.4.1 implementation. o Intra-area paths using non-backbone areas are always the most preferred. o The other paths, intra-area backbone paths and inter-area paths, diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h index a0aa7a0c6f..c3fa5954d5 100644 --- a/ospfd/ospf_route.h +++ b/ospfd/ospf_route.h @@ -132,6 +132,7 @@ extern void ospf_route_table_free(struct route_table *); extern void ospf_route_install(struct ospf *, struct route_table *); extern void ospf_route_table_dump(struct route_table *); +extern void ospf_route_table_print(struct vty *vty, struct route_table *rt); extern void ospf_intra_add_router(struct route_table *, struct vertex *, struct ospf_area *); diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index dfeb80bd17..e9e1882956 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -994,6 +994,33 @@ static void ospf_spf_dump(struct vertex *v, int i) ospf_spf_dump(v, i); } +void ospf_spf_print(struct vty *vty, struct vertex *v, int i) +{ + struct listnode *cnode; + struct listnode *nnode; + struct vertex_parent *parent; + + if (v->type == OSPF_VERTEX_ROUTER) { + vty_out(vty, "SPF Result: depth %d [R] %s\n", i, + inet_ntoa(v->lsa->id)); + } else { + struct network_lsa *lsa = (struct network_lsa *)v->lsa; + vty_out(vty, "SPF Result: depth %d [N] %s/%d\n", i, + inet_ntoa(v->lsa->id), ip_masklen(lsa->mask)); + } + + for (ALL_LIST_ELEMENTS_RO(v->parents, nnode, parent)) { + vty_out(vty, " nexthop %s lsa pos %d\n", + inet_ntoa(parent->nexthop->router), + parent->nexthop->lsa_pos); + } + + i++; + + for (ALL_LIST_ELEMENTS_RO(v->children, cnode, v)) + ospf_spf_print(vty, v, i); +} + /* Second stage of SPF calculation. */ static void ospf_spf_process_stubs(struct ospf_area *area, struct vertex *v, struct route_table *rt, int parent_is_root) diff --git a/ospfd/ospf_spf.h b/ospfd/ospf_spf.h index 9bf3dc645e..15c48a124c 100644 --- a/ospfd/ospf_spf.h +++ b/ospfd/ospf_spf.h @@ -82,5 +82,7 @@ extern int ospf_spf_calculate_areas(struct ospf *ospf, bool is_dry_run); extern void ospf_rtrs_free(struct route_table *); +extern void ospf_spf_print(struct vty *vty, struct vertex *v, int i); + /* void ospf_spf_calculate_timer_add (); */ #endif /* _QUAGGA_OSPF_SPF_H */