Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid
authorMarion Guthmuller <marion.guthmuller@loria.fr>
Wed, 7 Mar 2012 17:29:13 +0000 (18:29 +0100)
committerMarion Guthmuller <marion.guthmuller@loria.fr>
Wed, 7 Mar 2012 17:29:13 +0000 (18:29 +0100)
20 files changed:
buildtools/Cmake/Distrib.cmake
doc/FAQ.doc
examples/msg/migration/migration.c
examples/msg/tracing/categories.tesh
examples/msg/tracing/ms.tesh
examples/msg/tracing/procmig.tesh
examples/msg/tracing/trace_platform.tesh
examples/smpi/tracing/smpi_traced.tesh
src/gras/Transport/rl_transport.c
src/include/surf/surf.h
src/instr/instr_config.c
src/instr/instr_private.h
src/instr/instr_resource_utilization.c
src/instr/instr_routing.c
src/surf/cpu_cas01.c
src/surf/network.c
src/surf/network_ns3.c
src/surf/network_private.h
src/surf/surf_routing.c
src/surf/workstation.c

index 0e63df6..58c37f4 100644 (file)
@@ -26,7 +26,7 @@ add_custom_target(manpages ALL
        COMMENT "Generating manpages"
 )
 install(FILES ${MANPAGE_DIR}/simgrid_update_xml.1
-        DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/usr/share/man/man1)
+        DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/man/man1)
 
 endif(NOT WIN32)
 
@@ -138,6 +138,7 @@ COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_INSTALL_PREFIX}/bin/tesh
 COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/bin/simgrid-colorizer
 COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/bin/simgrid_update_xml
 COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/bin/gras_stub_generator
+COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/bin/graphicator
 COMMAND ${CMAKE_COMMAND} -E    echo "uninstall bin ok"
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/amok
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/gras
@@ -145,13 +146,17 @@ COMMAND ${CMAKE_COMMAND} -E       remove_directory ${CMAKE_INSTALL_PREFIX}/include/ins
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/msg 
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/simdag
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/smpi
+COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/simix
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/surf
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/xbt
 COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/mc
+COMMAND ${CMAKE_COMMAND} -E    remove_directory ${CMAKE_INSTALL_PREFIX}/include/simgrid
 COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/include/simgrid_config.h
 COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/include/gras.h 
 COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/include/xbt.h
 COMMAND ${CMAKE_COMMAND} -E    echo "uninstall include ok"
+COMMAND ${CMAKE_COMMAND} -E    remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/simgrid_update_xml.1
+COMMAND ${CMAKE_COMMAND} -E    echo "uninstall man ok"
 WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}"
 )
 
index 010990b..42e6649 100644 (file)
@@ -970,9 +970,7 @@ informative bug repports:
 http://www.chiark.greenend.org.uk/~sgtatham/bugs.html (it is not SimGrid
 specific at all, but it's full of good advices).
 
-\author Arnaud Legrand (arnaud.legrand::imag.fr)
-\author Martin Quinson (martin.quinson::loria.fr)
-
+\author Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
 
 */
 
index 2fc714d..cd2b65d 100644 (file)
@@ -12,6 +12,8 @@
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
                              "Messages specific for this msg example");
 
+xbt_mutex_t mutex = NULL;
+xbt_cond_t cond = NULL;
 static m_process_t process_to_migrate = NULL;
 
 /** The guy we will move from host to host. It move alone and then is moved by policeman back  */
@@ -31,7 +33,10 @@ static int emigrant(int argc, char *argv[])
   MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin"));
   MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
   MSG_process_sleep(4);
+  xbt_mutex_acquire(mutex);
   process_to_migrate = MSG_process_self();
+  xbt_cond_broadcast(cond);
+  xbt_mutex_release(mutex);
   MSG_process_suspend(MSG_process_self());
   m_host_t h = MSG_process_get_host(MSG_process_self());
   XBT_INFO("I've been moved on this new host: %s", h->name);
@@ -43,11 +48,15 @@ static int emigrant(int argc, char *argv[])
 /* This function move the emigrant on Jacquelin */
 static int policeman(int argc, char *argv[])
 {
+
+  xbt_mutex_acquire(mutex);
   XBT_INFO("Wait a bit before migrating the emigrant.");
-  while (process_to_migrate == NULL) MSG_process_sleep(1);
+  while (process_to_migrate == NULL) xbt_cond_wait(cond, mutex);
   MSG_process_migrate(process_to_migrate, MSG_get_host_by_name("Jacquelin"));
   XBT_INFO("I moved the emigrant");
   MSG_process_resume(process_to_migrate);
+  xbt_mutex_release(mutex);
+
   return 0;
 }                               /* end_of_policeman */
 
@@ -75,8 +84,13 @@ int main(int argc, char *argv[])
   MSG_launch_application(argv[2]);
 
   /* Run the simulation */
+  mutex = xbt_mutex_init();
+  cond = xbt_cond_init();
   res = MSG_main();
   XBT_INFO("Simulation time %g", MSG_get_clock());
+  xbt_cond_destroy(cond);
+  xbt_mutex_destroy(mutex);
+
   if (res == MSG_OK)
     res = MSG_clean();
 
