2 * Copyright (C) 2020 NetDEF, Inc.
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)
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
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
19 #ifndef _PATH_PCEP_CONTROLLER_H_
20 #define _PATH_PCEP_CONTROLLER_H_
22 #include "pathd/path_pcep.h"
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
,
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
);
40 enum pcep_pathd_event_type
{
41 PCEP_PATH_UNDEFINED
= 0,
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
;
54 struct pcc_state
*pcc
[MAX_PCC
];
57 /* Timer handling data structures */
59 enum pcep_ctrl_timeout_type
{ TO_UNDEFINED
, TO_COMPUTATION_REQUEST
, TO_MAX
};
61 enum pcep_ctrl_timer_type
{
66 TM_CALCULATE_BEST_PCE
,
67 TM_SESSION_TIMEOUT_PCC
,
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
;
79 /* Socket handling data structures */
81 enum pcep_ctrl_socket_type
{ SOCK_PCEPLIB
= 1 };
83 struct pcep_ctrl_socket_data
{
84 struct ctrl_state
*ctrl_state
;
85 enum pcep_ctrl_socket_type type
;
92 typedef int (*pcep_ctrl_thread_callback
)(struct thread
*);
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 */
100 struct ipaddr pcc_addr
;
105 uint32_t next_plspid
;
106 bool is_best_multi_pce
;
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
,
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
);
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
);
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
,
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
);
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
);
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
,
178 #endif // _PATH_PCEP_CONTROLLER_H_