Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix copyright headers
[simgrid.git] / src / surf / network.c
index ecd6d4e..de86cc0 100644 (file)
@@ -1,6 +1,5 @@
-/*     $Id$     */
-
-/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -16,9 +15,9 @@ surf_model_t surf_network_model = NULL;
 static lmm_system_t network_maxmin_system = NULL;
 static void (*network_solve) (lmm_system_t) = NULL;
 
-double latency_factor = 1.0;    /* default value */
-double bandwidth_factor = 1.0;  /* default value */
-double weight_S_parameter = 0.0;        /* default value */
+double sg_latency_factor = 1.0;    /* default value; can be set by model or from command line */
+double sg_bandwidth_factor = 1.0;  /* default value; can be set by model or from command line */
+double sg_weight_S_parameter = 0.0;/* default value; can be set by model or from command line */
 
 double sg_tcp_gamma = 0.0;
 
@@ -38,7 +37,7 @@ static link_CM02_t net_link_new(char *name,
     surf_resource_lmm_new(sizeof(s_link_CM02_t),
                           surf_network_model, name, properties,
                           network_maxmin_system,
-                          bandwidth_factor * bw_initial,
+                          sg_bandwidth_factor * bw_initial,
                           history,
                           state_initial, state_trace,
                           bw_initial, bw_trace);
@@ -56,6 +55,9 @@ static link_CM02_t net_link_new(char *name,
 
   xbt_dict_set(surf_network_model->resource_set, name, nw_link,
                surf_resource_free);
+#ifdef HAVE_TRACING
+  TRACE_surf_link_declaration (name, bw_initial, lat_initial);
+#endif
 
   return nw_link;
 }
@@ -234,6 +236,17 @@ static void net_update_actions_state(double now, double delta)
    */
 
   xbt_swag_foreach_safe(action, next_action, running_actions) {
+
+#ifdef HAVE_TRACING
+    xbt_dynar_t route = used_routing->get_route(action->src, action->dst);
+    link_CM02_t link;
+    unsigned int i;
+    xbt_dynar_foreach(route, i, link) {
+       TRACE_surf_link_set_utilization (link->lmm_resource.generic_resource.name,
+          action->generic_action.data, lmm_variable_getvalue(action->variable), now-delta, delta);
+    }
+#endif
+
     deltap = delta;
     if (action->latency > 0) {
       if (action->latency > deltap) {
@@ -279,7 +292,7 @@ static void net_update_resource_state(void *id,
 
   if (event_type == nw_link->lmm_resource.power.event) {
     double delta =
-      weight_S_parameter / value - weight_S_parameter /
+      sg_weight_S_parameter / value - sg_weight_S_parameter /
       (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale);
     lmm_variable_t var = NULL;
     lmm_element_t elem = NULL;
@@ -288,10 +301,13 @@ static void net_update_resource_state(void *id,
     nw_link->lmm_resource.power.peak = value;
     lmm_update_constraint_bound(network_maxmin_system,
                                 nw_link->lmm_resource.constraint,
-                                bandwidth_factor *
+                                sg_bandwidth_factor *
                                 (nw_link->lmm_resource.power.peak *
                                  nw_link->lmm_resource.power.scale));
-    if (weight_S_parameter > 0) {
+#ifdef HAVE_TRACING
+    TRACE_surf_link_set_bandwidth (date, nw_link->lmm_resource.generic_resource.name, sg_bandwidth_factor * (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale));
+#endif
+    if (sg_weight_S_parameter > 0) {
       while ((var = lmm_get_var_from_cnst
               (network_maxmin_system, nw_link->lmm_resource.constraint,
                &elem))) {
@@ -402,13 +418,13 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name,
     action->latency += link->lat_current;
     action->weight +=
       link->lat_current +
-      weight_S_parameter /
+      sg_weight_S_parameter /
       (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
   }
   /* LARGE PLATFORMS HACK:
      Add src->link and dst->link latencies */
   action->lat_current = action->latency;
-  action->latency *= latency_factor;
+  action->latency *= sg_latency_factor;
 
   /* LARGE PLATFORMS HACK:
      lmm_variable_new(..., total_route_size) */
@@ -446,6 +462,10 @@ static surf_action_t net_communicate(const char *src_name, const char *dst_name,
   /* LARGE PLATFORMS HACK:
      expand also with src->link and dst->link */
 
+  /* saving the src and dst of this communication */
+  action->src = src;
+  action->dst = dst;
+
   XBT_OUT;
 
   return (surf_action_t) action;
@@ -558,9 +578,9 @@ void surf_network_model_init_LegrandVelho(const char *filename)
   xbt_dynar_push(model_list, &surf_network_model);
   network_solve = lmm_solve;
 
-  latency_factor = 10.4;
-  bandwidth_factor = 0.92;
-  weight_S_parameter = 8775;
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor",10.4);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
 
   update_model_description(surf_network_model_description,
                            "LV08", surf_network_model);
@@ -602,9 +622,9 @@ void surf_network_model_init_Reno(const char *filename)
   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
   network_solve = lagrange_solve;
 
-  latency_factor = 10.4;
-  bandwidth_factor = 0.92;
-  weight_S_parameter = 8775;
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
 
   update_model_description(surf_network_model_description,
                            "Reno", surf_network_model);
@@ -623,9 +643,9 @@ void surf_network_model_init_Reno2(const char *filename)
                                     func_reno2_fpi);
   network_solve = lagrange_solve;
 
-  latency_factor = 10.4;
-  bandwidth_factor = 0.92;
-  weight_S_parameter = 8775;
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S_parameter", 8775);
 
   update_model_description(surf_network_model_description,
                            "Reno2", surf_network_model);
@@ -643,9 +663,9 @@ void surf_network_model_init_Vegas(const char *filename)
                                     func_vegas_fpi);
   network_solve = lagrange_solve;
 
-  latency_factor = 10.4;
-  bandwidth_factor = 0.92;
-  weight_S_parameter = 8775;
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/latency_factor", 10.4);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/bandwidth_factor", 0.92);
+  xbt_cfg_setdefault_double(_surf_cfg_set,"network/weight_S", 8775);
 
   update_model_description(surf_network_model_description,
                            "Vegas", surf_network_model);