1 /* Copyright (c) 2013-2021. 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 "network_constant.hpp"
7 #include "src/surf/surf_interface.hpp"
8 #include "surf/surf.hpp"
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
15 void surf_network_model_init_Constant()
17 /* FIXME[donassolo]: this smells bad, but works
18 * (the constructor saves its pointer in all_existing_models and models_by_type :O).
19 * We need a manager for these models */
20 new simgrid::kernel::resource::NetworkConstantModel();
27 NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL)
29 all_existing_models.push_back(this);
30 models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
33 LinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/,
34 s4u::Link::SharingPolicy)
36 xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
37 "Please remove any link from your platform (and switch to routing='None')",
42 double NetworkConstantModel::next_occurring_event(double /*now*/)
45 for (kernel::resource::Action const& action : *get_started_action_set()) {
46 const auto& net_action = static_cast<const NetworkConstantAction&>(action);
47 if (net_action.latency_ > 0 && (min < 0 || net_action.latency_ < min))
48 min = net_action.latency_;
53 void NetworkConstantModel::update_actions_state(double /*now*/, double delta)
55 for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
56 auto& action = static_cast<NetworkConstantAction&>(*it);
57 ++it; // increment iterator here since the following calls to action.finish() may invalidate it
58 if (action.latency_ > 0) {
59 if (action.latency_ > delta) {
60 double_update(&action.latency_, delta, sg_surf_precision);
62 action.latency_ = 0.0;
65 action.update_remains(action.get_cost() * delta / action.initial_latency_);
66 action.update_max_duration(delta);
68 if ((action.get_remains_no_update() <= 0) ||
69 ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
70 action.finish(Action::State::FINISHED);
75 Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double)
77 auto* action = new NetworkConstantAction(this, *src, *dst, size, sg_latency_factor);
79 s4u::Link::on_communicate(*action);
86 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, s4u::Host& src, s4u::Host& dst, double size,
88 : NetworkAction(model_, src, dst, size, false), initial_latency_(latency)
92 NetworkConstantAction::set_state(Action::State::FINISHED);
95 NetworkConstantAction::~NetworkConstantAction() = default;
97 void NetworkConstantAction::update_remains_lazy(double /*now*/)
102 } // namespace resource
103 } // namespace kernel
104 } // namespace simgrid