summaryrefslogtreecommitdiffstats
path: root/mmss
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-03-18 02:00:48 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-03-18 02:00:48 +0100
commit8a8800c818d06fbf7c1dfd16129757a41731dfe5 (patch)
treeb76a59833b0584f6a47b4eb64e362abdf7b5a445 /mmss
parent73071f996142d7cffe61a1922089f8e8b2928e64 (diff)
downloadgmrf-8a8800c818d06fbf7c1dfd16129757a41731dfe5.tar
gmrf-8a8800c818d06fbf7c1dfd16129757a41731dfe5.zip
Merge MMSS node with GMRF context, implement packet handling
Diffstat (limited to 'mmss')
-rw-r--r--mmss/mmss.c41
-rw-r--r--mmss/mmss.h14
-rw-r--r--mmss/types.h1
3 files changed, 44 insertions, 12 deletions
diff --git a/mmss/mmss.c b/mmss/mmss.c
index bcdf3a8..eca99ad 100644
--- a/mmss/mmss.c
+++ b/mmss/mmss.c
@@ -26,12 +26,16 @@
#include "mmss.h"
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
int main() {
mmss_context_t ctx = { .now = 0 };
mmss_network_t net = { .mtu = 1500 };
- mmss_node_t node1 = {}, node2 = {};
+ gmrf_context_t node1 = { .mmss = &ctx }, node2 = { .mmss = &ctx };
gmrf_iface_t iface1 = {}, iface2 = {};
iface1.net = &net;
@@ -48,8 +52,39 @@ int main() {
iface2.network_next = &iface1;
net.interfaces = &iface2;
- gmrf_context_t ctx_node1 = {&ctx, &node1};
- gmrf_context_t ctx_node2 = {&ctx, &node2};
+ node2.next = &node1;
+ gmrf_context_t *nodes = &node2;
+
+ while (true) {
+ int timeout = mmss_queue_timeout(&ctx, &ctx.packet_queue);
+
+ if (timeout < 0) {
+ fprintf(stderr, "Nothing queued, deadlock occured.\n");
+ break;
+ }
+
+ if (timeout > 0) {
+ assert(!mmss_queue_get(&ctx, &ctx.packet_queue));
+
+ ctx.now += timeout;
+ timeout = mmss_queue_timeout(&ctx, &ctx.packet_queue);
+ }
+
+ assert(timeout == 0);
+
+ while (timeout == 0) {
+ mmss_packet_t *packet = mmss_queue_get(&ctx, &ctx.packet_queue);
+ assert(packet);
+
+ packet->dest->node->handle_packet(packet->dest->node, packet->dest,
+ &packet->source->address, packet->data,
+ packet->len);
+
+ free(packet);
+
+ timeout = mmss_queue_timeout(&ctx, &ctx.packet_queue);
+ }
+ }
return 0;
}
diff --git a/mmss/mmss.h b/mmss/mmss.h
index 81a446f..cabd7cd 100644
--- a/mmss/mmss.h
+++ b/mmss/mmss.h
@@ -37,10 +37,13 @@ struct mmss_context {
mmss_queue_t packet_queue;
};
-struct mmss_node {
- mmss_node_t *next;
+struct gmrf_context {
+ gmrf_context_t *next;
+ mmss_context_t *mmss;
gmrf_iface_t *interfaces;
+
+ gmrf_handle_packet_func handle_packet;
};
struct mmss_network {
@@ -66,16 +69,11 @@ struct gmrf_iface {
gmrf_iface_t *node_next;
gmrf_iface_t *network_next;
- mmss_node_t *node;
+ gmrf_context_t *node;
mmss_network_t *net;
gmrf_addr_t address;
};
-struct gmrf_context {
- mmss_context_t *mmss;
- mmss_node_t *node;
-};
-
#endif /* _GMRF_MMSS_MMSS_H_ */
diff --git a/mmss/types.h b/mmss/types.h
index b7fe24d..56e6250 100644
--- a/mmss/types.h
+++ b/mmss/types.h
@@ -28,7 +28,6 @@
#define _GMRF_MMSS_TYPES_H_
typedef struct mmss_context mmss_context_t;
-typedef struct mmss_node mmss_node_t;
typedef struct mmss_network mmss_network_t;
typedef struct mmss_packet mmss_packet_t;