index a4ad298..2cd60cc 100644 (file)
@@ -10,12 +10,11 @@ $ $SG_TEST_EXENV ${bindir:=.}/tracing/categories$EXEEXT --cfg=tracing:1 --cfg=tr
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/categorized' to 'tracing/categories.cat.plist'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/uncategorized' to 'tracing/categories.uncat.plist'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ $SG_TEST_EXENV cat tracing/categories.cat.plist
 > {
 >   node = (LINK, HOST, );
->   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
+>   edge = (0-LINK4-HOST1, 0-HOST1-LINK4, 0-LINK4-LINK4, );
 > 
 >   host = {
 >     type = square;
@@ -32,7 +31,7 @@ $ $SG_TEST_EXENV cat tracing/categories.cat.plist
 $ $SG_TEST_EXENV cat tracing/categories.uncat.plist
 > {
 >   node = (LINK, HOST, );
->   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
+>   edge = (0-LINK4-HOST1, 0-HOST1-LINK4, 0-LINK4-LINK4, );
 > 
 >   host = {
 >     type = square;
index b3770d9..84635eb 100644 (file)
@@ -9,7 +9,6 @@ $ $SG_TEST_EXENV ${bindir:=.}/tracing/ms$EXEEXT --cfg=tracing:1 --cfg=tracing/bu
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/categorized' to 'tracing/ms.cat.plist'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/uncategorized' to 'tracing/ms.uncat.plist'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 p Testing tracing by process 
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/ms$EXEEXT --cfg=tracing:1 --cfg=tracing/msg/process:1 --cfg=tracing/buffer:1 --cfg=tracing/filename:tracing/ms.trace --cfg=tracing/categorized:1 --cfg=tracing/uncategorized:1 --cfg=triva/categorized:tracing/ms.cat.plist --cfg=triva/uncategorized:tracing/ms.uncat.plist ${srcdir:=.}/tracing/platform.xml ${srcdir:=.}/tracing/deployment.xml
@@ -21,12 +20,11 @@ $ $SG_TEST_EXENV ${bindir:=.}/tracing/ms$EXEEXT --cfg=tracing:1 --cfg=tracing/ms
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/categorized' to 'tracing/ms.cat.plist'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/uncategorized' to 'tracing/ms.uncat.plist'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ $SG_TEST_EXENV cat tracing/ms.uncat.plist
 > {
 >   node = (LINK, HOST, );
->   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
+>   edge = (0-HOST1-LINK14, 0-LINK14-HOST1, 0-LINK14-LINK14, );
 > 
 >   host = {
 >     type = square;
@@ -43,7 +41,7 @@ $ $SG_TEST_EXENV cat tracing/ms.uncat.plist
 $ $SG_TEST_EXENV cat tracing/ms.cat.plist
 > {
 >   node = (LINK, HOST, );
->   edge = (HOST-LINK, LINK-HOST, LINK-LINK, );
+>   edge = (0-HOST1-LINK14, 0-LINK14-HOST1, 0-LINK14-LINK14, );
 > 
 >   host = {
 >     type = square;
index ce4170c..1a6e400 100644 (file)
@@ -14,7 +14,6 @@ $ $SG_TEST_EXENV ${bindir:=.}/tracing/procmig$EXEEXT --cfg=tracing:1 --cfg=traci
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/buffer' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/filename' to 'tracing/procmig.trace'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/msg/process' to '1'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/procmig$EXEEXT --cfg=tracing/categorized:1 --cfg=tracing/uncategorized:1 --cfg=tracing/buffer:0 --cfg=tracing/filename:tracing/procmig.trace --cfg=tracing/msg/process:1 ${srcdir:=.}/tracing/platform.xml ${srcdir:=.}/tracing/procmig-deploy.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to '1'
@@ -31,12 +30,10 @@ $ $SG_TEST_EXENV ${bindir:=.}/tracing/procmig$EXEEXT --cfg=tracing:0 ${srcdir:=.
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/procmig$EXEEXT --cfg=tracing:1 --cfg=tracing/categorized:1 ${srcdir:=.}/tracing/platform.xml ${srcdir:=.}/tracing/procmig-deploy.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to '1'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/procmig$EXEEXT --cfg=tracing:1 --cfg=tracing/uncategorized:1 ${srcdir:=.}/tracing/platform.xml ${srcdir:=.}/tracing/procmig-deploy.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to '1'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/procmig$EXEEXT --cfg=tracing:1 --cfg=tracing/msg/process:1 ${srcdir:=.}/tracing/platform.xml ${srcdir:=.}/tracing/procmig-deploy.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to '1'
index b545934..8e3ade2 100644 (file)
@@ -4,7 +4,6 @@ p Tracing master/slave application
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/trace_platform$EXEEXT --cfg=tracing:1 --cfg=tracing/categorized:1 ${srcdir:=.}/tracing/platform.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to '1'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ cat simgrid.trace
 > %EventDef PajeDefineContainerType 0 
@@ -156,10 +155,10 @@ $ cat simgrid.trace
 > 6 0 15 3 0 "5"
 > 8 0 4 15 27946250.000000
 > 8 0 5 15 0.000278
-> 4 6 0 1 3 HOST-LINK
+> 4 6 0 1 3 0-HOST1-LINK3
 > 14 0 6 0 G 3 0
 > 15 0 6 0 G 11 0
-> 4 7 0 3 3 LINK-LINK
+> 4 7 0 3 3 0-LINK3-LINK3
 > 14 0 7 0 G 11 1
 > 15 0 7 0 G 12 1
 > 14 0 7 0 G 12 2
@@ -170,7 +169,7 @@ $ cat simgrid.trace
 > 15 0 7 0 G 7 4
 > 14 0 7 0 G 7 5
 > 15 0 7 0 G 13 5
-> 4 8 0 3 1 LINK-HOST
+> 4 8 0 3 1 0-LINK3-HOST1
 > 14 0 8 0 G 13 6
 > 15 0 8 0 G 1 6
 > 14 0 7 0 G 11 7
@@ -213,7 +212,6 @@ $ cat simgrid.trace
 $ $SG_TEST_EXENV ${bindir:=.}/tracing/trace_platform$EXEEXT --cfg=tracing:1 --cfg=tracing/categorized:1 ${srcdir:=.}/../platforms/g5k.xml
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to '1'
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 $ cat simgrid.trace
 > %EventDef PajeDefineContainerType 0 
index 2dbad1b..f589f01 100644 (file)
@@ -12,8 +12,6 @@ $ ../../bin/smpirun -trace -trace-resource -trace-file smpi_traced.trace -hostfi
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to '1'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
-
 
 p Another SMPI test
 $ ../../bin/smpirun -trace -trace-resource -trace-file smpi_traced.trace -hostfile ${srcdir:=.}/hostfile -platform ${srcdir:=.}/../msg/tracing/platform.xml -np 3 ./smpi_traced_simple
@@ -26,7 +24,6 @@ $ ../../bin/smpirun -trace -trace-resource -trace-file smpi_traced.trace -hostfi
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/categorized' to '1'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/uncategorized' to '1'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 
 p Testing without trace parameters
 $ ../../bin/smpirun -hostfile ${srcdir:=.}/hostfile -platform ${srcdir:=.}/../msg/tracing/platform.xml -np 3 ./smpi_traced_simple
@@ -59,7 +56,6 @@ $ ../../bin/smpirun -trace -trace-resource -trace-triva -trace-file smpi_traced.
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/categorized' to 'smpi_cat.plist'
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'triva/uncategorized' to 'smpi_uncat.plist'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
-> [0.000000] [instr_config/INFO] Tracing resource utilization active, network/optim configuration now set to Full.
 > [1.003981] [instr_config/INFO] No categories declared, ignoring generation of triva graph configuration
 
 p Testing with parameters but without activating them with the safe switch (-trace)
index 85a1a0e..f142dfc 100644 (file)
@@ -77,7 +77,7 @@ xbt_socket_t gras_trp_select(double timeout)
       if (now == -1 || now >= wakeup) {
         /* didn't find anything; no need to update _gras_lastly_selected_socket since its moredata is 0 (or we would have returned it directly) */
         THROWF(timeout_error, 0,
-               "Timeout (%f) elapsed with selecting for incomming connexions",
+               "Timeout (%f) elapsed with selecting for incoming connections",
                timeout);
       }
     }
@@ -90,7 +90,7 @@ xbt_socket_t gras_trp_select(double timeout)
         continue;
 
       if (sock_iter->incoming) {
-        XBT_DEBUG("Considering socket %d for select", sock_iter->sd);
+        //XBT_DEBUG("Considering socket %d for select", sock_iter->sd);
 #ifndef HAVE_WINSOCK_H
         if (max_fds < sock_iter->sd)
           max_fds = sock_iter->sd;
index 8cfa80a..4a9e9bc 100644 (file)
@@ -56,6 +56,13 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table,
 XBT_PUBLIC(void) model_help(const char *category,
                             s_surf_model_description_t * table);
 
+enum heap_action_type{
+  LATENCY = 100,
+  MAX_DURATION,
+  NORMAL,
+  NOTSET
+};
+
 /** \brief Action structure
  * \ingroup SURF_actions
  *
@@ -92,6 +99,10 @@ typedef struct surf_action_lmm {
   s_surf_action_t generic_action;
   lmm_variable_t variable;
   int suspended;
+  s_xbt_swag_hookup_t action_list_hookup;
+  int index_heap;
+  double last_update;
+  enum heap_action_type hat;
 } s_surf_action_lmm_t, *surf_action_lmm_t;
 
 /** \brief Action states
@@ -350,7 +361,7 @@ typedef struct s_storage_type {
 } s_storage_type_t, *storage_type_t;
 
 typedef struct s_mount {
-  char *id;
+  void *id;
   char *name;
 } s_mount_t, *mount_t;
 
@@ -506,7 +517,7 @@ XBT_PUBLIC(void) surf_network_model_init_bypass(const char *id,
  *
  *  \see surf_workstation_model_init_GTNETS()
  */
-XBT_PUBLIC(void) surf_network_model_init_GbTNETS(void);
+XBT_PUBLIC(void) surf_network_model_init_GTNETS(void);
 #endif
 
 #ifdef HAVE_NS3
@@ -520,19 +531,6 @@ XBT_PUBLIC(void) surf_network_model_init_GbTNETS(void);
  *  \see surf_workstation_model_init_NS3()
  */
 XBT_PUBLIC(void) surf_network_model_init_NS3(void);
-
-XBT_PUBLIC(void) parse_ns3_add_host(void);
-XBT_PUBLIC(void) parse_ns3_add_router(void);
-XBT_PUBLIC(void) parse_ns3_add_link(void);
-XBT_PUBLIC(void) parse_ns3_add_AS(void);
-XBT_PUBLIC(void) parse_ns3_add_route(void);
-XBT_PUBLIC(void) parse_ns3_add_ASroute(void);
-XBT_PUBLIC(void) parse_ns3_add_cluster(void);
-XBT_PUBLIC(void) parse_ns3_end_platform(void);
-XBT_PUBLIC(void) create_ns3_topology(void);
-XBT_PUBLIC(double) ns3_get_link_latency(const void *link);
-XBT_PUBLIC(double) ns3_get_link_bandwidth(const void *link);
-
 #endif
 
 /** \brief Initializes the platform with the network model Reno
index 2770759..ce36bb4 100644 (file)
@@ -506,16 +506,6 @@ void TRACE_generate_triva_cat_conf (void)
   }
 }
 
-void TRACE_set_network_update_mechanism (void)
-{
-  if (TRACE_is_enabled()){
-    if (TRACE_categorized() || TRACE_uncategorized()){
-      XBT_INFO ("Tracing resource utilization active, network/optim configuration now set to Full.");
-      xbt_cfg_set_string (_surf_cfg_set, "network/optim", "Full");
-    }
-  }
-}
-
 #undef OPT_TRACING
 #undef OPT_TRACING_PLATFORM
 #undef OPT_TRACING_SMPI
index 2125632..0ea9da6 100644 (file)
@@ -170,25 +170,18 @@ void TRACE_global_init(int *argc, char **argv);
 void TRACE_help(int detailed);
 void TRACE_generate_triva_uncat_conf (void);
 void TRACE_generate_triva_cat_conf (void);
-void TRACE_set_network_update_mechanism (void);
 
 /* from resource_utilization.c */
 void TRACE_surf_host_set_utilization(const char *resource,
-                                     smx_action_t smx_action,
-                                     surf_action_t surf_action,
-                                     double value, double now,
+                                     const char *category,
+                                     double value,
+                                     double now,
                                      double delta);
-void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_action,
-                                     surf_action_t surf_action,
-                                     double value, double now,
+void TRACE_surf_link_set_utilization(const char *resource,
+                                     const char *category,
+                                     double value,
+                                     double now,
                                      double delta);
-void TRACE_surf_resource_utilization_start(smx_action_t action);
-void TRACE_surf_resource_utilization_event(smx_action_t action, double now,
-                                           double delta,
-                                           const char *variable,
-                                           const char *resource,
-                                           double value);
-void TRACE_surf_resource_utilization_end(smx_action_t action);
 void TRACE_surf_resource_utilization_alloc(void);
 void TRACE_surf_resource_utilization_release(void);
 
index 02fb2db..d469737 100644 (file)
@@ -11,7 +11,7 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorized resource utilization");
 
 //to check if variables were previously set to 0, otherwise paje won't simulate them
-static xbt_dict_t platform_variables;   /* host or link name -> array of categories */
+static xbt_dict_t platform_variables;
 
 //used by all methods
 static void __TRACE_surf_check_variable_set_to_zero(double now,
@@ -41,22 +41,6 @@ static void __TRACE_surf_check_variable_set_to_zero(double now,
   xbt_free(key);
 }
 
-/*
-static void __TRACE_A_event(smx_action_t action, double now, double delta,
-                            const char *variable, const char *resource,
-                            double value)
-{
-  char valuestr[100];
-  snprintf(valuestr, 100, "%f", value);
-
-  __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
-  container_t container = PJ_container_get (resource);
-  type_t type = getVariableType (variable, NULL, container->type);
-  new_pajeAddVariable(now, container, type, value);
-  new_pajeSubVariable(now + delta, container, type, value);
-}
-*/
-
 static void instr_event (double now, double delta, type_t variable, container_t resource, double value)
 {
   __TRACE_surf_check_variable_set_to_zero(now, variable->name, resource->name);
@@ -67,9 +51,10 @@ static void instr_event (double now, double delta, type_t variable, container_t
 /*
  * TRACE_surf_link_set_utilization: entry point from SimGrid
  */
-void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_action,
-                                     surf_action_t surf_action,
-                                     double value, double now,
+void TRACE_surf_link_set_utilization(const char *resource,
+                                     const char *category,
+                                     double value,
+                                     double now,
                                      double delta)
 {
   //only trace link utilization if link is known by tracing mechanism
@@ -88,11 +73,11 @@ void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_acti
 
   //trace categorized utilization
   if (TRACE_categorized()){
-    if (!surf_action->category)
+    if (!category)
       return;
     //variable of this category starts by 'b', because we have a link here
     char category_type[INSTR_DEFAULT_STR_SIZE];
-    snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", surf_action->category);
+    snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", category);
     XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
     container_t container = PJ_container_get (resource);
     type_t type = PJ_type_get (category_type, container->type);
@@ -105,9 +90,9 @@ void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_acti
  * TRACE_surf_host_set_utilization: entry point from SimGrid
  */
 void TRACE_surf_host_set_utilization(const char *resource,
-                                     smx_action_t smx_action,
-                                     surf_action_t surf_action,
-                                     double value, double now,
+                                     const char *category,
+                                     double value,
+                                     double now,
                                      double delta)
 {
   //only trace host utilization if host is known by tracing mechanism
@@ -126,11 +111,11 @@ void TRACE_surf_host_set_utilization(const char *resource,
 
   //trace categorized utilization
   if (TRACE_categorized()){
-    if (!surf_action->category)
+    if (!category)
       return;
     //variable of this category starts by 'p', because we have a host here
     char category_type[INSTR_DEFAULT_STR_SIZE];
-    snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", surf_action->category);
+    snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", category);
     XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
     container_t container = PJ_container_get (resource);
     type_t type = PJ_type_get (category_type, container->type);
index 084d252..0802395 100644 (file)
@@ -18,42 +18,60 @@ extern xbt_dict_t defined_types; /* from instr_interface.c */
 static int platform_created = 0;            /* indicate whether the platform file has been traced */
 static xbt_dynar_t currentContainer = NULL; /* push and pop, used only in creation */
 
-static container_t findChild (container_t root, container_t a1)
+static container_t lowestCommonAncestor (container_t a1, container_t a2)
 {
-  if (root == a1) return root;
+  //this is only an optimization (since most of a1 and a2 share the same parent)
+  if (a1->father == a2->father) return a1->father;
 
-  xbt_dict_cursor_t cursor = NULL;
-  container_t child;
-  char *child_name;
-  xbt_dict_foreach(root->children, cursor, child_name, child) {
-    if (findChild (child, a1)) return child;
+  //create an array with all ancestors of a1
+  xbt_dynar_t ancestors_a1 = xbt_dynar_new(sizeof(container_t), NULL);
+  container_t p;
+  p = a1->father;
+  while (p){
+    xbt_dynar_push_as (ancestors_a1, container_t, p);
+    p = p->father;
   }
-  return NULL;
-}
 
-static container_t findCommonFather (container_t root, container_t a1, container_t a2)
-{
-  if (a1->father == a2->father) return a1->father;
+  //create an array with all ancestors of a2
+  xbt_dynar_t ancestors_a2 = xbt_dynar_new(sizeof(container_t), NULL);
+  p = a2->father;
+  while (p){
+    xbt_dynar_push_as (ancestors_a2, container_t, p);
+    p = p->father;
+  }
 
-  xbt_dict_cursor_t cursor = NULL;
-  container_t child;
-  char *child_name;
-  container_t a1_try = NULL;
-  container_t a2_try = NULL;
-  xbt_dict_foreach(root->children, cursor, child_name, child) {
-    a1_try = findChild (child, a1);
-    a2_try = findChild (child, a2);
-    if (a1_try && a2_try) return child;
+  //find the lowest ancestor
+  p = NULL;
+  int i = xbt_dynar_length (ancestors_a1) - 1;
+  int j = xbt_dynar_length (ancestors_a2) - 1;
+  while (i >= 0 && j >= 0){
+    container_t a1p = *(container_t*)xbt_dynar_get_ptr (ancestors_a1, i);
+    container_t a2p = *(container_t*)xbt_dynar_get_ptr (ancestors_a2, j);
+    if (a1p == a2p){
+      p = a1p;
+    }else{
+      break;
+    }
+    i--;
+    j--;
   }
-  return NULL;
+  xbt_dynar_free (&ancestors_a1);
+  xbt_dynar_free (&ancestors_a2);
+  return p;
 }
 
-static void linkContainers (container_t father, container_t src, container_t dst, xbt_dict_t filter)
+static void linkContainers (container_t src, container_t dst, xbt_dict_t filter)
 {
   //ignore loopback
   if (strcmp (src->name, "__loopback__") == 0 || strcmp (dst->name, "__loopback__") == 0)
     return;
 
+  //find common father
+  container_t father = lowestCommonAncestor (src, dst);
+  if (!father){
+    xbt_die ("common father unknown, this is a tracing problem");
+  }
+
   if (filter != NULL){
     //check if we already register this pair (we only need one direction)
     char aux1[INSTR_DEFAULT_STR_SIZE], aux2[INSTR_DEFAULT_STR_SIZE];
@@ -69,7 +87,10 @@ static void linkContainers (container_t father, container_t src, container_t dst
 
   //declare type
   char link_typename[INSTR_DEFAULT_STR_SIZE];
-  snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s", src->type->name, dst->type->name);
+  snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s%s-%s%s",
+            father->type->name,
+            src->type->name, src->type->id,
+            dst->type->name, dst->type->id);
   type_t link_type = PJ_type_get_or_null (link_typename, father->type);
   if (link_type == NULL){
     link_type = PJ_type_link_new (link_typename, father->type, src->type, dst->type);
@@ -131,10 +152,10 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t
           link_CM02_t *link = ((link_CM02_t*)xbt_dynar_get_ptr (route, i));
           char *link_name = (*link)->lmm_resource.generic_resource.name;
           container_t current = PJ_container_get(link_name);
-          linkContainers(container, previous, current, filter);
+          linkContainers(previous, current, filter);
           previous = current;
         }
-        linkContainers(container, previous, child2, filter);
+        linkContainers(previous, child2, filter);
 
       }else if (child1->kind == INSTR_AS &&
                 child2->kind == INSTR_AS &&
@@ -149,11 +170,11 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t
         xbt_dynar_foreach (route->link_list, cpt, link) {
           char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
           container_t current = PJ_container_get(link_name);
-          linkContainers (container, previous, current, filter);
+          linkContainers (previous, current, filter);
           previous = current;
         }
         container_t last = PJ_container_get(route->dst_gateway);
-        linkContainers (container, previous, last, filter);
+        linkContainers (previous, last, filter);
         generic_free_route(route);
       }
     }
index 6ba5ee4..10eb871 100644 (file)
@@ -6,13 +6,14 @@
 
 #include "surf_private.h"
 #include "surf/surf_resource.h"
+#include "maxmin_private.h"
 
 surf_model_t surf_cpu_model = NULL;
 lmm_system_t cpu_maxmin_system = NULL;
 e_UM_t cpu_update_mechanism = UM_UNDEFINED;
 static int cpu_selective_update = 0;
 
-static xbt_swag_t cpu_modified_cpu = NULL;
+static xbt_swag_t cpu_modified_set= NULL;
 static xbt_heap_t cpu_action_heap = NULL;
 
 #undef GENERIC_LMM_ACTION
@@ -24,9 +25,6 @@ static xbt_heap_t cpu_action_heap = NULL;
 
 typedef struct surf_action_cpu_cas01 {
   s_surf_action_lmm_t generic_lmm_action;
-  s_xbt_swag_hookup_t cpu_list_hookup;
-  int index_heap;
-  void *cpu;
 } s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t;
 
 typedef struct cpu_Cas01 {
@@ -39,8 +37,6 @@ typedef struct cpu_Cas01 {
   e_surf_resource_state_t state_current;
   tmgr_trace_event_t state_event;
   lmm_constraint_t constraint;
-  xbt_swag_t action_set;
-  double last_update;
 } s_cpu_Cas01_t, *cpu_Cas01_t;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
@@ -51,7 +47,36 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
 static xbt_swag_t
     cpu_running_action_set_that_does_not_need_being_checked = NULL;
 
-static void* cpu_create_resource(const char *name, double power_peak,
+/* added to manage the communication action's heap */
+static void net_action_update_index_heap(void *action, int i)
+{
+  surf_action_cpu_Cas01_t a = action;
+  GENERIC_LMM_ACTION(a).index_heap = i;
+}
+
+/* insert action on heap using a given key and a hat (heap_action_type)
+ * a hat can be of three types for communications:
+ *
+ * NORMAL = this is a normal heap entry stating the date to finish transmitting
+ * LATENCY = this is a heap entry to warn us when the latency is payed
+ * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
+ */
+static void heap_insert(surf_action_cpu_Cas01_t action, double key,
+                        enum heap_action_type hat)
+{
+  GENERIC_LMM_ACTION(action).hat = hat;
+  xbt_heap_push(cpu_action_heap, action, key);
+}
+
+static void heap_remove(surf_action_cpu_Cas01_t action)
+{
+  GENERIC_LMM_ACTION(action).hat = NOTSET;
+  if (GENERIC_LMM_ACTION(action).index_heap >= 0) {
+    xbt_heap_remove(cpu_action_heap, GENERIC_LMM_ACTION(action).index_heap);
+  }
+}
+
+static void *cpu_create_resource(const char *name, double power_peak,
                                  double power_scale,
                                  tmgr_trace_t power_trace,
                                  int core,
@@ -60,18 +85,18 @@ static void* cpu_create_resource(const char *name, double power_peak,
                                  xbt_dict_t cpu_properties)
 {
   cpu_Cas01_t cpu = NULL;
-  s_surf_action_cpu_Cas01_t action;
 
   xbt_assert(!surf_cpu_resource_by_name(name),
-              "Host '%s' declared several times in the platform file",
-              name);
+             "Host '%s' declared several times in the platform file",
+             name);
   cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t),
-          surf_cpu_model, name,cpu_properties);
+                                        surf_cpu_model, name,
+                                        cpu_properties);
   cpu->power_peak = power_peak;
   xbt_assert(cpu->power_peak > 0, "Power has to be >0");
   cpu->power_scale = power_scale;
   cpu->core = core;
-  xbt_assert(core>0,"Invalid number of cores %d",core);
+  xbt_assert(core > 0, "Invalid number of cores %d", core);
 
   if (power_trace)
     cpu->power_event =
@@ -87,8 +112,6 @@ static void* cpu_create_resource(const char *name, double power_peak,
                          cpu->core * cpu->power_scale * cpu->power_peak);
 
   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
-  if(cpu_update_mechanism == UM_LAZY)
-    cpu->action_set = xbt_swag_new(xbt_swag_offset(action, cpu_list_hookup));
 
   return cpu;
 }
@@ -96,14 +119,13 @@ static void* cpu_create_resource(const char *name, double power_peak,
 
 static void parse_cpu_init(sg_platf_host_cbarg_t host)
 {
-       cpu_create_resource(host->id,
-                         host->power_peak,
-                         host->power_scale,
-                         host->power_trace,
-                         host->core_amount,
-                         host->initial_state,
-                         host->state_trace,
-                         host->properties);
+  cpu_create_resource(host->id,
+                      host->power_peak,
+                      host->power_scale,
+                      host->power_trace,
+                      host->core_amount,
+                      host->initial_state,
+                      host->state_trace, host->properties);
 }
 
 static void cpu_add_traces_cpu(void)
@@ -159,13 +181,10 @@ static int cpu_action_unref(surf_action_t action)
     if (((surf_action_lmm_t) action)->variable)
       lmm_variable_free(cpu_maxmin_system,
                         ((surf_action_lmm_t) action)->variable);
-    if(cpu_update_mechanism == UM_LAZY){
-    /* remove from heap */
-    xbt_heap_remove(cpu_action_heap,
-                    ((surf_action_cpu_Cas01_t) action)->index_heap);
-    xbt_swag_remove(action,
-                    ((cpu_Cas01_t) ACTION_GET_CPU(action))->action_set);
-    xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
+    if (cpu_update_mechanism == UM_LAZY) {
+      /* remove from heap */
+      heap_remove((surf_action_cpu_Cas01_t) action);
+      xbt_swag_remove(action, cpu_modified_set);
     }
 #ifdef HAVE_TRACING
     xbt_free(action->category);
@@ -179,17 +198,15 @@ static int cpu_action_unref(surf_action_t action)
 static void cpu_action_cancel(surf_action_t action)
 {
   surf_action_state_set(action, SURF_ACTION_FAILED);
-  if(cpu_update_mechanism == UM_LAZY){
-  xbt_heap_remove(cpu_action_heap,
-                  ((surf_action_cpu_Cas01_t) action)->index_heap);
-  xbt_swag_remove(action,
-                  ((cpu_Cas01_t) ACTION_GET_CPU(action))->action_set);
+  if (cpu_update_mechanism == UM_LAZY) {
+    xbt_swag_remove(action, cpu_modified_set);
+    heap_remove((surf_action_cpu_Cas01_t) action);
   }
   return;
 }
 
-static void cpu_cpu_action_state_set(surf_action_t action,
-                                        e_surf_action_state_t state)
+static void cpu_action_state_set(surf_action_t action,
+                                     e_surf_action_state_t state)
 {
 /*   if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
 /*     if(((surf_action_lmm_t)action)->variable) { */
@@ -201,114 +218,128 @@ static void cpu_cpu_action_state_set(surf_action_t action,
   return;
 }
 
-static void cpu_update_remains(cpu_Cas01_t cpu, double now)
+static void update_action_remaining_lazy(double now)
 {
   surf_action_cpu_Cas01_t action;
+  double delta = 0.0;
 
-  if (cpu->last_update >= now)
-    return;
-  xbt_swag_foreach(action, cpu->action_set) {
+  xbt_swag_foreach(action, cpu_modified_set) {
     if (GENERIC_ACTION(action).state_set !=
         surf_cpu_model->states.running_action_set)
-      continue;
+      continue; // FIXME useless ????
 
     /* bogus priority, skip it */
     if (GENERIC_ACTION(action).priority <= 0)
       continue;
 
+    delta = now - GENERIC_LMM_ACTION(action).last_update;
     if (GENERIC_ACTION(action).remains > 0) {
+
       double_update(&(GENERIC_ACTION(action).remains),
-                    lmm_variable_getvalue(GENERIC_LMM_ACTION
-                                          (action).variable) * (now -
-                                                                cpu->last_update));
+                    lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
+
 #ifdef HAVE_TRACING
       if (TRACE_is_enabled()) {
+        cpu_Cas01_t cpu =
+            lmm_constraint_id(lmm_get_cnst_from_var
+                              (cpu_maxmin_system,
+                               GENERIC_LMM_ACTION(action).variable, 0));
         TRACE_surf_host_set_utilization(cpu->generic_resource.name,
-                                        action->
-                                        generic_lmm_action.generic_action.
-                                        data, (surf_action_t) action,
-                                        lmm_variable_getvalue
-                                        (GENERIC_LMM_ACTION
-                                         (action).variable),
-                                        cpu->last_update,
-                                        now - cpu->last_update);
+                                        ((surf_action_t)action)->category,
+                                        lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
+                                        GENERIC_LMM_ACTION(action).last_update,
+                                        now - GENERIC_LMM_ACTION(action).last_update);
       }
 #endif
       XBT_DEBUG("Update action(%p) remains %lf", action,
-             GENERIC_ACTION(action).remains);
+                GENERIC_ACTION(action).remains);
     }
+    GENERIC_LMM_ACTION(action).last_update = now;
   }
-  cpu->last_update = now;
+
 }
 
 static double cpu_share_resources_lazy(double now)
 {
-  surf_action_cpu_Cas01_t action;
-  double min;
+  surf_action_cpu_Cas01_t action = NULL;
+  double min = -1;
   double value;
-  cpu_Cas01_t cpu, cpu_next;
 
-  xbt_swag_foreach(cpu, cpu_modified_cpu)
-      cpu_update_remains(cpu, now);
+  XBT_DEBUG
+      ("Before share resources, the size of modified actions set is %d",
+       xbt_swag_size(cpu_modified_set));
+  update_action_remaining_lazy(now);
 
   lmm_solve(cpu_maxmin_system);
 
-  xbt_swag_foreach_safe(cpu, cpu_next, cpu_modified_cpu) {
-    xbt_swag_foreach(action, cpu->action_set) {
-      if (GENERIC_ACTION(action).state_set !=
-          surf_cpu_model->states.running_action_set)
-        continue;
-
-      /* bogus priority, skip it */
-      if (GENERIC_ACTION(action).priority <= 0)
-        continue;
-
-      min = -1;
-      value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
-      if (value > 0) {
-        if (GENERIC_ACTION(action).remains > 0) {
-          value = GENERIC_ACTION(action).remains / value;
-          min = now + value;
-        } else {
-          value = 0.0;
-          min = now;
-        }
-      }
+  XBT_DEBUG
+      ("After share resources, The size of modified actions set is %d",
+       xbt_swag_size(cpu_modified_set));
 
-      if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
-          && (min == -1
-              || GENERIC_ACTION(action).start +
-              GENERIC_ACTION(action).max_duration < min))
-        min =
-            GENERIC_ACTION(action).start +
-            GENERIC_ACTION(action).max_duration;
-
-      XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
-             GENERIC_ACTION(action).start, now + value,
-             GENERIC_ACTION(action).max_duration);
-
-      if (action->index_heap >= 0) {
-        surf_action_cpu_Cas01_t heap_act =
-            xbt_heap_remove(cpu_action_heap, action->index_heap);
-        if (heap_act != action)
-          DIE_IMPOSSIBLE;
-      }
-      if (min != -1) {
-        xbt_heap_push(cpu_action_heap, action, min);
-        XBT_DEBUG("Insert at heap action(%p) min %lf", action, min);
+  xbt_swag_foreach(action, cpu_modified_set) {
+    int max_dur_flag = 0;
+
+    if (GENERIC_ACTION(action).state_set !=
+        surf_cpu_model->states.running_action_set)
+      continue;
+
+    /* bogus priority, skip it */
+    if (GENERIC_ACTION(action).priority <= 0)
+      continue;
+
+    min = -1;
+    value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
+    if (value > 0) {
+      if (GENERIC_ACTION(action).remains > 0) {
+        value = GENERIC_ACTION(action).remains / value;
+        min = now + value;
+      } else {
+        value = 0.0;
+        min = now;
       }
     }
-    xbt_swag_remove(cpu, cpu_modified_cpu);
+
+    if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
+        && (min == -1
+            || GENERIC_ACTION(action).start +
+            GENERIC_ACTION(action).max_duration < min)) {
+      min = GENERIC_ACTION(action).start +
+          GENERIC_ACTION(action).max_duration;
+      max_dur_flag = 1;
+    }
+
+    XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
+        GENERIC_ACTION(action).start, now + value,
+        GENERIC_ACTION(action).max_duration);
+
+    if (min != -1) {
+      heap_remove(action);
+      heap_insert(action, min, max_dur_flag ? MAX_DURATION : NORMAL);
+      XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
+                now);
+    } else DIE_IMPOSSIBLE;
   }
-  return xbt_heap_size(cpu_action_heap) >
-      0 ? xbt_heap_maxkey(cpu_action_heap) - now : -1;
+
+  //hereafter must have already the min value for this resource model
+  if (xbt_heap_size(cpu_action_heap) > 0)
+    min = xbt_heap_maxkey(cpu_action_heap) - now;
+  else
+    min = -1;
+
+  XBT_DEBUG("The minimum with the HEAP %lf", min);
+
+  return min;
 }
 
-static double cpu_share_resources_full(double now) {
+static double cpu_share_resources_full(double now)
+{
   s_surf_action_cpu_Cas01_t action;
-  return generic_maxmin_share_resources(surf_cpu_model->states.running_action_set,
-      xbt_swag_offset(action, generic_lmm_action.variable),
-      cpu_maxmin_system, lmm_solve);
+  return generic_maxmin_share_resources(surf_cpu_model->states.
+                                        running_action_set,
+                                        xbt_swag_offset(action,
+                                                        generic_lmm_action.
+                                                        variable),
+                                        cpu_maxmin_system, lmm_solve);
 }
 
 static void cpu_update_actions_state_lazy(double now, double delta)
@@ -319,42 +350,38 @@ static void cpu_update_actions_state_lazy(double now, double delta)
     action = xbt_heap_pop(cpu_action_heap);
     XBT_DEBUG("Action %p: finish", action);
     GENERIC_ACTION(action).finish = surf_get_clock();
-    /* set the remains to 0 due to precision problems when updating the remaining amount */
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
-      cpu_Cas01_t cpu = ((cpu_Cas01_t)(action->cpu));
+      cpu_Cas01_t cpu =
+          lmm_constraint_id(lmm_get_cnst_from_var
+                            (cpu_maxmin_system,
+                             GENERIC_LMM_ACTION(action).variable, 0));
       TRACE_surf_host_set_utilization(cpu->generic_resource.name,
-          GENERIC_LMM_ACTION(action).generic_action.data,
-          (surf_action_t) action,
-          lmm_variable_getvalue (GENERIC_LMM_ACTION(action).variable),
-          cpu->last_update,
-          now - cpu->last_update);
+                                      ((surf_action_t)action)->category,
+                                      lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
+                                      GENERIC_LMM_ACTION(action).last_update,
+                                      now - GENERIC_LMM_ACTION(action).last_update);
     }
 #endif
+    /* set the remains to 0 due to precision problems when updating the remaining amount */
     GENERIC_ACTION(action).remains = 0;
-    cpu_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-    cpu_update_remains(action->cpu, surf_get_clock());
+    cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
+    heap_remove(action);
   }
 #ifdef HAVE_TRACING
   if (TRACE_is_enabled()) {
     //defining the last timestamp that we can safely dump to trace file
     //without losing the event ascending order (considering all CPU's)
-    void **data;
-    cpu_Cas01_t cpu;
-    xbt_lib_cursor_t cursor;
-    char *key;
     double smaller = -1;
-    xbt_lib_foreach(host_lib, cursor, key, data){
-      if(data[SURF_CPU_LEVEL]){
-        cpu = data[SURF_CPU_LEVEL];
-        if (smaller < 0){
-          smaller = cpu->last_update;
+    xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
+    xbt_swag_foreach(action, running_actions) {
+        if (smaller < 0) {
+          smaller = GENERIC_LMM_ACTION(action).last_update;
           continue;
         }
-        if (cpu->last_update < smaller){
-          smaller = cpu->last_update;
+        if (GENERIC_LMM_ACTION(action).last_update < smaller) {
+          smaller = GENERIC_LMM_ACTION(action).last_update;
         }
-      }
     }
     if (smaller > 0) {
       TRACE_last_timestamp_to_dump = smaller;
@@ -373,30 +400,34 @@ static void cpu_update_actions_state_full(double now, double delta)
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
       cpu_Cas01_t x =
-        lmm_constraint_id(lmm_get_cnst_from_var
-                          (cpu_maxmin_system, GENERIC_LMM_ACTION(action).variable, 0));
+          lmm_constraint_id(lmm_get_cnst_from_var
+                            (cpu_maxmin_system,
+                             GENERIC_LMM_ACTION(action).variable, 0));
 
       TRACE_surf_host_set_utilization(x->generic_resource.name,
-                                      GENERIC_ACTION(action).data,
-                                      (surf_action_t) action,
-                                      lmm_variable_getvalue
-                                      (GENERIC_LMM_ACTION(action).variable), now - delta,
+                                      ((surf_action_t)action)->category,
+                                      lmm_variable_getvalue(GENERIC_LMM_ACTION(action).
+                                       variable),
+                                      now - delta,
                                       delta);
-      TRACE_last_timestamp_to_dump = now-delta;
+      TRACE_last_timestamp_to_dump = now - delta;
     }
 #endif
     double_update(&(GENERIC_ACTION(action).remains),
-                  lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
-    if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
+                  lmm_variable_getvalue(GENERIC_LMM_ACTION(action).
+                                        variable) * delta);
+    if (GENERIC_LMM_ACTION(action).generic_action.max_duration !=
+        NO_MAX_DURATION)
       double_update(&(GENERIC_ACTION(action).max_duration), delta);
     if ((GENERIC_ACTION(action).remains <= 0) &&
-        (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
+        (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) >
+         0)) {
       GENERIC_ACTION(action).finish = surf_get_clock();
-      cpu_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
+      cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
     } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
                (GENERIC_ACTION(action).max_duration <= 0)) {
       GENERIC_ACTION(action).finish = surf_get_clock();
-      cpu_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
+      cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
     }
   }
 
@@ -404,8 +435,8 @@ static void cpu_update_actions_state_full(double now, double delta)
 }
 
 static void cpu_update_resource_state(void *id,
-                                         tmgr_trace_event_t event_type,
-                                         double value, double date)
+                                      tmgr_trace_event_t event_type,
+                                      double value, double date)
 {
   cpu_Cas01_t cpu = id;
   lmm_variable_t var = NULL;
@@ -414,19 +445,20 @@ static void cpu_update_resource_state(void *id,
   if (event_type == cpu->power_event) {
     cpu->power_scale = value;
     lmm_update_constraint_bound(cpu_maxmin_system, cpu->constraint,
-                                cpu->core * cpu->power_scale * cpu->power_peak);
+                                cpu->core * cpu->power_scale *
+                                cpu->power_peak);
 #ifdef HAVE_TRACING
     TRACE_surf_host_set_power(date, cpu->generic_resource.name,
-                              cpu->core * cpu->power_scale * cpu->power_peak);
+                              cpu->core * cpu->power_scale *
+                              cpu->power_peak);
 #endif
     while ((var = lmm_get_var_from_cnst
             (cpu_maxmin_system, cpu->constraint, &elem))) {
-       surf_action_cpu_Cas01_t action = lmm_variable_id(var);
-       lmm_update_variable_bound(cpu_maxmin_system, GENERIC_LMM_ACTION(action).variable,
-                                  cpu->power_scale * cpu->power_peak);
+      surf_action_cpu_Cas01_t action = lmm_variable_id(var);
+      lmm_update_variable_bound(cpu_maxmin_system,
+                                GENERIC_LMM_ACTION(action).variable,
+                                cpu->power_scale * cpu->power_peak);
     }
-    if(cpu_update_mechanism == UM_LAZY)
-      xbt_swag_insert(cpu, cpu_modified_cpu);
     if (tmgr_trace_event_free(event_type))
       cpu->power_event = NULL;
   } else if (event_type == cpu->state_event) {
@@ -437,8 +469,7 @@ static void cpu_update_resource_state(void *id,
 
       cpu->state_current = SURF_RESOURCE_OFF;
 
-      while ((var =
-              lmm_get_var_from_cnst(cpu_maxmin_system, cnst, &elem))) {
+      while ((var = lmm_get_var_from_cnst(cpu_maxmin_system, cnst, &elem))) {
         surf_action_t action = lmm_variable_id(var);
 
         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
@@ -446,7 +477,7 @@ static void cpu_update_resource_state(void *id,
             surf_action_state_get(action) ==
             SURF_ACTION_NOT_IN_THE_SYSTEM) {
           action->finish = date;
-          cpu_cpu_action_state_set(action, SURF_ACTION_FAILED);
+          cpu_action_state_set(action, SURF_ACTION_FAILED);
         }
       }
     }
@@ -476,12 +507,11 @@ static surf_action_t cpu_execute(void *cpu, double size)
 
   GENERIC_LMM_ACTION(action).variable =
       lmm_variable_new(cpu_maxmin_system, action,
-                       GENERIC_ACTION(action).priority, CPU->power_scale * CPU->power_peak, 1);
-  if(cpu_update_mechanism == UM_LAZY){
-    action->index_heap = -1;
-    action->cpu = CPU;
-    xbt_swag_insert(CPU, cpu_modified_cpu);
-    xbt_swag_insert(action, CPU->action_set);
+                       GENERIC_ACTION(action).priority,
+                       CPU->power_scale * CPU->power_peak, 1);
+  if (cpu_update_mechanism == UM_LAZY) {
+    GENERIC_LMM_ACTION(action).index_heap = -1;
+    GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
   }
   lmm_expand(cpu_maxmin_system, CPU->constraint,
              GENERIC_LMM_ACTION(action).variable, 1.0);
@@ -511,8 +541,14 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration)
 
   lmm_update_variable_weight(cpu_maxmin_system,
                              GENERIC_LMM_ACTION(action).variable, 0.0);
-  if(cpu_update_mechanism == UM_LAZY)
-    xbt_swag_insert(cpu, cpu_modified_cpu);
+  if (cpu_update_mechanism == UM_LAZY) {     // remove action from the heap
+    heap_remove((surf_action_cpu_Cas01_t) action);
+    // this is necessary for a variable with weight 0 since such
+    // variables are ignored in lmm and we need to set its max_duration
+    // correctly at the next call to share_resources
+    xbt_swag_insert_at_head(action,cpu_modified_set);
+  }
+
   XBT_OUT();
   return (surf_action_t) action;
 }
@@ -525,11 +561,8 @@ static void cpu_action_suspend(surf_action_t action)
                                ((surf_action_lmm_t) action)->variable,
                                0.0);
     ((surf_action_lmm_t) action)->suspended = 1;
-    if(cpu_update_mechanism == UM_LAZY){
-      xbt_heap_remove(cpu_action_heap,
-                      ((surf_action_cpu_Cas01_t) action)->index_heap);
-      xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
-    }
+    if (cpu_update_mechanism == UM_LAZY)
+      heap_remove((surf_action_cpu_Cas01_t) action);
   }
   XBT_OUT();
 }
@@ -543,8 +576,8 @@ static void cpu_action_resume(surf_action_t action)
                                ((surf_action_lmm_t) action)->variable,
                                action->priority);
     ((surf_action_lmm_t) action)->suspended = 0;
-    if(cpu_update_mechanism == UM_LAZY)
-      xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
+    if (cpu_update_mechanism == UM_LAZY)
+      heap_remove((surf_action_cpu_Cas01_t) action);
   }
   XBT_OUT();
 }
@@ -555,19 +588,17 @@ static int cpu_action_is_suspended(surf_action_t action)
 }
 
 static void cpu_action_set_max_duration(surf_action_t action,
-                                           double duration)
+                                        double duration)
 {
   XBT_IN("(%p,%g)", action, duration);
 
   action->max_duration = duration;
-  /* insert cpu in modified_cpu set to notice the max duration change */
-  if(cpu_update_mechanism == UM_LAZY)
-    xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
+  if (cpu_update_mechanism == UM_LAZY)
+    heap_remove((surf_action_cpu_Cas01_t) action);
   XBT_OUT();
 }
 
-static void cpu_action_set_priority(surf_action_t action,
-                                       double priority)
+static void cpu_action_set_priority(surf_action_t action, double priority)
 {
   XBT_IN("(%p,%g)", action, priority);
   action->priority = priority;
@@ -575,17 +606,17 @@ static void cpu_action_set_priority(surf_action_t action,
                              ((surf_action_lmm_t) action)->variable,
                              priority);
 
-  if(cpu_update_mechanism == UM_LAZY)
-    xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
+  if (cpu_update_mechanism == UM_LAZY)
+    heap_remove((surf_action_cpu_Cas01_t) action);
   XBT_OUT();
 }
 
 #ifdef HAVE_TRACING
 static void cpu_action_set_category(surf_action_t action,
-                                       const char *category)
+                                    const char *category)
 {
   XBT_IN("(%p,%s)", action, category);
-  action->category = xbt_strdup (category);
+  action->category = xbt_strdup(category);
   XBT_OUT();
 }
 #endif
@@ -594,8 +625,8 @@ static double cpu_action_get_remains(surf_action_t action)
 {
   XBT_IN("(%p)", action);
   /* update remains before return it */
-  if(cpu_update_mechanism == UM_LAZY)
-    cpu_update_remains(ACTION_GET_CPU(action), surf_get_clock());
+  if (cpu_update_mechanism == UM_LAZY)
+    update_action_remaining_lazy(surf_get_clock());
   XBT_OUT();
   return action->remains;
 }
@@ -616,42 +647,24 @@ static double cpu_get_available_speed(void *cpu)
   return ((cpu_Cas01_t) cpu)->power_scale;
 }
 
-static void cpu_action_update_index_heap(void *action, int i)
-{
-  ((surf_action_cpu_Cas01_t) action)->index_heap = i;
-}
-
 static void cpu_finalize(void)
 {
-  void **cpu;
-  xbt_lib_cursor_t cursor;
-  char *key;
-
-  xbt_lib_foreach(host_lib, cursor, key, cpu){
-    if(cpu[SURF_CPU_LEVEL])
-    {
-        cpu_Cas01_t CPU = cpu[SURF_CPU_LEVEL];
-        xbt_swag_free(CPU->action_set);
-    }
-  }
-
   lmm_system_free(cpu_maxmin_system);
   cpu_maxmin_system = NULL;
 
   surf_model_exit(surf_cpu_model);
   surf_cpu_model = NULL;
 
-  xbt_swag_free
-      (cpu_running_action_set_that_does_not_need_being_checked);
+  xbt_swag_free(cpu_running_action_set_that_does_not_need_being_checked);
   cpu_running_action_set_that_does_not_need_being_checked = NULL;
-  if(cpu_action_heap)  xbt_heap_free(cpu_action_heap);
-  if(cpu_modified_cpu) xbt_swag_free(cpu_modified_cpu);
+  if (cpu_action_heap)
+    xbt_heap_free(cpu_action_heap);
 }
 
 static void surf_cpu_model_init_internal()
 {
   s_surf_action_t action;
-  s_cpu_Cas01_t cpu;
+  s_surf_action_cpu_Cas01_t comp;
 
   surf_cpu_model = surf_model_init();
 
@@ -662,16 +675,20 @@ static void surf_cpu_model_init_internal()
 
   surf_cpu_model->action_unref = cpu_action_unref;
   surf_cpu_model->action_cancel = cpu_action_cancel;
-  surf_cpu_model->action_state_set = cpu_cpu_action_state_set;
+  surf_cpu_model->action_state_set = cpu_action_state_set;
 
   surf_cpu_model->model_private->resource_used = cpu_resource_used;
 
-  if(cpu_update_mechanism == UM_LAZY) {
-    surf_cpu_model->model_private->share_resources = cpu_share_resources_lazy;
-    surf_cpu_model->model_private->update_actions_state = cpu_update_actions_state_lazy;
+  if (cpu_update_mechanism == UM_LAZY) {
+    surf_cpu_model->model_private->share_resources =
+        cpu_share_resources_lazy;
+    surf_cpu_model->model_private->update_actions_state =
+        cpu_update_actions_state_lazy;
   } else if (cpu_update_mechanism == UM_FULL) {
-    surf_cpu_model->model_private->share_resources = cpu_share_resources_full;
-    surf_cpu_model->model_private->update_actions_state = cpu_update_actions_state_full;
+    surf_cpu_model->model_private->share_resources =
+        cpu_share_resources_full;
+    surf_cpu_model->model_private->update_actions_state =
+        cpu_update_actions_state_full;
   } else
     xbt_die("Invalid update mechanism!");
 
@@ -702,12 +719,13 @@ static void surf_cpu_model_init_internal()
   if (!cpu_maxmin_system) {
     cpu_maxmin_system = lmm_system_new(cpu_selective_update);
   }
-  if(cpu_update_mechanism == UM_LAZY){
+  if (cpu_update_mechanism == UM_LAZY) {
     cpu_action_heap = xbt_heap_new(8, NULL);
     xbt_heap_set_update_callback(cpu_action_heap,
-                                 cpu_action_update_index_heap);
-    cpu_modified_cpu =
-        xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup));
+        net_action_update_index_heap);
+    cpu_modified_set =
+        xbt_swag_new(xbt_swag_offset(comp, generic_lmm_action.action_list_hookup));
+    cpu_maxmin_system->keep_track = cpu_modified_set;
   }
 }
 
@@ -730,21 +748,25 @@ static void surf_cpu_model_init_internal()
 void surf_cpu_model_init_Cas01()
 {
   char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
-  int select = xbt_cfg_get_int(_surf_cfg_set, "cpu/maxmin_selective_update");
+  int select =
+      xbt_cfg_get_int(_surf_cfg_set, "cpu/maxmin_selective_update");
 
-  if(!strcmp(optim,"Full")) {
+  if (!strcmp(optim, "Full")) {
     cpu_update_mechanism = UM_FULL;
     cpu_selective_update = select;
-  } else if (!strcmp(optim,"Lazy")) {
+  } else if (!strcmp(optim, "Lazy")) {
     cpu_update_mechanism = UM_LAZY;
     cpu_selective_update = 1;
-    xbt_assert((select==1) || (xbt_cfg_is_default_value(_surf_cfg_set,"cpu/maxmin_selective_update")),
-        "Disabling selective update while using the lazy update mechanism is dumb!");
-  } else if (!strcmp(optim,"TI")) {
+    xbt_assert((select == 1)
+               ||
+               (xbt_cfg_is_default_value
+                (_surf_cfg_set, "cpu/maxmin_selective_update")),
+               "Disabling selective update while using the lazy update mechanism is dumb!");
+  } else if (!strcmp(optim, "TI")) {
     surf_cpu_model_init_ti();
     return;
   } else {
-    xbt_die("Unsupported optimization (%s) for this model",optim);
+    xbt_die("Unsupported optimization (%s) for this model", optim);
   }
 
   if (surf_cpu_model)
index af6e1ed..5156a31 100644 (file)
 #include "surf/surf_resource.h"
 #include "surf/surf_resource_lmm.h"
 
+#undef GENERIC_LMM_ACTION
 #undef GENERIC_ACTION
-#define GENERIC_ACTION(action) action->generic_action
+#define GENERIC_LMM_ACTION(action) (action)->generic_lmm_action
+#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
+
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
                                 "Logging specific to the SURF network module");
@@ -38,8 +41,8 @@ xbt_dynar_t smpi_lat_factor = NULL;
 
 typedef struct s_smpi_factor *smpi_factor_t;
 typedef struct s_smpi_factor {
-       long factor;
-       double value;
+  long factor;
+  double value;
 } s_smpi_factor_t;
 
 double sg_sender_gap = 0.0;
@@ -56,7 +59,7 @@ e_UM_t network_update_mechanism = UM_UNDEFINED;
 static int net_selective_update = 0;
 
 static int net_action_is_suspended(surf_action_t action);
-static void update_action_remaining(double now);
+static void update_action_remaining_lazy(double now);
 
 static xbt_swag_t net_modified_set = NULL;
 static xbt_heap_t net_action_heap = NULL;
@@ -64,7 +67,8 @@ static xbt_heap_t net_action_heap = NULL;
 /* added to manage the communication action's heap */
 static void net_action_update_index_heap(void *action, int i)
 {
-  ((surf_action_network_CM02_t) action)->index_heap = i;
+  surf_action_network_CM02_t a = action;
+  GENERIC_LMM_ACTION(a).index_heap = i;
 }
 
 /* insert action on heap using a given key and a hat (heap_action_type)
@@ -74,15 +78,18 @@ static void net_action_update_index_heap(void *action, int i)
  * LATENCY = this is a heap entry to warn us when the latency is payed
  * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
  */
-static void heap_insert(surf_action_network_CM02_t    action, double key, enum heap_action_type hat){
-  action->hat = hat;
+static void heap_insert(surf_action_network_CM02_t action, double key,
+                        enum heap_action_type hat)
+{
+  GENERIC_LMM_ACTION(action).hat = hat;
   xbt_heap_push(net_action_heap, action, key);
 }
 
-static void heap_remove(surf_action_network_CM02_t action){
-  action->hat = NOTSET;
-  if(((surf_action_network_CM02_t) action)->index_heap >= 0){
-      xbt_heap_remove(net_action_heap,action->index_heap);
+static void heap_remove(surf_action_network_CM02_t action)
+{
+  GENERIC_LMM_ACTION(action).hat = NOTSET;
+  if (GENERIC_LMM_ACTION(action).index_heap >= 0) {
+    xbt_heap_remove(net_action_heap, GENERIC_LMM_ACTION(action).index_heap);
   }
 }
 
@@ -110,61 +117,64 @@ static double constant_bandwidth_constraint(double rate, double bound,
 /**********************/
 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
 {
-       char *value = NULL;
-       unsigned int iter = 0;
-       s_smpi_factor_t fact;
-       xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
-
-       smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
-       radical_elements = xbt_str_split(smpi_coef_string, ";");
-       xbt_dynar_foreach(radical_elements, iter, value) {
-
-               radical_elements2 = xbt_str_split(value, ":");
-               if(xbt_dynar_length(radical_elements2) != 2)
-                       xbt_die("Malformed radical for smpi factor!");
-               fact.factor = atol(xbt_dynar_get_as(radical_elements2,0,char*));
-               fact.value = atof(xbt_dynar_get_as(radical_elements2,1,char*));
-               xbt_dynar_push_as(smpi_factor,s_smpi_factor_t,fact);
-               XBT_DEBUG("smpi_factor:\t%ld : %f",fact.factor,fact.value);
-               xbt_dynar_free(&radical_elements2);
-       }
-       xbt_dynar_free(&radical_elements);
-       return smpi_factor;
+  char *value = NULL;
+  unsigned int iter = 0;
+  s_smpi_factor_t fact;
+  xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
+
+  smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
+  radical_elements = xbt_str_split(smpi_coef_string, ";");
+  xbt_dynar_foreach(radical_elements, iter, value) {
+
+    radical_elements2 = xbt_str_split(value, ":");
+    if (xbt_dynar_length(radical_elements2) != 2)
+      xbt_die("Malformed radical for smpi factor!");
+    fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *));
+    fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *));
+    xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
+    XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
+    xbt_dynar_free(&radical_elements2);
+  }
+  xbt_dynar_free(&radical_elements);
+  return smpi_factor;
 }
 
 static double smpi_bandwidth_factor(double size)
 {
-       if(!smpi_bw_factor)
-               smpi_bw_factor = parse_factor( xbt_cfg_get_string(_surf_cfg_set,"smpi/bw_factor") );
-
-       unsigned int iter = 0;
-       s_smpi_factor_t fact;
-       xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
-               if(size >= fact.factor){
-                       XBT_DEBUG("%lf >= %ld return %f",size,fact.factor,fact.value);
-                       return fact.value;
-               }
-       }
-
-    return 1.0;
+  if (!smpi_bw_factor)
+    smpi_bw_factor =
+        parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/bw_factor"));
+
+  unsigned int iter = 0;
+  s_smpi_factor_t fact;
+  xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
+    if (size >= fact.factor) {
+      XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
+      return fact.value;
+    }
+  }
+
+  return 1.0;
 }
 
 static double smpi_latency_factor(double size)
 {
-       if(!smpi_lat_factor)
-               smpi_lat_factor = parse_factor( xbt_cfg_get_string(_surf_cfg_set,"smpi/lat_factor") );
-
-       unsigned int iter = 0;
-       s_smpi_factor_t fact;
-       xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
-               if(size >= fact.factor){
-                       XBT_DEBUG("%lf >= %ld return %f",size,fact.factor,fact.value);
-                       return fact.value;
-               }
-       }
-
-    return 1.0;
+  if (!smpi_lat_factor)
+    smpi_lat_factor =
+        parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/lat_factor"));
+
+  unsigned int iter = 0;
+  s_smpi_factor_t fact;
+  xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
+    if (size >= fact.factor) {
+      XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
+      return fact.value;
+    }
+  }
+
+  return 1.0;
 }
+
 /**--------- <copy/paste C code snippet in surf/network.c> -----------*/
 
 static double smpi_bandwidth_constraint(double rate, double bound,
@@ -180,19 +190,20 @@ static double (*bandwidth_factor_callback) (double) =
 static double (*bandwidth_constraint_callback) (double, double, double) =
     &constant_bandwidth_constraint;
 
-static void (*gap_append) (double, const link_CM02_t, surf_action_network_CM02_t) = NULL;
+static void (*gap_append) (double, const link_CM02_t,
+                           surf_action_network_CM02_t) = NULL;
 static void (*gap_remove) (surf_action_network_CM02_t) = NULL;
 
-static voidnet_create_resource(const char *name,
-                                double bw_initial,
-                                tmgr_trace_t bw_trace,
-                                double lat_initial,
-                                tmgr_trace_t lat_trace,
-                                e_surf_resource_state_t
-                                state_initial,
-                                tmgr_trace_t state_trace,
-                                e_surf_link_sharing_policy_t
-                                policy, xbt_dict_t properties)
+static void *net_create_resource(const char *name,
+                                 double bw_initial,
+                                 tmgr_trace_t bw_trace,
+                                 double lat_initial,
+                                 tmgr_trace_t lat_trace,
+                                 e_surf_resource_state_t
+                                 state_initial,
+                                 tmgr_trace_t state_trace,
+                                 e_surf_link_sharing_policy_t
+                                 policy, xbt_dict_t properties)
 {
   link_CM02_t nw_link = (link_CM02_t)
       surf_resource_lmm_new(sizeof(s_link_CM02_t),
@@ -204,8 +215,8 @@ static void* net_create_resource(const char *name,
                             bw_initial, bw_trace);
 
   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
-              "Link '%s' declared several times in the platform file.",
-              name);
+             "Link '%s' declared several times in the platform file.",
+             name);
 
   nw_link->lat_current = lat_initial;
   if (lat_trace)
@@ -222,19 +233,17 @@ static void* net_create_resource(const char *name,
 
 static void net_parse_link_init(sg_platf_link_cbarg_t link)
 {
-  if(link->policy == SURF_LINK_FULLDUPLEX){
+  if (link->policy == SURF_LINK_FULLDUPLEX) {
     char *link_id;
     link_id = bprintf("%s_UP", link->id);
-         net_create_resource(link_id,
-                           link->bandwidth,
-                           link->bandwidth_trace,
-                           link->latency,
-                           link->latency_trace,
-                           link->state,
-                           link->state_trace,
-                           link->policy,
-                           link->properties);
-         xbt_free(link_id);
+    net_create_resource(link_id,
+                        link->bandwidth,
+                        link->bandwidth_trace,
+                        link->latency,
+                        link->latency_trace,
+                        link->state,
+                        link->state_trace, link->policy, link->properties);
+    xbt_free(link_id);
     link_id = bprintf("%s_DOWN", link->id);
     net_create_resource(link_id,
                         link->bandwidth,
@@ -242,21 +251,16 @@ static void net_parse_link_init(sg_platf_link_cbarg_t link)
                         link->latency,
                         link->latency_trace,
                         link->state,
-                        link->state_trace,
-                        link->policy,
-                        link->properties);
+                        link->state_trace, link->policy, link->properties);
     xbt_free(link_id);
-  }
-  else{
+  } else {
     net_create_resource(link->id,
                         link->bandwidth,
                         link->bandwidth_trace,
                         link->latency,
                         link->latency_trace,
                         link->state,
-                        link->state_trace,
-                        link->policy,
-                        link->properties);
+                        link->state_trace, link->policy, link->properties);
   }
 }
 
@@ -273,14 +277,13 @@ static void net_add_traces(void)
   /* connect all traces relative to network */
   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    link_CM02_t link =
-               xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
+    link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
 
     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
-                trace_name, elm);
+               trace_name, elm);
     xbt_assert(trace,
-                "Cannot connect trace %s to link %s: trace undefined",
-                trace_name, elm);
+               "Cannot connect trace %s to link %s: trace undefined",
+               trace_name, elm);
 
     link->lmm_resource.state_event =
         tmgr_history_add_trace(history, trace, 0.0, 0, link);
@@ -288,14 +291,13 @@ static void net_add_traces(void)
 
   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    link_CM02_t link =
-               xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
+    link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
 
     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
-                trace_name, elm);
+               trace_name, elm);
     xbt_assert(trace,
-                "Cannot connect trace %s to link %s: trace undefined",
-                trace_name, elm);
+               "Cannot connect trace %s to link %s: trace undefined",
+               trace_name, elm);
 
     link->lmm_resource.power.event =
         tmgr_history_add_trace(history, trace, 0.0, 0, link);
