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"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
13 static int host_number_int = 0;
15 static void netcste_parse_nolink(sg_platf_link_cbarg_t link){
16 xbt_die("There is no link in the Constant network model. "
17 "Please remove any link from your platform (and switch to routing='None')");
23 void surf_network_model_init_Constant()
25 xbt_assert(surf_network_model == NULL);
26 surf_network_model = new NetworkConstantModel();
28 routing_model_create(NULL);
30 hostCreatedCallbacks.connect([](Host*) {
33 sg_platf_link_add_cb(netcste_parse_nolink);
35 Model *model = surf_network_model;
36 xbt_dynar_push(all_existing_models, &model);
39 double NetworkConstantModel::shareResources(double /*now*/)
41 NetworkConstantAction *action = NULL;
44 ActionList *actionSet = getRunningActionSet();
45 for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
46 ; it != itend ; ++it) {
47 action = static_cast<NetworkConstantAction*>(&*it);
48 if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
49 min = action->m_latency;
55 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
57 NetworkConstantAction *action = NULL;
58 ActionList *actionSet = getRunningActionSet();
59 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
60 ; it != itend ; it=itNext) {
62 action = static_cast<NetworkConstantAction*>(&*it);
63 if (action->m_latency > 0) {
64 if (action->m_latency > delta) {
65 double_update(&(action->m_latency), delta, sg_surf_precision);
67 action->m_latency = 0.0;
70 action->updateRemains(action->getCost() * delta / action->m_latInit);
71 if (action->getMaxDuration() != NO_MAX_DURATION)
72 action->updateMaxDuration(delta);
74 if (action->getRemainsNoUpdate() <= 0) {
76 action->setState(SURF_ACTION_DONE);
77 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
78 && (action->getMaxDuration() <= 0)) {
80 action->setState(SURF_ACTION_DONE);
85 Action *NetworkConstantModel::communicate(RoutingEdge *src, RoutingEdge *dst,
86 double size, double rate)
88 char *src_name = src->getName();
89 char *dst_name = dst->getName();
91 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
92 NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
95 surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
103 int NetworkConstantAction::unref()
107 if (action_hook.is_linked())
108 p_stateSet->erase(p_stateSet->iterator_to(*this));
115 void NetworkConstantAction::cancel()
120 void NetworkConstantAction::setCategory(const char * /*category*/)
122 //ignore completely the categories in constant model, they are not traced
125 void NetworkConstantAction::suspend()
130 void NetworkConstantAction::resume()
136 bool NetworkConstantAction::isSuspended()