summaryrefslogtreecommitdiffstats
path: root/isisd/isis_dr.c
diff options
context:
space:
mode:
authorChristian Franke <chris@opensourcerouting.org>2018-10-10 11:16:39 +0200
committerChristian Franke <chris@opensourcerouting.org>2018-12-04 12:49:25 +0100
commit7c4f7aabc5866238584dfd9497ec6cef32311ca1 (patch)
tree23e5bd786dee59dfda8dbeaa4010e18ae55808b0 /isisd/isis_dr.c
parentisisd: Add level&circuit thread argument to circuit (diff)
downloadfrr-7c4f7aabc5866238584dfd9497ec6cef32311ca1.tar.xz
frr-7c4f7aabc5866238584dfd9497ec6cef32311ca1.zip
isisd: reduce code duplication for levels
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Diffstat (limited to 'isisd/isis_dr.c')
-rw-r--r--isisd/isis_dr.c77
1 files changed, 26 insertions, 51 deletions
diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c
index f71fe9555..b2ec8ae59 100644
--- a/isisd/isis_dr.c
+++ b/isisd/isis_dr.c
@@ -62,35 +62,28 @@ const char *isis_disflag2string(int disflag)
return NULL; /* not reached */
}
-int isis_run_dr_l1(struct thread *thread)
+int isis_run_dr(struct thread *thread)
{
- struct isis_circuit *circuit;
+ struct isis_circuit_arg *arg = THREAD_ARG(thread);
- circuit = THREAD_ARG(thread);
- assert(circuit);
-
- if (circuit->u.bc.run_dr_elect[0])
- zlog_warn("isis_run_dr(): run_dr_elect already set for l1");
-
- circuit->u.bc.t_run_dr[0] = NULL;
- circuit->u.bc.run_dr_elect[0] = 1;
+ assert(arg);
- return ISIS_OK;
-}
+ struct isis_circuit *circuit = arg->circuit;
+ int level = arg->level;
-int isis_run_dr_l2(struct thread *thread)
-{
- struct isis_circuit *circuit;
-
- circuit = THREAD_ARG(thread);
assert(circuit);
- if (circuit->u.bc.run_dr_elect[1])
- zlog_warn("isis_run_dr(): run_dr_elect already set for l2");
+ if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
+ zlog_warn("%s: scheduled for non broadcast circuit from %s:%d",
+ __func__, thread->schedfrom, thread->schedfrom_line);
+ return ISIS_WARNING;
+ }
+ if (circuit->u.bc.run_dr_elect[level - 1])
+ zlog_warn("isis_run_dr(): run_dr_elect already set for l%d", level);
- circuit->u.bc.t_run_dr[1] = NULL;
- circuit->u.bc.run_dr_elect[1] = 1;
+ circuit->u.bc.t_run_dr[level - 1] = NULL;
+ circuit->u.bc.run_dr_elect[level - 1] = 1;
return ISIS_OK;
}
@@ -241,12 +234,6 @@ int isis_dr_resign(struct isis_circuit *circuit, int level)
if (level == 1) {
memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
- THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
-
- thread_add_timer(master, isis_run_dr_l1, circuit,
- 2 * circuit->hello_interval[0],
- &circuit->u.bc.t_run_dr[0]);
-
thread_add_timer(master, send_l1_psnp, circuit,
isis_jitter(circuit->psnp_interval[level - 1],
PSNP_JITTER),
@@ -254,18 +241,20 @@ int isis_dr_resign(struct isis_circuit *circuit, int level)
} else {
memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
- THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
-
- thread_add_timer(master, isis_run_dr_l2, circuit,
- 2 * circuit->hello_interval[1],
- &circuit->u.bc.t_run_dr[1]);
-
thread_add_timer(master, send_l2_psnp, circuit,
isis_jitter(circuit->psnp_interval[level - 1],
PSNP_JITTER),
&circuit->t_send_psnp[1]);
}
+ THREAD_TIMER_OFF(circuit->t_send_csnp[level - 1]);
+
+ thread_add_timer(master, isis_run_dr,
+ &circuit->level_arg[level - 1],
+ 2 * circuit->hello_interval[level - 1],
+ &circuit->u.bc.t_run_dr[level - 1]);
+
+
thread_add_event(master, isis_event_dis_status_change, circuit, 0,
NULL);
@@ -281,14 +270,10 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
/* Lets keep a pause in DR election */
circuit->u.bc.run_dr_elect[level - 1] = 0;
- if (level == 1)
- thread_add_timer(master, isis_run_dr_l1, circuit,
- 2 * circuit->hello_interval[0],
- &circuit->u.bc.t_run_dr[0]);
- else
- thread_add_timer(master, isis_run_dr_l2, circuit,
- 2 * circuit->hello_interval[1],
- &circuit->u.bc.t_run_dr[1]);
+ thread_add_timer(master, isis_run_dr,
+ &circuit->level_arg[level - 1],
+ 2 * circuit->hello_interval[level - 1],
+ &circuit->u.bc.t_run_dr[level - 1]);
circuit->u.bc.is_dr[level - 1] = 1;
if (level == 1) {
@@ -307,11 +292,6 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
thread_cancel (circuit->t_send_l1_psnp); */
lsp_generate_pseudo(circuit, 1);
- THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
- thread_add_timer(master, isis_run_dr_l1, circuit,
- 2 * circuit->hello_interval[0],
- &circuit->u.bc.t_run_dr[0]);
-
thread_add_timer(master, send_l1_csnp, circuit,
isis_jitter(circuit->csnp_interval[level - 1],
CSNP_JITTER),
@@ -333,11 +313,6 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
thread_cancel (circuit->t_send_l1_psnp); */
lsp_generate_pseudo(circuit, 2);
- THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
- thread_add_timer(master, isis_run_dr_l2, circuit,
- 2 * circuit->hello_interval[1],
- &circuit->u.bc.t_run_dr[1]);
-
thread_add_timer(master, send_l2_csnp, circuit,
isis_jitter(circuit->csnp_interval[level - 1],
CSNP_JITTER),