@@ -303,14 +305,13 @@ static void net_add_traces(void)
 
   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    link_CM02_t link =
-               xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
+    link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
 
     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
-                trace_name, elm);
+               trace_name, elm);
     xbt_assert(trace,
-                "Cannot connect trace %s to link %s: trace undefined",
-                trace_name, elm);
+               "Cannot connect trace %s to link %s: trace undefined",
+               trace_name, elm);
 
     link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
   }
@@ -325,9 +326,9 @@ static void net_define_callbacks(void)
 
 static int net_resource_used(void *resource_id)
 {
-  return lmm_constraint_used(network_maxmin_system,
-                             ((surf_resource_lmm_t)
-                              resource_id)->constraint);
+  return lmm_constraint_used(network_maxmin_system, ((surf_resource_lmm_t)
+                                                     resource_id)->
+                             constraint);
 }
 
 static int net_action_unref(surf_action_t action)
@@ -335,19 +336,14 @@ static int net_action_unref(surf_action_t action)
   action->refcount--;
   if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
-    if (((surf_action_network_CM02_t) action)->variable){
+    if (((surf_action_lmm_t)action)->variable) {
       lmm_variable_free(network_maxmin_system,
-                        ((surf_action_network_CM02_t) action)->variable);
+                        ((surf_action_lmm_t) action)->variable);
     }
