From: Christian Franke Date: Wed, 10 Oct 2018 13:43:01 +0000 (+0200) Subject: isisd: add send_hello_sched function X-Git-Tag: frr-7.1-dev~129^2~3 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a0a707ee6c2a546d4bb60ca7bf5655f856bc9e7d;p=mirror%2Ffrr.git isisd: add send_hello_sched function Add a function send_hello_sched so that the logic for scheduling a hello is not replicated inconsistently into different locations. Signed-off-by: Christian Franke --- diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 20094fb623..06385a4e1f 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -619,9 +619,7 @@ int isis_circuit_up(struct isis_circuit *circuit) if (!(circuit->is_type & level)) continue; - thread_add_event(master, send_hello_cb, - &circuit->level_arg[level - 1], 0, - &circuit->u.bc.t_send_lan_hello[level - 1]); + send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY); circuit->u.bc.lan_neighs[level - 1] = list_new(); thread_add_timer(master, isis_run_dr, @@ -637,9 +635,7 @@ int isis_circuit_up(struct isis_circuit *circuit) * for a ptp IF */ circuit->u.p2p.neighbor = NULL; - thread_add_event(master, send_hello_cb, - &circuit->level_arg[0], 0, - &circuit->u.p2p.t_send_p2p_hello); + send_hello_sched(circuit, 0, TRIGGERED_IIH_DELAY); } /* initializing PSNP timers */ diff --git a/isisd/isis_constants.h b/isisd/isis_constants.h index 1046b0014c..25eae06cb0 100644 --- a/isisd/isis_constants.h +++ b/isisd/isis_constants.h @@ -75,6 +75,8 @@ #define MIN_LSP_RETRANS_INTERVAL 5 /* Seconds */ +#define TRIGGERED_IIH_DELAY 50 /* msec */ + #define MIN_CSNP_INTERVAL 1 #define MAX_CSNP_INTERVAL 600 #define DEFAULT_CSNP_INTERVAL 10 diff --git a/isisd/isis_events.c b/isisd/isis_events.c index db197c7bea..4da23c5912 100644 --- a/isisd/isis_events.c +++ b/isisd/isis_events.c @@ -97,12 +97,7 @@ static void circuit_commence_level(struct isis_circuit *circuit, int level) 2 * circuit->hello_interval[level - 1], &circuit->u.bc.t_run_dr[level - 1]); - thread_add_timer(master, send_hello_cb, - &circuit->level_arg[level - 1], - isis_jitter(circuit->hello_interval[level - 1], - IIH_JITTER), - &circuit->u.bc.t_send_lan_hello[level - 1]); - + send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY); circuit->u.bc.lan_neighs[level - 1] = list_new(); } } diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index a2367c9213..900ce9f922 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -1742,7 +1742,7 @@ int send_hello(struct isis_circuit *circuit, int level) return retval; } -int send_hello_cb(struct thread *thread) +static int send_hello_cb(struct thread *thread) { struct isis_circuit_arg *arg = THREAD_ARG(thread); @@ -1755,12 +1755,9 @@ int send_hello_cb(struct thread *thread) if (circuit->circ_type == CIRCUIT_T_P2P) { circuit->u.p2p.t_send_p2p_hello = NULL; - send_hello(circuit, 1); - - thread_add_timer(master, send_hello_cb, arg, - isis_jitter(circuit->hello_interval[1], IIH_JITTER), - &circuit->u.p2p.t_send_p2p_hello); + send_hello_sched(circuit, ISIS_LEVEL1, + 1000 * circuit->hello_interval[1]); return ISIS_OK; } @@ -1783,13 +1780,56 @@ int send_hello_cb(struct thread *thread) int rv = send_hello(circuit, level); /* set next timer thread */ - thread_add_timer(master, send_hello_cb, arg, - isis_jitter(circuit->hello_interval[level - 1], IIH_JITTER), - &circuit->u.bc.t_send_lan_hello[level - 1]); - + send_hello_sched(circuit, level, 1000 * circuit->hello_interval[level - 1]); return rv; } +static void _send_hello_sched(struct isis_circuit *circuit, + struct thread **threadp, + int level, long delay) +{ + if (*threadp) { + if (thread_timer_remain_msec(*threadp) < (unsigned long)delay) + return; + + thread_cancel(*threadp); + } + + thread_add_timer_msec(master, send_hello_cb, + &circuit->level_arg[level - 1], + isis_jitter(delay, IIH_JITTER), + threadp); +} + +void send_hello_sched(struct isis_circuit *circuit, int level, long delay) +{ + if (circuit->circ_type == CIRCUIT_T_P2P) { + _send_hello_sched(circuit, &circuit->u.p2p.t_send_p2p_hello, + ISIS_LEVEL1, delay); + return; + } + + if (circuit->circ_type != CIRCUIT_T_BROADCAST) { + zlog_warn("%s: encountered unknown circuit type %d on %s", + __func__, circuit->circ_type, + circuit->interface->name); + return; + } + + for (int loop_level = ISIS_LEVEL1; loop_level <= ISIS_LEVEL2; loop_level++) { + if (!(loop_level & level)) + continue; + + _send_hello_sched( + circuit, + &circuit->u.bc.t_send_lan_hello[loop_level - 1], + loop_level, + delay + ); + } +} + + /* * Count the maximum number of lsps that can be accomodated by a given size. */ diff --git a/isisd/isis_pdu.h b/isisd/isis_pdu.h index f1cd6d4c1b..0fa3b2c7ab 100644 --- a/isisd/isis_pdu.h +++ b/isisd/isis_pdu.h @@ -208,7 +208,7 @@ int isis_receive(struct thread *thread); /* * Sending functions */ -int send_hello_cb(struct thread *thread); +void send_hello_sched(struct isis_circuit *circuit, int level, long delay); int send_csnp(struct isis_circuit *circuit, int level); int send_l1_csnp(struct thread *thread); int send_l2_csnp(struct thread *thread);