Logo AND Algorithmique Numérique Distribuée

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