summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/announce.c70
-rw-r--r--src/babel.c5
-rw-r--r--src/babel.h29
-rw-r--r--src/types.h16
5 files changed, 118 insertions, 3 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b962f38..da5e458 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,7 @@
include_directories(${GMRF_INCLUDE_DIR})
add_library(mmss_proto_babel MODULE
+ announce.c
babel.c
neigh.c
send.c
diff --git a/src/announce.c b/src/announce.c
new file mode 100644
index 0000000..dbe7a4c
--- /dev/null
+++ b/src/announce.c
@@ -0,0 +1,70 @@
+/*
+ Copyright (c) 2013, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#include "babel.h"
+
+#include <stdlib.h>
+
+
+gp_babel_announce_t* gp_babel_announce_new(gmrf_t *gmrf, gmrf_context_t *ctx) {
+ gp_babel_announce_t *a = calloc(1, sizeof(gp_babel_announce_t));
+
+ a->metric.metric = a->feasibility_distance.metric = a->last_metric = 0xffff;
+
+ a->next = ctx->announces;
+ ctx->announces = a;
+
+ return a;
+}
+
+gp_babel_announce_t* gp_babel_announce_find(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_node_id_t *node, uint16_t type, uint16_t key) {
+ gp_babel_announce_t *announce;
+ for (announce = ctx->announces; announce; announce = announce->next) {
+ if (gp_babel_node_id_equal(&announce->node, node)
+ && announce->type == type
+ && announce->key == key)
+ return announce;
+ }
+
+ return NULL;
+}
+
+gp_babel_announce_t* gp_babel_announce_get(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_node_id_t *node, uint16_t type, uint16_t key) {
+ gp_babel_announce_t *announce = gp_babel_announce_find(gmrf, ctx, node, type, key);
+
+ if (!announce) {
+ announce = gp_babel_announce_new(gmrf, ctx);
+ announce->node = *node;
+ announce->type = type;
+ announce->key = key;
+ }
+
+ return announce;
+}
+
+void gp_babel_announce_free(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_announce_t *announce) {
+ free(announce);
+}
diff --git a/src/babel.c b/src/babel.c
index 9ae6ff7..56d3ba0 100644
--- a/src/babel.c
+++ b/src/babel.c
@@ -77,6 +77,11 @@ gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) {
gmrf_context_t *ctx = calloc(1, sizeof(gmrf_context_t));
gmrf_random_bytes(gmrf, &ctx->self, sizeof(gp_babel_node_id_t));
+ gp_babel_announce_t *announce = gp_babel_announce_new(gmrf, ctx);
+ announce->node = ctx->self;
+ announce->type = 1;
+ announce->key = 1337;
+
return ctx;
}
diff --git a/src/babel.h b/src/babel.h
index 4e78ca0..3385ec1 100644
--- a/src/babel.h
+++ b/src/babel.h
@@ -39,11 +39,14 @@
#define GP_BABEL_MAINTENANCE_INTERVAL GP_BABEL_HELLO_INTERVAL
+
struct gmrf_context {
gp_babel_node_id_t self;
gp_babel_iface_t *interfaces;
gp_babel_neigh_t *neighbours;
+
+ gp_babel_announce_t *announces;
};
struct gp_babel_iface {
@@ -75,6 +78,27 @@ struct gp_babel_neigh {
uint16_t txcost;
};
+struct gp_babel_announce {
+ gp_babel_announce_t *next;
+
+ gp_babel_node_id_t node;
+ uint16_t type;
+ uint16_t key;
+
+ gp_babel_metric_seqno_t metric;
+ uint16_t last_metric;
+ gp_babel_metric_seqno_t feasibility_distance;
+
+ /* an incomplete announcement is specified by a len value of 0xff with NULL data */
+ uint8_t len;
+ uint8_t *data;
+};
+
+
+static inline bool gp_babel_node_id_equal(const gp_babel_node_id_t *id1, const gp_babel_node_id_t *id2) {
+ return (memcmp(id1->id, id2->id, GP_BABEL_NODE_ID_LENGTH) == 0);
+}
+
static inline gp_babel_iface_t* gp_babel_get_iface(gmrf_context_t *ctx, gmrf_iface_t *gmrf_iface) {
gp_babel_iface_t *iface;
for (iface = ctx->interfaces; iface; iface = iface->next) {
@@ -91,4 +115,9 @@ void gp_babel_handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t
void gp_babel_send_ack(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_neigh_t *neigh, uint16_t nonce);
void gp_babel_send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx);
+gp_babel_announce_t* gp_babel_announce_new(gmrf_t *gmrf, gmrf_context_t *ctx);
+gp_babel_announce_t* gp_babel_announce_find(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_node_id_t *node, uint16_t type, uint16_t key);
+gp_babel_announce_t* gp_babel_announce_get(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_node_id_t *node, uint16_t type, uint16_t key);
+void gp_babel_announce_free(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_announce_t *announce);
+
#endif /* _GMRF_PROTO_BABEL_BABEL_H_ */
diff --git a/src/types.h b/src/types.h
index 1d05c03..58b3721 100644
--- a/src/types.h
+++ b/src/types.h
@@ -30,13 +30,23 @@
#include <gmrf/gmrf.h>
+#define GP_BABEL_NODE_ID_LENGTH 8
+
typedef struct __attribute__((packed)) gp_gabel_node_id {
- uint8_t id[8];
+ uint8_t id[GP_BABEL_NODE_ID_LENGTH];
} gp_babel_node_id_t;
-typedef struct gp_babel_packet gp_babel_packet_t;
-typedef struct gp_babel_packet_buf gp_babel_packet_buf_t;
+typedef struct gp_babel_metric_seqno {
+ uint16_t metric;
+ uint16_t seqno;
+} gp_babel_metric_seqno_t;
+
+
typedef struct gp_babel_iface gp_babel_iface_t;
typedef struct gp_babel_neigh gp_babel_neigh_t;
+typedef struct gp_babel_announce gp_babel_announce_t;
+
+typedef struct gp_babel_packet gp_babel_packet_t;
+typedef struct gp_babel_packet_buf gp_babel_packet_buf_t;
#endif /* _GMRF_PROTO_BABEL_TYPES_H_ */