-    if(network_update_mechanism == UM_LAZY){// remove action from the heap
+    if (network_update_mechanism == UM_LAZY) {  // remove action from the heap
       heap_remove((surf_action_network_CM02_t) action);
       xbt_swag_remove(action, net_modified_set);
     }
-#ifdef HAVE_TRACING
-    xbt_free(((surf_action_network_CM02_t) action)->src_name);
-    xbt_free(((surf_action_network_CM02_t) action)->dst_name);
-    xbt_free(action->category);
-#endif
     surf_action_free(&action);
     return 1;
   }
@@ -358,9 +354,9 @@ static int net_action_unref(surf_action_t action)
 
 static void net_action_cancel(surf_action_t action)
 {
-       XBT_DEBUG("cancel action %p",action);
+  XBT_DEBUG("cancel action %p", action);
   surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
-  if(network_update_mechanism == UM_LAZY){// remove action from the heap
+  if (network_update_mechanism == UM_LAZY) {    // remove action from the heap
     xbt_swag_remove(action, net_modified_set);
     heap_remove((surf_action_network_CM02_t) action);
   }
@@ -380,50 +376,51 @@ int net_get_link_latency_limited(surf_action_t action)
 
 double net_action_get_remains(surf_action_t action)
 {
-  if(network_update_mechanism == UM_LAZY)/* update remains before return it */
-    update_action_remaining(surf_get_clock());
+  if (network_update_mechanism == UM_LAZY)      /* update remains before return it */
+    update_action_remaining_lazy(surf_get_clock());
   return action->remains;
 }
 
-static void update_action_remaining(double now){
+static void update_action_remaining_lazy(double now)
+{
   surf_action_network_CM02_t action = NULL;
   double delta = 0.0;
 
   xbt_swag_foreach(action, net_modified_set) {
 
-    if(action->suspended != 0){
-        continue;
+    if (GENERIC_LMM_ACTION(action).suspended != 0) {
+      continue;
     }
 
-    delta = now - action->last_update;
+    delta = now - GENERIC_LMM_ACTION(action).last_update;
 
-    double_update(&(action->generic_action.remains),
-                  lmm_variable_getvalue(action->variable) * delta);
+    double_update(&(((surf_action_t)action)->remains),
+                  lmm_variable_getvalue(((surf_action_lmm_t) action)->variable) * delta);
 
-    if (action->generic_action.max_duration != NO_MAX_DURATION)
-      double_update(&(action->generic_action.max_duration), delta);
+    if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
+      double_update(&(((surf_action_t)action)->max_duration), delta);
 
-    if ((action->generic_action.remains <= 0) &&
-        (lmm_get_variable_weight(action->variable) > 0)) {
-      action->generic_action.finish = surf_get_clock();
+    if ((((surf_action_t)action)->remains <= 0) &&
+        (lmm_get_variable_weight(((surf_action_lmm_t)action)->variable) > 0)) {
+      ((surf_action_t)action)->finish = surf_get_clock();
       surf_network_model->action_state_set((surf_action_t) action,
                                            SURF_ACTION_DONE);
       heap_remove(action);
-    } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
-               && (action->generic_action.max_duration <= 0)) {
-      action->generic_action.finish = surf_get_clock();
+    } else if (((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
+               && (((surf_action_t)action)->max_duration <= 0))) {
+      ((surf_action_t)action)->finish = surf_get_clock();
       surf_network_model->action_state_set((surf_action_t) action,
                                            SURF_ACTION_DONE);
       heap_remove(action);
     }
 
-    action->last_update = now;
+    GENERIC_LMM_ACTION(action).last_update = now;
   }
 }
 
 static double net_share_resources_full(double now)
 {
-  s_surf_action_network_CM02_t s_action;
+  s_surf_action_lmm_t s_action;
   surf_action_network_CM02_t action = NULL;
   xbt_swag_t running_actions =
       surf_network_model->states.running_action_set;
@@ -439,14 +436,14 @@ static double net_share_resources_full(double now)
 
   xbt_swag_foreach(action, running_actions) {
 #ifdef HAVE_LATENCY_BOUND_TRACKING
-    if (lmm_is_variable_limited_by_latency(action->variable)) {
-      (action->generic_action).latency_limited = 1;
+    if (lmm_is_variable_limited_by_latency(GENERIC_LMM_ACTION(action).variable)) {
+      action->latency_limited = 1;
     } else {
-      (action->generic_action).latency_limited = 0;
+      action->latency_limited = 0;
     }
 #endif
     if (action->latency > 0) {
-      min = (min<0)?action->latency:min(min,action->latency);
+      min = (min < 0) ? action->latency : min(min, action->latency);
     }
   }
 
@@ -458,30 +455,33 @@ static double net_share_resources_full(double now)
 static double net_share_resources_lazy(double now)
 {
   surf_action_network_CM02_t action = NULL;
-  double min=-1;
+  double min = -1;
   double value;
 
-  XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(net_modified_set));
-  update_action_remaining(now);
+  XBT_DEBUG
+      ("Before share resources, the size of modified actions set is %d",
+       xbt_swag_size(net_modified_set));
+  update_action_remaining_lazy(now);
 
   lmm_solve(network_maxmin_system);
 
-  XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(net_modified_set));
+  XBT_DEBUG
+      ("After share resources, The size of modified actions set is %d",
+       xbt_swag_size(net_modified_set));
 
   xbt_swag_foreach(action, net_modified_set) {
     int max_dur_flag = 0;
 
-    if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){
+    if (GENERIC_ACTION(action).state_set !=
+        surf_network_model->states.running_action_set)
       continue;
-    }
 
     /* bogus priority, skip it */
-    if (GENERIC_ACTION(action).priority <= 0){
+    if (GENERIC_ACTION(action).priority <= 0)
       continue;
-    }
 
     min = -1;
-    value = lmm_variable_getvalue(action->variable);
+    value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
     if (value > 0) {
       if (GENERIC_ACTION(action).remains > 0) {
         value = GENERIC_ACTION(action).remains / value;
@@ -495,32 +495,29 @@ static double net_share_resources_lazy(double now)
     if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
         && (min == -1
             || GENERIC_ACTION(action).start +
-            GENERIC_ACTION(action).max_duration < min)){
-      min =   GENERIC_ACTION(action).start +
+            GENERIC_ACTION(action).max_duration < min)) {
+      min = GENERIC_ACTION(action).start +
           GENERIC_ACTION(action).max_duration;
       max_dur_flag = 1;
     }
 
     XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
-        GENERIC_ACTION(action).start, now + value,
-        GENERIC_ACTION(action).max_duration);
-
-    if (action->index_heap >= 0) {
-      heap_remove((surf_action_network_CM02_t) action);
-    }
+              GENERIC_ACTION(action).start, now + value,
+              GENERIC_ACTION(action).max_duration);
 
     if (min != -1) {
-      heap_insert((surf_action_network_CM02_t) action, min, max_dur_flag?MAX_DURATION:NORMAL);
-      XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now);
-    }
+      heap_remove(action);
+      heap_insert(action, min, max_dur_flag ? MAX_DURATION : NORMAL);
+      XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
+                now);
+    } else DIE_IMPOSSIBLE;
   }
 
   //hereafter must have already the min value for this resource model
