1 /* Copyright (c) 2013-2017. 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"
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
13 void surf_network_model_init_Constant()
15 xbt_assert(surf_network_model == nullptr);
16 surf_network_model = new simgrid::surf::NetworkConstantModel();
17 all_existing_models->push_back(surf_network_model);
22 LinkImpl* NetworkConstantModel::createLink(const std::string& name, double bw, double lat,
23 e_surf_link_sharing_policy_t policy)
26 xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
27 "Please remove any link from your platform (and switch to routing='None')",
32 double NetworkConstantModel::nextOccuringEvent(double /*now*/)
36 ActionList* actionSet = getRunningActionSet();
37 ActionList::iterator it(actionSet->begin());
38 ActionList::iterator itend(actionSet->end());
39 for (; it != itend; ++it) {
40 NetworkConstantAction* action = static_cast<NetworkConstantAction*>(&*it);
41 if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
42 min = action->latency_;
48 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
50 NetworkConstantAction* action = nullptr;
51 ActionList* actionSet = getRunningActionSet();
52 ActionList::iterator it(actionSet->begin());
53 ActionList::iterator itNext = it;
54 ActionList::iterator itend(actionSet->end());
55 for (; it != itend; it = itNext) {
57 action = static_cast<NetworkConstantAction*>(&*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->updateRemains(action->getCost() * delta / action->initialLatency_);
66 if (action->getMaxDuration() != NO_MAX_DURATION)
67 action->updateMaxDuration(delta);
69 if ((action->getRemainsNoUpdate() <= 0) ||
70 ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) {
71 action->finish(Action::State::done);
76 Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
78 NetworkConstantAction* action = new NetworkConstantAction(this, size, sg_latency_factor);
80 simgrid::s4u::Link::onCommunicate(action, src, dst);
87 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel* model_, double size, double latency)
88 : NetworkAction(model_, size, false), initialLatency_(latency)
91 if (latency_ <= 0.0) {
92 stateSet_ = model_->getDoneActionSet();
93 stateSet_->push_back(*this);
97 NetworkConstantAction::~NetworkConstantAction() = default;