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_INITIATE_CANDIDATE
,
31 PCEP_MAIN_EVENT_UPDATE_CANDIDATE
,
32 PCEP_MAIN_EVENT_REMOVE_CANDIDATE_LSP
,
35 typedef int (*pcep_main_event_handler_t
)(enum pcep_main_event_type type
,
36 int pcc_id
, void *payload
);
37 typedef void (*pcep_refine_callback_t
)(struct ctrl_state
*ctrl_state
,
38 struct pcc_state
*pcc_state
,
39 struct path
*path
, void *payload
);
41 enum pcep_pathd_event_type
{
42 PCEP_PATH_UNDEFINED
= 0,
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
;
55 struct pcc_state
*pcc
[MAX_PCC
];
58 /* Timer handling data structures */
60 enum pcep_ctrl_timeout_type
{ TO_UNDEFINED
, TO_COMPUTATION_REQUEST
, TO_MAX
};
62 enum pcep_ctrl_timer_type
{
67 TM_CALCULATE_BEST_PCE
,
68 TM_SESSION_TIMEOUT_PCC
,
72 struct 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
;
80 /* Socket handling data structures */
82 enum pcep_ctrl_socket_type
{ SOCK_PCEPLIB
= 1 };
84 struct pcep_ctrl_socket_data
{
85 struct ctrl_state
*ctrl_state
;
86 enum pcep_ctrl_socket_type type
;
93 typedef int (*pcep_ctrl_thread_callback
)(struct thread
*);
95 /* PCC connection information, populated in a thread-safe
96 * manner with pcep_ctrl_get_pcc_info() */
97 struct pcep_pcc_info
{
98 struct ctrl_state
*ctrl_state
; /* will be NULL when returned */
101 struct ipaddr pcc_addr
;
106 uint32_t next_plspid
;
107 bool is_best_multi_pce
;
112 /* Functions called from the main thread */
113 int pcep_ctrl_initialize(struct thread_master
*main_thread
,
114 struct frr_pthread
**fpt
,
115 pcep_main_event_handler_t event_handler
);
116 int pcep_ctrl_finalize(struct frr_pthread
**fpt
);
117 int pcep_ctrl_update_pcc_options(struct frr_pthread
*fpt
,
118 struct pcc_opts
*opts
);
119 int pcep_ctrl_update_pce_options(struct frr_pthread
*fpt
,
120 struct pce_opts
*opts
);
121 int pcep_ctrl_remove_pcc(struct frr_pthread
*fpt
, struct pce_opts
*pce_opts
);
122 int pcep_ctrl_reset_pcc_session(struct frr_pthread
*fpt
, char *pce_name
);
123 int pcep_ctrl_pathd_event(struct frr_pthread
*fpt
,
124 enum pcep_pathd_event_type type
, struct path
*path
);
125 int pcep_ctrl_sync_path(struct frr_pthread
*fpt
, int pcc_id
, struct path
*path
);
126 int pcep_ctrl_sync_done(struct frr_pthread
*fpt
, int pcc_id
);
127 struct counters_group
*pcep_ctrl_get_counters(struct frr_pthread
*fpt
,
129 pcep_session
*pcep_ctrl_get_pcep_session(struct frr_pthread
*fpt
, int pcc_id
);
130 struct pcep_pcc_info
*pcep_ctrl_get_pcc_info(struct frr_pthread
*fpt
,
131 const char *pce_name
);
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 */
138 int pcep_ctrl_send_report(struct frr_pthread
*fpt
, int pcc_id
,
139 struct path
*path
, bool is_stable
);
141 int pcep_ctrl_send_error(struct frr_pthread
*fpt
, int pcc_id
,
142 struct pcep_error
*error
);
144 /* Functions called from the controller thread */
145 void pcep_thread_start_sync(struct ctrl_state
*ctrl_state
, int pcc_id
);
146 void pcep_thread_update_path(struct ctrl_state
*ctrl_state
, int pcc_id
,
148 void pcep_thread_initiate_path(struct ctrl_state
*ctrl_state
, int pcc_id
,
150 void pcep_thread_cancel_timer(struct thread
**thread
);
151 void pcep_thread_schedule_reconnect(struct ctrl_state
*ctrl_state
, int pcc_id
,
152 int retry_count
, struct thread
**thread
);
153 void 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
);
157 void pcep_thread_schedule_session_timeout(struct ctrl_state
*ctrl_state
,
158 int pcc_id
, int delay
,
159 struct thread
**thread
);
160 void pcep_thread_remove_candidate_path_segments(struct ctrl_state
*ctrl_state
,
161 struct pcc_state
*pcc_state
);
163 void pcep_thread_schedule_sync_best_pce(struct ctrl_state
*ctrl_state
,
164 int pcc_id
, int delay
,
165 struct thread
**thread
);
166 void 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
);
170 int pcep_thread_socket_read(void *fpt
, void **thread
, int fd
, void *payload
,
171 pcep_ctrl_thread_callback cb
);
172 int pcep_thread_socket_write(void *fpt
, void **thread
, int fd
, void *payload
,
173 pcep_ctrl_thread_callback cb
);
175 int pcep_thread_send_ctrl_event(void *fpt
, void *payload
,
176 pcep_ctrl_thread_callback cb
);
177 int pcep_thread_pcep_event(struct thread
*thread
);
178 int pcep_thread_pcc_count(struct ctrl_state
*ctrl_state
);
179 /* Called by the PCC to refine a path in the main thread */
180 int pcep_thread_refine_path(struct ctrl_state
*ctrl_state
, int pcc_id
,
181 pcep_refine_callback_t cb
, struct path
*path
,
184 #endif // _PATH_PCEP_CONTROLLER_H_