From c96efb13edfaf9b2f2c626bd2a5d5d5afd38155f Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 18 Sep 2016 06:27:43 +0200 Subject: lib, ipcp: Revise fast path and flow interfaces IPCPs can now use ap_init() to initialize the memory. All flows are accessed using flow descriptors, this greatly simplifies IPCP development. Reverts the fast path to a single ap_rbuff per process. Splits lib/ipcp into irmd/ipcp and lib/ipcp-dev. Adds a lib/shim-dev holding tailored functions for shims. Moves the buffer_t to utils.h. Fixes the shim-eth-llc length field. Removes the flow from shared.h. Fixes #4 Fixes #5 --- include/ouroboros/CMakeLists.txt | 2 +- include/ouroboros/common.h | 34 ---------------- include/ouroboros/dev.h | 25 +++++------- include/ouroboros/fcntl.h | 44 +++++++++++++++++++++ include/ouroboros/flow.h | 40 ------------------- include/ouroboros/ipcp-dev.h | 50 +++++++++++++++++++++++ include/ouroboros/ipcp.h | 81 -------------------------------------- include/ouroboros/local-dev.h | 34 ++++++++++++++++ include/ouroboros/np1_flow.h | 42 ++++++++++++++++++++ include/ouroboros/shared.h | 7 ---- include/ouroboros/shm_ap_rbuff.h | 12 +----- include/ouroboros/shm_rdrbuff.h | 59 ++++++++++++++------------- include/ouroboros/sockets.h | 4 +- include/ouroboros/utils.h | 17 +++++++- include/ouroboros/wrap/ouroboros.i | 4 +- 15 files changed, 234 insertions(+), 221 deletions(-) delete mode 100644 include/ouroboros/common.h create mode 100644 include/ouroboros/fcntl.h delete mode 100644 include/ouroboros/flow.h create mode 100644 include/ouroboros/ipcp-dev.h delete mode 100644 include/ouroboros/ipcp.h create mode 100644 include/ouroboros/local-dev.h create mode 100644 include/ouroboros/np1_flow.h (limited to 'include') diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index 78a7bb9c..f24857ed 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -6,7 +6,7 @@ set(HEADER_FILES cdap.h dev.h errno.h - flow.h + fcntl.h irm.h irm_config.h nsm.h diff --git a/include/ouroboros/common.h b/include/ouroboros/common.h deleted file mode 100644 index dbd050f1..00000000 --- a/include/ouroboros/common.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Common definitions - * - * 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_COMMON_H -#define OUROBOROS_COMMON_H - -#include -#include - -typedef struct { - uint8_t * data; - size_t len; -} buffer_t; - -#endif /* OUROBOROS_COMMON_H */ diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index fe5ff4b5..25299ee3 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -20,11 +20,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include -#include - #include -#include + +#include #ifndef OUROBOROS_DEV_H #define OUROBOROS_DEV_H @@ -36,32 +34,29 @@ int ap_init(char * ap_name); void ap_fini(void); -/* Returns file descriptor (> 0) and client AE name. */ +/* Returns flow descriptor (> 0) and client AE name. */ int flow_accept(char ** ae_name); -int flow_alloc_resp(int fd, int result); +int flow_alloc_resp(int fd, + int response); /* - * Returns file descriptor (> 0). + * Returns flow descriptor (> 0). * On returning, qos will contain the actual supplied QoS. */ -int flow_alloc(char * dst_name, - char * src_ae_name, +int flow_alloc(char * dst_name, + char * src_ae_name, struct qos_spec * qos); int flow_alloc_res(int fd); int flow_dealloc(int fd); -int flow_cntl(int fd, - int cmd, - int oflags); - -ssize_t flow_write(int fd, +ssize_t flow_write(int fd, void * buf, size_t count); -ssize_t flow_read(int fd, +ssize_t flow_read(int fd, void * buf, size_t count); diff --git a/include/ouroboros/fcntl.h b/include/ouroboros/fcntl.h new file mode 100644 index 00000000..ccb45996 --- /dev/null +++ b/include/ouroboros/fcntl.h @@ -0,0 +1,44 @@ +/* + * 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_FCNTL_H +#define OUROBOROS_FCNTL_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) + +#define FLOW_F_GETFL 00000001 +#define FLOW_F_SETFL 00000002 + +int flow_cntl(int fd, + int cmd, + int oflags); + +#endif /* OUROBOROS_FCNTL_H */ diff --git a/include/ouroboros/flow.h b/include/ouroboros/flow.h deleted file mode 100644 index 754c7632..00000000 --- a/include/ouroboros/flow.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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) - -#define FLOW_F_GETFL 00000001 -#define FLOW_F_SETFL 00000002 - -#endif /* OUROBOROS_FLOW_H */ diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h new file mode 100644 index 00000000..3c2ff264 --- /dev/null +++ b/include/ouroboros/ipcp-dev.h @@ -0,0 +1,50 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Additional API for IPCPs + * + * 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. + */ + +#include +#include + +#include +#include + +#ifndef OUROBOROS_IPCP_DEV_H +#define OUROBOROS_IPCP_DEV_H + +int ipcp_create_r(pid_t api); + +int ipcp_flow_req_arr(pid_t api, + char * dst_name, + char * src_ae_name); + +int ipcp_flow_alloc_reply(int fd, + int response); + +/* returns flow descriptor and du buff */ +int ipcp_flow_read(struct shm_du_buff ** sdb); + +int ipcp_flow_write(int fd, + struct shm_du_buff * sdb); + +void ipcp_flow_del(struct shm_du_buff * sdb); + +#endif /* OUROBOROS_IPCP_DEV_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h deleted file mode 100644 index 98337da6..00000000 --- a/include/ouroboros/ipcp.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * The API for the IRM to instruct IPCPs - * - * 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. - */ - -#include -#include -#include - -#include - -#ifndef OUROBOROS_IPCP_H -#define OUROBOROS_IPCP_H - -struct ipcp; - -/* Returns the process id */ -pid_t ipcp_create(enum ipcp_type ipcp_type); - -/* IPCP calls this when it is initialized */ -int ipcp_create_r(pid_t api); - -int ipcp_destroy(pid_t api); - -int ipcp_enroll(pid_t api, - char * dif_name); - -int ipcp_bootstrap(pid_t api, - dif_config_msg_t * conf); - -/* Flow related ops, these go from IRMd to IPCP */ - -int ipcp_name_reg(pid_t api, - char * name); -int ipcp_name_unreg(pid_t api, - char * name); - -int ipcp_flow_alloc(pid_t api, - int port_id, - pid_t n_api, - char * dst_name, - char * src_ae_name, - enum qos_cube qos); -int ipcp_flow_alloc_resp(pid_t api, - int port_id, - pid_t n_api, - int response); - -/* These operations go from the IPCP to the IRMd */ - -/* Returns the port_id */ -int ipcp_flow_req_arr(pid_t api, - char * dst_name, - char * src_ae_name); -int ipcp_flow_alloc_reply(pid_t api, - int port_id, - int response); - -int ipcp_flow_dealloc(pid_t api, - int port_id); - -int irm_flow_dealloc(int port_id); - -#endif /* OUROBOROS_IPCP_H */ diff --git a/include/ouroboros/local-dev.h b/include/ouroboros/local-dev.h new file mode 100644 index 00000000..b4915672 --- /dev/null +++ b/include/ouroboros/local-dev.h @@ -0,0 +1,34 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Optimized calls for the local IPCPs + * + * 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. + */ + +#include + +#ifndef OUROBOROS_LOCAL_DEV_H +#define OUROBOROS_LOCAL_DEV_H + +/* returns flow descriptor and rb_entry, no access to du_buff */ +int local_flow_read(struct rb_entry * e); + +int local_flow_write(int fd, + struct rb_entry * e); + +#endif /* OUROBOROS_LOCAL_DEV_H */ diff --git a/include/ouroboros/np1_flow.h b/include/ouroboros/np1_flow.h new file mode 100644 index 00000000..c89af70e --- /dev/null +++ b/include/ouroboros/np1_flow.h @@ -0,0 +1,42 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Adapter functions for N + 1 flow descriptors + * + * 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. + */ + +#include +#include +#include + +#include +#include +#include + +#ifndef OUROBOROS_NP1_FLOW_H +#define OUROBOROS_NP1_FLOW_H + +int np1_flow_alloc(pid_t n_api, + int port_id); + +int np1_flow_resp(pid_t n_api, + int port_id); + +int np1_flow_dealloc(int port_id); + +#endif /* OUROBOROS_NP1_FLOW_H */ diff --git a/include/ouroboros/shared.h b/include/ouroboros/shared.h index bfd99eb0..c38b1bde 100644 --- a/include/ouroboros/shared.h +++ b/include/ouroboros/shared.h @@ -30,11 +30,4 @@ enum qos_cube { QOS_MAX }; -enum flow_state { - FLOW_NULL = 0, - FLOW_PENDING, - FLOW_ALLOCATED, - FLOW_DESTROY -}; - #endif /* OUROBOROS_SHARED_H */ diff --git a/include/ouroboros/shm_ap_rbuff.h b/include/ouroboros/shm_ap_rbuff.h index 6b11fd2d..89d9876d 100644 --- a/include/ouroboros/shm_ap_rbuff.h +++ b/include/ouroboros/shm_ap_rbuff.h @@ -36,17 +36,9 @@ struct rb_entry { int port_id; }; -/* recv SDUs from N + 1 */ -struct shm_ap_rbuff * shm_ap_rbuff_create_n(); +struct shm_ap_rbuff * shm_ap_rbuff_create(); -/* recv SDUs from N - 1 */ -struct shm_ap_rbuff * shm_ap_rbuff_create_s(); - -/* write SDUs to N - 1 */ -struct shm_ap_rbuff * shm_ap_rbuff_open_n(pid_t api); - -/* write SDUs to N + 1 */ -struct shm_ap_rbuff * shm_ap_rbuff_open_s(pid_t api); +struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t api); void shm_ap_rbuff_close(struct shm_ap_rbuff * rb); diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h index 7a7049e3..f1be3652 100644 --- a/include/ouroboros/shm_rdrbuff.h +++ b/include/ouroboros/shm_rdrbuff.h @@ -33,6 +33,8 @@ struct shm_du_buff; struct shm_rdrbuff; +size_t shm_du_buff_get_idx(struct shm_du_buff * sdb); + struct shm_rdrbuff * shm_rdrbuff_create(); struct shm_rdrbuff * shm_rdrbuff_open(); @@ -44,40 +46,43 @@ void shm_rdrbuff_destroy(struct shm_rdrbuff * rdrb); void * shm_rdrbuff_sanitize(void * o); /* returns the index of the buffer in the DU map */ -ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, - pid_t dst_api, - size_t headspace, - size_t tailspace, - uint8_t * data, - size_t data_len); +ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, + pid_t dst_api, + size_t headspace, + size_t tailspace, + uint8_t * data, + size_t data_len); + +ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, + pid_t dst_api, + size_t headspace, + size_t tailspace, + uint8_t * data, + size_t data_len); -ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, - pid_t dst_api, - size_t headspace, - size_t tailspace, - uint8_t * data, - size_t data_len); +int shm_rdrbuff_read(uint8_t ** dst, + struct shm_rdrbuff * rdrb, + ssize_t idx); -int shm_rdrbuff_read(uint8_t ** dst, - struct shm_rdrbuff * rdrb, - ssize_t idx); +struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, + ssize_t idx); -int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, - ssize_t idx); +int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, + ssize_t idx); -uint8_t * shm_du_buff_head(struct shm_du_buff * sdb); +uint8_t * shm_du_buff_head(struct shm_du_buff * sdb); -uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb); +uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb); -uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb, - size_t size); +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, - size_t size); +uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb, + size_t size); -int shm_du_buff_head_release(struct shm_du_buff * sdb, - size_t size); +int shm_du_buff_head_release(struct shm_du_buff * sdb, + size_t size); -int shm_du_buff_tail_release(struct shm_du_buff * sdb, - size_t size); +int shm_du_buff_tail_release(struct shm_du_buff * sdb, + size_t size); #endif /* OUROBOROS_SHM_RDRBUFF_H */ diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index 5d654cb1..aef4259e 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -23,8 +23,6 @@ #ifndef OUROBOROS_SOCKETS_H #define OUROBOROS_SOCKETS_H -#include - #include #include "dif_config.pb-c.h" @@ -49,9 +47,11 @@ typedef IpcpMsg ipcp_msg_t; char * ipcp_sock_path(pid_t api); int server_socket_open(char * file_name); + int client_socket_open(char * file_name); irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); + irm_msg_t * send_recv_irm_msg_b(irm_msg_t * msg); #endif diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h index 17bd41ee..cf9a49bc 100644 --- a/include/ouroboros/utils.h +++ b/include/ouroboros/utils.h @@ -20,8 +20,19 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define MAX(a,b) (a > b ? a : b) -#define MIN(a,b) (a < b ? a : b) +#ifndef OUROBOROS_UTILS_H +#define OUROBOROS_UTILS_H + +#include +#include + +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) + +typedef struct { + uint8_t * data; + size_t len; +} buffer_t; /* * Returns the number of characters a uint would @@ -34,3 +45,5 @@ char * strdup(const char * src); /* gets the application name */ char * path_strip(char * src); + +#endif /* OUROBOROS_UTILS_H */ diff --git a/include/ouroboros/wrap/ouroboros.i b/include/ouroboros/wrap/ouroboros.i index 2f66aa16..394b505a 100644 --- a/include/ouroboros/wrap/ouroboros.i +++ b/include/ouroboros/wrap/ouroboros.i @@ -25,7 +25,7 @@ #include "ouroboros/cdap.h" #include "ouroboros/dev.h" #include "ouroboros/errno.h" -#include "ouroboros/flow.h" +#include "ouroboros/fcntl.h" #include "ouroboros/irm.h" #include "ouroboros/irm_config.h" #include "ouroboros/nsm.h" @@ -38,7 +38,7 @@ typedef int pid_t; %include "ouroboros/cdap.h" %include "ouroboros/dev.h" %include "ouroboros/errno.h" -%include "ouroboros/flow.h" +%include "ouroboros/fcntl.h" %include "ouroboros/irm.h" %include "ouroboros/irm_config.h" %include "ouroboros/nsm.h" -- cgit v1.2.3