Skip to content

Commit

Permalink
Do not poll pceplib pcep_events anymore
Browse files Browse the repository at this point in the history
- Instead, provide a callback that when called, will create
  an FRR thread event. This event callback will then handle
  the pceplib pcep_event
  • Loading branch information
Brady Johnson authored and bradyallenjohnson committed May 28, 2020
1 parent cb1b3a6 commit ef87269
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 56 deletions.
86 changes: 40 additions & 46 deletions pathd/path_pcep_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "pathd/path_pcep_nb.h"
#include "pathd/path_pcep_debug.h"

#define POLL_INTERVAL 1
#define MAX_RECONNECT_DELAY 120

#define min(a, b) \
Expand All @@ -49,13 +48,13 @@

/* Event handling data structures */
enum pcep_ctrl_event_type {
EV_INITIALIZE = 1,
EV_UPDATE_PCC_OPTS,
EV_UPDATE_PCC_OPTS = 1,
EV_UPDATE_PCE_OPTS,
EV_REMOVE_PCC,
EV_PATHD_EVENT,
EV_SYNC_PATH,
EV_SYNC_DONE
EV_SYNC_DONE,
EV_PCEPLIB_EVENT
};

struct pcep_ctrl_event_data {
Expand Down Expand Up @@ -93,7 +92,6 @@ static int pcep_ctrl_halt_cb(struct frr_pthread *fpt, void **res);

/* Internal Functions Called From Controller Thread */
static int pcep_thread_finish_event_handler(struct thread *thread);
static void pcep_thread_schedule_poll(struct ctrl_state *ctrl_state);
static int pcep_thread_get_counters_callback(struct thread *t);
static int pcep_thread_send_report_callback(struct thread *t);

Expand All @@ -105,7 +103,6 @@ static int schedule_thread_timer_with_cb(struct ctrl_state *ctrl_state,
int pcc_id, enum pcep_ctrl_timer_type type, uint32_t delay,
void *payload, struct thread **thread, pcep_ctrl_thread_callback timer_cb);
static int pcep_thread_timer_handler(struct thread *thread);
static int pcep_thread_timer_poll(struct ctrl_state *ctrl_state);

/* Controller Thread Socket read/write Handler */
static int schedule_thread_socket(struct ctrl_state *ctrl_state, int pcc_id,
Expand All @@ -117,6 +114,10 @@ static int schedule_thread_socket(struct ctrl_state *ctrl_state, int pcc_id,
static int send_to_thread(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_event_type type, uint32_t sub_type,
void *payload);
static int send_to_thread_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_event_type type,
uint32_t sub_type, void *payload,
pcep_ctrl_thread_callback event_cb);
static int pcep_thread_event_handler(struct thread *thread);
static int pcep_thread_event_update_pcc_options(struct ctrl_state *ctrl_state,
struct pcc_opts *opts);
Expand Down Expand Up @@ -187,7 +188,6 @@ int pcep_ctrl_initialize(struct thread_master *main_thread,
ctrl_state->main = main_thread;
ctrl_state->self = (*fpt)->master;
ctrl_state->main_event_handler = event_handler;
ctrl_state->t_poll = NULL;
ctrl_state->pcc_count = 0;
ctrl_state->pcc_opts =
XCALLOC(MTYPE_PCEP, sizeof(*ctrl_state->pcc_opts));
Expand All @@ -199,9 +199,6 @@ int pcep_ctrl_initialize(struct thread_master *main_thread,
/* Keep the state reference for events */
set_ctrl_state(*fpt, ctrl_state);

/* Initialize the PCEP thread */
send_to_thread(ctrl_state, 0, EV_INITIALIZE, 0, NULL);

return ret;
}

Expand Down Expand Up @@ -357,10 +354,6 @@ int pcep_thread_finish_event_handler(struct thread *thread)

assert(ctrl_state != NULL);

if (ctrl_state->t_poll != NULL) {
thread_cancel(ctrl_state->t_poll);
}

for (i = 0; i < ctrl_state->pcc_count; i++) {
pcep_pcc_finalize(ctrl_state, ctrl_state->pcc[i]);
ctrl_state->pcc[i] = NULL;
Expand All @@ -374,13 +367,6 @@ int pcep_thread_finish_event_handler(struct thread *thread)
return 0;
}

void pcep_thread_schedule_poll(struct ctrl_state *ctrl_state)
{
assert(ctrl_state->t_poll == NULL);
schedule_thread_timer(ctrl_state, 0, TM_POLL, POLL_INTERVAL, NULL,
&ctrl_state->t_poll);
}

int pcep_thread_get_counters_callback(struct thread *t)
{
struct get_counters_args *args = THREAD_ARG(t);
Expand Down Expand Up @@ -468,9 +454,6 @@ int pcep_thread_timer_handler(struct thread *thread)
struct pcc_state *pcc_state = NULL;

switch (type) {
case TM_POLL:
ret = pcep_thread_timer_poll(ctrl_state);
break;
case TM_RECONNECT_PCC:
pcc_state = get_pcc_state(ctrl_state, pcc_id);
pcep_pcc_reconnect(ctrl_state, pcc_state);
Expand All @@ -484,26 +467,23 @@ int pcep_thread_timer_handler(struct thread *thread)
return ret;
}

int pcep_thread_timer_poll(struct ctrl_state *ctrl_state)
int pcep_thread_pcep_event(struct thread *thread)
{
struct pcep_ctrl_event_data *data = THREAD_ARG(thread);
assert(data != NULL);
struct ctrl_state *ctrl_state = data->ctrl_state;
pcep_event *event = data->payload;
XFREE(MTYPE_PCEP, data);
int i;
pcep_event *event;

assert(ctrl_state->t_poll == NULL);

while ((event = event_queue_get_event()) != NULL) {
for (i = 0; i < ctrl_state->pcc_count; i++) {
struct pcc_state *pcc_state = ctrl_state->pcc[i];
if (pcc_state->sess != event->session)
continue;
pcep_pcc_pcep_event_handler(ctrl_state, pcc_state,
event);
break;
}
destroy_pcep_event(event);
}

pcep_thread_schedule_poll(ctrl_state);
for (i = 0; i < ctrl_state->pcc_count; i++) {
struct pcc_state *pcc_state = ctrl_state->pcc[i];
if (pcc_state->sess != event->session)
continue;
pcep_pcc_pcep_event_handler(ctrl_state, pcc_state, event);
break;
}
destroy_pcep_event(event);

return 0;
}
Expand Down Expand Up @@ -556,11 +536,28 @@ int pcep_thread_socket_read(void *fpt, void **thread, int fd, void *payload,
payload, fd, (struct thread **)thread, socket_cb);
}

int pcep_thread_send_ctrl_event(void *fpt, void *payload,
pcep_ctrl_thread_callback cb)
{
struct ctrl_state *ctrl_state = ((struct frr_pthread *)fpt)->data;

return send_to_thread_with_cb(ctrl_state, 0, EV_PCEPLIB_EVENT, 0,
payload, cb);
}

/* ------------ Controller Thread Event Handler ------------ */

int send_to_thread(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_event_type type, uint32_t sub_type,
void *payload)
{
return send_to_thread_with_cb(ctrl_state, pcc_id, type, sub_type,
payload, pcep_thread_event_handler);
}

int send_to_thread_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_event_type type, uint32_t sub_type,
void *payload, pcep_ctrl_thread_callback event_cb)
{
struct pcep_ctrl_event_data *data;

Expand All @@ -571,8 +568,8 @@ int send_to_thread(struct ctrl_state *ctrl_state, int pcc_id,
data->pcc_id = pcc_id;
data->payload = payload;

thread_add_event(ctrl_state->self, pcep_thread_event_handler,
(void *)data, 0, NULL);
thread_add_event(ctrl_state->self, event_cb, (void *)data, 0, NULL);

return 0;
}

Expand Down Expand Up @@ -600,9 +597,6 @@ int pcep_thread_event_handler(struct thread *thread)
struct pce_opts *pce_opts = NULL;

switch (type) {
case EV_INITIALIZE:
pcep_thread_schedule_poll(ctrl_state);
break;
case EV_UPDATE_PCC_OPTS:
assert(payload != NULL);
pcc_opts = (struct pcc_opts *)payload;
Expand Down
7 changes: 5 additions & 2 deletions pathd/path_pcep_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ struct ctrl_state {
struct thread_master *main;
struct thread_master *self;
pcep_main_event_handler_t main_event_handler;
struct thread *t_poll;
struct pcc_opts *pcc_opts;
int pcc_count;
struct pcc_state *pcc[MAX_PCC];
};

/* Timer handling data structures */

enum pcep_ctrl_timer_type { TM_POLL = 1, TM_RECONNECT_PCC, TM_PCEPLIB_TIMER };
enum pcep_ctrl_timer_type { TM_RECONNECT_PCC, TM_PCEPLIB_TIMER };

struct pcep_ctrl_timer_data {
struct ctrl_state *ctrl_state;
Expand Down Expand Up @@ -112,4 +111,8 @@ int pcep_thread_socket_read(void *fpt, void **thread, int fd,
int pcep_thread_socket_write(void *fpt, void **thread, int fd,
void *payload, pcep_ctrl_thread_callback cb);

int pcep_thread_send_ctrl_event(void *fpt, void *payload,
pcep_ctrl_thread_callback cb);
int pcep_thread_pcep_event(struct thread *thread);

#endif // _PATH_PCEP_CONTROLLER_H_
6 changes: 0 additions & 6 deletions pathd/path_pcep_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,6 @@ void _format_ctrl_state(int ps, struct ctrl_state *state)
PCEP_FORMAT("%*sself: <THREAD MASTER %p>\n", ps2, "",
state->self);
}
if (state->t_poll == NULL) {
PCEP_FORMAT("%*st_poll: NULL\n", ps2, "");
} else {
PCEP_FORMAT("%*st_poll: <THREAD %p>\n", ps2, "",
state->t_poll);
}
PCEP_FORMAT("%*spcc_count: %d\n", ps2, "", state->pcc_count);
PCEP_FORMAT("%*spcc:\n", ps2, "");
for (i = 0; i < state->pcc_count; i++) {
Expand Down
14 changes: 12 additions & 2 deletions pathd/path_pcep_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ static int pcep_lib_pceplib_socket_write_cb(void *fpt, void **thread, int fd,
static int pcep_lib_socket_read_ready(struct thread *thread);
static int pcep_lib_socket_write_ready(struct thread *thread);

/* pceplib pcep_event callbacks */
static void pcep_lib_pceplib_event_cb(void *fpt, pcep_event *event);

/* Internal functions */
static double_linked_list *pcep_lib_format_path(struct path *path);
static void pcep_lib_parse_open(struct pcep_caps *caps,
Expand Down Expand Up @@ -93,8 +96,9 @@ int pcep_lib_initialize(struct frr_pthread *fpt)
.timer_cancel_func = pcep_lib_pceplib_timer_cancel_cb,
/* Timers infrastructure */
.socket_read_func = pcep_lib_pceplib_socket_read_cb,
.socket_write_func = pcep_lib_pceplib_socket_write_cb
};
.socket_write_func = pcep_lib_pceplib_socket_write_cb,
/* PCEP events */
.pcep_event_func = pcep_lib_pceplib_event_cb};
if (!initialize_pcc_infra(&infra)) {
flog_err(EC_PATH_PCEP_PCC_INIT, "failed to initialize pceplib");
return 1;
Expand Down Expand Up @@ -238,6 +242,12 @@ int pcep_lib_socket_read_ready(struct thread *thread)
return retval;
}

/* Callback passed to pceplib when a pcep_event is ready */
void pcep_lib_pceplib_event_cb(void *fpt, pcep_event *event)
{
pcep_thread_send_ctrl_event(fpt, event, pcep_thread_pcep_event);
}

struct pcep_message *pcep_lib_format_report(struct path *path)
{
double_linked_list *objs = pcep_lib_format_path(path);
Expand Down

0 comments on commit ef87269

Please sign in to comment.