mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
lib,isisd: refactor igp-agnostic sr misc functions
SR Algorithms are independent of specific IGPs such as IS-IS. This commit adds lib/sr to aggregate IGP agnostic functions and constants. Signed-off-by: Hiroki Shirokura <hiroki.shirokura@linecorp.com> Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com> Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
parent
7f8dddf430
commit
81a067cd92
|
@ -611,7 +611,7 @@ static struct ls_vertex *lsp_to_vertex(struct ls_ted *ted, struct isis_lsp *lsp)
|
||||||
lnode.srgb.flag = cap->srgb.flags;
|
lnode.srgb.flag = cap->srgb.flags;
|
||||||
lnode.srgb.lower_bound = cap->srgb.lower_bound;
|
lnode.srgb.lower_bound = cap->srgb.lower_bound;
|
||||||
lnode.srgb.range_size = cap->srgb.range_size;
|
lnode.srgb.range_size = cap->srgb.range_size;
|
||||||
for (int i = 0; i < SR_ALGORITHM_COUNT; i++)
|
for (int i = 0; i < LIB_LS_SR_ALGO_COUNT; i++)
|
||||||
lnode.algo[i] = cap->algo[i];
|
lnode.algo[i] = cap->algo[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3552,9 +3552,8 @@ static void format_tlv_router_cap(const struct isis_router_cap *router_cap,
|
||||||
for (int i = 0; i < SR_ALGORITHM_COUNT; i++)
|
for (int i = 0; i < SR_ALGORITHM_COUNT; i++)
|
||||||
if (router_cap->algo[i] != SR_ALGORITHM_UNSET)
|
if (router_cap->algo[i] != SR_ALGORITHM_UNSET)
|
||||||
sbuf_push(buf, indent, " %u: %s\n", i,
|
sbuf_push(buf, indent, " %u: %s\n", i,
|
||||||
router_cap->algo[i] == 0
|
sr_algorithm_string(
|
||||||
? "SPF"
|
router_cap->algo[i]));
|
||||||
: "Strict SPF");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Segment Routing Node MSD as per RFC8491 section #2 */
|
/* Segment Routing Node MSD as per RFC8491 section #2 */
|
||||||
|
@ -3573,7 +3572,7 @@ static int pack_tlv_router_cap(const struct isis_router_cap *router_cap,
|
||||||
{
|
{
|
||||||
size_t tlv_len = ISIS_ROUTER_CAP_SIZE;
|
size_t tlv_len = ISIS_ROUTER_CAP_SIZE;
|
||||||
size_t len_pos;
|
size_t len_pos;
|
||||||
uint8_t nb_algo;
|
uint16_t nb_algo;
|
||||||
|
|
||||||
if (!router_cap)
|
if (!router_cap)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3757,13 +3756,9 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context,
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
break;
|
break;
|
||||||
/* Only 2 algorithms are supported: SPF & Strict SPF */
|
/* Only 2 algorithms are supported: SPF & Strict SPF */
|
||||||
stream_get(&rcap->algo, s,
|
stream_get(&rcap->algo, s, length > 2 ? 2 : length);
|
||||||
length > SR_ALGORITHM_COUNT
|
if (length > 2)
|
||||||
? SR_ALGORITHM_COUNT
|
stream_forward_getp(s, length - 2);
|
||||||
: length);
|
|
||||||
if (length > SR_ALGORITHM_COUNT)
|
|
||||||
stream_forward_getp(
|
|
||||||
s, length - SR_ALGORITHM_COUNT);
|
|
||||||
break;
|
break;
|
||||||
case ISIS_SUBTLV_SRLB:
|
case ISIS_SUBTLV_SRLB:
|
||||||
/* Check that SRLB is correctly formated */
|
/* Check that SRLB is correctly formated */
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#ifndef ISIS_TLVS_H
|
#ifndef ISIS_TLVS_H
|
||||||
#define ISIS_TLVS_H
|
#define ISIS_TLVS_H
|
||||||
|
|
||||||
|
#include "segment_routing.h"
|
||||||
#include "openbsd-tree.h"
|
#include "openbsd-tree.h"
|
||||||
#include "prefix.h"
|
#include "prefix.h"
|
||||||
|
|
||||||
|
@ -177,16 +178,6 @@ struct isis_lan_adj_sid {
|
||||||
#define ISIS_ROUTER_CAP_FLAG_D 0x02
|
#define ISIS_ROUTER_CAP_FLAG_D 0x02
|
||||||
#define ISIS_ROUTER_CAP_SIZE 5
|
#define ISIS_ROUTER_CAP_SIZE 5
|
||||||
|
|
||||||
/* Number of supported algorithm for Segment Routing.
|
|
||||||
* Right now only 2 have been standardized:
|
|
||||||
* - 0: SPF
|
|
||||||
* - 1: Strict SPF
|
|
||||||
*/
|
|
||||||
#define SR_ALGORITHM_COUNT 2
|
|
||||||
#define SR_ALGORITHM_SPF 0
|
|
||||||
#define SR_ALGORITHM_STRICT_SPF 1
|
|
||||||
#define SR_ALGORITHM_UNSET 255
|
|
||||||
|
|
||||||
#define MSD_TYPE_BASE_MPLS_IMPOSITION 0x01
|
#define MSD_TYPE_BASE_MPLS_IMPOSITION 0x01
|
||||||
#define MSD_TLV_SIZE 2
|
#define MSD_TLV_SIZE 2
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,9 @@ struct ls_node_id {
|
||||||
*/
|
*/
|
||||||
extern int ls_node_id_same(struct ls_node_id i1, struct ls_node_id i2);
|
extern int ls_node_id_same(struct ls_node_id i1, struct ls_node_id i2);
|
||||||
|
|
||||||
|
/* Supported number of algorithm by the link-state library */
|
||||||
|
#define LIB_LS_SR_ALGO_COUNT 2
|
||||||
|
|
||||||
/* Link State flags to indicate which Node parameters are valid */
|
/* Link State flags to indicate which Node parameters are valid */
|
||||||
#define LS_NODE_UNSET 0x0000
|
#define LS_NODE_UNSET 0x0000
|
||||||
#define LS_NODE_NAME 0x0001
|
#define LS_NODE_NAME 0x0001
|
||||||
|
@ -123,7 +126,7 @@ struct ls_node {
|
||||||
uint32_t lower_bound; /* MPLS label lower bound */
|
uint32_t lower_bound; /* MPLS label lower bound */
|
||||||
uint32_t range_size; /* MPLS label range size */
|
uint32_t range_size; /* MPLS label range size */
|
||||||
} srlb;
|
} srlb;
|
||||||
uint8_t algo[2]; /* Segment Routing Algorithms */
|
uint8_t algo[LIB_LS_SR_ALGO_COUNT]; /* Segment Routing Algorithms */
|
||||||
uint8_t msd; /* Maximum Stack Depth */
|
uint8_t msd; /* Maximum Stack Depth */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
30
lib/segment_routing.c
Normal file
30
lib/segment_routing.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
/*********************************************************************
|
||||||
|
* Copyright 2022 Hiroki Shirokura, LINE Corporation
|
||||||
|
* Copyright 2022 Masakazu Asama
|
||||||
|
* Copyright 2022 6WIND S.A.
|
||||||
|
*
|
||||||
|
* segment_routing.c: Segment-Routing Library
|
||||||
|
*
|
||||||
|
* Authors
|
||||||
|
* -------
|
||||||
|
* Hiroki Shirokura
|
||||||
|
* Masakazu Asama
|
||||||
|
* Louis Scalbert
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "segment_routing.h"
|
||||||
|
|
||||||
|
const char *sr_algorithm_string(uint8_t algo)
|
||||||
|
{
|
||||||
|
switch (algo) {
|
||||||
|
case SR_ALGORITHM_SPF:
|
||||||
|
return "SPF";
|
||||||
|
case SR_ALGORITHM_STRICT_SPF:
|
||||||
|
return "Strict SPF";
|
||||||
|
case SR_ALGORITHM_UNSET:
|
||||||
|
return "Unset";
|
||||||
|
default:
|
||||||
|
return algo >= SR_ALGORITHM_FLEX_MIN ? "Flex-Algo" : "Unknown";
|
||||||
|
}
|
||||||
|
}
|
42
lib/segment_routing.h
Normal file
42
lib/segment_routing.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
/*********************************************************************
|
||||||
|
* Copyright 2022 Hiroki Shirokura, LINE Corporation
|
||||||
|
* Copyright 2022 Masakazu Asama
|
||||||
|
* Copyright 2022 6WIND S.A.
|
||||||
|
*
|
||||||
|
* segment_routing.h: Segment-Routing Library
|
||||||
|
*
|
||||||
|
* Authors
|
||||||
|
* -------
|
||||||
|
* Hiroki Shirokura
|
||||||
|
* Masakazu Asama
|
||||||
|
* Louis Scalbert
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FRR_SR_H
|
||||||
|
#define _FRR_SR_H
|
||||||
|
|
||||||
|
#include <zebra.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IGP Algorithm Types
|
||||||
|
* https://www.iana.org/assignments/igp-parameters/igp-parameters.xhtml
|
||||||
|
*/
|
||||||
|
#define SR_ALGORITHM_SPF 0 /* RFC8665 */
|
||||||
|
#define SR_ALGORITHM_STRICT_SPF 1 /* RFC8665 */
|
||||||
|
#define SR_ALGORITHM_UNSET 127 /* FRRouting defined */
|
||||||
|
#define SR_ALGORITHM_FLEX_MIN 128 /* RFC9350 Flex-Algorithm */
|
||||||
|
#define SR_ALGORITHM_FLEX_MAX 255 /* RFC9350 Flex-Algorithm */
|
||||||
|
#define SR_ALGORITHM_COUNT 256
|
||||||
|
|
||||||
|
const char *sr_algorithm_string(uint8_t algo);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _FRR_SR_H */
|
|
@ -99,6 +99,7 @@ lib_libfrr_la_SOURCES = \
|
||||||
lib/sockopt.c \
|
lib/sockopt.c \
|
||||||
lib/sockunion.c \
|
lib/sockunion.c \
|
||||||
lib/spf_backoff.c \
|
lib/spf_backoff.c \
|
||||||
|
lib/segment_routing.c \
|
||||||
lib/srcdest_table.c \
|
lib/srcdest_table.c \
|
||||||
lib/stream.c \
|
lib/stream.c \
|
||||||
lib/strformat.c \
|
lib/strformat.c \
|
||||||
|
@ -282,6 +283,7 @@ pkginclude_HEADERS += \
|
||||||
lib/sockopt.h \
|
lib/sockopt.h \
|
||||||
lib/sockunion.h \
|
lib/sockunion.h \
|
||||||
lib/spf_backoff.h \
|
lib/spf_backoff.h \
|
||||||
|
lib/segment_routing.h \
|
||||||
lib/srcdest_table.h \
|
lib/srcdest_table.h \
|
||||||
lib/srte.h \
|
lib/srte.h \
|
||||||
lib/stream.h \
|
lib/stream.h \
|
||||||
|
|
Loading…
Reference in a new issue