diff options
author | dimitri staessens <[email protected]> | 2016-07-14 19:47:02 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-07-14 19:47:02 +0200 |
commit | 71956f22abec7bb15f6bfc52b4168ff85499eea1 (patch) | |
tree | 36340fda47cd84ada6fb1357c1c5c0677289f0e3 /src/ipcpd/normal | |
parent | 7ca7525221375996383951d90bbdca4ad995f965 (diff) | |
parent | d17c8a4924e0417d5385f933da1bcc75aad9b818 (diff) | |
download | ouroboros-71956f22abec7bb15f6bfc52b4168ff85499eea1.tar.gz ouroboros-71956f22abec7bb15f6bfc52b4168ff85499eea1.zip |
Merged in sandervrijders/ouroboros/be (pull request #172)
ipcpd: normal: Establish N-1 management flows
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r-- | src/ipcpd/normal/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/ipcpd/normal/dt_const.h | 9 | ||||
-rw-r--r-- | src/ipcpd/normal/fmgr.c | 242 | ||||
-rw-r--r-- | src/ipcpd/normal/fmgr.h | 8 | ||||
-rw-r--r-- | src/ipcpd/normal/frct.c | 67 | ||||
-rw-r--r-- | src/ipcpd/normal/frct.h | 6 | ||||
-rw-r--r-- | src/ipcpd/normal/main.c | 14 | ||||
-rw-r--r-- | src/ipcpd/normal/ribmgr.c | 62 | ||||
-rw-r--r-- | src/ipcpd/normal/ribmgr.h | 12 |
9 files changed, 407 insertions, 16 deletions
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index 5aefeabb..7e6d9266 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -17,6 +17,9 @@ SET(IPCP_NORMAL_TARGET ipcpd-normal CACHE STRING "IPCP_NORMAL_TARGET") set(SOURCE_FILES # Add source files here main.c + fmgr.c + frct.c + ribmgr.c ) add_executable (ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES}) diff --git a/src/ipcpd/normal/dt_const.h b/src/ipcpd/normal/dt_const.h index bc0c1466..65cde5f7 100644 --- a/src/ipcpd/normal/dt_const.h +++ b/src/ipcpd/normal/dt_const.h @@ -24,19 +24,14 @@ #ifndef IPCP_DT_CONST_H #define IPCP_DT_CONST_H -#include "ouroboros/common.h" +#include <stdint.h> -struct ipcp_dtp_const { - /* sizes in octets */ +struct dt_const { uint8_t addr_size; uint8_t cep_id_size; uint8_t pdu_length_size; uint8_t seqno_size; uint8_t qos_id_size; - /* uint8_t ctrl_sqnum_sz; is this in the spec?? */ -}; - -struct ipcp_dup_const { uint8_t ttl_size; uint8_t chk_size; }; diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c new file mode 100644 index 00000000..9521805f --- /dev/null +++ b/src/ipcpd/normal/fmgr.c @@ -0,0 +1,242 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Flow manager of the IPC Process + * + * Sander Vrijders <[email protected]> + * + * 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 "flow-manager" + +#include <ouroboros/config.h> +#include <ouroboros/logs.h> +#include <ouroboros/dev.h> +#include <ouroboros/list.h> + +#include <stdlib.h> +#include <stdbool.h> +#include <pthread.h> +#include <string.h> + +#include "fmgr.h" +#include "ribmgr.h" +#include "frct.h" + +struct n_1_flow { + int fd; + char * ae_name; + struct list_head next; +}; + +struct fmgr { + pthread_t listen_thread; + + struct list_head n_1_flows; + pthread_mutex_t n_1_flows_lock; + +} * instance = NULL; + +static int add_n_1_fd(int fd, + char * ae_name) +{ + struct n_1_flow * tmp; + + if (ae_name == NULL) + return -1; + + tmp = malloc(sizeof(*tmp)); + if (tmp == NULL) + return -1; + + tmp->fd = fd; + tmp->ae_name = ae_name; + + pthread_mutex_lock(&instance->n_1_flows_lock); + list_add(&tmp->next, &instance->n_1_flows); + pthread_mutex_unlock(&instance->n_1_flows_lock); + + return 0; +} + +static void * fmgr_listen(void * o) +{ + int fd; + char * ae_name; + + while (true) { + fd = flow_accept(&ae_name); + if (fd < 0) { + LOG_ERR("Failed to accept flow."); + continue; + } + + if (!(strcmp(ae_name, MGMT_AE) == 0 || + strcmp(ae_name, DT_AE) == 0)) { + if (flow_alloc_resp(fd, -1)) + LOG_ERR("Failed to reply to flow allocation."); + flow_dealloc(fd); + continue; + } + + if (flow_alloc_resp(fd, 0)) { + LOG_ERR("Failed to reply to flow allocation."); + flow_dealloc(fd); + continue; + } + + LOG_DBG("Accepted new flow allocation request for AE %s.", + ae_name); + + if (strcmp(ae_name, MGMT_AE) == 0 && + ribmgr_mgmt_flow(fd)) { + LOG_ERR("Failed to hand file descriptor to RIB."); + flow_dealloc(fd); + continue; + } + + if (strcmp(ae_name, DT_AE) == 0 && + frct_dt_flow(fd)) { + LOG_ERR("Failed to hand file descriptor to FRCT."); + flow_dealloc(fd); + continue; + } + + if (add_n_1_fd(fd, ae_name)) { + LOG_ERR("Failed to add file descriptor to list."); + flow_dealloc(fd); + continue; + } + } + + return (void *) 0; +} + +int fmgr_init() +{ + instance = malloc(sizeof(*instance)); + if (instance == NULL) { + return -1; + } + + INIT_LIST_HEAD(&instance->n_1_flows); + + pthread_mutex_init(&instance->n_1_flows_lock, NULL); + + pthread_create(&instance->listen_thread, + NULL, + fmgr_listen, + NULL); + + return 0; +} + +int fmgr_fini() +{ + struct list_head * pos = NULL; + + pthread_cancel(instance->listen_thread); + + pthread_join(instance->listen_thread, + NULL); + + list_for_each(pos, &instance->n_1_flows) { + struct n_1_flow * e = + list_entry(pos, struct n_1_flow, next); + if (e->ae_name != NULL) + free(e->ae_name); + flow_dealloc(e->fd); + } + + free(instance); + + return 0; +} + +int fmgr_mgmt_flow(char * dst_name) +{ + int fd; + int result; + + /* FIXME: Request retransmission. */ + fd = flow_alloc(dst_name, MGMT_AE, NULL); + if (fd < 0) { + LOG_ERR("Failed to allocate flow to %s", dst_name); + return -1; + } + + result = flow_alloc_res(fd); + if (result < 0) { + LOG_ERR("Result of flow allocation to %s is %d", + dst_name, result); + return -1; + } + + if (ribmgr_mgmt_flow(fd)) { + LOG_ERR("Failed to hand file descriptor to RIB manager"); + flow_dealloc(fd); + return -1; + } + + if (add_n_1_fd(fd, strdup(MGMT_AE))) { + LOG_ERR("Failed to add file descriptor to list."); + flow_dealloc(fd); + return -1; + } + + return 0; +} + +int fmgr_dt_flow(char * dst_name) +{ + LOG_MISSING; + + return -1; +} + +int fmgr_flow_alloc(pid_t n_api, + int port_id, + char * dst_ap_name, + char * src_ae_name, + enum qos_cube qos) +{ + LOG_MISSING; + + return -1; +} + +int fmgr_flow_alloc_resp(pid_t n_api, + int port_id, + int response) +{ + LOG_MISSING; + + return -1; +} + +int fmgr_flow_dealloc(int port_id) +{ + LOG_MISSING; + + return -1; +} + +int fmgr_flow_msg() +{ + LOG_MISSING; + + return -1; +} diff --git a/src/ipcpd/normal/fmgr.h b/src/ipcpd/normal/fmgr.h index 8a335e77..867cbff6 100644 --- a/src/ipcpd/normal/fmgr.h +++ b/src/ipcpd/normal/fmgr.h @@ -23,9 +23,15 @@ #ifndef OUROBOROS_IPCP_FMGR_H #define OUROBOROS_IPCP_FMGR_H -#include <ouroboros/qos.h> #include <ouroboros/shared.h> +#include <unistd.h> +#include <stdint.h> +#include <sys/types.h> + +#define MGMT_AE "Management" +#define DT_AE "Data transfer" + int fmgr_init(); int fmgr_fini(); diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c new file mode 100644 index 00000000..9ea2fd48 --- /dev/null +++ b/src/ipcpd/normal/frct.c @@ -0,0 +1,67 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * The Flow and Retransmission control component + * + * Sander Vrijders <[email protected]> + * + * 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 "flow-rtx-control" + +#include <ouroboros/logs.h> + +#include "frct.h" + +struct frct_i { + +}; + +int frct_init(struct dt_const * dt_const) +{ + LOG_MISSING; + + return -1; +} + +int frct_fini() +{ + LOG_MISSING; + + return -1; +} + +struct frct_i * frct_i_create(int port_id, + enum qos_cube cube) +{ + LOG_MISSING; + + return NULL; +} + +int frct_i_destroy(struct frct_i * instance) +{ + LOG_MISSING; + + return -1; +} + +int frct_dt_flow(int fd) +{ + LOG_MISSING; + + return -1; +} diff --git a/src/ipcpd/normal/frct.h b/src/ipcpd/normal/frct.h index 2ac66652..07fd2c65 100644 --- a/src/ipcpd/normal/frct.h +++ b/src/ipcpd/normal/frct.h @@ -23,9 +23,13 @@ #ifndef OUROBOROS_IPCP_FRCT_H #define OUROBOROS_IPCP_FRCT_H +#include <ouroboros/shared.h> + +#include "dt_const.h" + struct frct_i; -int frct_init(struct dt_const * const); +int frct_init(struct dt_const * dt_const); int frct_fini(); struct frct_i * frct_i_create(int port_id, diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 7ffd1c48..3433b116 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -1,11 +1,21 @@ -#define OUROBOROS_PREFIX "ipcp" +#define OUROBOROS_PREFIX "normal-ipcp" #include <ouroboros/logs.h> #include <stdbool.h> +#include "fmgr.h" +#include "ribmgr.h" + int main() { - LOG_DBG("Test of the IPCP"); + if (fmgr_init()) { + return -1; + } + + if (ribmgr_init()) { + fmgr_fini(); + return -1; + } while (true) { diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c new file mode 100644 index 00000000..39723e5a --- /dev/null +++ b/src/ipcpd/normal/ribmgr.c @@ -0,0 +1,62 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * RIB manager of the IPC Process + * + * Sander Vrijders <[email protected]> + * + * 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 "rib-manager" + +#include <ouroboros/logs.h> + +#include "ribmgr.h" + +int ribmgr_init() +{ + LOG_MISSING; + + return -1; +} + +int ribmgr_fini() +{ + LOG_MISSING; + + return -1; +} + +int ribmgr_mgmt_flow(int fd) +{ + LOG_MISSING; + + return -1; +} + +int ribmgr_bootstrap(struct dif_config * conf) +{ + LOG_MISSING; + + return -1; +} + +int ribmgr_fmgr_msg() +{ + LOG_MISSING; + + return -1; +} diff --git a/src/ipcpd/normal/ribmgr.h b/src/ipcpd/normal/ribmgr.h index b39aba63..335189f9 100644 --- a/src/ipcpd/normal/ribmgr.h +++ b/src/ipcpd/normal/ribmgr.h @@ -23,13 +23,15 @@ #ifndef OUROBOROS_IPCP_RIBMGR_H #define OUROBOROS_IPCP_RIBMGR_H -int rib_init(); -int rib_fini(); +#include <ouroboros/irm_config.h> -int rib_mgmt_flow(int fd); -int rib_bootstrap(struct dif_config * conf); +int ribmgr_init(); +int ribmgr_fini(); + +int ribmgr_mgmt_flow(int fd); +int ribmgr_bootstrap(struct dif_config * conf); /* Called by Flow Manager (param of type fmgr_msg_t) */ -int rib_fmgr_msg(); +int ribmgr_fmgr_msg(); #endif |