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