summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHiroki Shirokura <hiroki.shirokura@linecorp.com>2022-01-22 12:07:40 +0100
committerLouis Scalbert <louis.scalbert@6wind.com>2023-04-18 10:11:43 +0200
commit81a067cd9251b60a04bbc8133546e790044fa790 (patch)
treea9082b7945b7da51ad54df3adb73b4013205d070 /lib
parentisisd: update struct isis_sr_psid_info with algorithm id (diff)
downloadfrr-81a067cd9251b60a04bbc8133546e790044fa790.tar.xz
frr-81a067cd9251b60a04bbc8133546e790044fa790.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/link_state.h5
-rw-r--r--lib/segment_routing.c30
-rw-r--r--lib/segment_routing.h42
-rw-r--r--lib/subdir.am2
4 files changed, 78 insertions, 1 deletions
diff --git a/lib/link_state.h b/lib/link_state.h
index b75f03543..3d2ed7a87 100644
--- a/lib/link_state.h
+++ b/lib/link_state.h
@@ -92,6 +92,9 @@ struct ls_node_id {
*/
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 */
#define LS_NODE_UNSET 0x0000
#define LS_NODE_NAME 0x0001
@@ -123,7 +126,7 @@ struct ls_node {
uint32_t lower_bound; /* MPLS label lower bound */
uint32_t range_size; /* MPLS label range size */
} 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 */
};
diff --git a/lib/segment_routing.c b/lib/segment_routing.c
new file mode 100644
index 000000000..f45a64d29
--- /dev/null
+++ b/lib/segment_routing.c
@@ -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";
+ }
+}
diff --git a/lib/segment_routing.h b/lib/segment_routing.h
new file mode 100644
index 000000000..5e71466bf
--- /dev/null
+++ b/lib/segment_routing.h
@@ -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 */
diff --git a/lib/subdir.am b/lib/subdir.am
index dcc58b31a..318c09663 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -99,6 +99,7 @@ lib_libfrr_la_SOURCES = \
lib/sockopt.c \
lib/sockunion.c \
lib/spf_backoff.c \
+ lib/segment_routing.c \
lib/srcdest_table.c \
lib/stream.c \
lib/strformat.c \
@@ -282,6 +283,7 @@ pkginclude_HEADERS += \
lib/sockopt.h \
lib/sockunion.h \
lib/spf_backoff.h \
+ lib/segment_routing.h \
lib/srcdest_table.h \
lib/srte.h \
lib/stream.h \