-  if(xbt_heap_size(net_action_heap) > 0 ){
-    min = xbt_heap_maxkey(net_action_heap) - now ;
-  }else{
+  if (xbt_heap_size(net_action_heap) > 0)
+    min = xbt_heap_maxkey(net_action_heap) - now;
+  else
     min = -1;
-  }
 
   XBT_DEBUG("The minimum with the HEAP %lf", min);
 
@@ -549,52 +546,56 @@ static void net_update_actions_state_full(double now, double delta)
         double_update(&(deltap), action->latency);
         action->latency = 0.0;
       }
-      if ((action->latency == 0.0) && !(action->suspended))
-        lmm_update_variable_weight(network_maxmin_system, action->variable,
+      if ((action->latency == 0.0) && !(GENERIC_LMM_ACTION(action).suspended))
+        lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
                                    action->weight);
     }
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
-      xbt_dynar_t route=NULL;
-      routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL);
-      link_CM02_t link;
+      int n = lmm_get_number_of_cnst_from_var(network_maxmin_system, GENERIC_LMM_ACTION(action).variable);
       unsigned int i;
-      xbt_dynar_foreach(route, i, link) {
+      for (i = 0; i < n; i++){
+        lmm_constraint_t constraint = lmm_get_cnst_from_var(network_maxmin_system,
+                                                            GENERIC_LMM_ACTION(action).variable,
+                                                            i);
+        link_CM02_t link = lmm_constraint_id(constraint);
         TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
-                                        action->generic_action.data,
-                                        (surf_action_t) action,
-                                        lmm_variable_getvalue
-                                        (action->variable), now - delta,
+                                        ((surf_action_t)action)->category,
+                                        lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
+                                        now - delta,
                                         delta);
       }
     }
 #endif
-    if(!lmm_get_number_of_cnst_from_var(network_maxmin_system, action->variable)) {
-        /* 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.
-         */
-      double_update(&(action->generic_action.remains),
-          action->generic_action.remains);
+    if (!lmm_get_number_of_cnst_from_var
+        (network_maxmin_system, GENERIC_LMM_ACTION(action).variable)) {
+      /* 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.
+       */
+      double_update(&(GENERIC_ACTION(action).remains),
+                    GENERIC_ACTION(action).remains);
     }
-    double_update(&(action->generic_action.remains),
-                  lmm_variable_getvalue(action->variable) * deltap);
-    if (action->generic_action.max_duration != NO_MAX_DURATION)
-      double_update(&(action->generic_action.max_duration), delta);
-
-    if ((action->generic_action.remains <= 0) &&
-        (lmm_get_variable_weight(action->variable) > 0)) {
-      action->generic_action.finish = surf_get_clock();
+    double_update(&(GENERIC_ACTION(action).remains),
+                  lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * deltap);
+    if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
+      double_update(&(((surf_action_t)action)->max_duration), delta);
+
+    if ((GENERIC_ACTION(action).remains <= 0) &&
+        (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
+      ((surf_action_t)action)->finish = surf_get_clock();
       surf_network_model->action_state_set((surf_action_t) action,
                                            SURF_ACTION_DONE);
 
-      if(gap_remove) gap_remove(action);
-    } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
-               && (action->generic_action.max_duration <= 0)) {
-      action->generic_action.finish = surf_get_clock();
+      if (gap_remove)
+        gap_remove(action);
+    } else if ((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
+               && (((surf_action_t)action)->max_duration <= 0)) {
+      ((surf_action_t)action)->finish = surf_get_clock();
       surf_network_model->action_state_set((surf_action_t) action,
                                            SURF_ACTION_DONE);
-      if(gap_remove) gap_remove(action);
+      if (gap_remove)
+        gap_remove(action);
     }
   }
 
@@ -610,23 +611,41 @@ static void net_update_actions_state_lazy(double now, double delta)
     action = xbt_heap_pop(net_action_heap);
     XBT_DEBUG("Action %p: finish", action);
     GENERIC_ACTION(action).finish = surf_get_clock();
+#ifdef HAVE_TRACING
+    if (TRACE_is_enabled()) {
+      int n = lmm_get_number_of_cnst_from_var(network_maxmin_system, GENERIC_LMM_ACTION(action).variable);
+      unsigned int i;
+      for (i = 0; i < n; i++){
+        lmm_constraint_t constraint = lmm_get_cnst_from_var(network_maxmin_system,
+                                                            GENERIC_LMM_ACTION(action).variable,
+                                                            i);
+        link_CM02_t link = lmm_constraint_id(constraint);
+        TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
+                                        ((surf_action_t)action)->category,
+                                        lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
+                                        GENERIC_LMM_ACTION(action).last_update,
+                                        now - GENERIC_LMM_ACTION(action).last_update);
+      }
+    }
+#endif
 
     // if I am wearing a latency hat
-    if( action->hat ==  LATENCY){
-        lmm_update_variable_weight(network_maxmin_system, action->variable,
-                                           action->weight);
-        heap_remove(action);
-        action->last_update = surf_get_clock();
-
-    // if I am wearing a max_duration or normal hat
-    }else if( action->hat == MAX_DURATION || action->hat == NORMAL ){
-        // no need to communicate anymore
-        // assume that flows that reached max_duration have remaining of 0
-        GENERIC_ACTION(action).remains = 0;
-        action->generic_action.finish = surf_get_clock();
-              surf_network_model->action_state_set((surf_action_t) action,
-                                                   SURF_ACTION_DONE);
-        heap_remove(action);
+    if (GENERIC_LMM_ACTION(action).hat == LATENCY) {
+      lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
+                                 action->weight);
+      heap_remove(action);
+      GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
+
+      // if I am wearing a max_duration or normal hat
+    } else if (GENERIC_LMM_ACTION(action).hat == MAX_DURATION ||
+        GENERIC_LMM_ACTION(action).hat == NORMAL) {
+      // no need to communicate anymore
+      // assume that flows that reached max_duration have remaining of 0
+      GENERIC_ACTION(action).remains = 0;
+      ((surf_action_t)action)->finish = surf_get_clock();
+      surf_network_model->action_state_set((surf_action_t) action,
+                                           SURF_ACTION_DONE);
+      heap_remove(action);
     }
   }
   return;
@@ -657,7 +676,10 @@ static void net_update_resource_state(void *id,
                                 (nw_link->lmm_resource.power.peak *
                                  nw_link->lmm_resource.power.scale));
 #ifdef HAVE_TRACING
-    TRACE_surf_link_set_bandwidth(date, (char *)(((nw_link->lmm_resource).generic_resource).name),
+    TRACE_surf_link_set_bandwidth(date,
+                                  (char
+                                   *) (((nw_link->lmm_resource).
+                                        generic_resource).name),
                                   sg_bandwidth_factor *
                                   (nw_link->lmm_resource.power.peak *
                                    nw_link->lmm_resource.power.scale));
@@ -668,9 +690,9 @@ static void net_update_resource_state(void *id,
                &elem))) {
         action = lmm_variable_id(var);
         action->weight += delta;
-        if (!(action->suspended))
+        if (!(GENERIC_LMM_ACTION(action).suspended))
           lmm_update_variable_weight(network_maxmin_system,
-                                     action->variable, action->weight);
+                                     GENERIC_LMM_ACTION(action).variable, action->weight);
       }
     }
     if (tmgr_trace_event_free(event_type))
@@ -689,24 +711,25 @@ static void net_update_resource_state(void *id,
       action->lat_current += delta;
       action->weight += delta;
       if (action->rate < 0)
-        lmm_update_variable_bound(network_maxmin_system, action->variable,
+        lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
                                   sg_tcp_gamma / (2.0 *
                                                   action->lat_current));
       else {
-        lmm_update_variable_bound(network_maxmin_system, action->variable,
+        lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
                                   min(action->rate,
                                       sg_tcp_gamma / (2.0 *
-                                                      action->lat_current)));
+                                                      action->
+                                                      lat_current)));
 
         if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
           XBT_INFO("Flow is limited BYBANDWIDTH");
         } else {
           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
-                action->lat_current);
+                   action->lat_current);
         }
       }
-      if (!(action->suspended))
-        lmm_update_variable_weight(network_maxmin_system, action->variable,
+      if (!(GENERIC_LMM_ACTION(action).suspended))
+        lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
                                    action->weight);
 
     }
@@ -739,7 +762,9 @@ static void net_update_resource_state(void *id,
     xbt_abort();
   }
 
-  XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint);
+  XBT_DEBUG
+      ("There were a resource state event, need to update actions related to the constraint (%p)",
+       nw_link->lmm_resource.constraint);
   return;
 }
 
