]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
75c69d15 JG |
2 | /* |
3 | * Copyright (C) 2020 Volta Networks, Inc | |
4 | * | |
75c69d15 JG |
5 | * You should have received a copy of the GNU Lesser General Public License |
6 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
7 | * | |
8 | */ | |
9 | ||
10 | #ifndef _PATH_TED_H | |
11 | #define _PATH_TED_H | |
12 | ||
13 | #ifdef __cplusplus | |
14 | ||
15 | extern "C" { | |
16 | #endif | |
17 | ||
18 | #include <zebra.h> | |
19 | ||
20 | #include <stdbool.h> | |
21 | ||
22 | #include <debug.h> | |
23 | #include "linklist.h" | |
24 | #include "log.h" | |
25 | #include "command.h" | |
26 | #include "stream.h" | |
27 | #include "prefix.h" | |
28 | #include "zclient.h" | |
29 | #include "link_state.h" | |
30 | ||
31 | extern struct ted_state ted_state_g; | |
32 | #define TIMER_RETRY_DELAY 5 /* Timeout in seconds between ls sync request */ | |
33 | #define TED_KEY 1 | |
34 | #define TED_ASN 1 | |
35 | #define TED_NAME "PATHD TED" | |
36 | ||
37 | enum igp_import { | |
38 | IMPORT_UNKNOWN = 0, | |
39 | IMPORT_ISIS, | |
40 | IMPORT_OSPFv2, | |
41 | IMPORT_OSPFv3 | |
42 | }; | |
43 | struct ted_state { | |
44 | struct thread_master *main; | |
45 | /* Status of TED: enable or disable */ | |
46 | bool enabled; | |
47 | /* From which igp is going to receive data */ | |
48 | enum igp_import import; | |
49 | /* The TED itself as in link_state.h */ | |
50 | struct ls_ted *ted; | |
51 | /* Timer for ted sync */ | |
52 | struct thread *t_link_state_sync; | |
53 | /* Timer for refresh sid in segment list */ | |
54 | struct thread *t_segment_list_refresh; | |
55 | /* delay interval in seconds */ | |
56 | uint32_t link_state_delay_interval; | |
57 | /* delay interval refresh in seconds */ | |
58 | uint32_t segment_list_refresh_interval; | |
59 | struct debug dbg; | |
60 | }; | |
61 | /* Debug flags. */ | |
62 | #define PATH_TED_DEBUG_BASIC 0x01 | |
63 | #define PATH_TED_DEBUG(fmt, ...) \ | |
64 | do { \ | |
65 | if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \ | |
66 | DEBUGD(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \ | |
67 | } while (0) | |
68 | ||
69 | #define PATH_TED_ERROR(fmt, ...) \ | |
70 | do { \ | |
71 | if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \ | |
72 | DEBUGE(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \ | |
73 | } while (0) | |
74 | #define PATH_TED_WARN(fmt, ...) \ | |
75 | do { \ | |
76 | if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \ | |
77 | DEBUGW(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \ | |
78 | } while (0) | |
79 | #define PATH_TED_INFO(fmt, ...) \ | |
80 | do { \ | |
81 | if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \ | |
82 | DEBUGI(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \ | |
83 | } while (0) | |
84 | ||
85 | /* TED management functions */ | |
86 | bool path_ted_is_initialized(void); | |
87 | void path_ted_init(struct thread_master *master); | |
88 | uint32_t path_ted_teardown(void); | |
89 | void path_ted_timer_sync_cancel(void); | |
90 | void path_ted_timer_refresh_cancel(void); | |
91 | int path_ted_segment_list_refresh(void); | |
92 | ||
93 | /* TED configuration functions */ | |
94 | uint32_t path_ted_config_write(struct vty *vty); | |
96cb277e | 95 | void path_ted_show_debugging(struct vty *vty); |
75c69d15 JG |
96 | |
97 | /* TED util functions */ | |
98 | /* clang-format off */ | |
99 | #define LS_MSG_EVENT_PRINT(event) event == LS_MSG_EVENT_ADD?"add"\ | |
100 | : event == LS_MSG_EVENT_DELETE?"del"\ | |
101 | : event == LS_MSG_EVENT_UPDATE?"upd"\ | |
102 | : event == LS_MSG_EVENT_SYNC?"syn"\ | |
103 | : event == LS_MSG_EVENT_SYNC?"und" : "none" | |
104 | #define LS_MSG_TYPE_PRINT(type) type == LS_MSG_TYPE_NODE?"node"\ | |
105 | : type == LS_MSG_TYPE_ATTRIBUTES?"att"\ | |
106 | : type == LS_MSG_TYPE_PREFIX?"pre" : "none" | |
107 | #define LS_IGP_PRINT(type) type == ISIS_L1?"ISIS_L1"\ | |
108 | : type == ISIS_L2?"ISIS_L2"\ | |
109 | : type == DIRECT?"DIRECT"\ | |
110 | : type == STATIC?"STATIC"\ | |
111 | : type == OSPFv2?"OSPFv2" : "none" | |
112 | #define PATH_TED_IGP_PRINT(type) type == IMPORT_OSPFv2?"OSPFv2"\ | |
113 | : type == IMPORT_OSPFv3?"OSPFv3"\ | |
114 | : type == IMPORT_ISIS?"ISIS" : "none" | |
115 | /* clang-format on */ | |
116 | ||
117 | ||
118 | uint32_t path_ted_get_current_igp(uint32_t); | |
119 | /* TED Query functions */ | |
120 | ||
121 | /* | |
122 | * Type of queries from draft-ietf-spring-segment-routing-policy-07 for types | |
123 | * f,c,e | |
124 | */ | |
125 | ||
126 | /** | |
127 | * Search for sid based in prefix and optional algo | |
128 | * | |
129 | * @param prefix Net prefix to resolv | |
130 | * @param algo Algorithm for link state | |
131 | * | |
132 | * @return sid of attribute | |
133 | */ | |
134 | uint32_t path_ted_query_type_c(struct prefix *prefix, uint8_t algo); | |
135 | ||
136 | /** | |
137 | * Search for sid based in prefix and interface id | |
138 | * | |
139 | * @param prefix Net prefix to resolv | |
140 | * @param iface_id The interface id | |
141 | * | |
142 | * @return sid of attribute | |
143 | */ | |
144 | uint32_t path_ted_query_type_e(struct prefix *prefix, uint32_t iface_id); | |
145 | ||
146 | /** | |
147 | * Search for sid based in local, remote pair | |
148 | * | |
149 | * @param local local ip of attribute | |
150 | * @param remote remote ip of attribute | |
151 | * | |
152 | * @return sid of attribute | |
153 | */ | |
154 | uint32_t path_ted_query_type_f(struct ipaddr *local, struct ipaddr *remote); | |
155 | ||
156 | ||
157 | /** | |
158 | * Handle the received opaque msg | |
159 | * | |
160 | * @param msg Holds the ted data | |
161 | * | |
162 | * @return sid of attribute | |
163 | */ | |
164 | uint32_t path_ted_rcvd_message(struct ls_message *msg); | |
165 | ||
166 | #ifdef __cplusplus | |
167 | } | |
168 | #endif | |
169 | ||
170 | #endif /* _PATH_TED_H */ |