forked from Mirror/frr
tests: Integrate unit tests for TI-LFA
Signed-off-by: GalaxyGorilla <sascha@netdef.org>
This commit is contained in:
parent
184b834b6c
commit
66dc21bb23
|
@ -136,7 +136,6 @@ 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 *);
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
#include "lib/vty.h"
|
||||
#include "lib/mpls.h"
|
||||
#include "lib/if.h"
|
||||
#include "lib/table.h"
|
||||
|
||||
#include "ospfd/ospfd.h"
|
||||
#include "ospfd/ospf_route.h"
|
||||
#include "ospfd/ospf_spf.h"
|
||||
#include "ospfd/ospf_flood.h"
|
||||
#include "ospfd/ospf_lsa.h"
|
||||
|
@ -33,6 +35,51 @@ struct ospf_topology *test_find_topology(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int sort_paths(const void **path1, const void **path2)
|
||||
{
|
||||
const struct ospf_path *p1 = *path1;
|
||||
const struct ospf_path *p2 = *path2;
|
||||
|
||||
return (p1->nexthop.s_addr - p2->nexthop.s_addr);
|
||||
}
|
||||
|
||||
void print_route_table(struct vty *vty, struct route_table *rt)
|
||||
{
|
||||
struct route_node *rn;
|
||||
struct ospf_route * or ;
|
||||
struct listnode *pnode;
|
||||
struct ospf_path *path;
|
||||
struct mpls_label_stack *label_stack;
|
||||
char buf[MPLS_LABEL_STRLEN];
|
||||
|
||||
for (rn = route_top(rt); rn; rn = route_next(rn)) {
|
||||
if ((or = rn->info) == NULL)
|
||||
continue;
|
||||
|
||||
vty_out(vty, "N %-18pFX %-15pI4 %d\n", &rn->p,
|
||||
& or->u.std.area_id, or->cost);
|
||||
|
||||
list_sort(or->paths, sort_paths);
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
|
||||
if (path->nexthop.s_addr == 0)
|
||||
continue;
|
||||
|
||||
vty_out(vty, " -> %pI4 with adv router %pI4",
|
||||
&path->nexthop, &path->adv_router);
|
||||
|
||||
if (path->srni.backup_label_stack) {
|
||||
label_stack = path->srni.backup_label_stack;
|
||||
mpls_label2str(label_stack->num_labels,
|
||||
label_stack->label, buf,
|
||||
MPLS_LABEL_STRLEN, true);
|
||||
vty_out(vty, " and backup path %s", buf);
|
||||
}
|
||||
vty_out(vty, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ospf_test_node *test_find_node(struct ospf_topology *topology,
|
||||
const char *hostname)
|
||||
{
|
||||
|
|
|
@ -37,4 +37,10 @@ extern struct ospf_topology topo3;
|
|||
extern struct ospf_topology topo4;
|
||||
extern struct zebra_privs_t ospfd_privs;
|
||||
|
||||
/* For stable order in unit tests */
|
||||
extern int sort_paths(const void **path1, const void **path2);
|
||||
|
||||
/* Print the routing table */
|
||||
extern void print_route_table(struct vty *vty, struct route_table *rt);
|
||||
|
||||
#endif /* _COMMON_OSPF_H */
|
||||
|
|
|
@ -73,7 +73,7 @@ static void test_run_spf(struct vty *vty, struct ospf *ospf,
|
|||
|
||||
vty_out(vty,
|
||||
"\nRouting Table without TI-LFA backup paths:\n\n");
|
||||
ospf_route_table_print(vty, new_table);
|
||||
print_route_table(vty, new_table);
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
|
@ -129,7 +129,8 @@ static void test_run_spf(struct vty *vty, struct ospf *ospf,
|
|||
if (verbose)
|
||||
vty_out(vty,
|
||||
"\n\nFinal Routing Table including backup paths:\n\n");
|
||||
ospf_route_table_print(vty, new_table);
|
||||
|
||||
print_route_table(vty, new_table);
|
||||
}
|
||||
|
||||
static int test_run(struct vty *vty, struct ospf_topology *topology,
|
||||
|
@ -272,6 +273,7 @@ int main(int argc, char **argv)
|
|||
|
||||
/* Library inits. */
|
||||
cmd_init(1);
|
||||
cmd_hostname_set("test");
|
||||
vty_init(master, false);
|
||||
if (debug)
|
||||
zlog_aux_init("NONE: ", LOG_DEBUG);
|
||||
|
|
8
tests/ospfd/test_ospf_spf.in
Normal file
8
tests/ospfd/test_ospf_spf.in
Normal file
|
@ -0,0 +1,8 @@
|
|||
test ospf topology topo1 root rt1 ti-lfa
|
||||
test ospf topology topo1 root rt1 ti-lfa node-protection
|
||||
test ospf topology topo2 root rt1 ti-lfa
|
||||
test ospf topology topo2 root rt1 ti-lfa node-protection
|
||||
test ospf topology topo3 root rt1 ti-lfa
|
||||
test ospf topology topo3 root rt1 ti-lfa node-protection
|
||||
test ospf topology topo4 root rt1 ti-lfa
|
||||
test ospf topology topo4 root rt1 ti-lfa node-protection
|
|
@ -1,6 +1,4 @@
|
|||
import frrtest
|
||||
|
||||
class TestOspfSPF(frrtest.TestMultiOut):
|
||||
class TestOspfSPF(frrtest.TestRefOut):
|
||||
program = './test_ospf_spf'
|
||||
|
||||
TestOspfSPF.exit_cleanly()
|
||||
|
|
100
tests/ospfd/test_ospf_spf.refout
Normal file
100
tests/ospfd/test_ospf_spf.refout
Normal file
|
@ -0,0 +1,100 @@
|
|||
test# test ospf topology topo1 root rt1 ti-lfa
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 15002
|
||||
N 3.3.3.3/32 0.0.0.0 10
|
||||
-> 10.0.3.2 with adv router 3.3.3.3 and backup path 15001
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 20
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 15002
|
||||
-> 10.0.3.2 with adv router 3.3.3.3 and backup path 15001
|
||||
N 10.0.3.0/24 0.0.0.0 10
|
||||
test# test ospf topology topo1 root rt1 ti-lfa node-protection
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 3.3.3.3/32 0.0.0.0 10
|
||||
-> 10.0.3.2 with adv router 3.3.3.3
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 20
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
-> 10.0.3.2 with adv router 3.3.3.3
|
||||
N 10.0.3.0/24 0.0.0.0 10
|
||||
test# test ospf topology topo2 root rt1 ti-lfa
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 15002
|
||||
N 3.3.3.3/32 0.0.0.0 20
|
||||
-> 10.0.1.2 with adv router 3.3.3.3 and backup path 15002
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 20
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 15002
|
||||
N 10.0.3.0/24 0.0.0.0 30
|
||||
test# test ospf topology topo2 root rt1 ti-lfa node-protection
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 3.3.3.3/32 0.0.0.0 20
|
||||
-> 10.0.1.2 with adv router 3.3.3.3 and backup path 15002
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 20
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 10.0.3.0/24 0.0.0.0 30
|
||||
test# test ospf topology topo3 root rt1 ti-lfa
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 16030
|
||||
N 3.3.3.3/32 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 3.3.3.3 and backup path 15001
|
||||
N 4.4.4.4/32 0.0.0.0 10
|
||||
-> 10.0.4.2 with adv router 4.4.4.4 and backup path 15001/15004
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 30
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 16030
|
||||
N 10.0.3.0/24 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 4.4.4.4 and backup path 15001/15004
|
||||
N 10.0.4.0/24 0.0.0.0 10
|
||||
test# test ospf topology topo3 root rt1 ti-lfa node-protection
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 3.3.3.3/32 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 3.3.3.3 and backup path 15001
|
||||
N 4.4.4.4/32 0.0.0.0 10
|
||||
-> 10.0.4.2 with adv router 4.4.4.4
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 30
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 10.0.3.0/24 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 4.4.4.4
|
||||
N 10.0.4.0/24 0.0.0.0 10
|
||||
test# test ospf topology topo4 root rt1 ti-lfa
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 16030/15006
|
||||
N 3.3.3.3/32 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 3.3.3.3 and backup path 15001/15004
|
||||
N 4.4.4.4/32 0.0.0.0 10
|
||||
-> 10.0.4.2 with adv router 4.4.4.4 and backup path 15001/15004
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 60
|
||||
-> 10.0.1.2 with adv router 2.2.2.2 and backup path 16030/15006
|
||||
N 10.0.3.0/24 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 4.4.4.4 and backup path 15001/15004
|
||||
N 10.0.4.0/24 0.0.0.0 10
|
||||
test# test ospf topology topo4 root rt1 ti-lfa node-protection
|
||||
N 1.1.1.1/32 0.0.0.0 0
|
||||
N 2.2.2.2/32 0.0.0.0 10
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 3.3.3.3/32 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 3.3.3.3 and backup path 15001/15004
|
||||
N 4.4.4.4/32 0.0.0.0 10
|
||||
-> 10.0.4.2 with adv router 4.4.4.4
|
||||
N 10.0.1.0/24 0.0.0.0 10
|
||||
N 10.0.2.0/24 0.0.0.0 60
|
||||
-> 10.0.1.2 with adv router 2.2.2.2
|
||||
N 10.0.3.0/24 0.0.0.0 20
|
||||
-> 10.0.4.2 with adv router 4.4.4.4
|
||||
N 10.0.4.0/24 0.0.0.0 10
|
||||
test#
|
||||
end.
|
|
@ -387,6 +387,8 @@ EXTRA_DIST += \
|
|||
tests/isisd/test_isis_spf.refout \
|
||||
tests/isisd/test_isis_vertex_queue.py \
|
||||
tests/ospfd/test_ospf_spf.py \
|
||||
tests/ospfd/test_ospf_spf.in \
|
||||
tests/ospfd/test_ospf_spf.refout \
|
||||
tests/lib/cli/test_commands.in \
|
||||
tests/lib/cli/test_commands.py \
|
||||
tests/lib/cli/test_commands.refout \
|
||||
|
|
Loading…
Reference in a new issue