]> git.proxmox.com Git - mirror_frr.git/blob - pathd/path_pcep_controller.h
Merge pull request #10447 from ton31337/fix/json_with_whitespaces
[mirror_frr.git] / pathd / path_pcep_controller.h
1 /*
2 * Copyright (C) 2020 NetDEF, 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 General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef _PATH_PCEP_CONTROLLER_H_
20 #define _PATH_PCEP_CONTROLLER_H_
21
22 #include "pathd/path_pcep.h"
23
24 struct ctrl_state;
25 struct pcc_state;
26
27 enum pcep_main_event_type {
28 PCEP_MAIN_EVENT_UNDEFINED = 0,
29 PCEP_MAIN_EVENT_START_SYNC,
30 PCEP_MAIN_EVENT_INITIATE_CANDIDATE,
31 PCEP_MAIN_EVENT_UPDATE_CANDIDATE,
32 PCEP_MAIN_EVENT_REMOVE_CANDIDATE_LSP,
33 };
34
35 typedef int (*pcep_main_event_handler_t)(enum pcep_main_event_type type,
36 int pcc_id, void *payload);
37 typedef void (*pcep_refine_callback_t)(struct ctrl_state *ctrl_state,
38 struct pcc_state *pcc_state,
39 struct path *path, void *payload);
40
41 enum pcep_pathd_event_type {
42 PCEP_PATH_UNDEFINED = 0,
43 PCEP_PATH_CREATED,
44 PCEP_PATH_UPDATED,
45 PCEP_PATH_REMOVED
46 };
47
48 struct ctrl_state {
49 struct thread_master *main;
50 struct thread_master *self;
51 pcep_main_event_handler_t main_event_handler;
52 struct pcc_opts *pcc_opts;
53 int pcc_count;
54 int pcc_last_id;
55 struct pcc_state *pcc[MAX_PCC];
56 };
57
58 /* Timer handling data structures */
59
60 enum pcep_ctrl_timeout_type { TO_UNDEFINED, TO_COMPUTATION_REQUEST, TO_MAX };
61
62 enum pcep_ctrl_timer_type {
63 TM_UNDEFINED,
64 TM_RECONNECT_PCC,
65 TM_PCEPLIB_TIMER,
66 TM_TIMEOUT,
67 TM_CALCULATE_BEST_PCE,
68 TM_SESSION_TIMEOUT_PCC,
69 TM_MAX
70 };
71
72 struct pcep_ctrl_timer_data {
73 struct ctrl_state *ctrl_state;
74 enum pcep_ctrl_timer_type timer_type;
75 enum pcep_ctrl_timeout_type timeout_type;
76 int pcc_id;
77 void *payload;
78 };
79
80 /* Socket handling data structures */
81
82 enum pcep_ctrl_socket_type { SOCK_PCEPLIB = 1 };
83
84 struct pcep_ctrl_socket_data {
85 struct ctrl_state *ctrl_state;
86 enum pcep_ctrl_socket_type type;
87 bool is_read;
88 int fd;
89 int pcc_id;
90 void *payload;
91 };
92
93 typedef void (*pcep_ctrl_thread_callback)(struct thread *);
94
95 /* PCC connection information, populated in a thread-safe
96 * manner with pcep_ctrl_get_pcc_info() */
97 struct pcep_pcc_info {
98 struct ctrl_state *ctrl_state; /* will be NULL when returned */
99 char pce_name[64];
100 int pcc_id;
101 struct ipaddr pcc_addr;
102 uint16_t pcc_port;
103 int status;
104 short msd;
105 uint32_t next_reqid;
106 uint32_t next_plspid;
107 bool is_best_multi_pce;
108 bool previous_best;
109 uint8_t precedence;
110 };
111
112 /* Functions called from the main thread */
113 int pcep_ctrl_initialize(struct thread_master *main_thread,
114 struct frr_pthread **fpt,
115 pcep_main_event_handler_t event_handler);
116 int pcep_ctrl_finalize(struct frr_pthread **fpt);
117 int pcep_ctrl_update_pcc_options(struct frr_pthread *fpt,
118 struct pcc_opts *opts);
119 int pcep_ctrl_update_pce_options(struct frr_pthread *fpt,
120 struct pce_opts *opts);
121 int pcep_ctrl_remove_pcc(struct frr_pthread *fpt, struct pce_opts *pce_opts);
122 int pcep_ctrl_reset_pcc_session(struct frr_pthread *fpt, char *pce_name);
123 int pcep_ctrl_pathd_event(struct frr_pthread *fpt,
124 enum pcep_pathd_event_type type, struct path *path);
125 int pcep_ctrl_sync_path(struct frr_pthread *fpt, int pcc_id, struct path *path);
126 int pcep_ctrl_sync_done(struct frr_pthread *fpt, int pcc_id);
127 struct counters_group *pcep_ctrl_get_counters(struct frr_pthread *fpt,
128 int pcc_id);
129 pcep_session *pcep_ctrl_get_pcep_session(struct frr_pthread *fpt, int pcc_id);
130 struct pcep_pcc_info *pcep_ctrl_get_pcc_info(struct frr_pthread *fpt,
131 const char *pce_name);
132
133 /* Asynchronously send a report. The caller is giving away the path structure,
134 * it shouldn't be allocated on the stack. If `pcc_id` is `0` the report is
135 * sent by all PCCs. The parameter is_stable is used to hint wether the status
136 * will soon change, this is used to ensure all report updates are sent even
137 * when missing status update events */
138 int pcep_ctrl_send_report(struct frr_pthread *fpt, int pcc_id,
139 struct path *path, bool is_stable);
140
141 int pcep_ctrl_send_error(struct frr_pthread *fpt, int pcc_id,
142 struct pcep_error *error);
143
144 /* Functions called from the controller thread */
145 void pcep_thread_start_sync(struct ctrl_state *ctrl_state, int pcc_id);
146 void pcep_thread_update_path(struct ctrl_state *ctrl_state, int pcc_id,
147 struct path *path);
148 void pcep_thread_initiate_path(struct ctrl_state *ctrl_state, int pcc_id,
149 struct path *path);
150 void pcep_thread_cancel_timer(struct thread **thread);
151 void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
152 int retry_count, struct thread **thread);
153 void pcep_thread_schedule_timeout(struct ctrl_state *ctrl_state, int pcc_id,
154 enum pcep_ctrl_timeout_type type,
155 uint32_t delay, void *param,
156 struct thread **thread);
157 void pcep_thread_schedule_session_timeout(struct ctrl_state *ctrl_state,
158 int pcc_id, int delay,
159 struct thread **thread);
160 void pcep_thread_remove_candidate_path_segments(struct ctrl_state *ctrl_state,
161 struct pcc_state *pcc_state);
162
163 void pcep_thread_schedule_sync_best_pce(struct ctrl_state *ctrl_state,
164 int pcc_id, int delay,
165 struct thread **thread);
166 void pcep_thread_schedule_pceplib_timer(struct ctrl_state *ctrl_state,
167 int delay, void *payload,
168 struct thread **thread,
169 pcep_ctrl_thread_callback cb);
170 int pcep_thread_socket_read(void *fpt, void **thread, int fd, void *payload,
171 pcep_ctrl_thread_callback cb);
172 int pcep_thread_socket_write(void *fpt, void **thread, int fd, void *payload,
173 pcep_ctrl_thread_callback cb);
174
175 int pcep_thread_send_ctrl_event(void *fpt, void *payload,
176 pcep_ctrl_thread_callback cb);
177 void pcep_thread_pcep_event(struct thread *thread);
178 int pcep_thread_pcc_count(struct ctrl_state *ctrl_state);
179 /* Called by the PCC to refine a path in the main thread */
180 int pcep_thread_refine_path(struct ctrl_state *ctrl_state, int pcc_id,
181 pcep_refine_callback_t cb, struct path *path,
182 void *payload);
183
184 #endif // _PATH_PCEP_CONTROLLER_H_