From 521e9a5415c11e4d37ad4b2100166470f03eeacf Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 18 Mar 2014 00:18:44 +0100 Subject: [PATCH 01/10] lex: add std namespace to a few function calls --- mmss/lex.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mmss/lex.cpp b/mmss/lex.cpp index 3eb6e24..0b8e28b 100644 --- a/mmss/lex.cpp +++ b/mmss/lex.cpp @@ -123,7 +123,7 @@ int lex_t::io_error(YYSTYPE *yylval) { } int lex_t::syntax_error(YYSTYPE *yylval) { - if (ferror(file)) + if (std::ferror(file)) return io_error(yylval); yylval->error = "syntax error"; @@ -143,7 +143,7 @@ int lex_t::consume_comment(YYSTYPE *yylval, YYLTYPE *yylloc) { prev = current(); } - if (ferror(file)) + if (std::ferror(file)) return io_error(yylval); yylval->error = "unterminated block comment"; @@ -170,7 +170,7 @@ int lex_t::parse_string(YYSTYPE *yylval, YYLTYPE *yylloc) { while (true) { if (!next(yylloc, true)) { - free(buf); + std::free(buf); return unterminated_string(yylval); } @@ -250,7 +250,7 @@ int lex_t::parse_float(YYSTYPE *yylval, YYLTYPE *yylloc) { yylval->fnum = std::strtof(token, &endptr); bool ok = !*endptr; - free(token); + std::free(token); if (!ok) return syntax_error(yylval); From aaddd2e7cde6d23c26573d7da0ab10398037a954 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 18 Mar 2014 18:02:19 +0100 Subject: [PATCH 02/10] Update copyright years --- include/gmrf/gmrf.h | 2 +- include/mmss/protocol.h | 2 +- mmss-protocol/mmss_protocol.c | 2 +- mmss/config.cpp | 2 +- mmss/config.hpp | 2 +- mmss/config.y | 2 +- mmss/context.cpp | 2 +- mmss/context.hpp | 2 +- mmss/event.cpp | 2 +- mmss/event.hpp | 2 +- mmss/gmrf.cpp | 2 +- mmss/iface.cpp | 2 +- mmss/iface.hpp | 2 +- mmss/lex.cpp | 2 +- mmss/lex.hpp | 2 +- mmss/mmss.cpp | 2 +- mmss/network.cpp | 2 +- mmss/network.hpp | 2 +- mmss/node.hpp | 2 +- mmss/now.hpp | 2 +- mmss/protocol.cpp | 2 +- mmss/protocol.hpp | 2 +- mmss/queue.hpp | 2 +- mmss/types.hpp | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/gmrf/gmrf.h b/include/gmrf/gmrf.h index 54e9e90..7fc1535 100644 --- a/include/gmrf/gmrf.h +++ b/include/gmrf/gmrf.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/include/mmss/protocol.h b/include/mmss/protocol.h index 277e325..b0c6286 100644 --- a/include/mmss/protocol.h +++ b/include/mmss/protocol.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss-protocol/mmss_protocol.c b/mmss-protocol/mmss_protocol.c index 16f10e4..3ee8a2f 100644 --- a/mmss-protocol/mmss_protocol.c +++ b/mmss-protocol/mmss_protocol.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/config.cpp b/mmss/config.cpp index 394ca5b..befbecf 100644 --- a/mmss/config.cpp +++ b/mmss/config.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/config.hpp b/mmss/config.hpp index dc21bff..9c6ca28 100644 --- a/mmss/config.hpp +++ b/mmss/config.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/config.y b/mmss/config.y index 4b4647a..63bfcb8 100644 --- a/mmss/config.y +++ b/mmss/config.y @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/context.cpp b/mmss/context.cpp index b4d001d..dd24ae8 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/context.hpp b/mmss/context.hpp index 8282c77..db0c283 100644 --- a/mmss/context.hpp +++ b/mmss/context.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/event.cpp b/mmss/event.cpp index 94aefac..a4b783e 100644 --- a/mmss/event.cpp +++ b/mmss/event.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/event.hpp b/mmss/event.hpp index c346781..62e26f6 100644 --- a/mmss/event.hpp +++ b/mmss/event.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/gmrf.cpp b/mmss/gmrf.cpp index c7b2fbc..1b05b7d 100644 --- a/mmss/gmrf.cpp +++ b/mmss/gmrf.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/iface.cpp b/mmss/iface.cpp index 77b5872..502312c 100644 --- a/mmss/iface.cpp +++ b/mmss/iface.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/iface.hpp b/mmss/iface.hpp index 3b8cc0b..040e271 100644 --- a/mmss/iface.hpp +++ b/mmss/iface.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/lex.cpp b/mmss/lex.cpp index 0b8e28b..61eed16 100644 --- a/mmss/lex.cpp +++ b/mmss/lex.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2012-2014, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/lex.hpp b/mmss/lex.hpp index 19bbd4d..8289748 100644 --- a/mmss/lex.hpp +++ b/mmss/lex.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2012-2014, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/mmss.cpp b/mmss/mmss.cpp index 846d79b..14a6781 100644 --- a/mmss/mmss.cpp +++ b/mmss/mmss.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/network.cpp b/mmss/network.cpp index 9eb3b3a..7550541 100644 --- a/mmss/network.cpp +++ b/mmss/network.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/network.hpp b/mmss/network.hpp index 8ae72f3..7eca164 100644 --- a/mmss/network.hpp +++ b/mmss/network.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/node.hpp b/mmss/node.hpp index feb20c2..06016cc 100644 --- a/mmss/node.hpp +++ b/mmss/node.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/now.hpp b/mmss/now.hpp index 9b14127..8da3fa7 100644 --- a/mmss/now.hpp +++ b/mmss/now.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/protocol.cpp b/mmss/protocol.cpp index 8dcc49d..8134eb8 100644 --- a/mmss/protocol.cpp +++ b/mmss/protocol.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/protocol.hpp b/mmss/protocol.hpp index 0bdc60b..341a028 100644 --- a/mmss/protocol.hpp +++ b/mmss/protocol.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/queue.hpp b/mmss/queue.hpp index 16051ee..a0dd0e5 100644 --- a/mmss/queue.hpp +++ b/mmss/queue.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/mmss/types.hpp b/mmss/types.hpp index bf95437..54a8474 100644 --- a/mmss/types.hpp +++ b/mmss/types.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Matthias Schiffer + Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without From a78a01eaccf4fcbdf34aa994254d7e536040f906 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 21 Mar 2014 04:51:48 +0100 Subject: [PATCH 03/10] Add monitors Monitors are used to log events from the simulated nodes. So far there are a log monitor which just logs the nodes' log messages and a SQLite monitor which does nothing at the moment. --- mmss/CMakeLists.txt | 2 ++ mmss/context.cpp | 23 +++++++++--------- mmss/context.hpp | 37 +++++++++++++++++++++++++++- mmss/gmrf.cpp | 30 ++++++++++++++++++----- mmss/monitor.hpp | 51 +++++++++++++++++++++++++++++++++++++++ mmss/monitor_log.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ mmss/monitor_log.hpp | 46 +++++++++++++++++++++++++++++++++++ mmss/monitor_sqlite.cpp | 49 +++++++++++++++++++++++++++++++++++++ mmss/monitor_sqlite.hpp | 46 +++++++++++++++++++++++++++++++++++ mmss/types.hpp | 1 + 10 files changed, 319 insertions(+), 19 deletions(-) create mode 100644 mmss/monitor.hpp create mode 100644 mmss/monitor_log.cpp create mode 100644 mmss/monitor_log.hpp create mode 100644 mmss/monitor_sqlite.cpp create mode 100644 mmss/monitor_sqlite.hpp diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 694a49d..4823bce 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -11,6 +11,8 @@ add_executable(mmss iface.cpp lex.cpp mmss.cpp + monitor_log.cpp + monitor_sqlite.cpp network.cpp protocol.cpp ${BISON_mmss_config_parse_OUTPUTS} diff --git a/mmss/context.cpp b/mmss/context.cpp index dd24ae8..4cf5011 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -29,6 +29,9 @@ #include "network.hpp" #include "node.hpp" +#include "monitor_log.hpp" +#include "monitor_sqlite.hpp" + #include #include #include @@ -65,25 +68,18 @@ static inline const char* get_log_prefix(int log_level) { } -void context_t::vlogf_orig(const node_t *orig, int priority, const char *format, std::va_list ap) { +void context_t::logf(int priority, const char *format, ...) { char buf[1024]; size_t pos; - if (orig) - pos = snprintf_safe(buf, sizeof(buf), "[% 6u.%03u] %s: %s", now()/1000, now()%1000, orig->get_name().c_str(), get_log_prefix(priority)); - else - pos = snprintf_safe(buf, sizeof(buf), "[% 6u.%03u] %s", now()/1000, now()%1000, get_log_prefix(priority)); + pos = snprintf_safe(buf, sizeof(buf), "[% 6u.%03u] %s", now()/1000, now()%1000, get_log_prefix(priority)); - std::vsnprintf(buf+pos, sizeof(buf)-pos, format, ap); - - std::fprintf(stderr, "%s\n", buf); -} - -void context_t::logf(int priority, const char *format, ...) { std::va_list ap; va_start(ap, format); - vlogf_orig(nullptr, priority, format, ap); + std::vsnprintf(buf+pos, sizeof(buf)-pos, format, ap); va_end(ap); + + std::fprintf(stderr, "%s\n", buf); } void context_t::run(int argc, char *argv[]) { @@ -93,6 +89,9 @@ void context_t::run(int argc, char *argv[]) { } + attach_monitor(std::make_shared()); + attach_monitor(std::make_shared()); + std::shared_ptr conf = config_t::read(this, argv[1]); if (!conf) diff --git a/mmss/context.hpp b/mmss/context.hpp index db0c283..60fa4c3 100644 --- a/mmss/context.hpp +++ b/mmss/context.hpp @@ -27,6 +27,7 @@ #pragma once #include "event.hpp" +#include "monitor.hpp" #include "queue.hpp" #include @@ -39,6 +40,7 @@ namespace MMSS { class context_t : public now_t, public nocopy_t { private: timeout_queue_t event_queue; + std::list> monitors; public: context_t() : event_queue(this) {} @@ -47,7 +49,40 @@ public: event_queue.put(std::move(data), timeout); } - void vlogf_orig(const node_t *orig, int priority, const char *format, std::va_list ap); + void attach_monitor(std::shared_ptr &&monitor) { + monitors.emplace_back(std::move(monitor)); + } + + void node_log(node_t *node, int priority, const std::string &message) { + for (auto monitor : monitors) + monitor->handle_log(node, priority, message); + } + + void node_init(node_t *node, const uint8_t *node_id, size_t len) { + for (auto monitor : monitors) + monitor->handle_init(node, node_id, len); + } + + void node_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { + for (auto monitor : monitors) + monitor->handle_neigh(node, iface, addr, rxcost, txcost); + } + + void node_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr) { + for (auto monitor : monitors) + monitor->handle_neigh_lost(node, iface, addr); + } + + void node_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) { + for (auto monitor : monitors) + monitor->handle_route(node, node_id, len, iface, addr, metric); + } + + void node_route_lost(node_t *node, const uint8_t *node_id, size_t len) { + for (auto monitor : monitors) + monitor->handle_route_lost(node, node_id, len); + } + void logf(int priority, const char *format, ...); void run(int argc, char *argv[]); diff --git a/mmss/gmrf.cpp b/mmss/gmrf.cpp index 1b05b7d..a2a60a8 100644 --- a/mmss/gmrf.cpp +++ b/mmss/gmrf.cpp @@ -29,6 +29,8 @@ #include "iface.hpp" #include "node.hpp" +#include + using namespace MMSS; @@ -82,23 +84,39 @@ void gmrf_logf(gmrf_t *gmrf, int priority, const char *format, ...) { va_list ap; va_start(ap, format); - node->get_context()->vlogf_orig(node, priority, format, ap); + + char *message; + if (vasprintf(&message, format, ap) >= 0) { + node->get_context()->node_log(node, priority, std::string(message)); + std::free(message); + } + va_end(ap); } -void gmrf_debug_init(gmrf_t *gmrf UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { +void gmrf_debug_init(gmrf_t *gmrf, const uint8_t *node_id, size_t len) { + node_t *node = static_cast(gmrf); + node->get_context()->node_init(node, node_id, len); } -void gmrf_debug_neigh(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { +void gmrf_debug_neigh(gmrf_t *gmrf, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { + node_t *node = static_cast(gmrf); + node->get_context()->node_neigh(node, iface, addr, rxcost, txcost); } -void gmrf_debug_neigh_lost(gmrf_t *gmrf UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { +void gmrf_debug_neigh_lost(gmrf_t *gmrf, gmrf_iface_t *iface, const gmrf_addr_t *addr) { + node_t *node = static_cast(gmrf); + node->get_context()->node_neigh_lost(node, iface, addr); } -void gmrf_debug_route(gmrf_t *gmrf UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { +void gmrf_debug_route(gmrf_t *gmrf, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) { + node_t *node = static_cast(gmrf); + node->get_context()->node_route(node, node_id, len, iface, addr, metric); } -void gmrf_debug_route_lost(gmrf_t *gmrf UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { +void gmrf_debug_route_lost(gmrf_t *gmrf, const uint8_t *node_id, size_t len) { + node_t *node = static_cast(gmrf); + node->get_context()->node_route_lost(node, node_id, len); } } diff --git a/mmss/monitor.hpp b/mmss/monitor.hpp new file mode 100644 index 0000000..7ce3816 --- /dev/null +++ b/mmss/monitor.hpp @@ -0,0 +1,51 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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. +*/ + + +#pragma once + +#include "types.hpp" + +#include + + +namespace MMSS { + +class monitor_t : public nocopy_t { +public: + virtual ~monitor_t() {} + + virtual void handle_log(node_t *node, int priority, const std::string &message) = 0; + + virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len) = 0; + + virtual void handle_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) = 0; + virtual void handle_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr) = 0; + + virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) = 0; + virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len) = 0; +}; + +} diff --git a/mmss/monitor_log.cpp b/mmss/monitor_log.cpp new file mode 100644 index 0000000..4356e24 --- /dev/null +++ b/mmss/monitor_log.cpp @@ -0,0 +1,53 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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 "monitor_log.hpp" +#include "context.hpp" +#include "node.hpp" + + +namespace MMSS { + +void monitor_log_t::handle_log(node_t *node, int priority, const std::string &message) { + node->get_context()->logf(priority, "%s: %s", node->get_name().c_str(), message.c_str()); +} + +void monitor_log_t::handle_init(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { +} + +void monitor_log_t::handle_neigh(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { +} + +void monitor_log_t::handle_neigh_lost(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { +} + +void monitor_log_t::handle_route(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { +} + +void monitor_log_t::handle_route_lost(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { +} + +} diff --git a/mmss/monitor_log.hpp b/mmss/monitor_log.hpp new file mode 100644 index 0000000..960eacb --- /dev/null +++ b/mmss/monitor_log.hpp @@ -0,0 +1,46 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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. +*/ + + +#pragma once + +#include "monitor.hpp" + +namespace MMSS { + +class monitor_log_t : public monitor_t { +public: + virtual void handle_log(node_t *node, int priority, const std::string &message); + + virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); + + virtual void handle_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); + virtual void handle_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr); + + virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric); + virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len); +}; + +} diff --git a/mmss/monitor_sqlite.cpp b/mmss/monitor_sqlite.cpp new file mode 100644 index 0000000..34b1da4 --- /dev/null +++ b/mmss/monitor_sqlite.cpp @@ -0,0 +1,49 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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 "monitor_sqlite.hpp" + +namespace MMSS { + +void monitor_sqlite_t::handle_log(node_t *node UNUSED, int priority UNUSED, const std::string &message UNUSED) { +} + +void monitor_sqlite_t::handle_init(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { +} + +void monitor_sqlite_t::handle_neigh(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { +} + +void monitor_sqlite_t::handle_neigh_lost(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { +} + +void monitor_sqlite_t::handle_route(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { +} + +void monitor_sqlite_t::handle_route_lost(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { +} + +} diff --git a/mmss/monitor_sqlite.hpp b/mmss/monitor_sqlite.hpp new file mode 100644 index 0000000..afb6e2f --- /dev/null +++ b/mmss/monitor_sqlite.hpp @@ -0,0 +1,46 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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. +*/ + + +#pragma once + +#include "monitor.hpp" + +namespace MMSS { + +class monitor_sqlite_t : public monitor_t { +public: + virtual void handle_log(node_t *node, int priority, const std::string &message); + + virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); + + virtual void handle_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); + virtual void handle_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr); + + virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric); + virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len); +}; + +} diff --git a/mmss/types.hpp b/mmss/types.hpp index 54a8474..b649849 100644 --- a/mmss/types.hpp +++ b/mmss/types.hpp @@ -56,6 +56,7 @@ private: class context_t; class config_t; class iface_t; +class monitor_t; class network_t; class node_t; class now_t; From 28aa3884766bb09485428ce0c91104f7129b8145 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 21 Mar 2014 04:54:33 +0100 Subject: [PATCH 04/10] Require libsqlite3 --- CMakeLists.txt | 5 +++++ mmss/CMakeLists.txt | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6509ceb..662913a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,11 @@ project(GMRF C CXX) set(CMAKE_MODULE_PATH ${GMRF_SOURCE_DIR}) find_package(BISON 2.5 REQUIRED) +find_package(PkgConfig REQUIRED) + + +pkg_check_modules(SQLITE REQUIRED sqlite3) + add_subdirectory(mmss) add_subdirectory(mmss-protocol) diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 4823bce..470ae00 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories(${GMRF_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +link_directories(${SQLITE_LIBRARY_DIRS}) set_directory_properties(PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE) BISON_TARGET(mmss_config_parse config.y ${CMAKE_CURRENT_BINARY_DIR}/config.yy.cpp) @@ -18,4 +19,7 @@ add_executable(mmss ${BISON_mmss_config_parse_OUTPUTS} ) target_link_libraries(mmss dl) -set_target_properties(mmss PROPERTIES COMPILE_FLAGS "-std=c++11 -Wall") +set_property(TARGET mmss PROPERTY COMPILE_FLAGS "-std=c++11 ${SQLITE_CFLAGS_OTHER} -Wall") +set_property(TARGET mmss PROPERTY LINK_FLAGS "${SQLITE_LDFLAGS_OTHER}") +set_property(TARGET mmss APPEND PROPERTY INCLUDE_DIRECTORIES ${SQLITE_INCLUDE_DIRS}) +target_link_libraries(mmss ${SQLITE_LIBRARIES}) From d317a324c1c9fbc827f195f648a7a86dc17f89a1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Mar 2014 01:15:05 +0100 Subject: [PATCH 05/10] Revert "Require libsqlite3" This reverts commit 28aa3884766bb09485428ce0c91104f7129b8145. --- CMakeLists.txt | 5 ----- mmss/CMakeLists.txt | 6 +----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 662913a..6509ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,6 @@ project(GMRF C CXX) set(CMAKE_MODULE_PATH ${GMRF_SOURCE_DIR}) find_package(BISON 2.5 REQUIRED) -find_package(PkgConfig REQUIRED) - - -pkg_check_modules(SQLITE REQUIRED sqlite3) - add_subdirectory(mmss) add_subdirectory(mmss-protocol) diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 470ae00..4823bce 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -1,5 +1,4 @@ include_directories(${GMRF_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -link_directories(${SQLITE_LIBRARY_DIRS}) set_directory_properties(PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE) BISON_TARGET(mmss_config_parse config.y ${CMAKE_CURRENT_BINARY_DIR}/config.yy.cpp) @@ -19,7 +18,4 @@ add_executable(mmss ${BISON_mmss_config_parse_OUTPUTS} ) target_link_libraries(mmss dl) -set_property(TARGET mmss PROPERTY COMPILE_FLAGS "-std=c++11 ${SQLITE_CFLAGS_OTHER} -Wall") -set_property(TARGET mmss PROPERTY LINK_FLAGS "${SQLITE_LDFLAGS_OTHER}") -set_property(TARGET mmss APPEND PROPERTY INCLUDE_DIRECTORIES ${SQLITE_INCLUDE_DIRS}) -target_link_libraries(mmss ${SQLITE_LIBRARIES}) +set_target_properties(mmss PROPERTIES COMPILE_FLAGS "-std=c++11 -Wall") From dff97425cdcbfbbb0ca4d5c8cf48d7a24111979d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Mar 2014 01:16:48 +0100 Subject: [PATCH 06/10] Remove SQLite monitor SQLite is slows down the simulation to much. --- mmss/CMakeLists.txt | 1 - mmss/context.cpp | 2 -- mmss/monitor_sqlite.cpp | 49 ----------------------------------------- mmss/monitor_sqlite.hpp | 46 -------------------------------------- 4 files changed, 98 deletions(-) delete mode 100644 mmss/monitor_sqlite.cpp delete mode 100644 mmss/monitor_sqlite.hpp diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 4823bce..0b9217f 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -12,7 +12,6 @@ add_executable(mmss lex.cpp mmss.cpp monitor_log.cpp - monitor_sqlite.cpp network.cpp protocol.cpp ${BISON_mmss_config_parse_OUTPUTS} diff --git a/mmss/context.cpp b/mmss/context.cpp index 4cf5011..3ab4086 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -30,7 +30,6 @@ #include "node.hpp" #include "monitor_log.hpp" -#include "monitor_sqlite.hpp" #include #include @@ -90,7 +89,6 @@ void context_t::run(int argc, char *argv[]) { attach_monitor(std::make_shared()); - attach_monitor(std::make_shared()); std::shared_ptr conf = config_t::read(this, argv[1]); diff --git a/mmss/monitor_sqlite.cpp b/mmss/monitor_sqlite.cpp deleted file mode 100644 index 34b1da4..0000000 --- a/mmss/monitor_sqlite.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (c) 2013-2014, Matthias Schiffer - 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 "monitor_sqlite.hpp" - -namespace MMSS { - -void monitor_sqlite_t::handle_log(node_t *node UNUSED, int priority UNUSED, const std::string &message UNUSED) { -} - -void monitor_sqlite_t::handle_init(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { -} - -void monitor_sqlite_t::handle_neigh(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { -} - -void monitor_sqlite_t::handle_neigh_lost(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { -} - -void monitor_sqlite_t::handle_route(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { -} - -void monitor_sqlite_t::handle_route_lost(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { -} - -} diff --git a/mmss/monitor_sqlite.hpp b/mmss/monitor_sqlite.hpp deleted file mode 100644 index afb6e2f..0000000 --- a/mmss/monitor_sqlite.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (c) 2013-2014, Matthias Schiffer - 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. -*/ - - -#pragma once - -#include "monitor.hpp" - -namespace MMSS { - -class monitor_sqlite_t : public monitor_t { -public: - virtual void handle_log(node_t *node, int priority, const std::string &message); - - virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); - - virtual void handle_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); - virtual void handle_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr); - - virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric); - virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len); -}; - -} From 2096f29487ceff44f1c3e6e5b18efa8c7cb573f6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Mar 2014 20:11:54 +0100 Subject: [PATCH 07/10] Change gmrf_iface_t arguments in monitors to iface_t --- mmss/context.hpp | 6 +++--- mmss/gmrf.cpp | 6 +++--- mmss/monitor.hpp | 6 +++--- mmss/monitor_log.cpp | 6 +++--- mmss/monitor_log.hpp | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mmss/context.hpp b/mmss/context.hpp index 60fa4c3..4c7e478 100644 --- a/mmss/context.hpp +++ b/mmss/context.hpp @@ -63,17 +63,17 @@ public: monitor->handle_init(node, node_id, len); } - void node_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { + void node_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { for (auto monitor : monitors) monitor->handle_neigh(node, iface, addr, rxcost, txcost); } - void node_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr) { + void node_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr) { for (auto monitor : monitors) monitor->handle_neigh_lost(node, iface, addr); } - void node_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) { + void node_route(node_t *node, const uint8_t *node_id, size_t len, iface_t *iface, const gmrf_addr_t *addr, int metric) { for (auto monitor : monitors) monitor->handle_route(node, node_id, len, iface, addr, metric); } diff --git a/mmss/gmrf.cpp b/mmss/gmrf.cpp index a2a60a8..e8bbffb 100644 --- a/mmss/gmrf.cpp +++ b/mmss/gmrf.cpp @@ -101,17 +101,17 @@ void gmrf_debug_init(gmrf_t *gmrf, const uint8_t *node_id, size_t len) { void gmrf_debug_neigh(gmrf_t *gmrf, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { node_t *node = static_cast(gmrf); - node->get_context()->node_neigh(node, iface, addr, rxcost, txcost); + node->get_context()->node_neigh(node, static_cast(iface), addr, rxcost, txcost); } void gmrf_debug_neigh_lost(gmrf_t *gmrf, gmrf_iface_t *iface, const gmrf_addr_t *addr) { node_t *node = static_cast(gmrf); - node->get_context()->node_neigh_lost(node, iface, addr); + node->get_context()->node_neigh_lost(node, static_cast(iface), addr); } void gmrf_debug_route(gmrf_t *gmrf, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) { node_t *node = static_cast(gmrf); - node->get_context()->node_route(node, node_id, len, iface, addr, metric); + node->get_context()->node_route(node, node_id, len, static_cast(iface), addr, metric); } void gmrf_debug_route_lost(gmrf_t *gmrf, const uint8_t *node_id, size_t len) { diff --git a/mmss/monitor.hpp b/mmss/monitor.hpp index 7ce3816..36855af 100644 --- a/mmss/monitor.hpp +++ b/mmss/monitor.hpp @@ -41,10 +41,10 @@ public: virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len) = 0; - virtual void handle_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) = 0; - virtual void handle_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr) = 0; + virtual void handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) = 0; + virtual void handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr) = 0; - virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric) = 0; + virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, iface_t *iface, const gmrf_addr_t *addr, int metric) = 0; virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len) = 0; }; diff --git a/mmss/monitor_log.cpp b/mmss/monitor_log.cpp index 4356e24..bbb56a4 100644 --- a/mmss/monitor_log.cpp +++ b/mmss/monitor_log.cpp @@ -38,13 +38,13 @@ void monitor_log_t::handle_log(node_t *node, int priority, const std::string &me void monitor_log_t::handle_init(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { } -void monitor_log_t::handle_neigh(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { +void monitor_log_t::handle_neigh(node_t *node UNUSED, iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { } -void monitor_log_t::handle_neigh_lost(node_t *node UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { +void monitor_log_t::handle_neigh_lost(node_t *node UNUSED, iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED) { } -void monitor_log_t::handle_route(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, gmrf_iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { +void monitor_log_t::handle_route(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED, iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, int metric UNUSED) { } void monitor_log_t::handle_route_lost(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { diff --git a/mmss/monitor_log.hpp b/mmss/monitor_log.hpp index 960eacb..084e8eb 100644 --- a/mmss/monitor_log.hpp +++ b/mmss/monitor_log.hpp @@ -36,10 +36,10 @@ public: virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); - virtual void handle_neigh(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); - virtual void handle_neigh_lost(node_t *node, gmrf_iface_t *iface, const gmrf_addr_t *addr); + virtual void handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); + virtual void handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr); - virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, gmrf_iface_t *iface, const gmrf_addr_t *addr, int metric); + virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, iface_t *iface, const gmrf_addr_t *addr, int metric); virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len); }; From aa20bcc6eb539ab1d6a9490e1843f9ab1e025155 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 23 Mar 2014 17:57:54 +0100 Subject: [PATCH 08/10] Add file monitor --- mmss/CMakeLists.txt | 1 + mmss/context.cpp | 6 ++- mmss/monitor_file.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ mmss/monitor_file.hpp | 55 ++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 mmss/monitor_file.cpp create mode 100644 mmss/monitor_file.hpp diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 0b9217f..2406508 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(mmss iface.cpp lex.cpp mmss.cpp + monitor_file.cpp monitor_log.cpp network.cpp protocol.cpp diff --git a/mmss/context.cpp b/mmss/context.cpp index 3ab4086..656299a 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -29,6 +29,7 @@ #include "network.hpp" #include "node.hpp" +#include "monitor_file.hpp" #include "monitor_log.hpp" #include @@ -82,13 +83,14 @@ void context_t::logf(int priority, const char *format, ...) { } void context_t::run(int argc, char *argv[]) { - if (argc != 2) { - std::fprintf(stderr, "usage: %s config\n", argv[0]); + if (argc != 3) { + std::fprintf(stderr, "usage: %s config logfile\n", argv[0]); std::exit(1); } attach_monitor(std::make_shared()); + attach_monitor(std::make_shared(argv[2])); std::shared_ptr conf = config_t::read(this, argv[1]); diff --git a/mmss/monitor_file.cpp b/mmss/monitor_file.cpp new file mode 100644 index 0000000..249d779 --- /dev/null +++ b/mmss/monitor_file.cpp @@ -0,0 +1,89 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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 "monitor_file.hpp" +#include "context.hpp" +#include "node.hpp" + + +namespace MMSS { + +monitor_file_t::monitor_file_t(const std::string &filename) { + file = std::fopen(filename.c_str(), "w"); + + if (!file) { + std::fprintf(stderr, "monitor_file: unable to open output file\n"); + std::exit(1); + } +} + +monitor_file_t::~monitor_file_t() { + std::fclose(file); +} + +void monitor_file_t::handle_log(node_t *node, int priority, const std::string &message) { + std::fprintf(file, "%llu LOG %s %i %s\n", (unsigned long long)node->get_context()->now(), node->get_name().c_str(), priority, message.c_str()); +} + +void monitor_file_t::handle_init(node_t *node, const uint8_t *node_id, size_t len) { + std::fprintf(file, "%llu INIT %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str()); + for (size_t i = 0; i < len; i++) + std::fprintf(file, "%02x", node_id[i]); + std::fprintf(file, "\n"); +} + +void monitor_file_t::handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { + std::fprintf(file, "%llu NEIGH %s %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str(), iface->get_name().c_str()); + for (size_t i = 0; i < GMRF_ADDR_LEN; i++) + std::fprintf(file, "%02x", addr->d[i]); + std::fprintf(file, " %f %f\n", rxcost, txcost); +} + +void monitor_file_t::handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr) { + std::fprintf(file, "%llu NEIGH %s %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str(), iface->get_name().c_str()); + for (size_t i = 0; i < GMRF_ADDR_LEN; i++) + std::fprintf(file, "%02x", addr->d[i]); + std::fprintf(file, " LOST\n"); +} + +void monitor_file_t::handle_route(node_t *node, const uint8_t *node_id, size_t len, iface_t *iface, const gmrf_addr_t *addr, int metric) { + std::fprintf(file, "%llu ROUTE %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str()); + for (size_t i = 0; i < len; i++) + std::fprintf(file, "%02x", node_id[i]); + std::fprintf(file, " %s ", iface->get_name().c_str()); + for (size_t i = 0; i < GMRF_ADDR_LEN; i++) + std::fprintf(file, "%02x", addr->d[i]); + std::fprintf(file, " %i\n", metric); +} + +void monitor_file_t::handle_route_lost(node_t *node, const uint8_t *node_id, size_t len) { + std::fprintf(file, "%llu ROUTE %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str()); + for (size_t i = 0; i < len; i++) + std::fprintf(file, "%02x", node_id[i]); + std::fprintf(file, " LOST\n"); +} + +} diff --git a/mmss/monitor_file.hpp b/mmss/monitor_file.hpp new file mode 100644 index 0000000..a125aee --- /dev/null +++ b/mmss/monitor_file.hpp @@ -0,0 +1,55 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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. +*/ + + +#pragma once + +#include "monitor.hpp" + +#include + + +namespace MMSS { + +class monitor_file_t : public monitor_t { +private: + std::FILE *file; + +public: + monitor_file_t(const std::string &filename); + virtual ~monitor_file_t(); + + virtual void handle_log(node_t *node, int priority, const std::string &message); + + virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); + + virtual void handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); + virtual void handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr); + + virtual void handle_route(node_t *node, const uint8_t *node_id, size_t len, iface_t *iface, const gmrf_addr_t *addr, int metric); + virtual void handle_route_lost(node_t *node, const uint8_t *node_id, size_t len); +}; + +} From cbbfe4360d95294d792956df43df4a72854a8e80 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 23 Mar 2014 22:18:29 +0100 Subject: [PATCH 09/10] config: allow to omit empty network sections --- mmss/config.y | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mmss/config.y b/mmss/config.y index 63bfcb8..90b2a9e 100644 --- a/mmss/config.y +++ b/mmss/config.y @@ -97,7 +97,7 @@ config: config statement | ; -statement: TOK_NETWORK network '{' network_config '}' +statement: TOK_NETWORK network network_tail | TOK_PROTOCOL protocol ';' | TOK_NODE node '{' node_config '}' ; @@ -108,6 +108,10 @@ network: TOK_STRING { } ; +network_tail: + '{' network_config '}' + | ';' + network_config: network_config network_statement | ; From 8cc6b6dd69cee050c16a1c871c986ed933141866 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 24 Jul 2014 23:35:20 +0200 Subject: [PATCH 10/10] Completely log simulations --- examples/babel_test.mmss | 75 +++++++++++++++++++++++++++++----------- mmss/CMakeLists.txt | 1 + mmss/context.hpp | 10 ++++++ mmss/monitor.hpp | 3 ++ mmss/monitor_file.cpp | 14 ++++++++ mmss/monitor_file.hpp | 3 ++ mmss/monitor_log.cpp | 9 ++++- mmss/monitor_log.hpp | 3 ++ mmss/network.cpp | 5 +++ mmss/network.hpp | 3 +- mmss/node.cpp | 39 +++++++++++++++++++++ mmss/node.hpp | 5 +-- 12 files changed, 143 insertions(+), 27 deletions(-) create mode 100644 mmss/node.cpp diff --git a/examples/babel_test.mmss b/examples/babel_test.mmss index fad6f0a..7002fb1 100644 --- a/examples/babel_test.mmss +++ b/examples/babel_test.mmss @@ -1,28 +1,63 @@ protocol "babel" load "./libmmss_proto_babel.so" default; -network "net0" { - etx min 1.0 max 5.0 sine period 15 m; -} +/* topology: -network "net1" { - etx min 1.0 max 5.0 sine period 15 m phase 5 m; -} + C - D + / \ +A - B G - H + \ / + E - F -network "net2" { - etx min 1.0 max 5.0 sine period 15 m phase 10 m; -} +*/ -node "node1" { - interface "mmss1.0" network "net0" address 00:00:00:00:00:00:00:10; - interface "mmss1.1" network "net1" address 00:00:00:00:00:00:00:11; -} -node "node2" { - interface "mmss2.1" network "net1" address 00:00:00:00:00:00:00:21; - interface "mmss2.2" network "net2" address 00:00:00:00:00:00:00:22; -} +network "net_A_B"; +network "net_B_C"; +network "net_B_E"; +network "net_C_D" { etx min 1.0 max 5.0 sine period 20 m; } +network "net_D_G"; +network "net_E_F" { etx min 1.0 max 5.0 sine period 20 m phase 10 m; } +network "net_F_G"; +network "net_G_H"; -node "node3" { - interface "mmss3.2" network "net2" address 00:00:00:00:00:00:00:32; - interface "mmss3.0" network "net0" address 00:00:00:00:00:00:00:30; + +#network "net1" { +# etx min 1.0 max 5.0 sine period 15 m phase 5 m; +#} + +#network "net2" { +# etx min 1.0 max 5.0 sine period 15 m phase 10 m; +#} + +node "A" { + interface "mmss_A_B" network "net_A_B" address 00:00:00:00:00:00:01:02; +} +node "B" { + interface "mmss_B_A" network "net_A_B" address 00:00:00:00:00:00:02:01; + interface "mmss_B_C" network "net_B_C" address 00:00:00:00:00:00:02:03; + interface "mmss_B_E" network "net_B_E" address 00:00:00:00:00:00:02:05; +} +node "C" { + interface "mmss_C_B" network "net_B_C" address 00:00:00:00:00:00:03:02; + interface "mmss_C_D" network "net_C_D" address 00:00:00:00:00:00:03:04; +} +node "D" { + interface "mmss_D_C" network "net_C_D" address 00:00:00:00:00:00:04:03; + interface "mmss_D_G" network "net_D_G" address 00:00:00:00:00:00:04:07; +} +node "E" { + interface "mmss_E_B" network "net_B_E" address 00:00:00:00:00:00:05:02; + interface "mmss_E_F" network "net_E_F" address 00:00:00:00:00:00:05:06; +} +node "F" { + interface "mmss_F_E" network "net_E_F" address 00:00:00:00:00:00:06:05; + interface "mmss_F_G" network "net_F_G" address 00:00:00:00:00:00:06:07; +} +node "G" { + interface "mmss_G_D" network "net_D_G" address 00:00:00:00:00:00:07:04; + interface "mmss_G_F" network "net_F_G" address 00:00:00:00:00:00:07:06; + interface "mmss_G_H" network "net_G_H" address 00:00:00:00:00:00:07:08; +} +node "H" { + interface "mmss_H_G" network "net_G_H" address 00:00:00:00:00:00:08:07; } diff --git a/mmss/CMakeLists.txt b/mmss/CMakeLists.txt index 2406508..9f586c0 100644 --- a/mmss/CMakeLists.txt +++ b/mmss/CMakeLists.txt @@ -14,6 +14,7 @@ add_executable(mmss monitor_file.cpp monitor_log.cpp network.cpp + node.cpp protocol.cpp ${BISON_mmss_config_parse_OUTPUTS} ) diff --git a/mmss/context.hpp b/mmss/context.hpp index 4c7e478..90ffea1 100644 --- a/mmss/context.hpp +++ b/mmss/context.hpp @@ -63,6 +63,16 @@ public: monitor->handle_init(node, node_id, len); } + void network(network_t *net) { + for (auto monitor : monitors) + monitor->handle_network(net); + } + + void node_iface(node_t *node, iface_t *iface) { + for (auto monitor : monitors) + monitor->handle_iface(node, iface); + } + void node_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { for (auto monitor : monitors) monitor->handle_neigh(node, iface, addr, rxcost, txcost); diff --git a/mmss/monitor.hpp b/mmss/monitor.hpp index 36855af..bfe43bb 100644 --- a/mmss/monitor.hpp +++ b/mmss/monitor.hpp @@ -41,6 +41,9 @@ public: virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len) = 0; + virtual void handle_network(network_t *net) = 0; + virtual void handle_iface(node_t *node, iface_t *iface) = 0; + virtual void handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) = 0; virtual void handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr) = 0; diff --git a/mmss/monitor_file.cpp b/mmss/monitor_file.cpp index 249d779..0de8a92 100644 --- a/mmss/monitor_file.cpp +++ b/mmss/monitor_file.cpp @@ -55,6 +55,20 @@ void monitor_file_t::handle_init(node_t *node, const uint8_t *node_id, size_t le std::fprintf(file, "\n"); } +void monitor_file_t::handle_network(network_t *net) { + std::fprintf(file, "%llu NETWORK %s\n", (unsigned long long)net->get_context()->now(), net->get_name().c_str()); +} + +void monitor_file_t::handle_iface(node_t *node, iface_t *iface) { + std::fprintf(file, "%llu IFACE %s %s %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str(), iface->get_name().c_str(), iface->get_network()->get_name().c_str()); + + const gmrf_addr_t *addr = iface->get_address(); + for (size_t i = 0; i < GMRF_ADDR_LEN; i++) + std::fprintf(file, "%02x", addr->d[i]); + + std::fprintf(file, "\n"); +} + void monitor_file_t::handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost) { std::fprintf(file, "%llu NEIGH %s %s ", (unsigned long long)node->get_context()->now(), node->get_name().c_str(), iface->get_name().c_str()); for (size_t i = 0; i < GMRF_ADDR_LEN; i++) diff --git a/mmss/monitor_file.hpp b/mmss/monitor_file.hpp index a125aee..37c018c 100644 --- a/mmss/monitor_file.hpp +++ b/mmss/monitor_file.hpp @@ -45,6 +45,9 @@ public: virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); + virtual void handle_network(network_t *net); + virtual void handle_iface(node_t *node, iface_t *iface); + virtual void handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); virtual void handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr); diff --git a/mmss/monitor_log.cpp b/mmss/monitor_log.cpp index bbb56a4..9a21e03 100644 --- a/mmss/monitor_log.cpp +++ b/mmss/monitor_log.cpp @@ -32,12 +32,19 @@ namespace MMSS { void monitor_log_t::handle_log(node_t *node, int priority, const std::string &message) { - node->get_context()->logf(priority, "%s: %s", node->get_name().c_str(), message.c_str()); + if (priority < LOG_DEBUG) + node->get_context()->logf(priority, "%s: %s", node->get_name().c_str(), message.c_str()); } void monitor_log_t::handle_init(node_t *node UNUSED, const uint8_t *node_id UNUSED, size_t len UNUSED) { } +void monitor_log_t::handle_network(network_t *net UNUSED) { +} + +void monitor_log_t::handle_iface(node_t *node UNUSED, iface_t *iface UNUSED) { +} + void monitor_log_t::handle_neigh(node_t *node UNUSED, iface_t *iface UNUSED, const gmrf_addr_t *addr UNUSED, float rxcost UNUSED, float txcost UNUSED) { } diff --git a/mmss/monitor_log.hpp b/mmss/monitor_log.hpp index 084e8eb..262dd2d 100644 --- a/mmss/monitor_log.hpp +++ b/mmss/monitor_log.hpp @@ -36,6 +36,9 @@ public: virtual void handle_init(node_t *node, const uint8_t *node_id, size_t len); + virtual void handle_network(network_t *net); + virtual void handle_iface(node_t *node, iface_t *iface); + virtual void handle_neigh(node_t *node, iface_t *iface, const gmrf_addr_t *addr, float rxcost, float txcost); virtual void handle_neigh_lost(node_t *node, iface_t *iface, const gmrf_addr_t *addr); diff --git a/mmss/network.cpp b/mmss/network.cpp index 7550541..6e47240 100644 --- a/mmss/network.cpp +++ b/mmss/network.cpp @@ -34,6 +34,11 @@ namespace MMSS { +network_t::network_t(context_t *mmss0, const std::string &name0, unsigned rand_seed0) + : mmss(mmss0), name(name0), mtu(1500), rand_seed(rand_seed0), etx_min(1), etx_max(1) { + mmss->network(this); +} + float network_t::get_etx() const { if (etx_min == etx_max) return etx_min; diff --git a/mmss/network.hpp b/mmss/network.hpp index 7eca164..54e3f77 100644 --- a/mmss/network.hpp +++ b/mmss/network.hpp @@ -57,8 +57,7 @@ private: void enqueue(const void *data, size_t len, const iface_t *src_iface, const std::shared_ptr &dest_iface); public: - network_t(context_t *mmss0, const std::string &name0, unsigned rand_seed0) - : mmss(mmss0), name(name0), mtu(1500), rand_seed(rand_seed0), etx_min(1), etx_max(1) {} + network_t(context_t *mmss0, const std::string &name0, unsigned rand_seed0); void set_packet_loss(float etx) { etx_min = etx_max = etx; diff --git a/mmss/node.cpp b/mmss/node.cpp new file mode 100644 index 0000000..41461f5 --- /dev/null +++ b/mmss/node.cpp @@ -0,0 +1,39 @@ +/* + Copyright (c) 2013-2014, Matthias Schiffer + 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 "node.hpp" +#include "context.hpp" + + +namespace MMSS { + +gmrf_iface_state_t * node_t::add_iface(const std::shared_ptr &iface) { + interfaces.insert(iface); + mmss->node_iface(this, iface.get()); + return proto->add_iface(gmrf_ctx, iface.get()); +} + +} diff --git a/mmss/node.hpp b/mmss/node.hpp index 06016cc..adebcf2 100644 --- a/mmss/node.hpp +++ b/mmss/node.hpp @@ -59,10 +59,7 @@ public: return node; } - gmrf_iface_state_t* add_iface(const std::shared_ptr &iface) { - interfaces.insert(iface); - return proto->add_iface(gmrf_ctx, iface.get()); - } + gmrf_iface_state_t* add_iface(const std::shared_ptr &iface); context_t* get_context() const { return mmss;