Logo AND Algorithmique Numérique Distribuée

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