]> git.proxmox.com Git - mirror_frr.git/blobdiff - pathd/path_pcep_controller.c
Merge pull request #9899 from Drumato/zebra-srv6-locator-detail-json-support
[mirror_frr.git] / pathd / path_pcep_controller.c
index 528dcc3539923d7eb66de22a06091401fb314f41..162c53590f9c14dfac207c7ba70e610d435f5bf7 100644 (file)
 
 #define MAX_RECONNECT_DELAY 120
 
-#define min(a, b)                                                              \
-       ({                                                                     \
-               __typeof__(a) _a = (a);                                        \
-               __typeof__(b) _b = (b);                                        \
-               _a <= _b ? _a : _b;                                            \
-       })
-
-
 /* Event handling data structures */
 enum pcep_ctrl_event_type {
        EV_UPDATE_PCC_OPTS = 1,
@@ -57,6 +49,7 @@ enum pcep_ctrl_event_type {
        EV_PCEPLIB_EVENT,
        EV_RESET_PCC_SESSION,
        EV_SEND_REPORT,
+       EV_SEND_ERROR,
        EV_PATH_REFINED
 };
 
@@ -328,6 +321,14 @@ int pcep_ctrl_send_report(struct frr_pthread *fpt, int pcc_id,
 }
 
 
+int pcep_ctrl_send_error(struct frr_pthread *fpt, int pcc_id,
+                        struct pcep_error *error)
+{
+       struct ctrl_state *ctrl_state = get_ctrl_state(fpt);
+       return send_to_thread(ctrl_state, pcc_id, EV_SEND_ERROR, 0, error);
+}
+
+
 /* ------------ Internal Functions Called from Main Thread ------------ */
 
 int pcep_ctrl_halt_cb(struct frr_pthread *fpt, void **res)
@@ -368,6 +369,13 @@ void pcep_thread_update_path(struct ctrl_state *ctrl_state, int pcc_id,
                     path);
 }
 
+void pcep_thread_initiate_path(struct ctrl_state *ctrl_state, int pcc_id,
+                              struct path *path)
+{
+       send_to_main(ctrl_state, pcc_id, PCEP_MAIN_EVENT_INITIATE_CANDIDATE,
+                    path);
+}
+
 void pcep_thread_remove_candidate_path_segments(struct ctrl_state *ctrl_state,
                                                struct pcc_state *pcc_state)
 {
@@ -743,6 +751,7 @@ int pcep_thread_event_handler(struct thread *thread)
        struct pcep_refine_path_event_data *refine_data = NULL;
 
        struct path *path_copy = NULL;
+       struct pcep_error *error = NULL;
 
        switch (type) {
        case EV_UPDATE_PCC_OPTS:
@@ -818,6 +827,13 @@ int pcep_thread_event_handler(struct thread *thread)
                refine_data = (struct pcep_refine_path_event_data *)payload;
                pcep_thread_path_refined_event(ctrl_state, refine_data);
                break;
+       case EV_SEND_ERROR:
+               assert(payload != NULL);
+               error = (struct pcep_error *)payload;
+               pcc_state = pcep_pcc_get_pcc_by_id(ctrl_state->pcc, pcc_id);
+               pcep_pcc_send_error(ctrl_state, pcc_state, error,
+                                   (bool)sub_type);
+               break;
        default:
                flog_warn(EC_PATH_PCEP_RECOVERABLE_INTERNAL_ERROR,
                          "Unexpected event received in controller thread: %u",
@@ -1054,7 +1070,7 @@ void remove_pcc_state(struct ctrl_state *ctrl_state,
 
 uint32_t backoff_delay(uint32_t max, uint32_t base, uint32_t retry_count)
 {
-       uint32_t a = min(max, base * (1 << retry_count));
+       uint32_t a = MIN(max, base * (1 << retry_count));
        uint64_t r = frr_weak_random(), m = RAND_MAX;
        uint32_t b = (a / 2) + (r * (a / 2)) / m;
        return b;