Logo AND Algorithmique Numérique Distribuée

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