Skip to content

Commit

Permalink
pathd: pcep module: formating cleanup and function extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
sylane committed May 22, 2020
1 parent a086f95 commit cb1b3a6
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions pathd/path_pcep.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static int pcep_main_event_handler(enum pcep_main_event_type type, int pcc_id,
void *payload);
static int pcep_main_event_start_sync(int pcc_id);
static int pcep_main_event_start_sync_cb(struct path *path, void *arg);
static int pcep_main_event_update_candidate(struct path *path);

/* Hook Handlers called from the Main Thread */
static int pathd_candidate_created_handler(struct srte_candidate *candidate);
Expand Down Expand Up @@ -142,42 +143,13 @@ int pcep_main_event_handler(enum pcep_main_event_type type, int pcc_id,
{
int ret = 0;

/* Possible payload values */
struct path *path = NULL, *resp = NULL;

switch (type) {
case PCEP_MAIN_EVENT_START_SYNC:
ret = pcep_main_event_start_sync(pcc_id);
break;
case PCEP_MAIN_EVENT_UPDATE_CANDIDATE:
assert(payload != NULL);
path = (struct path *)payload;
ret = path_nb_update_path(path);
if (ret != PATH_NB_ERR && path->srp_id != 0) {
/* ODL and Cisco requires the first reported
* LSP to have a DOWN status, the later status changes
* will be comunicated through hook calls.
*/
enum pcep_lsp_operational_status real_status;
if(resp = path_nb_get_path(&path->nbkey)){
resp->srp_id = path->srp_id;
real_status = resp->status;
resp->status = PCEP_LSP_OPERATIONAL_DOWN;
pcep_ctrl_send_report(pcep_g->fpt, path->pcc_id, resp);
/* If the update did not have any effect and the real
* status is not DOWN, we need to send a second report
* so the PCE is aware of the real status. This is due
* to the fact that NO notification will be received
* if the update did not apply any changes */
if ((ret == PATH_NB_NO_CHANGE)
&& (real_status != PCEP_LSP_OPERATIONAL_DOWN)) {
resp->status = real_status;
resp->srp_id = 0;
pcep_ctrl_send_report(pcep_g->fpt, path->pcc_id, resp);
}
pcep_free_path(resp);
}
}
ret = pcep_main_event_update_candidate((struct path *)payload);
break;
default:
flog_warn(EC_PATH_PCEP_RECOVERABLE_INTERNAL_ERROR,
Expand Down Expand Up @@ -205,6 +177,41 @@ int pcep_main_event_start_sync_cb(struct path *path, void *arg)
return 1;
}

int pcep_main_event_update_candidate(struct path *path)
{
struct path *resp = NULL;
int ret = 0;

ret = path_nb_update_path(path);
if (ret != PATH_NB_ERR && path->srp_id != 0) {
/* ODL and Cisco requires the first reported
* LSP to have a DOWN status, the later status changes
* will be comunicated through hook calls.
*/
enum pcep_lsp_operational_status real_status;
if ((resp = path_nb_get_path(&path->nbkey))) {
resp->srp_id = path->srp_id;
real_status = resp->status;
resp->status = PCEP_LSP_OPERATIONAL_DOWN;
pcep_ctrl_send_report(pcep_g->fpt, path->pcc_id, resp);
/* If the update did not have any effect and the real
* status is not DOWN, we need to send a second report
* so the PCE is aware of the real status. This is due
* to the fact that NO notification will be received
* if the update did not apply any changes */
if ((ret == PATH_NB_NO_CHANGE)
&& (real_status != PCEP_LSP_OPERATIONAL_DOWN)) {
resp->status = real_status;
resp->srp_id = 0;
pcep_ctrl_send_report(pcep_g->fpt, path->pcc_id,
resp);
}
pcep_free_path(resp);
}
}
return ret;
}


/* ------------ Hook Handlers Functions Called From Main Thread ------------ */

Expand Down

0 comments on commit cb1b3a6

Please sign in to comment.