2 * Copyright (C) 2020 Volta Networks, Inc
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)
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
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/>.
38 #include "link_state.h"
40 extern struct ted_state ted_state_g
;
41 #define TIMER_RETRY_DELAY 5 /* Timeout in seconds between ls sync request */
44 #define TED_NAME "PATHD TED"
53 struct thread_master
*main
;
54 /* Status of TED: enable or disable */
56 /* From which igp is going to receive data */
57 enum igp_import import
;
58 /* The TED itself as in link_state.h */
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
;
71 #define PATH_TED_DEBUG_BASIC 0x01
72 #define PATH_TED_DEBUG(fmt, ...) \
74 if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \
75 DEBUGD(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
78 #define PATH_TED_ERROR(fmt, ...) \
80 if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \
81 DEBUGE(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
83 #define PATH_TED_WARN(fmt, ...) \
85 if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \
86 DEBUGW(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
88 #define PATH_TED_INFO(fmt, ...) \
90 if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \
91 DEBUGI(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
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);
102 /* TED configuration functions */
103 uint32_t path_ted_config_write(struct vty
*vty
);
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 */
126 uint32_t path_ted_get_current_igp(uint32_t);
127 /* TED Query functions */
130 * Type of queries from draft-ietf-spring-segment-routing-policy-07 for types
135 * Search for sid based in prefix and optional algo
137 * @param prefix Net prefix to resolv
138 * @param algo Algorithm for link state
140 * @return sid of attribute
142 uint32_t path_ted_query_type_c(struct prefix
*prefix
, uint8_t algo
);
145 * Search for sid based in prefix and interface id
147 * @param prefix Net prefix to resolv
148 * @param iface_id The interface id
150 * @return sid of attribute
152 uint32_t path_ted_query_type_e(struct prefix
*prefix
, uint32_t iface_id
);
155 * Search for sid based in local, remote pair
157 * @param local local ip of attribute
158 * @param remote remote ip of attribute
160 * @return sid of attribute
162 uint32_t path_ted_query_type_f(struct ipaddr
*local
, struct ipaddr
*remote
);
166 * Handle the received opaque msg
168 * @param msg Holds the ted data
170 * @return sid of attribute
172 uint32_t path_ted_rcvd_message(struct ls_message
*msg
);
178 #endif /* _PATH_TED_H */