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