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"
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
32 typedef int (*pcep_main_event_handler_t
)(enum pcep_main_event_type type
,
33 int pcc_id
, void *payload
);
35 enum pcep_pathd_event_type
{
36 PCEP_PATH_UNDEFINED
= 0,
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
;
49 struct pcc_state
*pcc
[MAX_PCC
];
52 /* Timer handling data structures */
54 enum pcep_ctrl_timeout_type
{ TO_UNDEFINED
, TO_COMPUTATION_REQUEST
, TO_MAX
};
56 enum pcep_ctrl_timer_type
{
61 TM_CALCULATE_BEST_PCE
,
62 TM_SESSION_TIMEOUT_PCC
,
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
;
74 /* Socket handling data structures */
76 enum pcep_ctrl_socket_type
{ SOCK_PCEPLIB
= 1 };
78 struct pcep_ctrl_socket_data
{
79 struct ctrl_state
*ctrl_state
;
80 enum pcep_ctrl_socket_type type
;
87 typedef int (*pcep_ctrl_thread_callback
)(struct thread
*);
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 */
95 struct ipaddr pcc_addr
;
100 uint32_t next_plspid
;
101 bool is_best_multi_pce
;
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
,
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
);
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
,
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
,
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
);
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
);
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
);
166 #endif // _PATH_PCEP_CONTROLLER_H_