1 /* Copyright (c) 2013-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "network_constant.hpp"
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
14 void surf_network_model_init_Constant()
16 xbt_assert(surf_network_model == nullptr);
17 surf_network_model = new simgrid::surf::NetworkConstantModel();
18 all_existing_models->push_back(surf_network_model);
23 Link* NetworkConstantModel::createLink(const char* name, double bw, double lat, 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 for(auto it(actionSet->begin()), itend(actionSet->end()) ; it != itend ; ++it) {
38 NetworkConstantAction *action = static_cast<NetworkConstantAction*>(&*it);
39 if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
40 min = action->latency_;
46 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
48 NetworkConstantAction *action = nullptr;
49 ActionList *actionSet = getRunningActionSet();
50 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
51 ; it != itend ; it=itNext) {
53 action = static_cast<NetworkConstantAction*>(&*it);
54 if (action->latency_ > 0) {
55 if (action->latency_ > delta) {
56 double_update(&(action->latency_), delta, sg_surf_precision);
58 action->latency_ = 0.0;
61 action->updateRemains(action->getCost() * delta / action->initialLatency_);
62 if (action->getMaxDuration() != NO_MAX_DURATION)
63 action->updateMaxDuration(delta);
65 if (action->getRemainsNoUpdate() <= 0) {
67 action->setState(Action::State::done);
68 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
69 && (action->getMaxDuration() <= 0)) {
71 action->setState(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 Link::onCommunicate(action, src, dst);
87 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel *model_, double size, double latency)
88 : NetworkAction(model_, size, false)
89 , initialLatency_(latency)
92 if (latency_ <= 0.0) {
93 stateSet_ = model_->getDoneActionSet();
94 stateSet_->push_back(*this);
98 NetworkConstantAction::~NetworkConstantAction() = default;