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 <chris@opensourcerouting.org>
This commit is contained in:
Christian Franke 2018-10-10 15:43:01 +02:00
parent 78ca034252
commit a0a707ee6c
5 changed files with 56 additions and 23 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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();
}
}

View File

@ -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.
*/

View File

@ -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);