Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In <host> and <link>, attributes availability and state are gone.
[simgrid.git] / src / surf / network_cm02.cpp
index 4ab3280..5218880 100644 (file)
@@ -9,7 +9,6 @@
 #include "network_cm02.hpp"
 #include "maxmin_private.hpp"
 #include "simgrid/sg_config.h"
-#include "src/surf/platform.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
 
@@ -21,20 +20,6 @@ double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or
 double sg_tcp_gamma = 0.0;
 int sg_network_crosstraffic = 0;
 
-/*************
- * CallBacks *
- *************/
-
-void net_define_callbacks(void)
-{
-  /* Figuring out the network links */
-  simgrid::surf::on_link.connect(netlink_parse_init);
-}
-
-/*********
- * Model *
- *********/
-
 /************************************************************************/
 /* New model based on optimizations discussed during Pedro Velho's thesis*/
 /************************************************************************/
@@ -54,16 +39,13 @@ void surf_network_model_init_LegrandVelho(void)
   if (surf_network_model)
     return;
 
+  simgrid::surf::on_link.connect(netlink_parse_init);
   surf_network_model = new simgrid::surf::NetworkCm02Model();
-  net_define_callbacks();
-  simgrid::surf::Model *model = surf_network_model;
-  xbt_dynar_push(all_existing_models, &model);
-
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",
-                            13.01);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
-                            0.97);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 20537);
+  xbt_dynar_push(all_existing_models, &surf_network_model);
+
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",      13.01);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",     0.97);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",         20537);
 }
 
 /***************************************************************************/
@@ -83,13 +65,13 @@ void surf_network_model_init_CM02(void)
   if (surf_network_model)
     return;
 
+  simgrid::surf::on_link.connect(netlink_parse_init);
   surf_network_model = new simgrid::surf::NetworkCm02Model();
   xbt_dynar_push(all_existing_models, &surf_network_model);
-  net_define_callbacks();
 
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",   1.0);
   xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 1.0);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",         0.0);
 }
 
 /***************************************************************************/
@@ -107,15 +89,16 @@ void surf_network_model_init_Reno(void)
   if (surf_network_model)
     return;
 
+  simgrid::surf::on_link.connect(netlink_parse_init);
   surf_network_model = new simgrid::surf::NetworkCm02Model();
   xbt_dynar_push(all_existing_models, &surf_network_model);
-  net_define_callbacks();
+
   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
   surf_network_model->f_networkSolve = lagrange_solve;
 
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",     10.4);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",    0.92);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",         8775);
 }
 
 
@@ -124,15 +107,16 @@ void surf_network_model_init_Reno2(void)
   if (surf_network_model)
     return;
 
+  simgrid::surf::on_link.connect(netlink_parse_init);
   surf_network_model = new simgrid::surf::NetworkCm02Model();
   xbt_dynar_push(all_existing_models, &surf_network_model);
-  net_define_callbacks();
+
   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, func_reno2_fpi);
   surf_network_model->f_networkSolve = lagrange_solve;
 
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",    10.4);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",   0.92);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",        8775);
 }
 
 void surf_network_model_init_Vegas(void)
@@ -140,15 +124,16 @@ void surf_network_model_init_Vegas(void)
   if (surf_network_model)
     return;
 
+  simgrid::surf::on_link.connect(netlink_parse_init);
   surf_network_model = new simgrid::surf::NetworkCm02Model();
   xbt_dynar_push(all_existing_models, &surf_network_model);
