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 simgrid::surf::NetworkConstantModel();
28 routing_model_create(NULL);
30 simgrid::surf::Host::creationCallbacks.connect([](simgrid::surf::Host*) {
33 sg_platf_link_add_cb(netcste_parse_nolink);
35 simgrid::surf::Model *model = surf_network_model;
36 xbt_dynar_push(all_existing_models, &model);
42 double NetworkConstantModel::shareResources(double /*now*/)
44 NetworkConstantAction *action = NULL;
47 ActionList *actionSet = getRunningActionSet();
48 for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
49 ; it != itend ; ++it) {
50 action = static_cast<NetworkConstantAction*>(&*it);
51 if (action->m_latency > 0 && (min < 0 || action->m_latency < min))
52 min = action->m_latency;
58 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
60 NetworkConstantAction *action = NULL;
61 ActionList *actionSet = getRunningActionSet();
62 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
63 ; it != itend ; it=itNext) {
65 action = static_cast<NetworkConstantAction*>(&*it);
66 if (action->m_latency > 0) {
67 if (action->m_latency > delta) {
68 double_update(&(action->m_latency), delta, sg_surf_precision);
70 action->m_latency = 0.0;
73 action->updateRemains(action->getCost() * delta / action->m_latInit);
74 if (action->getMaxDuration() != NO_MAX_DURATION)
75 action->updateMaxDuration(delta);
77 if (action->getRemainsNoUpdate() <= 0) {
79 action->setState(SURF_ACTION_DONE);
80 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
81 && (action->getMaxDuration() <= 0)) {
83 action->setState(SURF_ACTION_DONE);
88 Action *NetworkConstantModel::communicate(RoutingEdge *src, RoutingEdge *dst,
89 double size, double rate)
91 char *src_name = src->getName();
92 char *dst_name = dst->getName();
94 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
95 NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
98 networkCommunicateCallbacks(action, src, dst, size, rate);
106 int NetworkConstantAction::unref()
110 if (action_hook.is_linked())
111 p_stateSet->erase(p_stateSet->iterator_to(*this));
118 void NetworkConstantAction::cancel()
123 void NetworkConstantAction::setCategory(const char * /*category*/)
125 //ignore completely the categories in constant model, they are not traced
128 void NetworkConstantAction::suspend()
133 void NetworkConstantAction::resume()
139 bool NetworkConstantAction::isSuspended()