]> git.proxmox.com Git - mirror_frr.git/blame - lib/flex_algo.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / flex_algo.h
CommitLineData
735fb37d
HS
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*********************************************************************
3 * Copyright 2022 Hiroki Shirokura, LINE Corporation
4 * Copyright 2022 Masakazu Asama
5 * Copyright 2022 6WIND S.A.
6 *
7 * flex_algo.h: Flexible Algorithm library
8 *
9 * Authors
10 * -------
11 * Hiroki Shirokura
12 * Masakazu Asama
13 * Louis Scalbert
14 */
15
16#ifndef _FRR_FLEX_ALGO_H
17#define _FRR_FLEX_ALGO_H
18
19#include "admin_group.h"
20#include "linklist.h"
21#include "prefix.h"
22#include "segment_routing.h"
23
24#define FLEX_ALGO_PRIO_DEFAULT 128
25
26#define CALC_TYPE_SPF 0
27
28/* flex-algo definition flags */
29
30/* M-flag (aka. prefix-metric)
31 * Flex-Algorithm specific prefix and ASBR metric MUST be used
32 */
33#define FAD_FLAG_M 0x80
34
35/*
36 * Metric Type values from RFC9350 section 5.1
37 */
38enum flex_algo_metric_type {
39 MT_IGP = 0,
40 MT_MIN_UNI_LINK_DELAY = 1,
41 MT_TE_DEFAULT = 2,
42};
43
44
45/* Flex-Algo data about a given algorithm.
46 * It includes the definition and some local data.
47 */
48struct flex_algo {
49 /* Flex-Algo definition */
50 uint8_t algorithm;
51 enum flex_algo_metric_type metric_type;
52 uint8_t calc_type;
53 uint8_t priority;
54 uint8_t flags;
55
56 /* extended admin-groups */
57 struct admin_group admin_group_exclude_any;
58 struct admin_group admin_group_include_any;
59 struct admin_group admin_group_include_all;
60
61 /* Exclude SRLG Sub-TLV is not yet supported by IS-IS
62 * True if a Exclude SRLG Sub-TLV has been found
63 */
64 bool exclude_srlg;
65
66 /* True if an unsupported sub-TLV other Exclude SRLG
67 * has been received.
68 * A router that receives an unsupported definition
69 * that is elected must not participate in the algorithm.
70 * This boolean prevents future sub-TLV from being considered
71 * as supported.
72 */
73 bool unsupported_subtlv;
74
75 /* Flex-Algo local data */
76
77 /* True if the local definition must be advertised */
78 bool advertise_definition;
79
80 /* which dataplane must be used for the algorithm */
81#define FLEX_ALGO_SR_MPLS 0x01
82#define FLEX_ALGO_SRV6 0x02
83#define FLEX_ALGO_IP 0x04
84 uint8_t dataplanes;
85
3f55b8c6
LS
86 /* True if the Algorithm is locally enabled (ie. a definition has been
87 * found and is supported).
88 */
89 bool state;
90
735fb37d
HS
91 /*
92 * This property can be freely extended among different routing
93 * protocols. Since Flex-Algo is an IGP protocol agnostic, both IS-IS
94 * and OSPF can implement Flex-Algo. The struct flex_algo thus provides
95 * the general data structure of Flex-Algo, and the value of extending
96 * it with the IGP protocol is provided by this property.
97 */
98 void *data;
99};
100
101typedef void *(*flex_algo_allocator_t)(void *);
102typedef void (*flex_algo_releaser_t)(void *);
103
104struct flex_algos {
105 flex_algo_allocator_t allocator;
106 flex_algo_releaser_t releaser;
107 struct list *flex_algos;
108};
109
110/*
111 * Flex-Algo Utilities
112 */
113struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
114 flex_algo_releaser_t releaser);
87acad86 115void flex_algos_free(struct flex_algos *flex_algos);
735fb37d
HS
116struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
117 uint8_t algorithm, void *arg);
118struct flex_algo *flex_algo_lookup(struct flex_algos *flex_algos,
119 uint8_t algorithm);
120void flex_algos_free(struct flex_algos *flex_algos);
121bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2);
122void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm);
123bool flex_algo_id_valid(uint16_t algorithm);
124char *flex_algo_metric_type_print(char *type_str, size_t sz,
125 enum flex_algo_metric_type metric_type);
126
3f55b8c6
LS
127bool flex_algo_get_state(struct flex_algos *flex_algos, uint8_t algorithm);
128
129void flex_algo_set_state(struct flex_algos *flex_algos, uint8_t algorithm,
130 bool state);
735fb37d 131#endif /* _FRR_FLEX_ALGO_H */