From eb9f44379d5316e7f7e9311d7a66d2041eca743a Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 7 May 2016 16:11:09 +0200 Subject: irmd: flow allocation and fast path This commit has a first implementation of flow allocation (the "slow path") and read/write (the "fast path") for ouroboros. It provides basic but unstable communications over the shared memory. It required a lot of changes all over the stack, and fixes a number of previously undetected issues. This PR still need heavy revision regarding data model, locking and cleanup. lib/dev: modifications to the API. It now uses an ap_init() call to set the AP name and sets the Instance ID to the pid of the process. It also binds the AP to the shared memory and creates tables for mappings in the fast path. A call to ap_fini() releases the resources. lib/shm_ap_rbuff: added ring buffer for data exchange between processes in the fast path. It passes an index in the shm_du_map. lib/shm_du_map: rewrote API to work with calls from dev.c. Garbage collector added. Tests updated to new API. ipcpd/ipcp-data: removed everything related to flows, as these are universal for all ap's and kept in ap_data (dev.c), or similar structs for shim ipcps. shim-udp: added flow allocator and read/write functions and shm elements. irmd: revised data model and structures necessary for flow allocation. tools: echo updated to new dev.h API. messaging system was updated to comply with new flow allocation messages. All exchanges use pid and port_id to bootstrap the fast path. --- include/ouroboros/CMakeLists.txt | 1 + include/ouroboros/dev.h | 19 +++++++++------ include/ouroboros/flow.h | 43 +++++++++++++++++++++++++++++++++ include/ouroboros/ipcp.h | 4 +++- include/ouroboros/shm_ap_rbuff.h | 52 ++++++++++++++++++++++++++++++++++++++++ include/ouroboros/shm_du_map.h | 21 +++++++++++----- include/ouroboros/utils.h | 1 + 7 files changed, 127 insertions(+), 14 deletions(-) create mode 100644 include/ouroboros/flow.h create mode 100644 include/ouroboros/shm_ap_rbuff.h (limited to 'include') diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index cfa299ca..6a247e8e 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -15,6 +15,7 @@ set(HEADER_FILES irm.h list.h logs.h + shm_ap_rbuff.h shm_du_map.h sockets.h utils.h diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index 414273ef..e857e211 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -24,29 +24,34 @@ #define OUROBOROS_DEV_H #include +#include #define UNKNOWN_AP "__UNKNOWN_AP__" #define UNKNOWN_AE "__UNKNOWN_AE__" +/* These calls should be removed once we write the ouroboros OS. */ +int ap_init(char * ap_name); +void ap_fini(); + /* Returns file descriptor */ -int ap_reg(char * ap_name, char ** difs, size_t difs_size); -int ap_unreg(char * ap_name, char ** difs, size_t difs_size); +int ap_reg(char ** difs, size_t difs_size); +int ap_unreg(char ** difs, size_t difs_size); /* Returns file descriptor (> 0) and client name(s) */ -int flow_accept(int fd, char * ap_name, char * ae_name); +int flow_accept(int fd, char ** ap_name, char ** ae_name); int flow_alloc_resp(int fd, int result); /* Returns file descriptor */ -int flow_alloc(char * dst_ap_name, char * src_ap_name, - char * src_ae_name, struct qos_spec * qos, - int oflags); +int flow_alloc(char * dst_name, + char * src_ae_name, + struct qos_spec * qos); /* If flow is accepted returns a value > 0 */ int flow_alloc_res(int fd); int flow_dealloc(int fd); /* Wraps around fnctl */ -int flow_cntl(int fd, int oflags); +int flow_cntl(int fd, int cmd, int oflags); ssize_t flow_write(int fd, void * buf, size_t count); ssize_t flow_read(int fd, void * buf, size_t count); diff --git a/include/ouroboros/flow.h b/include/ouroboros/flow.h new file mode 100644 index 00000000..ff9085f7 --- /dev/null +++ b/include/ouroboros/flow.h @@ -0,0 +1,43 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Flows + * + * Dimitri Staessens + * + * 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_FLOW_H +#define OUROBOROS_FLOW_H + +/* same values as fcntl.h */ +#define FLOW_O_RDONLY 00000000 +#define FLOW_O_WRONLY 00000001 +#define FLOW_O_RDWR 00000002 +#define FLOW_O_ACCMODE 00000003 + +#define FLOW_O_NONBLOCK 00004000 +#define FLOW_O_DEFAULT 00000002 + +#define FLOW_O_INVALID (FLOW_O_WRONLY | FLOW_O_RDWR) + +enum flow_state { + FLOW_NULL = 0, + FLOW_ALLOCATED, + FLOW_PENDING +}; + +#endif /* OUROBOROS_FLOW_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index e3c17bda..570eca67 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -61,13 +61,15 @@ int ipcp_name_unreg(pid_t pid, int ipcp_flow_alloc(pid_t pid, uint32_t port_id, + pid_t n_pid, char * dst_name, char * src_ap_name, char * src_ae_name, struct qos_spec * qos); int ipcp_flow_alloc_resp(pid_t pid, uint32_t port_id, - int result); + pid_t n_pid, + int response); /* These operations go from the IPCP to the IRMd */ diff --git a/include/ouroboros/shm_ap_rbuff.h b/include/ouroboros/shm_ap_rbuff.h new file mode 100644 index 00000000..070542b0 --- /dev/null +++ b/include/ouroboros/shm_ap_rbuff.h @@ -0,0 +1,52 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Ring buffer for application processes + * + * Dimitri Staessens + * Sander Vrijders + * + * 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_SHM_AP_RBUFF_H +#define OUROBOROS_SHM_AP_RBUFF_H + +#ifndef SHM_AP_RBUFF +#define SHM_AP_RBUFF "ouroboros_rb_" +#endif + +#ifndef SHM_RBUFF_SIZE +#define SHM_RBUFF_SIZE (1 << 12) +#endif + +#include + +struct shm_ap_rbuff; + +struct rb_entry { + size_t index; + int port_id; +}; + +struct shm_ap_rbuff * shm_ap_rbuff_create(); +struct shm_ap_rbuff * shm_ap_rbuff_open(); +void shm_ap_rbuff_close(struct shm_ap_rbuff * rb); +void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb); +int shm_ap_rbuff_write(struct shm_ap_rbuff * rb, + struct rb_entry * e); +struct rb_entry * shm_ap_rbuff_read(); + +#endif /* OUROBOROS_SHM_AP_RBUFF_H */ diff --git a/include/ouroboros/shm_du_map.h b/include/ouroboros/shm_du_map.h index fb51768d..f575aa42 100644 --- a/include/ouroboros/shm_du_map.h +++ b/include/ouroboros/shm_du_map.h @@ -44,14 +44,23 @@ struct shm_du_map; struct shm_du_map * shm_du_map_create(); struct shm_du_map * shm_du_map_open(); void shm_du_map_close(struct shm_du_map * dum); +void shm_du_map_destroy(struct shm_du_map * dum); -struct shm_du_buff * shm_create_du_buff(struct shm_du_map * dum, - size_t size, - size_t headspace, - uint8_t * data, - size_t len); -int shm_release_du_buff(struct shm_du_map * dum); +/* returns the index of the buffer in the DU map */ +int shm_create_du_buff(struct shm_du_map * dum, + size_t size, + size_t headspace, + uint8_t * data, + size_t len); +/* FIXME: revise these */ +int shm_du_map_read_sdu(uint8_t ** dst, + struct shm_du_map * dum, + size_t idx); +int shm_release_du_buff(struct shm_du_map * dum, size_t idx); + + +/* FIXME: use shm_du_map * and index */ uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb, size_t size); uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb, diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h index 2e5a4944..a1d2ac96 100644 --- a/include/ouroboros/utils.h +++ b/include/ouroboros/utils.h @@ -21,6 +21,7 @@ */ #define MAX(a,b) (a > b ? a : b) +#define MIN(a,b) (a < b ? a : b) /* * Returns the number of characters a uint would -- cgit v1.2.3 From 021af9e01ce6c6376534b33ef1a06ea4189028d4 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 8 May 2016 16:23:24 +0200 Subject: lib: changed SHM_AP_RBUFF to SHM_AP_RBUFF_PREFIX This better reflects the use as the pid is appended to that name. --- include/ouroboros/shm_ap_rbuff.h | 2 +- src/lib/shm_ap_rbuff.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/ouroboros/shm_ap_rbuff.h b/include/ouroboros/shm_ap_rbuff.h index 070542b0..0ee3e81e 100644 --- a/include/ouroboros/shm_ap_rbuff.h +++ b/include/ouroboros/shm_ap_rbuff.h @@ -25,7 +25,7 @@ #define OUROBOROS_SHM_AP_RBUFF_H #ifndef SHM_AP_RBUFF -#define SHM_AP_RBUFF "ouroboros_rb_" +#define SHM_AP_RBUFF_PREFIX "ouroboros_rb_" #endif #ifndef SHM_RBUFF_SIZE diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index 4bd64775..0a41dfb3 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -59,7 +59,7 @@ struct shm_ap_rbuff * shm_ap_rbuff_create() pthread_mutexattr_t attr; char fn[25]; - sprintf(fn, SHM_AP_RBUFF "%d", getpid()); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", getpid()); rb = malloc(sizeof(*rb)); if (rb == NULL) { @@ -132,7 +132,7 @@ struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t pid) struct rb_entry * shm_base; char fn[25]; - sprintf(fn, SHM_AP_RBUFF "%d", pid); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", pid); rb = malloc(sizeof(*rb)); if (rb == NULL) { @@ -186,7 +186,7 @@ void shm_ap_rbuff_close(struct shm_ap_rbuff * rb) return; } - sprintf(fn, SHM_AP_RBUFF "%d", rb->pid); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->pid); if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) LOG_DBGF("Couldn't unmap shared memory."); @@ -209,7 +209,7 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb) return; } - sprintf(fn, SHM_AP_RBUFF "%d", rb->pid); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->pid); if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) LOG_DBGF("Couldn't unmap shared memory."); -- cgit v1.2.3