Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not require doxygen in maintainer mode
[simgrid.git] / src / surf / network_constant.c
index 9665c2d..1f06f33 100644 (file)
@@ -7,11 +7,11 @@
 
 #include "surf_private.h"
 #include "network_common.h"
+#include "surf/random_mgr.h"
 #include "xbt/dict.h"
 #include "xbt/str.h"
 #include "xbt/log.h"
 
-#define CONSTANT_VALUE 1.0
 typedef struct network_card_Constant {
   char *name;
   int id;
@@ -20,15 +20,14 @@ typedef struct network_card_Constant {
 typedef struct surf_action_network_Constant {
   s_surf_action_t generic_action;
   double latency;
-  double lat_current;
-  double rate;
+  double lat_init;
   int suspended;
   network_card_Constant_t src;
   network_card_Constant_t dst;
 } s_surf_action_network_Constant_t, *surf_action_network_Constant_t;
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
-
+static random_data_t random_latency = NULL;
 static int card_number = 0;
 static int host_number = 0;
 
@@ -60,7 +59,6 @@ static void parse_route_set_endpoints(void)
   src_id = network_card_new(A_surfxml_route_src);
   dst_id = network_card_new(A_surfxml_route_dst);
   route_action = A_surfxml_route_action;
-  route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
 }
 
 static void parse_route_set_route(void)
@@ -82,19 +80,8 @@ static void define_callbacks(const char *file)
 {
   /* Figuring out the network links */
   surfxml_add_callback(STag_surfxml_host_cb_list, &count_hosts);
-  surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
-  surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
   surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-  surfxml_add_callback(STag_surfxml_platform_cb_list, &init_data);
-  surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
-  surfxml_add_callback(STag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_endpoints);
-  surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_route);
-  surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_foreach);
-  surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_cluster);
-  surfxml_add_callback(STag_surfxml_trace_cb_list, &parse_trace_init);
-  surfxml_add_callback(ETag_surfxml_trace_cb_list, &parse_trace_finalize);
-  surfxml_add_callback(STag_surfxml_trace_c_connect_cb_list, &parse_trace_c_connect);
 }
 
 static void *name_service(const char *name)
@@ -115,8 +102,8 @@ static int resource_used(void *resource_id)
 
 static int action_free(surf_action_t action)
 {
-  action->using--;
-  if (!action->using) {
+  action->refcount --;
+  if (!action->refcount ) {
     xbt_swag_remove(action, action->state_set);
     free(action);
     return 1;
@@ -126,7 +113,7 @@ static int action_free(surf_action_t action)
 
 static void action_use(surf_action_t action)
 {
-  action->using++;
+  action->refcount ++;
 }
 
 static void action_cancel(surf_action_t action)
@@ -181,7 +168,7 @@ static void update_actions_state(double now, double delta)
       }
     }
     double_update(&(action->generic_action.remains),
-                 action->generic_action.cost * delta/ CONSTANT_VALUE);
+                 action->generic_action.cost * delta/action->lat_init);
     if (action->generic_action.max_duration != NO_MAX_DURATION)
       double_update(&(action->generic_action.max_duration), delta);
 
@@ -200,7 +187,7 @@ static void update_actions_state(double now, double delta)
 
 static void update_resource_state(void *id,
                                  tmgr_trace_event_t event_type,
-                                 double value)
+                                 double value, double time)
 {
   DIE_IMPOSSIBLE;
 }
@@ -216,7 +203,7 @@ static surf_action_t communicate(void *src, void *dst, double size,
 
   action = xbt_new0(s_surf_action_network_Constant_t, 1);
 
-  action->generic_action.using = 1;
+  action->generic_action.refcount  = 1;
   action->generic_action.cost = size;
   action->generic_action.remains = size;
   action->generic_action.max_duration = NO_MAX_DURATION;
@@ -225,14 +212,19 @@ static surf_action_t communicate(void *src, void *dst, double size,
   action->generic_action.model_type =
       (surf_model_t) surf_network_model;
   action->suspended = 0;
-  action->generic_action.state_set =
+
+  action->latency = random_generate(random_latency);
+  action->lat_init = action->latency;
+
+  if(action->latency<=0.0)
+    action->generic_action.state_set =
+      surf_network_model->common_public->states.done_action_set;
+  else
+    action->generic_action.state_set =
       surf_network_model->common_public->states.running_action_set;
 
   xbt_swag_insert(action, action->generic_action.state_set);
-  action->rate = rate;
 
-  action->latency = CONSTANT_VALUE;
-  action->lat_current = action->latency;
 
   XBT_OUT;
 
@@ -267,6 +259,11 @@ static double get_link_latency(const void *link)
   DIE_IMPOSSIBLE;
 }
 
+static int link_shared(const void *link)
+{
+  DIE_IMPOSSIBLE;
+}
+
 static xbt_dict_t get_properties(void *link)
 {
   DIE_IMPOSSIBLE;
@@ -296,7 +293,6 @@ static void action_set_max_duration(surf_action_t action, double duration)
 static void finalize(void)
 {
   xbt_dict_free(&network_card_set);
-  xbt_dict_free(&link_set);
   xbt_swag_free(surf_network_model->common_public->states.
                ready_action_set);
   xbt_swag_free(surf_network_model->common_public->states.
@@ -378,12 +374,15 @@ static void surf_network_model_init_internal(void)
       get_link_bandwidth;
   surf_network_model->extension_public->get_link_latency =
       get_link_latency;
+  surf_network_model->extension_public->link_shared =
+      link_shared;
 
   surf_network_model->common_public->get_properties =  get_properties;
 
-  link_set = xbt_dict_new();
   network_card_set = xbt_dict_new();
 
+  if(!random_latency) 
+    random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034);
 }
 
 void surf_network_model_init_Constant(const char *filename)
@@ -396,7 +395,6 @@ void surf_network_model_init_Constant(const char *filename)
   xbt_dynar_push(model_list, &surf_network_model);
 
   update_model_description(surf_network_model_description,
-                             surf_network_model_description_size,
-                             "Constant",
-                             (surf_model_t) surf_network_model);
+                          "Constant",
+                          (surf_model_t) surf_network_model);
 }