1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020 NetDEF, Inc.
6 #ifndef _PATH_PCEP_CONTROLLER_H_
7 #define _PATH_PCEP_CONTROLLER_H_
9 #include "pathd/path_pcep.h"
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
,
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
);
28 enum pcep_pathd_event_type
{
29 PCEP_PATH_UNDEFINED
= 0,
36 struct thread_master
*main
;
37 struct thread_master
*self
;
38 pcep_main_event_handler_t main_event_handler
;
39 struct pcc_opts
*pcc_opts
;
42 struct pcc_state
*pcc
[MAX_PCC
];
45 /* Timer handling data structures */
47 enum pcep_ctrl_timeout_type
{ TO_UNDEFINED
, TO_COMPUTATION_REQUEST
, TO_MAX
};
49 enum pcep_ctrl_timer_type
{
54 TM_CALCULATE_BEST_PCE
,
55 TM_SESSION_TIMEOUT_PCC
,
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
;
67 /* Socket handling data structures */
69 enum pcep_ctrl_socket_type
{ SOCK_PCEPLIB
= 1 };
71 struct pcep_ctrl_socket_data
{
72 struct ctrl_state
*ctrl_state
;
73 enum pcep_ctrl_socket_type type
;
80 typedef void (*pcep_ctrl_thread_callback
)(struct thread
*);
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 */
88 struct ipaddr pcc_addr
;
94 bool is_best_multi_pce
;
99 /* Functions called from the main thread */
100 int pcep_ctrl_initialize(struct thread_master
*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
,
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
);
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
);
128 int pcep_ctrl_send_error(struct frr_pthread
*fpt
, int pcc_id
,
129 struct pcep_error
*error
);
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
,
135 void pcep_thread_initiate_path(struct ctrl_state
*ctrl_state
, int pcc_id
,
137 void pcep_thread_cancel_timer(struct thread
**thread
);
138 void pcep_thread_schedule_reconnect(struct ctrl_state
*ctrl_state
, int pcc_id
,
139 int retry_count
, struct thread
**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 thread
**thread
);
144 void pcep_thread_schedule_session_timeout(struct ctrl_state
*ctrl_state
,
145 int pcc_id
, int delay
,
146 struct thread
**thread
);
147 void pcep_thread_remove_candidate_path_segments(struct ctrl_state
*ctrl_state
,
148 struct pcc_state
*pcc_state
);
150 void pcep_thread_schedule_sync_best_pce(struct ctrl_state
*ctrl_state
,
151 int pcc_id
, int delay
,
152 struct thread
**thread
);
153 void pcep_thread_schedule_pceplib_timer(struct ctrl_state
*ctrl_state
,
154 int delay
, void *payload
,
155 struct thread
**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
);
162 int pcep_thread_send_ctrl_event(void *fpt
, void *payload
,
163 pcep_ctrl_thread_callback cb
);
164 void pcep_thread_pcep_event(struct thread
*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
,
171 #endif // _PATH_PCEP_CONTROLLER_H_