diff options
| author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-10-31 19:47:45 +0100 | 
|---|---|---|
| committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-11-01 09:38:20 +0100 | 
| commit | 2d88fdaaa018d607eca5ce057dfbdf41beb6125b (patch) | |
| tree | f5085671663fa6798065d283619b6e8997e0f51b /src/ipcpd/normal | |
| parent | 72eb9eed1284643db20c45ef82365fa54fd0ef1c (diff) | |
| download | ouroboros-2d88fdaaa018d607eca5ce057dfbdf41beb6125b.tar.gz ouroboros-2d88fdaaa018d607eca5ce057dfbdf41beb6125b.zip  | |
ipcpd: normal: Add policy for obtaining a flat address
This adds a policy for obtaining a flat address, and thus also the
infrastructure for policies in the IPCP. The IPCP should check if the
address is available; this is currently not there yet.
Diffstat (limited to 'src/ipcpd/normal')
| -rw-r--r-- | src/ipcpd/normal/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ipcpd/normal/addr_auth.c | 78 | ||||
| -rw-r--r-- | src/ipcpd/normal/addr_auth.h | 39 | ||||
| -rw-r--r-- | src/ipcpd/normal/flat.c | 63 | ||||
| -rw-r--r-- | src/ipcpd/normal/flat.h | 30 | ||||
| -rw-r--r-- | src/ipcpd/normal/ribmgr.c | 48 | ||||
| -rw-r--r-- | src/ipcpd/normal/ribmgr.h | 3 | ||||
| -rw-r--r-- | src/ipcpd/normal/shm_pci.h | 1 | ||||
| -rw-r--r-- | src/ipcpd/normal/static_info.proto | 2 | 
9 files changed, 251 insertions, 15 deletions
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index 151721a2..08c5c691 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -22,8 +22,10 @@ protobuf_generate_c(FLOW_ALLOC_SRCS FLOW_ALLOC_HDRS  set(SOURCE_FILES          # Add source files here +        addr_auth.c          cdap_request.c          crc32.c +        flat.c          fmgr.c          frct.c          main.c diff --git a/src/ipcpd/normal/addr_auth.c b/src/ipcpd/normal/addr_auth.c new file mode 100644 index 00000000..71bcfafa --- /dev/null +++ b/src/ipcpd/normal/addr_auth.c @@ -0,0 +1,78 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Address authority + * + *    Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define OUROBOROS_PREFIX "addr_auth" + +#include <ouroboros/config.h> +#include <ouroboros/logs.h> + +#include "addr_auth.h" +#include "flat.h" + +#include <stdlib.h> +#include <assert.h> + +struct addr_auth * addr_auth_create(enum pol_addr_auth type) +{ +        struct addr_auth * tmp; + +        tmp = malloc(sizeof(*tmp)); +        if (tmp == NULL) +                return NULL; + +        switch (type) { +        case FLAT_RANDOM: +                if (flat_init()) { +                        free(tmp); +                        return NULL; +                } + +                tmp->address = flat_address; +                tmp->type = type; +                break; +        default: +                LOG_ERR("Unknown address authority type."); +                free(tmp); +                return NULL; +        } + +        return tmp; +} + +int addr_auth_destroy(struct addr_auth * instance) +{ +        assert(instance); + +        switch (instance->type) { +        case FLAT_RANDOM: +                if (flat_fini()) { +                        return -1; +                } +                break; +        default: +                LOG_ERR("Unknown address authority type."); +        } + +        free(instance); + +        return 0; +} diff --git a/src/ipcpd/normal/addr_auth.h b/src/ipcpd/normal/addr_auth.h new file mode 100644 index 00000000..6881dd55 --- /dev/null +++ b/src/ipcpd/normal/addr_auth.h @@ -0,0 +1,39 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Address authority + * + *    Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef OUROBOROS_ADDR_AUTH +#define OUROBOROS_ADDR_AUTH + +#include <ouroboros/irm_config.h> + +#include <stdint.h> + +struct addr_auth { +        enum pol_addr_auth type; +        uint64_t (* address)(void); +}; + +struct addr_auth * addr_auth_create(enum pol_addr_auth type); + +int                addr_auth_destroy(struct addr_auth * instance); + +#endif /* OUROBOROS_ADDR_AUTH */ diff --git a/src/ipcpd/normal/flat.c b/src/ipcpd/normal/flat.c new file mode 100644 index 00000000..8caa85b4 --- /dev/null +++ b/src/ipcpd/normal/flat.c @@ -0,0 +1,63 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Policy for flat addresses in a distributed way + * + *    Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define OUROBOROS_PREFIX "flat-addr-auth" + +#include <ouroboros/config.h> +#include <ouroboros/logs.h> + +#include <time.h> +#include <stdlib.h> +#include <math.h> + +#include "shm_pci.h" +#include "ribmgr.h" + +int flat_init(void) +{ +        srand(time(NULL)); + +        return 0; +} + +int flat_fini(void) +{ +        return 0; +} + +uint64_t flat_address(void) +{ +        uint64_t addr; +        uint64_t max_addr; +        struct dt_const * dtc; + +        dtc = ribmgr_dt_const(); +        if (dtc == NULL) +                return INVALID_ADDR; + +        max_addr = (1 << (8 * dtc->addr_size)) - 1; +        addr = (rand() % (max_addr - 1)) + 1; + +        /* FIXME: Add check for uniqueness of address */ + +        return addr; +} diff --git a/src/ipcpd/normal/flat.h b/src/ipcpd/normal/flat.h new file mode 100644 index 00000000..51cb511b --- /dev/null +++ b/src/ipcpd/normal/flat.h @@ -0,0 +1,30 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Policy for flat addresses in a distributed way + * + *    Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef OUROBOROS_FLAT +#define OUROBOROS_FLAT + +int      flat_init(void); +int      flat_fini(void); +uint64_t flat_address(void); + +#endif /* OUROBOROS_FLAT */ diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index cd12bcc6..295a6724 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -34,6 +34,7 @@  #include <string.h>  #include <errno.h> +#include "addr_auth.h"  #include "ribmgr.h"  #include "dt_const.h"  #include "frct.h" @@ -53,15 +54,17 @@ struct mgmt_flow {  };  struct { -        struct dt_const  dtc; +        struct dt_const    dtc; -        uint32_t         address; +        uint64_t           address; -        struct list_head flows; -        pthread_rwlock_t flows_lock; +        struct list_head   flows; +        pthread_rwlock_t   flows_lock; -        struct list_head cdap_reqs; -        pthread_mutex_t  cdap_reqs_lock; +        struct list_head   cdap_reqs; +        pthread_mutex_t    cdap_reqs_lock; + +        struct addr_auth * addr_auth;  } rib;  /* Call while holding cdap_reqs_lock */ @@ -153,6 +156,9 @@ int ribmgr_fini()          }          pthread_rwlock_unlock(&rib.flows_lock); +        if (rib.addr_auth != NULL) +                addr_auth_destroy(rib.addr_auth); +          pthread_mutex_destroy(&rib.cdap_reqs_lock);          pthread_rwlock_destroy(&rib.flows_lock); @@ -247,7 +253,18 @@ int ribmgr_cdap_write(struct cdap * instance,                  rib.dtc.min_pdu_size = msg->min_pdu_size;                  rib.dtc.max_pdu_size = msg->max_pdu_size; -                rib.address = msg->address; +                rib.addr_auth = addr_auth_create(msg->addr_auth_type); +                if (rib.addr_auth == NULL) { +                        ipcp_set_state(IPCP_INIT); +                        pthread_rwlock_unlock(&ipcpi.state_lock); +                        cdap_send_reply(instance, invoke_id, -1, NULL, 0); +                        static_info_msg__free_unpacked(msg, NULL); +                        LOG_ERR("Failed to create address authority"); +                        return -1; +                } + +                rib.address = rib.addr_auth->address(); +                LOG_DBG("IPCP has address %lu", rib.address);                  if (frct_init()) {                          ipcp_set_state(IPCP_INIT); @@ -333,9 +350,7 @@ int ribmgr_cdap_start(struct cdap * instance,                  stat_info.has_chk = rib.dtc.has_chk;                  stat_info.min_pdu_size  = rib.dtc.min_pdu_size;                  stat_info.max_pdu_size = rib.dtc.max_pdu_size; - -                /* FIXME: Hand out an address. */ -                stat_info.address = 0; +                stat_info.addr_auth_type = rib.addr_auth->type;                  len = static_info_msg__get_packed_size(&stat_info);                  if (len == 0) { @@ -544,11 +559,18 @@ int ribmgr_bootstrap(struct dif_config * conf)          rib.dtc.min_pdu_size = conf->min_pdu_size;          rib.dtc.max_pdu_size = conf->max_pdu_size; -        /* FIXME: Set correct address. */ -        rib.address = 0; +        rib.addr_auth = addr_auth_create(conf->addr_auth_type); +        if (rib.addr_auth == NULL) { +                LOG_ERR("Failed to create address authority."); +                return -1; +        } + +        rib.address = rib.addr_auth->address(); +        LOG_DBG("IPCP has address %lu", rib.address);          if (frct_init()) {                  LOG_ERR("Failed to initialize FRCT."); +                addr_auth_destroy(rib.addr_auth);                  return -1;          } @@ -562,7 +584,7 @@ struct dt_const * ribmgr_dt_const()          return &(rib.dtc);  } -uint32_t ribmgr_address() +uint64_t ribmgr_address()  {          return rib.address;  } diff --git a/src/ipcpd/normal/ribmgr.h b/src/ipcpd/normal/ribmgr.h index 01bfcb40..556a399f 100644 --- a/src/ipcpd/normal/ribmgr.h +++ b/src/ipcpd/normal/ribmgr.h @@ -24,6 +24,7 @@  #define OUROBOROS_IPCP_RIBMGR_H  #include <ouroboros/irm_config.h> +#include <ouroboros/utils.h>  #include "dt_const.h" @@ -43,6 +44,6 @@ int               ribmgr_bootstrap(struct dif_config * conf);   */  struct dt_const * ribmgr_dt_const(void); -uint32_t          ribmgr_address(void); +uint64_t          ribmgr_address(void);  #endif diff --git a/src/ipcpd/normal/shm_pci.h b/src/ipcpd/normal/shm_pci.h index 2836737c..6e955d84 100644 --- a/src/ipcpd/normal/shm_pci.h +++ b/src/ipcpd/normal/shm_pci.h @@ -34,6 +34,7 @@  typedef uint32_t cep_id_t;  #define INVALID_CEP_ID 0 +#define INVALID_ADDR 0  struct pci {          uint8_t  pdu_type; diff --git a/src/ipcpd/normal/static_info.proto b/src/ipcpd/normal/static_info.proto index 04824a38..65a53377 100644 --- a/src/ipcpd/normal/static_info.proto +++ b/src/ipcpd/normal/static_info.proto @@ -7,5 +7,5 @@ message static_info_msg {          required bool   has_chk         = 6;          required uint32 min_pdu_size    = 7;          required uint32 max_pdu_size    = 8; -        required uint32 address         = 9; +        required uint32 addr_auth_type  = 9;  }
\ No newline at end of file  | 
