summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/pol/complete.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-20 16:52:23 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-04-20 17:07:51 +0200
commitb3f13ce940382cf449a244b2ff65dbf36ce2fe4b (patch)
treea5a856f89fca7cf7074dc5427c8f8c08f62155bb /src/ipcpd/normal/pol/complete.c
parent2a802888e91a274fa49d341da7744ea9c386b150 (diff)
downloadouroboros-b3f13ce940382cf449a244b2ff65dbf36ce2fe4b.tar.gz
ouroboros-b3f13ce940382cf449a244b2ff65dbf36ce2fe4b.zip
ipcpd: Build complete graph with gam
The complete policy will now build a complete graph. Currently a simple timer is used to check the member list periodically.
Diffstat (limited to 'src/ipcpd/normal/pol/complete.c')
-rw-r--r--src/ipcpd/normal/pol/complete.c71
1 files changed, 50 insertions, 21 deletions
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;
}