diff options
| author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-03-03 10:31:03 +0000 | 
|---|---|---|
| committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2017-03-03 10:31:03 +0000 | 
| commit | b1b59cc4642faa99514f2288ba1bb5324a79850f (patch) | |
| tree | cec27d3c2064f0c0bcb564060d9d9012f819b22f /src/ipcpd/normal/pol | |
| parent | 46c2f9d5363cdff2d99cf1b1c4a41c5bf97d2c03 (diff) | |
| parent | a409fd81dfc6d22f9a287f15394b86490dea5273 (diff) | |
| download | ouroboros-b1b59cc4642faa99514f2288ba1bb5324a79850f.tar.gz ouroboros-b1b59cc4642faa99514f2288ba1bb5324a79850f.zip | |
Merged in sandervrijders/ouroboros/be-ae-conn (pull request #396)
ipcpd: normal: Refactor application entities and add neighbors struct
Diffstat (limited to 'src/ipcpd/normal/pol')
| -rw-r--r-- | src/ipcpd/normal/pol/complete.c | 189 | ||||
| -rw-r--r-- | src/ipcpd/normal/pol/complete.h | 29 | 
2 files changed, 82 insertions, 136 deletions
| diff --git a/src/ipcpd/normal/pol/complete.c b/src/ipcpd/normal/pol/complete.c index daf8c9bf..f84c3a23 100644 --- a/src/ipcpd/normal/pol/complete.c +++ b/src/ipcpd/normal/pol/complete.c @@ -1,7 +1,7 @@  /*   * Ouroboros - Copyright (C) 2016 - 2017   * - * Graph adjacency manager for IPC Process components + * Sets up a complete graph   *   *    Dimitri Staessens <dimitri.staessens@intec.ugent.be>   *    Sander Vrijders   <sander.vrijders@intec.ugent.be> @@ -20,35 +20,54 @@   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   */ -#define OUROBOROS_PREFIX "complete-graph-adjacency-manager" +#define OUROBOROS_PREFIX "complete"  #include <ouroboros/config.h> -#include <ouroboros/logs.h> -#include <ouroboros/list.h> -#include <ouroboros/qos.h> +#include <ouroboros/shared.h>  #include <ouroboros/rib.h> +#include <ouroboros/dev.h> +#include <ouroboros/logs.h> +#include <ouroboros/errno.h> +#include <ouroboros/cacep.h> -#include "ipcp.h" -#include "gam.h" +#include "neighbors.h" +#include "frct.h"  #include "ribconfig.h" +#include "ipcp.h" +#include "ae.h"  #include <string.h>  #include <stdlib.h>  #include <assert.h> -struct neighbor { -        struct list_head next; -        uint64_t         neighbor; +struct complete { +        struct nbs * nbs; +        struct ae *  ae; +        pthread_t    allocator; +        pthread_t    listener;  }; -struct complete { -        struct list_head neighbors; -        pthread_mutex_t  neighbors_lock; +static void * listener(void * o) +{ +        struct complete * complete; +        struct conn       conn; -        pthread_t        allocator; +        complete = (struct complete *) o; -        struct gam *     gam; -}; +        while (true) { +                if (connmgr_wait(complete->ae, &conn)) { +                        log_err("Error while getting next connection."); +                        continue; +                } + +                if (nbs_add(complete->nbs, conn)) { +                        log_err("Failed to add neighbor."); +                        continue; +                } +        } + +        return (void *) 0; +}  static void * allocator(void * o)  { @@ -56,10 +75,10 @@ static void * allocator(void * o)          ssize_t           len;          char **           children;          ssize_t           i; -        struct complete * complete = (struct complete *) o; +        struct complete * complete; +        struct conn       conn; -        assert(complete); -        assert(complete->gam); +        complete = (struct complete *) o;          qs.delay = 0;          qs.jitter = 0; @@ -67,8 +86,23 @@ static void * allocator(void * o)          /* FIXME: subscribe to members to keep the graph complete. */          len = rib_children("/" MEMBERS_NAME, &children);          for (i = 0; i < len; ++i) { -                if (strcmp(children[i], ipcpi.name) < 0) -                        gam_flow_alloc(complete->gam, children[i], qs); +                if (strcmp(children[i], ipcpi.name) < 0) { +                        if (connmgr_alloc(complete->ae, +                                          children[i], +                                          &qs, +                                          &conn)) { +                                log_warn("Failed to get a conn to neighbor."); +                                free(children[i]); +                                continue; +                        } + +                        if (nbs_add(complete->nbs, conn)) { +                                log_err("Failed to add neighbor."); +                                free(children[i]); +                                continue; +                        } + +                }                  free(children[i]);          } @@ -78,118 +112,41 @@ static void * allocator(void * o)          return (void *) 0;  } -void * complete_create(struct gam * gam) +void * complete_create(struct nbs * nbs, +                       struct ae *  ae)  {          struct complete * complete; -        assert(gam); -          complete = malloc(sizeof(*complete));          if (complete == NULL)                  return NULL; -        list_head_init(&complete->neighbors); -        complete->gam = gam; - -        if (pthread_mutex_init(&complete->neighbors_lock, NULL)) { -                free(complete); -                return NULL; -        } - -        return (void *) complete; -} - -int complete_start(void * o) -{ -        struct complete * complete = (struct complete *) o; - -        assert(complete); -        assert(complete->gam); +        complete->nbs = nbs; +        complete->ae = ae;          if (pthread_create(&complete->allocator, NULL, -                           allocator, (void *) complete)) { -                pthread_mutex_destroy(&complete->neighbors_lock); -                free(complete); -                return -1; -        } +                           allocator, (void *) complete)) +                return NULL; -        /* FIXME: Handle flooding of the flow allocator before detaching.*/ -        pthread_join(complete->allocator, NULL); +        if (pthread_create(&complete->listener, NULL, +                           listener, (void *) complete)) +                return NULL; -        return 0; +        return complete;  } -int complete_stop(void * o) +void complete_destroy(void * ops_o)  { -        (void) o; +        struct complete * complete; -        return 0; -} +        assert(ops_o); -void complete_destroy(void * o) -{ -        struct list_head * p = NULL; -        struct list_head * n = NULL; -        struct complete * complete = (struct complete *) o; - -        list_for_each_safe(p, n, &complete->neighbors) { -                struct neighbor * e = list_entry(p, struct neighbor, next); -                list_del(&e->next); -                free(e); -        } +        complete = (struct complete *) ops_o; -        pthread_mutex_destroy(&complete->neighbors_lock); +        pthread_cancel(complete->allocator); +        pthread_cancel(complete->listener); +        pthread_join(complete->allocator, NULL); +        pthread_join(complete->listener, NULL);          free(complete);  } - -int complete_accept_new_flow(void * o) -{ -        (void) o; - -        return 0; -} - -int complete_accept_flow(void *                    o, -                         qosspec_t                 qs, -                         const struct conn_info * info) -{ -        struct list_head * pos = NULL; -        struct neighbor * n; -        struct complete * complete = (struct complete *) o; - -        (void) qs; - -        assert(complete); - -        pthread_mutex_lock(&complete->neighbors_lock); - -        list_for_each(pos, &complete->neighbors) { -                struct neighbor * e = list_entry(pos, struct neighbor, next); -                /* FIXME: figure out union type and check name or address */ -                if (e->neighbor == info->addr) { -                        pthread_mutex_unlock(&complete->neighbors_lock); -                        return -1; -                } - -                assert(complete); -                assert(&complete->neighbors_lock); -                assert(pos->nxt); -        } - -        n = malloc(sizeof(*n)); -        if (n == NULL) { -                pthread_mutex_unlock(&complete->neighbors_lock); -                return -1; -        } - -        list_head_init(&n->next); - -        n->neighbor = info->addr; - -        list_add(&n->next, &complete->neighbors); - -        pthread_mutex_unlock(&complete->neighbors_lock); - -        return 0; -} diff --git a/src/ipcpd/normal/pol/complete.h b/src/ipcpd/normal/pol/complete.h index 8fe1437f..40aca69d 100644 --- a/src/ipcpd/normal/pol/complete.h +++ b/src/ipcpd/normal/pol/complete.h @@ -1,7 +1,7 @@  /*   * Ouroboros - Copyright (C) 2016 - 2017   * - * Graph adjacency manager for IPC Process components + * Sets up a complete graph   *   *    Dimitri Staessens <dimitri.staessens@intec.ugent.be>   *    Sander Vrijders   <sander.vrijders@intec.ugent.be> @@ -23,30 +23,19 @@  #ifndef OUROBOROS_IPCPD_NORMAL_POL_COMPLETE_H  #define OUROBOROS_IPCPD_NORMAL_POL_COMPLETE_H -#include "gam.h" -#include "pol-gam-ops.h" - -void * complete_create(struct gam * instance); - -void   complete_destroy(void * o); +#include <ouroboros/irm_config.h> +#include <ouroboros/qos.h> -int    complete_start(void * o); - -int    complete_stop(void * o); +#include "pol-gam-ops.h" -int    complete_accept_new_flow(void * o); +void * complete_create(struct nbs * nbs, +                       struct ae *  ae); -int    complete_accept_flow(void *                   o, -                            qosspec_t                qs, -                            const struct conn_info * info); +void   complete_destroy(void * ops_o);  struct pol_gam_ops complete_ops = { -        .create          = complete_create, -        .destroy         = complete_destroy, -        .start           = complete_start, -        .stop            = complete_stop, -        .accept_new_flow = complete_accept_new_flow, -        .accept_flow     = complete_accept_flow +        .create   = complete_create, +        .destroy  = complete_destroy  };  #endif /* OUROBOROS_IPCPD_NORMAL_POL_COMPLETE_H */ | 
