diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-03-28 08:38:05 +0000 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-03-28 08:38:05 +0000 |
commit | ba13c05b8b61365ff9e969c15affd2e1d52b76ed (patch) | |
tree | baa5d6178914dd12106845ca81c81b63e4249c6f /src | |
parent | 7ee6dadd39f3d4b5874d23bfcdcdd66eb195124e (diff) | |
parent | 6d080d9b9ee2e480717935e4ce94870fc87ea5f7 (diff) | |
download | ouroboros-ba13c05b8b61365ff9e969c15affd2e1d52b76ed.tar.gz ouroboros-ba13c05b8b61365ff9e969c15affd2e1d52b76ed.zip |
Merged in sandervrijders/ouroboros/be-upd-graph (pull request #426)
Be upd graph
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/normal/fmgr.c | 15 | ||||
-rw-r--r-- | src/ipcpd/normal/frct.c | 5 | ||||
-rw-r--r-- | src/ipcpd/normal/graph.c | 90 | ||||
-rw-r--r-- | src/ipcpd/normal/graph.h | 5 | ||||
-rw-r--r-- | src/ipcpd/normal/main.c | 13 | ||||
-rw-r--r-- | src/ipcpd/normal/pff.c | 20 | ||||
-rw-r--r-- | src/ipcpd/normal/routing.c | 15 | ||||
-rw-r--r-- | src/ipcpd/normal/shm_pci.c | 20 | ||||
-rw-r--r-- | src/lib/list.c | 12 | ||||
-rw-r--r-- | src/lib/rib.c | 12 |
10 files changed, 87 insertions, 120 deletions
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index a8a9ba58..5a1bd842 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -198,13 +198,16 @@ void * fmgr_nm1_sdu_reader(void * o) continue; } + pff_lock(fmgr.pff[i]); fd = pff_nhop(fmgr.pff[i], pci.dst_addr); if (fd < 0) { + pff_unlock(fmgr.pff[i]); log_err("No next hop for %lu", pci.dst_addr); ipcp_flow_del(sdb); continue; } + pff_unlock(fmgr.pff[i]); if (ipcp_flow_write(fd, sdb)) { log_err("Failed to write SDU to fd %d.", @@ -293,6 +296,12 @@ int fmgr_init(void) } } + if (shm_pci_init()) { + log_err("Failed to init shm pci."); + fmgr_destroy_flows(); + return -1; + } + memset(&info, 0, sizeof(info)); strcpy(info.ae_name, DT_AE); @@ -689,12 +698,15 @@ int fmgr_nm1_write_sdu(struct pci * pci, if (pci == NULL || sdb == NULL) return -EINVAL; + pff_lock(fmgr.pff[pci->qos_id]); fd = pff_nhop(fmgr.pff[pci->qos_id], pci->dst_addr); if (fd < 0) { + pff_unlock(fmgr.pff[pci->qos_id]); log_err("Could not get nhop for address %lu", pci->dst_addr); ipcp_flow_del(sdb); return -1; } + pff_unlock(fmgr.pff[pci->qos_id]); if (shm_pci_ser(sdb, pci)) { log_err("Failed to serialize PDU."); @@ -720,11 +732,14 @@ int fmgr_nm1_write_buf(struct pci * pci, if (pci == NULL || buf == NULL || buf->data == NULL) return -EINVAL; + pff_lock(fmgr.pff[pci->qos_id]); fd = pff_nhop(fmgr.pff[pci->qos_id], pci->dst_addr); if (fd < 0) { + pff_unlock(fmgr.pff[pci->qos_id]); log_err("Could not get nhop for address %lu", pci->dst_addr); return -1; } + pff_unlock(fmgr.pff[pci->qos_id]); buffer = shm_pci_ser_buf(buf, pci); if (buffer == NULL) { diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c index 8bf080ce..01bdb660 100644 --- a/src/ipcpd/normal/frct.c +++ b/src/ipcpd/normal/frct.c @@ -227,7 +227,6 @@ int frct_nm1_post_sdu(struct pci * pci, if (fmgr_np1_post_buf(id, &buf)) { log_err("Failed to hand buffer to FMGR."); - free(pci); return -1; } } else if (pci->pdu_type == PDU_TYPE_MGMT) { @@ -246,20 +245,16 @@ int frct_nm1_post_sdu(struct pci * pci, if (fmgr_np1_post_buf(pci->dst_cep_id, &buf)) { log_err("Failed to hand buffer to Flow Manager."); - free(pci); return -1; } } else { /* FIXME: Known cep-ids are delivered to FMGR (minimal DTP) */ if (fmgr_np1_post_sdu(pci->dst_cep_id, sdb)) { log_err("Failed to hand SDU to FMGR."); - free(pci); return -1; } } - free(pci); - return 0; } diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c index 272576bb..5fd6fcb6 100644 --- a/src/ipcpd/normal/graph.c +++ b/src/ipcpd/normal/graph.c @@ -81,29 +81,31 @@ static struct vertex * find_vertex_by_addr(struct graph * graph, return NULL; } -static int add_edge(struct vertex * vertex, - struct vertex * nb, - qosspec_t qs) +static struct edge * add_edge(struct vertex * vertex, + struct vertex * nb) { struct edge * edge; edge = malloc(sizeof(*edge)); if (edge == NULL) - return -ENOMEM; + return NULL; list_head_init(&edge->next); edge->nb = nb; - edge->qs = qs; list_add(&edge->next, &vertex->edges); - return 0; + log_dbg("Added a new edge to the graph."); + + return edge; } static void del_edge(struct edge * edge) { list_del(&edge->next); free(edge); + + log_dbg("Removed an edge of the graph."); } static struct vertex * add_vertex(struct graph * graph, @@ -130,6 +132,8 @@ static struct vertex * add_vertex(struct graph * graph, graph->nr_vertices++; + log_dbg("Added new vertex."); + return vertex; } @@ -148,6 +152,8 @@ static void del_vertex(struct graph * graph, free(vertex); + log_dbg("Removed a vertex from the graph."); + graph->nr_vertices--; } @@ -191,10 +197,10 @@ void graph_destroy(struct graph * graph) free(graph); } -int graph_add_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr, - qosspec_t qs) +int graph_update_edge(struct graph * graph, + uint64_t s_addr, + uint64_t d_addr, + qosspec_t qs) { struct vertex * v; struct edge * e; @@ -209,71 +215,41 @@ int graph_add_edge(struct graph * graph, v = add_vertex(graph, s_addr); if (v == NULL) { pthread_mutex_unlock(&graph->lock); + log_err("Failed to add vertex."); return -ENOMEM; } } - e = find_edge_by_addr(v, d_addr); - if (e != NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("Edge already exists."); - return -1; - } - nb = find_vertex_by_addr(graph, d_addr); if (nb == NULL) { nb = add_vertex(graph, d_addr); if (nb == NULL) { + if (list_is_empty(&v->edges)) + del_vertex(graph, v); pthread_mutex_unlock(&graph->lock); + log_err("Failed to add vertex."); return -ENOMEM; } } - if (add_edge(v, nb, qs)) { - pthread_mutex_unlock(&graph->lock); - log_err("Failed to add edge."); - return -1; - } - - pthread_mutex_unlock(&graph->lock); - - log_dbg("Added an edge to the graph."); - - return 0; -} - -int graph_update_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr, - qosspec_t qs) -{ - struct vertex * v; - struct edge * e; - - assert(graph); - - pthread_mutex_lock(&graph->lock); - - v = find_vertex_by_addr(graph, s_addr); - if (v == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("No such vertex."); - return -1; - } - e = find_edge_by_addr(v, d_addr); if (e == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("No such edge."); - return -1; + e = add_edge(v, nb); + if (e == NULL) { + if (list_is_empty(&v->edges)) + del_vertex(graph, v); + if (list_is_empty(&nb->edges)) + del_vertex(graph, v); + pthread_mutex_unlock(&graph->lock); + log_err("Failed to add edge."); + return -ENOMEM; + } } e->qs = qs; pthread_mutex_unlock(&graph->lock); - log_dbg("Updated an edge of the graph."); - return 0; } @@ -321,8 +297,6 @@ int graph_del_edge(struct graph * graph, pthread_mutex_unlock(&graph->lock); - log_dbg("Removed an edge of the graph."); - return 0; } @@ -501,7 +475,7 @@ ssize_t graph_routing_table(struct graph * graph, index = get_vertex_index(graph, prev); } - (*table)[++j] = malloc(sizeof(***table)); + (*table)[j] = malloc(sizeof(***table)); if ((*table)[j] == NULL) { pthread_mutex_unlock(&graph->lock); for (k = 0; k < j; ++k) @@ -513,7 +487,7 @@ ssize_t graph_routing_table(struct graph * graph, (*table)[j]->dst = v->addr; (*table)[j]->nhop = nhop->addr; - + j++; i++; } diff --git a/src/ipcpd/normal/graph.h b/src/ipcpd/normal/graph.h index 226092c7..70be8626 100644 --- a/src/ipcpd/normal/graph.h +++ b/src/ipcpd/normal/graph.h @@ -37,11 +37,6 @@ struct graph * graph_create(void); void graph_destroy(struct graph * graph); -int graph_add_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr, - qosspec_t qs); - int graph_update_edge(struct graph * graph, uint64_t s_addr, uint64_t d_addr, diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 41e0544d..ef7f07cf 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -85,6 +85,7 @@ static int boot_components(void) char buf[256]; ssize_t len; enum pol_addr_auth pa; + char path[RIB_MAX_PATH_LEN + 1]; len = rib_read(DIF_PATH, &buf, 256); if (len < 0) { @@ -108,7 +109,6 @@ static int boot_components(void) if (rib_read(BOOT_PATH "/addr_auth/type", &pa, sizeof(pa)) != sizeof(pa)) { log_err("Failed to read policy for address authority."); - connmgr_fini(); return -1; } @@ -124,6 +124,14 @@ static int boot_components(void) return -1; } + path[0] = '\0'; + rib_path_append(rib_path_append(path, MEMBERS_NAME), ipcpi.name); + if (rib_write(path, &ipcpi.dt_addr, sizeof(&ipcpi.dt_addr))) { + log_err("Failed to write address to member object."); + addr_auth_fini(); + return -1; + } + log_dbg("IPCP got address %" PRIu64 ".", ipcpi.dt_addr); log_dbg("Starting ribmgr."); @@ -342,6 +350,9 @@ static int normal_ipcp_bootstrap(struct dif_config * conf) rib_write(BOOT_PATH "/dt/const/seqno_size", &conf->seqno_size, sizeof(conf->seqno_size)) || + rib_write(BOOT_PATH "/dt/const/pdu_length_size", + &conf->pdu_length_size, + sizeof(conf->pdu_length_size)) || rib_write(BOOT_PATH "/dt/const/has_ttl", &conf->has_ttl, sizeof(conf->has_ttl)) || diff --git a/src/ipcpd/normal/pff.c b/src/ipcpd/normal/pff.c index 77c2c551..c26c2263 100644 --- a/src/ipcpd/normal/pff.c +++ b/src/ipcpd/normal/pff.c @@ -60,9 +60,7 @@ void pff_destroy(struct pff * instance) { assert(instance); - pthread_mutex_lock(&instance->lock); htable_destroy(instance->table); - pthread_mutex_unlock(&instance->lock); pthread_mutex_destroy(&instance->lock); free(instance); @@ -89,13 +87,10 @@ int pff_add(struct pff * instance, uint64_t addr, int fd) return -ENOMEM; *val = fd; - pthread_mutex_lock(&instance->lock); if (htable_insert(instance->table, addr, val)) { - pthread_mutex_unlock(&instance->lock); free(val); return -1; } - pthread_mutex_unlock(&instance->lock); return 0; } @@ -111,19 +106,15 @@ int pff_update(struct pff * instance, uint64_t addr, int fd) return -ENOMEM; *val = fd; - pthread_mutex_lock(&instance->lock); if (htable_delete(instance->table, addr)) { - pthread_mutex_unlock(&instance->lock); free(val); return -1; } if (htable_insert(instance->table, addr, val)) { - pthread_mutex_unlock(&instance->lock); free(val); return -1; } - pthread_mutex_unlock(&instance->lock); return 0; } @@ -132,12 +123,8 @@ int pff_remove(struct pff * instance, uint64_t addr) { assert(instance); - pthread_mutex_lock(&instance->lock); - if (htable_delete(instance->table, addr)) { - pthread_mutex_unlock(&instance->lock); + if (htable_delete(instance->table, addr)) return -1; - } - pthread_mutex_unlock(&instance->lock); return 0; } @@ -146,9 +133,7 @@ void pff_flush(struct pff * instance) { assert(instance); - pthread_mutex_lock(&instance->lock); htable_flush(instance->table); - pthread_mutex_unlock(&instance->lock); } int pff_nhop(struct pff * instance, uint64_t addr) @@ -158,14 +143,11 @@ int pff_nhop(struct pff * instance, uint64_t addr) assert(instance); - pthread_mutex_lock(&instance->lock); j = (int *) htable_lookup(instance->table, addr); if (j == NULL) { - pthread_mutex_unlock(&instance->lock); return -1; } fd = *j; - pthread_mutex_unlock(&instance->lock); return fd; } diff --git a/src/ipcpd/normal/routing.c b/src/ipcpd/normal/routing.c index 998b294a..bf736311 100644 --- a/src/ipcpd/normal/routing.c +++ b/src/ipcpd/normal/routing.c @@ -235,23 +235,14 @@ static int read_fso(char * path, return -1; } - if (flag & RO_CREATE) { - if (graph_add_edge(routing.graph, - fso->s_addr, fso->d_addr, qs)) { - log_err("Failed to add edge to graph."); - fso__free_unpacked(fso, NULL); - return -1; - } - } else if (flag & RO_MODIFY) { + if (flag & RO_MODIFY) { if (graph_update_edge(routing.graph, fso->s_addr, fso->d_addr, qs)) { - log_err("Failed to update edge of graph."); fso__free_unpacked(fso, NULL); return -1; } } else if (flag & RO_DELETE) { if (graph_del_edge(routing.graph, fso->s_addr, fso->d_addr)) { - log_err("Failed to del edge of graph."); fso__free_unpacked(fso, NULL); return -1; } @@ -272,8 +263,7 @@ static void * rib_listener(void * o) (void) o; - if (ro_set_add(routing.set, ROUTING_PATH, - RO_MODIFY | RO_CREATE | RO_DELETE)) { + if (ro_set_add(routing.set, ROUTING_PATH, RO_MODIFY | RO_DELETE)) { log_err("Failed to add to RO set"); return (void * ) -1; } @@ -292,6 +282,7 @@ static void * rib_listener(void * o) } while (rib_event_wait(routing.set, routing.queue, NULL) == 0) { + path[0] = '\0'; flag = rqueue_next(routing.queue, path); if (flag < 0) continue; diff --git a/src/ipcpd/normal/shm_pci.c b/src/ipcpd/normal/shm_pci.c index 001463eb..e6cd1042 100644 --- a/src/ipcpd/normal/shm_pci.c +++ b/src/ipcpd/normal/shm_pci.c @@ -88,30 +88,32 @@ int shm_pci_init(void) /* read dt constants from the RIB */ if (rib_read(BOOT_PATH "/dt/const/addr_size", &pci_info.dtc.addr_size, - sizeof(pci_info.dtc.addr_size)) || + sizeof(pci_info.dtc.addr_size)) < 0 || rib_read(BOOT_PATH "/dt/const/cep_id_size", &pci_info.dtc.cep_id_size, - sizeof(pci_info.dtc.cep_id_size)) || + sizeof(pci_info.dtc.cep_id_size)) < 0 || rib_read(BOOT_PATH "/dt/const/seqno_size", &pci_info.dtc.seqno_size, - sizeof(pci_info.dtc.seqno_size)) || + sizeof(pci_info.dtc.seqno_size)) < 0 || + rib_read(BOOT_PATH "/dt/const/pdu_length_size", + &pci_info.dtc.pdu_length_size, + sizeof(pci_info.dtc.pdu_length_size)) < 0 || rib_read(BOOT_PATH "/dt/const/has_ttl", &pci_info.dtc.has_ttl, - sizeof(pci_info.dtc.has_ttl)) || + sizeof(pci_info.dtc.has_ttl)) < 0 || rib_read(BOOT_PATH "/dt/const/has_chk", &pci_info.dtc.has_chk, - sizeof(pci_info.dtc.has_chk)) || + sizeof(pci_info.dtc.has_chk)) < 0 || rib_read(BOOT_PATH "/dt/const/min_pdu_size", &pci_info.dtc.min_pdu_size, - sizeof(pci_info.dtc.min_pdu_size)) || + sizeof(pci_info.dtc.min_pdu_size)) < 0 || rib_read(BOOT_PATH "/dt/const/max_pdu_size", &pci_info.dtc.max_pdu_size, - sizeof(pci_info.dtc.max_pdu_size))) + sizeof(pci_info.dtc.max_pdu_size)) < 0) return -1; 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; @@ -132,7 +134,7 @@ int shm_pci_init(void) } void shm_pci_fini(void) { - return ; + return; } int shm_pci_ser(struct shm_du_buff * sdb, diff --git a/src/lib/list.c b/src/lib/list.c index b6b4bbd2..d5aba058 100644 --- a/src/lib/list.c +++ b/src/lib/list.c @@ -71,13 +71,9 @@ bool list_is_empty(struct list_head * h) return h->nxt == h; } -void list_move(struct list_head * dst, - struct list_head * src) +void list_move(struct list_head * n, + struct list_head * h) { - dst->nxt = src->nxt; - dst->prv = src->prv; - dst->nxt->prv = src->nxt->prv; - dst->prv->nxt = src->prv->nxt; - - list_head_init(src); + del_list(n->prv, n->nxt); + add_list(n, h, h->nxt); } diff --git a/src/lib/rib.c b/src/lib/rib.c index fc58f266..d39a17d2 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -1114,6 +1114,7 @@ int rib_event_wait(ro_set_t * set, { struct rib_sub * sub; struct timespec abstime; + struct revent * ev; ssize_t ret = 0; @@ -1136,6 +1137,9 @@ int rib_event_wait(ro_set_t * set, pthread_mutex_lock(&sub->lock); + pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock, + (void *) &sub->lock); + while (list_is_empty(&sub->events) && ret != -ETIMEDOUT) { if (timeout != NULL) ret = -pthread_cond_timedwait(&sub->cond, @@ -1145,12 +1149,14 @@ int rib_event_wait(ro_set_t * set, ret = -pthread_cond_wait(&sub->cond, &sub->lock); } - pthread_mutex_unlock(&sub->lock); + pthread_cleanup_pop(true); pthread_rwlock_wrlock(&rib.lock); - if (ret != -ETIMEDOUT) - list_move(&rq->events, &sub->events); + if (ret != -ETIMEDOUT) { + ev = list_first_entry(&sub->events, struct revent, next); + list_move(&ev->next, &rq->events); + } pthread_rwlock_unlock(&rib.lock); |