Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d9f36dddcf1d7f48248705b34f24fd60e6bd21eb
[simgrid.git] / src / surf / network_constant.cpp
1 /* Copyright (c) 2013-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "network_constant.hpp"
8 #include "surf/random_mgr.h"
9
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
11 static int host_number_int = 0;
12
13 static void netcste_count_hosts(sg_platf_host_cbarg_t /*h*/) {
14   host_number_int++;
15 }
16
17 /*********
18  * Model *
19  *********/
20 void surf_network_model_init_Constant()
21 {
22   xbt_assert(surf_network_model == NULL);
23   surf_network_model = new NetworkConstantModel();
24
25   sg_platf_host_add_cb(netcste_count_hosts);
26
27   ModelPtr model = static_cast<ModelPtr>(surf_network_model);
28   xbt_dynar_push(model_list, &model);
29 }
30
31 double NetworkConstantModel::shareResources(double /*now*/)
32 {
33   NetworkConstantActionPtr action = NULL;
34   double min = -1.0;
35
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) {
41       if (min < 0)
42         min = action->m_latency;
43       else if (action->m_latency < min)
44         min = action->m_latency;
45     }
46   }
47
48   return min;
49 }
50
51 void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
52 {
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) {
57     ++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);
62       } else {
63         action->m_latency = 0.0;
64       }
65     }
66     action->updateRemains(action->getCost() * delta / action->m_latInit);
67     if (action->getMaxDuration() != NO_MAX_DURATION)
68       action->updateMaxDuration(delta);
69
70     if (action->getRemainsNoUpdate() <= 0) {
71       action->finish();
72       action->setState(SURF_ACTION_DONE);
73     } else if ((action->getMaxDuration() != NO_MAX_DURATION)
74                && (action->getMaxDuration() <= 0)) {
75       action->finish();
76       action->setState(SURF_ACTION_DONE);
77     }
78   }
79 }
80
81 ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
82                                          double size, double rate)
83 {
84   char *src_name = src->getName();
85   char *dst_name = dst->getName();
86
87   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
88   NetworkConstantActionPtr action = new NetworkConstantAction(this, size, sg_latency_factor);
89   XBT_OUT();
90
91   return action;
92 }
93
94 /************
95  * Resource *
96  ************/
97 bool NetworkConstantLink::isUsed()
98 {
99   return 0;
100 }
101
102 void NetworkConstantLink::updateState(tmgr_trace_event_t /*event_type*/,
103                                          double /*value*/, double /*time*/)
104 {
105   DIE_IMPOSSIBLE;
106 }
107
108 double NetworkConstantLink::getBandwidth()
109 {
110   DIE_IMPOSSIBLE;
111   return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
112 }
113
114 double NetworkConstantLink::getLatency()
115 {
116   DIE_IMPOSSIBLE;
117   return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
118 }
119
120 bool NetworkConstantLink::isShared()
121 {
122   DIE_IMPOSSIBLE;
123   return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
124 }
125
126 /**********
127  * Action *
128  **********/
129
130 int NetworkConstantAction::unref()
131 {
132   m_refcount--;
133   if (!m_refcount) {
134         if (actionHook::is_linked())
135           p_stateSet->erase(p_stateSet->iterator_to(*this));
136     delete this;
137   return 1;
138   }
139   return 0;
140 }
141
142 void NetworkConstantAction::cancel()
143 {
144   return;
145 }
146
147 #ifdef HAVE_TRACING
148 void NetworkConstantAction::setCategory(const char */*category*/)
149 {
150   //ignore completely the categories in constant model, they are not traced
151 }
152 #endif
153
154 void NetworkConstantAction::suspend()
155 {
156   m_suspended = true;
157 }
158
159 void NetworkConstantAction::resume()
160 {
161   if (m_suspended)
162         m_suspended = false;
163 }
164
165 void NetworkConstantAction::recycle()
166 {
167   return;
168 }
169
170 bool NetworkConstantAction::isSuspended()
171 {
172   return m_suspended;
173 }
174