]>
git.proxmox.com Git - mirror_frr.git/blob - tests/isisd/test_isis_spf.c
2 * Copyright (C) 2020 NetDEF, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <lib/version.h>
31 #include "isisd/isisd.h"
32 #include "isisd/isis_dynhn.h"
33 #include "isisd/isis_misc.h"
34 #include "isisd/isis_spf.h"
35 #include "isisd/isis_spf_private.h"
37 #include "test_common.h"
44 #define F_DISPLAY_LSPDB 0x01
45 #define F_IPV4_ONLY 0x02
46 #define F_IPV6_ONLY 0x04
47 #define F_LEVEL1_ONLY 0x08
48 #define F_LEVEL2_ONLY 0x10
50 static struct isis
*isis
;
52 static void test_run_spf(struct vty
*vty
, const struct isis_topology
*topology
,
53 const struct isis_test_node
*root
,
54 struct isis_area
*area
, struct lspdb_head
*lspdb
,
55 int level
, int tree
, bool reverse
)
57 struct isis_spftree
*spftree
;
58 enum spf_type spf_type
;
61 spf_type
= reverse
? SPF_TYPE_REVERSE
: SPF_TYPE_FORWARD
;
62 spftree
= isis_spftree_new(area
, lspdb
, root
->sysid
, level
, tree
,
63 spf_type
, F_SPFTREE_NO_ADJACENCIES
);
64 isis_run_spf(spftree
);
66 /* Print the SPT and the corresponding routing table. */
67 isis_print_spftree(vty
, spftree
);
68 isis_print_routes(vty
, spftree
);
70 /* Cleanup SPF tree. */
71 isis_spftree_del(spftree
);
74 static int test_run(struct vty
*vty
, const struct isis_topology
*topology
,
75 const struct isis_test_node
*root
, enum test_type test_type
,
78 struct isis_area
*area
;
81 memcpy(isis
->sysid
, root
->sysid
, sizeof(isis
->sysid
));
82 area
= isis_area_create("1", NULL
);
83 area
->is_type
= IS_LEVEL_1_AND_2
;
84 area
->srdb
.enabled
= true;
85 if (test_topology_load(topology
, area
, area
->lspdb
) != 0) {
86 vty_out(vty
, "%% Failed to load topology\n");
90 for (int level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
91 if (level
== IS_LEVEL_1
&& CHECK_FLAG(flags
, F_LEVEL2_ONLY
))
93 if (level
== IS_LEVEL_2
&& CHECK_FLAG(flags
, F_LEVEL1_ONLY
))
95 if ((root
->level
& level
) == 0)
98 /* Print the LDPDB. */
99 if (CHECK_FLAG(flags
, F_DISPLAY_LSPDB
))
100 show_isis_database_lspdb(vty
, area
, level
- 1,
101 &area
->lspdb
[level
- 1], NULL
,
102 ISIS_UI_LEVEL_DETAIL
);
104 for (int tree
= SPFTREE_IPV4
; tree
<= SPFTREE_IPV6
; tree
++) {
105 if (tree
== SPFTREE_IPV4
106 && CHECK_FLAG(flags
, F_IPV6_ONLY
))
108 if (tree
== SPFTREE_IPV6
109 && CHECK_FLAG(flags
, F_IPV4_ONLY
))
114 test_run_spf(vty
, topology
, root
, area
,
115 &area
->lspdb
[level
- 1], level
,
118 case TEST_REVERSE_SPF
:
119 test_run_spf(vty
, topology
, root
, area
,
120 &area
->lspdb
[level
- 1], level
,
127 /* Cleanup IS-IS area. */
128 isis_area_destroy(area
);
130 /* Cleanup hostnames. */
131 dyn_cache_cleanup_all();
136 DEFUN(test_isis
, test_isis_cmd
,
137 "test isis topology (1-13) root HOSTNAME\
142 [display-lspdb] [<ipv4-only|ipv6-only>] [<level-1-only|level-2-only>]",
144 "IS-IS routing protocol\n"
146 "Test topology number\n"
148 "SPF root hostname\n"
149 "Normal Shortest Path First\n"
150 "Reverse Shortest Path First\n"
151 "Display the LSPDB\n"
152 "Do IPv4 processing only\n"
153 "Do IPv6 processing only\n"
157 uint16_t topology_number
;
158 const struct isis_topology
*topology
;
159 const struct isis_test_node
*root
;
160 enum test_type test_type
;
165 argv_find(argv
, argc
, "topology", &idx
);
166 topology_number
= atoi(argv
[idx
+ 1]->arg
);
167 topology
= test_topology_find(test_topologies
, topology_number
);
169 vty_out(vty
, "%% Topology \"%s\" not found\n",
174 /* Find root node. */
175 argv_find(argv
, argc
, "root", &idx
);
176 root
= test_topology_find_node(topology
, argv
[idx
+ 1]->arg
, 0);
178 vty_out(vty
, "%% Node \"%s\" not found\n", argv
[idx
+ 1]->arg
);
182 /* Parse test information. */
183 if (argv_find(argv
, argc
, "spf", &idx
))
184 test_type
= TEST_SPF
;
185 else if (argv_find(argv
, argc
, "reverse-spf", &idx
))
186 test_type
= TEST_REVERSE_SPF
;
190 /* Parse control flags. */
191 if (argv_find(argv
, argc
, "display-lspdb", &idx
))
192 SET_FLAG(flags
, F_DISPLAY_LSPDB
);
193 if (argv_find(argv
, argc
, "ipv4-only", &idx
))
194 SET_FLAG(flags
, F_IPV4_ONLY
);
195 else if (argv_find(argv
, argc
, "ipv6-only", &idx
))
196 SET_FLAG(flags
, F_IPV6_ONLY
);
197 if (argv_find(argv
, argc
, "level-1-only", &idx
))
198 SET_FLAG(flags
, F_LEVEL1_ONLY
);
199 else if (argv_find(argv
, argc
, "level-2-only", &idx
))
200 SET_FLAG(flags
, F_LEVEL2_ONLY
);
202 return test_run(vty
, topology
, root
, test_type
, flags
);
205 static void vty_do_exit(int isexit
)
213 thread_master_free(master
);
215 log_memstats(stderr
, "test-isis-spf");
220 struct option longopts
[] = {{"help", no_argument
, NULL
, 'h'},
221 {"debug", no_argument
, NULL
, 'd'},
224 /* Help information display. */
225 static void usage(char *progname
, int status
)
228 fprintf(stderr
, "Try `%s --help' for more information.\n",
231 printf("Usage : %s [OPTION...]\n\
232 isisd SPF test program.\n\n\
233 -u, --debug Enable debugging\n\
234 -h, --help Display this help and exit\n\
236 Report bugs to %s\n",
237 progname
, FRR_BUG_ADDRESS
);
242 int main(int argc
, char **argv
)
246 struct thread thread
;
249 /* Set umask before anything for security */
252 /* get program name */
253 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
258 opt
= getopt_long(argc
, argv
, "hd", longopts
, 0);
279 master
= thread_master_create(NULL
);
280 isis_master_init(master
);
284 cmd_hostname_set("test");
285 vty_init(master
, false);
288 zlog_aux_init("NONE: ", LOG_DEBUG
);
290 zlog_aux_init("NONE: ", ZLOG_DISABLED
);
293 yang_module_load("frr-isisd");
294 isis
= isis_new(VRF_DEFAULT_NAME
);
295 listnode_add(im
->isis
, isis
);
296 SET_FLAG(im
->options
, F_ISIS_UNIT_TEST
);
297 debug_spf_events
|= DEBUG_SPF_EVENTS
;
298 debug_events
|= DEBUG_EVENTS
;
299 debug_rte_events
|= DEBUG_RTE_EVENTS
;
301 /* Install test command. */
302 install_element(VIEW_NODE
, &test_isis_cmd
);
304 /* Read input from .in file. */
305 vty_stdio(vty_do_exit
);
307 /* Fetch next active thread. */
308 while (thread_fetch(master
, &thread
))
309 thread_call(&thread
);