Logo AND Algorithmique Numérique Distribuée

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