]> git.proxmox.com Git - mirror_frr.git/commitdiff
tests: Integrate unit tests for TI-LFA
authorGalaxyGorilla <sascha@netdef.org>
Tue, 17 Nov 2020 13:03:18 +0000 (13:03 +0000)
committerGalaxyGorilla <sascha@netdef.org>
Tue, 19 Jan 2021 15:32:13 +0000 (15:32 +0000)
Signed-off-by: GalaxyGorilla <sascha@netdef.org>
ospfd/ospf_route.h
tests/ospfd/common.c
tests/ospfd/common.h
tests/ospfd/test_ospf_spf.c
tests/ospfd/test_ospf_spf.in [new file with mode: 0644]
tests/ospfd/test_ospf_spf.py
tests/ospfd/test_ospf_spf.refout [new file with mode: 0644]
tests/subdir.am

index 86a14352ba2bc4d689001b3f6a49543ef8e94f28..811581c0d30415aa3213c5225acddb0957012d13 100644 (file)
@@ -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 *);
index e5139f799cec037a35d352b66fdf4cb311dc8a28..2f3ae3cb5e215fff71e8f5050e57a968f257b090 100644 (file)
@@ -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)
 {
index 6a6fe97f85f54c14047cb2124e067b348f0fd043..ecc340ad41936a39c69fb1a967eb495659e06715 100644 (file)
@@ -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 */
index 29c00eeb9b57164ba6142e6fe3054e676243030c..9d7ddacc7aa7ad204b9f3004c3f35c53f6158168 100644 (file)
@@ -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);
diff --git a/tests/ospfd/test_ospf_spf.in b/tests/ospfd/test_ospf_spf.in
new file mode 100644 (file)
index 0000000..ccd51e5
--- /dev/null
@@ -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
index 3ae1c00e1561c0ff4eed435ccb2a1db8823c690d..92a1c6a1457eb2dabfc2f1f73f3bf8dd4ab7a620 100644 (file)
@@ -1,6 +1,4 @@
 import frrtest
 
-class TestOspfSPF(frrtest.TestMultiOut):
+class TestOspfSPF(frrtest.TestRefOut):
     program = './test_ospf_spf'
-
-TestOspfSPF.exit_cleanly()
diff --git a/tests/ospfd/test_ospf_spf.refout b/tests/ospfd/test_ospf_spf.refout
new file mode 100644 (file)
index 0000000..4cd04de
--- /dev/null
@@ -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.
index 5bbe1a20c6d5b05f2fd6c4f1e8f3ff39e2b5f7a1..b2ce54ba662ad8ecea8d1b501a8927b94e8f82c9 100644 (file)
@@ -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 \