From 373efaf24d3600fe4dadf6bfaaee8d19e2ec32d7 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 6 Feb 2017 16:05:44 +0100 Subject: ipcpd, lib: Revise normal IPCP This PR updates the normal IPCP to use the new RIB. The old ribmgr is removed and replaced by a stub that needs to be implemented. All components (dir, fmgr, frct) were adapted to the new RIB API. A lot of functionality was moved outside of the ribmgr, such as the addr_auth, which is now a component of the IPCP. The address is also stored to the ipcpi struct. The irm tool has an option to set the gam policy of the rib manager. --- src/ipcpd/normal/fmgr.c | 100 +++++++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 39 deletions(-) (limited to 'src/ipcpd/normal/fmgr.c') diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index 6fe6fb60..6b21cdbf 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -29,22 +29,19 @@ #include #include #include - -#include -#include -#include -#include +#include #include "fmgr.h" -#include "ribmgr.h" #include "frct.h" #include "ipcp.h" #include "shm_pci.h" -#include "dir.h" -#include "pathname.h" -#include "ro.h" #include "gam.h" +#include +#include +#include +#include + #include "flow_alloc.pb-c.h" typedef FlowAllocMsg flow_alloc_msg_t; @@ -167,10 +164,10 @@ void * fmgr_nm1_sdu_reader(void * o) continue; } - if (pci->dst_addr != ribmgr_address()) { + if (pci->dst_addr != ipcpi.address) { LOG_DBG("PDU needs to be forwarded."); - if (ribmgr_dt_const()->has_ttl) { + if (pci->has_ttl) { if (pci->ttl == 0) { LOG_DBG("TTL was zero."); ipcp_flow_del(sdb); @@ -269,8 +266,11 @@ static void fmgr_destroy_flows(void) } } -int fmgr_init() +int fmgr_init(void) { + enum pol_cacep pc; + enum pol_gam pg; + int i; for (i = 0; i < AP_MAX_FLOWS; ++i) @@ -305,7 +305,22 @@ int fmgr_init() } } - fmgr.gam = gam_create(ribmgr_dt_gam(), DT_AE); + if (rib_read("/" BOOT_NAME "/dt/gam/type", &pg, sizeof(pg)) + != sizeof(pg)) { + LOG_ERR("Failed to read policy for ribmgr gam."); + return -1; + } + + if (rib_read("/" BOOT_NAME "/dt/gam/cacep", &pc, sizeof(pc)) + != sizeof(pc)) { + LOG_ERR("Failed to read CACEP policy for ribmgr gam."); + return -1; + } + + /* FIXME: Implement cacep policies */ + (void) pc; + + fmgr.gam = gam_create(pg, DT_AE); if (fmgr.gam == NULL) { LOG_ERR("Failed to create graph adjacency manager."); fmgr_destroy_flows(); @@ -324,7 +339,7 @@ int fmgr_init() return 0; } -int fmgr_fini() +void fmgr_fini() { struct list_head * pos = NULL; struct list_head * n = NULL; @@ -359,8 +374,6 @@ int fmgr_fini() pthread_rwlock_destroy(&fmgr.np1_flows_lock); fmgr_destroy_flows(); - - return 0; } int fmgr_np1_alloc(int fd, @@ -371,27 +384,43 @@ int fmgr_np1_alloc(int fd, cep_id_t cep_id; buffer_t buf; flow_alloc_msg_t msg = FLOW_ALLOC_MSG__INIT; - char * path; - uint8_t * ro_data; + char path[RIB_MAX_PATH_LEN + 1]; uint64_t addr; + ssize_t ch; + ssize_t i; + char ** children; + char * dst_ipcp = NULL; - path = pathname_create(RO_DIR); - if (path == NULL) - return -1; + assert(strlen(dst_ap_name) + strlen("/" DIR_NAME) + 1 + < RIB_MAX_PATH_LEN); + + strcpy(path, "/" DIR_NAME); + + rib_path_append(path, dst_ap_name); - path = pathname_append(path, dst_ap_name); - if (path == NULL) { - pathname_destroy(path); + ch = rib_children(path, &children); + if (ch <= 0) return -1; - } - if (ro_read(path, &ro_data) < 0) { - pathname_destroy(path); + for (i = 0; i < ch; ++i) + if (dst_ipcp == NULL && strcmp(children[i], ipcpi.name) != 0) + dst_ipcp = children[i]; + else + free(children[i]); + + free(children); + + if (dst_ipcp == NULL) return -1; - } - addr = *((uint64_t *) ro_data); - pathname_destroy(path); + strcpy(path, "/" MEMBERS_NAME); + + rib_path_append(path, dst_ipcp); + + free(dst_ipcp); + + if (rib_read(path, &addr, sizeof(addr)) < 0) + return -1; msg.code = FLOW_ALLOC_CODE__FLOW_REQ; msg.dst_name = dst_ap_name; @@ -400,16 +429,12 @@ int fmgr_np1_alloc(int fd, msg.qoscube = cube; buf.len = flow_alloc_msg__get_packed_size(&msg); - if (buf.len == 0) { - free(ro_data); + if (buf.len == 0) return -1; - } buf.data = malloc(buf.len); - if (buf.data == NULL) { - free(ro_data); + if (buf.data == NULL) return -1; - } flow_alloc_msg__pack(&msg, buf.data); @@ -417,14 +442,11 @@ int fmgr_np1_alloc(int fd, cep_id = frct_i_create(addr, &buf, cube); if (cep_id == INVALID_CEP_ID) { - free(ro_data); free(buf.data); pthread_rwlock_unlock(&fmgr.np1_flows_lock); return -1; } - free(ro_data); - fmgr.np1_fd_to_cep_id[fd] = cep_id; fmgr.np1_cep_id_to_fd[cep_id] = fd; -- cgit v1.2.3 From d64f05e8bf1277132b648bda2e1175ad8c1d2d5c Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 6 Feb 2017 21:48:00 +0100 Subject: ipcpd: Revise PCI manipulation in normal The pci function will store offsets to avoid having to recalculate them every time. TTL handling is removed from the fmgr, the TTL is automatically decreased when deserializing the PCI (or set to 1 if there is no TTL present so the PDU will be forwarded). The deserialisation function now takes a pointer to a struct pci as input to avoid memory allocation and release each time a PDU is processed. Some checks have been replaced with assert() and return values replaced with void where it makes sense. --- include/ouroboros/shm_rdrbuff.h | 4 +- src/ipcpd/normal/fmgr.c | 42 +++------- src/ipcpd/normal/shm_pci.c | 175 ++++++++++++++++++---------------------- src/ipcpd/normal/shm_pci.h | 9 +-- src/lib/shm_rdrbuff.c | 20 ++--- 5 files changed, 100 insertions(+), 150 deletions(-) (limited to 'src/ipcpd/normal/fmgr.c') diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h index cdac51f0..2e23381b 100644 --- a/include/ouroboros/shm_rdrbuff.h +++ b/include/ouroboros/shm_rdrbuff.h @@ -78,9 +78,9 @@ uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb, 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, +void shm_du_buff_head_release(struct shm_du_buff * sdb, size_t size); -int shm_du_buff_tail_release(struct shm_du_buff * sdb, +void shm_du_buff_tail_release(struct shm_du_buff * sdb, size_t size); #endif /* OUROBOROS_SHM_RDRBUFF_H */ diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index 6b21cdbf..b79d20b4 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -129,13 +129,15 @@ void * fmgr_nm1_sdu_reader(void * o) { struct timespec timeout = {0, FD_UPDATE_TIMEOUT}; struct shm_du_buff * sdb; - struct pci * pci; + struct pci pci; int fd; int i = 0; int ret; (void) o; + memset(&pci, 0, sizeof(pci)); + while (true) { /* FIXME: replace with scheduling policy call */ i = (i + 1) % QOS_CUBE_MAX; @@ -157,30 +159,15 @@ void * fmgr_nm1_sdu_reader(void * o) continue; } - pci = shm_pci_des(sdb); - if (pci == NULL) { - LOG_ERR("Failed to get PCI."); - ipcp_flow_del(sdb); - continue; - } + shm_pci_des(sdb, &pci); - if (pci->dst_addr != ipcpi.address) { + if (pci.dst_addr != ipcpi.address) { LOG_DBG("PDU needs to be forwarded."); - if (pci->has_ttl) { - if (pci->ttl == 0) { - LOG_DBG("TTL was zero."); - ipcp_flow_del(sdb); - free(pci); - continue; - } - - if (shm_pci_dec_ttl(sdb)) { - LOG_ERR("Failed to dec TTL."); - ipcp_flow_del(sdb); - free(pci); - continue; - } + if (pci.ttl == 0) { + LOG_DBG("TTL was zero."); + ipcp_flow_del(sdb); + continue; } /* @@ -188,21 +175,14 @@ void * fmgr_nm1_sdu_reader(void * o) * we don't have a PFF yet */ ipcp_flow_del(sdb); - free(pci); continue; } - if (shm_pci_shrink(sdb)) { - LOG_ERR("Failed to shrink PDU."); - ipcp_flow_del(sdb); - free(pci); - continue; - } + shm_pci_shrink(sdb); - if (frct_nm1_post_sdu(pci, sdb)) { + if (frct_nm1_post_sdu(&pci, sdb)) { LOG_ERR("Failed to hand PDU to FRCT."); ipcp_flow_del(sdb); - free(pci); continue; } } diff --git a/src/ipcpd/normal/shm_pci.c b/src/ipcpd/normal/shm_pci.c index 735bdee1..1c2cee54 100644 --- a/src/ipcpd/normal/shm_pci.c +++ b/src/ipcpd/normal/shm_pci.c @@ -20,10 +20,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define OUROBOROS_PREFIX "shm-pci" - #include -#include #include #include #include @@ -33,6 +30,7 @@ #include #include +#include #define PDU_TYPE_SIZE 1 #define QOS_ID_SIZE 1 @@ -46,33 +44,44 @@ struct { struct dt_const dtc; size_t head_size; size_t tail_size; + + /* offsets */ + size_t dst_addr_o; + size_t src_addr_o; + size_t dst_cep_id_o; + size_t src_cep_id_o; + size_t pdu_length_o; + size_t seqno_o; + size_t qos_id_o; + size_t ttl_o; } pci_info; static void ser_pci_head(uint8_t * head, struct pci * pci) { - int offset = 0; uint8_t ttl = DEFAULT_TTL; + assert(head); + assert(pci); + + /* FIXME: Add check and operations for Big Endian machines */ memcpy(head, &pci->pdu_type, PDU_TYPE_SIZE); - offset += PDU_TYPE_SIZE; - memcpy(head + offset, &pci->dst_addr, pci_info.dtc.addr_size); - offset += pci_info.dtc.addr_size; - memcpy(head + offset, &pci->src_addr, pci_info.dtc.addr_size); - offset += pci_info.dtc.addr_size; - memcpy(head + offset, &pci->dst_cep_id, pci_info.dtc.cep_id_size); - offset += pci_info.dtc.cep_id_size; - memcpy(head + offset, &pci->src_cep_id, pci_info.dtc.cep_id_size); - offset += pci_info.dtc.cep_id_size; - memcpy(head + offset, &pci->pdu_length, pci_info.dtc.pdu_length_size); - offset += pci_info.dtc.pdu_length_size; - memcpy(head + offset, &pci->seqno, pci_info.dtc.seqno_size); - offset += pci_info.dtc.seqno_size; - memcpy(head + offset, &pci->qos_id, QOS_ID_SIZE); - offset += QOS_ID_SIZE; + memcpy(head + pci_info.dst_addr_o, &pci->dst_addr, + pci_info.dtc.addr_size); + memcpy(head + pci_info.src_addr_o, &pci->src_addr, + pci_info.dtc.addr_size); + memcpy(head + pci_info.dst_cep_id_o, &pci->dst_cep_id, + pci_info.dtc.cep_id_size); + memcpy(head + pci_info.src_cep_id_o, &pci->src_cep_id, + pci_info.dtc.cep_id_size); + memcpy(head + pci_info.pdu_length_o, &pci->pdu_length, + pci_info.dtc.pdu_length_size); + memcpy(head + pci_info.seqno_o, &pci->seqno, + pci_info.dtc.seqno_size); + memcpy(head + pci_info.qos_id_o, &pci->qos_id, QOS_ID_SIZE); if (pci_info.dtc.has_ttl) - memcpy(head + offset, &ttl, TTL_SIZE); + memcpy(head + pci_info.ttl_o, &ttl, TTL_SIZE); } int shm_pci_init(void) @@ -101,9 +110,19 @@ int shm_pci_init(void) sizeof(pci_info.dtc.max_pdu_size))) return -1; - pci_info.head_size = PDU_TYPE_SIZE + pci_info.dtc.addr_size * 2 + - pci_info.dtc.cep_id_size * 2 + pci_info.dtc.pdu_length_size + - pci_info.dtc.seqno_size + QOS_ID_SIZE; + pci_info.dst_addr_o = PDU_TYPE_SIZE; + pci_info.src_addr_o = pci_info.dst_addr_o + pci_info.dtc.addr_size; + pci_info.dst_cep_id_o = pci_info.dst_addr_o + pci_info.dtc.addr_size; + pci_info.dst_cep_id_o = pci_info.src_addr_o + pci_info.dtc.addr_size; + pci_info.src_cep_id_o = pci_info.dst_cep_id_o + + pci_info.dtc.cep_id_size; + pci_info.pdu_length_o = pci_info.src_cep_id_o + + pci_info.dtc.cep_id_size; + pci_info.seqno_o = pci_info.pdu_length_o + pci_info.dtc.pdu_length_size; + pci_info.qos_id_o = pci_info.seqno_o + pci_info.dtc.seqno_size; + pci_info.ttl_o = pci_info.qos_id_o + QOS_ID_SIZE; + + pci_info.head_size = pci_info.ttl_o; if (pci_info.dtc.has_ttl) pci_info.head_size += TTL_SIZE; @@ -118,14 +137,17 @@ void shm_pci_fini(void) { } int shm_pci_ser(struct shm_du_buff * sdb, - struct pci * pci) + struct pci * pci) { uint8_t * head; uint8_t * tail; + assert(sdb); + assert(pci); + head = shm_du_buff_head_alloc(sdb, pci_info.head_size); if (head == NULL) - return -1; + return -EPERM; ser_pci_head(head, pci); @@ -133,7 +155,7 @@ int shm_pci_ser(struct shm_du_buff * sdb, tail = shm_du_buff_tail_alloc(sdb, pci_info.tail_size); if (tail == NULL) { shm_du_buff_head_release(sdb, pci_info.head_size); - return -1; + return -EPERM; } crc32((uint32_t *) tail, head, tail - head); @@ -147,8 +169,8 @@ buffer_t * shm_pci_ser_buf(buffer_t * buf, { buffer_t * buffer; - if (buf == NULL || pci == NULL) - return NULL; + assert(buf); + assert(pci); buffer = malloc(sizeof(*buffer)); if (buffer == NULL) @@ -178,85 +200,44 @@ buffer_t * shm_pci_ser_buf(buffer_t * buf, return buffer; } -struct pci * shm_pci_des(struct shm_du_buff * sdb) +void shm_pci_des(struct shm_du_buff * sdb, + struct pci * pci) { uint8_t * head; - struct pci * pci; - int offset = 0; - if (sdb == NULL) - return NULL; + assert(sdb); + assert(pci); head = shm_du_buff_head(sdb); - pci = malloc(sizeof(*pci)); - if (pci == NULL) - return NULL; - + /* FIXME: Add check and operations for Big Endian machines */ memcpy(&pci->pdu_type, head, PDU_TYPE_SIZE); - offset += PDU_TYPE_SIZE; - memcpy(&pci->dst_addr, head + offset, pci_info.dtc.addr_size); - offset += pci_info.dtc.addr_size; - memcpy(&pci->src_addr, head + offset, pci_info.dtc.addr_size); - offset += pci_info.dtc.addr_size; - memcpy(&pci->dst_cep_id, head + offset, pci_info.dtc.cep_id_size); - offset += pci_info.dtc.cep_id_size; - memcpy(&pci->src_cep_id, head + offset, pci_info.dtc.cep_id_size); - offset += pci_info.dtc.cep_id_size; - memcpy(&pci->pdu_length, head + offset, pci_info.dtc.pdu_length_size); - offset += pci_info.dtc.pdu_length_size; - memcpy(&pci->seqno, head + offset, pci_info.dtc.seqno_size); - offset += pci_info.dtc.seqno_size; - memcpy(&pci->qos_id, head + offset, QOS_ID_SIZE); - offset += QOS_ID_SIZE; - pci->has_ttl = pci_info.dtc.has_ttl; - if (pci_info.dtc.has_ttl) - memcpy(&pci->ttl, head + offset, TTL_SIZE); - - return pci; -} - -int shm_pci_shrink(struct shm_du_buff * sdb) -{ - if (sdb == NULL) - return -1; - - if (shm_du_buff_head_release(sdb, pci_info.head_size)) { - LOG_ERR("Failed to shrink head."); - return -1; - } - - if (shm_du_buff_tail_release(sdb, pci_info.tail_size)) { - LOG_ERR("Failed to shrink tail."); - return -1; + memcpy(&pci->dst_addr, head + pci_info.dst_addr_o, + pci_info.dtc.addr_size); + memcpy(&pci->src_addr, head + pci_info.src_addr_o, + pci_info.dtc.addr_size); + memcpy(&pci->dst_cep_id, head + pci_info.dst_cep_id_o, + pci_info.dtc.cep_id_size); + memcpy(&pci->src_cep_id, head + pci_info.src_cep_id_o, + pci_info.dtc.cep_id_size); + memcpy(&pci->pdu_length, head + pci_info.pdu_length_o, + pci_info.dtc.pdu_length_size); + memcpy(&pci->seqno, head + pci_info.seqno_o, + pci_info.dtc.seqno_size); + memcpy(&pci->qos_id, head + pci_info.qos_id_o, QOS_ID_SIZE); + + if (pci_info.dtc.has_ttl) { + --*(head + pci_info.ttl_o); /* decrease TTL */ + memcpy(&pci->ttl, head + pci_info.ttl_o, TTL_SIZE); + } else { + pci->ttl = 1; } - - return 0; } -int shm_pci_dec_ttl(struct shm_du_buff * sdb) +void shm_pci_shrink(struct shm_du_buff * sdb) { - uint8_t * head; - uint8_t * tail; - - if (pci_info.dtc.has_ttl == false) - return 0; + assert(sdb); - head = shm_du_buff_head(sdb); - if (head == NULL) - return -1; - - head[pci_info.head_size - TTL_SIZE]--; - - if (pci_info.dtc.has_chk) { - tail = shm_du_buff_tail(sdb); - if (tail == NULL) - return -1; - - tail -= CHK_SIZE; - - crc32((uint32_t *) tail, head, tail - head); - } - - return 0; + shm_du_buff_head_release(sdb, pci_info.head_size); + shm_du_buff_tail_release(sdb, pci_info.tail_size); } diff --git a/src/ipcpd/normal/shm_pci.h b/src/ipcpd/normal/shm_pci.h index 9fe3d9aa..17ce5cdd 100644 --- a/src/ipcpd/normal/shm_pci.h +++ b/src/ipcpd/normal/shm_pci.h @@ -44,8 +44,6 @@ struct pci { uint32_t pdu_length; uint64_t seqno; uint8_t ttl; - /* FIXME: Deprecate this and the dec_ttl call */ - int has_ttl; }; int shm_pci_init(void); @@ -58,10 +56,9 @@ int shm_pci_ser(struct shm_du_buff * sdb, buffer_t * shm_pci_ser_buf(buffer_t * buf, struct pci * pci); -struct pci * shm_pci_des(struct shm_du_buff * sdb); - -int shm_pci_shrink(struct shm_du_buff * sdb); +void shm_pci_des(struct shm_du_buff * sdb, + struct pci * pci); -int shm_pci_dec_ttl(struct shm_du_buff * sdb); +void shm_pci_shrink(struct shm_du_buff * sdb); #endif /* OUROBOROS_IPCPD_NORMAL_SHM_PCI_H */ diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index ce81d171..55047aa5 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -619,28 +619,20 @@ uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb, return buf; } -int shm_du_buff_head_release(struct shm_du_buff * sdb, - size_t size) +void shm_du_buff_head_release(struct shm_du_buff * sdb, + size_t size) { assert(sdb); - - if (size > sdb->du_tail - sdb->du_head) - return -EOVERFLOW; + assert(!(size > sdb->du_tail - sdb->du_head)); sdb->du_head += size; - - return 0; } -int shm_du_buff_tail_release(struct shm_du_buff * sdb, - size_t size) +void shm_du_buff_tail_release(struct shm_du_buff * sdb, + size_t size) { assert(sdb); - - if (size > sdb->du_tail - sdb->du_head) - return -EOVERFLOW; + assert(!(size > sdb->du_tail - sdb->du_head)); sdb->du_tail -= size; - - return 0; } -- cgit v1.2.3