summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-20 15:20:10 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-20 15:20:10 +0000
commit4bfd6c07281847405e127e9588376fcf20d07a7e (patch)
tree17b4f02e6802499ad51f4712104be4554f0c777e
parenta3048addc6a6f4284ade5c024ae42db5719f509a (diff)
parentb3f13ce940382cf449a244b2ff65dbf36ce2fe4b (diff)
downloadouroboros-4bfd6c07281847405e127e9588376fcf20d07a7e.tar.gz
ouroboros-4bfd6c07281847405e127e9588376fcf20d07a7e.zip
Merged in dstaesse/ouroboros/be-complete (pull request #489)
ipcpd: Build complete graph with gam
-rw-r--r--src/ipcpd/normal/neighbors.c22
-rw-r--r--src/ipcpd/normal/neighbors.h3
-rw-r--r--src/ipcpd/normal/pol/complete.c71
-rw-r--r--src/ipcpd/normal/ribmgr.c3
4 files changed, 78 insertions, 21 deletions
diff --git a/src/ipcpd/normal/neighbors.c b/src/ipcpd/normal/neighbors.c
index f52a2319..0dbc22f2 100644
--- a/src/ipcpd/normal/neighbors.c
+++ b/src/ipcpd/normal/neighbors.c
@@ -177,6 +177,28 @@ int nbs_del(struct nbs * nbs,
return -1;
}
+bool nbs_has(struct nbs * nbs,
+ uint64_t addr)
+{
+ struct list_head * p = NULL;
+
+ assert(nbs);
+
+ pthread_mutex_lock(&nbs->list_lock);
+
+ list_for_each(p, &nbs->list) {
+ struct nb * e = list_entry(p, struct nb, next);
+ if (e->conn.conn_info.addr == addr) {
+ pthread_mutex_unlock(&nbs->list_lock);
+ return true;
+ }
+ }
+
+ pthread_mutex_unlock(&nbs->list_lock);
+
+ return false;
+}
+
int nbs_reg_notifier(struct nbs * nbs,
struct nb_notifier * notify)
{
diff --git a/src/ipcpd/normal/neighbors.h b/src/ipcpd/normal/neighbors.h
index c958affc..b9fa1405 100644
--- a/src/ipcpd/normal/neighbors.h
+++ b/src/ipcpd/normal/neighbors.h
@@ -72,6 +72,9 @@ int nbs_update_qos(struct nbs * nbs,
int nbs_del(struct nbs * nbs,
int fd);
+bool nbs_has(struct nbs * nbs,
+ uint64_t addr);
+
int nbs_reg_notifier(struct nbs * nbs,
struct nb_notifier * notify);
diff --git a/src/ipcpd/normal/pol/complete.c b/src/ipcpd/normal/pol/complete.c
index 6c0be9ec..20a2dafb 100644
--- a/src/ipcpd/normal/pol/complete.c
+++ b/src/ipcpd/normal/pol/complete.c
@@ -40,6 +40,8 @@
#include <stdlib.h>
#include <assert.h>
+#define COMPLETE_REFRESH 1000 /* ms */
+
struct complete {
struct nbs * nbs;
struct ae * ae;
@@ -69,6 +71,11 @@ static void * listener(void * o)
return (void *) 0;
}
+static void path_reset(char * path)
+{
+ path[strlen(MEMBERS_PATH)] = '\0';
+}
+
static void * allocator(void * o)
{
qosspec_t qs;
@@ -77,6 +84,12 @@ static void * allocator(void * o)
ssize_t i;
struct complete * complete;
struct conn conn;
+ uint64_t addr;
+ char path[RIB_MAX_PATH_LEN];
+ struct timespec to = {(COMPLETE_REFRESH / 1000),
+ (COMPLETE_REFRESH % 1000) * 1000000};
+
+ strcpy(path, MEMBERS_PATH);
complete = (struct complete *) o;
@@ -86,31 +99,47 @@ static void * allocator(void * o)
/* FIXME: implement QoS specs */
qs.cube = QOS_CUBE_BE;
- /* FIXME: subscribe to members to keep the graph complete. */
- len = rib_children("/" MEMBERS_NAME, &children);
- for (i = 0; i < len; ++i) {
- if (strcmp(children[i], ipcpi.name) != 0) {
- if (connmgr_alloc(complete->ae,
- children[i],
- &qs,
- &conn)) {
- log_warn("Failed to get a conn to neighbor.");
- free(children[i]);
- continue;
- }
-
- if (nbs_add(complete->nbs, conn)) {
- log_err("Failed to add neighbor.");
- free(children[i]);
- continue;
+ while (true) {
+ len = rib_children(MEMBERS_PATH, &children);
+ for (i = 0; i < len; ++i) {
+ if (strcmp(children[i], ipcpi.name) != 0) {
+ path_reset(path);
+ rib_path_append(path, children[i]);
+ if (rib_read(path, &addr,
+ sizeof(addr)) !=
+ sizeof(addr)) {
+ log_err("Failed to read address.");
+ free(children[i]);
+ continue;
+ }
+
+ if (nbs_has(complete->nbs, addr)) {
+ free(children[i]);
+ continue;
+ }
+
+ if (connmgr_alloc(complete->ae, children[i],
+ &qs, &conn)) {
+ log_warn("Failed conn to neighbor.");
+ free(children[i]);
+ continue;
+ }
+
+ if (nbs_add(complete->nbs, conn)) {
+ log_err("Failed to add neighbor.");
+ free(children[i]);
+ continue;
+ }
}
+ free(children[i]);
}
- free(children[i]);
- }
- if (len > 0)
- free(children);
+ if (len > 0)
+ free(children);
+
+ nanosleep(&to, NULL);
+ }
return (void *) 0;
}
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
index 772269ae..266a628d 100644
--- a/src/ipcpd/normal/ribmgr.c
+++ b/src/ipcpd/normal/ribmgr.c
@@ -37,6 +37,7 @@
#include "gam.h"
#include "ribconfig.h"
#include "ribmgr.h"
+#include "ipcp.h"
#include <stdlib.h>
#include <pthread.h>
@@ -322,6 +323,8 @@ int ribmgr_init(void)
strcpy(info.protocol, CDAP_PROTO);
info.pref_version = 1;
info.pref_syntax = PROTO_GPB;
+ /* NOTE: Use the same name as the DT AE of this IPCP */
+ info.addr = ipcpi.dt_addr;
ribmgr.nbs = nbs_create();
if (ribmgr.nbs == NULL) {