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 == NULL);
17 surf_network_model = new simgrid::surf::NetworkConstantModel();
18 xbt_dynar_push(all_existing_models, &surf_network_model);
20 routing_model_create(NULL);
26 Link* NetworkConstantModel::createLink(const char *name, double bw, double lat, e_surf_link_sharing_policy_t policy,
27 xbt_dict_t properties) {
29 xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
30 "Please remove any link from your platform (and switch to routing='None')", name);
34 double NetworkConstantModel::next_occuring_event(double /*now*/)
36 NetworkConstantAction *action = NULL;
39 ActionList *actionSet = getRunningActionSet();
40 for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
41 ; it != itend ; ++it) {
42 action = static_cast<NetworkConstantAction*>(&*it);
43 if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
44 min = action->latency_;
50 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
52 NetworkConstantAction *action = NULL;
53 ActionList *actionSet = getRunningActionSet();
54 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
55 ; 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) {
71 action->setState(Action::State::done);
72 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
73 && (action->getMaxDuration() <= 0)) {
75 action->setState(Action::State::done);
80 Action *NetworkConstantModel::communicate(NetCard *src, NetCard *dst, double size, double rate)
82 NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
84 Link::onCommunicate(action, src, dst);
91 NetworkConstantAction::NetworkConstantAction(NetworkConstantModel *model_, double size, double latency)
92 : NetworkAction(model_, size, false)
93 , initialLatency_(latency)
96 if (latency_ <= 0.0) {
97 stateSet_ = getModel()->getDoneActionSet();
98 stateSet_->push_back(*this);