]> git.proxmox.com Git - mirror_frr.git/blame - lib/flex_algo.h
Merge pull request #13386 from donaldsharp/bgp_received_routes
[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
86 /*
87 * This property can be freely extended among different routing
88 * protocols. Since Flex-Algo is an IGP protocol agnostic, both IS-IS
89 * and OSPF can implement Flex-Algo. The struct flex_algo thus provides
90 * the general data structure of Flex-Algo, and the value of extending
91 * it with the IGP protocol is provided by this property.
92 */
93 void *data;
94};
95
96typedef void *(*flex_algo_allocator_t)(void *);
97typedef void (*flex_algo_releaser_t)(void *);
98
99struct flex_algos {
100 flex_algo_allocator_t allocator;
101 flex_algo_releaser_t releaser;
102 struct list *flex_algos;
103};
104
105/*
106 * Flex-Algo Utilities
107 */
108struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
109 flex_algo_releaser_t releaser);
110struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
111 uint8_t algorithm, void *arg);
112struct flex_algo *flex_algo_lookup(struct flex_algos *flex_algos,
113 uint8_t algorithm);
114void flex_algos_free(struct flex_algos *flex_algos);
115bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2);
116void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm);
117bool flex_algo_id_valid(uint16_t algorithm);
118char *flex_algo_metric_type_print(char *type_str, size_t sz,
119 enum flex_algo_metric_type metric_type);
120
121#endif /* _FRR_FLEX_ALGO_H */