1 /* Copyright (c) 2013-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/kernel/routing/NetZoneImpl.hpp>
7 #include <simgrid/s4u/Engine.hpp>
9 #include "src/kernel/EngineImpl.hpp"
10 #include "src/surf/network_constant.hpp"
11 #include "src/surf/surf_interface.hpp"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
18 void surf_network_model_init_Constant()
20 auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>("Network_Constant");
21 auto* engine = simgrid::kernel::EngineImpl::get_instance();
22 engine->add_model(net_model);
23 engine->get_netzone_root()->set_network_model(net_model);
26 namespace simgrid::kernel::resource {
28 StandardLinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/)
30 xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
31 "Please remove any link from your platform (and switch to routing='None')",
36 StandardLinkImpl* NetworkConstantModel::create_wifi_link(const std::string& name, const std::vector<double>& bandwidths)
38 return create_link(name, bandwidths);
41 double NetworkConstantModel::next_occurring_event(double /*now*/)
44 for (Action const& action : *get_started_action_set()) {
45 const auto& net_action = static_cast<const NetworkConstantAction&>(action);
46 if (net_action.latency_ > 0 && (min < 0 || net_action.latency_ < min))
47 min = net_action.latency_;
52 void NetworkConstantModel::update_actions_state(double /*now*/, double delta)
54 for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
55 auto& action = static_cast<NetworkConstantAction&>(*it);
56 ++it; // increment iterator here since the following calls to action.finish() may invalidate it
57 if (action.latency_ > 0) {
58 if (action.latency_ > delta) {
59 double_update(&action.latency_, delta, sg_surf_precision);
61 action.latency_ = 0.0;
64 action.update_remains(action.get_cost() * delta / get_latency_factor());
65 action.update_max_duration(delta);
67 if ((action.get_remains_no_update() <= 0) ||
68 ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
69 action.finish(Action::State::FINISHED);
74 Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double /*rate*/,
77 return (new NetworkConstantAction(this, *src, *dst, size));
83 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, s4u::Host& src, s4u::Host& dst, double size)
84 : NetworkAction(model_, src, dst, size, false)
86 latency_ = model_->get_latency_factor();
88 set_state(Action::State::FINISHED);
91 void NetworkConstantAction::update_remains_lazy(double /*now*/)
96 } // namespace simgrid::kernel::resource