@@ -753,18 +778,18 @@ static surf_action_t net_communicate(const char *src_name,
   int failed = 0;
   surf_action_network_CM02_t action = NULL;
   double bandwidth_bound;
-  double latency=0.0;
+  double latency = 0.0;
   xbt_dynar_t back_route = NULL;
   int constraints_per_variable = 0;
 
-  xbt_dynar_t route=xbt_dynar_new(global_routing->size_of_link,NULL);
+  xbt_dynar_t route = xbt_dynar_new(global_routing->size_of_link, NULL);
 
   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
 
   routing_get_route_and_latency(src_name, dst_name, &route, &latency);
   xbt_assert(!xbt_dynar_is_empty(route) || latency,
-              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
-              src_name, dst_name);
+             "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
+             src_name, dst_name);
 
   xbt_dynar_foreach(route, i, link) {
     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
@@ -773,7 +798,7 @@ static surf_action_t net_communicate(const char *src_name,
     }
   }
   if (sg_network_crosstraffic == 1) {
-    routing_get_route_and_latency(dst_name, src_name, &back_route,NULL);
+    routing_get_route_and_latency(dst_name, src_name, &back_route, NULL);
     xbt_dynar_foreach(back_route, i, link) {
       if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
         failed = 1;
@@ -786,19 +811,19 @@ static surf_action_t net_communicate(const char *src_name,
       surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
                       surf_network_model, failed);
 #ifdef HAVE_LATENCY_BOUND_TRACKING
-  (action->generic_action).latency_limited = 0;
+  action->latency_limited = 0;
 #endif
   action->weight = action->latency = latency;
 
-  xbt_swag_insert(action, action->generic_action.state_set);
+  xbt_swag_insert(action, ((surf_action_t)action)->state_set);
   action->rate = rate;
-  if(network_update_mechanism == UM_LAZY){
-    action->index_heap = -1;
-    action->last_update = surf_get_clock();
+  if (network_update_mechanism == UM_LAZY) {
+    GENERIC_LMM_ACTION(action).index_heap = -1;
+    GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
   }
 
   bandwidth_bound = -1.0;
-  if(sg_weight_S_parameter>0) {
+  if (sg_weight_S_parameter > 0) {
     xbt_dynar_foreach(route, i, link) {
       action->weight +=
           sg_weight_S_parameter /
@@ -808,74 +833,72 @@ static surf_action_t net_communicate(const char *src_name,
   xbt_dynar_foreach(route, i, link) {
     double bb = bandwidth_factor_callback(size) *
         (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
-    bandwidth_bound = (bandwidth_bound < 0.0)?bb:min(bandwidth_bound,bb);
+    bandwidth_bound =
+        (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
   }
 
   action->lat_current = action->latency;
   action->latency *= latency_factor_callback(size);
   action->rate =
-      bandwidth_constraint_callback(action->rate, bandwidth_bound,
-                                        size);
-  if(gap_append) {
-    xbt_assert(!xbt_dynar_is_empty(route),"Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
+      bandwidth_constraint_callback(action->rate, bandwidth_bound, size);
+  if (gap_append) {
+    xbt_assert(!xbt_dynar_is_empty(route),
+               "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
 
-    link = *(link_CM02_t*)xbt_dynar_get_ptr(route, 0);
+    link = *(link_CM02_t *) xbt_dynar_get_ptr(route, 0);
     gap_append(size, link, action);
     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
-           action, src_name, dst_name, action->sender.gap, action->latency);
+              action, src_name, dst_name, action->sender.gap,
+              action->latency);
   }
 
   constraints_per_variable = xbt_dynar_length(route);
   if (back_route != NULL)
     constraints_per_variable += xbt_dynar_length(back_route);
 
-  if (action->latency > 0){
-      action->variable =
+  if (action->latency > 0) {
+    GENERIC_LMM_ACTION(action).variable =
         lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
                          constraints_per_variable);
-    if(network_update_mechanism == UM_LAZY){
+    if (network_update_mechanism == UM_LAZY) {
       // add to the heap the event when the latency is payed
-      XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update);
-      heap_insert(action, action->latency + action->last_update, xbt_dynar_is_empty(route)?NORMAL:LATENCY);
+      XBT_DEBUG("Added action (%p) one latency event at date %f", action,
+                action->latency + GENERIC_LMM_ACTION(action).last_update);
+      heap_insert(action, action->latency + GENERIC_LMM_ACTION(action).last_update,
+                  xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
     }
   } else
-    action->variable =
+    GENERIC_LMM_ACTION(action).variable =
         lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
                          constraints_per_variable);
 
   if (action->rate < 0) {
-    lmm_update_variable_bound(network_maxmin_system, action->variable,
-        (action->lat_current > 0)?
-            sg_tcp_gamma / (2.0 * action->lat_current)  :-1.0);
+    lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
+                              (action->lat_current > 0) ?
+                              sg_tcp_gamma / (2.0 *
+                                              action->lat_current) : -1.0);
   } else {
-    lmm_update_variable_bound(network_maxmin_system, action->variable,
-        (action->lat_current > 0)?
-            min(action->rate, sg_tcp_gamma / (2.0 * action->lat_current))
-            :action->rate);
+    lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
+                              (action->lat_current > 0) ?
+                              min(action->rate,
+                                  sg_tcp_gamma / (2.0 *
+                                                  action->lat_current))
+                              : action->rate);
   }
 
   xbt_dynar_foreach(route, i, link) {
     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
-               action->variable, 1.0);
+               GENERIC_LMM_ACTION(action).variable, 1.0);
   }
 
   if (sg_network_crosstraffic == 1) {
     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
     xbt_dynar_foreach(back_route, i, link) {
       lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
-                 action->variable, .05);
+                 GENERIC_LMM_ACTION(action).variable, .05);
     }
   }
 
-#ifdef HAVE_TRACING
-  if (TRACE_is_enabled()) {
-    action->src_name = xbt_strdup(src_name);
-    action->dst_name = xbt_strdup(dst_name);
-  } else {
-    action->src_name = action->dst_name = NULL;
-  }
-#endif
-
   xbt_dynar_free(&route);
   XBT_OUT();
 
@@ -884,8 +907,8 @@ static surf_action_t net_communicate(const char *src_name,
 
 static xbt_dynar_t net_get_route(const char *src, const char *dst)
 {
-  xbt_dynar_t route=NULL;
-  routing_get_route_and_latency(src, dst,&route,NULL);
+  xbt_dynar_t route = NULL;
+  routing_get_route_and_latency(src, dst, &route, NULL);
   return route;
 }
 
@@ -908,45 +931,46 @@ static int net_link_shared(const void *link)
 
 static void net_action_suspend(surf_action_t action)
 {
-  ((surf_action_network_CM02_t) action)->suspended = 1;
+  ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 1;
   lmm_update_variable_weight(network_maxmin_system,
                              ((surf_action_network_CM02_t)
-                              action)->variable, 0.0);
+                              action)->generic_lmm_action.variable, 0.0);
 
-  if(network_update_mechanism == UM_LAZY)// remove action from the heap
+  if (network_update_mechanism == UM_LAZY)      // remove action from the heap
     heap_remove((surf_action_network_CM02_t) action);
 }
 
 static void net_action_resume(surf_action_t action)
 {
-  if (((surf_action_network_CM02_t) action)->suspended) {
+  if (((surf_action_network_CM02_t) action)->generic_lmm_action.suspended) {
     lmm_update_variable_weight(network_maxmin_system,
                                ((surf_action_network_CM02_t)
-                                action)->variable,
+                                action)->generic_lmm_action.variable,
                                ((surf_action_network_CM02_t)
                                 action)->weight);
-    ((surf_action_network_CM02_t) action)->suspended = 0;
-    if(network_update_mechanism == UM_LAZY)// remove action from the heap
+    ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 0;
+    if (network_update_mechanism == UM_LAZY)    // remove action from the heap
       heap_remove((surf_action_network_CM02_t) action);
   }
 }
 
 static int net_action_is_suspended(surf_action_t action)
 {
-  return ((surf_action_network_CM02_t) action)->suspended;
+  return ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended;
 }
 
 void net_action_set_max_duration(surf_action_t action, double duration)
 {
   action->max_duration = duration;
-  if(network_update_mechanism == UM_LAZY)// remove action from the heap
+  if (network_update_mechanism == UM_LAZY)      // remove action from the heap
     heap_remove((surf_action_network_CM02_t) action);
 }
 
 #ifdef HAVE_TRACING
-static void net_action_set_category(surf_action_t action, const char *category)
+static void net_action_set_category(surf_action_t action,
+                                    const char *category)
 {
-  action->category = xbt_strdup (category);
+  action->category = xbt_strdup(category);
 }
 #endif
 
@@ -958,65 +982,77 @@ static void net_finalize(void)
   lmm_system_free(network_maxmin_system);
   network_maxmin_system = NULL;
 
-  if(network_update_mechanism == UM_LAZY){
+  if (network_update_mechanism == UM_LAZY) {
     xbt_heap_free(net_action_heap);
     xbt_swag_free(net_modified_set);
   }
 
-  if(smpi_bw_factor)
-         xbt_dynar_free(&smpi_bw_factor);
-  if(smpi_lat_factor)
-         xbt_dynar_free(&smpi_lat_factor);
+  if (smpi_bw_factor)
+    xbt_dynar_free(&smpi_bw_factor);
+  if (smpi_lat_factor)
+    xbt_dynar_free(&smpi_lat_factor);
 }
 
-static void smpi_gap_append(double size, const link_CM02_t link, surf_action_network_CM02_t action) {
-   const char* src = link->lmm_resource.generic_resource.name;
-   xbt_fifo_t fifo;
-   surf_action_network_CM02_t last_action;
-   double bw;
-
-   if(sg_sender_gap > 0.0) {
-      if(!gap_lookup) {
-         gap_lookup = xbt_dict_new();
-      }
-      fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, src);
-      action->sender.gap = 0.0;
-      if(fifo && xbt_fifo_size(fifo) > 0) {
-         /* Compute gap from last send */
-         last_action = (surf_action_network_CM02_t)xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
-         bw = net_get_link_bandwidth(link);
-         action->sender.gap = last_action->sender.gap + max(sg_sender_gap, last_action->sender.size / bw);
-         action->latency += action->sender.gap;
-      }
-      /* Append action as last send */
-      action->sender.link_name = link->lmm_resource.generic_resource.name;
-      fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, action->sender.link_name);
-      if(!fifo) {
-         fifo = xbt_fifo_new();
-         xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
-      }
-      action->sender.fifo_item = xbt_fifo_push(fifo, action);
-      action->sender.size = size;
-   }
+static void smpi_gap_append(double size, const link_CM02_t link,
+                            surf_action_network_CM02_t action)
+{
+  const char *src = link->lmm_resource.generic_resource.name;
+  xbt_fifo_t fifo;
+  surf_action_network_CM02_t last_action;
+  double bw;
+
+  if (sg_sender_gap > 0.0) {
+    if (!gap_lookup) {
+      gap_lookup = xbt_dict_new();
+    }
+    fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
+    action->sender.gap = 0.0;
+    if (fifo && xbt_fifo_size(fifo) > 0) {
+      /* Compute gap from last send */
+      last_action =
+          (surf_action_network_CM02_t)
+          xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
+      bw = net_get_link_bandwidth(link);
+      action->sender.gap =
+          last_action->sender.gap + max(sg_sender_gap,
+                                        last_action->sender.size / bw);
+      action->latency += action->sender.gap;
+    }
+    /* Append action as last send */
+    action->sender.link_name = link->lmm_resource.generic_resource.name;
+    fifo =
+        (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
+                                          action->sender.link_name);
+    if (!fifo) {
+      fifo = xbt_fifo_new();
+      xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
+    }
+    action->sender.fifo_item = xbt_fifo_push(fifo, action);
+    action->sender.size = size;
+  }
 }
 
-static void smpi_gap_remove(surf_action_network_CM02_t action) {
-   xbt_fifo_t fifo;
-   size_t size;
-
-   if(sg_sender_gap > 0.0 && action->sender.link_name && action->sender.fifo_item) {
-      fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, action->sender.link_name);
-      xbt_fifo_remove_item(fifo, action->sender.fifo_item);
-      size = xbt_fifo_size(fifo);
-      if(size == 0) {
-         xbt_fifo_free(fifo);
-         xbt_dict_remove(gap_lookup, action->sender.link_name);
-         size = xbt_dict_length(gap_lookup);
-         if(size == 0) {
-            xbt_dict_free(&gap_lookup);
-         }
+static void smpi_gap_remove(surf_action_network_CM02_t action)
+{
+  xbt_fifo_t fifo;
+  size_t size;
+
+  if (sg_sender_gap > 0.0 && action->sender.link_name
+      && action->sender.fifo_item) {
+    fifo =
+        (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
+                                          action->sender.link_name);
+    xbt_fifo_remove_item(fifo, action->sender.fifo_item);
+    size = xbt_fifo_size(fifo);
+    if (size == 0) {
+      xbt_fifo_free(fifo);
+      xbt_dict_remove(gap_lookup, action->sender.link_name);
+      size = xbt_dict_length(gap_lookup);
+      if (size == 0) {
+        xbt_dict_free(&gap_lookup);
       }
-   }
+    }
+  }
 }
 
 static void surf_network_model_init_internal(void)
@@ -1037,16 +1073,20 @@ static void surf_network_model_init_internal(void)
 #endif
 
   surf_network_model->model_private->resource_used = net_resource_used;
-  if(network_update_mechanism == UM_LAZY) {
-    surf_network_model->model_private->share_resources = net_share_resources_lazy;
-    surf_network_model->model_private->update_actions_state = net_update_actions_state_lazy;
-  } else if(network_update_mechanism == UM_FULL) {
-    surf_network_model->model_private->share_resources = net_share_resources_full;
-    surf_network_model->model_private->update_actions_state = net_update_actions_state_full;
+  if (network_update_mechanism == UM_LAZY) {
+    surf_network_model->model_private->share_resources =
+        net_share_resources_lazy;
+    surf_network_model->model_private->update_actions_state =
+        net_update_actions_state_lazy;
+  } else if (network_update_mechanism == UM_FULL) {
+    surf_network_model->model_private->share_resources =
+        net_share_resources_full;
+    surf_network_model->model_private->update_actions_state =
+        net_update_actions_state_full;
   }
 
   surf_network_model->model_private->update_resource_state =
-                 net_update_resource_state;
+      net_update_resource_state;
   surf_network_model->model_private->finalize = net_finalize;
 
   surf_network_model->suspend = net_action_suspend;
@@ -1057,49 +1097,52 @@ static void surf_network_model_init_internal(void)
   surf_network_model->extension.network.communicate = net_communicate;
   surf_network_model->extension.network.get_route = net_get_route;
   surf_network_model->extension.network.get_link_bandwidth =
-                 net_get_link_bandwidth;
+      net_get_link_bandwidth;
   surf_network_model->extension.network.get_link_latency =
-                 net_get_link_latency;
+      net_get_link_latency;
   surf_network_model->extension.network.link_shared = net_link_shared;
   surf_network_model->extension.network.add_traces = net_add_traces;
   surf_network_model->extension.network.create_resource =
-                 net_create_resource;
+      net_create_resource;
 
- if (!network_maxmin_system)
 if (!network_maxmin_system)
     network_maxmin_system = lmm_system_new(net_selective_update);
 
- routing_model_create(sizeof(link_CM02_t),
-      net_create_resource("__loopback__",
-          498000000, NULL, 0.000015, NULL,
-          SURF_RESOURCE_ON, NULL,
-          SURF_LINK_FATPIPE, NULL));
-
-  if(network_update_mechanism == UM_LAZY){
-    net_action_heap = xbt_heap_new(8,NULL);
-    xbt_heap_set_update_callback(net_action_heap, net_action_update_index_heap);
-    net_modified_set = xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
+  routing_model_create(sizeof(link_CM02_t),
+                       net_create_resource("__loopback__",
+                                           498000000, NULL, 0.000015, NULL,
+                                           SURF_RESOURCE_ON, NULL,
+                                           SURF_LINK_FATPIPE, NULL));
+
+  if (network_update_mechanism == UM_LAZY) {
+    net_action_heap = xbt_heap_new(8, NULL);
+    xbt_heap_set_update_callback(net_action_heap,
+                                 net_action_update_index_heap);
+    net_modified_set =
+        xbt_swag_new(xbt_swag_offset(comm, generic_lmm_action.action_list_hookup));
     network_maxmin_system->keep_track = net_modified_set;
   }
 }
 
-static void set_update_mechanism(void) {
-#ifdef HAVE_TRACING
-  TRACE_set_network_update_mechanism ();
-#endif
-
+static void set_update_mechanism(void)
+{
   char *optim = xbt_cfg_get_string(_surf_cfg_set, "network/optim");
-  int select = xbt_cfg_get_int(_surf_cfg_set, "network/maxmin_selective_update");
+  int select =
+      xbt_cfg_get_int(_surf_cfg_set, "network/maxmin_selective_update");
 
-  if(!strcmp(optim,"Full")) {
+  if (!strcmp(optim, "Full")) {
     network_update_mechanism = UM_FULL;
     net_selective_update = select;
-  } else if (!strcmp(optim,"Lazy")) {
+  } else if (!strcmp(optim, "Lazy")) {
     network_update_mechanism = UM_LAZY;
     net_selective_update = 1;
-    xbt_assert((select==1) || (xbt_cfg_is_default_value(_surf_cfg_set,"network/maxmin_selective_update")),
-        "Disabling selective update while using the lazy update mechanism is dumb!");
+    xbt_assert((select == 1)
+               ||
+               (xbt_cfg_is_default_value
+                (_surf_cfg_set, "network/maxmin_selective_update")),
+               "Disabling selective update while using the lazy update mechanism is dumb!");
   } else {
-    xbt_die("Unsupported optimization (%s) for this model",optim);
+    xbt_die("Unsupported optimization (%s) for this model", optim);
   }
 }
 
@@ -1161,8 +1204,10 @@ void surf_network_model_init_LegrandVelho(void)
   xbt_dynar_push(model_list, &surf_network_model);
   network_solve = lmm_solve;
 
-  xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 13.01);
-  xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",0.97);
+  xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor",
+                            13.01);
+  xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
+                            0.97);
   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 20537);
 }
 
@@ -1190,7 +1235,8 @@ void surf_network_model_init_CM02(void)
   network_solve = lmm_solve;
 
   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 1.0);
-  xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", 1.0);
+  xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
+                            1.0);
   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 0.0);
 }
 
index 7b4a54f..a089531 100644 (file)
@@ -35,301 +35,290 @@ static int action_unref(surf_action_t action);
 
 xbt_dynar_t IPV4addr;
 
-static void replace_str(char *str, const char *orig, const char *rep)
-{
-  char buffer[30];
-  char *p;
-
-  if(!(p = strstr(str, orig)))  // Is 'orig' even in 'str'?
-    return;
-
-  strncpy(buffer, str, p-str); // Copy characters from 'str' start to 'orig' st$
-  buffer[p-str] = '\0';
-
-  sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig));
-  xbt_free(str);
-  str = xbt_strdup(buffer);
-}
-
 static void replace_bdw_ns3(char ** bdw)
 {
-       char *temp = xbt_strdup(*bdw);
-       xbt_free(*bdw);
-       *bdw = bprintf("%fBps",atof(temp));
-       xbt_free(temp);
+  char *temp = xbt_strdup(*bdw);
+  xbt_free(*bdw);
+  *bdw = bprintf("%fBps",atof(temp));
+  xbt_free(temp);
 
 }
 
 static void replace_lat_ns3(char ** lat)
 {
-       char *temp = xbt_strdup(*lat);
-       xbt_free(*lat);
-       *lat = bprintf("%fs",atof(temp));
-       xbt_free(temp);
+  char *temp = xbt_strdup(*lat);
+  xbt_free(*lat);
+  *lat = bprintf("%fs",atof(temp));
+  xbt_free(temp);
 }
 
-void parse_ns3_add_host(void)
+static void parse_ns3_add_host(sg_platf_host_cbarg_t host)
 {
-       XBT_DEBUG("NS3_ADD_HOST '%s'",A_surfxml_host_id);
-       xbt_lib_set(host_lib,
-                               A_surfxml_host_id,
-                               NS3_HOST_LEVEL,
-                               ns3_add_host(A_surfxml_host_id)
-                               );
+  XBT_DEBUG("NS3_ADD_HOST '%s'",A_surfxml_host_id);
+  xbt_lib_set(host_lib,
+              A_surfxml_host_id,
+              NS3_HOST_LEVEL,
+              ns3_add_host(A_surfxml_host_id)
+    );
 }
 
