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