Merge MMSS node with GMRF context, implement packet handling

This commit is contained in:
Matthias Schiffer 2013-03-18 02:00:48 +01:00
parent 73071f9961
commit 8a8800c818
4 changed files with 46 additions and 12 deletions

View file

@ -58,4 +58,6 @@ size_t gmrf_iface_get_mtu(gmrf_context_t *ctx, gmrf_iface_t *iface);
bool gmrf_iface_send(gmrf_context_t *ctx, gmrf_iface_t *iface, const void *data, size_t len, const gmrf_addr_t *dest);
bool gmrf_iface_send_bc(gmrf_context_t *ctx, gmrf_iface_t *iface, const void *data, size_t len);
typedef void (*gmrf_handle_packet_func)(gmrf_context_t *ctx, gmrf_iface_t *iface, const gmrf_addr_t *source, const void *data, size_t len);
#endif /* _GMRF_GMRF_H_ */

View file

@ -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;
}

View file

@ -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_ */

View file

@ -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;