-static void ns3_free_dynar(void * elmts){
-       free(elmts);
-       return;
+static void ns3_free_dynar(void * elmts)
+{
+  free(elmts);
+  return;
 }
 
-void parse_ns3_add_link(void)
+static void parse_ns3_add_link(sg_platf_link_cbarg_t l)
 {
-       XBT_DEBUG("NS3_ADD_LINK '%s'",A_surfxml_link_id);
-
-       if(!IPV4addr) IPV4addr = xbt_dynar_new(sizeof(char*),ns3_free_dynar);
-
-       tmgr_trace_t bw_trace;
-       tmgr_trace_t state_trace;
-       tmgr_trace_t lat_trace;
-
-       bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
-       lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
-       state_trace = tmgr_trace_new(A_surfxml_link_state_file);
-
-       if (bw_trace)
-               XBT_INFO("The NS3 network model doesn't support bandwidth state traces");
-       if (lat_trace)
-               XBT_INFO("The NS3 network model doesn't support latency state traces");
-       if (state_trace)
-               XBT_INFO("The NS3 network model doesn't support link state traces");
-
-       ns3_link_t link_ns3 = xbt_new0(s_ns3_link_t,1);;
-       link_ns3->id = xbt_strdup(A_surfxml_link_id);
-       link_ns3->bdw = xbt_strdup(A_surfxml_link_bandwidth);
-       link_ns3->lat = xbt_strdup(A_surfxml_link_latency);
-
-       surf_ns3_link_t link = xbt_new0(s_surf_ns3_link_t,1);
-       link->generic_resource.name = xbt_strdup(A_surfxml_link_id);
-       link->generic_resource.properties = current_property_set;
-       link->data = link_ns3;
-       link->created = 1;
-
-       xbt_lib_set(link_lib,A_surfxml_link_id,NS3_LINK_LEVEL,link_ns3);
-       xbt_lib_set(link_lib,A_surfxml_link_id,SURF_LINK_LEVEL,link);
+  XBT_DEBUG("NS3_ADD_LINK '%s'",A_surfxml_link_id);
+
+  if(!IPV4addr) IPV4addr = xbt_dynar_new(sizeof(char*),ns3_free_dynar);
+
+  tmgr_trace_t bw_trace;
+  tmgr_trace_t state_trace;
+  tmgr_trace_t lat_trace;
+
+  bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
+  lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
+  state_trace = tmgr_trace_new(A_surfxml_link_state_file);
+
+  if (bw_trace)
+    XBT_INFO("The NS3 network model doesn't support bandwidth state traces");
+  if (lat_trace)
+    XBT_INFO("The NS3 network model doesn't support latency state traces");
+  if (state_trace)
+    XBT_INFO("The NS3 network model doesn't support link state traces");
+
+  ns3_link_t link_ns3 = xbt_new0(s_ns3_link_t,1);;
+  link_ns3->id = xbt_strdup(A_surfxml_link_id);
+  link_ns3->bdw = xbt_strdup(A_surfxml_link_bandwidth);
+  link_ns3->lat = xbt_strdup(A_surfxml_link_latency);
+
+  surf_ns3_link_t link = xbt_new0(s_surf_ns3_link_t,1);
+  link->generic_resource.name = xbt_strdup(A_surfxml_link_id);
+  link->generic_resource.properties = current_property_set;
+  link->data = link_ns3;
+  link->created = 1;
+
+  xbt_lib_set(link_lib,A_surfxml_link_id,NS3_LINK_LEVEL,link_ns3);
+  xbt_lib_set(link_lib,A_surfxml_link_id,SURF_LINK_LEVEL,link);
 }
-void parse_ns3_add_router(void)
+
+static void parse_ns3_add_router(sg_platf_router_cbarg_t router)
 {
-       XBT_DEBUG("NS3_ADD_ROUTER '%s'",A_surfxml_router_id);
-       xbt_lib_set(as_router_lib,
-                               A_surfxml_router_id,
-                               NS3_ASR_LEVEL,
-                               ns3_add_router(A_surfxml_router_id)
-                               );
+  XBT_DEBUG("NS3_ADD_ROUTER '%s'",A_surfxml_router_id);
+  xbt_lib_set(as_router_lib,
+              A_surfxml_router_id,
+              NS3_ASR_LEVEL,
+              ns3_add_router(A_surfxml_router_id)
+    );
 }
-void parse_ns3_add_AS(void)
+
+static void parse_ns3_add_AS(const char*id, const char*routing)
 {
-       XBT_DEBUG("NS3_ADD_AS '%s'",A_surfxml_AS_id);
-       xbt_lib_set(as_router_lib,
-                               A_surfxml_AS_id,
-                               NS3_ASR_LEVEL,
-                               ns3_add_AS(A_surfxml_AS_id)
-                               );
+  XBT_DEBUG("NS3_ADD_AS '%s'",A_surfxml_AS_id);
+  xbt_lib_set(as_router_lib,
+              A_surfxml_AS_id,
+              NS3_ASR_LEVEL,
+              ns3_add_AS(A_surfxml_AS_id)
+    );
 }
-void parse_ns3_add_cluster(void)
+
+static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster)
 {
-       char *cluster_prefix = A_surfxml_cluster_prefix;
-       char *cluster_suffix = A_surfxml_cluster_suffix;
-       char *cluster_radical = A_surfxml_cluster_radical;
-       char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
-       char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
-       char *cluster_bw = A_surfxml_cluster_bw;
-       char *cluster_lat = A_surfxml_cluster_lat;
-       char *groups = NULL;
-
-       int start, end, i;
-       unsigned int iter;
-
-       xbt_dynar_t radical_elements;
-       xbt_dynar_t radical_ends;
-       xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
-
-       char *router_id,*host_id;
-
-       radical_elements = xbt_str_split(cluster_radical, ",");
-       xbt_dynar_foreach(radical_elements, iter, groups) {
-               radical_ends = xbt_str_split(groups, "-");
-
-               switch (xbt_dynar_length(radical_ends)) {
-               case 1:
-                 surf_parse_get_int(&start,xbt_dynar_get_as(radical_ends, 0, char *));
-                 xbt_dynar_push_as(tab_elements_num, int, start);
-                 router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix);
-                 xbt_lib_set(host_lib,
-                                               router_id,
-                                               NS3_HOST_LEVEL,
-                                               ns3_add_host_cluster(router_id)
-                                               );
-                 XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
-                 free(router_id);
-                 break;
-
-               case 2:
-                 surf_parse_get_int(&start,xbt_dynar_get_as(radical_ends, 0, char *));
-                 surf_parse_get_int(&end, xbt_dynar_get_as(radical_ends, 1, char *));
-                 for (i = start; i <= end; i++){
-                       xbt_dynar_push_as(tab_elements_num, int, i);
-                       router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix);
-                       xbt_lib_set(host_lib,
-                                               router_id,
-                                               NS3_HOST_LEVEL,
-                                               ns3_add_host_cluster(router_id)
-                                               );
-                       XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
-                       free(router_id);
-                 }
-                 break;
-
-               default:
-                 XBT_DEBUG("Malformed radical");
-               }
-       }
-
-       //Create links
-       unsigned int cpt;
-       int elmts;
-       char * lat = xbt_strdup(cluster_lat);
-       char * bw =  xbt_strdup(cluster_bw);
-       replace_lat_ns3(&lat);
-       replace_bdw_ns3(&bw);
-
-       xbt_dynar_foreach(tab_elements_num,cpt,elmts)
-       {
-               host_id   = bprintf("%s%d%s", cluster_prefix, elmts, cluster_suffix);
-               router_id = bprintf("ns3_%s%d%s", cluster_prefix, elmts, cluster_suffix);
-               XBT_DEBUG("Create link from '%s' to '%s'",host_id,router_id);
-
-               ns3_nodes_t host_src = xbt_lib_get_or_null(host_lib,host_id,  NS3_HOST_LEVEL);
-               ns3_nodes_t host_dst = xbt_lib_get_or_null(host_lib,router_id,NS3_HOST_LEVEL);
-
-               if(host_src && host_dst){}
-               else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
-
-               ns3_add_link(host_src->node_num,host_src->type,
-                                        host_dst->node_num,host_dst->type,
-                                        bw,lat);
-
-               free(router_id);
-               free(host_id);
-       }
-       xbt_dynar_free(&tab_elements_num);
-
-
-       //Create link backbone
-       lat = xbt_strdup(cluster_bb_lat);
-       bw =  xbt_strdup(cluster_bb_bw);
-       replace_lat_ns3(&lat);
-       replace_bdw_ns3(&bw);
-       ns3_add_cluster(bw,lat,A_surfxml_cluster_id);
-       xbt_free(lat);
-       xbt_free(bw);   
+  char *cluster_prefix = A_surfxml_cluster_prefix;
+  char *cluster_suffix = A_surfxml_cluster_suffix;
+  char *cluster_radical = A_surfxml_cluster_radical;
+  char *cluster_bb_bw = A_surfxml_cluster_bb_bw;
+  char *cluster_bb_lat = A_surfxml_cluster_bb_lat;
+  char *cluster_bw = A_surfxml_cluster_bw;
+  char *cluster_lat = A_surfxml_cluster_lat;
+  char *groups = NULL;
+
+  int start, end, i;
+  unsigned int iter;
+
+  xbt_dynar_t radical_elements;
+  xbt_dynar_t radical_ends;
+  xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
+
+  char *router_id,*host_id;
+
+  radical_elements = xbt_str_split(cluster_radical, ",");
+  xbt_dynar_foreach(radical_elements, iter, groups) {
+    radical_ends = xbt_str_split(groups, "-");
+
+    switch (xbt_dynar_length(radical_ends)) {
+    case 1:
+      start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
+      xbt_dynar_push_as(tab_elements_num, int, start);
+      router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix);
+      xbt_lib_set(host_lib,
+                  router_id,
+                  NS3_HOST_LEVEL,
+                  ns3_add_host_cluster(router_id)
+        );
+      XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
+      free(router_id);
+      break;
+
+    case 2:
+      start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
+      end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
+      for (i = start; i <= end; i++){
+        xbt_dynar_push_as(tab_elements_num, int, i);
+        router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix);
+        xbt_lib_set(host_lib,
+                    router_id,
+                    NS3_HOST_LEVEL,
+                    ns3_add_host_cluster(router_id)
+          );
+        XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
+        free(router_id);
+      }
+      break;
+
+    default:
+      XBT_DEBUG("Malformed radical");
+    }
+  }
+
+  //Create links
+  unsigned int cpt;
+  int elmts;
+  char * lat = xbt_strdup(cluster_lat);
+  char * bw =  xbt_strdup(cluster_bw);
+  replace_lat_ns3(&lat);
+  replace_bdw_ns3(&bw);
+
+  xbt_dynar_foreach(tab_elements_num,cpt,elmts)
+  {
+    host_id   = bprintf("%s%d%s", cluster_prefix, elmts, cluster_suffix);
+    router_id = bprintf("ns3_%s%d%s", cluster_prefix, elmts, cluster_suffix);
+    XBT_DEBUG("Create link from '%s' to '%s'",host_id,router_id);
+
+    ns3_nodes_t host_src = xbt_lib_get_or_null(host_lib,host_id,  NS3_HOST_LEVEL);
+    ns3_nodes_t host_dst = xbt_lib_get_or_null(host_lib,router_id,NS3_HOST_LEVEL);
+
+    if(host_src && host_dst){}
+    else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
+
+    ns3_add_link(host_src->node_num,host_src->type,
+                 host_dst->node_num,host_dst->type,
+                 bw,lat);
+
+    free(router_id);
+    free(host_id);
+  }
+  xbt_dynar_free(&tab_elements_num);
+
+
+  //Create link backbone
+  lat = xbt_strdup(cluster_bb_lat);
+  bw =  xbt_strdup(cluster_bb_bw);
+  replace_lat_ns3(&lat);
+  replace_bdw_ns3(&bw);
+  ns3_add_cluster(bw,lat,A_surfxml_cluster_id);
+  xbt_free(lat);
+  xbt_free(bw);        
 }
 
-double ns3_get_link_latency (const void *link)
+static double ns3_get_link_latency (const void *link)
 {
-       double lat;
-       //XBT_DEBUG("link_id:%s link_lat:%s link_bdw:%s",((surf_ns3_link_t)link)->data->id,((surf_ns3_link_t)link)->data->lat,((surf_ns3_link_t)link)->data->bdw);
-       sscanf(((surf_ns3_link_t)link)->data->lat,"%lg",&lat);
-       return lat;
+  double lat;
+  //XBT_DEBUG("link_id:%s link_lat:%s link_bdw:%s",((surf_ns3_link_t)link)->data->id,((surf_ns3_link_t)link)->data->lat,((surf_ns3_link_t)link)->data->bdw);
+  sscanf(((surf_ns3_link_t)link)->data->lat,"%lg",&lat);
+  return lat;
 }
-double ns3_get_link_bandwidth (const void *link)
+static double ns3_get_link_bandwidth (const void *link)
 {
-       double bdw;
-       //XBT_DEBUG("link_id:%s link_lat:%s link_bdw:%s",((surf_ns3_link_t)link)->data->id,((surf_ns3_link_t)link)->data->lat,((surf_ns3_link_t)link)->data->bdw);
-       sscanf(((surf_ns3_link_t)link)->data->bdw,"%lg",&bdw);
-       return bdw;
+  double bdw;
+  //XBT_DEBUG("link_id:%s link_lat:%s link_bdw:%s",((surf_ns3_link_t)link)->data->id,((surf_ns3_link_t)link)->data->lat,((surf_ns3_link_t)link)->data->bdw);
+  sscanf(((surf_ns3_link_t)link)->data->bdw,"%lg",&bdw);
+  return bdw;
 }
 
 static xbt_dynar_t ns3_get_route(const char *src, const char *dst)
 {
-  return global_routing->get_route(src, dst);
+  xbt_dynar_t route = NULL;
+  routing_get_route_and_latency(src, dst, &route, NULL);
+  return route;
 }
 
-void parse_ns3_end_platform(void)
+static void parse_ns3_end_platform(void)
 {
-       ns3_end_platform();
+  ns3_end_platform();
 }
 
 /* Create the ns3 topology based on routing strategy */
-void create_ns3_topology()
+static void create_ns3_topology(void)
 {
-   XBT_DEBUG("Starting topology generation");
-
-   xbt_dynar_shrink(IPV4addr,0);
-
-   //get the onelinks from the parsed platform
-   xbt_dynar_t onelink_routes = global_routing->get_onelink_routes();
-   if (!onelink_routes)
-     xbt_die("There is no routes!");
-   XBT_DEBUG("Have get_onelink_routes, found %ld routes",onelink_routes->used);
-   //save them in trace file
-   onelink_t onelink;
-   unsigned int iter;
-   xbt_dynar_foreach(onelink_routes, iter, onelink) {
-     char *src = onelink->src;
-     char *dst = onelink->dst;
-     void *link = onelink->link_ptr;
-
-     if( strcmp(src,dst) && ((surf_ns3_link_t)link)->created){
-     XBT_DEBUG("Route from '%s' to '%s' with link '%s'",src,dst,((surf_ns3_link_t)link)->data->id);
-     char * link_bdw = xbt_strdup(((surf_ns3_link_t)link)->data->bdw);
-        char * link_lat = xbt_strdup(((surf_ns3_link_t)link)->data->lat);
-        replace_lat_ns3(&link_lat);
-        replace_bdw_ns3(&link_bdw);
-        ((surf_ns3_link_t)link)->created = 0;
-
-        //      XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id);
-     XBT_DEBUG("\tLink (%s) bdw:%s lat:%s",((surf_ns3_link_t)link)->data->id,
-                link_bdw,
-                link_lat
-                );
-
-     //create link ns3
-     ns3_nodes_t host_src = xbt_lib_get_or_null(host_lib,src,NS3_HOST_LEVEL);
-     if(!host_src) host_src = xbt_lib_get_or_null(as_router_lib,src,NS3_ASR_LEVEL);
-     ns3_nodes_t host_dst = xbt_lib_get_or_null(host_lib,dst,NS3_HOST_LEVEL);
-     if(!host_dst) host_dst = xbt_lib_get_or_null(as_router_lib,dst,NS3_ASR_LEVEL);
-
-     if(host_src && host_dst){}
-     else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
-
-     ns3_add_link(host_src->node_num,host_src->type,host_dst->node_num,host_dst->type,link_bdw,link_lat);
-
-     xbt_free(link_bdw);
-     xbt_free(link_lat);
-     }
-   }
+  XBT_DEBUG("Starting topology generation");
+
+  xbt_dynar_shrink(IPV4addr,0);
+
+  //get the onelinks from the parsed platform
+  xbt_dynar_t onelink_routes = global_routing->get_onelink_routes();
+  if (!onelink_routes)
+    xbt_die("There is no routes!");
+  XBT_DEBUG("Have get_onelink_routes, found %ld routes",onelink_routes->used);
+  //save them in trace file
+  onelink_t onelink;
+  unsigned int iter;
+  xbt_dynar_foreach(onelink_routes, iter, onelink) {
+    char *src = onelink->src;
+    char *dst = onelink->dst;
+    void *link = onelink->link_ptr;
+
+    if( strcmp(src,dst) && ((surf_ns3_link_t)link)->created){
+      XBT_DEBUG("Route from '%s' to '%s' with link '%s'",src,dst,((surf_ns3_link_t)link)->data->id);
+      char * link_bdw = xbt_strdup(((surf_ns3_link_t)link)->data->bdw);
+      char * link_lat = xbt_strdup(((surf_ns3_link_t)link)->data->lat);
+      replace_lat_ns3(&link_lat);
+      replace_bdw_ns3(&link_bdw);
+      ((surf_ns3_link_t)link)->created = 0;
+
+      //        XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id);
+      XBT_DEBUG("\tLink (%s) bdw:%s lat:%s",((surf_ns3_link_t)link)->data->id,
+                link_bdw,
+                link_lat
+        );
+
+      //create link ns3
+      ns3_nodes_t host_src = xbt_lib_get_or_null(host_lib,src,NS3_HOST_LEVEL);
+      if(!host_src) host_src = xbt_lib_get_or_null(as_router_lib,src,NS3_ASR_LEVEL);
+      ns3_nodes_t host_dst = xbt_lib_get_or_null(host_lib,dst,NS3_HOST_LEVEL);
+      if(!host_dst) host_dst = xbt_lib_get_or_null(as_router_lib,dst,NS3_ASR_LEVEL);
+
+      if(host_src && host_dst){}
+      else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
+
+      ns3_add_link(host_src->node_num,host_src->type,host_dst->node_num,host_dst->type,link_bdw,link_lat);
+
+      xbt_free(link_bdw);
+      xbt_free(link_lat);
+    }
+  }
 }
 
 static void define_callbacks_ns3(void)
 {
-  surfxml_add_callback(STag_surfxml_host_cb_list, &parse_ns3_add_host);              //HOST
-  surfxml_add_callback(STag_surfxml_router_cb_list, &parse_ns3_add_router);      //ROUTER
-  surfxml_add_callback(STag_surfxml_link_cb_list, &parse_ns3_add_link);              //LINK
-  surfxml_add_callback(STag_surfxml_AS_cb_list, &parse_ns3_add_AS);                  //AS
-  surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_ns3_add_cluster); //CLUSTER
-
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &create_ns3_topology);    //get_one_link_routes
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &parse_ns3_end_platform); //InitializeRoutes
+  sg_platf_host_add_cb (&parse_ns3_add_host);
+  sg_platf_router_add_cb (&parse_ns3_add_router);
+  sg_platf_link_add_cb (&parse_ns3_add_link);
+  sg_platf_cluster_add_cb (&parse_ns3_add_cluster);
+  sg_platf_AS_begin_add_cb (&parse_ns3_add_AS);
+  sg_platf_postparse_add_cb(&create_ns3_topology); //get_one_link_routes
+  sg_platf_postparse_add_cb(&parse_ns3_end_platform); //InitializeRoutes
 }
 
 static void free_ns3_link(void * elmts)
 {
-       ns3_link_t link = elmts;
-       free(link->id);
-       free(link->bdw);
-       free(link->lat);
-       free(link);
+  ns3_link_t link = elmts;
+  free(link->id);
+  free(link->bdw);
+  free(link->lat);
+  free(link);
 }
 
 static void free_ns3_host(void * elmts)
