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