1 /* Copyright (c) 2013-2014. 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 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
11 static int host_number_int = 0;
13 static void netcste_count_hosts(sg_platf_host_cbarg_t /*h*/) {
20 void surf_network_model_init_Constant()
22 xbt_assert(surf_network_model == NULL);
23 surf_network_model = new NetworkConstantModel();
25 sg_platf_host_add_cb(netcste_count_hosts);
27 ModelPtr model = static_cast<ModelPtr>(surf_network_model);
28 xbt_dynar_push(model_list, &model);
31 double NetworkConstantModel::shareResources(double /*now*/)
33 NetworkConstantActionPtr action = NULL;
36 ActionListPtr actionSet = getRunningActionSet();
37 for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
38 ; it != itend ; ++it) {
39 action = static_cast<NetworkConstantActionPtr>(&*it);
40 if (action->m_latency > 0) {
42 min = action->m_latency;
43 else if (action->m_latency < min)
44 min = action->m_latency;
51 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
53 NetworkConstantActionPtr action = NULL;
54 ActionListPtr actionSet = getRunningActionSet();
55 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
56 ; it != itend ; it=itNext) {
58 action = static_cast<NetworkConstantActionPtr>(&*it);
59 if (action->m_latency > 0) {
60 if (action->m_latency > delta) {
61 double_update(&(action->m_latency), delta);
63 action->m_latency = 0.0;
66 action->updateRemains(action->getCost() * delta / action->m_latInit);
67 if (action->getMaxDuration() != NO_MAX_DURATION)
68 action->updateMaxDuration(delta);
70 if (action->getRemainsNoUpdate() <= 0) {
72 action->setState(SURF_ACTION_DONE);
73 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
74 && (action->getMaxDuration() <= 0)) {
76 action->setState(SURF_ACTION_DONE);
81 ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
82 double size, double rate)
84 char *src_name = src->getName();
85 char *dst_name = dst->getName();
87 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
88 NetworkConstantActionPtr action = new NetworkConstantAction(this, size, sg_latency_factor);
97 bool NetworkConstantLink::isUsed()
102 void NetworkConstantLink::updateState(tmgr_trace_event_t /*event_type*/,
103 double /*value*/, double /*time*/)
108 double NetworkConstantLink::getBandwidth()
111 return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
114 double NetworkConstantLink::getLatency()
117 return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
120 bool NetworkConstantLink::isShared()
123 return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
130 int NetworkConstantAction::unref()
134 if (actionHook::is_linked())
135 p_stateSet->erase(p_stateSet->iterator_to(*this));
142 void NetworkConstantAction::cancel()
148 void NetworkConstantAction::setCategory(const char */*category*/)
150 //ignore completely the categories in constant model, they are not traced
154 void NetworkConstantAction::suspend()
159 void NetworkConstantAction::resume()
165 void NetworkConstantAction::recycle()
170 bool NetworkConstantAction::isSuspended()