diff options
| author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2018-10-11 01:44:29 +0200 | 
|---|---|---|
| committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-10-11 13:42:38 +0200 | 
| commit | 9b8d2830250ecffb298f6c72196cffb94991f4d1 (patch) | |
| tree | 8887ddf242f0022b04944704d08508d3b27ec6bb /src/ipcpd | |
| parent | ebf4e472b0065677cb3caf2b67b4bf31fd1f7343 (diff) | |
| download | ouroboros-9b8d2830250ecffb298f6c72196cffb94991f4d1.tar.gz ouroboros-9b8d2830250ecffb298f6c72196cffb94991f4d1.zip | |
ipcpd: Speed up enrolment of DHT
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@ugent.be>
Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/ipcpd')
| -rw-r--r-- | src/ipcpd/normal/dht.c | 4 | ||||
| -rw-r--r-- | 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 4064bf5c..aa1909e9 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 e2e9eab5..8db1a9c5 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; | 