-  net_define_callbacks();
+
   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
   surf_network_model->f_networkSolve = lagrange_solve;
 
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 0.92);
-  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",    10.4);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",   0.92);
+  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S",        8775);
 }
 
 namespace simgrid {
@@ -177,7 +162,7 @@ NetworkCm02Model::NetworkCm02Model()
 
   routing_model_create(createLink("__loopback__",
                                 498000000, NULL, 0.000015, NULL,
-                                1 /*SURF_RESOURCE_ON*/, NULL,
+                                NULL,
                                 SURF_LINK_FATPIPE, NULL));
 
   if (p_updateMechanism == UM_LAZY) {
@@ -189,21 +174,17 @@ NetworkCm02Model::NetworkCm02Model()
 }
 
 Link* NetworkCm02Model::createLink(const char *name,
-                                 double bw_initial,
-                                 tmgr_trace_t bw_trace,
-                                 double lat_initial,
-                                 tmgr_trace_t lat_trace,
-                                 int initiallyOn,
-                                 tmgr_trace_t state_trace,
-                                 e_surf_link_sharing_policy_t policy,
-                                 xbt_dict_t properties)
+    double bw_initial, tmgr_trace_t bw_trace,
+    double lat_initial, tmgr_trace_t lat_trace,
+    tmgr_trace_t state_trace,
+    e_surf_link_sharing_policy_t policy, xbt_dict_t properties)
 {
   xbt_assert(NULL == Link::byName(name),
              "Link '%s' declared several times in the platform",
              name);
 
   Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial,
-                     initiallyOn, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
+                     state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
   Link::onCreation(link);
   return link;
 }
@@ -217,11 +198,9 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
     XBT_DEBUG("Something happened to action %p", action);
     if (TRACE_is_enabled()) {
       int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
-      int i;
-      for (i = 0; i < n; i++){
-        lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
-                                                            action->getVariable(),
-                                                            i);
+
+      for (int i = 0; i < n; i++){
+        lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i);
         NetworkCm02Link *link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
         TRACE_surf_link_set_utilization(link->getName(),
                                         action->getCategory(),
@@ -285,11 +264,9 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
       }
       if (TRACE_is_enabled()) {
         int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable());
-        int i;
-        for (i = 0; i < n; i++){
-          lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
-                                                            action->getVariable(),
-                                                            i);
+        for (int i = 0; i < n; i++){
+          lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i);
+
           NetworkCm02Link* link = static_cast<NetworkCm02Link*>(lmm_constraint_id(constraint));
           TRACE_surf_link_set_utilization(link->getName(),
                                         action->getCategory(),
@@ -301,8 +278,7 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
                                         now - action->getLastUpdate());
         }
       }
-      if (!lmm_get_number_of_cnst_from_var
-          (p_maxminSystem, action->getVariable())) {
+      if (!lmm_get_number_of_cnst_from_var (p_maxminSystem, action->getVariable())) {
         /* There is actually no link used, hence an infinite bandwidth.
          * This happens often when using models like vivaldi.
          * In such case, just make sure that the action completes immediately.
@@ -326,7 +302,6 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
       action->gapRemove();
     }
   }
-  return;
 }
 
 Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
@@ -344,12 +319,12 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
 
   xbt_dynar_t route = xbt_dynar_new(sizeof(NetCard*), NULL);
 
-  XBT_IN("(%s,%s,%g,%g)", src->getName(), dst->getName(), size, rate);
+  XBT_IN("(%s,%s,%g,%g)", src->name(), dst->name(), size, rate);
 
   routing_platf->getRouteAndLatency(src, dst, &route, &latency);
   xbt_assert(!xbt_dynar_is_empty(route) || latency,
              "You're trying to send data from %s to %s but there is no connecting path between these two hosts.",
-             src->getName(), dst->getName());
+             src->name(), dst->name());
 
   xbt_dynar_foreach(route, i, _link) {
   link = static_cast<NetworkCm02Link*>(_link);
@@ -390,7 +365,7 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
     }
   }
   xbt_dynar_foreach(route, i, _link) {
-  link = static_cast<NetworkCm02Link*>(_link);
+    link = static_cast<NetworkCm02Link*>(_link);
     double bb = bandwidthFactor(size) * link->getBandwidth();
     bandwidth_bound =
         (bandwidth_bound < 0.0) ? bb : std::min(bandwidth_bound, bb);
@@ -406,7 +381,7 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
     link = *static_cast<NetworkCm02Link **>(xbt_dynar_get_ptr(route, 0));
     gapAppend(size, link, action);
     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
-              action, src->getName(), dst->getName(), action->m_senderGap,
+              action, src->name(), dst->name(), action->m_senderGap,
               action->m_latency);
   }
 
@@ -433,7 +408,7 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
   }
 
   xbt_dynar_foreach(route, i, _link) {
-  link = static_cast<NetworkCm02Link*>(_link);
+    link = static_cast<NetworkCm02Link*>(_link);
     lmm_expand(p_maxminSystem, link->getConstraint(), action->getVariable(), 1.0);
   }
 
@@ -457,19 +432,14 @@ Action *NetworkCm02Model::communicate(NetCard *src, NetCard *dst,
  * Resource *
  ************/
 NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props,
-                             lmm_system_t system,
-                             double constraint_value,
-                             int initiallyOn, tmgr_trace_t state_trace,
-                             double bw_peak, tmgr_trace_t bw_trace,
-                             double lat_initial, tmgr_trace_t lat_trace,
-                             e_surf_link_sharing_policy_t policy)
+    lmm_system_t system,
+    double constraint_value,
+    tmgr_trace_t state_trace,
+    double bw_peak, tmgr_trace_t bw_trace,
+    double lat_initial, tmgr_trace_t lat_trace,
+    e_surf_link_sharing_policy_t policy)
 : Link(model, name, props, lmm_constraint_new(system, this, constraint_value), state_trace)
 {
-  if (initiallyOn)
-    turnOn();
-  else
-    turnOff();
-
   m_bandwidth.scale = 1.0;
   m_bandwidth.peak = bw_peak;
   if (bw_trace)
@@ -483,7 +453,7 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_
     m_latency.event = future_evt_set->add_trace(lat_trace, 0.0, this);
 
   if (policy == SURF_LINK_FATPIPE)
-  lmm_constraint_shared(getConstraint());
+    lmm_constraint_shared(getConstraint());
 }
 
 
