summaryrefslogtreecommitdiffstats
path: root/lib/flex_algo.h
blob: e617e7cae849e56c8aaa4da00965b73058e8dd87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// SPDX-License-Identifier: GPL-2.0-or-later
/*********************************************************************
 * Copyright 2022 Hiroki Shirokura, LINE Corporation
 * Copyright 2022 Masakazu Asama
 * Copyright 2022 6WIND S.A.
 *
 * flex_algo.h: Flexible Algorithm library
 *
 * Authors
 * -------
 * Hiroki Shirokura
 * Masakazu Asama
 * Louis Scalbert
 */

#ifndef _FRR_FLEX_ALGO_H
#define _FRR_FLEX_ALGO_H

#include "admin_group.h"
#include "linklist.h"
#include "prefix.h"
#include "segment_routing.h"

#define FLEX_ALGO_PRIO_DEFAULT 128

#define CALC_TYPE_SPF 0

/* flex-algo definition flags */

/* M-flag (aka. prefix-metric)
 * Flex-Algorithm specific prefix and ASBR metric MUST be used
 */
#define FAD_FLAG_M 0x80

/*
 * Metric Type values from RFC9350 section 5.1
 */
enum flex_algo_metric_type {
	MT_IGP = 0,
	MT_MIN_UNI_LINK_DELAY = 1,
	MT_TE_DEFAULT = 2,
};


/* Flex-Algo data about a given algorithm.
 * It includes the definition and some local data.
 */
struct flex_algo {
	/* Flex-Algo definition */
	uint8_t algorithm;
	enum flex_algo_metric_type metric_type;
	uint8_t calc_type;
	uint8_t priority;
	uint8_t flags;

	/* extended admin-groups */
	struct admin_group admin_group_exclude_any;
	struct admin_group admin_group_include_any;
	struct admin_group admin_group_include_all;

	/* Exclude SRLG Sub-TLV is not yet supported by IS-IS
	 * True if a Exclude SRLG Sub-TLV has been found
	 */
	bool exclude_srlg;

	/* True if an unsupported sub-TLV other Exclude SRLG
	 * has been received.
	 * A router that receives an unsupported definition
	 * that is elected must not participate in the algorithm.
	 * This boolean prevents future sub-TLV from being considered
	 * as supported.
	 */
	bool unsupported_subtlv;

	/* Flex-Algo local data */

	/* True if the local definition must be advertised */
	bool advertise_definition;

	/* which dataplane must be used for the algorithm */
#define FLEX_ALGO_SR_MPLS 0x01
#define FLEX_ALGO_SRV6 0x02
#define FLEX_ALGO_IP 0x04
	uint8_t dataplanes;

	/* True if the Algorithm is locally enabled (ie. a definition has been
	 * found and is supported).
	 */
	bool state;

	/*
	 * This property can be freely extended among different routing
	 * protocols. Since Flex-Algo is an IGP protocol agnostic, both IS-IS
	 * and OSPF can implement Flex-Algo. The struct flex_algo thus provides
	 * the general data structure of Flex-Algo, and the value of extending
	 * it with the IGP protocol is provided by this property.
	 */
	void *data;
};

typedef void *(*flex_algo_allocator_t)(void *);
typedef void (*flex_algo_releaser_t)(void *);

struct flex_algos {
	flex_algo_allocator_t allocator;
	flex_algo_releaser_t releaser;
	struct list *flex_algos;
};

/*
 * Flex-Algo Utilities
 */
struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
				    flex_algo_releaser_t releaser);
void flex_algos_free(struct flex_algos *flex_algos);
struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
				  uint8_t algorithm, void *arg);
struct flex_algo *flex_algo_lookup(struct flex_algos *flex_algos,
				   uint8_t algorithm);
void flex_algos_free(struct flex_algos *flex_algos);
bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2);
void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm);
bool flex_algo_id_valid(uint16_t algorithm);
char *flex_algo_metric_type_print(char *type_str, size_t sz,
				  enum flex_algo_metric_type metric_type);

bool flex_algo_get_state(struct flex_algos *flex_algos, uint8_t algorithm);

void flex_algo_set_state(struct flex_algos *flex_algos, uint8_t algorithm,
			 bool state);
#endif /* _FRR_FLEX_ALGO_H */