isisd: make optional algorithm id in 'show isis route'

To avoid calling for each algorithm the 'show isis route'
command, the algorithm id is optional. The below command
will dump the routes for all the algorithms:

> show isis route algorithm

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
Philippe Guibert 2022-12-15 09:26:45 +01:00 committed by Louis Scalbert
parent 311eac53e8
commit 88e368b4dc

View File

@ -3011,6 +3011,39 @@ static void show_isis_route_common(struct vty *vty, int levels,
}
}
static void show_isis_route_all_algos(struct vty *vty, int levels,
struct isis *isis, bool prefix_sid,
bool backup, json_object **json)
{
uint16_t algo;
json_object *json_algo = NULL, *json_algos = NULL;
if (json) {
*json = json_object_new_object();
json_algos = json_object_new_array();
}
for (algo = SR_ALGORITHM_FLEX_MIN; algo <= SR_ALGORITHM_FLEX_MAX;
algo++) {
show_isis_route_common(vty, levels, isis, prefix_sid, backup,
(uint8_t)algo, json ? &json_algo : NULL);
if (!json)
continue;
if (json_object_object_length(json_algo) == 0) {
json_object_free(json_algo);
continue;
}
json_object_object_add(json_algo, "algorithm",
json_object_new_int(algo));
json_object_array_add(json_algos, json_algo);
}
if (json)
json_object_object_add(*json, "algorithms", json_algos);
}
DEFUN(show_isis_route, show_isis_route_cmd,
"show " PROTO_NAME
" [vrf <NAME|all>] route"
@ -3019,7 +3052,7 @@ DEFUN(show_isis_route, show_isis_route_cmd,
#endif /* ifndef FABRICD */
" [<prefix-sid|backup>]"
#ifndef FABRICD
" [algorithm (128-255)]"
" [algorithm [(128-255)]]"
#endif /* ifndef FABRICD */
" [json$uj]",
SHOW_STR PROTO_HELP VRF_FULL_CMD_HELP_STR
@ -3041,6 +3074,7 @@ DEFUN(show_isis_route, show_isis_route_cmd,
struct listnode *node;
const char *vrf_name = VRF_DEFAULT_NAME;
bool all_vrf = false;
bool all_algorithm = false;
bool prefix_sid = false;
bool backup = false;
bool uj = use_json(argc, argv);
@ -3067,8 +3101,13 @@ DEFUN(show_isis_route, show_isis_route_cmd,
backup = true;
#ifndef FABRICD
if (argv_find(argv, argc, "algorithm", &idx))
algorithm = (uint8_t)strtoul(argv[idx + 1]->arg, NULL, 10);
if (argv_find(argv, argc, "algorithm", &idx)) {
if (argv_find(argv, argc, "(128-255)", &idx))
algorithm = (uint8_t)strtoul(argv[idx + 1]->arg, NULL,
10);
else
all_algorithm = true;
}
#endif /* ifndef FABRICD */
if (uj)
@ -3077,9 +3116,19 @@ DEFUN(show_isis_route, show_isis_route_cmd,
if (vrf_name) {
if (all_vrf) {
for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) {
show_isis_route_common(
vty, levels, isis, prefix_sid, backup,
algorithm, uj ? &json_vrf : NULL);
if (all_algorithm)
show_isis_route_all_algos(vty, levels,
isis,
prefix_sid,
backup,
uj ? &json_vrf
: NULL);
else
show_isis_route_common(vty, levels,
isis, prefix_sid,
backup, algorithm,
uj ? &json_vrf
: NULL);
if (uj) {
json_object_object_add(
json_vrf, "vrf_id",
@ -3092,9 +3141,15 @@ DEFUN(show_isis_route, show_isis_route_cmd,
}
isis = isis_lookup_by_vrfname(vrf_name);
if (isis != NULL) {
show_isis_route_common(vty, levels, isis, prefix_sid,
backup, algorithm,
uj ? &json_vrf : NULL);
if (all_algorithm)
show_isis_route_all_algos(vty, levels, isis,
prefix_sid, backup,
uj ? &json_vrf : NULL);
else
show_isis_route_common(vty, levels, isis,
prefix_sid, backup,
algorithm,
uj ? &json_vrf : NULL);
if (uj) {
json_object_object_add(
json_vrf, "vrf_id",