summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-03-24 14:05:40 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2017-03-24 14:36:20 +0100
commit0ed6ef2567a8355013e2cd61a1a31df6be67ae01 (patch)
tree1967a00bfe73a11cafbee7a5e97173abd7699add
parent2ee56ae4d3c90b77d77e9be8e5e00832256e50de (diff)
downloadouroboros-0ed6ef2567a8355013e2cd61a1a31df6be67ae01.tar.gz
ouroboros-0ed6ef2567a8355013e2cd61a1a31df6be67ae01.zip
ipcpd: normal: Fill in forwarding table
The routing now takes the results of the routing table to fill in the forwarding table, by going through the neighbors and filling in the right fd.
-rw-r--r--include/ouroboros/hashtable.h4
-rw-r--r--src/ipcpd/normal/pff.c19
-rw-r--r--src/ipcpd/normal/pff.h6
-rw-r--r--src/ipcpd/normal/routing.c42
-rw-r--r--src/lib/hashtable.c18
-rw-r--r--src/lib/tests/hashtable_test.c10
6 files changed, 78 insertions, 21 deletions
diff --git a/include/ouroboros/hashtable.h b/include/ouroboros/hashtable.h
index 81fbcc1a..5e1ff4b1 100644
--- a/include/ouroboros/hashtable.h
+++ b/include/ouroboros/hashtable.h
@@ -34,7 +34,9 @@ struct htable;
struct htable * htable_create(uint64_t buckets,
bool hash_key);
-int htable_destroy(struct htable * table);
+void htable_destroy(struct htable * table);
+
+void htable_flush(struct htable * table);
/* Passes ownership of the block of memory */
int htable_insert(struct htable * table,
diff --git a/src/ipcpd/normal/pff.c b/src/ipcpd/normal/pff.c
index 8cab7936..77c2c551 100644
--- a/src/ipcpd/normal/pff.c
+++ b/src/ipcpd/normal/pff.c
@@ -68,6 +68,16 @@ void pff_destroy(struct pff * instance)
free(instance);
}
+void pff_lock(struct pff * instance)
+{
+ pthread_mutex_lock(&instance->lock);
+}
+
+void pff_unlock(struct pff * instance)
+{
+ pthread_mutex_unlock(&instance->lock);
+}
+
int pff_add(struct pff * instance, uint64_t addr, int fd)
{
int * val;
@@ -132,6 +142,15 @@ int pff_remove(struct pff * instance, uint64_t addr)
return 0;
}
+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)
{
int * j;
diff --git a/src/ipcpd/normal/pff.h b/src/ipcpd/normal/pff.h
index 667c341e..7d8ce469 100644
--- a/src/ipcpd/normal/pff.h
+++ b/src/ipcpd/normal/pff.h
@@ -34,6 +34,10 @@ struct pff * pff_create(void);
void pff_destroy(struct pff * instance);
+void pff_lock(struct pff * instance);
+
+void pff_unlock(struct pff * instance);
+
int pff_add(struct pff * instance,
uint64_t addr,
int fd);
@@ -45,6 +49,8 @@ int pff_update(struct pff * instance,
int pff_remove(struct pff * instance,
uint64_t addr);
+void pff_flush(struct pff * instance);
+
/* Returns fd towards next hop */
int pff_nhop(struct pff * instance,
uint64_t addr);
diff --git a/src/ipcpd/normal/routing.c b/src/ipcpd/normal/routing.c
index f8705991..b750ca84 100644
--- a/src/ipcpd/normal/routing.c
+++ b/src/ipcpd/normal/routing.c
@@ -35,6 +35,7 @@
#include "ribconfig.h"
#include "ipcp.h"
#include "graph.h"
+#include "neighbors.h"
#include <assert.h>
#include <stdlib.h>
@@ -63,14 +64,32 @@ struct {
pthread_t rib_listener;
} routing;
+/* Take under neighbors lock */
+static int addr_to_fd(uint64_t addr)
+{
+ struct list_head * p = NULL;
+
+ list_for_each(p, &routing.nbs->list) {
+ struct nb * e = list_entry(p, struct nb, next);
+ if (e->conn.conn_info.addr == addr)
+ return e->conn.flow_info.fd;
+ }
+
+ return -1;
+}
+
static void * calculate_pff(void * o)
{
+ struct routing_i * instance;
struct routing_table ** table;
ssize_t n_table;
+ int i;
+ int fd;
- (void) o;
+ instance = (struct routing_i *) o;
while (true) {
+ table = NULL;
n_table = graph_routing_table(routing.graph,
ipcpi.dt_addr, &table);
if (table == NULL) {
@@ -78,10 +97,21 @@ static void * calculate_pff(void * o)
continue;
}
- /*
- * FIXME: Calculate address to fd here
- * and fill in PFF
- */
+ pthread_mutex_lock(&routing.nbs->list_lock);
+ pff_lock(instance->pff);
+
+ pff_flush(instance->pff);
+
+ for (i = 0; i < n_table; i++) {
+ fd = addr_to_fd(table[i]->nhop);
+ if (fd == -1)
+ continue;
+
+ pff_add(instance->pff, table[i]->dst, fd);
+ }
+
+ pff_unlock(instance->pff);
+ pthread_mutex_unlock(&routing.nbs->list_lock);
freepp(struct routing_table, table, n_table);
sleep(RECALC_TIME);
@@ -102,7 +132,7 @@ struct routing_i * routing_i_create(struct pff * pff)
tmp->pff = pff;
- pthread_create(&tmp->calculator, NULL, calculate_pff, NULL);
+ pthread_create(&tmp->calculator, NULL, calculate_pff, (void *) tmp);
return tmp;
}
diff --git a/src/lib/hashtable.c b/src/lib/hashtable.c
index 0a534da7..77b56075 100644
--- a/src/lib/hashtable.c
+++ b/src/lib/hashtable.c
@@ -76,7 +76,17 @@ struct htable * htable_create(uint64_t buckets, bool hash_key)
return tmp;
}
-int htable_destroy(struct htable * table)
+void htable_destroy(struct htable * table)
+{
+ assert(table);
+ assert(table->buckets);
+
+ htable_flush(table);
+ free(table->buckets);
+ free(table);
+}
+
+void htable_flush(struct htable * table)
{
unsigned int i;
struct list_head * pos = NULL;
@@ -88,15 +98,11 @@ int htable_destroy(struct htable * table)
for (i = 0; i < table->buckets_size; i++) {
list_for_each_safe(pos, n, &(table->buckets[i])) {
entry = list_entry(pos, struct htable_entry, next);
+ list_del(&entry->next);
free(entry->val);
free(entry);
}
}
-
- free(table->buckets);
- free(table);
-
- return 0;
}
static uint64_t hash(uint64_t x)
diff --git a/src/lib/tests/hashtable_test.c b/src/lib/tests/hashtable_test.c
index a5b0e469..1160e34d 100644
--- a/src/lib/tests/hashtable_test.c
+++ b/src/lib/tests/hashtable_test.c
@@ -42,10 +42,7 @@ int hashtable_test(int argc, char ** argv)
return -1;
}
- if (htable_destroy(table)) {
- printf("Failed to destroy.\n");
- return -1;
- }
+ htable_destroy(table);
table = htable_create(HASHTABLE_SIZE, false);
if (table == NULL) {
@@ -124,10 +121,7 @@ int hashtable_test(int argc, char ** argv)
return -1;
}
- if (htable_destroy(table)) {
- printf("Failed to destroy.\n");
- return -1;
- }
+ htable_destroy(table);
return 0;
}