diff options
Diffstat (limited to 'mmss/config.cpp')
-rw-r--r-- | mmss/config.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
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<network_t>(mmss, name, rand_seed++))).first->second; - networks.insert(std::make_pair(name, std::make_shared<network_t>(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); |