From 1ff55d4c9acb9e1688bf76f12ae5ae26027ce113 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Jul 2013 21:00:11 +0200 Subject: Implement simple packet loss simulation --- mmss/config.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'mmss/config.cpp') diff --git a/mmss/config.cpp b/mmss/config.cpp index 0692d5f..475b1c5 100644 --- a/mmss/config.cpp +++ b/mmss/config.cpp @@ -66,12 +66,44 @@ bool config_t::add_network(const char *name) { return false; } + current_net = &networks.insert(std::make_pair(name, std::make_shared(mmss, name, rand_seed++))).first->second; - networks.insert(std::make_pair(name, std::make_shared(name))); + return true; +} + +bool config_t::set_packet_loss(float etx) { + if (etx < 1) { + mmss->logf(LOG_ERR, "config error: network `%s': ETX must be at least 1.0", (*current_net)->get_name().c_str()); + return false; + } + + (*current_net)->set_packet_loss(etx); + + return true; +} + +bool config_t::set_packet_loss(float etx_min, float etx_max, float period, float phase) { + if (etx_min < 1) { + mmss->logf(LOG_ERR, "config error: network `%s': ETX must be at least 1.0", (*current_net)->get_name().c_str()); + return false; + } + + if (etx_max < etx_min) { + mmss->logf(LOG_ERR, "config error: network `%s': max ETX smaller than min ETX", (*current_net)->get_name().c_str()); + return false; + } + + if (period <= 0) { + mmss->logf(LOG_ERR, "config error: network `%s': zero or negative period", (*current_net)->get_name().c_str()); + return false; + } + + (*current_net)->set_packet_loss(etx_min, etx_max, period, phase); return true; } + bool config_t::add_node(const char *name, const char *proto) { if (nodes.find(name) != nodes.end()) { mmss->logf(LOG_ERR, "config error: duplicate node `%s'", name); -- cgit v1.2.3