[PATCH 2/3] ipcpd: Speed up enrolment of DHT

  • From: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Thu, 11 Oct 2018 01:44:29 +0200

The link-state algorithm will now quickly recalculate for link
additions (but not for removals, for stability). Upon notification of
a new link, the DHT will wait for a brief moment to enroll.

This reduces enrolment for large networks by some orders of magnitude.

Signed-off-by: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
---
 src/ipcpd/normal/dht.c            |   4 +
 src/ipcpd/normal/pol/link_state.c | 126 +++++++++++++++---------------
 2 files changed, 68 insertions(+), 62 deletions(-)

diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c
index 4064bf5..aa1909e 100644
--- a/src/ipcpd/normal/dht.c
+++ b/src/ipcpd/normal/dht.c
@@ -2729,6 +2729,10 @@ static void handle_event(void *       self,
                 pthread_t          thr;
                 struct join_info * inf;
                 struct conn *      c     = (struct conn *) o;
+                struct timespec    slack = {0, 10 * MILLION};
+
+                /* Give the pff some time to update for the new link. */
+                nanosleep(&slack, NULL);
 
                 switch(dht_get_state(dht)) {
                 case DHT_INIT:
diff --git a/src/ipcpd/normal/pol/link_state.c 
b/src/ipcpd/normal/pol/link_state.c
index e2e9eab..8db1a9c 100644
--- a/src/ipcpd/normal/pol/link_state.c
+++ b/src/ipcpd/normal/pol/link_state.c
@@ -374,7 +374,66 @@ static int lsdb_del_nb(uint64_t     addr,
         return -EPERM;
 }
 
-static void set_pff_modified(void)
+static int nbr_to_fd(uint64_t addr)
+{
+        struct list_head * p;
+
+        pthread_rwlock_rdlock(&ls.db_lock);
+
+        list_for_each(p, &ls.nbs) {
+                struct nb * nb = list_entry(p, struct nb, next);
+                if (nb->addr == addr && nb->type == NB_DT) {
+                        pthread_rwlock_unlock(&ls.db_lock);
+                        return nb->fd;
+                }
+        }
+
+        pthread_rwlock_unlock(&ls.db_lock);
+
+        return -1;
+}
+
+static void calculate_pff(struct routing_i * instance)
+{
+        int                fd;
+        struct list_head   table;
+        struct list_head * p;
+        struct list_head * q;
+        int                fds[PROG_MAX_FLOWS];
+
+        if (graph_routing_table(ls.graph, ls.routing_algo,
+                                ipcpi.dt_addr, &table))
+                return;
+
+        pff_lock(instance->pff);
+
+        pff_flush(instance->pff);
+
+        /* Calulcate forwarding table from routing table. */
+        list_for_each(p, &table) {
+                int                    i = 0;
+                struct routing_table * t =
+                        list_entry(p, struct routing_table, next);
+
+                list_for_each(q, &t->nhops) {
+                        struct nhop * n = list_entry(q, struct nhop, next);
+
+                        fd = nbr_to_fd(n->nhop);
+                        if (fd == -1)
+                                continue;
+
+                        fds[i++] = fd;
+                }
+
+                pff_add(instance->pff, t->dst, fds, i);
+        }
+
+        pff_unlock(instance->pff);
+
+        graph_free_routing_table(ls.graph, &table);
+}
+
+static void set_pff_modified(bool calc)
 {
         struct list_head * p;
 
@@ -385,6 +444,8 @@ static void set_pff_modified(void)
                 pthread_mutex_lock(&inst->lock);
                 inst->modified = true;
                 pthread_mutex_unlock(&inst->lock);
+                if (calc)
+                        calculate_pff(inst);
         }
         pthread_mutex_unlock(&ls.routing_i_lock);
 }
@@ -439,7 +500,7 @@ static int lsdb_add_link(uint64_t    src,
 
         pthread_rwlock_unlock(&ls.db_lock);
 
-        set_pff_modified();
+        set_pff_modified(true);
 
         return 0;
 }
@@ -462,7 +523,7 @@ static int lsdb_del_link(uint64_t src,
                         ls.db_len--;
 
                         pthread_rwlock_unlock(&ls.db_lock);
-                        set_pff_modified();
+                        set_pff_modified(false);
                         free(a);
                         return 0;
                 }
@@ -473,65 +534,6 @@ static int lsdb_del_link(uint64_t src,
         return -EPERM;
 }
 
-static int nbr_to_fd(uint64_t addr)
-{
-        struct list_head * p;
-
-        pthread_rwlock_rdlock(&ls.db_lock);
-
-        list_for_each(p, &ls.nbs) {
-                struct nb * nb = list_entry(p, struct nb, next);
-                if (nb->addr == addr && nb->type == NB_DT) {
-                        pthread_rwlock_unlock(&ls.db_lock);
-                        return nb->fd;
-                }
-        }
-
-        pthread_rwlock_unlock(&ls.db_lock);
-
-        return -1;
-}
-
-static void calculate_pff(struct routing_i * instance)
-{
-        int                fd;
-        struct list_head   table;
-        struct list_head * p;
-        struct list_head * q;
-        int                fds[PROG_MAX_FLOWS];
-
-        if (graph_routing_table(ls.graph, ls.routing_algo,
-                                ipcpi.dt_addr, &table))
-                return;
-
-        pff_lock(instance->pff);
-
-        pff_flush(instance->pff);
-
-        /* Calulcate forwarding table from routing table. */
-        list_for_each(p, &table) {
-                int                    i = 0;
-                struct routing_table * t =
-                        list_entry(p, struct routing_table, next);
-
-                list_for_each(q, &t->nhops) {
-                        struct nhop * n = list_entry(q, struct nhop, next);
-
-                        fd = nbr_to_fd(n->nhop);
-                        if (fd == -1)
-                                continue;
-
-                        fds[i++] = fd;
-                }
-
-                pff_add(instance->pff, t->dst, fds, i);
-        }
-
-        pff_unlock(instance->pff);
-
-        graph_free_routing_table(ls.graph, &table);
-}
-
 static void * periodic_recalc_pff(void * o)
 {
         bool               modified;
-- 
2.19.1


Other related posts:

  • » [PATCH 2/3] ipcpd: Speed up enrolment of DHT - Dimitri Staessens