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"
8 #include "surf/random_mgr.h"
10 #include "host_interface.hpp"
11 #include "src/surf/platform.hpp"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
18 void surf_network_model_init_Constant()
20 xbt_assert(surf_network_model == NULL);
21 surf_network_model = new simgrid::surf::NetworkConstantModel();
23 routing_model_create(NULL);
25 simgrid::surf::on_link.connect([](sg_platf_link_cbarg_t link){
26 xbt_die("There is no link in the Constant network model. "
27 "Please remove any link from your platform (and switch to routing='None')");
31 simgrid::surf::Model *model = surf_network_model;
32 xbt_dynar_push(all_existing_models, &model);
38 double NetworkConstantModel::shareResources(double /*now*/)
40 NetworkConstantAction *action = NULL;
43 ActionList *actionSet = getRunningActionSet();
44 for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
45 ; it != itend ; ++it) {
46 action = static_cast<NetworkConstantAction*>(&*it);
47 if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
48 min = action->m_latency;
54 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
56 NetworkConstantAction *action = NULL;
57 ActionList *actionSet = getRunningActionSet();
58 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
59 ; it != itend ; it=itNext) {
61 action = static_cast<NetworkConstantAction*>(&*it);
62 if (action->m_latency > 0) {
63 if (action->m_latency > delta) {
64 double_update(&(action->m_latency), delta, sg_surf_precision);
66 action->m_latency = 0.0;
69 action->updateRemains(action->getCost() * delta / action->m_latInit);
70 if (action->getMaxDuration() != NO_MAX_DURATION)
71 action->updateMaxDuration(delta);
73 if (action->getRemainsNoUpdate() <= 0) {
75 action->setState(SURF_ACTION_DONE);
76 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
77 && (action->getMaxDuration() <= 0)) {
79 action->setState(SURF_ACTION_DONE);
84 Action *NetworkConstantModel::communicate(NetCard *src, NetCard *dst,
85 double size, double rate)
87 char *src_name = src->getName();
88 char *dst_name = dst->getName();
90 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
91 NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
94 networkCommunicateCallbacks(action, src, dst, size, rate);
102 int NetworkConstantAction::unref()
106 if (action_hook.is_linked())
107 p_stateSet->erase(p_stateSet->iterator_to(*this));
114 void NetworkConstantAction::cancel()