2013-03-18 00:04:29 +01:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
#ifndef _GMRF_MMSS_MMSS_HPP_
|
|
|
|
#define _GMRF_MMSS_MMSS_HPP_
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
#include "queue.hpp"
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
#include <memory>
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
namespace MMSS {
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
class context_t {
|
|
|
|
public:
|
2013-03-18 00:04:29 +01:00
|
|
|
uint64_t now;
|
2013-07-26 17:45:15 +02:00
|
|
|
timeout_queue_t<packet_t> packet_queue;
|
|
|
|
timeout_queue_t<scheduled_t> scheduled_queue;
|
|
|
|
|
|
|
|
context_t() : now(0), packet_queue(this), scheduled_queue(this) {}
|
2013-03-18 00:04:29 +01:00
|
|
|
};
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
class config_t {
|
|
|
|
public:
|
|
|
|
network_t *networks;
|
2013-07-26 14:22:18 +02:00
|
|
|
gmrf_t *nodes;
|
|
|
|
};
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
class network_t {
|
|
|
|
public:
|
|
|
|
network_t *next;
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
char *name;
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
gmrf_iface_t *interfaces;
|
2013-03-18 00:04:29 +01:00
|
|
|
size_t mtu;
|
|
|
|
};
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
class packet_t {
|
|
|
|
public:
|
2013-03-18 01:03:43 +01:00
|
|
|
uint64_t sent;
|
|
|
|
|
2013-03-18 01:36:34 +01:00
|
|
|
gmrf_iface_t *source;
|
|
|
|
gmrf_iface_t *dest;
|
2013-03-18 01:03:43 +01:00
|
|
|
|
|
|
|
size_t len;
|
2013-07-26 17:45:15 +02:00
|
|
|
std::unique_ptr<uint8_t> data;
|
2013-03-18 01:03:43 +01:00
|
|
|
};
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
class scheduled_t {
|
|
|
|
public:
|
2013-03-18 18:06:24 +01:00
|
|
|
gmrf_t *node;
|
|
|
|
gmrf_scheduled_func f;
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
2013-03-18 19:09:25 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
const protocol_t* load_protocol(const char *module);
|
2013-03-18 19:30:37 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
namespace Config {
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
void add_network(context_t *mmss, config_t *conf, const char *name);
|
2013-03-18 00:04:29 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
}
|
2013-03-18 03:06:20 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
bool read_config(context_t *mmss, config_t *conf, const char *filename);
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
void add_iface(gmrf_t *node, network_t *net, const char *name, const gmrf_addr_t *address);
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
uint64_t now(const context_t *mmss);
|
2013-03-18 19:30:37 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
void dispatch(std::shared_ptr<packet_t> packet);
|
|
|
|
void run_scheduled(std::shared_ptr<scheduled_t> scheduled);
|
2013-03-18 18:06:24 +01:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
void logf(context_t *mmss, int priority, const char *format, ...);
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-03-18 18:06:24 +01:00
|
|
|
|
|
|
|
static inline int max(int a, int b) {
|
|
|
|
return (a > b) ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int min(int a, int b) {
|
|
|
|
return (a < b) ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
static inline size_t alignto(size_t l, size_t a) {
|
|
|
|
return ((l+a-1)/a)*a;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
struct gmrf {
|
|
|
|
gmrf_t *next;
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
char *name;
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
MMSS::context_t *mmss;
|
|
|
|
gmrf_context_t *ctx;
|
|
|
|
gmrf_iface_t *interfaces;
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
unsigned rand_seed;
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
const MMSS::protocol_t *proto;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gmrf_iface {
|
|
|
|
gmrf_iface_t *node_next;
|
|
|
|
gmrf_iface_t *network_next;
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
char *name;
|
|
|
|
gmrf_addr_t address;
|
|
|
|
|
|
|
|
gmrf_t *node;
|
|
|
|
MMSS::network_t *net;
|
|
|
|
};
|
2013-07-26 14:22:18 +02:00
|
|
|
|
2013-07-26 17:45:15 +02:00
|
|
|
#endif /* _GMRF_MMSS_MMSS_HPP_ */
|