summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-09-13 09:41:41 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-09-13 09:41:41 +0000
commit888d3dbe7c3844d2efe9d6bc9823630db5d47a3b (patch)
treeed79946a5ff22267857cd6d5a864d15339c942a1 /src/ipcpd/normal
parent2e4cdc1f680d5ee9086adac76acebdec3bd1da3f (diff)
parent45c6615484ffe347654c34decb72ff1ef9bde0f3 (diff)
downloadouroboros-888d3dbe7c3844d2efe9d6bc9823630db5d47a3b.tar.gz
ouroboros-888d3dbe7c3844d2efe9d6bc9823630db5d47a3b.zip
Merged in dstaesse/ouroboros/be-rib-removal (pull request #589)
ipcpd: Revise internals of normal IPCP
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r--src/ipcpd/normal/CMakeLists.txt6
-rw-r--r--src/ipcpd/normal/connmgr.c34
-rw-r--r--src/ipcpd/normal/connmgr.h11
-rw-r--r--src/ipcpd/normal/dht.c14
-rw-r--r--src/ipcpd/normal/dir.c2
-rw-r--r--src/ipcpd/normal/dt.c94
-rw-r--r--src/ipcpd/normal/dt_pci.c2
-rw-r--r--src/ipcpd/normal/enroll.c6
-rw-r--r--src/ipcpd/normal/fa.c12
-rw-r--r--src/ipcpd/normal/main.c40
-rw-r--r--src/ipcpd/normal/neighbors.c239
-rw-r--r--src/ipcpd/normal/neighbors.h84
-rw-r--r--src/ipcpd/normal/pol-routing-ops.h2
-rw-r--r--src/ipcpd/normal/pol/flat.c2
-rw-r--r--src/ipcpd/normal/pol/link_state.c620
-rw-r--r--src/ipcpd/normal/pol/link_state.h12
-rw-r--r--src/ipcpd/normal/pol/link_state.proto (renamed from src/ipcpd/normal/pol/fso.proto)8
-rw-r--r--src/ipcpd/normal/ribconfig.h33
-rw-r--r--src/ipcpd/normal/ribmgr.c423
-rw-r--r--src/ipcpd/normal/ribmgr.h54
-rw-r--r--src/ipcpd/normal/routing.c13
-rw-r--r--src/ipcpd/normal/routing.h4
-rw-r--r--src/ipcpd/normal/sdu_sched.c13
-rw-r--r--src/ipcpd/normal/sdu_sched.h8
24 files changed, 569 insertions, 1167 deletions
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt
index aebc6c35..e5fc33da 100644
--- a/src/ipcpd/normal/CMakeLists.txt
+++ b/src/ipcpd/normal/CMakeLists.txt
@@ -20,7 +20,7 @@ protobuf_generate_c(ENROLL_PROTO_SRCS ENROLL_PROTO_HDRS enroll.proto
protobuf_generate_c(KAD_PROTO_SRCS KAD_PROTO_HDRS kademlia.proto)
# Add GPB sources of policies last
-protobuf_generate_c(FSO_SRCS FSO_HDRS pol/fso.proto)
+protobuf_generate_c(LS_PROTO_SRCS LS_PROTO_HDRS pol/link_state.proto)
math(EXPR PFT_EXPR "1 << 12")
set(PFT_SIZE ${PFT_EXPR} CACHE STRING
@@ -37,9 +37,7 @@ set(SOURCE_FILES
enroll.c
fa.c
main.c
- neighbors.c
pff.c
- ribmgr.c
routing.c
sdu_sched.c
# Add policies last
@@ -49,7 +47,7 @@ set(SOURCE_FILES
)
add_executable(ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES}
- ${FLOW_ALLOC_SRCS} ${FSO_SRCS} ${KAD_PROTO_SRCS} ${ENROLL_PROTO_SRCS})
+ ${FLOW_ALLOC_SRCS} ${LS_PROTO_SRCS} ${KAD_PROTO_SRCS} ${ENROLL_PROTO_SRCS})
target_link_libraries(ipcpd-normal LINK_PUBLIC ouroboros)
include(AddCompileFlags)
diff --git a/src/ipcpd/normal/connmgr.c b/src/ipcpd/normal/connmgr.c
index 9feac0f6..8d3da709 100644
--- a/src/ipcpd/normal/connmgr.c
+++ b/src/ipcpd/normal/connmgr.c
@@ -26,16 +26,15 @@
#include <ouroboros/dev.h>
#include <ouroboros/cacep.h>
-#include <ouroboros/cdap.h>
#include <ouroboros/errno.h>
#include <ouroboros/list.h>
#include <ouroboros/logs.h>
+#include <ouroboros/notifier.h>
#include "ae.h"
#include "connmgr.h"
#include "enroll.h"
#include "ipcp.h"
-#include "ribmgr.h"
#include <pthread.h>
#include <string.h>
@@ -198,8 +197,7 @@ void connmgr_stop(void)
}
int connmgr_ae_init(enum ae_id id,
- const struct conn_info * info,
- struct nbs * nbs)
+ const struct conn_info * info)
{
struct ae * ae;
@@ -220,8 +218,6 @@ int connmgr_ae_init(enum ae_id id,
memcpy(&connmgr.aes[id].info, info, sizeof(connmgr.aes[id].info));
- connmgr.aes[id].nbs = nbs;
-
return 0;
}
@@ -258,8 +254,6 @@ void connmgr_ae_fini(enum ae_id id)
pthread_mutex_destroy(&ae->lock);
memset(&connmgr.aes[id].info, 0, sizeof(connmgr.aes[id].info));
-
- connmgr.aes[id].nbs = NULL;
}
int connmgr_ipcp_connect(const char * dst,
@@ -394,8 +388,16 @@ int connmgr_alloc(enum ae_id id,
return -1;
}
- if (connmgr.aes[id].nbs != NULL)
- nbs_add(connmgr.aes[id].nbs, *conn);
+ switch (id) {
+ case AEID_DT:
+ notifier_event(NOTIFY_DT_CONN_ADD, conn);
+ break;
+ case AEID_MGMT:
+ notifier_event(NOTIFY_MGMT_CONN_ADD, conn);
+ break;
+ default:
+ break;
+ }
return 0;
}
@@ -403,8 +405,16 @@ int connmgr_alloc(enum ae_id id,
int connmgr_dealloc(enum ae_id id,
struct conn * conn)
{
- if (connmgr.aes[id].nbs != NULL)
- nbs_del(connmgr.aes[id].nbs, conn->flow_info.fd);
+ switch (id) {
+ case AEID_DT:
+ notifier_event(NOTIFY_DT_CONN_DEL, conn);
+ break;
+ case AEID_MGMT:
+ notifier_event(NOTIFY_MGMT_CONN_DEL, conn);
+ break;
+ default:
+ break;
+ }
return flow_dealloc(conn->flow_info.fd);
}
diff --git a/src/ipcpd/normal/connmgr.h b/src/ipcpd/normal/connmgr.h
index 379877e6..ca5288ae 100644
--- a/src/ipcpd/normal/connmgr.h
+++ b/src/ipcpd/normal/connmgr.h
@@ -27,7 +27,13 @@
#include <ouroboros/qos.h>
#include "ae.h"
-#include "neighbors.h"
+
+#define NOTIFY_DT_CONN_ADD 0x00D0
+#define NOTIFY_DT_CONN_DEL 0x00D1
+#define NOTIFY_DT_CONN_QOS 0x00D2
+
+#define NOTIFY_MGMT_CONN_ADD 0x00F0
+#define NOTIFY_MGMT_CONN_DEL 0x00F1
int connmgr_init(void);
@@ -38,8 +44,7 @@ int connmgr_start(void);
void connmgr_stop(void);
int connmgr_ae_init(enum ae_id id,
- const struct conn_info * info,
- struct nbs * nbs);
+ const struct conn_info * info);
void connmgr_ae_fini(enum ae_id id);
diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c
index d139cb91..b1ba44a8 100644
--- a/src/ipcpd/normal/dht.c
+++ b/src/ipcpd/normal/dht.c
@@ -328,9 +328,6 @@ static void kad_req_destroy(struct kad_req * req)
{
assert(req);
- if (req->key != NULL)
- free(req->key);
-
pthread_mutex_lock(&req->lock);
switch (req->state) {
@@ -351,7 +348,7 @@ static void kad_req_destroy(struct kad_req * req)
break;
}
- while (req->state != REQ_NULL)
+ while (req->state != REQ_NULL && req->state != REQ_DONE)
pthread_cond_wait(&req->cond, &req->lock);
pthread_mutex_unlock(&req->lock);
@@ -359,6 +356,9 @@ static void kad_req_destroy(struct kad_req * req)
pthread_cond_destroy(&req->cond);
pthread_mutex_destroy(&req->lock);
+ if (req->key != NULL)
+ free(req->key);
+
free(req);
}
@@ -391,7 +391,7 @@ static int kad_req_wait(struct kad_req * req,
case REQ_PENDING: /* ETIMEDOUT */
case REQ_RESPONSE:
req->state = REQ_DONE;
- pthread_cond_signal(&req->cond);
+ pthread_cond_broadcast(&req->cond);
break;
default:
break;
@@ -1859,7 +1859,7 @@ static void * work(void * o)
if (now.tv_sec > v->t_exp) {
list_del(&v->next);
val_destroy(v);
- }
+ }
if (now.tv_sec > v->t_rep) {
kad_publish(dht, e->key, v->addr,
@@ -2018,7 +2018,7 @@ static void kad_handle_response(struct dht * dht,
case KAD_FIND_VALUE:
case KAD_FIND_NODE:
if (dht_get_state(dht) != DHT_RUNNING)
- return;
+ break;
kad_handle_find_resp(dht, req, msg);
break;
default:
diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c
index d2cda4f9..6d04c66a 100644
--- a/src/ipcpd/normal/dir.c
+++ b/src/ipcpd/normal/dir.c
@@ -27,13 +27,11 @@
#include <ouroboros/endian.h>
#include <ouroboros/errno.h>
#include <ouroboros/logs.h>
-#include <ouroboros/rib.h>
#include <ouroboros/utils.h>
#include "dir.h"
#include "dht.h"
#include "ipcp.h"
-#include "ribconfig.h"
#include <stdlib.h>
#include <string.h>
diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c
index 282f6bee..2df17163 100644
--- a/src/ipcpd/normal/dt.c
+++ b/src/ipcpd/normal/dt.c
@@ -29,19 +29,17 @@
#include <ouroboros/bitmap.h>
#include <ouroboros/errno.h>
#include <ouroboros/logs.h>
-#include <ouroboros/rib.h>
#include <ouroboros/dev.h>
+#include <ouroboros/notifier.h>
#include "connmgr.h"
#include "ipcp.h"
#include "dt.h"
#include "dt_pci.h"
#include "pff.h"
-#include "neighbors.h"
#include "routing.h"
#include "sdu_sched.h"
#include "ae.h"
-#include "ribconfig.h"
#include "fa.h"
#include <stdlib.h>
@@ -66,36 +64,33 @@ struct {
struct ae_info aes[AP_RES_FDS];
pthread_rwlock_t lock;
- struct nbs * nbs;
-
- struct nb_notifier nb_notifier;
-
pthread_t listener;
} dt;
-static int dt_neighbor_event(enum nb_event event,
- struct conn conn)
+static void handle_event(int event,
+ const void * o)
{
- /* We are only interested in neighbors being added and removed. */
+ struct conn * c;
+
+ c = (struct conn *) o;
+
switch (event) {
- case NEIGHBOR_ADDED:
- sdu_sched_add(dt.sdu_sched, conn.flow_info.fd);
- log_dbg("Added fd %d to SDU scheduler.", conn.flow_info.fd);
+ case NOTIFY_DT_CONN_ADD:
+ sdu_sched_add(dt.sdu_sched, c->flow_info.fd);
+ log_dbg("Added fd %d to SDU scheduler.", c->flow_info.fd);
break;
- case NEIGHBOR_REMOVED:
- sdu_sched_del(dt.sdu_sched, conn.flow_info.fd);
- log_dbg("Removed fd %d from SDU scheduler.", conn.flow_info.fd);
+ case NOTIFY_DT_CONN_DEL:
+ sdu_sched_del(dt.sdu_sched, c->flow_info.fd);
+ log_dbg("Removed fd %d from SDU scheduler.", c->flow_info.fd);
break;
default:
break;
}
-
- return 0;
}
-static int sdu_handler(int fd,
- qoscube_t qc,
- struct shm_du_buff * sdb)
+static void sdu_handler(int fd,
+ qoscube_t qc,
+ struct shm_du_buff * sdb)
{
struct dt_pci dt_pci;
@@ -107,45 +102,38 @@ static int sdu_handler(int fd,
if (dt_pci.ttl == 0) {
log_dbg("TTL was zero.");
ipcp_sdb_release(sdb);
- return 0;
+ return;
}
fd = pff_nhop(dt.pff[qc], dt_pci.dst_addr);
if (fd < 0) {
log_err("No next hop for %" PRIu64, dt_pci.dst_addr);
ipcp_sdb_release(sdb);
- return -1;
+ return;
}
if (ipcp_flow_write(fd, sdb)) {
log_err("Failed to write SDU to fd %d.", fd);
ipcp_sdb_release(sdb);
- return -1;
+ return;
}
} else {
dt_pci_shrink(sdb);
if (dt_pci.fd > AP_RES_FDS) {
- if (ipcp_flow_write(dt_pci.fd, sdb)) {
+ if (ipcp_flow_write(dt_pci.fd, sdb))
ipcp_sdb_release(sdb);
- return -1;
- }
- return 0;
+ return;
}
if (dt.aes[dt_pci.fd].post_sdu == NULL) {
log_err("No registered AE on fd %d.", dt_pci.fd);
ipcp_sdb_release(sdb);
- return -EPERM;
+ return;
}
dt.aes[dt_pci.fd].post_sdu(dt.aes[dt_pci.fd].ae, sdb);
-
- return 0;
}
-
- /* silence compiler */
- return 0;
}
static void * dt_conn_handle(void * o)
@@ -160,11 +148,9 @@ static void * dt_conn_handle(void * o)
continue;
}
- log_dbg("Got new connection.");
-
/* NOTE: connection acceptance policy could be here. */
- nbs_add(dt.nbs, conn);
+ notifier_event(NOTIFY_DT_CONN_ADD, &conn);
}
return 0;
@@ -192,24 +178,17 @@ int dt_init(enum pol_routing pr,
goto fail_pci_init;
}
- dt.nbs = nbs_create();
- if (dt.nbs == NULL) {
- log_err("Failed to create neighbors struct.");
- goto fail_nbs;
+ if (notifier_reg(handle_event)) {
+ log_err("Failed to register with notifier.");
+ goto fail_notifier_reg;
}
- dt.nb_notifier.notify_call = dt_neighbor_event;
- if (nbs_reg_notifier(dt.nbs, &dt.nb_notifier)) {
- log_err("Failed to register notifier.");
- goto fail_nbs_notifier;
- }
-
- if (connmgr_ae_init(AEID_DT, &info, dt.nbs)) {
+ if (connmgr_ae_init(AEID_DT, &info)) {
log_err("Failed to register with connmgr.");
goto fail_connmgr_ae_init;
}
- if (routing_init(pr, dt.nbs)) {
+ if (routing_init(pr)) {
log_err("Failed to init routing.");
goto fail_routing;
}
@@ -249,20 +228,17 @@ int dt_init(enum pol_routing pr,
for (j = 0; j < QOS_CUBE_MAX; ++j)
routing_i_destroy(dt.routing[j]);
fail_routing_i:
- connmgr_ae_fini(AEID_DT);
- fail_connmgr_ae_init:
for (i = 0; i < QOS_CUBE_MAX; ++i)
pff_destroy(dt.pff[i]);
fail_pff:
routing_fini();
fail_routing:
- nbs_unreg_notifier(dt.nbs, &dt.nb_notifier);
- fail_nbs_notifier:
- nbs_destroy(dt.nbs);
- fail_nbs:
+ connmgr_ae_fini(AEID_DT);
+ fail_connmgr_ae_init:
+ notifier_unreg(&handle_event);
+ fail_notifier_reg:
dt_pci_fini();
fail_pci_init:
- connmgr_ae_fini(AEID_DT);
return -1;
}
@@ -282,11 +258,11 @@ void dt_fini(void)
routing_fini();
- nbs_unreg_notifier(dt.nbs, &dt.nb_notifier);
+ connmgr_ae_fini(AEID_DT);
- nbs_destroy(dt.nbs);
+ notifier_unreg(&handle_event);
- connmgr_ae_fini(AEID_DT);
+ dt_pci_fini();
}
int dt_start(void)
diff --git a/src/ipcpd/normal/dt_pci.c b/src/ipcpd/normal/dt_pci.c
index 5704a09a..4684265d 100644
--- a/src/ipcpd/normal/dt_pci.c
+++ b/src/ipcpd/normal/dt_pci.c
@@ -21,10 +21,8 @@
*/
#include <ouroboros/errno.h>
-#include <ouroboros/rib.h>
#include "dt_pci.h"
-#include "ribconfig.h"
#include <stdlib.h>
#include <string.h>
diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c
index ad229f40..d14c62ac 100644
--- a/src/ipcpd/normal/enroll.c
+++ b/src/ipcpd/normal/enroll.c
@@ -29,14 +29,12 @@
#include <ouroboros/time_utils.h>
#include <ouroboros/dev.h>
#include <ouroboros/logs.h>
-#include <ouroboros/rib.h>
#include <ouroboros/errno.h>
#include <ouroboros/sockets.h>
#include "connmgr.h"
#include "enroll.h"
#include "ipcp.h"
-#include "ribconfig.h"
#include <assert.h>
#include <stdlib.h>
@@ -270,6 +268,8 @@ static void * enroll_handle(void * o)
else
log_dbg("Neigbor reported failed enrollment.");
+ enroll_msg__free_unpacked(msg, NULL);
+
connmgr_dealloc(AEID_ENROLL, &conn);
}
@@ -339,7 +339,7 @@ int enroll_init(void)
info.pref_syntax = PROTO_GPB;
info.addr = 0;
- if (connmgr_ae_init(AEID_ENROLL, &info, NULL)) {
+ if (connmgr_ae_init(AEID_ENROLL, &info)) {
log_err("Failed to register with connmgr.");
return -1;
}
diff --git a/src/ipcpd/normal/fa.c b/src/ipcpd/normal/fa.c
index 682dc5c6..e684abd2 100644
--- a/src/ipcpd/normal/fa.c
+++ b/src/ipcpd/normal/fa.c
@@ -28,7 +28,6 @@
#include <ouroboros/logs.h>
#include <ouroboros/fqueue.h>
-#include <ouroboros/rib.h>
#include <ouroboros/errno.h>
#include <ouroboros/dev.h>
#include <ouroboros/ipcp-dev.h>
@@ -38,7 +37,6 @@
#include "fa.h"
#include "sdu_sched.h"
#include "ipcp.h"
-#include "ribconfig.h"
#include "dt.h"
#include <pthread.h>
@@ -59,9 +57,9 @@ struct {
struct sdu_sched * sdu_sched;
} fa;
-static int sdu_handler(int fd,
- qoscube_t qc,
- struct shm_du_buff * sdb)
+static void sdu_handler(int fd,
+ qoscube_t qc,
+ struct shm_du_buff * sdb)
{
pthread_rwlock_rdlock(&fa.flows_lock);
@@ -69,12 +67,10 @@ static int sdu_handler(int fd,
pthread_rwlock_unlock(&fa.flows_lock);
ipcp_sdb_release(sdb);
log_warn("Failed to forward SDU.");
- return -1;
+ return;
}
pthread_rwlock_unlock(&fa.flows_lock);
-
- return 0;
}
static void destroy_conn(int fd)
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 22b6e718..2b35a04a 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -31,9 +31,9 @@
#include <ouroboros/ipcp-dev.h>
#include <ouroboros/time_utils.h>
#include <ouroboros/irm.h>
-#include <ouroboros/rib.h>
#include <ouroboros/hash.h>
#include <ouroboros/errno.h>
+#include <ouroboros/notifier.h>
#include "addr_auth.h"
#include "connmgr.h"
@@ -42,8 +42,6 @@
#include "fa.h"
#include "dt.h"
#include "ipcp.h"
-#include "ribconfig.h"
-#include "ribmgr.h"
#include <stdbool.h>
#include <signal.h>
@@ -56,11 +54,6 @@
static int initialize_components(const struct ipcp_config * conf)
{
- if (rib_init()) {
- log_err("Failed to initialize RIB.");
- goto fail_rib_init;
- }
-
ipcpi.dif_name = strdup(conf->dif_info.dif_name);
if (ipcpi.dif_name == NULL) {
log_err("Failed to set DIF name.");
@@ -85,11 +78,6 @@ static int initialize_components(const struct ipcp_config * conf)
log_dbg("IPCP got address %" PRIu64 ".", ipcpi.dt_addr);
- if (ribmgr_init()) {
- log_err("Failed to initialize RIB manager.");
- goto fail_ribmgr;
- }
-
if (dt_init(conf->routing_type,
conf->addr_size,
conf->fd_size,
@@ -117,14 +105,10 @@ static int initialize_components(const struct ipcp_config * conf)
fail_fa:
dt_fini();
fail_dt:
- ribmgr_fini();
- fail_ribmgr:
addr_auth_fini();
fail_addr_auth:
free(ipcpi.dif_name);
fail_dif_name:
- rib_fini();
- fail_rib_init:
return -1;
}
@@ -136,13 +120,9 @@ static void finalize_components(void)
dt_fini();
- ribmgr_fini();
-
addr_auth_fini();
free(ipcpi.dif_name);
-
- rib_fini();
}
static int start_components(void)
@@ -151,11 +131,6 @@ static int start_components(void)
ipcp_set_state(IPCP_OPERATIONAL);
- if (ribmgr_start()) {
- log_err("Failed to start RIB manager.");
- goto fail_ribmgr_start;
- }
-
if (fa_start()) {
log_err("Failed to start flow allocator.");
goto fail_fa_start;
@@ -178,8 +153,6 @@ static int start_components(void)
fail_enroll_start:
fa_stop();
fail_fa_start:
- ribmgr_stop();
- fail_ribmgr_start:
ipcp_set_state(IPCP_INIT);
return -1;
}
@@ -195,8 +168,6 @@ static void stop_components(void)
fa_stop();
- ribmgr_stop();
-
ipcp_set_state(IPCP_INIT);
}
@@ -377,6 +348,11 @@ int main(int argc,
goto fail_enroll_init;
}
+ if (notifier_init()) {
+ log_err("Failed to initialize notifier component.");
+ goto fail_notifier_init;
+ }
+
if (ipcp_boot() < 0) {
log_err("Failed to boot IPCP.");
goto fail_boot;
@@ -396,6 +372,8 @@ int main(int argc,
finalize_components();
}
+ notifier_fini();
+
enroll_fini();
connmgr_fini();
@@ -409,6 +387,8 @@ int main(int argc,
fail_create_r:
ipcp_shutdown();
fail_boot:
+ notifier_fini();
+ fail_notifier_init:
enroll_fini();
fail_enroll_init:
connmgr_fini();
diff --git a/src/ipcpd/normal/neighbors.c b/src/ipcpd/normal/neighbors.c
deleted file mode 100644
index c32e9aa2..00000000
--- a/src/ipcpd/normal/neighbors.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * Neighbors
- *
- * Dimitri Staessens <dimitri.staessens@ugent.be>
- * Sander Vrijders <sander.vrijders@ugent.be>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., http://www.fsf.org/about/contact/.
- */
-
-#define _POSIX_C_SOURCE 199309L
-
-#define OUROBOROS_PREFIX "neighbors"
-
-#include <ouroboros/qoscube.h>
-#include <ouroboros/ipcp-dev.h>
-#include <ouroboros/errno.h>
-#include <ouroboros/logs.h>
-
-#include "neighbors.h"
-
-#include <stdlib.h>
-#include <assert.h>
-#include <inttypes.h>
-
-static void notify_listeners(enum nb_event event,
- struct nb * nb,
- struct nbs * nbs)
-{
- struct list_head * p = NULL;
-
- pthread_mutex_lock(&nbs->notifiers_lock);
-
- list_for_each(p, &nbs->notifiers) {
- struct nb_notifier * e =
- list_entry(p, struct nb_notifier, next);
- if (e->notify_call(event, nb->conn))
- log_err("Listener reported an error.");
- }
-
- pthread_mutex_unlock(&nbs->notifiers_lock);
-}
-
-struct nbs * nbs_create(void)
-{
- struct nbs * nbs;
-
- nbs = malloc(sizeof(*nbs));
- if (nbs == NULL)
- return NULL;
-
- list_head_init(&nbs->list);
- list_head_init(&nbs->notifiers);
-
- if (pthread_mutex_init(&nbs->list_lock, NULL))
- return NULL;
-
- if (pthread_mutex_init(&nbs->notifiers_lock, NULL)) {
- pthread_mutex_destroy(&nbs->list_lock);
- return NULL;
- }
-
- return nbs;
-}
-
-void nbs_destroy(struct nbs * nbs)
-{
- struct list_head * p = NULL;
- struct list_head * n = NULL;
-
- assert(nbs);
-
- pthread_mutex_lock(&nbs->list_lock);
-
- list_for_each_safe(p, n, &nbs->list) {
- struct nb * e = list_entry(p, struct nb, next);
- list_del(&e->next);
- free(e);
- }
-
- pthread_mutex_unlock(&nbs->list_lock);
-
- pthread_mutex_destroy(&nbs->list_lock);
- pthread_mutex_destroy(&nbs->notifiers_lock);
-
- free(nbs);
-}
-
-int nbs_add(struct nbs * nbs,
- struct conn conn)
-{
- struct nb * nb;
-
- assert(nbs);
-
- nb = malloc(sizeof(*nb));
- if (nb == NULL)
- return -ENOMEM;
-
- nb->conn = conn;
-
- pthread_mutex_lock(&nbs->list_lock);
-
- list_add(&nb->next, &nbs->list);
-
- notify_listeners(NEIGHBOR_ADDED, nb, nbs);
-
- pthread_mutex_unlock(&nbs->list_lock);
-
- log_info("Added neighbor with fd %d and address %" PRIu64 " to list.",
- conn.flow_info.fd, conn.conn_info.addr);
-
- return 0;
-}
-
-int nbs_update_qos(struct nbs * nbs,
- int fd,
- qosspec_t qs)
-{
- 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.flow_info.fd == fd) {
- e->conn.flow_info.qs = qs;
-
- notify_listeners(NEIGHBOR_QOS_CHANGE, e, nbs);
-
- pthread_mutex_unlock(&nbs->list_lock);
- return 0;
- }
- }
-
- pthread_mutex_unlock(&nbs->list_lock);
-
- return -1;
-}
-
-int nbs_del(struct nbs * nbs,
- int fd)
-{
- struct list_head * p = NULL;
- struct list_head * n = NULL;
-
- assert(nbs);
-
- pthread_mutex_lock(&nbs->list_lock);
-
- list_for_each_safe(p, n, &nbs->list) {
- struct nb * e = list_entry(p, struct nb, next);
- if (e->conn.flow_info.fd == fd) {
- notify_listeners(NEIGHBOR_REMOVED, e, nbs);
- list_del(&e->next);
- free(e);
- pthread_mutex_unlock(&nbs->list_lock);
- return 0;
- }
- }
-
- pthread_mutex_unlock(&nbs->list_lock);
-
- 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)
-{
- assert(nbs);
- assert(notify);
-
- pthread_mutex_lock(&nbs->notifiers_lock);
-
- list_add(&notify->next, &nbs->notifiers);
-
- pthread_mutex_unlock(&nbs->notifiers_lock);
-
- return 0;
-}
-
-int nbs_unreg_notifier(struct nbs * nbs,
- struct nb_notifier * notify)
-{
- struct list_head * p = NULL;
- struct list_head * n = NULL;
-
- pthread_mutex_lock(&nbs->notifiers_lock);
-
- list_for_each_safe(p, n, &nbs->notifiers) {
- struct nb_notifier * e =
- list_entry(p, struct nb_notifier, next);
- if (e == notify) {
- list_del(&e->next);
- pthread_mutex_unlock(&nbs->notifiers_lock);
- return 0;
- }
- }
-
- pthread_mutex_unlock(&nbs->notifiers_lock);
-
- return -1;
-}
diff --git a/src/ipcpd/normal/neighbors.h b/src/ipcpd/normal/neighbors.h
deleted file mode 100644
index 9c5a6e50..00000000
--- a/src/ipcpd/normal/neighbors.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * Neighbors
- *
- * Dimitri Staessens <dimitri.staessens@ugent.be>
- * Sander Vrijders <sander.vrijders@ugent.be>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., http://www.fsf.org/about/contact/.
- */
-
-#ifndef OUROBOROS_IPCPD_NORMAL_NEIGHBORS_H
-#define OUROBOROS_IPCPD_NORMAL_NEIGHBORS_H
-
-#include <ouroboros/ipcp.h>
-#include <ouroboros/list.h>
-#include <ouroboros/qos.h>
-#include <ouroboros/fqueue.h>
-#include <ouroboros/cacep.h>
-
-#include "ae.h"
-
-enum nb_event {
- NEIGHBOR_ADDED,
- NEIGHBOR_REMOVED,
- NEIGHBOR_QOS_CHANGE
-};
-
-typedef int (* nb_notify_t)(enum nb_event event,
- struct conn conn);
-
-struct nb {
- struct list_head next;
- struct conn conn;
-};
-
-struct nb_notifier {
- struct list_head next;
- nb_notify_t notify_call;
-};
-
-struct nbs {
- struct list_head notifiers;
- pthread_mutex_t notifiers_lock;
-
- struct list_head list;
- pthread_mutex_t list_lock;
-};
-
-struct nbs * nbs_create(void);
-
-void nbs_destroy(struct nbs * nbs);
-
-int nbs_add(struct nbs * nbs,
- struct conn conn);
-
-int nbs_update_qos(struct nbs * nbs,
- int fd,
- qosspec_t qs);
-
-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);
-
-int nbs_unreg_notifier(struct nbs * nbs,
- struct nb_notifier * notify);
-
-#endif
diff --git a/src/ipcpd/normal/pol-routing-ops.h b/src/ipcpd/normal/pol-routing-ops.h
index 0fec10fc..9804d5ad 100644
--- a/src/ipcpd/normal/pol-routing-ops.h
+++ b/src/ipcpd/normal/pol-routing-ops.h
@@ -26,7 +26,7 @@
#include "pff.h"
struct pol_routing_ops {
- int (* init)(struct nbs * nbs);
+ int (* init)(void);
void (* fini)(void);
diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c
index 7a5a785e..0c4648c5 100644
--- a/src/ipcpd/normal/pol/flat.c
+++ b/src/ipcpd/normal/pol/flat.c
@@ -27,11 +27,9 @@
#include <ouroboros/logs.h>
#include <ouroboros/errno.h>
#include <ouroboros/time_utils.h>
-#include <ouroboros/rib.h>
#include <ouroboros/utils.h>
#include "ipcp.h"
-#include "ribconfig.h"
#include <time.h>
#include <stdlib.h>
diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c
index 512ced7f..7df09bce 100644
--- a/src/ipcpd/normal/pol/link_state.c
+++ b/src/ipcpd/normal/pol/link_state.c
@@ -27,14 +27,16 @@
#include <ouroboros/errno.h>
#include <ouroboros/list.h>
#include <ouroboros/logs.h>
-#include <ouroboros/rib.h>
-#include <ouroboros/rqueue.h>
+#include <ouroboros/utils.h>
+#include <ouroboros/notifier.h>
+#include <ouroboros/dev.h>
+#include <ouroboros/fqueue.h>
-#include "ribmgr.h"
-#include "ribconfig.h"
+#include "ae.h"
+#include "connmgr.h"
#include "graph.h"
-#include "neighbors.h"
#include "ipcp.h"
+#include "link_state.h"
#include "pff.h"
#include <assert.h>
@@ -43,39 +45,230 @@
#include <string.h>
#include <pthread.h>
-#include "fso.pb-c.h"
-typedef Fso fso_t;
+#include "link_state.pb-c.h"
+typedef LinkStateMsg link_state_msg_t;
-#define BUF_SIZE 256
-#define RECALC_TIME 4
+#define RECALC_TIME 4
+#define LS_UPDATE_TIME 15
+#define LS_TIMEO 60
+#define LSA_MAX_LEN 128
+
+#ifndef CLOCK_REALTIME_COARSE
+#define CLOCK_REALTIME_COARSE CLOCK_REALTIME
+#endif
struct routing_i {
struct pff * pff;
pthread_t calculator;
};
+/* TODO: link weight support. */
+struct adjacency {
+ struct list_head next;
+
+ uint64_t dst;
+ uint64_t src;
+
+ time_t stamp;
+};
+
+enum nb_type {
+ NB_DT = 0,
+ NB_MGMT
+};
+
+struct nb {
+ struct list_head next;
+
+ uint64_t addr;
+ int fd;
+ enum nb_type type;
+};
+
struct {
- struct nbs * nbs;
- struct nb_notifier nb_notifier;
+ struct list_head nbs;
+ fset_t * mgmt_set;
- struct graph * graph;
+ struct list_head db;
- ro_set_t * set;
- rqueue_t * queue;
- pthread_t rib_listener;
-} link_state;
+ pthread_rwlock_t db_lock;
-/* Take under neighbors lock */
-static int addr_to_fd(uint64_t addr)
+ struct graph * graph;
+
+ pthread_t lsupdate;
+ pthread_t lsreader;
+ pthread_t listener;
+} ls;
+
+struct pol_routing_ops link_state_ops = {
+ .init = link_state_init,
+ .fini = link_state_fini,
+ .routing_i_create = link_state_routing_i_create,
+ .routing_i_destroy = link_state_routing_i_destroy
+};
+
+static int lsdb_add_nb(uint64_t addr,
+ int fd,
+ enum nb_type type)
{
- struct list_head * p = NULL;
+ struct list_head * p;
+ struct nb * nb;
+
+ pthread_rwlock_wrlock(&ls.db_lock);
+
+ list_for_each(p, &ls.nbs) {
+ struct nb * el = list_entry(p, struct nb, next);
+ if (el->addr == addr && el->type == type) {
+ log_dbg("Already know %s neighbor %" PRIu64 ".",
+ type == NB_DT ? "dt" : "mgmt", addr);
+ if (el->fd != fd) {
+ log_warn("Existing neighbor assigned new fd.");
+ el->fd = fd;
+ }
+ pthread_rwlock_unlock(&ls.db_lock);
+ return -EPERM;
+ }
- list_for_each(p, &link_state.nbs->list) {
- struct nb * e = list_entry(p, struct nb, next);
- if (e->conn.conn_info.addr == addr)
- return e->conn.flow_info.fd;
+ if (addr > el->addr)
+ break;
}
+ nb = malloc(sizeof(*nb));
+ if (nb == NULL) {
+ pthread_rwlock_unlock(&ls.db_lock);
+ return -ENOMEM;
+ }
+
+ nb->addr = addr;
+ nb->fd = fd;
+ nb->type = type;
+
+ list_add_tail(&nb->next, p);
+
+ log_dbg("Type %s neighbor %" PRIu64 " added.",
+ nb->type == NB_DT ? "dt" : "mgmt", addr);
+
+ pthread_rwlock_unlock(&ls.db_lock);
+
+ return 0;
+}
+
+static int lsdb_del_nb(uint64_t addr,
+ int fd)
+{
+ struct list_head * p;
+ struct list_head * h;
+
+ pthread_rwlock_wrlock(&ls.db_lock);
+
+ list_for_each_safe(p, h, &ls.nbs) {
+ struct nb * nb = list_entry(p, struct nb, next);
+ if (nb->addr == addr && nb->fd == fd) {
+ list_del(&nb->next);
+ pthread_rwlock_unlock(&ls.db_lock);
+ log_dbg("Type %s neighbor %" PRIu64 " deleted.",
+ nb->type == NB_DT ? "dt" : "mgmt", addr);
+ free(nb);
+ return 0;
+ }
+ }
+
+ pthread_rwlock_unlock(&ls.db_lock);
+
+ return -EPERM;
+}
+
+static int lsdb_add_link(uint64_t src,
+ uint64_t dst,
+ qosspec_t * qs)
+{
+ struct list_head * p;
+ struct adjacency * adj;
+ struct timespec now;
+
+ clock_gettime(CLOCK_REALTIME_COARSE, &now);
+
+ pthread_rwlock_wrlock(&ls.db_lock);
+
+ list_for_each(p, &ls.db) {
+ struct adjacency * a = list_entry(p, struct adjacency, next);
+ if (a->dst == dst && a->src == src) {
+ a->stamp = now.tv_sec;
+ pthread_rwlock_unlock(&ls.db_lock);
+ return 0;
+ }
+
+ if (a->dst > dst || (a->dst == dst && a->src > src))
+ break;
+ }
+
+ adj = malloc(sizeof(*adj));
+ if (adj == NULL) {
+ pthread_rwlock_unlock(&ls.db_lock);
+ return -ENOMEM;
+ }
+
+ adj->dst = dst;
+ adj->src = src;
+ adj->stamp = now.tv_sec;
+
+ list_add_tail(&adj->next, p);
+
+ if (graph_update_edge(ls.graph, src, dst, *qs))
+ log_warn("Failed to add edge to graph.");
+
+ log_dbg("Added %" PRIu64 " - %" PRIu64" to lsdb.", adj->src, adj->dst);
+
+ pthread_rwlock_unlock(&ls.db_lock);
+
+ return 0;
+}
+
+static int lsdb_del_link(uint64_t src,
+ uint64_t dst)
+{
+ struct list_head * p;
+ struct list_head * h;
+
+ pthread_rwlock_wrlock(&ls.db_lock);
+
+ list_for_each_safe(p, h, &ls.db) {
+ struct adjacency * a = list_entry(p, struct adjacency, next);
+ if (a->dst == dst && a->src == src) {
+ list_del(&a->next);
+ if (graph_del_edge(ls.graph, src, dst))
+ log_warn("Failed to delete edge from graph.");
+
+ log_dbg("Removed %" PRIu64 " - %" PRIu64" from lsdb.",
+ a->src, a->dst);
+
+ pthread_rwlock_unlock(&ls.db_lock);
+ free(a);
+ return 0;
+ }
+ }
+
+ pthread_rwlock_unlock(&ls.db_lock);
+
+ return -EPERM;
+}
+
+static int nbr_to_fd(uint64_t addr)
+{
+ struct list_head * p;
+
+ pthread_rwlock_rdlock(&ls.db_lock);
+
+ list_for_each(p, &ls.nbs) {
+ struct nb * nb = list_entry(p, struct nb, next);
+ if (nb->addr == addr && nb->type == NB_DT) {
+ pthread_rwlock_unlock(&ls.db_lock);
+ return nb->fd;
+ }
+ }
+
+ pthread_rwlock_unlock(&ls.db_lock);
+
return -1;
}
@@ -91,20 +284,19 @@ static void * calculate_pff(void * o)
while (true) {
table = NULL;
- n_table = graph_routing_table(link_state.graph,
+ n_table = graph_routing_table(ls.graph,
ipcpi.dt_addr, &table);
if (n_table < 0) {
sleep(RECALC_TIME);
continue;
}
- pthread_mutex_lock(&link_state.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);
+ fd = nbr_to_fd(table[i]->nhop);
if (fd == -1)
continue;
@@ -112,7 +304,6 @@ static void * calculate_pff(void * o)
}
pff_unlock(instance->pff);
- pthread_mutex_unlock(&link_state.nbs->list_lock);
freepp(struct routing_table, table, n_table);
sleep(RECALC_TIME);
@@ -121,154 +312,209 @@ static void * calculate_pff(void * o)
return (void *) 0;
}
-static int link_state_neighbor_event(enum nb_event event,
- struct conn conn)
+static void send_lsa(uint64_t dst,
+ uint64_t src)
{
- char path[RIB_MAX_PATH_LEN + 1];
- char fso_name[RIB_MAX_PATH_LEN + 1];
- fso_t fso = FSO__INIT;
- size_t len;
- uint8_t * data;
+ uint8_t buf[LSA_MAX_LEN];
+ link_state_msg_t lsa = LINK_STATE_MSG__INIT;
+ size_t len;
+ struct list_head * p;
- path[0] = '\0';
- sprintf(fso_name, "%" PRIu64 "-%" PRIu64,
- ipcpi.dt_addr, conn.conn_info.addr);
- rib_path_append(rib_path_append(path, ROUTING_NAME), fso_name);
+ lsa.d_addr = dst;
+ lsa.s_addr = src;
- switch (event) {
- case NEIGHBOR_ADDED:
- fso.s_addr = ipcpi.dt_addr;
- fso.d_addr = conn.conn_info.addr;
+ len = link_state_msg__get_packed_size(&lsa);
- len = fso__get_packed_size(&fso);
- if (len == 0)
- return -1;
+ assert(len <= LSA_MAX_LEN);
- data = malloc(len);
- if (data == NULL)
- return -1;
+ link_state_msg__pack(&lsa, buf);
- fso__pack(&fso, data);
+ list_for_each(p, &ls.nbs) {
+ struct nb * nb = list_entry(p, struct nb, next);
+ if (nb->type == NB_MGMT)
+ flow_write(nb->fd, buf, len);
+ }
+}
- if (rib_add(ROUTING_PATH, fso_name)) {
- log_err("Failed to add FSO.");
- free(data);
- return -1;
- }
+static void * lsupdate(void * o)
+{
+ struct list_head * p;
+ struct list_head * h;
+ struct timespec now;
- if (rib_put(path, data, len)) {
- log_err("Failed to put FSO in RIB.");
- rib_del(path);
- free(data);
- return -1;
- }
+ (void) o;
- log_dbg("Added %s to RIB.", path);
+ while (true) {
+ clock_gettime(CLOCK_REALTIME_COARSE, &now);
+
+ pthread_rwlock_rdlock(&ls.db_lock);
+
+ pthread_cleanup_push((void (*) (void *)) pthread_rwlock_unlock,
+ (void *) &ls.db_lock);
+
+ list_for_each_safe(p, h, &ls.db) {
+ struct adjacency * adj;
+ adj = list_entry(p, struct adjacency, next);
+ if (now.tv_sec - adj->stamp > LS_TIMEO) {
+ list_del(&adj->next);
+ log_dbg("%" PRIu64 " - %" PRIu64" timed out.",
+ adj->src, adj->dst);
+ if (graph_del_edge(ls.graph, adj->src,
+ adj->dst))
+ log_dbg("Failed to delete edge.");
+ free(adj);
+ continue;
+ }
- break;
- case NEIGHBOR_REMOVED:
- if (rib_del(path)) {
- log_err("Failed to remove FSO.");
- return -1;
+ if (adj->src == ipcpi.dt_addr) {
+ send_lsa(adj->src, adj->dst);
+ adj->stamp = now.tv_sec;
+ }
}
- log_dbg("Removed %s from RIB.", path);
+ pthread_cleanup_pop(true);
- break;
- case NEIGHBOR_QOS_CHANGE:
- log_info("Not currently supported.");
- break;
- default:
- log_info("Unsupported event for routing.");
- break;
+ sleep(LS_UPDATE_TIME);
}
- return 0;
+ return (void *) 0;
}
-static int read_fso(char * path,
- int32_t flag)
+static void * ls_conn_handle(void * o)
{
- ssize_t len;
- uint8_t ro[BUF_SIZE];
- fso_t * fso;
- qosspec_t qs;
+ struct conn conn;
- memset(&qs, 0, sizeof(qs));
+ (void) o;
- len = rib_read(path, ro, BUF_SIZE);
- if (len < 0) {
- log_err("Failed to read FSO.");
- return -1;
- }
+ while (true) {
+ if (connmgr_wait(AEID_MGMT, &conn)) {
+ log_err("Failed to get next MGMT connection.");
+ continue;
+ }
- fso = fso__unpack(NULL, len, ro);
- if (fso == NULL) {
- log_err("Failed to unpack.");
- return -1;
- }
+ /* NOTE: connection acceptance policy could be here. */
- if (flag & RO_MODIFY) {
- if (graph_update_edge(link_state.graph,
- fso->s_addr, fso->d_addr, qs)) {
- fso__free_unpacked(fso, NULL);
- return -1;
- }
- } else if (flag & RO_DELETE) {
- if (graph_del_edge(link_state.graph, fso->s_addr, fso->d_addr)) {
- fso__free_unpacked(fso, NULL);
- return -1;
- }
+ notifier_event(NOTIFY_MGMT_CONN_ADD, &conn);
}
- fso__free_unpacked(fso, NULL);
-
return 0;
}
-static void * rib_listener(void * o)
+
+static void forward_lsm(uint8_t * buf,
+ size_t len,
+ int in_fd)
{
- int32_t flag;
- char path[RIB_MAX_PATH_LEN + 1];
- char ** children;
- ssize_t len;
- int i;
+ struct list_head * p;
- (void) o;
+ pthread_rwlock_rdlock(&ls.db_lock);
- if (ro_set_add(link_state.set, ROUTING_PATH, RO_MODIFY | RO_DELETE)) {
- log_err("Failed to add to RO set");
- return (void * ) -1;
+ list_for_each(p, &ls.nbs) {
+ struct nb * nb = list_entry(p, struct nb, next);
+ if (nb->type == NB_MGMT && nb->fd != in_fd)
+ flow_write(nb->fd, buf, len);
}
- len = rib_children(ROUTING_PATH, &children);
- if (len < 0) {
- log_err("Failed to retrieve children.");
+ pthread_rwlock_unlock(&ls.db_lock);
+}
+
+static void * lsreader(void * o)
+{
+ fqueue_t * fq;
+ int ret;
+ uint8_t buf[LSA_MAX_LEN];
+ size_t len;
+ int fd;
+ qosspec_t qs;
+
+ (void) o;
+
+ memset(&qs, 0, sizeof(qs));
+
+ fq = fqueue_create();
+ if (fq == NULL)
return (void *) -1;
- }
- for (i = 0; i < len; i++) {
- if (read_fso(children[i], RO_CREATE)) {
- log_err("Failed to parse FSO.");
+ pthread_cleanup_push((void (*) (void *)) fqueue_destroy,
+ (void *) fq);
+
+ while (true) {
+ ret = fevent(ls.mgmt_set, fq, NULL);
+ if (ret < 0) {
+ log_warn("Event error: %d.", ret);
continue;
}
- }
- while (rib_event_wait(link_state.set, link_state.queue, NULL) == 0) {
- path[0] = '\0';
- flag = rqueue_next(link_state.queue, path);
- if (flag < 0)
- continue;
+ while ((fd = fqueue_next(fq)) >= 0) {
+ link_state_msg_t * msg;
+ len = flow_read(fd, buf, LSA_MAX_LEN);
+ if (len <= 0)
+ continue;
- if (read_fso(path, flag)) {
- log_err("Failed to parse FSO.");
- continue;
+ msg = link_state_msg__unpack(NULL, len, buf);
+ if (msg == NULL) {
+ log_dbg("Failed to unpack link state message.");
+ continue;
+ }
+
+ lsdb_add_link(msg->s_addr, msg->d_addr, &qs);
+
+ link_state_msg__free_unpacked(msg, NULL);
+
+ forward_lsm(buf, len, fd);
}
}
+ pthread_cleanup_pop(true);
+
return (void *) 0;
}
+static void handle_event(int event,
+ const void * o)
+{
+ /* FIXME: Apply correct QoS on graph */
+ struct conn * c;
+ qosspec_t qs;
+
+ c = (struct conn *) o;
+
+ memset(&qs, 0, sizeof(qs));
+
+ switch (event) {
+ case NOTIFY_DT_CONN_ADD:
+ if (lsdb_add_nb(c->conn_info.addr, c->flow_info.fd, NB_DT))
+ log_dbg("Failed to add neighbor to LSDB.");
+
+ if (lsdb_add_link(ipcpi.dt_addr, c->conn_info.addr, &qs))
+ log_dbg("Failed to add adjacency to LSDB.");
+ break;
+ case NOTIFY_DT_CONN_DEL:
+ if (lsdb_del_nb(c->conn_info.addr, c->flow_info.fd))
+ log_dbg("Failed to delete neighbor from LSDB.");
+
+ if (lsdb_del_link(ipcpi.dt_addr, c->conn_info.addr))
+ log_dbg("Local link was not in LSDB.");
+ break;
+ case NOTIFY_DT_CONN_QOS:
+ log_dbg("QoS changes currently unsupported.");
+ break;
+ case NOTIFY_MGMT_CONN_ADD:
+ fset_add(ls.mgmt_set, c->flow_info.fd);
+ if (lsdb_add_nb(c->conn_info.addr, c->flow_info.fd, NB_MGMT))
+ log_warn("Failed to add mgmt neighbor to LSDB.");
+ break;
+ case NOTIFY_MGMT_CONN_DEL:
+ fset_del(ls.mgmt_set, c->flow_info.fd);
+ if (lsdb_del_nb(c->conn_info.addr, c->flow_info.fd))
+ log_warn("Failed to add mgmt neighbor to LSDB.");
+ break;
+ default:
+ log_info("Unknown routing event.");
+ break;
+ }
+}
+
struct routing_i * link_state_routing_i_create(struct pff * pff)
{
struct routing_i * tmp;
@@ -281,7 +527,10 @@ struct routing_i * link_state_routing_i_create(struct pff * pff)
tmp->pff = pff;
- pthread_create(&tmp->calculator, NULL, calculate_pff, (void *) tmp);
+ if (pthread_create(&tmp->calculator, NULL, calculate_pff, tmp)) {
+ free(tmp);
+ return NULL;
+ }
return tmp;
}
@@ -297,61 +546,100 @@ void link_state_routing_i_destroy(struct routing_i * instance)
free(instance);
}
-int link_state_init(struct nbs * nbs)
+int link_state_init(void)
{
- link_state.graph = graph_create();
- if (link_state.graph == NULL)
+ struct conn_info info;
+
+ memset(&info, 0, sizeof(info));
+
+ strcpy(info.ae_name, LS_AE);
+ strcpy(info.protocol, LS_PROTO);
+ info.pref_version = 1;
+ info.pref_syntax = PROTO_GPB;
+ info.addr = ipcpi.dt_addr;
+
+ ls.graph = graph_create();
+ if (ls.graph == NULL)
goto fail_graph;
- if (rib_add(RIB_ROOT, ROUTING_NAME))
- goto fail_rib_add;
+ if (notifier_reg(handle_event))
+ goto fail_notifier_reg;
+
+ if (pthread_rwlock_init(&ls.db_lock, NULL))
+ goto fail_db_lock_init;
+
+ if (connmgr_ae_init(AEID_MGMT, &info))
+ goto fail_connmgr_ae_init;
- link_state.nbs = nbs;
+ ls.mgmt_set = fset_create();
+ if (ls.mgmt_set == NULL)
+ goto fail_fset_create;
- link_state.nb_notifier.notify_call = link_state_neighbor_event;
- if (nbs_reg_notifier(link_state.nbs, &link_state.nb_notifier))
- goto fail_nbs_reg_notifier;
+ list_head_init(&ls.db);
+ list_head_init(&ls.nbs);
- link_state.set = ro_set_create();
- if (link_state.set == NULL)
- goto fail_ro_set_create;
+ if (pthread_create(&ls.lsupdate, NULL, lsupdate, NULL))
+ goto fail_pthread_create_lsupdate;
- link_state.queue = rqueue_create();
- if (link_state.queue == NULL)
- goto fail_rqueue_create;
+ if (pthread_create(&ls.lsreader, NULL, lsreader, NULL))
+ goto fail_pthread_create_lsreader;
- if (pthread_create(&link_state.rib_listener, NULL, rib_listener, NULL))
- goto fail_listener_create;
+ if (pthread_create(&ls.listener, NULL, ls_conn_handle, NULL))
+ goto fail_pthread_create_listener;
return 0;
- fail_listener_create:
- ro_set_destroy(link_state.set);
- fail_rqueue_create:
- ro_set_destroy(link_state.set);
- fail_ro_set_create:
- nbs_unreg_notifier(link_state.nbs, &link_state.nb_notifier);
- fail_nbs_reg_notifier:
- rib_del(ROUTING_PATH);
- fail_rib_add:
- graph_destroy(link_state.graph);
+ fail_pthread_create_listener:
+ pthread_cancel(ls.lsreader);
+ pthread_join(ls.lsreader, NULL);
+ fail_pthread_create_lsreader:
+ pthread_cancel(ls.lsupdate);
+ pthread_join(ls.lsupdate, NULL);
+ fail_pthread_create_lsupdate:
+ fset_destroy(ls.mgmt_set);
+ fail_fset_create:
+ connmgr_ae_fini(AEID_MGMT);
+ fail_connmgr_ae_init:
+ pthread_rwlock_destroy(&ls.db_lock);
+ fail_db_lock_init:
+ notifier_unreg(handle_event);
+ fail_notifier_reg:
+ graph_destroy(ls.graph);
fail_graph:
return -1;
}
void link_state_fini(void)
{
- pthread_cancel(link_state.rib_listener);
+ struct list_head * p;
+ struct list_head * h;
+
+ pthread_cancel(ls.listener);
+ pthread_join(ls.listener, NULL);
+
+ pthread_cancel(ls.lsreader);
+ pthread_join(ls.lsreader, NULL);
- pthread_join(link_state.rib_listener, NULL);
+ pthread_cancel(ls.lsupdate);
+ pthread_join(ls.lsupdate, NULL);
- rqueue_destroy(link_state.queue);
+ fset_destroy(ls.mgmt_set);
- ro_set_destroy(link_state.set);
+ connmgr_ae_fini(AEID_MGMT);
+
+ graph_destroy(ls.graph);
+
+ pthread_rwlock_wrlock(&ls.db_lock);
+
+ list_for_each_safe(p, h, &ls.db) {
+ struct adjacency * a = list_entry(p, struct adjacency, next);
+ list_del(&a->next);
+ free(a);
+ }
- graph_destroy(link_state.graph);
+ pthread_rwlock_unlock(&ls.db_lock);
- rib_del(ROUTING_PATH);
+ pthread_rwlock_destroy(&ls.db_lock);
- nbs_unreg_notifier(link_state.nbs, &link_state.nb_notifier);
+ notifier_unreg(handle_event);
}
diff --git a/src/ipcpd/normal/pol/link_state.h b/src/ipcpd/normal/pol/link_state.h
index 9b96bcab..58f90d91 100644
--- a/src/ipcpd/normal/pol/link_state.h
+++ b/src/ipcpd/normal/pol/link_state.h
@@ -23,9 +23,12 @@
#ifndef OUROBOROS_IPCPD_NORMAL_POL_LINK_STATE_H
#define OUROBOROS_IPCPD_NORMAL_POL_LINK_STATE_H
+#define LS_AE "Management"
+#define LS_PROTO "LSP"
+
#include "pol-routing-ops.h"
-int link_state_init(struct nbs * nbs);
+int link_state_init(void);
void link_state_fini(void);
@@ -33,11 +36,6 @@ struct routing_i * link_state_routing_i_create(struct pff * pff);
void link_state_routing_i_destroy(struct routing_i * instance);
-struct pol_routing_ops link_state_ops = {
- .init = link_state_init,
- .fini = link_state_fini,
- .routing_i_create = link_state_routing_i_create,
- .routing_i_destroy = link_state_routing_i_destroy
-};
+struct pol_routing_ops link_state_ops;
#endif /* OUROBOROS_IPCPD_NORMAL_POL_LINK_STATE_H */
diff --git a/src/ipcpd/normal/pol/fso.proto b/src/ipcpd/normal/pol/link_state.proto
index 27a78efd..4e2280b0 100644
--- a/src/ipcpd/normal/pol/fso.proto
+++ b/src/ipcpd/normal/pol/link_state.proto
@@ -1,7 +1,7 @@
/*
* Ouroboros - Copyright (C) 2016 - 2017
*
- * Flow State Object message
+ * Link State message
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
@@ -22,8 +22,8 @@
syntax = "proto2";
-message fso {
- required uint64 s_addr = 1;
- required uint64 d_addr = 2;
+message link_state_msg {
+ required uint64 d_addr = 1;
+ required uint64 s_addr = 2;
/* Add QoS parameters of link here */
};
diff --git a/src/ipcpd/normal/ribconfig.h b/src/ipcpd/normal/ribconfig.h
deleted file mode 100644
index f6d10133..00000000
--- a/src/ipcpd/normal/ribconfig.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * Normal IPC Process - RIB configuration
- *
- * Dimitri Staessens <dimitri.staessens@ugent.be>
- * Sander Vrijders <sander.vrijders@ugent.be>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., http://www.fsf.org/about/contact/.
- */
-
-#ifndef OUROBOROS_IPCPD_NORMAL_RIB_CONFIG_H
-#define OUROBOROS_IPCPD_NORMAL_RIB_CONFIG_H
-
-/* RIB configuration for normal */
-#define RIB_MAX_PATH_LEN 256
-
-#define DLR "/"
-#define ROUTING_NAME "fsdb"
-#define ROUTING_PATH DLR ROUTING_NAME
-
-#endif /* OUROBOROS_IPCPD_NORMAL_RIB_CONFIG_H */
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
deleted file mode 100644
index a5e7d6ce..00000000
--- a/src/ipcpd/normal/ribmgr.c
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * RIB manager of the IPC Process
- *
- * Dimitri Staessens <dimitri.staessens@ugent.be>
- * Sander Vrijders <sander.vrijders@ugent.be>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., http://www.fsf.org/about/contact/.
- */
-
-#define _POSIX_C_SOURCE 200112L
-
-#define OUROBOROS_PREFIX "rib-manager"
-
-#include <ouroboros/logs.h>
-#include <ouroboros/cdap.h>
-#include <ouroboros/list.h>
-#include <ouroboros/time_utils.h>
-#include <ouroboros/ipcp-dev.h>
-#include <ouroboros/errno.h>
-#include <ouroboros/dev.h>
-#include <ouroboros/fqueue.h>
-#include <ouroboros/rib.h>
-
-#include "ae.h"
-#include "connmgr.h"
-#include "ipcp.h"
-#include "neighbors.h"
-#include "ribconfig.h"
-#include "ribmgr.h"
-
-#include <stdlib.h>
-#include <pthread.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-
-#define MGMT_AE "Management"
-#define RIB_SYNC_TIMEOUT 1
-
-enum ribmgr_state {
- RIBMGR_NULL = 0,
- RIBMGR_INIT,
- RIBMGR_OPERATIONAL,
- RIBMGR_SHUTDOWN
-};
-
-struct {
- struct cdap * cdap;
-
- pthread_t reader;
- pthread_t sync;
-
- struct nbs * nbs;
- struct ae * ae;
-
- struct nb_notifier nb_notifier;
-
- pthread_rwlock_t state_lock;
- enum ribmgr_state state;
-} ribmgr;
-
-static int ribmgr_neighbor_event(enum nb_event event,
- struct conn conn)
-{
- switch (event) {
- case NEIGHBOR_ADDED:
- cdap_add_flow(ribmgr.cdap, conn.flow_info.fd);
- break;
- case NEIGHBOR_REMOVED:
- cdap_del_flow(ribmgr.cdap, conn.flow_info.fd);
- break;
- default:
- /* Don't care about other events */
- break;
- }
-
- return 0;
-}
-
-static enum ribmgr_state ribmgr_get_state(void)
-{
- enum ribmgr_state state;
-
- pthread_rwlock_rdlock(&ribmgr.state_lock);
-
- state = ribmgr.state;
-
- pthread_rwlock_unlock(&ribmgr.state_lock);
-
- return state;
-}
-
-static void ribmgr_set_state(enum ribmgr_state state)
-{
- pthread_rwlock_wrlock(&ribmgr.state_lock);
-
- ribmgr.state = state;
-
- pthread_rwlock_unlock(&ribmgr.state_lock);
-}
-
-static void * reader(void * o)
-{
- cdap_key_t key;
- enum cdap_opcode oc;
- char * name;
- uint8_t * data;
- size_t len;
- ssize_t slen;
- uint32_t flags;
- uint8_t * buf;
- int rval;
-
- (void) o;
-
- while (ribmgr_get_state() == RIBMGR_OPERATIONAL) {
- key = cdap_request_wait(ribmgr.cdap, &oc, &name, &data,
- (size_t *) &len , &flags);
- assert(key != -EINVAL);
-
- if (key == INVALID_CDAP_KEY) {
- log_warn("Bad CDAP request.");
- continue;
- }
-
- assert(name);
- assert(strlen(name));
-
- switch (oc) {
- case CDAP_READ:
- assert(len == 0);
- slen = rib_pack(name, &buf, PACK_HASH_ROOT);
- if (slen < 0) {
- log_err("Failed to pack %s.", name);
- cdap_reply_send(ribmgr.cdap, key, -1, NULL, 0);
- free(name);
- continue;
- }
-
- log_dbg("Packed %s (%zu bytes).", name, slen);
-
- free(name);
-
- if (cdap_reply_send(ribmgr.cdap, key, 0, buf, slen)) {
- log_err("Failed to send CDAP reply.");
- free(buf);
- continue;
- }
-
- free(buf);
- break;
- case CDAP_WRITE:
- assert(len);
- assert(data);
-
- rval = rib_unpack(data, len, 0);
- switch(rval) {
- case 0:
- break;
- case -EFAULT:
- log_warn("Hash mismatch, not in sync.");
- free(data);
- break;
- default:
- log_warn("Error unpacking %s.", name);
- cdap_reply_send(ribmgr.cdap, key, -1, NULL, 0);
- free(name);
- free(data);
- continue;
- }
-
- free(name);
-
- if (cdap_reply_send(ribmgr.cdap, key, 0, NULL, 0)) {
- log_err("Failed to send CDAP reply.");
- continue;
- }
- break;
- case CDAP_CREATE:
- assert(len);
- assert(data);
-
- rval = rib_unpack(data, len, UNPACK_CREATE);
- switch(rval) {
- case 0:
- break;
- case -EFAULT:
- log_warn("Hash mismatch, not yet in sync.");
- free(data);
- break;
- default:
- log_warn("Error unpacking %s.", name);
- cdap_reply_send(ribmgr.cdap, key, -1, NULL, 0);
- free(name);
- free(data);
- continue;
- }
-
- free(name);
-
- if (cdap_reply_send(ribmgr.cdap, key, 0, NULL, 0)) {
- log_err("Failed to send CDAP reply.");
- continue;
- }
- break;
- case CDAP_DELETE:
- assert(len == 0);
- if (rib_del(name)) {
- log_warn("Failed deleting %s.", name);
- cdap_reply_send(ribmgr.cdap, key, -1, NULL, 0);
- }
-
- free(name);
-
- if (cdap_reply_send(ribmgr.cdap, key, 0, NULL, 0)) {
- log_err("Failed to send CDAP reply.");
- continue;
- }
- break;
- case CDAP_START:
- case CDAP_STOP:
- log_warn("Unsupported CDAP command.");
- if (len)
- free(data);
- break;
- default:
- log_err("Bad CDAP command.");
- if (len)
- free(data);
- break;
- }
- }
-
- return (void *) 0;
-}
-
-char path[RIB_MAX_PATH_LEN + 1];
-
-static void path_reset(void) {
- path[strlen(RIB_ROOT)] = '\0';
- assert(strcmp(path, RIB_ROOT) == 0);
-}
-
-static int ribmgr_sync(const char * path)
-{
- uint8_t * buf;
- ssize_t len;
- cdap_key_t * keys;
-
- len = rib_pack(path, &buf, PACK_HASH_ALL);
- if (len < 0) {
- log_warn("Failed to pack %s.", path);
- return -1;
- }
-
- keys = cdap_request_send(ribmgr.cdap, CDAP_CREATE, path, buf, len, 0);
- if (keys != NULL) {
- cdap_key_t * key = keys;
- while (*key != INVALID_CDAP_KEY)
- cdap_reply_wait(ribmgr.cdap, *(key++), NULL, NULL);
- free(keys);
- }
-
- free(buf);
-
- return 0;
-}
-
-/* FIXME: Temporary thread, syncs rib with neighbors every second */
-static void * sync_rib(void *o)
-{
- char ** children;
- ssize_t ch;
-
- (void) o;
-
- strcpy(path, RIB_ROOT);
-
- while (ribmgr_get_state() == RIBMGR_OPERATIONAL) {
- sleep(RIB_SYNC_TIMEOUT);
-
- ch = rib_children(RIB_ROOT, &children);
- if (ch <= 0)
- continue;
-
- while (ch > 0) {
- path_reset();
-
- rib_path_append(path, children[--ch]);
- free(children[ch]);
-
- /* Sync fsdb */
- if (strcmp(path, ROUTING_PATH) == 0)
- ribmgr_sync(path);
- }
-
- free(children);
- }
-
- return (void *) 0;
-}
-
-int ribmgr_init(void)
-{
- struct conn_info info;
-
- memset(&info, 0, sizeof(info));
-
- strcpy(info.ae_name, MGMT_AE);
- strcpy(info.protocol, CDAP_PROTO);
- info.pref_version = 1;
- info.pref_syntax = PROTO_GPB;
- info.addr = 0;
-
- ribmgr.nbs = nbs_create();
- if (ribmgr.nbs == NULL) {
- log_err("Failed to create neighbors.");
- goto fail_nbs_create;
- }
-
- if (connmgr_ae_init(AEID_MGMT, &info, ribmgr.nbs)) {
- log_err("Failed to register with connmgr.");
- goto fail_connmgr_ae_init;
- };
-
- ribmgr.cdap = cdap_create();
- if (ribmgr.cdap == NULL) {
- log_err("Failed to create CDAP instance.");
- goto fail_cdap_create;
- }
-
- ribmgr.nb_notifier.notify_call = ribmgr_neighbor_event;
- if (nbs_reg_notifier(ribmgr.nbs, &ribmgr.nb_notifier)) {
- log_err("Failed to register notifier.");
- goto fail_nbs_reg_notifier;
- }
-
- if (pthread_rwlock_init(&ribmgr.state_lock, NULL)) {
- log_err("Failed to init rwlock.");
- goto fail_rwlock_init;
- }
-
- ribmgr.state = RIBMGR_INIT;
-
- return 0;
-
- fail_rwlock_init:
- nbs_unreg_notifier(ribmgr.nbs, &ribmgr.nb_notifier);
- fail_nbs_reg_notifier:
- cdap_destroy(ribmgr.cdap);
- fail_cdap_create:
- connmgr_ae_fini(AEID_MGMT);
- fail_connmgr_ae_init:
- nbs_destroy(ribmgr.nbs);
- fail_nbs_create:
- return -1;
-}
-
-void ribmgr_fini(void)
-{
- if (ribmgr_get_state() == RIBMGR_SHUTDOWN) {
- pthread_join(ribmgr.reader, NULL);
- pthread_join(ribmgr.sync, NULL);
- }
-
- nbs_unreg_notifier(ribmgr.nbs, &ribmgr.nb_notifier);
- cdap_destroy(ribmgr.cdap);
- nbs_destroy(ribmgr.nbs);
-
- connmgr_ae_fini(AEID_MGMT);
-}
-
-int ribmgr_start(void)
-{
- ribmgr_set_state(RIBMGR_OPERATIONAL);
-
- if (pthread_create(&ribmgr.sync, NULL, sync_rib, NULL)) {
- ribmgr_set_state(RIBMGR_NULL);
- return -1;
- }
-
- if (pthread_create(&ribmgr.reader, NULL, reader, NULL)) {
- ribmgr_set_state(RIBMGR_SHUTDOWN);
- pthread_cancel(ribmgr.reader);
- return -1;
- }
-
- return 0;
-}
-
-void ribmgr_stop(void)
-{
- if (ribmgr_get_state() == RIBMGR_OPERATIONAL) {
- ribmgr_set_state(RIBMGR_SHUTDOWN);
- pthread_cancel(ribmgr.reader);
- }
-}
-
-int ribmgr_disseminate(char * path,
- enum diss_target target,
- enum diss_freq freq,
- size_t delay)
-{
- (void) path;
- (void) target;
- (void) freq;
- (void) delay;
-
- return 0;
-}
diff --git a/src/ipcpd/normal/ribmgr.h b/src/ipcpd/normal/ribmgr.h
deleted file mode 100644
index 20f87548..00000000
--- a/src/ipcpd/normal/ribmgr.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * RIB manager of the IPC Process
- *
- * Dimitri Staessens <dimitri.staessens@ugent.be>
- * Sander Vrijders <sander.vrijders@ugent.be>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., http://www.fsf.org/about/contact/.
- */
-
-#ifndef OUROBOROS_IPCPD_NORMAL_RIBMGR_H
-#define OUROBOROS_IPCPD_NORMAL_RIBMGR_H
-
-#include <ouroboros/ipcp.h>
-#include <ouroboros/utils.h>
-#include <ouroboros/qos.h>
-
-enum diss_target {
- NONE = 0,
- NEIGHBORS,
- ALL_MEMBERS
-};
-
-enum diss_freq {
- SINGLE = 0,
- PERIODIC
-};
-
-int ribmgr_init(void);
-
-void ribmgr_fini(void);
-
-int ribmgr_start(void);
-
-void ribmgr_stop(void);
-
-int ribmgr_disseminate(char * path,
- enum diss_target target,
- enum diss_freq freq,
- size_t delay);
-
-#endif /* OUROBOROS_IPCPD_NORMAL_RIBMGR_H */
diff --git a/src/ipcpd/normal/routing.c b/src/ipcpd/normal/routing.c
index 04e6fd76..47ce3518 100644
--- a/src/ipcpd/normal/routing.c
+++ b/src/ipcpd/normal/routing.c
@@ -22,29 +22,24 @@
#define _POSIX_C_SOURCE 200112L
-#define OUROBOROS_PREFIX "routing"
-
-#include <ouroboros/logs.h>
+#include <ouroboros/errno.h>
#include "routing.h"
#include "pol/link_state.h"
-
struct pol_routing_ops * r_ops;
-int routing_init(enum pol_routing pr,
- struct nbs * nbs)
+int routing_init(enum pol_routing pr)
{
switch (pr) {
case LINK_STATE:
r_ops = &link_state_ops;
break;
default:
- log_err("Unknown routing type.");
- return -1;
+ return -ENOTSUP;
}
- return r_ops->init(nbs);
+ return r_ops->init();
}
struct routing_i * routing_i_create(struct pff * pff)
diff --git a/src/ipcpd/normal/routing.h b/src/ipcpd/normal/routing.h
index 0ef11020..6c8cae76 100644
--- a/src/ipcpd/normal/routing.h
+++ b/src/ipcpd/normal/routing.h
@@ -27,12 +27,10 @@
#include <ouroboros/qos.h>
#include "pff.h"
-#include "neighbors.h"
#include <stdint.h>
-int routing_init(enum pol_routing pr,
- struct nbs * nbs);
+int routing_init(enum pol_routing pr);
void routing_fini(void);
diff --git a/src/ipcpd/normal/sdu_sched.c b/src/ipcpd/normal/sdu_sched.c
index c7e799e2..7a82a874 100644
--- a/src/ipcpd/normal/sdu_sched.c
+++ b/src/ipcpd/normal/sdu_sched.c
@@ -38,9 +38,9 @@
#define FD_UPDATE_TIMEOUT 10000 /* nanoseconds */
struct sdu_sched {
- fset_t * set[QOS_CUBE_MAX];
- next_sdu_t callback;
- pthread_t sdu_readers[IPCP_SCHED_THREADS];
+ fset_t * set[QOS_CUBE_MAX];
+ next_sdu_fn_t callback;
+ pthread_t sdu_readers[IPCP_SCHED_THREADS];
};
static void cleanup_reader(void * o)
@@ -95,10 +95,7 @@ static void * sdu_reader(void * o)
continue;
}
- if (sched->callback(fd, i, sdb)) {
- log_warn("Callback reported an error.");
- continue;
- }
+ sched->callback(fd, i, sdb);
}
}
@@ -107,7 +104,7 @@ static void * sdu_reader(void * o)
return (void *) 0;
}
-struct sdu_sched * sdu_sched_create(next_sdu_t callback)
+struct sdu_sched * sdu_sched_create(next_sdu_fn_t callback)
{
struct sdu_sched * sdu_sched;
int i;
diff --git a/src/ipcpd/normal/sdu_sched.h b/src/ipcpd/normal/sdu_sched.h
index 05371452..733f5648 100644
--- a/src/ipcpd/normal/sdu_sched.h
+++ b/src/ipcpd/normal/sdu_sched.h
@@ -26,11 +26,11 @@
#include <ouroboros/ipcp-dev.h>
#include <ouroboros/fqueue.h>
-typedef int (* next_sdu_t)(int fd,
- qoscube_t qc,
- struct shm_du_buff * sdb);
+typedef void (* next_sdu_fn_t)(int fd,
+ qoscube_t qc,
+ struct shm_du_buff * sdb);
-struct sdu_sched * sdu_sched_create(next_sdu_t callback);
+struct sdu_sched * sdu_sched_create(next_sdu_fn_t callback);
void sdu_sched_destroy(struct sdu_sched * sdu_sched);