@@ -524,30 +494,26 @@ void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value)
     xbt_die("Unknown event!\n");
   }
 
-  XBT_DEBUG
-      ("There was a resource state event, need to update actions related to the constraint (%p)",
+  XBT_DEBUG("There was a resource state event, need to update actions related to the constraint (%p)",
        getConstraint());
 }
 
 void NetworkCm02Link::updateBandwidth(double value) {
-  double delta = sg_weight_S_parameter / value - sg_weight_S_parameter /
-                 (m_bandwidth.peak * m_bandwidth.scale);
-  lmm_variable_t var = NULL;
-  lmm_element_t elem = NULL;
-  lmm_element_t nextelem = NULL;
-  int numelem = 0;
-
-  NetworkCm02Action *action = NULL;
 
   m_bandwidth.peak = value;
-  lmm_update_constraint_bound(getModel()->getMaxminSystem(),
-                              getConstraint(),
-                              sg_bandwidth_factor *
-                              (m_bandwidth.peak * m_bandwidth.scale));
+
+  lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(),
+      sg_bandwidth_factor * (m_bandwidth.peak * m_bandwidth.scale));
   TRACE_surf_link_set_bandwidth(surf_get_clock(), getName(), sg_bandwidth_factor * m_bandwidth.peak * m_bandwidth.scale);
+
   if (sg_weight_S_parameter > 0) {
+    double delta = sg_weight_S_parameter / value - sg_weight_S_parameter / (m_bandwidth.peak * m_bandwidth.scale);
+
+    lmm_variable_t var;
+    lmm_element_t elem = NULL, nextelem = NULL;
+    int numelem = 0;
     while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
-      action = (NetworkCm02Action*) lmm_variable_id(var);
+      NetworkCm02Action *action = (NetworkCm02Action*) lmm_variable_id(var);
       action->m_weight += delta;
       if (!action->isSuspended())
         lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
@@ -561,11 +527,11 @@ void NetworkCm02Link::updateLatency(double value){
   lmm_element_t elem = NULL;
   lmm_element_t nextelem = NULL;
   int numelem = 0;
-  NetworkCm02Action *action = NULL;
 
   m_latency.peak = value;
+
   while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
-    action = (NetworkCm02Action*) lmm_variable_id(var);
+    NetworkCm02Action *action = (NetworkCm02Action*) lmm_variable_id(var);
     action->m_latCurrent += delta;
     action->m_weight += delta;
     if (action->m_rate < 0)
@@ -577,8 +543,7 @@ void NetworkCm02Link::updateLatency(double value){
       if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
         XBT_INFO("Flow is limited BYBANDWIDTH");
       } else {
-        XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
-                 action->m_latCurrent);
+        XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", action->m_latCurrent);
       }
     }
     if (!action->isSuspended())