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);
14 static int host_number_int = 0;
16 static void netcste_parse_nolink(sg_platf_link_cbarg_t link){
17 xbt_die("There is no link in the Constant network model. "
18 "Please remove any link from your platform (and switch to routing='None')");
24 void surf_network_model_init_Constant()
26 xbt_assert(surf_network_model == NULL);
27 surf_network_model = new simgrid::surf::NetworkConstantModel();
29 routing_model_create(NULL);
31 simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host&) {
34 simgrid::surf::on_link.connect(netcste_parse_nolink);
36 simgrid::surf::Model *model = surf_network_model;
37 xbt_dynar_push(all_existing_models, &model);
43 double NetworkConstantModel::shareResources(double /*now*/)
45 NetworkConstantAction *action = NULL;
48 ActionList *actionSet = getRunningActionSet();
49 for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
50 ; it != itend ; ++it) {
51 action = static_cast<NetworkConstantAction*>(&*it);
52 if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
53 min = action->m_latency;
59 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
61 NetworkConstantAction *action = NULL;
62 ActionList *actionSet = getRunningActionSet();
63 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
64 ; it != itend ; it=itNext) {
66 action = static_cast<NetworkConstantAction*>(&*it);
67 if (action->m_latency > 0) {
68 if (action->m_latency > delta) {
69 double_update(&(action->m_latency), delta, sg_surf_precision);
71 action->m_latency = 0.0;
74 action->updateRemains(action->getCost() * delta / action->m_latInit);
75 if (action->getMaxDuration() != NO_MAX_DURATION)
76 action->updateMaxDuration(delta);
78 if (action->getRemainsNoUpdate() <= 0) {
80 action->setState(SURF_ACTION_DONE);
81 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
82 && (action->getMaxDuration() <= 0)) {
84 action->setState(SURF_ACTION_DONE);
89 Action *NetworkConstantModel::communicate(NetCard *src, NetCard *dst,
90 double size, double rate)
92 char *src_name = src->getName();
93 char *dst_name = dst->getName();
95 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
96 NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
99 networkCommunicateCallbacks(action, src, dst, size, rate);
107 int NetworkConstantAction::unref()
111 if (action_hook.is_linked())
112 p_stateSet->erase(p_stateSet->iterator_to(*this));
119 void NetworkConstantAction::cancel()