]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: add send_hello_sched function
authorChristian Franke <chris@opensourcerouting.org>
Wed, 10 Oct 2018 13:43:01 +0000 (15:43 +0200)
committerChristian Franke <chris@opensourcerouting.org>
Tue, 4 Dec 2018 15:13:24 +0000 (16:13 +0100)
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>
isisd/isis_circuit.c
isisd/isis_constants.h
isisd/isis_events.c
isisd/isis_pdu.c
isisd/isis_pdu.h

index 20094fb6236968c39e5961167e135bd0f5d96d97..06385a4e1f5d7e47d112f988a4e1f2393b936abe 100644 (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 */
index 1046b0014c4fee743c543412f4aee8a75143b9bf..25eae06cb0af0d473957bb1232fd2ac486aded13 100644 (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
index db197c7beadbf51f90e05335da2aed945cbe1ff9..4da23c591261a1b98588830877a98149003d4d39 100644 (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();
        }
 }
index a2367c9213b50546e4ff1ad23aa5d59b99bde70a..900ce9f922e9a6dd5bd08f92b3797a83929053f7 100644 (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.
  */
index f1cd6d4c1b8cb8c700c85103d6b8863ccd712d72..0fa3b2c7ab06a40a83faaaa76aa5551746739dca 100644 (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);