@@ -354,146 +343,144 @@ static void ns3_action_set_category(surf_action_t action, const char *category)
 
 void surf_network_model_init_NS3()
 {
-       if (surf_network_model)
-               return;
+  if (surf_network_model)
+    return;
 
-       surf_network_model = surf_model_init();
-       surf_network_model->name = "network NS3";
-       surf_network_model->extension.network.get_link_latency = ns3_get_link_latency;
-       surf_network_model->extension.network.get_link_bandwidth = ns3_get_link_bandwidth;
-       surf_network_model->extension.network.get_route = ns3_get_route;
+  surf_network_model = surf_model_init();
+  surf_network_model->name = "network NS3";
+  surf_network_model->extension.network.get_link_latency = ns3_get_link_latency;
+  surf_network_model->extension.network.get_link_bandwidth = ns3_get_link_bandwidth;
+  surf_network_model->extension.network.get_route = ns3_get_route;
 
-       surf_network_model->model_private->share_resources = ns3_share_resources;
-       surf_network_model->model_private->update_actions_state = ns3_update_actions_state;
-       surf_network_model->model_private->finalize = finalize;
+  surf_network_model->model_private->share_resources = ns3_share_resources;
+  surf_network_model->model_private->update_actions_state = ns3_update_actions_state;
+  surf_network_model->model_private->finalize = finalize;
 
-       surf_network_model->suspend = action_suspend;
-       surf_network_model->resume = action_resume;
-       surf_network_model->is_suspended = action_is_suspended;
-       surf_network_model->action_unref = action_unref;
-       surf_network_model->extension.network.communicate = ns3_communicate;
+  surf_network_model->suspend = action_suspend;
+  surf_network_model->resume = action_resume;
+  surf_network_model->is_suspended = action_is_suspended;
+  surf_network_model->action_unref = action_unref;
+  surf_network_model->extension.network.communicate = ns3_communicate;
 
 #ifdef HAVE_TRACING
   surf_network_model->set_category = ns3_action_set_category;
 #endif
 
-       /* Added the initialization for NS3 interface */
+  /* Added the initialization for NS3 interface */
 
-       if (ns3_initialize(xbt_cfg_get_string(_surf_cfg_set,"ns3/TcpModel"))) {
-       xbt_die("Impossible to initialize NS3 interface");
-       }
+  if (ns3_initialize(xbt_cfg_get_string(_surf_cfg_set,"ns3/TcpModel"))) {
+    xbt_die("Impossible to initialize NS3 interface");
+  }
 
-       routing_model_create(sizeof(s_surf_ns3_link_t), NULL, NULL);
-       define_callbacks_ns3();
+  routing_model_create(sizeof(s_surf_ns3_link_t), NULL);
+  define_callbacks_ns3();
 
-       NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_host);
-       NS3_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_host);
-       NS3_LINK_LEVEL = xbt_lib_add_level(link_lib,(void_f_pvoid_t)free_ns3_link);
+  NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_host);
+  NS3_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_host);
+  NS3_LINK_LEVEL = xbt_lib_add_level(link_lib,(void_f_pvoid_t)free_ns3_link);
 
-       xbt_dynar_push(model_list, &surf_network_model);
-       update_model_description(surf_network_model_description,
-                   "NS3", surf_network_model);
+  xbt_dynar_push(model_list, &surf_network_model);
 
 #ifdef HAVE_LATENCY_BOUND_TRACKING
-       surf_network_model->get_latency_limited = ns3_get_link_latency_limited;
+  surf_network_model->get_latency_limited = ns3_get_link_latency_limited;
 #endif
 }
 
 static void finalize(void)
 {
-       ns3_finalize();
-       xbt_dynar_free_container(&IPV4addr);
-       xbt_dict_free(&dict_socket);
+  ns3_finalize();
+  xbt_dynar_free_container(&IPV4addr);
+  xbt_dict_free(&dict_socket);
 }
 
 static double ns3_share_resources(double min)
 {
-       XBT_DEBUG("ns3_share_resources");
-
-       xbt_swag_t running_actions =
-         surf_network_model->states.running_action_set;
-
-       //get the first relevant value from the running_actions list
-       if (!xbt_swag_size(running_actions) || min == 0.0)
-         return -1.0;
-       else
-        do {
-          ns3_simulator(min);
-          time_to_next_flow_completion = ns3_time() - surf_get_clock();
-        } while(double_equals(time_to_next_flow_completion,0));
-
-       XBT_DEBUG("min       : %f",min);
-       XBT_DEBUG("ns3  time : %f",ns3_time());
-       XBT_DEBUG("surf time : %f",surf_get_clock());
-       XBT_DEBUG("Next completion %f :",time_to_next_flow_completion);
-
-       return time_to_next_flow_completion;
+  XBT_DEBUG("ns3_share_resources");
+
+  xbt_swag_t running_actions =
+    surf_network_model->states.running_action_set;
+
+  //get the first relevant value from the running_actions list
+  if (!xbt_swag_size(running_actions) || min == 0.0)
+    return -1.0;
+  else
+    do {
+      ns3_simulator(min);
+      time_to_next_flow_completion = ns3_time() - surf_get_clock();
+    } while(double_equals(time_to_next_flow_completion,0));
+
+  XBT_DEBUG("min       : %f",min);
+  XBT_DEBUG("ns3  time : %f",ns3_time());
+  XBT_DEBUG("surf time : %f",surf_get_clock());
+  XBT_DEBUG("Next completion %f :",time_to_next_flow_completion);
+
+  return time_to_next_flow_completion;
 }
 
 static void ns3_update_actions_state(double now, double delta)
 {
-         xbt_dict_cursor_t cursor = NULL;
-         char *key;
-         void *data;
-
-         static xbt_dynar_t socket_to_destroy = NULL;
-    if(!socket_to_destroy) socket_to_destroy = xbt_dynar_new(sizeof(char*),NULL);
-
-         surf_action_network_ns3_t action = NULL;
-         xbt_swag_t running_actions =
-             surf_network_model->states.running_action_set;
-
-         /* If there are no running flows, just return */
-         if (!xbt_swag_size(running_actions)) {
-           while(double_positive(now-ns3_time())) {
-             ns3_simulator(now-ns3_time());
-           }
-           return;
-         }
-
-         xbt_dict_foreach(dict_socket,cursor,key,data){
-           action = (surf_action_network_ns3_t)ns3_get_socket_action(data);
-           XBT_DEBUG("Processing socket %p (action %p)",data,action);
-           action->generic_action.remains = action->generic_action.cost - ns3_get_socket_sent(data);
+  xbt_dict_cursor_t cursor = NULL;
+  char *key;
+  void *data;
+
+  static xbt_dynar_t socket_to_destroy = NULL;
+  if(!socket_to_destroy) socket_to_destroy = xbt_dynar_new(sizeof(char*),NULL);
+
+  surf_action_network_ns3_t action = NULL;
+  xbt_swag_t running_actions =
+    surf_network_model->states.running_action_set;
+
+  /* If there are no running flows, just return */
+  if (!xbt_swag_size(running_actions)) {
+    while(double_positive(now-ns3_time())) {
+      ns3_simulator(now-ns3_time());
+    }
+    return;
+  }
+
+  xbt_dict_foreach(dict_socket,cursor,key,data){
+    action = (surf_action_network_ns3_t)ns3_get_socket_action(data);
+    XBT_DEBUG("Processing socket %p (action %p)",data,action);
+    action->generic_action.remains = action->generic_action.cost - ns3_get_socket_sent(data);
 
 #ifdef HAVE_TRACING
-           if (TRACE_is_enabled() &&
-               surf_action_state_get(&(action->generic_action)) == SURF_ACTION_RUNNING){
-             double data_sent = ns3_get_socket_sent(data);
-             double data_delta_sent = data_sent - action->last_sent;
-
-             xbt_dynar_t route = global_routing->get_route(action->src_name, action->dst_name);
-             unsigned int i;
-             for (i = 0; i < xbt_dynar_length (route); i++){
-               surf_ns3_link_t *link = ((surf_ns3_link_t*)xbt_dynar_get_ptr (route, i));
-               TRACE_surf_link_set_utilization ((*link)->generic_resource.name,
-                   action->generic_action.data,
-                   (surf_action_t) action,
-                   (data_delta_sent)/delta,
-                   now-delta,
-                   delta);
-             }
-             action->last_sent = data_sent;
-           }
+    if (TRACE_is_enabled() &&
+        surf_action_state_get(&(action->generic_action)) == SURF_ACTION_RUNNING){
+      double data_sent = ns3_get_socket_sent(data);
+      double data_delta_sent = data_sent - action->last_sent;
+
+      xbt_dynar_t route = NULL;
+      routing_get_route_and_latency (action->src_name, action->dst_name, &route, NULL);
+      unsigned int i;
+      for (i = 0; i < xbt_dynar_length (route); i++){
+        surf_ns3_link_t *link = ((surf_ns3_link_t*)xbt_dynar_get_ptr (route, i));
+        TRACE_surf_link_set_utilization ((*link)->generic_resource.name,
+                                         ((surf_action_t) action)->category,
+                                         (data_delta_sent)/delta,
+                                         now-delta,
+                                         delta);
+      }
+      action->last_sent = data_sent;
+    }
 #endif
 
-           if(ns3_get_socket_is_finished(data) == 1){
-             xbt_dynar_push(socket_to_destroy,&key);
-             XBT_DEBUG("Destroy socket %p of action %p", key, action);
-             action->generic_action.finish = now;
-             surf_action_state_set(&(action->generic_action), SURF_ACTION_DONE);
-           }
-         }
-
-         while (!xbt_dynar_is_empty(socket_to_destroy)){
-           xbt_dynar_pop(socket_to_destroy,&key);
-
-           void *data = xbt_dict_get (dict_socket, key);
-           surf_action_network_ns3_t action = (surf_action_network_ns3_t)ns3_get_socket_action(data);
-           XBT_DEBUG ("Removing socket %p of action %p", key, action);
-           xbt_dict_remove(dict_socket,key);
-         }
-         return;
+    if(ns3_get_socket_is_finished(data) == 1){
+      xbt_dynar_push(socket_to_destroy,&key);
+      XBT_DEBUG("Destroy socket %p of action %p", key, action);
+      action->generic_action.finish = now;
+      surf_action_state_set(&(action->generic_action), SURF_ACTION_DONE);
+    }
+  }
+
+  while (!xbt_dynar_is_empty(socket_to_destroy)){
+    xbt_dynar_pop(socket_to_destroy,&key);
+
+    void *data = xbt_dict_get (dict_socket, key);
+    surf_action_network_ns3_t action = (surf_action_network_ns3_t)ns3_get_socket_action(data);
+    XBT_DEBUG ("Removing socket %p of action %p", key, action);
+    xbt_dict_remove(dict_socket,key);
+  }
+  return;
 }
 
 /* Max durations are not supported */
index 68dfe46..000acc7 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2004, 2005, 2007, 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2012. 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. */
@@ -20,20 +19,11 @@ typedef struct network_link_CM02 {
   tmgr_trace_event_t lat_event;
 } s_link_CM02_t, *link_CM02_t;
 
-enum heap_action_type{
-  LATENCY = 100,
-  MAX_DURATION,
-  NORMAL,
-  NOTSET
-};
-
 typedef struct surf_action_network_CM02 {
-  s_surf_action_t generic_action;
-  s_xbt_swag_hookup_t action_list_hookup;
+  s_surf_action_lmm_t generic_lmm_action;
   double latency;
   double lat_current;
   double weight;
-  lmm_variable_t variable;
   double rate;
   struct {
      const char* link_name;
@@ -44,14 +34,6 @@ typedef struct surf_action_network_CM02 {
 #ifdef HAVE_LATENCY_BOUND_TRACKING
   int latency_limited;
 #endif
-  int suspended;
-#ifdef HAVE_TRACING
-  char *src_name;
-  char *dst_name;
-#endif
-  int index_heap;
-  enum heap_action_type hat;
-  double last_update;
 } s_surf_action_network_CM02_t, *surf_action_network_CM02_t;
 
 #endif                          /* _SURF_NETWORK_PRIVATE_H */
index 8cb67c0..a0d7d02 100644 (file)
@@ -571,14 +571,7 @@ static void _get_route_and_latency(const char *src, const char *dst,
   /* If dest gateway is not our destination, we have to recursively find our way from this point */
   // FIXME why can't I factorize it the same way than [src;src_gw] without breaking the examples??
   if (strcmp(dst_gateway, dst)) {
-    xbt_dynar_t route_dst = xbt_dynar_new(global_routing->size_of_link,NULL);
-
-    _get_route_and_latency(dst_gateway, dst, &route_dst, latency);
-
-    xbt_dynar_foreach(route_dst, cpt, link) {
-      xbt_dynar_push(*links, &link);
-    }
-    xbt_dynar_free(&route_dst);
+    _get_route_and_latency(dst_gateway, dst, links, latency);
   }
 
   xbt_free(src_gateway);
@@ -788,29 +781,26 @@ static void routing_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage)
 static void mount_free(void *p)
 {
   mount_t mnt = p;
-  xbt_free(mnt->id);
   xbt_free(mnt->name);
 }
 
 static void routing_parse_mount(sg_platf_mount_cbarg_t mount)
 {
-
   // Verification of an existing storage
   void* storage = xbt_lib_get_or_null(storage_lib, mount->id,ROUTING_STORAGE_LEVEL);
   xbt_assert(storage,"Disk id \"%s\" does not exists", mount->id);
 
   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->id, mount->name);
 
-  mount_t mnt = xbt_new0(s_mount_t, 1);
-  mnt->id = xbt_strdup(mount->id);
-  mnt->name = xbt_strdup(mount->name);
+  s_mount_t mnt;
+  mnt.id = surf_storage_resource_by_name(mount->id);
+  mnt.name = xbt_strdup(mount->name);
 
   if(!mount_list){
     XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
     mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
   }
   xbt_dynar_push(mount_list,&mnt);
-
 }
 
 static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
index 946df08..3b33462 100644 (file)
@@ -277,23 +277,29 @@ static xbt_dict_t ws_get_properties(const void *ws)
   return surf_resource_properties(((workstation_CLM03_t) ws)->cpu);
 }
 
-static surf_action_t ws_action_open(void *workstation, const char* storage, const char* path, const char* mode)
+static storage_t find_storage_on_mount_list(void *workstation,const char* storage)
 {
   storage_t st = NULL;
-  mount_t mnt = NULL;
+  s_mount_t mnt;
   unsigned int cursor;
   xbt_dynar_t storage_list = ((workstation_CLM03_t) workstation)->storage;
 
   XBT_DEBUG("Search for storage name '%s' on '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
   xbt_dynar_foreach(storage_list,cursor,mnt)
   {
-     XBT_DEBUG("See '%s'",mnt->name);
-     if(!strcmp(storage,mnt->name)){
-       st = surf_storage_resource_by_name(mnt->id);
-       break;
-     }
+    XBT_DEBUG("See '%s'",mnt.name);
+    if(!strcmp(storage,mnt.name)){
+      st = mnt.id;
+      break;
+    }
   }
-  if(!st) xbt_die("Don't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
+  if(!st) xbt_die("Can't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
+  return st;
+}
+
+static surf_action_t ws_action_open(void *workstation, const char* storage, const char* path, const char* mode)
+{
+  storage_t st = find_storage_on_mount_list(workstation, storage);
   XBT_DEBUG("OPEN on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
   return model->extension.storage.open(st, path, mode);
@@ -301,21 +307,7 @@ static surf_action_t ws_action_open(void *workstation, const char* storage, cons
 
 static surf_action_t ws_action_close(void *workstation, const char* storage, surf_file_t fp)
 {
-  storage_t st = NULL;
-  mount_t mnt = NULL;
-  unsigned int cursor;
-  xbt_dynar_t storage_list = ((workstation_CLM03_t) workstation)->storage;
-
-  XBT_DEBUG("Search for storage name '%s' on '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
-  xbt_dynar_foreach(storage_list,cursor,mnt)
-  {
-    XBT_DEBUG("See '%s'",mnt->name);
-    if(!strcmp(storage,mnt->name)){
-      st = surf_storage_resource_by_name(mnt->id);
-      break;
-    }
-  }
-  if(!st) xbt_die("Don't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
+  storage_t st = find_storage_on_mount_list(workstation, storage);
   XBT_DEBUG("CLOSE on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
   return model->extension.storage.close(st, fp);
@@ -323,21 +315,7 @@ static surf_action_t ws_action_close(void *workstation, const char* storage, sur
 
 static surf_action_t ws_action_read(void *workstation, const char* storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream)
 {
-  storage_t st = NULL;
-  mount_t mnt = NULL;
-  unsigned int cursor;
-  xbt_dynar_t storage_list = ((workstation_CLM03_t) workstation)->storage;
-
-  XBT_DEBUG("Search for storage name '%s' on '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
-  xbt_dynar_foreach(storage_list,cursor,mnt)
-  {
-    XBT_DEBUG("See '%s'",mnt->name);
-    if(!strcmp(storage,mnt->name)){
-      st = surf_storage_resource_by_name(mnt->id);
-      break;
-    }
-  }
-  if(!st) xbt_die("Don't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
+  storage_t st = find_storage_on_mount_list(workstation, storage);
   XBT_DEBUG("READ on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
   return model->extension.storage.read(st, ptr, size, nmemb, stream);
@@ -345,21 +323,7 @@ static surf_action_t ws_action_read(void *workstation, const char* storage, void
 
 static surf_action_t ws_action_write(void *workstation, const char* storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream)
 {
-  storage_t st = NULL;
-  mount_t mnt = NULL;
-  unsigned int cursor;
-  xbt_dynar_t storage_list = ((workstation_CLM03_t) workstation)->storage;
-
-  XBT_DEBUG("Search for storage name '%s' on '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
-  xbt_dynar_foreach(storage_list,cursor,mnt)
-  {
-    XBT_DEBUG("See '%s'",mnt->name);
-    if(!strcmp(storage,mnt->name)){
-      st = surf_storage_resource_by_name(mnt->id);
-      break;
-    }
-  }
-  if(!st) xbt_die("Don't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
+  storage_t st = find_storage_on_mount_list(workstation, storage);
   XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
   return model->extension.storage.write(st,  ptr, size, nmemb, stream);
@@ -367,21 +331,7 @@ static surf_action_t ws_action_write(void *workstation, const char* storage, con
 
 static surf_action_t ws_action_stat(void *workstation, const char* storage, int fd, void* buf)
 {
-  storage_t st = NULL;
-  mount_t mnt = NULL;
-  unsigned int cursor;
-  xbt_dynar_t storage_list = ((workstation_CLM03_t) workstation)->storage;
-
-  XBT_DEBUG("Search for storage name '%s' on '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
-  xbt_dynar_foreach(storage_list,cursor,mnt)
-  {
-    XBT_DEBUG("See '%s'",mnt->name);
-    if(!strcmp(storage,mnt->name)){
-      st = surf_storage_resource_by_name(mnt->id);
-      break;
-    }
-  }
-  if(!st) xbt_die("Don't find mount '%s' for '%s'",storage,((workstation_CLM03_t) workstation)->generic_resource.name);
+  storage_t st = find_storage_on_mount_list(workstation, storage);
   XBT_DEBUG("STAT on disk '%s'",st->generic_resource.name);
   surf_model_t model = st->generic_resource.model;
   return model->extension.storage.stat(st,  fd, buf);