]> git.proxmox.com Git - mirror_frr.git/blame - pathd/path_pcep_controller.h
Merge pull request #9899 from Drumato/zebra-srv6-locator-detail-json-support
[mirror_frr.git] / pathd / path_pcep_controller.h
CommitLineData
efba0985
SM
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
74971473
JG
24struct ctrl_state;
25struct pcc_state;
efba0985
SM
26
27enum pcep_main_event_type {
28 PCEP_MAIN_EVENT_UNDEFINED = 0,
29 PCEP_MAIN_EVENT_START_SYNC,
56634922 30 PCEP_MAIN_EVENT_INITIATE_CANDIDATE,
efba0985 31 PCEP_MAIN_EVENT_UPDATE_CANDIDATE,
74971473 32 PCEP_MAIN_EVENT_REMOVE_CANDIDATE_LSP,
efba0985
SM
33};
34
35typedef int (*pcep_main_event_handler_t)(enum pcep_main_event_type type,
36 int pcc_id, void *payload);
74971473
JG
37typedef void (*pcep_refine_callback_t)(struct ctrl_state *ctrl_state,
38 struct pcc_state *pcc_state,
39 struct path *path, void *payload);
efba0985
SM
40
41enum pcep_pathd_event_type {
42 PCEP_PATH_UNDEFINED = 0,
43 PCEP_PATH_CREATED,
44 PCEP_PATH_UPDATED,
45 PCEP_PATH_REMOVED
46};
47
48struct 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
60enum pcep_ctrl_timeout_type { TO_UNDEFINED, TO_COMPUTATION_REQUEST, TO_MAX };
61
62enum 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
72struct 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
82enum pcep_ctrl_socket_type { SOCK_PCEPLIB = 1 };
83
84struct 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
93typedef int (*pcep_ctrl_thread_callback)(struct thread *);
94
95/* PCC connection information, populated in a thread-safe
96 * manner with pcep_ctrl_get_pcc_info() */
97struct 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;
5a90e1f3 108 bool previous_best;
efba0985
SM
109 uint8_t precedence;
110};
111
112/* Functions called from the main thread */
113int pcep_ctrl_initialize(struct thread_master *main_thread,
114 struct frr_pthread **fpt,
115 pcep_main_event_handler_t event_handler);
116int pcep_ctrl_finalize(struct frr_pthread **fpt);
117int pcep_ctrl_update_pcc_options(struct frr_pthread *fpt,
118 struct pcc_opts *opts);
119int pcep_ctrl_update_pce_options(struct frr_pthread *fpt,
120 struct pce_opts *opts);
121int pcep_ctrl_remove_pcc(struct frr_pthread *fpt, struct pce_opts *pce_opts);
122int pcep_ctrl_reset_pcc_session(struct frr_pthread *fpt, char *pce_name);
123int pcep_ctrl_pathd_event(struct frr_pthread *fpt,
124 enum pcep_pathd_event_type type, struct path *path);
125int pcep_ctrl_sync_path(struct frr_pthread *fpt, int pcc_id, struct path *path);
126int pcep_ctrl_sync_done(struct frr_pthread *fpt, int pcc_id);
127struct counters_group *pcep_ctrl_get_counters(struct frr_pthread *fpt,
128 int pcc_id);
129pcep_session *pcep_ctrl_get_pcep_session(struct frr_pthread *fpt, int pcc_id);
130struct pcep_pcc_info *pcep_ctrl_get_pcc_info(struct frr_pthread *fpt,
131 const char *pce_name);
132
74971473
JG
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 */
138int pcep_ctrl_send_report(struct frr_pthread *fpt, int pcc_id,
139 struct path *path, bool is_stable);
efba0985 140
56634922
JG
141int pcep_ctrl_send_error(struct frr_pthread *fpt, int pcc_id,
142 struct pcep_error *error);
143
efba0985
SM
144/* Functions called from the controller thread */
145void pcep_thread_start_sync(struct ctrl_state *ctrl_state, int pcc_id);
146void pcep_thread_update_path(struct ctrl_state *ctrl_state, int pcc_id,
147 struct path *path);
56634922
JG
148void pcep_thread_initiate_path(struct ctrl_state *ctrl_state, int pcc_id,
149 struct path *path);
efba0985
SM
150void pcep_thread_cancel_timer(struct thread **thread);
151void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
152 int retry_count, struct thread **thread);
153void 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);
157void pcep_thread_schedule_session_timeout(struct ctrl_state *ctrl_state,
158 int pcc_id, int delay,
159 struct thread **thread);
160void pcep_thread_remove_candidate_path_segments(struct ctrl_state *ctrl_state,
161 struct pcc_state *pcc_state);
162
163void pcep_thread_schedule_sync_best_pce(struct ctrl_state *ctrl_state,
164 int pcc_id, int delay,
165 struct thread **thread);
166void 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);
170int pcep_thread_socket_read(void *fpt, void **thread, int fd, void *payload,
171 pcep_ctrl_thread_callback cb);
172int pcep_thread_socket_write(void *fpt, void **thread, int fd, void *payload,
173 pcep_ctrl_thread_callback cb);
174
175int pcep_thread_send_ctrl_event(void *fpt, void *payload,
176 pcep_ctrl_thread_callback cb);
177int pcep_thread_pcep_event(struct thread *thread);
178int pcep_thread_pcc_count(struct ctrl_state *ctrl_state);
74971473
JG
179/* Called by the PCC to refine a path in the main thread */
180int pcep_thread_refine_path(struct ctrl_state *ctrl_state, int pcc_id,
181 pcep_refine_callback_t cb, struct path *path,
182 void *payload);
efba0985
SM
183
184#endif // _PATH_PCEP_CONTROLLER_H_