Skip to content

Commit

Permalink
Plugin FRR timers infra into PCEPlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Brady Johnson committed May 14, 2020
1 parent e29360d commit fc9850b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pathd/path_pcep.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ int pcep_module_late_init(struct thread_master *tm)

struct frr_pthread *fpt;

if (pcep_lib_initialize())
if (pcep_ctrl_initialize(tm, &fpt, pcep_main_event_handler))
return 1;

if (pcep_ctrl_initialize(tm, &fpt, pcep_main_event_handler))
if (pcep_lib_initialize(fpt))
return 1;

pcep_g->master = tm;
Expand Down
18 changes: 17 additions & 1 deletion pathd/path_pcep_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct pcep_main_event_data {

/* Timer handling data structures */

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

struct pcep_ctrl_timer_data {
struct ctrl_state *ctrl_state;
Expand Down Expand Up @@ -320,6 +320,18 @@ void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
thread);
}

void pcep_thread_schedule_pceplib_timer(struct ctrl_state *ctrl_state,
int delay, void *payload, struct thread **thread)
{
PCEP_DEBUG("Schedule pceplib timer for %us", delay);
schedule_thread(ctrl_state, 0, TM_PCEPLIB_TIMER, delay, payload, thread);
}

void pcep_thread_cancel_pceplib_timer(struct thread *thread)
{
PCEP_DEBUG("Cancel pceplib timer");
thread_cancel_async(thread->master, &thread, NULL);
}

/* ------------ Internal Functions Called From Controller Thread ------------ */

Expand Down Expand Up @@ -426,6 +438,7 @@ int pcep_thread_timer_handler(struct thread *thread)
assert(ctrl_state != NULL);
enum pcep_ctrl_timer_type type = data->type;
int pcc_id = data->pcc_id;
void *payload = data->payload;
XFREE(MTYPE_PCEP, data);

int ret = 0;
Expand All @@ -439,6 +452,9 @@ int pcep_thread_timer_handler(struct thread *thread)
pcc_state = get_pcc_state(ctrl_state, pcc_id);
pcep_pcc_reconnect(ctrl_state, pcc_state);
break;
case TM_PCEPLIB_TIMER:
pcep_lib_timer_expire(payload);
break;
default:
flog_warn(EC_PATH_PCEP_RECOVERABLE_INTERNAL_ERROR,
"Unknown controller timer triggered: %u", type);
Expand Down
4 changes: 4 additions & 0 deletions pathd/path_pcep_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ void pcep_thread_update_path(struct ctrl_state *ctrl_state, int pcc_id,
void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
int retry_count, struct thread **thread);

void pcep_thread_schedule_pceplib_timer(struct ctrl_state *ctrl_state,
int delay, void *payload, struct thread **thread);
void pcep_thread_cancel_pceplib_timer(struct thread *thread);

#endif // _PATH_PCEP_CONTROLLER_H_
49 changes: 39 additions & 10 deletions pathd/path_pcep_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <debug.h>
#include <pcep_utils_counters.h>
#include <pcep_timers.h>
#include "pathd/path_errors.h"
#include "pathd/path_memory.h"
#include "pathd/path_pcep.h"
Expand All @@ -31,6 +32,9 @@
/* pceplib logging callback */
static int pceplib_logging_cb(int level, const char *fmt, va_list args);

static void *pcep_lib_pceplib_timer_create_cb(void *fpt, int delay, void *payload);
static void pcep_lib_pceplib_timer_cancel_cb(void *thread);

/* Internal functions */
static double_linked_list *pcep_lib_format_path(struct path *path);
static void pcep_lib_parse_open(struct pcep_caps *caps,
Expand All @@ -54,28 +58,34 @@ static void free_counter(struct counter *counter);

/* ------------ API Functions ------------ */

int pcep_lib_initialize(void)
int pcep_lib_initialize(struct frr_pthread *fpt)
{
PCEP_DEBUG("Initializing pceplib");

/* Register pceplib logging callback */
register_logger(pceplib_logging_cb);

/* Its ok that this object goes out of scope, as it
* wont be stored, and its values will be copied */
struct pceplib_infra_config infra = {
.pceplib_infra_mt = MTYPE_PCEPLIB_INFRA,
/* Memory infrastructure */
.pceplib_infra_mt = MTYPE_PCEPLIB_INFRA,
.pceplib_messages_mt = MTYPE_PCEPLIB_MESSAGES,
.mfunc = (pceplib_malloc_func) qmalloc,
.cfunc = (pceplib_calloc_func) qcalloc,
.rfunc = (pceplib_realloc_func) qrealloc,
.sfunc = (pceplib_strdup_func) qstrdup,
.ffunc = (pceplib_free_func) qfree
.malloc_func = (pceplib_malloc_func) qmalloc,
.calloc_func = (pceplib_calloc_func) qcalloc,
.realloc_func = (pceplib_realloc_func) qrealloc,
.strdup_func = (pceplib_strdup_func) qstrdup,
.free_func = (pceplib_free_func) qfree,
/* Timers infrastructure */
.external_timer_infra_data = fpt,
.timer_create_func = pcep_lib_pceplib_timer_create_cb,
.timer_cancel_func = pcep_lib_pceplib_timer_cancel_cb
};
if (!initialize_pcc_infra(&infra)) {
flog_err(EC_PATH_PCEP_PCC_INIT, "failed to initialize pceplib");
return 1;
}

/* Register pceplib logging callback */
register_logger(pceplib_logging_cb);
return 0;
}

Expand Down Expand Up @@ -133,6 +143,26 @@ void pcep_lib_disconnect(pcep_session *sess)
disconnect_pce(sess);
}

void *pcep_lib_pceplib_timer_create_cb(void *fpt, int delay, void *payload)
{
struct ctrl_state *ctrl_state = ((struct frr_pthread *) fpt)->data;
struct thread *thread = NULL;

pcep_thread_schedule_pceplib_timer(ctrl_state, delay, payload, &thread);

return thread;
}

void pcep_lib_pceplib_timer_cancel_cb(void *thread)
{
pcep_thread_cancel_pceplib_timer(thread);
}

void pcep_lib_timer_expire(void *payload)
{
pceplib_external_timer_expire_handler(payload);
}

struct pcep_message *pcep_lib_format_report(struct path *path)
{
double_linked_list *objs = pcep_lib_format_path(path);
Expand Down Expand Up @@ -289,7 +319,6 @@ int pceplib_logging_cb(int priority, const char *fmt, va_list args)
return 0;
}


/* ------------ Internal Functions ------------ */

double_linked_list *pcep_lib_format_path(struct path *path)
Expand Down
4 changes: 3 additions & 1 deletion pathd/path_pcep_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

#include <stdbool.h>
#include <pcep_pcc_api.h>
#include "frr_pthread.h"
#include "pathd/path_pcep.h"

int pcep_lib_initialize(void);
int pcep_lib_initialize(struct frr_pthread *fpt);
void pcep_lib_finalize(void);
pcep_session *pcep_lib_connect(struct ipaddr *src_addr, int src_port,
struct ipaddr *dst_addr, int dst_port,
Expand All @@ -38,5 +39,6 @@ void pcep_lib_parse_capabilities(struct pcep_message *msg,
struct pcep_caps *caps);
struct counters_group *pcep_lib_copy_counters(pcep_session *sess);
void pcep_lib_free_counters(struct counters_group *counters);
void pcep_lib_timer_expire(void *payload);

#endif // _PATH_PCEP_LIB_H_

0 comments on commit fc9850b

Please sign in to comment.