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 = 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 && (min < 0 || action->m_latency < min))
41 min = action->m_latency;
47 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
49 NetworkConstantActionPtr action = NULL;
50 ActionListPtr actionSet = getRunningActionSet();
51 for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
52 ; it != itend ; it=itNext) {
54 action = static_cast<NetworkConstantActionPtr>(&*it);
55 if (action->m_latency > 0) {
56 if (action->m_latency > delta) {
57 double_update(&(action->m_latency), delta, sg_surf_precision);
59 action->m_latency = 0.0;
62 action->updateRemains(action->getCost() * delta / action->m_latInit);
63 if (action->getMaxDuration() != NO_MAX_DURATION)
64 action->updateMaxDuration(delta);
66 if (action->getRemainsNoUpdate() <= 0) {
68 action->setState(SURF_ACTION_DONE);
69 } else if ((action->getMaxDuration() != NO_MAX_DURATION)
70 && (action->getMaxDuration() <= 0)) {
72 action->setState(SURF_ACTION_DONE);
77 ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
78 double size, double rate)
80 char *src_name = src->getName();
81 char *dst_name = dst->getName();
83 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
84 NetworkConstantActionPtr action = new NetworkConstantAction(this, size, sg_latency_factor);
87 surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
94 bool NetworkConstantLink::isUsed()
99 void NetworkConstantLink::updateState(tmgr_trace_event_t /*event_type*/,
100 double /*value*/, double /*time*/)
105 double NetworkConstantLink::getBandwidth()
108 return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
111 double NetworkConstantLink::getLatency()
114 return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
117 bool NetworkConstantLink::isShared()
120 return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
127 int NetworkConstantAction::unref()
131 if (actionHook::is_linked())
132 p_stateSet->erase(p_stateSet->iterator_to(*this));
139 void NetworkConstantAction::cancel()
144 void NetworkConstantAction::setCategory(const char */*category*/)
146 //ignore completely the categories in constant model, they are not traced
149 void NetworkConstantAction::suspend()
154 void NetworkConstantAction::resume()
160 void NetworkConstantAction::recycle()
165 bool NetworkConstantAction::isSuspended()